You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[spirv] Add vk::image_format attribute for Buffers, RWBuffers and RWTextures (#3395)
According to Vulkan specification when using `OpImageRead/OpImageWrite`, the `OpTypeImage` (`Buffers`, `RWBuffers`, `RWTextures`) must have a format that matches the format on the API side, unless the StorageImageReadWithoutFormat/StorageImageWriteWithoutFormat is added and `Unknown` is used as the format.
This pull request addressess #2498 for the format part by adding an attribute `[[vk::image_format("<image format as spelled in SPIR-V spec>")]].` Example of the syntax:
```
[[vk::image_format("rgba8")]]
RWBuffer<float4> Buf;
[[vk::image_format("rg16f")]]
RWTexture2D<float2> Tex;
RWTexture2D<float2> Tex2; // Works like before
```
The `image_format` only applies to **global variables** of type `Buffer`, `RWBuffer`, `RWTexture`. For variables and function parameters it is propagated by the inlining pass in legalization. This required a small change to one of the passes in SPIRV-Tools, that should be also checked by someone more familiar with the codebase: KhronosGroup/SPIRV-Tools#4126
Note that this does not fix the handling of unspecified format (that case still works like before, using `R32f`, etc. based on the type in shader), although it should be still fixed to add the
StorageImageReadWithoutFormat and/or StorageImageWriteWithoutFormat and use Undefined. But I think the ability to specify the format is more urgent.
Design note from Jaebaek:
Since the `image_format` attribute only applies to **global variables**, under the DXC architecture
only `DeclResultIdMapper` can check the attribute when it handles `VarDecl`s. It means
we have to pass the `image_format` information to `LowerTypeVisitor` because it cannot access to
`VarDecl`. In order to pass the `image_format`, we use `SpirvContext` that can be accessed by
`SpirvEmitter` and all visitors. We use `SpirvVariable` to `spv::ImageFormat` mapping because the
attribute only applies to **global variables** (not to image types).
See how we use `llvm::DenseMap<const SpirvVariable *, spv::ImageFormat> spvVarToImageFormat`.
Copy file name to clipboardExpand all lines: docs/SPIR-V.rst
+67Lines changed: 67 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -786,6 +786,73 @@ are translated into SPIR-V ``OpTypeImage``, with parameters:
786
786
The meanings of the headers in the above table is explained in ``OpTypeImage``
787
787
of the SPIR-V spec.
788
788
789
+
Vulkan specific Image Formats
790
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
791
+
792
+
Since HLSL lacks the syntax for fully specifying image formats for textures in
793
+
SPIR-V, we introduce ``[[vk::image_format("FORMAT")]]`` attribute for texture types.
794
+
For example,
795
+
796
+
.. code:: hlsl
797
+
[[vk::image_format("rgba8")]]
798
+
RWBuffer<float4> Buf;
799
+
800
+
[[vk::image_format("rg16f")]]
801
+
RWTexture2D<float2> Tex;
802
+
803
+
RWTexture2D<float2> Tex2; // Works like before
804
+
805
+
``rgba8`` means ``Rgba8`` `SPIR-V Image Format <https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html#_a_id_image_format_a_image_format>`_.
806
+
The following table lists the mapping between ``FORMAT`` of
807
+
``[[vk::image_format("FORMAT")]]`` and its corresponding SPIR-V Image Format.
0 commit comments