Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
imjiangjun
pbrt-v4
提交
0dec8bb6
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,发现更多精彩内容 >>
提交
0dec8bb6
编写于
7月 28, 2021
作者:
M
Matt Pharr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update from book source. No functional changes.
上级
1e51ecbb
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
105 addition
and
114 deletion
+105
-114
src/pbrt/cmd/pbrt.cpp
src/pbrt/cmd/pbrt.cpp
+2
-1
src/pbrt/cpu/aggregates.cpp
src/pbrt/cpu/aggregates.cpp
+4
-2
src/pbrt/cpu/integrators.cpp
src/pbrt/cpu/integrators.cpp
+9
-9
src/pbrt/cpu/render.cpp
src/pbrt/cpu/render.cpp
+2
-2
src/pbrt/options.cpp
src/pbrt/options.cpp
+12
-11
src/pbrt/parsedscene.cpp
src/pbrt/parsedscene.cpp
+7
-7
src/pbrt/pbrt.cpp
src/pbrt/pbrt.cpp
+4
-4
src/pbrt/samplers.cpp
src/pbrt/samplers.cpp
+8
-22
src/pbrt/textures.cpp
src/pbrt/textures.cpp
+8
-4
src/pbrt/util/buffercache.h
src/pbrt/util/buffercache.h
+13
-18
src/pbrt/util/containers.h
src/pbrt/util/containers.h
+7
-8
src/pbrt/util/image.cpp
src/pbrt/util/image.cpp
+7
-2
src/pbrt/util/log.h
src/pbrt/util/log.h
+1
-2
src/pbrt/util/mesh.h
src/pbrt/util/mesh.h
+1
-2
src/pbrt/util/parallel.h
src/pbrt/util/parallel.h
+5
-6
src/pbrt/wavefront/integrator.cpp
src/pbrt/wavefront/integrator.cpp
+13
-13
src/pbrt/wavefront/integrator.h
src/pbrt/wavefront/integrator.h
+2
-1
未找到文件。
src/pbrt/cmd/pbrt.cpp
浏览文件 @
0dec8bb6
...
...
@@ -167,8 +167,9 @@ int main(int argc, char *argv[]) {
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"format"
,
&
format
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"log-level"
,
&
logLevel
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"log-utilization"
,
&
options
.
logUtilization
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"log-file"
,
&
options
.
logFile
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"log-utilization"
,
&
options
.
logUtilization
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"mse-reference-image"
,
&
options
.
mseReferenceImage
,
onError
)
||
ParseArg
(
&
iter
,
args
.
end
(),
"mse-reference-out"
,
&
options
.
mseReferenceOutput
,
...
...
src/pbrt/cpu/aggregates.cpp
浏览文件 @
0dec8bb6
...
...
@@ -153,9 +153,11 @@ BVHAggregate::BVHAggregate(std::vector<Primitive> prims, int maxPrimsInNode,
// Declare _Allocator_s used for BVH construction
pstd
::
pmr
::
monotonic_buffer_resource
resource
;
Allocator
alloc
(
&
resource
);
std
::
vector
<
std
::
unique_ptr
<
pstd
::
pmr
::
monotonic_buffer_resource
>>
threadBufferResources
;
std
::
vector
<
std
::
unique_ptr
<
pstd
::
pmr
::
monotonic_buffer_resource
>>
threadBufferResources
;
ThreadLocal
<
Allocator
>
threadAllocators
([
&
threadBufferResources
]()
{
threadBufferResources
.
push_back
(
std
::
make_unique
<
pstd
::
pmr
::
monotonic_buffer_resource
>
());
threadBufferResources
.
push_back
(
std
::
make_unique
<
pstd
::
pmr
::
monotonic_buffer_resource
>
());
auto
ptr
=
threadBufferResources
.
back
().
get
();
return
Allocator
(
ptr
);
});
...
...
src/pbrt/cpu/integrators.cpp
浏览文件 @
0dec8bb6
...
...
@@ -94,7 +94,8 @@ void ImageTileIntegrator::Render() {
});
// Declare common variables for rendering image in tiles
ThreadLocal
<
ScratchBuffer
>
scratchBuffers
([]()
{
return
ScratchBuffer
(
65536
);
}
);
ThreadLocal
<
ScratchBuffer
>
scratchBuffers
([]()
{
return
ScratchBuffer
(
65536
);
});
ThreadLocal
<
Sampler
>
samplers
([
this
]()
{
return
samplerPrototype
.
Clone
();
});
Bounds2i
pixelBounds
=
camera
.
GetFilm
().
PixelBounds
();
...
...
@@ -2539,7 +2540,8 @@ void MLTIntegrator::Render() {
int
nBootstrapSamples
=
nBootstrap
*
(
maxDepth
+
1
);
std
::
vector
<
Float
>
bootstrapWeights
(
nBootstrapSamples
,
0
);
// Allocate scratch buffers for MLT samples
ThreadLocal
<
ScratchBuffer
>
threadScratchBuffers
([]()
{
return
ScratchBuffer
(
65536
);
});
ThreadLocal
<
ScratchBuffer
>
threadScratchBuffers
(
[]()
{
return
ScratchBuffer
(
65536
);
});
// Generate bootstrap samples in parallel
ProgressReporter
progress
(
nBootstrap
,
"Generating bootstrap paths"
,
Options
->
quiet
);
...
...
@@ -2795,9 +2797,8 @@ void SPPMIntegrator::Render() {
});
// Allocate samplers for SPPM rendering
ThreadLocal
<
Sampler
>
threadSamplers
([
this
]()
{
return
samplerPrototype
.
Clone
(
Allocator
());
});
ThreadLocal
<
Sampler
>
threadSamplers
(
[
this
]()
{
return
samplerPrototype
.
Clone
(
Allocator
());
});
pstd
::
vector
<
DigitPermutation
>
*
digitPermutations
(
ComputeRadicalInversePermutations
(
digitPermutationsSeed
));
...
...
@@ -3013,7 +3014,8 @@ void SPPMIntegrator::Render() {
// Trace photons and accumulate contributions
// Create per-thread scratch buffers for photon shooting
ThreadLocal
<
ScratchBuffer
>
photonShootScratchBuffers
([]()
{
return
ScratchBuffer
(
65536
);
});
ThreadLocal
<
ScratchBuffer
>
photonShootScratchBuffers
(
[]()
{
return
ScratchBuffer
(
65536
);
});
ParallelFor
(
0
,
photonsPerIteration
,
[
&
](
int64_t
start
,
int64_t
end
)
{
// Follow photon paths for photon index range _start_ - _end_
...
...
@@ -3141,9 +3143,7 @@ void SPPMIntegrator::Render() {
}
});
// Reset _threadScratchBuffers_ after tracing photons
threadScratchBuffers
.
ForAll
([](
ScratchBuffer
&
buffer
)
{
buffer
.
Reset
();
});
threadScratchBuffers
.
ForAll
([](
ScratchBuffer
&
buffer
)
{
buffer
.
Reset
();
});
progress
.
Update
();
photonPaths
+=
photonsPerIteration
;
...
...
src/pbrt/cpu/render.cpp
浏览文件 @
0dec8bb6
...
...
@@ -88,8 +88,8 @@ void RenderCPU(ParsedScene &parsedScene) {
parsedScene
.
CreateMaterials
(
textures
,
threadAllocators
,
&
namedMaterials
,
&
materials
);
LOG_VERBOSE
(
"Finished materials"
);
Primitive
accel
=
parsedScene
.
CreateAggregate
(
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
Primitive
accel
=
parsedScene
.
CreateAggregate
(
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
// Integrator
const
RGBColorSpace
*
integratorColorSpace
=
parsedScene
.
film
.
parameters
.
ColorSpace
();
...
...
src/pbrt/options.cpp
浏览文件 @
0dec8bb6
...
...
@@ -27,18 +27,19 @@ std::string ToString(const RenderingCoordinateSystem &r) {
std
::
string
PBRTOptions
::
ToString
()
const
{
return
StringPrintf
(
"[ PBRTOptions seed: %s quiet: %s disablePixelJitter: %s
disableWavelengthJitter: %s
"
"
forceDiffuse: %s useGPU: %s wavefront: %s renderingSpace: %s nThreads
: %s "
"
logLevel: %s logFile: %s logUtilization: %s writePartialImages: %s recordPixelStatistics
: %s "
"
printStatistics: %s pixelSamples: %s gpuDevice: %s quickRender: %s upgrade
: %s "
"
imageFile: %s mseReferenceImage: %s mseReferenceOutput: %s debugStart
: %s "
"
displayServer: %s cropWindow: %s pixelBounds: %s pixelMaterial
: %s "
"displacementEdgeScale: %f ]"
,
"[ PBRTOptions seed: %s quiet: %s disablePixelJitter: %s "
"
disableWavelengthJitter: %s forceDiffuse: %s useGPU: %s wavefront
: %s "
"
renderingSpace: %s nThreads: %s logLevel: %s logFile: %s logUtilization
: %s "
"
writePartialImages: %s recordPixelStatistics: %s printStatistics
: %s "
"
pixelSamples: %s gpuDevice: %s quickRender: %s upgrade: %s imageFile
: %s "
"
mseReferenceImage: %s mseReferenceOutput: %s debugStart: %s displayServer
: %s "
"
cropWindow: %s pixelBounds: %s pixelMaterial: %s
displacementEdgeScale: %f ]"
,
seed
,
quiet
,
disablePixelJitter
,
disableWavelengthJitter
,
forceDiffuse
,
useGPU
,
wavefront
,
renderingSpace
,
nThreads
,
logLevel
,
logFile
,
logUtilization
,
writePartialImages
,
recordPixelStatistics
,
printStatistics
,
pixelSamples
,
gpuDevice
,
quickRender
,
upgrade
,
imageFile
,
mseReferenceImage
,
mseReferenceOutput
,
debugStart
,
displayServer
,
cropWindow
,
pixelBounds
,
pixelMaterial
,
displacementEdgeScale
);
wavefront
,
renderingSpace
,
nThreads
,
logLevel
,
logFile
,
logUtilization
,
writePartialImages
,
recordPixelStatistics
,
printStatistics
,
pixelSamples
,
gpuDevice
,
quickRender
,
upgrade
,
imageFile
,
mseReferenceImage
,
mseReferenceOutput
,
debugStart
,
displayServer
,
cropWindow
,
pixelBounds
,
pixelMaterial
,
displacementEdgeScale
);
}
}
// namespace pbrt
src/pbrt/parsedscene.cpp
浏览文件 @
0dec8bb6
...
...
@@ -808,9 +808,8 @@ void ParsedScene::CreateMaterials(
std
::
map
<
std
::
string
,
Image
*>
normalMapCache
;
std
::
mutex
mutex
;
ParallelFor
(
0
,
normalMapFilenameVector
.
size
(),
[
&
](
int64_t
index
)
{
std
::
string
filename
=
normalMapFilenameVector
[
index
];
Allocator
alloc
=
threadAllocators
.
Get
();
std
::
string
filename
=
normalMapFilenameVector
[
index
];
ImageAndMetadata
immeta
=
Image
::
Read
(
filename
,
Allocator
(),
ColorEncoding
::
Linear
);
Image
&
image
=
immeta
.
image
;
...
...
@@ -829,9 +828,10 @@ void ParsedScene::CreateMaterials(
// Named materials
for
(
const
auto
&
nm
:
namedMaterials
)
{
Allocator
alloc
=
threadAllocators
.
Get
();
const
std
::
string
&
name
=
nm
.
first
;
const
SceneEntity
&
mtl
=
nm
.
second
;
Allocator
alloc
=
threadAllocators
.
Get
();
if
(
namedMaterialsOut
->
find
(
name
)
!=
namedMaterialsOut
->
end
())
{
ErrorExitDeferred
(
&
mtl
.
loc
,
"%s: trying to redefine named material."
,
name
);
continue
;
...
...
@@ -950,8 +950,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal<Allocator> &threadAllocato
std
::
mutex
mutex
;
ParallelFor
(
0
,
parallelFloatTextures
.
size
(),
[
&
](
int64_t
i
)
{
const
auto
&
tex
=
floatTextures
[
parallelFloatTextures
[
i
]];
Allocator
alloc
=
threadAllocators
.
Get
();
const
auto
&
tex
=
floatTextures
[
parallelFloatTextures
[
i
]];
pbrt
::
Transform
renderFromTexture
=
tex
.
second
.
renderFromObject
.
startTransform
;
// Pass nullptr for the textures, since they shouldn't be accessed
...
...
@@ -964,8 +964,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal<Allocator> &threadAllocato
});
ParallelFor
(
0
,
parallelSpectrumTextures
.
size
(),
[
&
](
int64_t
i
)
{
const
auto
&
tex
=
spectrumTextures
[
parallelSpectrumTextures
[
i
]];
Allocator
alloc
=
threadAllocators
.
Get
();
const
auto
&
tex
=
spectrumTextures
[
parallelSpectrumTextures
[
i
]];
pbrt
::
Transform
renderFromTexture
=
tex
.
second
.
renderFromObject
.
startTransform
;
// nullptr for the textures, as above.
...
...
@@ -990,8 +990,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal<Allocator> &threadAllocato
LOG_VERBOSE
(
"Loading serial textures"
);
// And do the rest serially
for
(
size_t
index
:
serialFloatTextures
)
{
const
auto
&
tex
=
floatTextures
[
index
];
Allocator
alloc
=
threadAllocators
.
Get
();
const
auto
&
tex
=
floatTextures
[
index
];
pbrt
::
Transform
renderFromTexture
=
tex
.
second
.
renderFromObject
.
startTransform
;
TextureParameterDictionary
texDict
(
&
tex
.
second
.
parameters
,
&
textures
);
...
...
@@ -1000,8 +1000,8 @@ NamedTextures ParsedScene::CreateTextures(ThreadLocal<Allocator> &threadAllocato
textures
.
floatTextures
[
tex
.
first
]
=
t
;
}
for
(
size_t
index
:
serialSpectrumTextures
)
{
const
auto
&
tex
=
spectrumTextures
[
index
];
Allocator
alloc
=
threadAllocators
.
Get
();
const
auto
&
tex
=
spectrumTextures
[
index
];
if
(
tex
.
second
.
renderFromObject
.
IsAnimated
())
Warning
(
&
tex
.
second
.
loc
,
"Animated world to texture transform not supported. "
...
...
src/pbrt/pbrt.cpp
浏览文件 @
0dec8bb6
...
...
@@ -61,11 +61,11 @@ void InitPBRT(const PBRTOptions &opt) {
CUDA_CHECK
(
cudaMemcpyToSymbol
(
OptionsGPU
,
Options
,
sizeof
(
OptionsGPU
)));
// Leak so things aren't freed
pstd
::
pmr
::
monotonic_buffer_resource
*
bufferResource
=
new
pstd
::
pmr
::
monotonic_buffer_resource
(
1024
*
1024
,
&
CUDATrackedMemoryResource
::
singleton
);
// Leak this so memory it allocates isn't freed
pstd
::
pmr
::
monotonic_buffer_resource
*
bufferResource
=
new
pstd
::
pmr
::
monotonic_buffer_resource
(
1024
*
1024
,
&
CUDATrackedMemoryResource
::
singleton
);
Allocator
alloc
(
bufferResource
);
ColorEncoding
::
Init
(
alloc
);
Spectra
::
Init
(
alloc
);
RGBToSpectrumTable
::
Init
(
alloc
);
...
...
src/pbrt/samplers.cpp
浏览文件 @
0dec8bb6
...
...
@@ -52,9 +52,7 @@ HaltonSampler::HaltonSampler(int samplesPerPixel, Point2i fullRes,
}
Sampler
HaltonSampler
::
Clone
(
Allocator
alloc
)
{
HaltonSampler
*
s
=
(
HaltonSampler
*
)
alloc
.
allocate_object
<
HaltonSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
HaltonSampler
>
(
*
this
);
}
std
::
string
HaltonSampler
::
ToString
()
const
{
...
...
@@ -95,9 +93,7 @@ HaltonSampler *HaltonSampler::Create(const ParameterDictionary ¶meters,
}
Sampler
SobolSampler
::
Clone
(
Allocator
alloc
)
{
SobolSampler
*
s
=
(
SobolSampler
*
)
alloc
.
allocate_object
<
SobolSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
SobolSampler
>
(
*
this
);
}
std
::
string
PaddedSobolSampler
::
ToString
()
const
{
...
...
@@ -107,9 +103,7 @@ std::string PaddedSobolSampler::ToString() const {
}
Sampler
PaddedSobolSampler
::
Clone
(
Allocator
alloc
)
{
PaddedSobolSampler
*
s
=
(
PaddedSobolSampler
*
)
alloc
.
allocate_object
<
PaddedSobolSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
PaddedSobolSampler
>
(
*
this
);
}
PaddedSobolSampler
*
PaddedSobolSampler
::
Create
(
const
ParameterDictionary
&
parameters
,
...
...
@@ -140,9 +134,7 @@ PaddedSobolSampler *PaddedSobolSampler::Create(const ParameterDictionary ¶me
// ZSobolSampler Method Definitions
Sampler
ZSobolSampler
::
Clone
(
Allocator
alloc
)
{
ZSobolSampler
*
s
=
(
ZSobolSampler
*
)
alloc
.
allocate_object
<
ZSobolSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
ZSobolSampler
>
(
*
this
);
}
std
::
string
ZSobolSampler
::
ToString
()
const
{
...
...
@@ -227,9 +219,7 @@ PMJ02BNSampler *PMJ02BNSampler::Create(const ParameterDictionary ¶meters,
}
Sampler
PMJ02BNSampler
::
Clone
(
Allocator
alloc
)
{
PMJ02BNSampler
*
s
=
(
PMJ02BNSampler
*
)
alloc
.
allocate_object
<
PMJ02BNSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
PMJ02BNSampler
>
(
*
this
);
}
std
::
string
PMJ02BNSampler
::
ToString
()
const
{
...
...
@@ -245,9 +235,7 @@ std::string IndependentSampler::ToString() const {
}
Sampler
IndependentSampler
::
Clone
(
Allocator
alloc
)
{
IndependentSampler
*
s
=
(
IndependentSampler
*
)
alloc
.
allocate_object
<
IndependentSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
IndependentSampler
>
(
*
this
);
}
IndependentSampler
*
IndependentSampler
::
Create
(
const
ParameterDictionary
&
parameters
,
...
...
@@ -304,9 +292,7 @@ std::string StratifiedSampler::ToString() const {
}
Sampler
StratifiedSampler
::
Clone
(
Allocator
alloc
)
{
StratifiedSampler
*
s
=
(
StratifiedSampler
*
)
alloc
.
allocate_object
<
StratifiedSampler
>
();
alloc
.
construct
(
s
,
*
this
);
return
s
;
return
alloc
.
new_object
<
StratifiedSampler
>
(
*
this
);
}
StratifiedSampler
*
StratifiedSampler
::
Create
(
const
ParameterDictionary
&
parameters
,
...
...
@@ -348,7 +334,7 @@ Point2f MLTSampler::GetPixel2D() {
}
Sampler
MLTSampler
::
Clone
(
Allocator
alloc
)
{
LOG_FATAL
(
"MLTSampler::Clone() mplemented"
);
LOG_FATAL
(
"MLTSampler::Clone()
is not i
mplemented"
);
return
{};
}
...
...
src/pbrt/textures.cpp
浏览文件 @
0dec8bb6
...
...
@@ -1292,8 +1292,10 @@ GPUSpectrumImageTexture *GPUSpectrumImageTexture::Create(
texDesc
.
maxAnisotropy
=
Clamp
(
maxAniso
,
1
,
16
);
texDesc
.
maxMipmapLevelClamp
=
nMIPMapLevels
-
1
;
texDesc
.
minMipmapLevelClamp
=
0
;
texDesc
.
mipmapFilterMode
=
(
filter
==
"trilinear"
||
filter
==
"ewa"
||
filter
==
"EWA"
)
?
cudaFilterModeLinear
:
cudaFilterModePoint
;
texDesc
.
mipmapFilterMode
=
(
filter
==
"trilinear"
||
filter
==
"ewa"
||
filter
==
"EWA"
)
?
cudaFilterModeLinear
:
cudaFilterModePoint
;
texDesc
.
borderColor
[
0
]
=
texDesc
.
borderColor
[
1
]
=
texDesc
.
borderColor
[
2
]
=
texDesc
.
borderColor
[
3
]
=
0.
f
;
texDesc
.
sRGB
=
1
;
...
...
@@ -1415,8 +1417,10 @@ GPUFloatImageTexture *GPUFloatImageTexture::Create(
texDesc
.
maxAnisotropy
=
Clamp
(
maxAniso
,
1
,
16
);
texDesc
.
maxMipmapLevelClamp
=
nMIPMapLevels
-
1
;
texDesc
.
minMipmapLevelClamp
=
0
;
texDesc
.
mipmapFilterMode
=
(
filter
==
"trilinear"
||
filter
==
"ewa"
||
filter
==
"EWA"
)
?
cudaFilterModeLinear
:
cudaFilterModePoint
;
texDesc
.
mipmapFilterMode
=
(
filter
==
"trilinear"
||
filter
==
"ewa"
||
filter
==
"EWA"
)
?
cudaFilterModeLinear
:
cudaFilterModePoint
;
texDesc
.
borderColor
[
0
]
=
texDesc
.
borderColor
[
1
]
=
texDesc
.
borderColor
[
2
]
=
texDesc
.
borderColor
[
3
]
=
0.
f
;
texDesc
.
sRGB
=
1
;
...
...
src/pbrt/util/buffercache.h
浏览文件 @
0dec8bb6
...
...
@@ -33,40 +33,36 @@ class BufferCache {
++
nBufferCacheLookups
;
// Return pointer to data if _buf_ contents is already in the cache
Buffer
lookupBuffer
(
buf
.
data
(),
buf
.
size
());
int
shardIndex
=
uint32_t
(
lookupBuffer
.
hash
)
>>
(
32
-
logShards
);
CHECK
(
shardIndex
>=
0
&&
shardIndex
<
nShards
);
DCHECK
(
shardIndex
>=
0
&&
shardIndex
<
nShards
);
mutex
[
shardIndex
].
lock_shared
();
if
(
auto
iter
=
cache
[
shardIndex
].
find
(
lookupBuffer
);
iter
!=
cache
[
shardIndex
].
end
())
{
DCHECK
(
std
::
memcmp
(
buf
.
data
(),
iter
->
ptr
,
buf
.
size
()
*
sizeof
(
T
))
==
0
);
if
(
auto
iter
=
cache
[
shardIndex
].
find
(
lookupBuffer
);
iter
!=
cache
[
shardIndex
].
end
())
{
const
T
*
ptr
=
iter
->
ptr
;
mutex
[
shardIndex
].
unlock_shared
();
DCHECK
(
std
::
memcmp
(
buf
.
data
(),
iter
->
ptr
,
buf
.
size
()
*
sizeof
(
T
))
==
0
);
++
nBufferCacheHits
;
redundantBufferBytes
+=
buf
.
size
()
*
sizeof
(
T
);
return
ptr
;
}
mutex
[
shardIndex
].
unlock_shared
();
// Add _buf_ contents to cache and return pointer to cached copy
mutex
[
shardIndex
].
unlock_shared
();
T
*
ptr
=
alloc
.
allocate_object
<
T
>
(
buf
.
size
());
std
::
copy
(
buf
.
begin
(),
buf
.
end
(),
ptr
);
bytesUsed
+=
buf
.
size
()
*
sizeof
(
T
);
mutex
[
shardIndex
].
lock
();
if
(
auto
iter
=
cache
[
shardIndex
].
find
(
lookupBuffer
);
iter
!=
cache
[
shardIndex
].
end
())
{
// Someone else got it in there in the meantime...
alloc
.
deallocate_object
(
ptr
,
buf
.
size
());
const
T
*
ptr
=
iter
->
ptr
;
// Handle the case of another thread adding the buffer first
if
(
auto
iter
=
cache
[
shardIndex
].
find
(
lookupBuffer
);
iter
!=
cache
[
shardIndex
].
end
())
{
const
T
*
cachePtr
=
iter
->
ptr
;
mutex
[
shardIndex
].
unlock
();
alloc
.
deallocate_object
(
ptr
,
buf
.
size
());
++
nBufferCacheHits
;
redundantBufferBytes
+=
buf
.
size
()
*
sizeof
(
T
);
return
p
tr
;
return
cacheP
tr
;
}
cache
[
shardIndex
].
insert
(
Buffer
(
ptr
,
buf
.
size
()));
mutex
[
shardIndex
].
unlock
();
return
ptr
;
...
...
@@ -88,8 +84,7 @@ class BufferCache {
}
const
T
*
ptr
=
nullptr
;
size_t
size
=
0
;
size_t
hash
;
size_t
size
=
0
,
hash
;
};
// BufferCache::BufferHasher Definition
...
...
src/pbrt/util/containers.h
浏览文件 @
0dec8bb6
...
...
@@ -838,14 +838,13 @@ class SampledGrid {
Vector3f
d
=
pSamples
-
(
Point3f
)
pi
;
// Return trilinearly interpolated voxel values
auto
d00
=
Lerp
(
d
.
x
,
Lookup
(
pi
),
Lookup
(
pi
+
Vector3i
(
1
,
0
,
0
)));
auto
d10
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
1
,
0
)),
Lookup
(
pi
+
Vector3i
(
1
,
1
,
0
)));
auto
d01
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
0
,
1
)),
Lookup
(
pi
+
Vector3i
(
1
,
0
,
1
)));
auto
d11
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
1
,
1
)),
Lookup
(
pi
+
Vector3i
(
1
,
1
,
1
)));
auto
d00
=
Lerp
(
d
.
x
,
Lookup
(
pi
),
Lookup
(
pi
+
Vector3i
(
1
,
0
,
0
)));
auto
d10
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
1
,
0
)),
Lookup
(
pi
+
Vector3i
(
1
,
1
,
0
)));
auto
d01
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
0
,
1
)),
Lookup
(
pi
+
Vector3i
(
1
,
0
,
1
)));
auto
d11
=
Lerp
(
d
.
x
,
Lookup
(
pi
+
Vector3i
(
0
,
1
,
1
)),
Lookup
(
pi
+
Vector3i
(
1
,
1
,
1
)));
return
Lerp
(
d
.
z
,
Lerp
(
d
.
y
,
d00
,
d10
),
Lerp
(
d
.
y
,
d01
,
d11
));
}
...
...
src/pbrt/util/image.cpp
浏览文件 @
0dec8bb6
...
...
@@ -197,7 +197,8 @@ pstd::vector<Image> Image::GeneratePyramid(Image image, WrapMode2D wrapMode,
}
bool
Image
::
HasAnyInfinitePixels
()
const
{
if
(
format
==
PixelFormat
::
U256
)
return
false
;
if
(
format
==
PixelFormat
::
U256
)
return
false
;
for
(
int
y
=
0
;
y
<
resolution
.
y
;
++
y
)
for
(
int
x
=
0
;
x
<
resolution
.
x
;
++
x
)
...
...
@@ -208,7 +209,8 @@ bool Image::HasAnyInfinitePixels() const {
}
bool
Image
::
HasAnyNaNPixels
()
const
{
if
(
format
==
PixelFormat
::
U256
)
return
false
;
if
(
format
==
PixelFormat
::
U256
)
return
false
;
for
(
int
y
=
0
;
y
<
resolution
.
y
;
++
y
)
for
(
int
x
=
0
;
x
<
resolution
.
x
;
++
x
)
...
...
@@ -1339,7 +1341,10 @@ Image Image::SelectChannels(const ImageChannelDesc &desc, Allocator alloc) const
dst
[
i
]
=
src
[
desc
.
offset
[
i
]];
}
break
;
default:
LOG_FATAL
(
"Unhandled PixelFormat"
);
}
return
image
;
}
...
...
src/pbrt/util/log.h
浏览文件 @
0dec8bb6
...
...
@@ -18,9 +18,8 @@ enum class LogLevel { Verbose, Error, Fatal, Invalid };
std
::
string
ToString
(
LogLevel
level
);
LogLevel
LogLevelFromString
(
const
std
::
string
&
s
);
void
InitLogging
(
LogLevel
level
,
std
::
string
logFile
,
bool
logUtilization
,
bool
useGPU
);
void
ShutdownLogging
();
void
InitLogging
(
LogLevel
level
,
std
::
string
logFile
,
bool
logUtilization
,
bool
useGPU
);
#ifdef PBRT_BUILD_GPU_RENDERER
...
...
src/pbrt/util/mesh.h
浏览文件 @
0dec8bb6
...
...
@@ -27,8 +27,7 @@ class TriangleMesh {
TriangleMesh
(
const
Transform
&
renderFromObject
,
bool
reverseOrientation
,
std
::
vector
<
int
>
vertexIndices
,
std
::
vector
<
Point3f
>
p
,
std
::
vector
<
Vector3f
>
S
,
std
::
vector
<
Normal3f
>
N
,
std
::
vector
<
Point2f
>
uv
,
std
::
vector
<
int
>
faceIndices
,
Allocator
alloc
);
std
::
vector
<
Point2f
>
uv
,
std
::
vector
<
int
>
faceIndices
,
Allocator
alloc
);
std
::
string
ToString
()
const
;
...
...
src/pbrt/util/parallel.h
浏览文件 @
0dec8bb6
...
...
@@ -23,13 +23,12 @@
namespace
pbrt
{
// ThreadLocal Definition
template
<
typename
T
,
int
maxThreads
=
256
>
class
ThreadLocal
{
public:
ThreadLocal
()
:
hashTable
(
maxThreads
),
create
([]()
{
return
T
();
})
{}
ThreadLocal
(
std
::
function
<
T
(
void
)
>
&&
c
)
:
hashTable
(
maxThreads
),
create
(
c
)
{}
public:
ThreadLocal
()
:
hashTable
(
maxThreads
),
create
([]()
{
return
T
();
})
{}
ThreadLocal
(
std
::
function
<
T
(
void
)
>
&&
c
)
:
hashTable
(
maxThreads
),
create
(
c
)
{}
T
&
Get
()
{
std
::
thread
::
id
tid
=
std
::
this_thread
::
get_id
();
...
...
@@ -86,7 +85,7 @@ public:
mutex
.
unlock
();
}
private:
private:
struct
Entry
{
std
::
thread
::
id
tid
;
T
value
;
...
...
src/pbrt/wavefront/integrator.cpp
浏览文件 @
0dec8bb6
...
...
@@ -75,12 +75,12 @@ static void updateMaterialNeeds(
(
*
haveUniversalEvalMaterial
)[
m
.
Tag
()]
=
true
;
}
WavefrontPathIntegrator
::
WavefrontPathIntegrator
(
pstd
::
pmr
::
memory_resource
*
memoryResource
,
ParsedScene
&
scene
)
WavefrontPathIntegrator
::
WavefrontPathIntegrator
(
pstd
::
pmr
::
memory_resource
*
memoryResource
,
ParsedScene
&
scene
)
:
memoryResource
(
memoryResource
)
{
ThreadLocal
<
Allocator
>
threadAllocators
([
memoryResource
]()
{
pstd
::
pmr
::
monotonic_buffer_resource
*
resource
=
new
pstd
::
pmr
::
monotonic_buffer_resource
(
1024
*
1024
,
memoryResource
);
new
pstd
::
pmr
::
monotonic_buffer_resource
(
1024
*
1024
,
memoryResource
);
return
Allocator
(
resource
);
});
...
...
@@ -149,6 +149,7 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem
LOG_VERBOSE
(
"Starting to create lights"
);
pstd
::
vector
<
Light
>
allLights
;
infiniteLights
=
alloc
.
new_object
<
pstd
::
vector
<
Light
>>
(
alloc
);
for
(
const
auto
&
light
:
scene
.
lights
)
{
Medium
outsideMedium
=
findMedium
(
light
.
medium
,
&
light
.
loc
);
...
...
@@ -171,11 +172,10 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem
std
::
map
<
int
,
pstd
::
vector
<
Light
>
*>
shapeIndexToAreaLights
;
std
::
set
<
std
::
string
>
namedMaterialsThatAreInterfaces
;
for
(
auto
iter
=
scene
.
namedMaterials
.
begin
();
iter
!=
scene
.
namedMaterials
.
end
();
++
iter
)
{
for
(
auto
iter
=
scene
.
namedMaterials
.
begin
();
iter
!=
scene
.
namedMaterials
.
end
();
++
iter
)
{
std
::
string
materialName
=
iter
->
second
.
parameters
.
GetOneString
(
"type"
,
""
);
if
(
materialName
==
"interface"
||
materialName
==
"none"
||
materialName
.
empty
())
if
(
materialName
==
"interface"
||
materialName
==
"none"
||
materialName
.
empty
())
namedMaterialsThatAreInterfaces
.
insert
(
iter
->
first
);
}
...
...
@@ -263,14 +263,14 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem
CUDATrackedMemoryResource
*
mr
=
dynamic_cast
<
CUDATrackedMemoryResource
*>
(
memoryResource
);
CHECK
(
mr
);
aggregate
=
new
OptiXAggregate
(
scene
,
mr
,
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
aggregate
=
new
OptiXAggregate
(
scene
,
mr
,
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
#else
LOG_FATAL
(
"Options->useGPU was set without PBRT_BUILD_GPU_RENDERER enabled"
);
#endif
}
else
aggregate
=
new
CPUAggregate
(
scene
,
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
aggregate
=
new
CPUAggregate
(
scene
,
textures
,
shapeIndexToAreaLights
,
media
,
namedMaterials
,
materials
);
// Preprocess the light sources
for
(
Light
light
:
allLights
)
...
...
@@ -310,8 +310,8 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(pstd::pmr::memory_resource *mem
if
(
!
Options
->
mseReferenceOutput
.
empty
())
Warning
(
"The wavefront integrator does not support --mse-reference-out."
);
///////////////////////////////////////////////////////////////////////////
// Allocate storage for all of the queues/buffers...
///////////////////////////////////////////////////////////////////////////
// Allocate storage for all of the queues/buffers...
#ifdef PBRT_BUILD_GPU_RENDERER
CUDATrackedMemoryResource
*
mr
=
...
...
src/pbrt/wavefront/integrator.h
浏览文件 @
0dec8bb6
...
...
@@ -118,7 +118,6 @@ class WavefrontPathIntegrator {
}
// WavefrontPathIntegrator Member Variables
pstd
::
pmr
::
memory_resource
*
memoryResource
;
bool
initializeVisibleSurface
;
bool
haveSubsurface
;
bool
haveMedia
;
...
...
@@ -136,6 +135,8 @@ class WavefrontPathIntegrator {
};
Stats
*
stats
;
pstd
::
pmr
::
memory_resource
*
memoryResource
;
Filter
filter
;
Film
film
;
Sampler
sampler
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录