-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPIR-V] RWTexture2D without format qualifier should emit Unknown type for its OpTypeImage #7047
Comments
IMO this needs fixed because this behavior can cause shader authors to implicitly rely on ReadWithoutFormat/WriteWithoutFormat capability without having it explicitly declared in the SPIR-V. If the required OpCapability were included, VVL would complain and make the shader author aware they're relying on it. |
Hi, This issue has been raised multiple times (#4941 is the last one).
I did suggested to remove the format guess in the past, but a good argument was raised against: when using the same shaders across multiple APIs, this format guessing can be useful for both reflection, and execution.
Not sure I understand. Do you have a case where the capability is not added when it should? |
Sorry, I should have been more clear. What I had in mind was the following scenario:
In the scenario above, the developer has come to rely on write-without-format without even requesting it or knowing about it.
IMO, this could also be viewed as a strong argument in favor of NOT guessing the format and just writing Unknown when an explicit qualifier is missing, because of the exact scenario outlined above. If a developer wishes to target such devices, they need to provide an explicit format qualifier, because whatever dxc guesses is quite likely to not match the format of the actual bound image view. Granted, VVL need to issue an error or warning in this case, which they currently don't (KhronosGroup/Vulkan-ValidationLayers#9129). But even if they did, the compiler not guessing in the first place would make diagnostics easier - the developer would immediately and directly be made aware that they're relying on a feature they didn't enable (rather than in a round-about way, by a "mismatched format" error).
I would object that when writing shaders across multiple APIs in HLSL, I would expect the compiler to try to maintain consistent semantics across different targets. If in D3D HLSL, read/write-without-format is implied, then it should be also implied for SPIR-V HLSL unless the explicit qualifier is provided. Otherwise, we'd find ourselves in a situation where the same exact code means two very different things on different platforms, and what's the point of cross-platform shaders then? I understand the tooling argument, but it feels wrong to bend the meaning of generated code out of shape just because it happens to help some tool. Maybe putting the guessed format under some sort of different decoration is the answer here. Ultimately you decide whether the change is worth it, hope you consider my points above when you do :) |
We will not be doing this in DXC. It is a change of behaviour that will force existing code to have to change if the developer wants to target a platform that does not support the extension. In Clang, the current unofficial plan is to use unknown when targeting Vulkan 1.3, which guarentees the capabilities are available. For earlier versions of Vulkan, we will need to replicate the DXC behaviour for backwards compatibility. |
Description
Consider the following simple compute shader:
this produces SPIR-V with the following
OpTypeImage
corresponding tooutputImage
:%type_2d_image = OpTypeImage %float 2D 2 0 0 2 Rgba32f
Note that the format is
Rgba32f
. Most GPUs that supportWriteWithoutFormat
capability seem to ignore the format parameter ofOpTypeImage
anyway, so this doesn't really affect behavior on them. For GPUs that actually do care about the format somehow, this would corrupt the image if e.g. an RGBA8 image is bound inadvertently (and there seems to be no validation warning, I filed a separate issue for that).In any case, the generated code seems inconsistent with the implied HLSL semantics: as far as im aware, D3D hlsl assumes StorageImageWriteWithoutFormat capability by default,. To match this in SPIR-V, the corresponding OpCapability should be emitted and Unknown format used, unless an explicit image_format qualifier is used.
Environment
The text was updated successfully, but these errors were encountered: