DirectXShaderCompiler/external
seppala2 03cc4f8663
[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: https://github.com/KhronosGroup/SPIRV-Tools/pull/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`.
2021-03-01 10:07:40 -05:00
..
SPIRV-Headers@a3fdfe8146 [spirv] Add vk::image_format attribute for Buffers, RWBuffers and RWTextures (#3395) 2021-03-01 10:07:40 -05:00
SPIRV-Tools@ef3290bbea [spirv] Add vk::image_format attribute for Buffers, RWBuffers and RWTextures (#3395) 2021-03-01 10:07:40 -05:00
effcee@cd25ec17e9 [spirv] Update effcee (external dependency for testing) (#2495) 2019-09-27 15:27:13 -04:00
googletest@440527a61e [spirv] Fix Wave*CountBits() and improve compilation time (#1574) 2018-09-27 12:20:23 -04:00
re2@4c916c947a [spirv] Update external projects (#1546) 2018-09-18 15:47:41 -04:00
CMakeLists.txt [spirv] Update SPIRV-Tools and SPIRV-Headers (#3074) 2020-08-11 21:35:19 -05:00
GTestConfig.cmake [linux-port] Fix spirv test warnings (#1337) 2018-06-02 04:16:29 -04:00