Skip to content

Commit 5ee978d

Browse files
authored
build(deps): Adjust to OIIO change to IC/TS API (#1848)
On the OIIO side, there's a PR in review that changes the ImageCache and TextureSystem APIs to return shared_ptr instead of raw. (AcademySoftwareFoundation/OpenImageIO#4377) This is destined for the upcoming OIIO 3.0 release. This patch on the OSL side ensures that we build cleanly against both OIIO 2.x and 3.0. Signed-off-by: Larry Gritz <[email protected]>
1 parent 28b71e7 commit 5ee978d

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

src/liboslexec/oslexec_pvt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ class ShadingSystemImpl {
842842
void setup_op_descriptors();
843843

844844
RendererServices* m_renderer; ///< Renderer services
845-
TextureSystem* m_texturesys; ///< Texture system
845+
std::shared_ptr<TextureSystem> m_texturesys_sp;
846+
TextureSystem* m_texturesys; ///< Texture system
846847

847848
ErrorHandler* m_err; ///< Error handler
848849
mutable std::list<std::string> m_errseen, m_warnseen;

src/liboslexec/rendservices.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ using namespace OSL::pvt;
1919
OSL_NAMESPACE_ENTER
2020

2121

22+
#ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED
23+
namespace {
24+
std::mutex shared_texturesys_mutex;
25+
std::shared_ptr<TextureSystem> shared_texturesys;
26+
} // namespace
27+
#endif
28+
29+
2230

2331
RendererServices::RendererServices(TextureSystem* texsys) : m_texturesys(texsys)
2432
{
@@ -31,7 +39,17 @@ RendererServices::RendererServices(TextureSystem* texsys) : m_texturesys(texsys)
3139
OSL_ASSERT(
3240
0 && "RendererServices was not passed a working TextureSystem*");
3341
#else
42+
# ifdef OIIO_TEXTURESYSTEM_CREATE_SHARED
43+
{
44+
std::lock_guard<std::mutex> lock(shared_texturesys_mutex);
45+
if (!shared_texturesys) {
46+
shared_texturesys = TextureSystem::create(true /* shared */);
47+
}
48+
m_texturesys = shared_texturesys.get();
49+
}
50+
# else
3451
m_texturesys = TextureSystem::create(true /* shared */);
52+
# endif
3553
// Make some good guesses about default options
3654
m_texturesys->attribute("automip", 1);
3755
m_texturesys->attribute("autotile", 64);

src/liboslexec/shadingsys.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,12 @@ ShadingSystemImpl::ShadingSystemImpl(RendererServices* renderer,
12011201
OSL_ASSERT(0
12021202
&& "ShadingSystem was not passed a working TextureSystem*");
12031203
#else
1204+
# if OIIO_TEXTURESYSTEM_CREATE_SHARED
1205+
m_texturesys_sp = TextureSystem::create(true /* shared */);
1206+
m_texturesys = m_texturesys_sp.get();
1207+
# else
12041208
m_texturesys = TextureSystem::create(true /* shared */);
1209+
# endif
12051210
// Make some good guesses about default options
12061211
m_texturesys->attribute("automip", 1);
12071212
m_texturesys->attribute("autotile", 64);

src/osl.imageio/oslinput.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,22 @@ static OIIO::mutex shading_mutex;
218218
static ShadingSystem* shadingsys = NULL;
219219
static OIIO_RendererServices* renderer = NULL;
220220
static ErrorRecorder errhandler;
221-
221+
static std::shared_ptr<TextureSystem> shared_texsys;
222222

223223

224224
static void
225225
setup_shadingsys()
226226
{
227227
OIIO::lock_guard lock(shading_mutex);
228228
if (!shadingsys) {
229-
renderer = new OIIO_RendererServices(TextureSystem::create(true));
229+
#if OIIO_TEXTURESYSTEM_CREATE_SHARED
230+
if (!shared_texsys)
231+
shared_texsys = TextureSystem::create(true);
232+
auto ts = shared_texsys.get();
233+
#else
234+
auto ts = TextureSystem::create(true);
235+
#endif
236+
renderer = new OIIO_RendererServices(ts);
230237
shadingsys = new ShadingSystem(renderer, NULL, &errhandler);
231238
}
232239
}

src/testshade/testshade.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ static char* userdata_base_ptr = nullptr;
129129
static char* output_base_ptr = nullptr;
130130
static bool use_rs_bitcode
131131
= false; // use free function bitcode version of renderer services
132-
133132
static int jbufferMB = 16;
134133

135134
// Testshade thread tracking and assignment.
@@ -675,8 +674,12 @@ print_info()
675674
else
676675
#endif
677676
rend = new SimpleRenderer;
678-
TextureSystem* texturesys = TextureSystem::create();
677+
auto texturesys = TextureSystem::create();
678+
#if OIIO_TEXTURESYSTEM_CREATE_SHARED
679+
shadingsys = new ShadingSystem(rend, texturesys.get(), &errhandler);
680+
#else
679681
shadingsys = new ShadingSystem(rend, texturesys, &errhandler);
682+
#endif
680683
rend->init_shadingsys(shadingsys);
681684
set_shadingsys_options();
682685

@@ -1963,7 +1966,12 @@ test_shade(int argc, const char* argv[])
19631966
// Request a TextureSystem (by default it will be the global shared
19641967
// one). This isn't strictly necessary, if you pass nullptr to
19651968
// ShadingSystem ctr, it will ask for the shared one internally.
1969+
#if OIIO_TEXTURESYSTEM_CREATE_SHARED
1970+
std::shared_ptr<TextureSystem> texturesys_owned = TextureSystem::create();
1971+
TextureSystem* texturesys = texturesys_owned.get();
1972+
#else
19661973
TextureSystem* texturesys = TextureSystem::create();
1974+
#endif
19671975

19681976
// Create a new shading system. We pass it the RendererServices
19691977
// object that services callbacks from the shading system, the
@@ -2327,8 +2335,8 @@ test_shade(int argc, const char* argv[])
23272335
std::cout << "ERRORS left in TextureSystem:\n" << err << "\n";
23282336
retcode = EXIT_FAILURE;
23292337
}
2330-
OIIO::ImageCache* ic = texturesys->imagecache();
2331-
err = ic ? ic->geterror() : std::string();
2338+
auto ic = texturesys->imagecache();
2339+
err = ic ? ic->geterror() : std::string();
23322340
if (!err.empty()) {
23332341
std::cout << "ERRORS left in ImageCache:\n" << err << "\n";
23342342
retcode = EXIT_FAILURE;

0 commit comments

Comments
 (0)