@@ -157,23 +157,49 @@ test. Some of the difficulties are:
157157 they cannot use the same id for two different types. This can become hard to
158158 manage.
159159
160- This proposal deprecates the old mechanism, and replaces it with a new type
161- ` vk::SpirvType<int OpCode, ...> ` . The template on the type contains the opcode
162- and all of the parameters necessary for that opcode. The difficulty with this is
163- that the operands are not just literal integer values. Sometimes they are
164- another type.
160+ This proposal deprecates the old mechanism, and replaces it with two new types
161+ ` vk::SpirvOpaqueType<uint OpCode, ...> ` and
162+ ` vk::SpirvType<uint OpCode, uint size, uint alignment, ...> ` . For
163+ ` SpirvOpaqueType ` , the template on the type contains the opcode and all of the
164+ parameters necessary for that opcode. Each parameter must be one of three kinds
165+ of values:
166+
167+ 1 . Any expression that can be evaluated to a constant integer or boolean value
168+ at compile time. This value will be passed in to the type-declaration
169+ instruction as the id of an ` OpConstant* ` instruction.
170+ 1 . An expression as described above, wrapped in a call to ` vk::ext_literal ` .
171+ This value will be passed in to the type-declaration instruction as an
172+ immediate literal value.
173+ 1 . Any type. The id of the lowered type will be passed in to the
174+ type-declaration instruction.
175+
176+ For example, [ ` OpTypeArray ` ] (https://registry.khronos.org/SPIR-V/specs/unified1/
177+ SPIRV.html#OpTypeArray) takes an id for the element type and an id for the
178+ element length, so an array of 16 integers could be declared as
179+
180+ ```
181+ vk::SpirvOpaqueType</* OpTypeArray */ 28, int, 16>
182+ ```
183+
184+ [ ` OpTypeVector ` ] (https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#
185+ OpTypeVector) takes an id for the component type and a literal for the component
186+ count, so a 4-integer vector could be declared as
187+
188+ ```
189+ vk::SpirvOpaqueType</* OpTypeVector */ 23, int, vk::ext_literal(4)>
190+ ```
165191
166192The header file could create a partial instantiation with a more meaningful
167193name. For example, if you wanted to declare the types from the
168194[ SPV_INTEL_device_side_avc_motion_estimation] ( http://htmlpreview.github.io/?https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_device_side_avc_motion_estimation.html )
169195you could have
170196
171197```
172- typedef vk::SprivType </* OpTypeAvcMcePayloadINTEL */ 5704> AvcMcePayloadINTEL;
198+ typedef vk::SpirvOpaqueType </* OpTypeAvcMcePayloadINTEL */ 5704> AvcMcePayloadINTEL;
173199
174200// Requires HLSL2021
175201template<typename ImageType>
176- using VmeImageINTEL = vk::SpirvType </* OpTypeVmeImageINTEL */ 5700, Imagetype>;
202+ using VmeImageINTEL = vk::SpirvOpaqueType </* OpTypeVmeImageINTEL */ 5700, Imagetype>;
177203```
178204
179205Then the user could simply use the types:
@@ -183,6 +209,22 @@ VmeImageINTEL<Texture2D> image;
183209AvcMcePayloadINTEL payload;
184210```
185211
212+ If you want to use an inline SPIR-V type in a context where the size and
213+ alignment matter, for example as an interface type or in a push constant, you
214+ should use ` SpirvType ` instead of ` SpirvOpaqueType ` .
215+
216+ ` SpirvType ` additionally takes a ` size ` parameter, specifying the number of
217+ bytes a single value of the type occupies, and an ` alignment ` parameter,
218+ specifying a power of two that the value will be aligned to in memory. For
219+ example, an unsigned 8-bit integer type could be declared as
220+
221+ ```
222+ typedef vk::SpirvType</* OpTypeInt */ 21, /* size */ 1, /* alignment */ 1, vk::ext_literal(8), vk::ext_literal(false)> uint8_t;
223+ ```
224+
225+ Neither ` SpirvType ` nor ` SpirvOpaqueType ` may be used as the component type for
226+ an HLSL vector or matrix.
227+
186228### Decorations
187229
188230The current inline SPIR-V includes the ` vk::ext_decorate ` attribute. This works
0 commit comments