From 988f00fe3c42626773ec8f3f619c7122bdef70a7 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Thu, 1 Feb 2018 09:22:16 +0100 Subject: [PATCH] Fix OpImage on OpSampledImages in HLSL. --- .../texture-size-combined-image-sampler.frag | 30 +++++++++++++++++++ .../texture-size-combined-image-sampler.frag | 30 +++++++++++++++++++ .../texture-size-combined-image-sampler.frag | 9 ++++++ spirv_hlsl.cpp | 7 +++-- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 reference/opt/shaders-hlsl/frag/texture-size-combined-image-sampler.frag create mode 100644 reference/shaders-hlsl/frag/texture-size-combined-image-sampler.frag create mode 100644 shaders-hlsl/frag/texture-size-combined-image-sampler.frag 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; }