diff --git a/reference/shaders-hlsl/frag/tex-sampling.frag b/reference/shaders-hlsl/frag/tex-sampling.frag index 98d532c4..7e10bfdd 100644 --- a/reference/shaders-hlsl/frag/tex-sampling.frag +++ b/reference/shaders-hlsl/frag/tex-sampling.frag @@ -89,7 +89,16 @@ void frag_main() texcolor += tex1dArray.Sample(_tex1dArray_sampler, texCoord2d); texcolor += tex2dArray.Sample(_tex2dArray_sampler, texCoord3d); texcolor += texCubeArray.Sample(_texCubeArray_sampler, texCoord4d); - texcolor += tex2d.Gather(_tex2d_sampler, texCoord2d, 0); + texcolor += tex2d.GatherRed(_tex2d_sampler, texCoord2d); + texcolor += tex2d.GatherRed(_tex2d_sampler, texCoord2d); + texcolor += tex2d.GatherGreen(_tex2d_sampler, texCoord2d); + texcolor += tex2d.GatherBlue(_tex2d_sampler, texCoord2d); + texcolor += tex2d.GatherAlpha(_tex2d_sampler, texCoord2d); + texcolor += tex2d.GatherRed(_tex2d_sampler, texCoord2d, int2(1, 1)); + texcolor += tex2d.GatherRed(_tex2d_sampler, texCoord2d, int2(1, 1)); + texcolor += tex2d.GatherGreen(_tex2d_sampler, texCoord2d, int2(1, 1)); + texcolor += tex2d.GatherBlue(_tex2d_sampler, texCoord2d, int2(1, 1)); + texcolor += tex2d.GatherAlpha(_tex2d_sampler, texCoord2d, int2(1, 1)); texcolor += tex2d.Load(int3(int2(1, 2), 0)); texcolor += separateTex2d.Sample(samplerNonDepth, texCoord2d); texcolor.w += separateTex2dDepth.SampleCmp(samplerDepth, texCoord3d.xy, texCoord3d.z); diff --git a/shaders-hlsl/frag/tex-sampling.frag b/shaders-hlsl/frag/tex-sampling.frag index 182879f2..4a386c0d 100644 --- a/shaders-hlsl/frag/tex-sampling.frag +++ b/shaders-hlsl/frag/tex-sampling.frag @@ -61,6 +61,16 @@ void main() texcolor += texture(texCubeArray, texCoord4d); texcolor += textureGather(tex2d, texCoord2d); + texcolor += textureGather(tex2d, texCoord2d, 0); + texcolor += textureGather(tex2d, texCoord2d, 1); + texcolor += textureGather(tex2d, texCoord2d, 2); + texcolor += textureGather(tex2d, texCoord2d, 3); + + texcolor += textureGatherOffset(tex2d, texCoord2d, ivec2(1, 1)); + texcolor += textureGatherOffset(tex2d, texCoord2d, ivec2(1, 1), 0); + texcolor += textureGatherOffset(tex2d, texCoord2d, ivec2(1, 1), 1); + texcolor += textureGatherOffset(tex2d, texCoord2d, ivec2(1, 1), 2); + texcolor += textureGatherOffset(tex2d, texCoord2d, ivec2(1, 1), 3); texcolor += texelFetch(tex2d, ivec2(1, 2), 0); diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index f2aace50..ab00ed6d 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -1463,7 +1463,36 @@ void CompilerHLSL::emit_texture_op(const Instruction &i) if (imgtype.image.depth) texop += ".SampleCmp"; else if (gather) - texop += ".Gather"; + { + uint32_t comp_num = get(comp).scalar(); + if (options.shader_model >= 50) + { + switch (comp_num) + { + case 0: + texop += ".GatherRed"; + break; + case 1: + texop += ".GatherGreen"; + break; + case 2: + texop += ".GatherBlue"; + break; + case 3: + texop += ".GatherAlpha"; + break; + default: + SPIRV_CROSS_THROW("Invalid component."); + } + } + else + { + if (comp_num == 0) + texop += ".Gather"; + else + SPIRV_CROSS_THROW("HLSL shader model 4 can only gather from the red component."); + } + } else if (bias) texop += ".SampleBias"; else if (grad_x || grad_y) @@ -1641,13 +1670,6 @@ void CompilerHLSL::emit_texture_op(const Instruction &i) expr += to_expression(offset); } - if (comp) - { - forward = forward && should_forward(comp); - expr += ", "; - expr += to_expression(comp); - } - if (sample) { expr += ", ";