Skip to content

Commit

Permalink
texture3d testing, fixes, refactoring, coverage (AcademySoftwareFound…
Browse files Browse the repository at this point in the history
…ation#3699)

* More extensive testing of texture3d: handle vs filename, subimages,
  >4 channels, closest sample interpolation.

* Fixes for tex3d > 4 chan that turned out to be broken.

* Some rearrangement for the >4 channel case

* Refactor and simplify accum3d_sample_bilinear so multiple data types
  all use the same templated code path.

* This all reduces the amount of untested code in OIIO by another 0.4%.
  • Loading branch information
lgritz committed Jan 7, 2023
1 parent 52e5d89 commit 9260df1
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 239 deletions.
333 changes: 115 additions & 218 deletions src/libtexture/texture3d.cpp

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions src/testtex/testtex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,14 @@ tex3d_region(ImageBuf& image, ustring filename, Mapping3D mapping, ROI roi)
mapping(p.x(), p.y(), P, dPdx, dPdy, dPdz);

// Call the texture system to do the filtering.
bool ok = texsys->texture3d(texture_handle, perthread_info, opt, P,
dPdx, dPdy, dPdz, nchannels, result,
dresultds, dresultdt, dresultdr);
bool ok = use_handle
? texsys->texture3d(texture_handle, perthread_info, opt,
P, dPdx, dPdy, dPdz, nchannels,
result, dresultds, dresultdt,
dresultdr)
: texsys->texture3d(filename, opt, P, dPdx, dPdy, dPdz,
nchannels, result, dresultds,
dresultdt, dresultdr);
if (!ok) {
std::string e = texsys->geterror();
if (!e.empty())
Expand Down Expand Up @@ -978,13 +983,19 @@ tex3d_region_batch(ImageBuf& image, ustring filename, Mapping3DWide mapping,
RunMask mask = RunMaskOn >> (BatchWidth - npoints);

// Call the texture system to do the filtering.
if (y == 0 && x == 0)
Strutil::print("P = {}\n", P);
bool ok = texsys->texture3d(texture_handle, perthread_info, opt,
mask, (float*)&P, (float*)&dPdx,
(float*)&dPdy, (float*)&dPdz, nchannels,
(float*)result, (float*)dresultds,
(float*)dresultdt, (float*)dresultdr);
bool ok
= use_handle
? texsys->texture3d(texture_handle, perthread_info, opt,
mask, (float*)&P, (float*)&dPdx,
(float*)&dPdy, (float*)&dPdz,
nchannels, (float*)result,
(float*)dresultds, (float*)dresultdt,
(float*)dresultdr)
: texsys->texture3d(filename, opt, mask, (float*)&P,
(float*)&dPdx, (float*)&dPdy,
(float*)&dPdz, nchannels,
(float*)result, (float*)dresultds,
(float*)dresultdt, (float*)dresultdr);
if (!ok) {
std::string e = texsys->geterror();
if (!e.empty())
Expand All @@ -1008,7 +1019,7 @@ tex3d_region_batch(ImageBuf& image, ustring filename, Mapping3DWide mapping,
void
test_texture3d(ustring filename, Mapping3D mapping)
{
Strutil::print("Testing 3d texture {}, output = {}\n", filename,
Strutil::print("Testing texture3d {}, output = {}\n", filename,
output_filename);
int nchannels = nchannels_override ? nchannels_override : 4;
ImageSpec outspec(output_xres, output_yres, nchannels, TypeDesc::FLOAT);
Expand Down Expand Up @@ -1038,7 +1049,7 @@ test_texture3d(ustring filename, Mapping3D mapping)
void
test_texture3d_batch(ustring filename, Mapping3DWide mapping)
{
Strutil::print("Testing 3d texture {}, output = {}\n", filename,
Strutil::print("Testing BATCHED texture3d {}, output = {}\n", filename,
output_filename);
int nchannels = nchannels_override ? nchannels_override : 4;
ImageSpec outspec(output_xres, output_yres, nchannels, TypeDesc::FLOAT);
Expand Down
Binary file added testsuite/texture-texture3d/ref/closest.exr
Binary file not shown.
Binary file added testsuite/texture-texture3d/ref/out-5chan.exr
Binary file not shown.
48 changes: 48 additions & 0 deletions testsuite/texture-texture3d/ref/out-batch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Created texture system
Result of get_texture_info resolution (as int[2]) = true 33x33
Result of get_texture_info resolution (as int[3]) = true 33x33x33
Result of get_texture_info channels = true 1
Result of get_texture_info channels = true 1
Result of get_texture_info data format = true float
Result of get_texture_info datawindow (as int[4]) = true [-16 -16 16 16]
Result of get_texture_info datawindow (as int[6]) = true [-16 -16 -16 16 16 16]
Result of get_texture_info displaywindow (as int[4]) = true [-12 -12 12 12]
Result of get_texture_info displaywindow (as int[6]) = true [-12 -12 -12 12 12 12]
Result of get_texture_info datetime = false
Result of get_texture_info averagecolor = no
Result of get_texture_info averagealpha = no
Result of get_texture_info constantcolor = no
Result of get_texture_info constantalpha = no
Texture type is true Volume Texture

Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out.exr
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out-handle.exr
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out-5chan.exr
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out-subimage0.exr
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out-subimagedensity.exr
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = out-subimagemissing.exr
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
Created texture system
Testing BATCHED texture3d ../openvdb/src/sphere.vdb, output = closest.exr
Comparing "out.exr" and "ref/out.exr"
PASS
Comparing "out-handle.exr" and "ref/out-handle.exr"
PASS
Comparing "out-5chan.exr" and "ref/out-5chan.exr"
PASS
Comparing "out-subimage0.exr" and "ref/out-subimage0.exr"
PASS
Comparing "out-subimagedensity.exr" and "ref/out-subimagedensity.exr"
PASS
Comparing "out-subimagemissing.exr" and "ref/out-subimagemissing.exr"
PASS
Comparing "closest.exr" and "ref/closest.exr"
PASS
Binary file added testsuite/texture-texture3d/ref/out-handle.exr
Binary file not shown.
Binary file added testsuite/texture-texture3d/ref/out-subimage0.exr
Binary file not shown.
Binary file not shown.
Binary file not shown.
49 changes: 42 additions & 7 deletions testsuite/texture-texture3d/ref/out.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
Created texture system
Result of get_texture_info resolution = 1 33x33
Result of get_texture_info channels = 1 1
Result of get_texture_info channels = 1 1
Result of get_texture_info data format = 1 float
Result of get_texture_info datetime = 0
Result of get_texture_info resolution (as int[2]) = true 33x33
Result of get_texture_info resolution (as int[3]) = true 33x33x33
Result of get_texture_info channels = true 1
Result of get_texture_info channels = true 1
Result of get_texture_info data format = true float
Result of get_texture_info datawindow (as int[4]) = true [-16 -16 16 16]
Result of get_texture_info datawindow (as int[6]) = true [-16 -16 -16 16 16 16]
Result of get_texture_info displaywindow (as int[4]) = true [-12 -12 12 12]
Result of get_texture_info displaywindow (as int[6]) = true [-12 -12 -12 12 12 12]
Result of get_texture_info datetime = false
Result of get_texture_info averagecolor = no
Result of get_texture_info averagealpha = no
Result of get_texture_info constantcolor = no
Texture type is 1 Volume Texture
Result of get_texture_info constantalpha = no
Texture type is true Volume Texture

Testing 3d texture ../openvdb/src/sphere.vdb, output = out.exr
Testing texture3d ../openvdb/src/sphere.vdb, output = out.exr
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = out-handle.exr
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = out-5chan.exr
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = out-subimage0.exr
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = out-subimagedensity.exr
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = out-subimagemissing.exr
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
ERROR: Unknown subimage "missing" in texture "../openvdb/src/sphere.vdb"
Created texture system
Testing texture3d ../openvdb/src/sphere.vdb, output = closest.exr
Comparing "out.exr" and "ref/out.exr"
PASS
Comparing "out-handle.exr" and "ref/out-handle.exr"
PASS
Comparing "out-5chan.exr" and "ref/out-5chan.exr"
PASS
Comparing "out-subimage0.exr" and "ref/out-subimage0.exr"
PASS
Comparing "out-subimagedensity.exr" and "ref/out-subimagedensity.exr"
PASS
Comparing "out-subimagemissing.exr" and "ref/out-subimagemissing.exr"
PASS
Comparing "closest.exr" and "ref/closest.exr"
PASS
38 changes: 36 additions & 2 deletions testsuite/texture-texture3d/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
#!/usr/bin/env python

command = testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 ../openvdb/src/sphere.vdb")
outputs = [ "out.exr" ]
redirect = ">> out.txt 2>&1"

# basic
command += testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"../openvdb/src/sphere.vdb -o out.exr")

# handles, derivatives
command += testtex_command("--handle --derivs --no-gettextureinfo "
"-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"-o out-handle.exr ../openvdb/src/sphere.vdb")

# more channels
command += testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"-nchannels 5 --no-gettextureinfo ../openvdb/src/sphere.vdb -o out-5chan.exr")

# subimages
command += testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"-subimage 0 --no-gettextureinfo ../openvdb/src/sphere.vdb -o out-subimage0.exr")
command += testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"-subimagename density --no-gettextureinfo ../openvdb/src/sphere.vdb -o out-subimagedensity.exr")
command += testtex_command("-res 2 2 --nowarp --offset 5 5 5 --scalest 3 3 "
"-subimagename missing --no-gettextureinfo ../openvdb/src/sphere.vdb -o out-subimagemissing.exr")

# interp and mip modes
command += testtex_command("-res 128 128 --nowarp --offset 5 5 5 --scalest 3 3 "
"-interpmode 0 --no-gettextureinfo "
"../openvdb/src/sphere.vdb -o closest.exr")

outputs = [ "out.exr",
"out-handle.exr",
"out-5chan.exr",
"out-subimage0.exr",
"out-subimagedensity.exr",
"out-subimagemissing.exr",
"closest.exr",
"out.txt" ]

0 comments on commit 9260df1

Please sign in to comment.