diff options
| author | Robin Voetter <robin@voetter.nl> | 2024-10-27 16:31:45 +0100 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2024-10-27 16:31:45 +0100 |
| commit | 49a067ccfe6cc3ee59b0fe0f2dc32f80ab75d574 (patch) | |
| tree | 349a61aee17121afb7a63e37c6ce4c49073ab8cb /src/target.zig | |
| parent | 39013619b943956f0c26422a01f026d845dc96a9 (diff) | |
| download | zig-49a067ccfe6cc3ee59b0fe0f2dc32f80ab75d574.tar.gz zig-49a067ccfe6cc3ee59b0fe0f2dc32f80ab75d574.zip | |
spirv: forbid merging logical pointers
Under some architecture/operating system combinations it is forbidden
to return a pointer from a merge, as these pointers must point to a
location at compile time. This adds a check for those cases when
returning a pointer from a block merge.
Diffstat (limited to 'src/target.zig')
| -rw-r--r-- | src/target.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/target.zig b/src/target.zig index 1f8a567f03..b0d2bdfe74 100644 --- a/src/target.zig +++ b/src/target.zig @@ -398,6 +398,31 @@ pub fn addrSpaceCastIsValid( } } +/// Under SPIR-V with Vulkan, pointers are not 'real' (physical), but rather 'logical'. Effectively, +/// this means that all such pointers have to be resolvable to a location at compile time, and places +/// a number of restrictions on usage of such pointers. For example, a logical pointer may not be +/// part of a merge (result of a branch) and may not be stored in memory at all. This function returns +/// for a particular architecture and address space wether such pointers are logical. +pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool { + if (target.os.tag != .vulkan) { + return false; + } + + return switch (as) { + // TODO: Vulkan doesn't support pointers in the generic address space, we + // should remove this case but this requires a change in defaultAddressSpace(). + // For now, at least disable them from being regarded as physical. + .generic => true, + // For now, all global pointers are represented using PhysicalStorageBuffer, so these are real + // pointers. + .global => false, + // TODO: Allowed with VK_KHR_variable_pointers. + .shared => true, + .constant, .local, .input, .output, .uniform => true, + else => unreachable, + }; +} + pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 { // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc |
