From 2d1b6633b53a04a280d19fc92725dda8a96cc530 Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Thu, 4 Jul 2024 09:59:18 -0400 Subject: [PATCH] [0011] Allows cap and ext attributes on variable declarations (#270) To be able to add the necessary capabilities and extensions for SpirvTypes, we have to be able to add the capabilities and extension attributes to the variables of that type. This change updates the inline spirv spec to allow adding the capabilities and extension attributes to type aliases, variables, and fields. --- proposals/0011-inline-spirv.md | 43 ++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/proposals/0011-inline-spirv.md b/proposals/0011-inline-spirv.md index 38db3ac9..f67a685d 100644 --- a/proposals/0011-inline-spirv.md +++ b/proposals/0011-inline-spirv.md @@ -178,6 +178,7 @@ kinds of values: For example, `123` can be passed in as an immediate literal by using `vk::Literal >`. + 1. Any type. The id of the lowered type will be passed in to the type-declaration instruction. @@ -203,11 +204,16 @@ name. For example, if you wanted to declare the types from the you could have ``` +[[vk::ext_capability(/* SubgroupAvcMotionEstimationINTEL */ 5696)]] +[[vk::ext_extension("SPV_INTEL_device_side_avc_motion_estimation")]] typedef vk::SpirvOpaqueType AvcMcePayloadINTEL; // Requires HLSL2021 template -using VmeImageINTEL = vk::SpirvOpaqueType; +using VmeImageINTEL +[[vk::ext_capability(/* SubgroupAvcMotionEstimationINTEL */ 5696)]] +[[vk::ext_extension("SPV_INTEL_device_side_avc_motion_estimation")]] + = vk::SpirvOpaqueType; ``` Then the user could simply use the types: @@ -319,7 +325,40 @@ either an input or an output, not both. Existing inline SPIR-V has attributes to indicate that a capability or extension is needed by a particular part of the code. There are examples above. This -proposal will allows these attribute to be applied to an entry point. +proposal allows these attribute to be applied to an entry point. + +For types, the existing inline SPIR-V allows these attributes to be used on the +function that was used to define the type. However, that function is no longer +used when types are defined using `vk::SpirvType` and `vk::SpirvOpaqueType`. To +be able to add the capabilities and extensions that are required for a type, we +will allow these attributes to be used on variable declarations, field +declarations, and type aliases. Examples of these attributes with a typedef and +using statement are in the Types section. + +The attributes can be added to fields and variable declarations for cases when a +type alias is not used. + +For example, + +```c++ +class Payload { + + [[vk::ext_capability(/* SubgroupAvcMotionEstimationINTEL */ 5696)]] + [[vk::ext_extension("SPV_INTEL_device_side_avc_motion_estimation")]] + vk::SpirvOpaqueType payload; +}; + +[[vk::ext_capability(/* SubgroupAvcMotionEstimationINTEL */ 5696)]] +[[vk::ext_extension("SPV_INTEL_device_side_avc_motion_estimation")]] +vk::SpirvOpaqueType globalPayload; +``` + +In this case, the user of the header file, could use `Paylaod::payload` and +`globalPayload`. without worrying about the capabilities and extensions. + +When a compiler encounters either attribute, it is expected to add the +capability and extension to the module. However, the compiler is allowed, but +not required, to remove capabilities and extensions that are not required. ## Detailed design