No more staging buffer; generic buffer doubles as staging
This commit is contained in:
22
src/Game.zig
22
src/Game.zig
@@ -21,7 +21,6 @@ const Iterator2 = math.Iterator2;
|
||||
const Materials = @import("engine/Materials.zig");
|
||||
const Player = @import("Player.zig");
|
||||
const Skybox = @import("engine/Skybox.zig");
|
||||
const StagingBuffer = @import("engine/StagingBuffer.zig");
|
||||
const Swapchain = @import("engine/Swapchain.zig");
|
||||
const Texture = @import("engine/Texture.zig");
|
||||
const Textures = @import("engine/Textures.zig");
|
||||
@@ -37,7 +36,8 @@ vertex_buffer: shaders.VertexBuffer,
|
||||
index_buffer: shaders.IndexBuffer,
|
||||
|
||||
global_uniforms: shaders.GlobalUniformsBuffer,
|
||||
global_uniforms_staging_buffer: StagingBuffer,
|
||||
global_uniforms_staging_buffer: shaders.GlobalUniformsBuffer,
|
||||
global_uniforms_staging_ptr: *shaders.GlobalUniforms,
|
||||
global_uniforms_transfer_semaphores: []vk.Semaphore,
|
||||
point_lights: shaders.PointLightBuffer,
|
||||
directional_lights: shaders.DirectionalLightBuffer,
|
||||
@@ -221,12 +221,17 @@ pub fn init() !Game {
|
||||
});
|
||||
errdefer global_uniforms.deinit();
|
||||
|
||||
var global_uniforms_staging_buffer = try StagingBuffer.init(.{
|
||||
.capacity = @sizeOf(shaders.GlobalUniforms),
|
||||
var global_uniforms_staging_buffer = try shaders.GlobalUniformsBuffer.init(.{
|
||||
.usage = .staging,
|
||||
.target_queue = .graphics,
|
||||
.mappable = true,
|
||||
.name = "GlobalUniforms Staging",
|
||||
});
|
||||
errdefer global_uniforms_staging_buffer.deinit();
|
||||
|
||||
const global_uniforms_staging_ptr = try global_uniforms_staging_buffer.map();
|
||||
errdefer global_uniforms_staging_buffer.unmap();
|
||||
|
||||
const global_uniforms_transfer_semaphores = blk: {
|
||||
var semaphores: std.ArrayList(vk.Semaphore) = try .initCapacity(allocator_general, swapchain.swapchain_images.len);
|
||||
errdefer semaphores.deinit(allocator_general);
|
||||
@@ -744,6 +749,7 @@ pub fn init() !Game {
|
||||
|
||||
.global_uniforms = global_uniforms,
|
||||
.global_uniforms_staging_buffer = global_uniforms_staging_buffer,
|
||||
.global_uniforms_staging_ptr = global_uniforms_staging_ptr,
|
||||
.global_uniforms_transfer_semaphores = global_uniforms_transfer_semaphores,
|
||||
.point_lights = point_lights,
|
||||
.directional_lights = directional_lights,
|
||||
@@ -776,6 +782,7 @@ pub fn deinit(self: *Game) void {
|
||||
self.skybox.deinit();
|
||||
|
||||
self.global_uniforms.deinit();
|
||||
self.global_uniforms_staging_buffer.unmap();
|
||||
self.global_uniforms_staging_buffer.deinit();
|
||||
self.point_lights.deinit();
|
||||
self.directional_lights.deinit();
|
||||
@@ -901,7 +908,7 @@ fn render(self: *Game) !void {
|
||||
|
||||
const ambient_light = vm.Vector3.init(0.01, 0.01, 0.01);
|
||||
|
||||
const global_uniforms_data: shaders.GlobalUniforms = .{
|
||||
self.global_uniforms_staging_ptr.* = .{
|
||||
.matrixWStoVS = matrix_ws_to_vs,
|
||||
.matrixVStoCS = matrix_vs_to_cs,
|
||||
.matrixSSPXtoCS = matrix_sspx_to_cs,
|
||||
@@ -910,10 +917,7 @@ fn render(self: *Game) !void {
|
||||
.directionalLightCount = directional_lights_data.len,
|
||||
.ambientLight = ambient_light,
|
||||
};
|
||||
|
||||
const staging_memory = try self.global_uniforms_staging_buffer.map();
|
||||
@memcpy(staging_memory, std.mem.asBytes(&global_uniforms_data));
|
||||
self.global_uniforms_staging_buffer.unmap();
|
||||
try self.global_uniforms_staging_buffer.flush(0, 1);
|
||||
|
||||
try self.deferred_command_buffers.ensureUnusedCapacity(allocator_general, 1);
|
||||
const global_uniforms_transfer_command_buffer = try CommandBuffer.init(.transfer);
|
||||
|
||||
Reference in New Issue
Block a user