microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
2.98k stars 666 forks source link

[SPIR-V][Feature Request][SM6.7] Implement GatherRaw in the SPIR-V backend #6611

Open Keenuts opened 1 month ago

Keenuts commented 1 month ago

Shader Model 6.7 added Raw Gather Methods which are currently unimplemented in the SPIR-V backend.

Texture2D<uint32_t> tex;
SamplerState samplerState;

float4 main() : SV_Target {
  uint4 res = tex.GatherRaw(samplerState, float2(0, 0));
  return float(res.x).xxxx;
}
dxc -T ps_6_7 shader.hlsl -spirv
shader.hlsl:5:19: error: intrinsic 'GatherRaw' method unimplemented
  uint4 res = tex.GatherRaw(samplerState, float2(0, 0));
                  ^
s-perron commented 1 month ago

I don't think this can be implemented in a straight forward way. The problem is that the new instruction retrieves "a single value that represents a raw, bitwise copy of all of the element’s channels without any conversion of texture contents." As far a I can tell, no existing Vulkan instruction will do that.

s-perron commented 1 month ago

FYI: https://docs.vulkan.org/spec/latest/chapters/textures.html#textures-format-conversion

Keenuts commented 1 month ago

When we talked about that, it seemed we'd need to to 4 OpImageGather calls to recombine the N components. But I saw the GatherRaw limits thew formats of the textures to single channels, or worst case, 2 channels textures. So doesn't this means in most cases, we would have a single OpImageGather to do? And in a very few cases 2?

s-perron commented 1 month ago

The issue the the bitwise copy. AFAIK, all of the existing instructions will do a format conversion. The point of RawGather is to avoid the format conversion.