This commit is contained in:
peterino2 2025-06-07 14:15:40 -07:00
parent 6f2396c814
commit 116f5b010f
1 changed files with 27 additions and 27 deletions

View File

@ -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);