Skip to content

Commit

Permalink
Change RendererServices::get_texture_handle back to ustring (#1726)
Browse files Browse the repository at this point in the history
We were overzealous in switching everything to ustringhash.  The
filename argument to get_texture_handle should allow taking a ustring.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Sep 12, 2023
1 parent fdc0579 commit e235661
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

cmake_minimum_required (VERSION 3.12)

set (OSL_VERSION "1.13.4.0")
set (OSL_VERSION "1.13.5.0")
set (OSL_VERSION_OVERRIDE "" CACHE STRING
"Version override (use with caution)!")
mark_as_advanced (OSL_VERSION_OVERRIDE)
Expand Down
3 changes: 3 additions & 0 deletions src/include/OSL/rendererservices.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ class OSLEXECPUBLIC RendererServices {
/// null, may be used in renderer-specific ways to specialize a handle
/// based on certain texture option choices.
virtual TextureHandle*
get_texture_handle(ustring filename, ShadingContext* context,
const TextureOpt* options = nullptr);
virtual TextureHandle*
get_texture_handle(ustringhash filename, ShadingContext* context,
const TextureOpt* options = nullptr);

Expand Down
17 changes: 13 additions & 4 deletions src/liboslexec/rendservices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,31 @@ RendererServices::filefmt(OSL::ShaderGlobals* sg,


RendererServices::TextureHandle*
RendererServices::get_texture_handle(ustringhash filename,
ShadingContext* context,
RendererServices::get_texture_handle(ustring filename, ShadingContext* context,
const TextureOpt* options)
{
#ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
return texturesys()->get_texture_handle(ustring_from(filename),
return texturesys()->get_texture_handle(filename,
context->texture_thread_info(),
options);
#else
return texturesys()->get_texture_handle(ustring_from(filename),
return texturesys()->get_texture_handle(filename,
context->texture_thread_info());
#endif
}



RendererServices::TextureHandle*
RendererServices::get_texture_handle(ustringhash filename,
ShadingContext* context,
const TextureOpt* options)
{
return get_texture_handle(ustring_from(filename), context, options);
}



bool
RendererServices::good(TextureHandle* texture_handle)
{
Expand Down
12 changes: 7 additions & 5 deletions src/testrender/optixraytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,17 +976,17 @@ OptixRaytracer::good(TextureHandle* handle OSL_MAYBE_UNUSED)
/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
RendererServices::TextureHandle*
OptixRaytracer::get_texture_handle(ustringhash filename,
OptixRaytracer::get_texture_handle(ustring filename,
ShadingContext* /*shading_context*/,
const TextureOpt* options)
{
auto itr = m_samplers.find(filename);
if (itr == m_samplers.end()) {
// Open image
OIIO::ImageBuf image;
if (!image.init_spec(ustring_from(filename), 0, 0)) {
errhandler().errorfmt("Could not load: {} (hash {})",
ustring_from(filename), filename);
if (!image.init_spec(filename, 0, 0)) {
errhandler().errorfmt("Could not load: {} (hash {})", filename,
filename);
return (TextureHandle*)nullptr;
}

Expand Down Expand Up @@ -1033,7 +1033,9 @@ OptixRaytracer::get_texture_handle(ustringhash filename,
cudaTextureObject_t cuda_tex = 0;
CUDA_CHECK(
cudaCreateTextureObject(&cuda_tex, &res_desc, &tex_desc, nullptr));
itr = m_samplers.emplace(std::move(filename), std::move(cuda_tex)).first;
itr = m_samplers
.emplace(std::move(filename.hash()), std::move(cuda_tex))
.first;
}
return reinterpret_cast<RendererServices::TextureHandle*>(itr->second);
}
Expand Down
2 changes: 1 addition & 1 deletion src/testrender/optixraytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OptixRaytracer final : public SimpleRaytracer {

/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
TextureHandle* get_texture_handle(ustringhash filename,
TextureHandle* get_texture_handle(ustring filename,
ShadingContext* shading_context,
const TextureOpt* options) override;

Expand Down
12 changes: 7 additions & 5 deletions src/testshade/optixgridrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,17 +808,17 @@ OptixGridRenderer::good(TextureHandle* handle OSL_MAYBE_UNUSED)
/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
RendererServices::TextureHandle*
OptixGridRenderer::get_texture_handle(ustringhash filename,
OptixGridRenderer::get_texture_handle(ustring filename,
ShadingContext* /*shading_context*/,
const TextureOpt* /*options*/)
{
auto itr = m_samplers.find(filename);
if (itr == m_samplers.end()) {
// Open image
OIIO::ImageBuf image;
if (!image.init_spec(ustring_from(filename), 0, 0)) {
errhandler().errorfmt("Could not load: {} (hash {})",
ustring_from(filename), filename);
if (!image.init_spec(filename, 0, 0)) {
errhandler().errorfmt("Could not load: {} (hash {})", filename,
filename);
return (TextureHandle*)nullptr;
}

Expand Down Expand Up @@ -868,7 +868,9 @@ OptixGridRenderer::get_texture_handle(ustringhash filename,
cudaTextureObject_t cuda_tex = 0;
CUDA_CHECK(
cudaCreateTextureObject(&cuda_tex, &res_desc, &tex_desc, nullptr));
itr = m_samplers.emplace(std::move(filename), std::move(cuda_tex)).first;
itr = m_samplers
.emplace(std::move(filename.hash()), std::move(cuda_tex))
.first;
}
return reinterpret_cast<RendererServices::TextureHandle*>(itr->second);
}
Expand Down
2 changes: 1 addition & 1 deletion src/testshade/optixgridrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class OptixGridRenderer final : public SimpleRenderer {

/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
TextureHandle* get_texture_handle(ustringhash filename,
TextureHandle* get_texture_handle(ustring filename,
ShadingContext* shading_context,
const TextureOpt* options) override;

Expand Down
4 changes: 2 additions & 2 deletions testsuite/example-cuda/cuda_grid_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ CudaGridRenderer::good(TextureHandle* handle)
/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
RendererServices::TextureHandle*
CudaGridRenderer::get_texture_handle(OSL::ustringhash filename,
CudaGridRenderer::get_texture_handle(OSL::ustring filename,
ShadingContext* shading_context,
const TextureOpt* options)
{
Expand Down Expand Up @@ -139,7 +139,7 @@ CudaGridRenderer::get_texture_handle(OSL::ustringhash filename,
cudaTextureObject_t cuda_tex = 0;
CUDA_CHECK(
cudaCreateTextureObject(&cuda_tex, &res_desc, &tex_desc, nullptr));
itr = _samplers.emplace(filename, std::move(cuda_tex)).first;
itr = _samplers.emplace(filename.hash(), std::move(cuda_tex)).first;
}
return reinterpret_cast<RendererServices::TextureHandle*>(itr->second);
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/example-cuda/cuda_grid_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CudaGridRenderer final : public OSL::RendererServices {

/// Given the name of a texture, return an opaque handle that can be
/// used with texture calls to avoid the name lookups.
virtual TextureHandle* get_texture_handle(ustringhash filename,
virtual TextureHandle* get_texture_handle(ustring filename,
ShadingContext* shading_context,
const TextureOpt* options);

Expand Down

0 comments on commit e235661

Please sign in to comment.