authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-10-20 16:59:32+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2024-10-27 15:19:56+01:00
log7c6923136718aab50fc20a327e47c0c23517dda2
tree16bd1698bd9e8c6a3723e299331af4a97bac68bb
parent6de456c179d81b9118ecd26eb9d7c90213bac313
signaturebadge-check Signed by SSH key SHA256:ZS52FNyUv2WUXvO4njmVaFVO46RHojFuOrxRc4LuKzg

spirv: use PhysicalStorageBuffer64 for global pointers under vk

We can use real pointers with this storage class!!

2 files changed, 28 insertions(+), 11 deletions(-)

src/codegen/spirv.zig+7-2
......@@ -1843,11 +1843,16 @@ const NavGen = struct {
18431843 return switch (as) {
18441844 .generic => switch (target.os.tag) {
18451845 .vulkan => .Private,
1846 else => .Generic,
1846 .opencl => .Generic,
1847 else => unreachable,
18471848 },
18481849 .shared => .Workgroup,
18491850 .local => .Private,
1850 .global => .CrossWorkgroup,
1851 .global => switch (target.os.tag) {
1852 .opencl => .CrossWorkgroup,
1853 .vulkan => .PhysicalStorageBuffer,
1854 else => unreachable,
1855 },
18511856 .constant => .UniformConstant,
18521857 .input => .Input,
18531858 .output => .Output,
src/link/SpirV.zig+21-9
......@@ -296,9 +296,8 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {
296296 // TODO: Integrate with a hypothetical feature system
297297 const caps: []const spec.Capability = switch (target.os.tag) {
298298 .opencl => &.{ .Kernel, .Addresses, .Int8, .Int16, .Int64, .Float64, .Float16, .Vector16, .GenericPointer },
299 .opengl => &.{.Shader},
300 .vulkan => &.{ .Shader, .VariablePointersStorageBuffer, .Int8, .Int16, .Int64, .Float64, .Float16 },
301 else => unreachable, // TODO
299 .vulkan => &.{ .Shader, .PhysicalStorageBufferAddresses, .StoragePushConstant16, .Int8, .Int16, .Int64, .Float64, .Float16 },
300 else => unreachable,
302301 };
303302
304303 for (caps) |cap| {
......@@ -306,19 +305,32 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {
306305 .capability = cap,
307306 });
308307 }
308
309 switch (target.os.tag) {
310 .vulkan => {
311 try spv.sections.extensions.emit(gpa, .OpExtension, .{
312 .name = "SPV_KHR_physical_storage_buffer",
313 });
314 },
315 else => {},
316 }
309317}
310318
311319fn writeMemoryModel(spv: *SpvModule, target: std.Target) !void {
312320 const gpa = spv.gpa;
313321
314 const addressing_model = switch (target.os.tag) {
322 const addressing_model: spec.AddressingModel = switch (target.os.tag) {
315323 .opencl => switch (target.cpu.arch) {
316 .spirv32 => spec.AddressingModel.Physical32,
317 .spirv64 => spec.AddressingModel.Physical64,
318 else => unreachable, // TODO
324 .spirv32 => .Physical32,
325 .spirv64 => .Physical64,
326 else => unreachable,
327 },
328 .opengl, .vulkan => switch (target.cpu.arch) {
329 .spirv32 => .Logical, // TODO: I don't think this will ever be implemented.
330 .spirv64 => .PhysicalStorageBuffer64,
331 else => unreachable,
319332 },
320 .opengl, .vulkan => spec.AddressingModel.Logical,
321 else => unreachable, // TODO
333 else => unreachable,
322334 };
323335
324336 const memory_model: spec.MemoryModel = switch (target.os.tag) {