adding descriptor sets injections to graphics stages
Test / build_and_test (push) Successful in 45s
Build / build (push) Successful in 1m18s

This commit is contained in:
2026-05-15 00:58:58 +02:00
parent d460f22a45
commit 134925a16e
9 changed files with 75 additions and 28 deletions
+16 -6
View File
@@ -98,18 +98,28 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, layout: *base.
return self;
}
pub fn copy(interface: *Interface, copy_data: vk.CopyDescriptorSet) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
_ = self;
_ = copy_data;
}
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
allocator.free(self.heap);
allocator.destroy(self);
}
pub fn copy(interface: *Interface, src_interface: *const Interface, data: vk.CopyDescriptorSet) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
const src: *const Self = @alignCast(@fieldParentPtr("interface", src_interface));
for (self.descriptors[data.dst_binding..(data.dst_binding + data.descriptor_count)], src.descriptors[data.src_binding..(data.src_binding + data.descriptor_count)]) |*dst_desc, src_desc| {
switch (dst_desc.*) {
.buffer => |dst_buffer| @memcpy(dst_buffer[0..], src_desc.buffer[0..]),
.image => |dst_image| @memcpy(dst_image[0..], src_desc.image[0..]),
else => {
dst_desc.* = .{ .unsupported = .{} };
base.unsupported("descriptor type for copy", .{});
},
}
}
}
pub fn write(interface: *Interface, write_data: vk.WriteDescriptorSet) VkError!void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
+1 -2
View File
@@ -174,8 +174,7 @@ fn writeDescriptorSets(self: *Self, rt: *spv.Runtime) !void {
switch (binding) {
.buffer => |buffer_data_array| for (buffer_data_array, 0..) |buffer_data, descriptor_index| {
if (buffer_data.object) |buffer| {
const memory = if (buffer.interface.memory) |memory| memory else continue :bindings;
const map: []u8 = @as([*]u8, @ptrCast(try memory.map(buffer_data.offset, buffer_data.size)))[0..buffer_data.size];
const map = buffer.mapAsSliceWithOffset(u8, buffer_data.offset, buffer_data.size) catch continue :bindings;
try rt.writeDescriptorSet(
map,
@as(u32, @intCast(set_index)),
+45
View File
@@ -179,6 +179,16 @@ fn drawCall(self: *Self, bounded_allocator: *BoundedAllocator, vertex_count: usi
logger.debug(fmt, args);
};
const pipeline = self.state.pipeline orelse return VkError.InvalidPipelineDrv;
const vertex_shader = pipeline.stages.getPtrAssertContains(.vertex);
for (vertex_shader.runtimes[0..]) |*runtime| {
writeDescriptorSets(&draw_call, &runtime.rt) catch return VkError.Unknown;
}
const fragment_shader = pipeline.stages.getPtrAssertContains(.fragment);
for (fragment_shader.runtimes[0..]) |*runtime| {
writeDescriptorSets(&draw_call, &runtime.rt) catch return VkError.Unknown;
}
self.vertexShaderStage(allocator, &draw_call, vertex_count, instance_count, first_vertex, first_instance, indices) catch |err| {
std.log.scoped(.@"Vertex stage").err("catched a '{s}'", .{@errorName(err)});
if (@errorReturnTrace()) |trace| {
@@ -297,3 +307,38 @@ fn resolveScissor(self: *Self, scissor_index: usize) VkError!vk.Rect2D {
return VkError.Unknown;
}
fn writeDescriptorSets(draw_call: *DrawCall, rt: *spv.Runtime) !void {
sets: for (draw_call.renderer.state.sets[0..], 0..) |set, set_index| {
if (set == null)
continue :sets;
bindings: for (set.?.descriptors[0..], 0..) |binding, binding_index| {
switch (binding) {
.buffer => |buffer_data_array| for (buffer_data_array, 0..) |buffer_data, descriptor_index| {
if (buffer_data.object) |buffer| {
const map = buffer.mapAsSliceWithOffset(u8, buffer_data.offset, buffer_data.size) catch continue :bindings;
try rt.writeDescriptorSet(
map,
@as(u32, @intCast(set_index)),
@as(u32, @intCast(binding_index)),
@as(u32, @intCast(descriptor_index)),
);
}
},
.image => |image_data_array| for (image_data_array, 0..) |image_data, descriptor_index| {
if (image_data.object) |image_view| {
const addr: usize = @intFromPtr(image_view);
try rt.writeDescriptorSet(
std.mem.asBytes(&addr),
@as(u32, @intCast(set_index)),
@as(u32, @intCast(binding_index)),
@as(u32, @intCast(descriptor_index)),
);
}
},
else => {},
}
}
}
}
+3
View File
@@ -48,5 +48,8 @@ pub fn shaderInvocation(allocator: std.mem.Allocator, draw_call: *Renderer.DrawC
var color = zm.f32x4s(0.0);
try rt.readOutput(std.mem.asBytes(&color), output_result);
try rt.flushDescriptorSets(allocator);
return std.math.clamp(color, zm.f32x4s(0.0), zm.f32x4s(1.0));
}
+2
View File
@@ -90,6 +90,8 @@ inline fn run(data: RunData) !void {
};
try rt.readOutput(output.outputs[location].?.blob, result_word);
}
try rt.flushDescriptorSets(data.allocator);
}
}