[SPIR-V] vk::ext_capability doesn't propagate correctly
Description
The [[vk::ext_capability(...)]] tag doesn't propagate if it isn't attached to a [[vk::ext_instruction(...)]] tag. It should either work on every method/function or give errors/warnings on the ones its not supposed to work on/will be ignored. Right now, we're forced to create a specialized version of the same templated function if we want to support a capability only on certain types (e.g. PhysicalStorageBufferAddresses for pointers, but not for builtin types like uint32_t)
Steps to Reproduce
https://godbolt.org/z/PjY3TTq1K
The [[vk::ext_capability(/*PhysicalStorageBufferAddresses */ 5347 )]] at line 17 isn't being propagated correctly. If you uncomment line 13, it compiles correctly.
Actual Behavior
fatal error: generated SPIR-V is invalid: Operand 2 of TypePointer requires one of these capabilities: PhysicalStorageBufferAddresses
%spirvIntrinsicType = OpTypePointer PhysicalStorageBuffer %uint
note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible
Compiler returned: 5
Environment
- DXC version: DXC (trunk)
- Host Operating System: Linux Probably?
Thanks for reporting @nipunG314 !
These are the rules for where vk::ext_capability can be used, but agreed that error messaging should be improved.
[[vk::ext_capability(uint _capability_)]]
- An attribute to specify
OpCapabilityinstruction.- It can be an attribute of
vk::ext_execution_mode(...),vk::ext_execution_mode_id(...), a function declared withvk::ext_instruction(...), or a function declared with[[vk::ext_type_def(...)]]. We can use multiple[[vk::ext_extension(string extension_name)]]for a single function.- uint capability must be a constant expression.
https://github.com/microsoft/DirectXShaderCompiler/wiki/GL_EXT_spirv_intrinsics-for-SPIR-V-code-gen
In general, we do not want these attributes to propagate. We want it close to the feature that actually requires the extension or capability.
For your case, I would recommend addin it to the typedef:
https://github.com/microsoft/DirectXShaderCompiler/blob/9c6b2c1275e41cc385b2034aa2716ec2303a62d6/tools/clang/test/CodeGenSPIRV/spv.inline.capability.hlsl#L9-L10