diff --git a/Makefile b/Makefile index 0d4286f01..b7ea499b3 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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" diff --git a/src/include/OSL/batched_texture.h b/src/include/OSL/batched_texture.h index f0d03051c..8f5a5cb73 100644 --- a/src/include/OSL/batched_texture.h +++ b/src/include/OSL/batched_texture.h @@ -18,11 +18,9 @@ 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 @@ -30,19 +28,8 @@ struct UniformTextureOptions { 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 }; diff --git a/src/liboslexec/batched_llvm_gen.cpp b/src/liboslexec/batched_llvm_gen.cpp index f5c7242fc..f9e567844 100644 --- a/src/liboslexec/batched_llvm_gen.cpp +++ b/src/liboslexec/batched_llvm_gen.cpp @@ -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(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(Tex::Wrap::Default)); -#endif llvm::Value* sblur = wide_const_fzero_value; llvm::Value* tblur = wide_const_fzero_value; @@ -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(Tex::MipMode::Default)); - llvm::Value* interpmode = rop.ll.constant8( - static_cast(Tex::InterpMode::SmartBicubic)); -#else - // OIIO <= 3.0 - llvm::Value* mipmode = rop.ll.constant( + llvm::Value* mipmode = rop.ll.constant( static_cast(Tex::MipMode::Default)); llvm::Value* interpmode = rop.ll.constant( static_cast(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); @@ -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); @@ -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) @@ -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 @@ -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, diff --git a/src/liboslexec/batched_llvm_instance.cpp b/src/liboslexec/batched_llvm_instance.cpp index 7c3fbc5a9..772f71f67 100644 --- a/src/liboslexec/batched_llvm_instance.cpp +++ b/src/liboslexec/batched_llvm_instance.cpp @@ -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 diff --git a/src/liboslexec/constfold.cpp b/src/liboslexec/constfold.cpp index ebea860d7..05a2f6604 100644 --- a/src/liboslexec/constfold.cpp +++ b/src/liboslexec/constfold.cpp @@ -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; \ @@ -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; \ @@ -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; \ @@ -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; diff --git a/src/liboslexec/llvm_gen.cpp b/src/liboslexec/llvm_gen.cpp index 759ad46df..4c59bc686 100644 --- a/src/liboslexec/llvm_gen.cpp +++ b/src/liboslexec/llvm_gen.cpp @@ -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) { @@ -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); \ @@ -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) @@ -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) @@ -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()); diff --git a/src/liboslexec/optexture.cpp b/src/liboslexec/optexture.cpp index 2d5371830..5521abe8a 100644 --- a/src/liboslexec/optexture.cpp +++ b/src/liboslexec/optexture.cpp @@ -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(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; } @@ -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 @@ -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 diff --git a/src/liboslexec/oslexec_pvt.h b/src/liboslexec/oslexec_pvt.h index 3374ce148..3d3b87f20 100644 --- a/src/liboslexec/oslexec_pvt.h +++ b/src/liboslexec/oslexec_pvt.h @@ -25,12 +25,9 @@ # include "string_hash.h" #endif -#include - #include #include #include -#include #include #include @@ -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; } diff --git a/src/testshade/rs_simplerend.cpp b/src/testshade/rs_simplerend.cpp index b8d9f73a4..b6c9897d4 100644 --- a/src/testshade/rs_simplerend.cpp +++ b/src/testshade/rs_simplerend.cpp @@ -6,8 +6,6 @@ # error OSL_HOST_RS_BITCODE must be defined by your build system. #endif -#include - #include #include #include