diff --git a/reference/opt/shaders-hlsl/frag/texture-size-combined-image-sampler.frag b/reference/opt/shaders-hlsl/frag/texture-size-combined-image-sampler.frag new file mode 100644 index 00000000..d5c37374 --- /dev/null +++ b/reference/opt/shaders-hlsl/frag/texture-size-combined-image-sampler.frag @@ -0,0 +1,30 @@ +Texture2D uTex : register(t0); +SamplerState uSampler : register(s1); + +static int2 FooOut; + +struct SPIRV_Cross_Output +{ + int2 FooOut : SV_Target0; +}; + +uint2 SPIRV_Cross_textureSize(Texture2D Tex, uint Level, out uint Param) +{ + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; +} + +void frag_main() +{ + uint _23_dummy_parameter; + FooOut = int2(SPIRV_Cross_textureSize(uTex, uint(0), _23_dummy_parameter)); +} + +SPIRV_Cross_Output main() +{ + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FooOut = FooOut; + return stage_output; +} diff --git a/reference/shaders-hlsl/frag/texture-size-combined-image-sampler.frag b/reference/shaders-hlsl/frag/texture-size-combined-image-sampler.frag new file mode 100644 index 00000000..d5c37374 --- /dev/null +++ b/reference/shaders-hlsl/frag/texture-size-combined-image-sampler.frag @@ -0,0 +1,30 @@ +Texture2D uTex : register(t0); +SamplerState uSampler : register(s1); + +static int2 FooOut; + +struct SPIRV_Cross_Output +{ + int2 FooOut : SV_Target0; +}; + +uint2 SPIRV_Cross_textureSize(Texture2D Tex, uint Level, out uint Param) +{ + uint2 ret; + Tex.GetDimensions(Level, ret.x, ret.y, Param); + return ret; +} + +void frag_main() +{ + uint _23_dummy_parameter; + FooOut = int2(SPIRV_Cross_textureSize(uTex, uint(0), _23_dummy_parameter)); +} + +SPIRV_Cross_Output main() +{ + frag_main(); + SPIRV_Cross_Output stage_output; + stage_output.FooOut = FooOut; + return stage_output; +} diff --git a/shaders-hlsl/frag/texture-size-combined-image-sampler.frag b/shaders-hlsl/frag/texture-size-combined-image-sampler.frag new file mode 100644 index 00000000..94880595 --- /dev/null +++ b/shaders-hlsl/frag/texture-size-combined-image-sampler.frag @@ -0,0 +1,9 @@ +#version 450 +layout(set = 0, binding = 0) uniform texture2D uTex; +layout(set = 0, binding = 1) uniform sampler uSampler; +layout(location = 0) out ivec2 FooOut; + +void main() +{ + FooOut = textureSize(sampler2D(uTex, uSampler), 0); +} diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index b9bca008..a6997c66 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -3088,8 +3088,11 @@ void CompilerHLSL::emit_instruction(const Instruction &instruction) { uint32_t result_type = ops[0]; uint32_t id = ops[1]; - emit_op(result_type, id, to_expression(ops[2]), true, true); - // TODO: Maybe change this when separate samplers/images are supported + auto *combined = maybe_get(ops[2]); + if (combined) + emit_op(result_type, id, to_expression(combined->image), true, true); + else + emit_op(result_type, id, to_expression(ops[2]), true, true); break; }