提交 ba5c75d8 编写于 作者: M Matt Pharr

Bug fix: allocate ColorEncodings using an allocator

In particular, this ensures they are in GPU memory when GPU rendering us being used.
上级 1eea91e3
...@@ -59,6 +59,7 @@ void InitPBRT(const PBRTOptions &opt) { ...@@ -59,6 +59,7 @@ void InitPBRT(const PBRTOptions &opt) {
CUDA_CHECK(cudaMemcpyToSymbol(OptionsGPU, Options, sizeof(OptionsGPU))); CUDA_CHECK(cudaMemcpyToSymbol(OptionsGPU, Options, sizeof(OptionsGPU)));
ColorEncodingHandle::Init(gpuMemoryAllocator);
Spectra::Init(gpuMemoryAllocator); Spectra::Init(gpuMemoryAllocator);
RGBToSpectrumTable::Init(gpuMemoryAllocator); RGBToSpectrumTable::Init(gpuMemoryAllocator);
...@@ -70,6 +71,7 @@ void InitPBRT(const PBRTOptions &opt) { ...@@ -70,6 +71,7 @@ void InitPBRT(const PBRTOptions &opt) {
LOG_FATAL("Options::useGPU set with non-GPU build"); LOG_FATAL("Options::useGPU set with non-GPU build");
#endif #endif
} else { } else {
ColorEncodingHandle::Init(Allocator{});
// Before RGBColorSpace::Init! // Before RGBColorSpace::Init!
Spectra::Init(Allocator{}); Spectra::Init(Allocator{});
RGBToSpectrumTable::Init(Allocator{}); RGBToSpectrumTable::Init(Allocator{});
......
...@@ -409,7 +409,7 @@ FloatImageTexture *FloatImageTexture::Create(const Transform &renderFromTexture, ...@@ -409,7 +409,7 @@ FloatImageTexture *FloatImageTexture::Create(const Transform &renderFromTexture,
const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : "linear"; const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : "linear";
std::string encodingString = parameters.GetOneString("encoding", defaultEncoding); std::string encodingString = parameters.GetOneString("encoding", defaultEncoding);
ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString); ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString, alloc);
return alloc.new_object<FloatImageTexture>(map, filename, filterOptions, *wrapMode, return alloc.new_object<FloatImageTexture>(map, filename, filterOptions, *wrapMode,
scale, encoding, alloc); scale, encoding, alloc);
...@@ -442,7 +442,7 @@ SpectrumImageTexture *SpectrumImageTexture::Create( ...@@ -442,7 +442,7 @@ SpectrumImageTexture *SpectrumImageTexture::Create(
const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : "linear"; const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : "linear";
std::string encodingString = parameters.GetOneString("encoding", defaultEncoding); std::string encodingString = parameters.GetOneString("encoding", defaultEncoding);
ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString); ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString, alloc);
return alloc.new_object<SpectrumImageTexture>(map, filename, filterOptions, *wrapMode, return alloc.new_object<SpectrumImageTexture>(map, filename, filterOptions, *wrapMode,
scale, encoding, spectrumType, alloc); scale, encoding, spectrumType, alloc);
...@@ -668,7 +668,7 @@ FloatPtexTexture *FloatPtexTexture::Create(const Transform &renderFromTexture, ...@@ -668,7 +668,7 @@ FloatPtexTexture *FloatPtexTexture::Create(const Transform &renderFromTexture,
const FileLoc *loc, Allocator alloc) { const FileLoc *loc, Allocator alloc) {
std::string filename = ResolveFilename(parameters.GetOneString("filename", "")); std::string filename = ResolveFilename(parameters.GetOneString("filename", ""));
std::string encodingString = parameters.GetOneString("encoding", "gamma 2.2"); std::string encodingString = parameters.GetOneString("encoding", "gamma 2.2");
ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString); ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString, alloc);
return alloc.new_object<FloatPtexTexture>(filename, encoding); return alloc.new_object<FloatPtexTexture>(filename, encoding);
} }
...@@ -677,7 +677,7 @@ SpectrumPtexTexture *SpectrumPtexTexture::Create( ...@@ -677,7 +677,7 @@ SpectrumPtexTexture *SpectrumPtexTexture::Create(
SpectrumType spectrumType, const FileLoc *loc, Allocator alloc) { SpectrumType spectrumType, const FileLoc *loc, Allocator alloc) {
std::string filename = ResolveFilename(parameters.GetOneString("filename", "")); std::string filename = ResolveFilename(parameters.GetOneString("filename", ""));
std::string encodingString = parameters.GetOneString("encoding", "gamma 2.2"); std::string encodingString = parameters.GetOneString("encoding", "gamma 2.2");
ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString); ColorEncodingHandle encoding = ColorEncodingHandle::Get(encodingString, alloc);
return alloc.new_object<SpectrumPtexTexture>(filename, encoding, spectrumType); return alloc.new_object<SpectrumPtexTexture>(filename, encoding, spectrumType);
} }
...@@ -866,7 +866,7 @@ GPUSpectrumImageTexture *GPUSpectrumImageTexture::Create( ...@@ -866,7 +866,7 @@ GPUSpectrumImageTexture *GPUSpectrumImageTexture::Create(
const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" :
"linear"; std::string encodingString = parameters.GetOneString("encoding", "linear"; std::string encodingString = parameters.GetOneString("encoding",
defaultEncoding); const ColorEncoding *encoding = defaultEncoding); const ColorEncoding *encoding =
ColorEncodingHandle::Get(encodingString); ColorEncodingHandle::Get(encodingString, alloc);
*/ */
std::string filename = ResolveFilename(parameters.GetOneString("filename", "")); std::string filename = ResolveFilename(parameters.GetOneString("filename", ""));
...@@ -1061,7 +1061,7 @@ GPUFloatImageTexture *GPUFloatImageTexture::Create( ...@@ -1061,7 +1061,7 @@ GPUFloatImageTexture *GPUFloatImageTexture::Create(
const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" : const char *defaultEncoding = HasExtension(filename, "png") ? "sRGB" :
"linear"; std::string encodingString = parameters.GetOneString("encoding", "linear"; std::string encodingString = parameters.GetOneString("encoding",
defaultEncoding); const ColorEncoding *encoding = defaultEncoding); const ColorEncoding *encoding =
ColorEncodingHandle::Get(encodingString); ColorEncodingHandle::Get(encodingString, alloc);
*/ */
std::string filename = ResolveFilename(parameters.GetOneString("filename", "")); std::string filename = ResolveFilename(parameters.GetOneString("filename", ""));
......
...@@ -226,6 +226,11 @@ Float sRGBColorEncoding::ToFloatLinear(Float v) const { ...@@ -226,6 +226,11 @@ Float sRGBColorEncoding::ToFloatLinear(Float v) const {
return SRGBToLinear(v); return SRGBToLinear(v);
} }
void ColorEncodingHandle::Init(Allocator alloc) {
Linear = alloc.new_object<LinearColorEncoding>();
sRGB = alloc.new_object<sRGBColorEncoding>();
}
std::string ColorEncodingHandle::ToString() const { std::string ColorEncodingHandle::ToString() const {
if (!ptr()) if (!ptr())
return "(nullptr)"; return "(nullptr)";
...@@ -234,10 +239,11 @@ std::string ColorEncodingHandle::ToString() const { ...@@ -234,10 +239,11 @@ std::string ColorEncodingHandle::ToString() const {
return DispatchCPU(ts); return DispatchCPU(ts);
} }
const ColorEncodingHandle ColorEncodingHandle::Linear = new LinearColorEncoding; ColorEncodingHandle ColorEncodingHandle::Linear;
const ColorEncodingHandle ColorEncodingHandle::sRGB = new sRGBColorEncoding; ColorEncodingHandle ColorEncodingHandle::sRGB;
const ColorEncodingHandle ColorEncodingHandle::Get(const std::string &name) { const ColorEncodingHandle ColorEncodingHandle::Get(const std::string &name,
Allocator alloc) {
if (name == "linear") if (name == "linear")
return Linear; return Linear;
else if (name == "sRGB") else if (name == "sRGB")
...@@ -256,7 +262,7 @@ const ColorEncodingHandle ColorEncodingHandle::Get(const std::string &name) { ...@@ -256,7 +262,7 @@ const ColorEncodingHandle ColorEncodingHandle::Get(const std::string &name) {
if (iter != cache.end()) if (iter != cache.end())
return iter->second; return iter->second;
ColorEncodingHandle enc = new GammaColorEncoding(gamma); ColorEncodingHandle enc = alloc.new_object<GammaColorEncoding>(gamma);
cache[gamma] = enc; cache[gamma] = enc;
LOG_VERBOSE("Added ColorEncoding %s for gamma %f -> %s", name, gamma, enc); LOG_VERBOSE("Added ColorEncoding %s for gamma %f -> %s", name, gamma, enc);
return enc; return enc;
......
...@@ -409,10 +409,12 @@ class ColorEncodingHandle ...@@ -409,10 +409,12 @@ class ColorEncodingHandle
std::string ToString() const; std::string ToString() const;
static const ColorEncodingHandle Get(const std::string &name); static const ColorEncodingHandle Get(const std::string &name, Allocator alloc);
static const ColorEncodingHandle Linear; static ColorEncodingHandle Linear;
static const ColorEncodingHandle sRGB; static ColorEncodingHandle sRGB;
static void Init(Allocator alloc);
}; };
class LinearColorEncoding { class LinearColorEncoding {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册