Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): Adjust to OIIO changes to TextureOpt structure #1888

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ 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 @@ -379,7 +375,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, b8_AVX, b8_AVX2, b8_AVX2_noFMA,"
@echo " 0, b4_SSE2, 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
2 changes: 1 addition & 1 deletion src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ endif ()
#
# The USE_BATCHED option may be set to indicate that support for batched
# SIMD shader execution be compiled along with targe specific libraries
set (USE_BATCHED "" CACHE STRING "Build batched SIMD shader execution for (0, b4_SSE2, b8_AVX, b8_AVX2, b8_AVX2_noFMA, b8_AVX512, b8_AVX512_noFMA, b16_AVX512, b16_AVX512_noFMA)")
set_cache (USE_BATCHED "" "Build batched SIMD shader execution for (0, b4_SSE2, b8_AVX, b8_AVX2, b8_AVX2_noFMA, b8_AVX512, b8_AVX512_noFMA, b16_AVX512, b16_AVX512_noFMA)")
option (VEC_REPORT "Enable compiler's reporting system for vectorization" OFF)
set (BATCHED_SUPPORT_DEFINES "")
set (BATCHED_TARGET_LIBS "")
Expand Down
23 changes: 18 additions & 5 deletions src/include/OSL/batched_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,31 @@ 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
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.
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
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
float fill = 0.0f; ///< Fill value for missing channels
const float* missingcolor = nullptr; ///< Color for missing texture
};
Expand Down
117 changes: 85 additions & 32 deletions src/liboslexec/batched_llvm_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4274,8 +4274,15 @@ 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);
llvm::Value* wrap_default_value = rop.ll.constant(
#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(
static_cast<int>(Tex::Wrap::Default));
#endif

llvm::Value* sblur = wide_const_fzero_value;
llvm::Value* tblur = wide_const_fzero_value;
Expand All @@ -4293,10 +4300,19 @@ 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;
llvm::Value* mipmode = rop.ll.constant(
#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(
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 @@ -4403,24 +4419,46 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
continue; \
}

#define PARAM_UNIFORM_STRING_CODE(paramname, decoder, llvm_decoder, fieldname) \
if (name == Strings::paramname && valtype == TypeDesc::STRING) { \
if (valIsVarying) { \
is_##fieldname##_uniform = false; \
continue; \
} \
llvm::Value* val = nullptr; \
if (Val.is_constant()) { \
int mode = decoder(Val.get_string()); \
val = rop.ll.constant(mode); \
} else { \
val = rop.llvm_load_value(Val); \
llvm::Value* scalar_value_uh \
= rop.ll.call_function("osl_gen_ustringhash_pod", val); \
val = rop.ll.call_function(#llvm_decoder, scalar_value_uh); \
} \
fieldname = val; \
continue; \
#define PARAM_UNIFORM_STRING_INT_CODE(paramname, decoder, llvm_decoder, \
fieldname) \
if (name == Strings::paramname && valtype == TypeDesc::STRING) { \
if (valIsVarying) { \
is_##fieldname##_uniform = false; \
continue; \
} \
llvm::Value* val = nullptr; \
if (Val.is_constant()) { \
int mode = int(decoder(Val.get_string())); \
val = rop.ll.constant(mode); \
} else { \
val = rop.llvm_load_value(Val); \
llvm::Value* scalar_value_uh \
= rop.ll.call_function("osl_gen_ustringhash_pod", val); \
val = rop.ll.call_function(#llvm_decoder, scalar_value_uh); \
} \
fieldname = val; \
continue; \
}

#define PARAM_UNIFORM_STRING_UINT8_CODE(paramname, decoder, llvm_decoder, \
fieldname) \
if (name == Strings::paramname && valtype == TypeDesc::STRING) { \
if (valIsVarying) { \
is_##fieldname##_uniform = false; \
continue; \
} \
llvm::Value* val = nullptr; \
if (Val.is_constant()) { \
int mode = int(decoder(Val.get_string())); \
val = rop.ll.constant8(uint8_t(mode)); \
} else { \
val = rop.llvm_load_value(Val); \
llvm::Value* scalar_value_uh \
= rop.ll.call_function("osl_gen_ustringhash_pod", val); \
val = rop.ll.call_function(#llvm_decoder, scalar_value_uh); \
} \
fieldname = val; \
continue; \
}

if (name == Strings::wrap && valtype == TypeDesc::STRING) {
Expand All @@ -4434,7 +4472,7 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
}
llvm::Value* val = nullptr;
if (Val.is_constant()) {
int mode = TextureOpt::decode_wrapmode(Val.get_string());
int mode = int(TextureOpt::decode_wrapmode(Val.get_string()));
val = rop.ll.constant(mode);
} else {
val = rop.llvm_load_value(Val);
Expand All @@ -4450,14 +4488,33 @@ llvm_batched_texture_options(BatchedBackendLLVM& rop, int opnum,
}
continue;
}
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 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)
if (tex3d) {
PARAM_UNIFORM_STRING_CODE(rwrap, OIIO::TextureOpt::decode_wrapmode,
osl_texture_decode_wrapmode, rwrap)
PARAM_UNIFORM_STRING_INT_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 @@ -4479,10 +4536,6 @@ 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 @@ -4569,7 +4622,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_CODE
#undef PARAM_UNIFORM_STRING_INT_CODE
}

// The LLVMMemberIndex will be the same for any width of BatchedTextureOptions,
Expand Down
26 changes: 18 additions & 8 deletions src/liboslexec/batched_llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,14 +745,24 @@ 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
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()); // 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()); // anisotropic
sg_types.push_back(ll.type_int()); // conservative_filter
sg_types.push_back(ll.type_float()); // fill
Expand Down
15 changes: 8 additions & 7 deletions src/liboslexec/constfold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2501,10 +2501,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 == opt.field) \
if (valuetype == osltype && *(ctype*)value == (ctype)opt.field) \
elide = true; \
else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT \
&& *(int*)value == opt.field) \
&& *(int*)value == (int)opt.field) \
elide = true; \
else \
field##_set = true; \
Expand All @@ -2520,8 +2520,8 @@ DECLFOLDER(constfold_texture)
{ \
if (valuetype == osltype) { \
ctype* v = (ctype*)value; \
if (*v == opt.s##field && *v == opt.t##field \
&& *v == opt.r##field) \
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
&& *v == (ctype)opt.r##field) \
elide = true; \
else { \
s##field##_set = true; \
Expand All @@ -2530,8 +2530,8 @@ DECLFOLDER(constfold_texture)
} \
} else if (osltype == TypeDesc::FLOAT && valuetype == TypeDesc::INT) { \
int* v = (int*)value; \
if (*v == opt.s##field && *v == opt.t##field \
&& *v == opt.r##field) \
if (*v == (ctype)opt.s##field && *v == (ctype)opt.t##field \
&& *v == (ctype)opt.r##field) \
elide = true; \
else { \
s##field##_set = true; \
Expand Down Expand Up @@ -2573,7 +2573,8 @@ DECLFOLDER(constfold_texture)
else if (name == Strings::interp && !interp_set)
{
if (value && valuetype == TypeDesc::STRING
&& tex_interp_to_code(*(ustring*)value) == opt.interpmode)
&& tex_interp_to_code(*(ustring*)value)
== (int)opt.interpmode)
elide = true;
else
interp_set = true;
Expand Down
Loading
Loading