Skip to content

Commit b374fb5

Browse files
committed
refactor: de-virtualize IC and TS
Background: The ImageCache and TextureSystem had historically been implemented as pure virtual abstract base classe defining an interface, then a hidden concrete subclass. The flexibility this was intended to provide was never really used; instead the imagined main client for the flexibility, OSL, has a different mechanism for customizing the texture system (via their RendererServices class). Meanwhile, this has made the interfaces to IC and TS impossible to change without breaking the ABI. So this PR does the following: * ImageCache and TextureSytem are full de-virtualized, and are now concrete classes, no hidden subclassing, no virtual methods. As such, removing or changing existing methods will be an ABI break, but adding new methods is not. * Each use a PIMPL idiom, where all the data amd internal methods are hidden from the public enterface and do not affect the ABI. * Roughly speaking, we added the PIMPL pointers and made the ImageCacheImpl/TextureSystemImpl -- what used to be the hidden concrete subclasses -- into the hidden PIMPL classes. * Moved a lot of classes that used to be in a "pvt" namespace into the main namespace. If they are opaque types not exposed in public headers or as symbols exported from the library, it doesn't matter, so this just removes some arbitrary clutter. * Had to rearrange some of the recently added heapsize/footprint code, moved some inline functions in the headers into methods of the classes, defined in the cpp files. This itself is a huge ABI change, so will only be merged into master, to become part of the 3.0 release. This is not an API change, though! This is all about the internals, and should not require any client software to change a single line of code. I may do further simplification or refactoring of this code in the future, but that will all be smaller and have no further API/ABI changes that break compatibility. Although the structure of the class hierarchy has changed around, none of the logic about how IC and TS actually *work* has changed, so there should be no change in observable behavior.
1 parent 7faf944 commit b374fb5

File tree

11 files changed

+1534
-732
lines changed

11 files changed

+1534
-732
lines changed

src/include/OpenImageIO/imagebuf.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ OIIO_NAMESPACE_BEGIN
2525
class ImageBuf;
2626
class ImageBufImpl; // Opaque type for the unique_ptr.
2727
class ImageCache;
28-
29-
namespace pvt {
3028
class ImageCacheTile;
31-
}; // namespace pvt
3229

3330

3431

@@ -1369,7 +1366,7 @@ class OIIO_API ImageBuf {
13691366
int m_rng_xbegin, m_rng_xend, m_rng_ybegin, m_rng_yend, m_rng_zbegin,
13701367
m_rng_zend;
13711368
int m_x, m_y, m_z;
1372-
pvt::ImageCacheTile* m_tile = nullptr;
1369+
ImageCacheTile* m_tile = nullptr;
13731370
int m_tilexbegin, m_tileybegin, m_tilezbegin;
13741371
int m_tilexend;
13751372
int m_nchannels;
@@ -1638,7 +1635,7 @@ class OIIO_API ImageBuf {
16381635
// tile for the given pixel, and return the ptr to the actual pixel
16391636
// within the tile. If any read errors occur, set haderror=true (but
16401637
// if there are no errors, do not modify haderror).
1641-
const void* retile(int x, int y, int z, pvt::ImageCacheTile*& tile,
1638+
const void* retile(int x, int y, int z, ImageCacheTile*& tile,
16421639
int& tilexbegin, int& tileybegin, int& tilezbegin,
16431640
int& tilexend, bool& haderr, bool exists,
16441641
WrapMode wrap) const;

src/include/OpenImageIO/imagecache.h

Lines changed: 145 additions & 119 deletions
Large diffs are not rendered by default.

src/include/OpenImageIO/texture.h

Lines changed: 176 additions & 190 deletions
Large diffs are not rendered by default.

src/libtexture/environment.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,54 @@ OIIO_NAMESPACE_BEGIN
203203
using namespace pvt;
204204
using namespace simd;
205205

206+
207+
bool
208+
TextureSystem::environment(ustring filename, TextureOpt& options, V3fParam R,
209+
V3fParam dRdx, V3fParam dRdy, int nchannels,
210+
float* result, float* dresultds, float* dresultdt)
211+
{
212+
return m_impl->environment(filename, options, R, dRdx, dRdy, nchannels,
213+
result, dresultds, dresultdt);
214+
}
215+
216+
217+
bool
218+
TextureSystem::environment(TextureHandle* texture_handle,
219+
Perthread* thread_info, TextureOpt& options,
220+
V3fParam R, V3fParam dRdx, V3fParam dRdy,
221+
int nchannels, float* result, float* dresultds,
222+
float* dresultdt)
223+
{
224+
return m_impl->environment(texture_handle, thread_info, options, R, dRdx,
225+
dRdy, nchannels, result, dresultds, dresultdt);
226+
}
227+
228+
229+
bool
230+
TextureSystem::environment(ustring filename, TextureOptBatch& options,
231+
Tex::RunMask mask, const float* R, const float* dRdx,
232+
const float* dRdy, int nchannels, float* result,
233+
float* dresultds, float* dresultdt)
234+
{
235+
return m_impl->environment(filename, options, mask, R, dRdx, dRdy,
236+
nchannels, result, dresultds, dresultdt);
237+
}
238+
239+
240+
bool
241+
TextureSystem::environment(TextureHandle* texture_handle,
242+
Perthread* thread_info, TextureOptBatch& options,
243+
Tex::RunMask mask, const float* R, const float* dRdx,
244+
const float* dRdy, int nchannels, float* result,
245+
float* dresultds, float* dresultdt)
246+
{
247+
return m_impl->environment(texture_handle, thread_info, options, mask, R,
248+
dRdx, dRdy, nchannels, result, dresultds,
249+
dresultdt);
250+
}
251+
252+
253+
206254
namespace pvt {
207255

208256

@@ -225,6 +273,8 @@ vector_to_latlong(const Imath::V3f& R, bool y_is_up, float& s, float& t)
225273
t = 0.0f;
226274
}
227275

276+
} // namespace pvt
277+
228278

229279

230280
bool
@@ -594,6 +644,4 @@ TextureSystemImpl::environment(ustring filename, TextureOptBatch& options,
594644
}
595645

596646

597-
} // end namespace pvt
598-
599647
OIIO_NAMESPACE_END

0 commit comments

Comments
 (0)