Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
imjiangjun
pbrt-v4
提交
ba2dff68
P
pbrt-v4
项目概览
imjiangjun
/
pbrt-v4
12 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pbrt-v4
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ba2dff68
编写于
9月 01, 2021
作者:
M
Matt Pharr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ScratchBuffer: add Realloc() method to grow the arena when needed
上级
1b160afe
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
11 deletion
+32
-11
src/pbrt/util/memory.h
src/pbrt/util/memory.h
+32
-11
未找到文件。
src/pbrt/util/memory.h
浏览文件 @
ba2dff68
...
...
@@ -13,9 +13,11 @@
#include <atomic>
#include <cstddef>
#include <list>
#include <memory>
#include <mutex>
#include <type_traits>
#include <utility>
namespace
pbrt
{
...
...
@@ -70,37 +72,42 @@ struct AllocationTraits<T[n]> {
class
alignas
(
PBRT_L1_CACHE_LINE_SIZE
)
ScratchBuffer
{
public:
// ScratchBuffer Public Methods
ScratchBuffer
()
=
default
;
ScratchBuffer
(
int
size
)
:
allocatedBytes
(
size
)
{
ptr
=
(
uint8_t
*
)
Allocator
().
allocate_bytes
(
size
,
align
);
ScratchBuffer
(
int
size
=
256
)
:
allocSize
(
size
)
{
ptr
=
(
char
*
)
Allocator
().
allocate_bytes
(
size
,
align
);
}
ScratchBuffer
(
const
ScratchBuffer
&
)
=
delete
;
ScratchBuffer
(
ScratchBuffer
&&
b
)
{
ptr
=
b
.
ptr
;
alloc
atedBytes
=
b
.
allocatedBytes
;
alloc
Size
=
b
.
allocSize
;
offset
=
b
.
offset
;
smallBuffers
=
std
::
move
(
b
.
smallBuffers
);
b
.
ptr
=
nullptr
;
b
.
alloc
atedBytes
=
b
.
offset
=
0
;
b
.
alloc
Size
=
b
.
offset
=
0
;
}
~
ScratchBuffer
()
{
Allocator
().
deallocate_bytes
(
ptr
,
allocatedBytes
,
align
);
}
~
ScratchBuffer
()
{
Reset
();
Allocator
().
deallocate_bytes
(
ptr
,
allocSize
,
align
);
}
ScratchBuffer
&
operator
=
(
const
ScratchBuffer
&
)
=
delete
;
ScratchBuffer
&
operator
=
(
ScratchBuffer
&&
b
)
{
std
::
swap
(
b
.
ptr
,
ptr
);
std
::
swap
(
b
.
alloc
atedBytes
,
allocatedBytes
);
std
::
swap
(
b
.
alloc
Size
,
allocSize
);
std
::
swap
(
b
.
offset
,
offset
);
std
::
swap
(
b
.
smallBuffers
,
smallBuffers
);
return
*
this
;
}
void
*
Alloc
(
size_t
size
,
size_t
align
)
{
if
((
offset
%
align
)
!=
0
)
offset
+=
align
-
(
offset
%
align
);
CHECK_LE
(
offset
+
size
,
allocatedBytes
);
if
(
offset
+
size
>
allocSize
)
Realloc
(
size
);
void
*
p
=
ptr
+
offset
;
offset
+=
size
;
return
p
;
...
...
@@ -123,13 +130,27 @@ class alignas(PBRT_L1_CACHE_LINE_SIZE) ScratchBuffer {
}
PBRT_CPU_GPU
void
Reset
()
{
offset
=
0
;
}
void
Reset
()
{
for
(
const
auto
&
buf
:
smallBuffers
)
Allocator
().
deallocate_bytes
(
buf
.
first
,
buf
.
second
,
align
);
smallBuffers
.
clear
();
offset
=
0
;
}
private:
// ScratchBuffer Private Methods
void
Realloc
(
size_t
minSize
)
{
smallBuffers
.
push_back
(
std
::
make_pair
(
ptr
,
allocSize
));
allocSize
=
std
::
max
(
2
*
minSize
,
allocSize
+
minSize
);
ptr
=
(
char
*
)
Allocator
().
allocate_bytes
(
allocSize
,
align
);
offset
=
0
;
}
// ScratchBuffer Private Members
static
constexpr
int
align
=
PBRT_L1_CACHE_LINE_SIZE
;
uint8_t
*
ptr
=
nullptr
;
int
allocatedBytes
=
0
,
offset
=
0
;
char
*
ptr
=
nullptr
;
int
allocSize
=
0
,
offset
=
0
;
std
::
list
<
std
::
pair
<
char
*
,
size_t
>>
smallBuffers
;
};
}
// namespace pbrt
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录