From 116f5b010f996d11713a6ebdb0073d85a505a6b7 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sat, 7 Jun 2025 14:15:40 -0700 Subject: [PATCH] saving --- lib/sdl3/src/samples/hello-triangle.zig | 54 ++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/sdl3/src/samples/hello-triangle.zig b/lib/sdl3/src/samples/hello-triangle.zig index bc47227..0863874 100644 --- a/lib/sdl3/src/samples/hello-triangle.zig +++ b/lib/sdl3/src/samples/hello-triangle.zig @@ -92,17 +92,17 @@ pub fn startContext(self: *@This()) !void { pci.rasterizer_state.fill_mode = .fillmodeFill; self.pipeline = self.device.createGPUGraphicsPipeline(&pci); - // self.colorBuffer = self.device.createGPUBuffer(&.{ - // .usage = .{ .bufferusageVertex = true, .bufferusageGraphicsStorageRead = true }, - // .size = 8192 * 2, - // .props = 0, - // }); + self.colorBuffer = self.device.createGPUBuffer(&.{ + .usage = .{ .bufferusageVertex = true, .bufferusageGraphicsStorageRead = true }, + .size = 8192 * 2, + .props = 0, + }); - // self.colorBufferTransfer = self.device.createGPUTransferBuffer(&.{ - // .usage = .transferbufferusageUpload, - // .size = 8192 * 2, - // .props = 0, - // }); + self.colorBufferTransfer = self.device.createGPUTransferBuffer(&.{ + .usage = .transferbufferusageUpload, + .size = 8192 * 2, + .props = 0, + }); } pub fn loadFileAlloc(filename: []const u8, comptime alignment: usize, allocator: std.mem.Allocator) ![]u8 { @@ -182,27 +182,27 @@ pub fn draw(self: *@This(), dt: f64) void { const cmd = self.device.acquireGPUCommandBuffer(); var swapchain_texture: *gpu.GPUTexture = undefined; - // { - // const buffer = self.device.mapGPUTransferBuffer(self.colorBufferTransfer, true); + { + const buffer = self.device.mapGPUTransferBuffer(self.colorBufferTransfer, true); - // var b: [*][4]f32 = @ptrCast(@alignCast(buffer)); + var b: [*][4]f32 = @ptrCast(@alignCast(buffer)); - // b[0] = .{ @floatCast(std.math.sin(self.totalTime * 3 * 2 + 0.8) * 0.2 + 0.8), 0.4, 0.4, 1.0 }; - // b[1] = .{ 0.4, @floatCast(std.math.sin(self.totalTime * 2 * 2 + 0.3) * 0.2 + 0.8), 0.4, 1.0 }; - // b[2] = .{ 0.4, 0.4, @floatCast(std.math.sin(self.totalTime * 4 * 2) * 0.2 + 0.8), 1.0 }; + b[0] = .{ @floatCast(std.math.sin(self.totalTime * 3 * 2 + 0.8) * 0.2 + 0.8), 0.4, 0.4, 1.0 }; + b[1] = .{ 0.4, @floatCast(std.math.sin(self.totalTime * 2 * 2 + 0.3) * 0.2 + 0.8), 0.4, 1.0 }; + b[2] = .{ 0.4, 0.4, @floatCast(std.math.sin(self.totalTime * 4 * 2) * 0.2 + 0.8), 1.0 }; - // self.device.unmapGPUTransferBuffer(self.colorBufferTransfer); - // } + self.device.unmapGPUTransferBuffer(self.colorBufferTransfer); + } - // { - // const copyPass = cmd.beginGPUCopyPass(); - // defer copyPass.endGPUCopyPass(); - // copyPass.uploadToGPUBuffer(&.{ .transfer_buffer = self.colorBufferTransfer, .offset = 0 }, &.{ - // .buffer = self.colorBuffer, - // .offset = 0, - // .size = 4 * 12, - // }, true); - // } + { + const copyPass = cmd.beginGPUCopyPass(); + defer copyPass.endGPUCopyPass(); + copyPass.uploadToGPUBuffer(&.{ .transfer_buffer = self.colorBufferTransfer, .offset = 0 }, &.{ + .buffer = self.colorBuffer, + .offset = 0, + .size = 4 * 12, + }, true); + } if (cmd.waitAndAcquireGPUSwapchainTexture(self.window, &swapchain_texture, null, null)) { var targetInfo: gpu.GPUColorTargetInfo = std.mem.zeroes(gpu.GPUColorTargetInfo);