yes
This commit is contained in:
+48
-10
@@ -19,10 +19,12 @@ const Self = @This();
|
||||
|
||||
pub const GRAPHICS_PIPELINE_STATE = 0;
|
||||
pub const COMPUTE_PIPELINE_STATE = 1;
|
||||
pub const MAX_DYNAMIC_DESCRIPTORS_PER_SET = 64;
|
||||
|
||||
pub const PipelineState = struct {
|
||||
pipeline: ?*SoftPipeline,
|
||||
sets: [base.VULKAN_MAX_DESCRIPTOR_SETS]?*SoftDescriptorSet,
|
||||
dynamic_offsets: [base.VULKAN_MAX_DESCRIPTOR_SETS][MAX_DYNAMIC_DESCRIPTORS_PER_SET]u32,
|
||||
push_constant_blob: [lib.PUSH_CONSTANT_SIZE]u8,
|
||||
data: union {
|
||||
compute: struct {},
|
||||
@@ -45,6 +47,7 @@ pub fn setup(self: *Self, device: *SoftDevice) void {
|
||||
state.* = .{
|
||||
.pipeline = null,
|
||||
.sets = [_]?*SoftDescriptorSet{null} ** base.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||
.dynamic_offsets = [_][MAX_DYNAMIC_DESCRIPTORS_PER_SET]u32{[_]u32{0} ** MAX_DYNAMIC_DESCRIPTORS_PER_SET} ** base.VULKAN_MAX_DESCRIPTOR_SETS,
|
||||
.push_constant_blob = @splat(0),
|
||||
.data = switch (i) {
|
||||
GRAPHICS_PIPELINE_STATE => .{
|
||||
@@ -71,37 +74,66 @@ pub fn writeDescriptorSets(state: *PipelineState, 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 map = buffer.mapAsSliceWithAddedOffset(u8, buffer_data.offset, buffer_data.size) catch continue :bindings;
|
||||
try rt.writeDescriptorSet(
|
||||
const binding_layout = set.?.interface.layout.bindings[binding_index];
|
||||
const dynamic_offset: vk.DeviceSize = switch (binding_layout.descriptor_type) {
|
||||
.uniform_buffer_dynamic, .storage_buffer_dynamic => state.dynamic_offsets[set_index][binding_layout.dynamic_index + descriptor_index],
|
||||
else => 0,
|
||||
};
|
||||
const map = buffer.mapAsSliceWithAddedOffset(u8, buffer_data.offset + dynamic_offset, buffer_data.size) catch continue :bindings;
|
||||
rt.writeDescriptorSet(
|
||||
map,
|
||||
@as(u32, @intCast(set_index)),
|
||||
@as(u32, @intCast(binding_index)),
|
||||
@as(u32, @intCast(descriptor_index)),
|
||||
);
|
||||
) catch |err| switch (err) {
|
||||
error.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
.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(
|
||||
rt.writeDescriptorSet(
|
||||
std.mem.asBytes(&addr),
|
||||
@as(u32, @intCast(set_index)),
|
||||
@as(u32, @intCast(binding_index)),
|
||||
@as(u32, @intCast(descriptor_index)),
|
||||
);
|
||||
) catch |err| switch (err) {
|
||||
error.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
.sampler => |sampler_data_array| for (sampler_data_array, 0..) |sampler_data, descriptor_index| {
|
||||
if (sampler_data.object) |sampler| {
|
||||
const addr: usize = @intFromPtr(sampler);
|
||||
rt.writeDescriptorSet(
|
||||
std.mem.asBytes(&addr),
|
||||
@as(u32, @intCast(set_index)),
|
||||
@as(u32, @intCast(binding_index)),
|
||||
@as(u32, @intCast(descriptor_index)),
|
||||
) catch |err| switch (err) {
|
||||
error.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
.texel_buffer => |texel_data_array| for (texel_data_array, 0..) |texel_data, descriptor_index| {
|
||||
if (texel_data.object) |buffer_view| {
|
||||
const addr: usize = @intFromPtr(buffer_view);
|
||||
try rt.writeDescriptorSet(
|
||||
rt.writeDescriptorSet(
|
||||
std.mem.asBytes(&addr),
|
||||
@as(u32, @intCast(set_index)),
|
||||
@as(u32, @intCast(binding_index)),
|
||||
@as(u32, @intCast(descriptor_index)),
|
||||
);
|
||||
) catch |err| switch (err) {
|
||||
error.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -111,7 +143,10 @@ pub fn writeDescriptorSets(state: *PipelineState, rt: *spv.Runtime) !void {
|
||||
sampler: usize,
|
||||
};
|
||||
|
||||
var data: SampledImage = undefined;
|
||||
var data: SampledImage = .{
|
||||
.image = 0,
|
||||
.sampler = 0,
|
||||
};
|
||||
|
||||
if (texture_data.view) |image_view| {
|
||||
const addr: usize = @intFromPtr(image_view);
|
||||
@@ -122,12 +157,15 @@ pub fn writeDescriptorSets(state: *PipelineState, rt: *spv.Runtime) !void {
|
||||
data.sampler = addr;
|
||||
}
|
||||
|
||||
try rt.writeDescriptorSet(
|
||||
rt.writeDescriptorSet(
|
||||
std.mem.asBytes(&data),
|
||||
@as(u32, @intCast(set_index)),
|
||||
@as(u32, @intCast(binding_index)),
|
||||
@as(u32, @intCast(descriptor_index)),
|
||||
);
|
||||
) catch |err| switch (err) {
|
||||
error.NotFound => {},
|
||||
else => return err,
|
||||
};
|
||||
},
|
||||
|
||||
else => {},
|
||||
|
||||
Reference in New Issue
Block a user