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 {...@@ -1843,11 +1843,16 @@ const NavGen = struct {
1843 return switch (as) {1843 return switch (as) {
1844 .generic => switch (target.os.tag) {1844 .generic => switch (target.os.tag) {
1845 .vulkan => .Private,1845 .vulkan => .Private,
1846 else => .Generic,1846 .opencl => .Generic,
1847 else => unreachable,
1847 },1848 },
1848 .shared => .Workgroup,1849 .shared => .Workgroup,
1849 .local => .Private,1850 .local => .Private,
1850 .global => .CrossWorkgroup,1851 .global => switch (target.os.tag) {
1852 .opencl => .CrossWorkgroup,
1853 .vulkan => .PhysicalStorageBuffer,
1854 else => unreachable,
1855 },
1851 .constant => .UniformConstant,1856 .constant => .UniformConstant,
1852 .input => .Input,1857 .input => .Input,
1853 .output => .Output,1858 .output => .Output,
src/link/SpirV.zig+21-9
...@@ -296,9 +296,8 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {...@@ -296,9 +296,8 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {
296 // TODO: Integrate with a hypothetical feature system296 // TODO: Integrate with a hypothetical feature system
297 const caps: []const spec.Capability = switch (target.os.tag) {297 const caps: []const spec.Capability = switch (target.os.tag) {
298 .opencl => &.{ .Kernel, .Addresses, .Int8, .Int16, .Int64, .Float64, .Float16, .Vector16, .GenericPointer },298 .opencl => &.{ .Kernel, .Addresses, .Int8, .Int16, .Int64, .Float64, .Float16, .Vector16, .GenericPointer },
299 .opengl => &.{.Shader},299 .vulkan => &.{ .Shader, .PhysicalStorageBufferAddresses, .StoragePushConstant16, .Int8, .Int16, .Int64, .Float64, .Float16 },
300 .vulkan => &.{ .Shader, .VariablePointersStorageBuffer, .Int8, .Int16, .Int64, .Float64, .Float16 },300 else => unreachable,
301 else => unreachable, // TODO
302 };301 };
303302
304 for (caps) |cap| {303 for (caps) |cap| {
...@@ -306,19 +305,32 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {...@@ -306,19 +305,32 @@ fn writeCapabilities(spv: *SpvModule, target: std.Target) !void {
306 .capability = cap,305 .capability = cap,
307 });306 });
308 }307 }
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 }
309}317}
310318
311fn writeMemoryModel(spv: *SpvModule, target: std.Target) !void {319fn writeMemoryModel(spv: *SpvModule, target: std.Target) !void {
312 const gpa = spv.gpa;320 const gpa = spv.gpa;
313321
314 const addressing_model = switch (target.os.tag) {322 const addressing_model: spec.AddressingModel = switch (target.os.tag) {
315 .opencl => switch (target.cpu.arch) {323 .opencl => switch (target.cpu.arch) {
316 .spirv32 => spec.AddressingModel.Physical32,324 .spirv32 => .Physical32,
317 .spirv64 => spec.AddressingModel.Physical64,325 .spirv64 => .Physical64,
318 else => unreachable, // TODO326 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,
319 },332 },
320 .opengl, .vulkan => spec.AddressingModel.Logical,333 else => unreachable,
321 else => unreachable, // TODO
322 };334 };
323335
324 const memory_model: spec.MemoryModel = switch (target.os.tag) {336 const memory_model: spec.MemoryModel = switch (target.os.tag) {