There are many cases where we want to use readonly Texture without sampling (e.g. the format does not support sampling - for example uint64). In this case we want it to be a readonly storage image and GLSL provides correct decorations to do that:
Here we are using uint64_t format, which does not support sampling. On DirectX 12, we can use SRV descriptor for image0.
For Vulkan, DXC spirv codegen will generate "sampled image" for image0 and reflection tools (e.g. spirv_reflect) will treat it as SRV and descriptor type DESCRIPTOR_TYPE_SAMPLED_IMAGE. What we really want is SRV and DESCRIPTOR_TYPE_STORAGE_IMAGE. The only way to make it work is to change image0 to RWTexture2D, which will result in it being an UAV now (and register specification must change as well).
I believe providing "readony", "writeonly" annotations and emitting corresponding decorations would make it easy to tools to correctly map to Vulkan descriptor types.
Currently in spirv backend, Texture objects are always translated to sampled image.
OpTypeImage
will have sampled set to "will be used with sampler" (https://www.khronos.org/registry/SPIR-V/specs/1.0/SPIRV.html#OpTypeImage).There are many cases where we want to use readonly Texture without sampling (e.g. the format does not support sampling - for example uint64). In this case we want it to be a readonly storage image and GLSL provides correct decorations to do that:
The result contains "NonWritable" and "NonReadable":
Using HLSL with Vulkan makes it difficult to handle these cases, because read-only images will still be treated as UAVs but we want them to be SRVs.
Somewhat related discussion: https://github.com/KhronosGroup/SPIRV-Cross/issues/1306
To illustrate the problem, let me provide a more detailed use case.
Consider the following HLSL shader, which is pretty much identical to GLSL sample above:
Here we are using
uint64_t
format, which does not support sampling. On DirectX 12, we can use SRV descriptor for image0.For Vulkan, DXC spirv codegen will generate "sampled image" for
image0
and reflection tools (e.g. spirv_reflect) will treat it as SRV and descriptor typeDESCRIPTOR_TYPE_SAMPLED_IMAGE
. What we really want is SRV andDESCRIPTOR_TYPE_STORAGE_IMAGE
. The only way to make it work is to changeimage0
toRWTexture2D
, which will result in it being an UAV now (and register specification must change as well).I believe providing "readony", "writeonly" annotations and emitting corresponding decorations would make it easy to tools to correctly map to Vulkan descriptor types.