diff --git a/reference/shaders-hlsl/vert/sampler-buffers.vert b/reference/shaders-hlsl/vert/sampler-buffers.vert index 3652185..a4329db 100644 --- a/reference/shaders-hlsl/vert/sampler-buffers.vert +++ b/reference/shaders-hlsl/vert/sampler-buffers.vert @@ -8,9 +8,14 @@ struct SPIRV_Cross_Output float4 gl_Position : SV_Position; }; +float4 sample_from_function(Buffer s0, Buffer s1, Buffer s2) +{ + return (s0.Load(20) + asfloat(s1.Load(40))) + asfloat(s2.Load(60)); +} + void vert_main() { - gl_Position = (uFloatSampler.Load(20) + asfloat(uIntSampler.Load(40))) + asfloat(uUintSampler.Load(60)); + gl_Position = sample_from_function(uFloatSampler, uIntSampler, uUintSampler); } SPIRV_Cross_Output main() diff --git a/shaders-hlsl/vert/sampler-buffers.vert b/shaders-hlsl/vert/sampler-buffers.vert index a3dd838..dccbf77 100644 --- a/shaders-hlsl/vert/sampler-buffers.vert +++ b/shaders-hlsl/vert/sampler-buffers.vert @@ -4,10 +4,14 @@ layout(binding = 1) uniform samplerBuffer uFloatSampler; layout(binding = 2) uniform isamplerBuffer uIntSampler; layout(binding = 3) uniform usamplerBuffer uUintSampler; +vec4 sample_from_function(samplerBuffer s0, isamplerBuffer s1, usamplerBuffer s2) +{ + return texelFetch(s0, 20) + + intBitsToFloat(texelFetch(s1, 40)) + + uintBitsToFloat(texelFetch(s2, 60)); +} + void main() { - gl_Position = - texelFetch(uFloatSampler, 20) + - intBitsToFloat(texelFetch(uIntSampler, 40)) + - uintBitsToFloat(texelFetch(uUintSampler, 60)); + gl_Position = sample_from_function(uFloatSampler, uIntSampler, uUintSampler); } diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index 3d66231..3fa813b 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -1032,7 +1032,7 @@ string CompilerHLSL::to_func_call_arg(uint32_t id) // We don't have to consider combined image samplers here via OpSampledImage because // those variables cannot be passed as arguments to functions. // Only global SampledImage variables may be used as arguments. - if (type.basetype == SPIRType::SampledImage) + if (type.basetype == SPIRType::SampledImage && type.image.dim != DimBuffer) arg_str += ", " + to_sampler_expression(id); } @@ -1080,13 +1080,12 @@ void CompilerHLSL::emit_function_prototype(SPIRFunction &func, uint64_t return_f // Flatten a combined sampler to two separate arguments in modern HLSL. auto &arg_type = get(arg.type); - if (options.shader_model > 30 && arg_type.basetype == SPIRType::SampledImage) + if (options.shader_model > 30 && arg_type.basetype == SPIRType::SampledImage && arg_type.image.dim != DimBuffer) { // Manufacture automatic sampler arg for SampledImage texture decl += ", "; - if (arg_type.basetype == SPIRType::SampledImage) - decl += join(arg_type.image.depth ? "SamplerComparisonState " : "SamplerState ", - to_sampler_expression(arg.id)); + decl += join(arg_type.image.depth ? "SamplerComparisonState " : "SamplerState ", + to_sampler_expression(arg.id)); } if (&arg != &func.arguments.back())