Skip to content

Commit d0a598d

Browse files
committed
build(deps): Adjust to OIIO changes to TextureOpt structure (#1888)
OIIO 3.0 changes the TextureOpt structure a bit, and we need to adjust on the OSL end, too. Signed-off-by: Larry Gritz <[email protected]>
1 parent 145e71e commit d0a598d

File tree

9 files changed

+152
-50
lines changed

9 files changed

+152
-50
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,6 @@ ifneq (${USE_SIMD},)
152152
MY_CMAKE_FLAGS += -DUSE_SIMD:STRING="${USE_SIMD}"
153153
endif
154154

155-
ifneq (${USE_BATCHED},)
156-
MY_CMAKE_FLAGS += -DUSE_BATCHED:STRING="${USE_BATCHED}"
157-
endif
158-
159155
ifneq (${VEC_REPORT},)
160156
MY_CMAKE_FLAGS += -DVEC_REPORT:BOOL="${VEC_REPORT}"
161157
endif
@@ -402,7 +398,7 @@ help:
402398
@echo " avx, avx2, avx512f)"
403399
@echo " OSL_USE_OPTIX=1 Build the OptiX test renderer"
404400
@echo " USE_BATCHED=targets Build batched SIMD execution of shaders for (comma-separated choices:"
405-
@echo " 0, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
401+
@echo " 0, b4_SSE2, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
406402
@echo " b8_AVX512, b8_AVX512_noFMA,"
407403
@echo " b16_AVX512, b16_AVX512_noFMA)"
408404
@echo " VEC_REPORT=0 Generate compiler vectorization reports"

src/include/OSL/batched_texture.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,31 @@ using OIIO::Tex::Wrap;
1818

1919
struct UniformTextureOptions {
2020
// Options that must be the same for all points we're texturing at once
21-
int firstchannel = 0; ///< First channel of the lookup
22-
int subimage = 0; ///< Subimage or face ID
23-
ustring subimagename; ///< Subimage name
21+
int firstchannel = 0; ///< First channel of the lookup
22+
int subimage = 0; ///< Subimage or face ID
23+
ustring subimagename; ///< Subimage name
24+
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
25+
// Future expansion of an ideal v2 of OIIO's TextureOptBatch. But not yet.
2426
Tex::Wrap swrap = Tex::Wrap::Default; ///< Wrap mode in the s direction
2527
Tex::Wrap twrap = Tex::Wrap::Default; ///< Wrap mode in the t direction
2628
Tex::Wrap rwrap
2729
= Tex::Wrap::Default; ///< Wrap mode in the r direction (volumetric)
2830
Tex::MipMode mipmode = Tex::MipMode::Default; ///< Mip mode
2931
Tex::InterpMode interpmode
3032
= Tex::InterpMode::SmartBicubic; ///< Interpolation mode
31-
int anisotropic = 32; ///< Maximum anisotropic ratio
32-
int conservative_filter = 1; ///< True: over-blur rather than alias
33+
int anisotropic = 32; ///< Maximum anisotropic ratio
34+
int conservative_filter = 1; ///< True: over-blur rather than alias
35+
#else
36+
// Original (v1) sizing and layout of the TextureOptBatch struct.
37+
int swrap = int(Tex::Wrap::Default); ///< Wrap mode in the s direction
38+
int twrap = int(Tex::Wrap::Default); ///< Wrap mode in the t direction
39+
int rwrap = int(Tex::Wrap::Default); ///< Wrap mode in r (volumetric)
40+
int mipmode = int(Tex::MipMode::Default); ///< Mip mode
41+
int interpmode = int(
42+
Tex::InterpMode::SmartBicubic); ///< Interpolation mode
43+
int anisotropic = 32; ///< Maximum anisotropic ratio
44+
int conservative_filter = 1; ///< True: over-blur rather than alias
45+
#endif
3346
float fill = 0.0f; ///< Fill value for missing channels
3447
const float* missingcolor = nullptr; ///< Color for missing texture
3548
};

src/liboslexec/batched_llvm_gen.cpp

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4263,8 +4263,15 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
42634263
llvm::Value* wide_const_fzero_value = rop.ll.wide_constant(0.0f);
42644264
llvm::Value* wide_const_fone_value = rop.ll.wide_constant(1.0f);
42654265
llvm::Value* const_zero_value = rop.ll.constant(0);
4266-
llvm::Value* wrap_default_value = rop.ll.constant(
4266+
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
4267+
// Possible future TextureOptBatch v2 -- not active yet
4268+
llvm::Value* wrap_default_value = rop.ll.constant8(
4269+
static_cast<uint8_t>(Tex::Wrap::Default));
4270+
#else
4271+
// OIIO <= 3.0
4272+
llvm::Value* wrap_default_value = rop.ll.constant(
42674273
static_cast<int>(Tex::Wrap::Default));
4274+
#endif
42684275

42694276
llvm::Value* sblur = wide_const_fzero_value;
42704277
llvm::Value* tblur = wide_const_fzero_value;
@@ -4282,10 +4289,19 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
42824289
llvm::Value* swrap = wrap_default_value;
42834290
llvm::Value* twrap = wrap_default_value;
42844291
llvm::Value* rwrap = wrap_default_value;
4285-
llvm::Value* mipmode = rop.ll.constant(
4292+
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
4293+
// Possible future TextureOptBatch v2 -- not active yet
4294+
llvm::Value* mipmode = rop.ll.constant8(
4295+
static_cast<uint8_t>(Tex::MipMode::Default));
4296+
llvm::Value* interpmode = rop.ll.constant8(
4297+
static_cast<uint8_t>(Tex::InterpMode::SmartBicubic));
4298+
#else
4299+
// OIIO <= 3.0
4300+
llvm::Value* mipmode = rop.ll.constant(
42864301
static_cast<int>(Tex::MipMode::Default));
42874302
llvm::Value* interpmode = rop.ll.constant(
42884303
static_cast<int>(Tex::InterpMode::SmartBicubic));
4304+
#endif
42894305
llvm::Value* anisotropic = rop.ll.constant(32);
42904306
llvm::Value* conservative_filter = rop.ll.constant(1);
42914307
llvm::Value* fill = rop.ll.constant(0.0f);
@@ -4421,7 +4437,7 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
44214437
}
44224438
llvm::Value* val = nullptr;
44234439
if (Val.is_constant()) {
4424-
int mode = TextureOpt::decode_wrapmode(Val.get_string());
4440+
int mode = int(TextureOpt::decode_wrapmode(Val.get_string()));
44254441
val = rop.ll.constant(mode);
44264442
} else {
44274443
val = rop.llvm_load_value(Val);
@@ -4434,14 +4450,33 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
44344450
}
44354451
continue;
44364452
}
4437-
PARAM_UNIFORM_STRING_CODE(swrap, OIIO::TextureOpt::decode_wrapmode,
4438-
osl_texture_decode_wrapmode, swrap)
4439-
PARAM_UNIFORM_STRING_CODE(twrap, OIIO::TextureOpt::decode_wrapmode,
4440-
osl_texture_decode_wrapmode, twrap)
4453+
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
4454+
// Possible future TextureOptBatch v2 -- not active yet
4455+
PARAM_UNIFORM_STRING_UINT8_CODE(swrap, OIIO::Tex::decode_wrapmode,
4456+
osl_texture_decode_wrapmode, swrap)
4457+
PARAM_UNIFORM_STRING_UINT8_CODE(twrap, OIIO::Tex::decode_wrapmode,
4458+
osl_texture_decode_wrapmode, twrap)
4459+
if (tex3d) {
4460+
PARAM_UNIFORM_STRING_UINT8_CODE(rwrap, OIIO::Tex::decode_wrapmode,
4461+
osl_texture_decode_wrapmode, rwrap)
4462+
}
4463+
PARAM_UNIFORM_STRING_UINT8_CODE(interp, tex_interp_to_code,
4464+
osl_texture_decode_interpmode,
4465+
interpmode)
4466+
#else
4467+
// OIIO <= 3.0
4468+
PARAM_UNIFORM_STRING_INT_CODE(swrap, OIIO::TextureOpt::decode_wrapmode,
4469+
osl_texture_decode_wrapmode, swrap)
4470+
PARAM_UNIFORM_STRING_INT_CODE(twrap, OIIO::TextureOpt::decode_wrapmode,
4471+
osl_texture_decode_wrapmode, twrap)
44414472
if (tex3d) {
4442-
PARAM_UNIFORM_STRING_CODE(rwrap, OIIO::TextureOpt::decode_wrapmode,
4443-
osl_texture_decode_wrapmode, rwrap)
4473+
PARAM_UNIFORM_STRING_INT_CODE(rwrap,
4474+
OIIO::TextureOpt::decode_wrapmode,
4475+
osl_texture_decode_wrapmode, rwrap)
44444476
}
4477+
PARAM_UNIFORM_STRING_INT_CODE(interp, tex_interp_to_code,
4478+
osl_texture_decode_interpmode, interpmode)
4479+
#endif
44454480

44464481
PARAM_UNIFORM_FLOAT(fill)
44474482
PARAM_UNIFORM_INT(firstchannel)
@@ -4463,10 +4498,6 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
44634498
continue;
44644499
}
44654500

4466-
PARAM_UNIFORM_STRING_CODE(interp, tex_interp_to_code,
4467-
osl_texture_decode_interpmode, interpmode)
4468-
4469-
44704501
if (name == Strings::alpha && valtype == TypeDesc::FLOAT) {
44714502
OSL_ASSERT(
44724503
valIsVarying
@@ -4553,7 +4584,7 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
45534584
#undef PARAM_WIDE_FLOAT_S_T_R
45544585
#undef PARAM_UNIFORM_FLOAT
45554586
#undef PARAM_UNIFORM_INT
4556-
#undef PARAM_UNIFORM_STRING_CODE
4587+
#undef PARAM_UNIFORM_STRING_INT_CODE
45574588
}
45584589

45594590
// The LLVMMemberIndex will be the same for any width of BatchedTextureOptions,

src/liboslexec/batched_llvm_instance.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,24 @@ BatchedBackendLLVM::llvm_type_batched_texture_options()
717717
sg_types.push_back(ll.type_wide_float()); // rnd
718718

719719
// Uniform values of the batch
720-
sg_types.push_back(ll.type_int()); // firstchannel
721-
sg_types.push_back(ll.type_int()); // subimage
722-
sg_types.push_back(vp); // subimagename
723-
sg_types.push_back(ll.type_int()); // swrap
724-
sg_types.push_back(ll.type_int()); // twrap
725-
sg_types.push_back(ll.type_int()); // rwrap
726-
sg_types.push_back(ll.type_int()); // mipmode
727-
sg_types.push_back(ll.type_int()); // interpmode
720+
sg_types.push_back(ll.type_int()); // firstchannel
721+
sg_types.push_back(ll.type_int()); // subimage
722+
sg_types.push_back(vp); // subimagename
723+
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
724+
// Possible future TextureOptBatch v2 -- not active yet
725+
sg_types.push_back(ll.type_int8()); // swrap
726+
sg_types.push_back(ll.type_int8()); // twrap
727+
sg_types.push_back(ll.type_int8()); // rwrap
728+
sg_types.push_back(ll.type_int8()); // mipmode
729+
sg_types.push_back(ll.type_int8()); // interpmode
730+
#else
731+
// OIIO <= 3.0
732+
sg_types.push_back(ll.type_int()); // swrap
733+
sg_types.push_back(ll.type_int()); // twrap
734+
sg_types.push_back(ll.type_int()); // rwrap
735+
sg_types.push_back(ll.type_int()); // mipmode
736+
sg_types.push_back(ll.type_int()); // interpmode
737+
#endif
728738
sg_types.push_back(ll.type_int()); // anisotropic
729739
sg_types.push_back(ll.type_int()); // conservative_filter
730740
sg_types.push_back(ll.type_float()); // fill

src/liboslexec/constfold.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,10 +2494,10 @@ DECLFOLDER(constfold_texture)
24942494
// Keep from repeating the same tedious code for {s,t,r, }{width,blur,wrap}
24952495
#define CHECK(field, ctype, osltype) \
24962496
if (name == Strings::field && !field##_set) { \
2497-
if (valuetype == osltype && *(ctype*)value == opt.field) \
2497+
if (valuetype == osltype && *(ctype*)value == (ctype)opt.field) \
24982498
elide = true; \
24992499
else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT \
2500-
&& *(int*)value == opt.field) \
2500+
&& *(int*)value == (int)opt.field) \
25012501
elide = true; \
25022502
else \
25032503
field##_set = true; \
@@ -2513,8 +2513,8 @@ DECLFOLDER(constfold_texture)
25132513
{ \
25142514
if (valuetype == osltype) { \
25152515
ctype* v = (ctype*)value; \
2516-
if (*v == opt.s##field && *v == opt.t##field \
2517-
&& *v == opt.r##field) \
2516+
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
2517+
&& *v == (ctype)opt.r##field) \
25182518
elide = true; \
25192519
else { \
25202520
s##field##_set = true; \
@@ -2523,8 +2523,8 @@ DECLFOLDER(constfold_texture)
25232523
} \
25242524
} else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT) { \
25252525
int* v = (int*)value; \
2526-
if (*v == opt.s##field && *v == opt.t##field \
2527-
&& *v == opt.r##field) \
2526+
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
2527+
&& *v == (ctype)opt.r##field) \
25282528
elide = true; \
25292529
else { \
25302530
s##field##_set = true; \
@@ -2566,7 +2566,8 @@ DECLFOLDER(constfold_texture)
25662566
else if (name == Strings::interp && !interp_set)
25672567
{
25682568
if (value && valuetype == TypeDesc::STRING
2569-
&& tex_interp_to_code(*(ustring*)value) == opt.interpmode)
2569+
&& tex_interp_to_code(*(ustring*)value)
2570+
== (int)opt.interpmode)
25702571
elide = true;
25712572
else
25722573
interp_set = true;

src/liboslexec/llvm_gen.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,8 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
25682568
bool sblur_set = false, tblur_set = false, rblur_set = false;
25692569
bool swrap_set = false, twrap_set = false, rwrap_set = false;
25702570
bool firstchannel_set = false, fill_set = false, interp_set = false;
2571-
bool time_set = false, subimage_set = false;
2571+
// bool time_set = false;
2572+
bool subimage_set = false;
25722573

25732574
Opcode& op(rop.inst()->ops()[opnum]);
25742575
for (int a = first_optional_arg; a < op.nargs(); ++a) {
@@ -2639,8 +2640,8 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
26392640
#define PARAM_STRING_CODE(paramname, decoder, fieldname) \
26402641
if (name == Strings::paramname && valtype == TypeDesc::STRING) { \
26412642
if (Val.is_constant()) { \
2642-
int code = decoder(Val.get_string()); \
2643-
if (!paramname##_set && code == optdefaults.fieldname) \
2643+
int code = (int)decoder(Val.get_string()); \
2644+
if (!paramname##_set && code == (int)optdefaults.fieldname) \
26442645
continue; \
26452646
if (code >= 0) { \
26462647
llvm::Value* val = rop.ll.constant(code); \
@@ -2666,7 +2667,7 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
26662667

26672668
if (name == Strings::wrap && valtype == TypeDesc::STRING) {
26682669
if (Val.is_constant()) {
2669-
int mode = TextureOpt::decode_wrapmode(Val.get_string());
2670+
int mode = (int)TextureOpt::decode_wrapmode(Val.get_string());
26702671
llvm::Value* val = rop.ll.constant(mode);
26712672
rop.ll.call_function("osl_texture_set_stwrap_code", opt, val);
26722673
if (tex3d)
@@ -2686,7 +2687,6 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
26862687
PARAM_STRING_CODE(rwrap, TextureOpt::decode_wrapmode, rwrap)
26872688

26882689
PARAM_FLOAT(fill)
2689-
PARAM_FLOAT(time)
26902690
PARAM_INT(firstchannel)
26912691
PARAM_INT(subimage)
26922692

@@ -2745,6 +2745,16 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
27452745
rop.ll.constant(nchans), val);
27462746
continue;
27472747
}
2748+
2749+
// PARAM_FLOAT(time)
2750+
if (name == Strings::time
2751+
&& (valtype == TypeDesc::FLOAT || valtype == TypeDesc::INT)) {
2752+
// NOTE: currently no supported 3d texture format makes use of
2753+
// time. So there is no time in the TextureOpt struct, but will
2754+
// silently accept and ignore the time option.
2755+
continue;
2756+
}
2757+
27482758
rop.shadingcontext()->errorfmt(
27492759
"Unknown texture{} optional argument: \"{}\", <{}> ({}:{})",
27502760
tex3d ? "3d" : "", name, valtype, op.sourcefile(), op.sourceline());

src/liboslexec/optexture.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,41 @@ osl_get_texture_options(void* sg_)
3232
ShaderGlobals* sg = (ShaderGlobals*)sg_;
3333
TextureOpt* opt = sg->context->texture_options_ptr();
3434
new (opt) TextureOpt;
35+
#if defined(OIIO_TEXTUREOPT_VERSION) && OIIO_TEXTUREOPT_VERSION >= 2
36+
new (opt) TextureOpt;
37+
#else
38+
// TODO: Simplify when TextureOpt() has __device__ marker.
39+
TextureOpt* o = reinterpret_cast<TextureOpt*>(opt);
40+
o->firstchannel = 0;
41+
o->subimage = 0;
42+
o->subimagename = ustring();
43+
o->swrap = TextureOpt::WrapDefault;
44+
o->twrap = TextureOpt::WrapDefault;
45+
o->mipmode = TextureOpt::MipModeDefault;
46+
o->interpmode = TextureOpt::InterpSmartBicubic;
47+
o->anisotropic = 32;
48+
o->conservative_filter = true;
49+
o->sblur = 0.0f;
50+
o->tblur = 0.0f;
51+
o->swidth = 1.0f;
52+
o->twidth = 1.0f;
53+
o->fill = 0.0f;
54+
o->missingcolor = nullptr;
55+
o->time = 0.0f; // Deprecated
56+
o->rnd = -1.0f;
57+
o->samples = 1; // Deprecated
58+
o->rwrap = TextureOpt::WrapDefault;
59+
o->rblur = 0.0f;
60+
o->rwidth = 1.0f;
61+
# ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
62+
o->colortransformid = 0;
63+
int* envlayout = (int*)&o->colortransformid + 1;
64+
# else
65+
int* envlayout = (int*)&o->rwidth + 1;
66+
# endif
67+
// envlayout is private so we access it from the last public member for now.
68+
*envlayout = 0;
69+
#endif
3570
return opt;
3671
}
3772

@@ -45,7 +80,7 @@ osl_texture_set_firstchannel(void* opt, int x)
4580
OSL_SHADEOP int
4681
osl_texture_decode_wrapmode(ustring_pod name)
4782
{
48-
return OIIO::TextureOpt::decode_wrapmode(ustring_from(USTR(name)));
83+
return int(OIIO::TextureOpt::decode_wrapmode(ustring_from(USTR(name))));
4984
}
5085

5186
OSL_SHADEOP void
@@ -158,7 +193,8 @@ osl_texture_set_fill(void* opt, float x)
158193
OSL_SHADEOP void
159194
osl_texture_set_time(void* opt, float x)
160195
{
161-
((TextureOpt*)opt)->time = x;
196+
// Not used by the texture system
197+
// ((TextureOpt*)opt)->time = x;
162198
}
163199

164200
OSL_SHADEOP int

src/liboslexec/oslexec_pvt.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
# include "string_hash.h"
2626
#endif
2727

28+
#include <OpenImageIO/Imath.h>
29+
2830
#include <OpenImageIO/color.h>
2931
#include <OpenImageIO/paramlist.h>
3032
#include <OpenImageIO/refcnt.h>
33+
#include <OpenImageIO/texture.h>
3134
#include <OpenImageIO/thread.h>
3235
#include <OpenImageIO/ustring.h>
3336

@@ -2512,13 +2515,13 @@ tex_interp_to_code(StringParam modename)
25122515
{
25132516
int mode = -1;
25142517
if (modename == STRING_PARAMS(smartcubic))
2515-
mode = TextureOpt::InterpSmartBicubic;
2518+
mode = (int)TextureOpt::InterpSmartBicubic;
25162519
else if (modename == STRING_PARAMS(linear))
2517-
mode = TextureOpt::InterpBilinear;
2520+
mode = (int)TextureOpt::InterpBilinear;
25182521
else if (modename == STRING_PARAMS(cubic))
2519-
mode = TextureOpt::InterpBicubic;
2522+
mode = (int)TextureOpt::InterpBicubic;
25202523
else if (modename == STRING_PARAMS(closest))
2521-
mode = TextureOpt::InterpClosest;
2524+
mode = (int)TextureOpt::InterpClosest;
25222525
return mode;
25232526
}
25242527

src/testshade/rs_simplerend.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# error OSL_HOST_RS_BITCODE must be defined by your build system.
77
#endif
88

9+
#include <OpenImageIO/fmath.h>
10+
911
#include <OSL/fmt_util.h>
1012
#include <OSL/journal.h>
1113
#include <OSL/rendererservices.h>

0 commit comments

Comments
 (0)