Skip to content

Commit 92e488a

Browse files
authored
Testing; better tests of environment mapping, minor fixes (#3694)
Would you believe we never had a testsuite test for environment mapping? Well, it wasn't totally untested, in the sense that OSL testsuite had one, and obviously it's used in production all the time. But OIIO's testsuite didn't have any tests of TextureSystem::environmemt(). We now remedy that. * Add testsuite/texture-env, contains several environment tests, including handles vs filenames, subimage selection, different interp and mip modes, ask for >4 channels. * New CMake build option OIIO_TEX_IMPLEMENT_VARYINGREF can be used for testing to disable implementation of the old 1.x style of batch texture calls. We don't use them, they are deprecated. This option give us a way to exclude them from code analysis, because we really don't care. * Fix bug with >4 channels for environment batch shading! * Avoid unnecessary spec lookup in TileID constructor. * Avoid building testtex test_hash during code coverage -- it is an extremely specialized test, not run in the testsuite, it shouldn't really count againt good code coverage.
1 parent fabce2a commit 92e488a

25 files changed

+513
-15
lines changed

.github/workflows/analysis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
CMAKE_UNITY_BUILD=OFF
6262
CODECOV=1
6363
CTEST_TEST_TIMEOUT=1200
64+
OIIO_CMAKE_FLAGS="-DOIIO_TEX_IMPLEMENT_VARYINGREF=OFF"
6465

6566
runs-on: ${{ matrix.os }}
6667
container:

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ set (TEX_BATCH_SIZE "" CACHE STRING "Force TextureSystem SIMD batch size (e.g. 1
122122
if (TEX_BATCH_SIZE)
123123
add_definitions ("-DOIIO_TEXTURE_SIMD_BATCH_WIDTH=${TEX_BATCH_SIZE}")
124124
endif ()
125+
option (OIIO_TEX_IMPLEMENT_VARYINGREF "Implement the deprecated batch texture functions taking VaryingRef params" ON)
126+
if (NOT OIIO_TEX_IMPLEMENT_VARYINGREF)
127+
add_definitions (-DOIIO_TEX_NO_IMPLEMENT_VARYINGREF=1)
128+
endif ()
125129

126130
# Set the default namespace
127131
set (${PROJ_NAME}_NAMESPACE ${PROJECT_NAME} CACHE STRING

src/cmake/testing.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ macro (oiio_add_all_tests)
182182
texture-wrapfill
183183
texture-fat texture-skinny
184184
texture-stats
185+
texture-env
185186
)
186187
oiio_add_tests (${all_texture_tests})
187188
# Duplicate texture tests with batch mode

src/libtexture/environment.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,15 @@ TextureSystemImpl::environment(ustring filename, TextureOptions& options,
216216
float* result, float* dresultds,
217217
float* dresultdt)
218218
{
219+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
220+
return false;
221+
#else
219222
Perthread* thread_info = get_perthread_info();
220223
TextureHandle* texture_handle = get_texture_handle(filename, thread_info);
221224
return environment(texture_handle, thread_info, options, runflags,
222225
beginactive, endactive, R, dRdx, dRdy, nchannels, result,
223226
dresultds, dresultdt);
227+
#endif
224228
}
225229

226230

@@ -235,6 +239,9 @@ TextureSystemImpl::environment(TextureHandle* texture_handle,
235239
float* result, float* dresultds,
236240
float* dresultdt)
237241
{
242+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
243+
return false;
244+
#else
238245
if (!texture_handle)
239246
return false;
240247
bool ok = true;
@@ -256,6 +263,7 @@ TextureSystemImpl::environment(TextureHandle* texture_handle,
256263
}
257264
}
258265
return ok;
266+
#endif
259267
}
260268

261269

@@ -597,8 +605,10 @@ TextureSystemImpl::environment(TextureHandle* texture_handle,
597605

598606
bool ok = true;
599607
Tex::RunMask bit = 1;
608+
float* r = OIIO_ALLOCA(float, 3 * nchannels * Tex::BatchWidth);
609+
float* drds = r + nchannels * Tex::BatchWidth;
610+
float* drdt = r + 2 * nchannels * Tex::BatchWidth;
600611
for (int i = 0; i < Tex::BatchWidth; ++i, bit <<= 1) {
601-
float r[4], drds[4], drdt[4]; // temp result
602612
if (mask & bit) {
603613
opt.sblur = options.sblur[i];
604614
opt.tblur = options.tblur[i];

src/libtexture/imagecache_pvt.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ struct TileID {
489489
/// Initialize a TileID based on full elaboration of image file,
490490
/// subimage, and tile x,y,z indices.
491491
TileID(ImageCacheFile& file, int subimage, int miplevel, int x, int y,
492-
int z = 0, int chbegin = 0, int chend = -1)
492+
int z, int chbegin, int chend)
493493
: m_x(x)
494494
, m_y(y)
495495
, m_z(z)
@@ -499,9 +499,10 @@ struct TileID {
499499
, m_chend(chend)
500500
, m_file(&file)
501501
{
502-
int nc = file.spec(subimage, miplevel).nchannels;
503-
if (chend < chbegin || chend > nc)
502+
if (chend < chbegin) {
503+
int nc = file.spec(subimage, miplevel).nchannels;
504504
m_chend = nc;
505+
}
505506
}
506507

507508
/// Destructor is trivial, because we don't hold any resources

src/libtexture/texture3d.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,15 @@ TextureSystemImpl::texture3d(ustring filename, TextureOptions& options,
197197
float* result, float* dresultds, float* dresultdt,
198198
float* dresultdr)
199199
{
200+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
201+
return false;
202+
#else
200203
Perthread* thread_info = get_perthread_info();
201204
TextureHandle* texture_handle = get_texture_handle(filename, thread_info);
202205
return texture3d(texture_handle, thread_info, options, runflags,
203206
beginactive, endactive, P, dPdx, dPdy, dPdz, nchannels,
204207
result, dresultds, dresultdt, dresultdr);
208+
#endif
205209
}
206210

207211

@@ -214,6 +218,9 @@ TextureSystemImpl::texture3d(
214218
VaryingRef<Imath::V3f> dPdy, VaryingRef<Imath::V3f> dPdz, int nchannels,
215219
float* result, float* dresultds, float* dresultdt, float* dresultdr)
216220
{
221+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
222+
return false;
223+
#else
217224
bool ok = true;
218225
result += beginactive * nchannels;
219226
if (dresultds) {
@@ -235,6 +242,7 @@ TextureSystemImpl::texture3d(
235242
}
236243
}
237244
return ok;
245+
#endif
238246
}
239247

240248

src/libtexture/texturesys.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,11 +1024,15 @@ TextureSystemImpl::texture(ustring filename, TextureOptions& options,
10241024
int nchannels, float* result, float* dresultds,
10251025
float* dresultdt)
10261026
{
1027+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
1028+
return false;
1029+
#else
10271030
Perthread* thread_info = get_perthread_info();
10281031
TextureHandle* texture_handle = get_texture_handle(filename, thread_info);
10291032
return texture(texture_handle, thread_info, options, runflags, beginactive,
10301033
endactive, s, t, dsdx, dtdx, dsdy, dtdy, nchannels, result,
10311034
dresultds, dresultdt);
1035+
#endif
10321036
}
10331037

10341038

@@ -1043,6 +1047,9 @@ TextureSystemImpl::texture(TextureHandle* texture_handle,
10431047
int nchannels, float* result, float* dresultds,
10441048
float* dresultdt)
10451049
{
1050+
#ifdef OIIO_TEX_NO_IMPLEMENT_VARYINGREF
1051+
return false;
1052+
#else
10461053
if (!texture_handle)
10471054
return false;
10481055
bool ok = true;
@@ -1065,6 +1072,7 @@ TextureSystemImpl::texture(TextureHandle* texture_handle,
10651072
}
10661073
}
10671074
return ok;
1075+
#endif
10681076
}
10691077

10701078

0 commit comments

Comments
 (0)