Skip to content

Commit

Permalink
Revert "build(deps): Adjust to OIIO changes to TextureOpt structure (#…
Browse files Browse the repository at this point in the history
…1888)"

This reverts commit d0a598d.
  • Loading branch information
lgritz committed Dec 4, 2024
1 parent 56077d2 commit 16617e0
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 152 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ ifneq (${USE_SIMD},)
MY_CMAKE_FLAGS += -DUSE_SIMD:STRING="${USE_SIMD}"
endif

ifneq (${USE_BATCHED},)
MY_CMAKE_FLAGS += -DUSE_BATCHED:STRING="${USE_BATCHED}"
endif

ifneq (${VEC_REPORT},)
MY_CMAKE_FLAGS += -DVEC_REPORT:BOOL="${VEC_REPORT}"
endif
Expand Down Expand Up @@ -398,7 +402,7 @@ help:
@echo " avx, avx2, avx512f)"
@echo " OSL_USE_OPTIX=1 Build the OptiX test renderer"
@echo " USE_BATCHED=targets Build batched SIMD execution of shaders for (comma-separated choices:"
@echo " 0, b4_SSE2, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
@echo " 0, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
@echo " b8_AVX512, b8_AVX512_noFMA,"
@echo " b16_AVX512, b16_AVX512_noFMA)"
@echo " VEC_REPORT=0 Generate compiler vectorization reports"
Expand Down
23 changes: 5 additions & 18 deletions src/include/OSL/batched_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,18 @@ using OIIO::Tex::Wrap;

struct UniformTextureOptions {
// Options that must be the same for all points we're texturing at once
int firstchannel = 0; ///< First channel of the lookup
int subimage = 0; ///< Subimage or face ID
ustring subimagename; ///< Subimage name
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
// Future expansion of an ideal v2 of OIIO's TextureOptBatch. But not yet.
int firstchannel = 0; ///< First channel of the lookup
int subimage = 0; ///< Subimage or face ID
ustring subimagename; ///< Subimage name
Tex::Wrap swrap = Tex::Wrap::Default; ///< Wrap mode in the s direction
Tex::Wrap twrap = Tex::Wrap::Default; ///< Wrap mode in the t direction
Tex::Wrap rwrap
= Tex::Wrap::Default; ///< Wrap mode in the r direction (volumetric)
Tex::MipMode mipmode = Tex::MipMode::Default; ///< Mip mode
Tex::InterpMode interpmode
= Tex::InterpMode::SmartBicubic; ///< Interpolation mode
int anisotropic = 32; ///< Maximum anisotropic ratio
int conservative_filter = 1; ///< True: over-blur rather than alias
#else
// Original (v1) sizing and layout of the TextureOptBatch struct.
int swrap = int(Tex::Wrap::Default); ///< Wrap mode in the s direction
int twrap = int(Tex::Wrap::Default); ///< Wrap mode in the t direction
int rwrap = int(Tex::Wrap::Default); ///< Wrap mode in r (volumetric)
int mipmode = int(Tex::MipMode::Default); ///< Mip mode
int interpmode = int(
Tex::InterpMode::SmartBicubic); ///< Interpolation mode
int anisotropic = 32; ///< Maximum anisotropic ratio
int conservative_filter = 1; ///< True: over-blur rather than alias
#endif
int anisotropic = 32; ///< Maximum anisotropic ratio
int conservative_filter = 1; ///< True: over-blur rather than alias
float fill = 0.0f; ///< Fill value for missing channels
const float* missingcolor = nullptr; ///< Color for missing texture
};
Expand Down
59 changes: 14 additions & 45 deletions src/liboslexec/batched_llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4263,15 +4263,8 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
llvm::Value* wide_const_fzero_value = rop.ll.wide_constant(0.0f);
llvm::Value* wide_const_fone_value = rop.ll.wide_constant(1.0f);
llvm::Value* const_zero_value = rop.ll.constant(0);
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
// Possible future TextureOptBatch v2 -- not active yet
llvm::Value* wrap_default_value = rop.ll.constant8(
static_cast<uint8_t>(Tex::Wrap::Default));
#else
// OIIO <= 3.0
llvm::Value* wrap_default_value = rop.ll.constant(
llvm::Value* wrap_default_value = rop.ll.constant(
static_cast<int>(Tex::Wrap::Default));
#endif

llvm::Value* sblur = wide_const_fzero_value;
llvm::Value* tblur = wide_const_fzero_value;
Expand All @@ -4289,19 +4282,10 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
llvm::Value* swrap = wrap_default_value;
llvm::Value* twrap = wrap_default_value;
llvm::Value* rwrap = wrap_default_value;
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
// Possible future TextureOptBatch v2 -- not active yet
llvm::Value* mipmode = rop.ll.constant8(
static_cast<uint8_t>(Tex::MipMode::Default));
llvm::Value* interpmode = rop.ll.constant8(
static_cast<uint8_t>(Tex::InterpMode::SmartBicubic));
#else
// OIIO <= 3.0
llvm::Value* mipmode = rop.ll.constant(
llvm::Value* mipmode = rop.ll.constant(
static_cast<int>(Tex::MipMode::Default));
llvm::Value* interpmode = rop.ll.constant(
static_cast<int>(Tex::InterpMode::SmartBicubic));
#endif
llvm::Value* anisotropic = rop.ll.constant(32);
llvm::Value* conservative_filter = rop.ll.constant(1);
llvm::Value* fill = rop.ll.constant(0.0f);
Expand Down Expand Up @@ -4458,7 +4442,7 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
}
llvm::Value* val = nullptr;
if (Val.is_constant()) {
int mode = int(TextureOpt::decode_wrapmode(Val.get_string()));
int mode = TextureOpt::decode_wrapmode(Val.get_string());
val = rop.ll.constant(mode);
} else {
val = rop.llvm_load_value(Val);
Expand All @@ -4471,33 +4455,14 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
}
continue;
}
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
// Possible future TextureOptBatch v2 -- not active yet
PARAM_UNIFORM_STRING_UINT8_CODE(swrap, OIIO::Tex::decode_wrapmode,
osl_texture_decode_wrapmode, swrap)
PARAM_UNIFORM_STRING_UINT8_CODE(twrap, OIIO::Tex::decode_wrapmode,
osl_texture_decode_wrapmode, twrap)
if (tex3d) {
PARAM_UNIFORM_STRING_UINT8_CODE(rwrap, OIIO::Tex::decode_wrapmode,
osl_texture_decode_wrapmode, rwrap)
}
PARAM_UNIFORM_STRING_UINT8_CODE(interp, tex_interp_to_code,
osl_texture_decode_interpmode,
interpmode)
#else
// OIIO <= 3.0
PARAM_UNIFORM_STRING_INT_CODE(swrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, swrap)
PARAM_UNIFORM_STRING_INT_CODE(twrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, twrap)
PARAM_UNIFORM_STRING_CODE(swrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, swrap)
PARAM_UNIFORM_STRING_CODE(twrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, twrap)
if (tex3d) {
PARAM_UNIFORM_STRING_INT_CODE(rwrap,
OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, rwrap)
PARAM_UNIFORM_STRING_CODE(rwrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, rwrap)
}
PARAM_UNIFORM_STRING_INT_CODE(interp, tex_interp_to_code,
osl_texture_decode_interpmode, interpmode)
#endif

PARAM_UNIFORM_FLOAT(fill)
PARAM_UNIFORM_INT(firstchannel)
Expand All @@ -4519,6 +4484,10 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
continue;
}

PARAM_UNIFORM_STRING_CODE(interp, tex_interp_to_code,
osl_texture_decode_interpmode, interpmode)


if (name == Strings::alpha && valtype == TypeDesc::FLOAT) {
OSL_ASSERT(
valIsVarying
Expand Down Expand Up @@ -4605,7 +4574,7 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
#undef PARAM_WIDE_FLOAT_S_T_R
#undef PARAM_UNIFORM_FLOAT
#undef PARAM_UNIFORM_INT
#undef PARAM_UNIFORM_STRING_INT_CODE
#undef PARAM_UNIFORM_STRING_CODE
}

// The LLVMMemberIndex will be the same for any width of BatchedTextureOptions,
Expand Down
26 changes: 8 additions & 18 deletions src/liboslexec/batched_llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,24 +717,14 @@ BatchedBackendLLVM::llvm_type_batched_texture_options()
sg_types.push_back(ll.type_wide_float()); // rnd

// Uniform values of the batch
sg_types.push_back(ll.type_int()); // firstchannel
sg_types.push_back(ll.type_int()); // subimage
sg_types.push_back(vp); // subimagename
#if defined(OIIO_TEXTUREOPTBATCH_VERSION) && OIIO_TEXTUREOPTBATCH_VERSION >= 2
// Possible future TextureOptBatch v2 -- not active yet
sg_types.push_back(ll.type_int8()); // swrap
sg_types.push_back(ll.type_int8()); // twrap
sg_types.push_back(ll.type_int8()); // rwrap
sg_types.push_back(ll.type_int8()); // mipmode
sg_types.push_back(ll.type_int8()); // interpmode
#else
// OIIO <= 3.0
sg_types.push_back(ll.type_int()); // swrap
sg_types.push_back(ll.type_int()); // twrap
sg_types.push_back(ll.type_int()); // rwrap
sg_types.push_back(ll.type_int()); // mipmode
sg_types.push_back(ll.type_int()); // interpmode
#endif
sg_types.push_back(ll.type_int()); // firstchannel
sg_types.push_back(ll.type_int()); // subimage
sg_types.push_back(vp); // subimagename
sg_types.push_back(ll.type_int()); // swrap
sg_types.push_back(ll.type_int()); // twrap
sg_types.push_back(ll.type_int()); // rwrap
sg_types.push_back(ll.type_int()); // mipmode
sg_types.push_back(ll.type_int()); // interpmode
sg_types.push_back(ll.type_int()); // anisotropic
sg_types.push_back(ll.type_int()); // conservative_filter
sg_types.push_back(ll.type_float()); // fill
Expand Down
15 changes: 7 additions & 8 deletions src/liboslexec/constfold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,10 +2494,10 @@ DECLFOLDER(constfold_texture)
// Keep from repeating the same tedious code for {s,t,r, }{width,blur,wrap}
#define CHECK(field, ctype, osltype) \
if (name == Strings::field && !field##_set) { \
if (valuetype == osltype && *(ctype*)value == (ctype)opt.field) \
if (valuetype == osltype && *(ctype*)value == opt.field) \
elide = true; \
else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT \
&& *(int*)value == (int)opt.field) \
&& *(int*)value == opt.field) \
elide = true; \
else \
field##_set = true; \
Expand All @@ -2513,8 +2513,8 @@ DECLFOLDER(constfold_texture)
{ \
if (valuetype == osltype) { \
ctype* v = (ctype*)value; \
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
&& *v == (ctype)opt.r##field) \
if (*v == opt.s##field && *v == opt.t##field \
&& *v == opt.r##field) \
elide = true; \
else { \
s##field##_set = true; \
Expand All @@ -2523,8 +2523,8 @@ DECLFOLDER(constfold_texture)
} \
} else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT) { \
int* v = (int*)value; \
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
&& *v == (ctype)opt.r##field) \
if (*v == opt.s##field && *v == opt.t##field \
&& *v == opt.r##field) \
elide = true; \
else { \
s##field##_set = true; \
Expand Down Expand Up @@ -2566,8 +2566,7 @@ DECLFOLDER(constfold_texture)
else if (name == Strings::interp && !interp_set)
{
if (value && valuetype == TypeDesc::STRING
&& tex_interp_to_code(*(ustring*)value)
== (int)opt.interpmode)
&& tex_interp_to_code(*(ustring*)value) == opt.interpmode)
elide = true;
else
interp_set = true;
Expand Down
20 changes: 5 additions & 15 deletions src/liboslexec/llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,7 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
bool sblur_set = false, tblur_set = false, rblur_set = false;
bool swrap_set = false, twrap_set = false, rwrap_set = false;
bool firstchannel_set = false, fill_set = false, interp_set = false;
// bool time_set = false;
bool subimage_set = false;
bool time_set = false, subimage_set = false;

Opcode& op(rop.inst()->ops()[opnum]);
for (int a = first_optional_arg; a < op.nargs(); ++a) {
Expand Down Expand Up @@ -2640,8 +2639,8 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
#define PARAM_STRING_CODE(paramname, decoder, fieldname) \
if (name == Strings::paramname && valtype == TypeDesc::STRING) { \
if (Val.is_constant()) { \
int code = (int)decoder(Val.get_string()); \
if (!paramname##_set && code == (int)optdefaults.fieldname) \
int code = decoder(Val.get_string()); \
if (!paramname##_set && code == optdefaults.fieldname) \
continue; \
if (code >= 0) { \
llvm::Value* val = rop.ll.constant(code); \
Expand All @@ -2667,7 +2666,7 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,

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

PARAM_FLOAT(fill)
PARAM_FLOAT(time)
PARAM_INT(firstchannel)
PARAM_INT(subimage)

Expand Down Expand Up @@ -2745,16 +2745,6 @@ llvm_gen_texture_options(BackendLLVM& rop, int opnum, int first_optional_arg,
rop.ll.constant(nchans), val);
continue;
}

// PARAM_FLOAT(time)
if (name == Strings::time
&& (valtype == TypeDesc::FLOAT || valtype == TypeDesc::INT)) {
// NOTE: currently no supported 3d texture format makes use of
// time. So there is no time in the TextureOpt struct, but will
// silently accept and ignore the time option.
continue;
}

rop.shadingcontext()->errorfmt(
"Unknown texture{} optional argument: \"{}\", <{}> ({}:{})",
tex3d ? "3d" : "", name, valtype, op.sourcefile(), op.sourceline());
Expand Down
40 changes: 2 additions & 38 deletions src/liboslexec/optexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,6 @@ osl_get_texture_options(void* sg_)
ShaderGlobals* sg = (ShaderGlobals*)sg_;
TextureOpt* opt = sg->context->texture_options_ptr();
new (opt) TextureOpt;
#if defined(OIIO_TEXTUREOPT_VERSION) && OIIO_TEXTUREOPT_VERSION >= 2
new (opt) TextureOpt;
#else
// TODO: Simplify when TextureOpt() has __device__ marker.
TextureOpt* o = reinterpret_cast<TextureOpt*>(opt);
o->firstchannel = 0;
o->subimage = 0;
o->subimagename = ustring();
o->swrap = TextureOpt::WrapDefault;
o->twrap = TextureOpt::WrapDefault;
o->mipmode = TextureOpt::MipModeDefault;
o->interpmode = TextureOpt::InterpSmartBicubic;
o->anisotropic = 32;
o->conservative_filter = true;
o->sblur = 0.0f;
o->tblur = 0.0f;
o->swidth = 1.0f;
o->twidth = 1.0f;
o->fill = 0.0f;
o->missingcolor = nullptr;
o->time = 0.0f; // Deprecated
o->rnd = -1.0f;
o->samples = 1; // Deprecated
o->rwrap = TextureOpt::WrapDefault;
o->rblur = 0.0f;
o->rwidth = 1.0f;
# ifdef OIIO_TEXTURESYSTEM_SUPPORTS_COLORSPACE
o->colortransformid = 0;
int* envlayout = (int*)&o->colortransformid + 1;
# else
int* envlayout = (int*)&o->rwidth + 1;
# endif
// envlayout is private so we access it from the last public member for now.
*envlayout = 0;
#endif
return opt;
}

Expand All @@ -80,7 +45,7 @@ osl_texture_set_firstchannel(void* opt, int x)
OSL_SHADEOP int
osl_texture_decode_wrapmode(ustring_pod name)
{
return int(OIIO::TextureOpt::decode_wrapmode(ustring_from(USTR(name))));
return OIIO::TextureOpt::decode_wrapmode(ustring_from(USTR(name)));
}

OSL_SHADEOP void
Expand Down Expand Up @@ -193,8 +158,7 @@ osl_texture_set_fill(void* opt, float x)
OSL_SHADEOP void
osl_texture_set_time(void* opt, float x)
{
// Not used by the texture system
// ((TextureOpt*)opt)->time = x;
((TextureOpt*)opt)->time = x;
}

OSL_SHADEOP int
Expand Down
11 changes: 4 additions & 7 deletions src/liboslexec/oslexec_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@
# include "string_hash.h"
#endif

#include <OpenImageIO/Imath.h>

#include <OpenImageIO/color.h>
#include <OpenImageIO/paramlist.h>
#include <OpenImageIO/refcnt.h>
#include <OpenImageIO/texture.h>
#include <OpenImageIO/thread.h>
#include <OpenImageIO/ustring.h>

Expand Down Expand Up @@ -2515,13 +2512,13 @@ tex_interp_to_code(StringParam modename)
{
int mode = -1;
if (modename == STRING_PARAMS(smartcubic))
mode = (int)TextureOpt::InterpSmartBicubic;
mode = TextureOpt::InterpSmartBicubic;
else if (modename == STRING_PARAMS(linear))
mode = (int)TextureOpt::InterpBilinear;
mode = TextureOpt::InterpBilinear;
else if (modename == STRING_PARAMS(cubic))
mode = (int)TextureOpt::InterpBicubic;
mode = TextureOpt::InterpBicubic;
else if (modename == STRING_PARAMS(closest))
mode = (int)TextureOpt::InterpClosest;
mode = TextureOpt::InterpClosest;
return mode;
}

Expand Down
2 changes: 0 additions & 2 deletions src/testshade/rs_simplerend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
# error OSL_HOST_RS_BITCODE must be defined by your build system.
#endif

#include <OpenImageIO/fmath.h>

#include <OSL/fmt_util.h>
#include <OSL/journal.h>
#include <OSL/rendererservices.h>
Expand Down

0 comments on commit 16617e0

Please sign in to comment.