From 49a067ccfe6cc3ee59b0fe0f2dc32f80ab75d574 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Sun, 27 Oct 2024 16:31:45 +0100 Subject: 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. --- src/target.zig | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/target.zig') 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 -- cgit v1.2.3