Name Strings
SPV_KHR_untyped_pointers
Contact
To report problems with this extension, please open a new issue at:
Contributors
-
Alan Baker, Google
-
David Neto, Google
-
Hugo Devillers, Saarland University
-
Tobias Hector, AMD
-
Caio Oliveira, Intel
-
Graeme Leese, Broadcom
-
Ruihao Zhang, Qualcomm,
-
Dmitry Sidorov, Intel
-
Jeff Bolz, Nvidia
-
Victor Lomuller, Codeplay
-
Kevin Petit, Arm
-
Ben Ashbaugh, Intel
Notice
Copyright (c) 2024 The Khronos Group Inc. Copyright terms at http://www.khronos.org/registry/speccopyright.html
Status
Provisional
-
Approved by the SPIR-V Working Group: 2024-05-29
-
Approved by the Khronos Board of Promoters: 2024-07-12
Version
Last Modified Date |
2024-08-08 |
Revision |
2 |
Dependencies
This extension is written against the SPIR-V Specification, Version 1.6 Revision 3.
This extension modifies SPV_KHR_workgroup_memory_explicit_layout.
This extension modifies SPV_KHR_cooperative_matrix.
This extension modifies the OpenCL.std extended instruction set.
Overview
This extension introduces support for untyped pointers. It allows for the declaration and use of pointers that do not specify the type of data they point to. It also allows memory, atomic and other instructions to reinterpret data differently than the declared type of the variables they are used with. For example, loading a vector of floating-point values from a variable with a declared type of an array of integers. It provides an equivalent set of functionality to type-punning via pointer casting in high-level languages.
This extension adds the following new instructions:
Extension Name
To use this extension within a SPIR-V module, the following OpExtension must be present in the module:
OpExtension "SPV_KHR_untyped_pointers"
Modifications to the SPIR-V Specification, Version 1.6
Modify Section 2.2.1 Instructions:
Add the following new term:
Variable: An OpVariable or OpUntypedVariableKHR.
Change the following existing terms:
Object: An instantiation of a non-void type, either as the Result <id> of an operation, or created through a variable.
Memory Object: An object created through a variable. Such an object exists only for the duration of a function if it is a function variable, and otherwise exists for the duration of the invocation.
Memory Object Declaration: A variable, or an OpFunctionParameter of pointer type, or the contents of a variable that holds either a pointer to the PhysicalStorageBuffer storage class or an array of such pointers.
Intermediate Object or Intermediate Value or Intermediate Result: An object created by an operation (not memory allocated by a variable) and dying on its last consumption.
Modify Section 2.2.2 Types:
Add the following new term:
Pointer Type: An OpTypePointer or OpTypeUntypedPointerKHR.
Changes the following existing terms:
Physical Pointer Type: A pointer type whose Storage Class uses physical addressing according to the addressing model.
Variable Pointer: A pointer of logical pointer type that results from one of the following opcodes:
-
OpSelect
-
OpPhi
-
OpFunctionCall
-
OpPtrAccessChain
-
OpLoad
-
OpConstantNull
Additionally, any OpAccessChain, OpInBoundsAccessChain, OpUntypedAccessChainKHR, OpUntypedInBoundsAccessChainKHR or OpCopyObject that takes a variable pointer as an operand also produces a variable pointer. An OpFunctionParameter of pointer type is a variable pointer if any OpFunctionCall to the function statically passes a variable pointer as the value of the parameter.
Modify Section 2.4 Logical Layout of a Module:
Change references to OpVariable to variable.
Modify Section 2.16.1 Universal Validation Rules:
Modify the list items under the following list item:
Change:
To:
Change:
To:
Change:
To:
Change:
To:
Modify the list items under the following list item:
Change:
To:
Change:
To:
Change:
To:
Modify the list items under the following list item:
Change:
To:
Modify the list items under the following list item:
Change:
To:
Change:
To:
Modify the list items under the following list item:
Change:
To:
Changes list items under the following list item:
Change:
To:
Add the following list items:
Change list items under the following list item:
Change:
To:
Add the following list items:
Modify Section 2.16.2 Validation Rules for Shader Capabilities:
Modify the list items under the following list item:
Add the following list items:
Modify the list items under the following list item:
Change:
To:
Change:
To:
Modify Section 2.17 Universal Limits:
Change the table entry:
To:
Modify Section 2.18 Memory Model:
Change references to OpVariable to variable.
Add a new section at the end of Section 2 Specification titled Untyped Pointers:
OpTypePointer includes the data type of the memory that it points to as an operand of the type-declaration. Logical pointer types of type OpTypePointer are strongly typed. That is, the data they point to cannot be reinterpreted as another type in memory. Physical pointer types of type OpTypePointer are not strongly typed as OpBitcast can be used to cast from one representation to another. Unlike, OpTypePointer, OpTypeUntypedPointerKHR does not encode the type of data that it points to. This means that interpretation of the data type is left to instructions that utilize the pointer.
Each untyped instruction (OpUntyped…) has an operand that specifies how the data should be interpreted (e.g. Base Type in OpUntypedAccessChainKHR). Also, OpUntypedAccessChainKHR, OpUntypedInBoundsAccessChainKHR, OpUntypedPtrAccessChainKHR, and OpUntypedInBoundsPtrAccessChainKHR may take either a typed or untyped pointer as the Base operand. This facilitates translations from high-level languages as it can localize where untyped pointers appear in syntax evaluation.
When memory accessed via instructions have a pointer operand with type OpTypeUntypedPointerKHR (e.g. OpLoad or atomic instructions), the interpreted data type is specified by the Result Type if it exists. The intepreted data type for instructions without a Result Type (e.g. OpStore) comes from the type of the operand of the object being stored. OpCopyMemorySized interprets the data as an array of 8-bit integers.
When an instruction accesses memory via an untyped pointer for storage class S and with interpreted data type T, the instruction behaves as if the pointer were of type OpTypePointer having Storage Class S and Type T. That is, the instruction will access exactly the same memory locations and interpret the data there as if using the corresponding strongly typed pointer.
Modify Section 3.7 Storage Class:
Add OpTypeUntypedPointerKHR and OpUntypedVariableKHR to the list of "Used by" instructions.
Modify Section 3.20 Decoration:
Change references to OpVariable to variable.
Modify Section 3.21 BuiltIn:
Change references to OpVariable to variable.
Modify Section 3.31 Capability:
Change references to OpTypePointer to pointer type.
Add the following rows to the table:
Capability | Implicitly Declares | |
---|---|---|
4473 |
UntypedPointersKHR |
Modify Section 3.37 Instructions:
In the following instructions, change references to OpVariable to variable:
-
OpDecorateId
-
OpEntryPoint
-
OpTypeBool
Change the description of Result Type in OpImageTexelPointer to:
Change the description of Pointer in OpLoad to:
Change the description of Pointer in OpStore to:
Change the description of OpCopyMemory to:
Add the enabling capability UntypedPointersKHR to OpCopyMemorySized.
Change the restrictions on Operand 1 and Operand 2 in OpPtrEqual and OpPtrNotEqual to:
Change the restriction on Operand 1 and Operand 2 in OpPtrDiff to:
Change the description of Result Type in OpPtrCastToGeneric to:
Change the description of OpGenericCastToPtr to:
Change the description of OpGenericCastToPtrExplicit to:
Change the description of OpBitcast to:
Change the description of Pointer in OpLifetimeStart and OpLifetimeStop to:
Change the description of Pointer in OpAtomicLoad to:
Change the description of Pointer in OpAtomicStore to:
Change the description of Value in OpAtomicExchange to:
Change the description of Value in OpAtomicCompareExchange to:
Change the description of Value in OpAtomicIIncrement, OpAtomicIDecrement, OpAtomicIAdd, OpAtomicISub, OpAtomicSMin, OpAtomicUMin, OpAtomicSMax, OpAtomicUMax, OpAtomicAnd, OpAtomicOr, and OpAtomicXor to:
Add the following instruction to Section 3.37.6 Type-Declaration Instructions:
Add the following instructions to Section 3.37.8 Memory Instructions:
OpUntypedVariableKHR |
Capability: |
|||||
4 + variable |
4418 |
<id> Result Type |
Result <id> |
Storage Class |
Optional <id> Data Type |
Optional <id> Initializer |
OpUntypedAccessChainKHR |
Capability: |
|||||
5 + variable |
4419 |
<id> Result Type |
Result <id> |
<id> Base Type |
<id> Base |
<id>, <id>, … |
OpUntypedInBoundsAccessChainKHR |
Capability: |
|||||
5 + variable |
4420 |
<id> Result Type |
Result <id> |
<id> Base Type |
<id> Base |
<id>, <id>, … |
OpUntypedPtrAccessChainKHR |
Capability: |
||||||
6 + variable |
4423 |
<id> Result Type |
Result <id> |
<id> Base Type |
<id> Base |
<id> Element |
<id>, <id>, … |
OpUntypedInBoundsPtrAccessChainKHR |
Capability: |
||||||
6 + variable |
4424 |
<id> Result Type |
Result <id> |
<id> Base Type |
<id> Base |
<id> Element |
<id>, <id>, … |
OpUntypedArrayLengthKHR |
Capability: |
|||||
6 |
4425 |
<id> Result Type |
Result <id> |
<id> Structure |
<id> Pointer |
Literal Array member |
OpUntypedPrefetchKHR |
Capability: |
|||||
3 + variable |
4426 |
<id> Pointer Type |
<id> Num Bytes |
Optional <id> RW |
Optional <id> Locality |
Optional <id> Cache Type |
Modifications to the extension SPV_KHR_workgroup_memory_explicit_layout
Change:
To:
Change:
To:
Modifications to the extension SPV_KHR_cooperative_matrix
In the descriptions of OpCooperativeMatrixLoadKHR and OpCooperativeMatrixStoreKHR change:
To:
And, change:
To:
Modifications to the OpenCL.std extended instruction set
Change the pointer naming conventions from:
To:
In the descriptions of the extended instructions, whenever a pointer operand is described as pointer(p1, p2, …) to data types, split the sentence into two as follows:
This applies to the following instructions:
-
ptr in fract
-
exp in frexp
-
signp in lgamma_r
-
iptr in modf
-
quo in remquo
-
cosval in sincos
-
p in vloadn
-
p in vstoren
-
p in vload_half
-
p in vload_halfn
-
p in vstore_half
-
p in vstore_half_r
-
p in vstore_halfn
-
p in vstore_halfn_r
-
p in vloada_halfn
-
p in vstorea_halfn
-
p in vstorea_halfn_r
-
format in printf
In the above instructions any type matching rule that applies to a pointee type is only applied to typed pointers. For untyped pointers, the instructions as if the it were an appropriate typed pointer.
Note: prefetch should be replaced with OpUntypedPrefetchKHR.
Issues
-
Should this extension modify any other extensions?
Resolved
This extension modifies SPV_KHR_workgroup_memory_explicit_layout and SPV_KHR_cooperative_matrix.
-
Should this extension include pointer access chain equivalents?
Resolved
OpUntypedPtrAccessChainKHR and OpUntypedInBoundsPtrAccessChainKHR are not strictly necessary. OpUntypedAccessChainKHR (or OpUntypedInBoundsAccessChainKHR) could be used in place in all cases by changing the Base Type to be an array instead of just the element type; however, to simplify implementation transitions these instructions are included.
-
Should this extension modify any extended instructions?
Resolved
This extension modifies the OpenCL.std extended instruction set. GLSL.std.450 is not modified as the interpolation instructions operate on the Input storage class and FrexpStruct and ModfStruct should be preferred to the version that utilize pointers.
Revision History
Rev |
Date |
Author |
Changes |
2 |
2024-08-08 |
Kevin Petit |
Clarify OpPtrDiff support |
1 |
2024-05-29 |
Alan Baker |
Initial Revision |