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