@@ -549,31 +549,35 @@ pub fn addrSpaceCastIsValid(
549549 }
550550}
551551
552- /// Under SPIR-V with Vulkan, pointers are not 'real' (physical), but rather 'logical'. Effectively,
553- /// this means that all such pointers have to be resolvable to a location at compile time, and places
554- /// a number of restrictions on usage of such pointers. For example, a logical pointer may not be
555- /// part of a merge (result of a branch) and may not be stored in memory at all. This function returns
556- /// for a particular architecture and address space wether such pointers are logical.
557- pub fn arePointersLogical (target : * const std.Target , as : AddressSpace ) bool {
552+ /// Returns whether pointer operations (arithmetic, indexing, etc.) should be blocked
553+ /// for the given address space on the target architecture.
554+ ///
555+ /// Under SPIR-V with Vulkan
556+ /// (a) all physical pointers (.physical_storage_buffer, .global) always support pointer operations,
557+ /// (b) by default logical pointers (.constant, .input, .output, etc.) never support operations
558+ /// (c) some logical pointers (.storage_buffer, .shared) do support operations when
559+ /// the VariablePointers capability is enabled (which enables OpPtrAccessChain).
560+ pub fn shouldBlockPointerOps (target : * const std.Target , as : AddressSpace ) bool {
558561 if (target .os .tag != .vulkan ) return false ;
559562
560563 return switch (as ) {
561564 // TODO: Vulkan doesn't support pointers in the generic address space, we
562565 // should remove this case but this requires a change in defaultAddressSpace().
563- // For now, at least disable them from being regarded as physical.
564566 .generic = > true ,
565567 // For now, all global pointers are represented using StorageBuffer or CrossWorkgroup,
566568 // so these are real pointers.
567- .global = > false ,
568- .physical_storage_buffer = > false ,
569+ // Physical pointers always support operations
570+ .global , .physical_storage_buffer = > false ,
571+ // Logical pointers that support operations with VariablePointers capability
569572 .shared = > ! target .cpu .features .isEnabled (@intFromEnum (std .Target .spirv .Feature .variable_pointers )),
573+ .storage_buffer = > ! target .cpu .features .isEnabled (@intFromEnum (std .Target .spirv .Feature .variable_pointers )),
574+ // Logical pointers that never support operations
570575 .constant ,
571576 .local ,
572577 .input ,
573578 .output ,
574579 .uniform ,
575580 .push_constant ,
576- .storage_buffer ,
577581 = > true ,
578582 else = > unreachable ,
579583 };
0 commit comments