working on vertex implementation
This commit is contained in:
+49
-1
@@ -16,6 +16,16 @@ owner: *Device,
|
||||
vtable: *const VTable,
|
||||
bind_point: vk.PipelineBindPoint,
|
||||
stages: vk.ShaderStageFlags,
|
||||
mode: union(enum) {
|
||||
compute: struct {},
|
||||
graphics: struct {
|
||||
input_assembly: struct {
|
||||
binding_description: ?[]vk.VertexInputBindingDescription,
|
||||
attribute_description: ?[]vk.VertexInputAttributeDescription,
|
||||
topology: vk.PrimitiveTopology,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
pub const VTable = struct {
|
||||
destroy: *const fn (*Self, std.mem.Allocator) void,
|
||||
@@ -30,11 +40,11 @@ pub fn initCompute(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipel
|
||||
.vtable = undefined,
|
||||
.bind_point = .compute,
|
||||
.stages = info.stage.stage,
|
||||
.mode = .{ .compute = .{} },
|
||||
};
|
||||
}
|
||||
|
||||
pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*PipelineCache, info: *const vk.GraphicsPipelineCreateInfo) VkError!Self {
|
||||
_ = allocator;
|
||||
_ = cache;
|
||||
|
||||
var stages: vk.ShaderStageFlags = .{};
|
||||
@@ -49,9 +59,47 @@ pub fn initGraphics(device: *Device, allocator: std.mem.Allocator, cache: ?*Pipe
|
||||
.vtable = undefined,
|
||||
.bind_point = .graphics,
|
||||
.stages = stages,
|
||||
.mode = .{
|
||||
.graphics = .{
|
||||
.input_assembly = .{
|
||||
.binding_description = blk: {
|
||||
if (info.p_vertex_input_state) |vertex_input_state| {
|
||||
if (vertex_input_state.p_vertex_binding_descriptions) |vertex_binding_descriptions| {
|
||||
break :blk allocator.dupe(vk.VertexInputBindingDescription, vertex_binding_descriptions[0..vertex_input_state.vertex_binding_description_count]) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
} else {
|
||||
return VkError.ValidationFailed;
|
||||
}
|
||||
break :blk null;
|
||||
},
|
||||
.attribute_description = blk: {
|
||||
if (info.p_vertex_input_state) |vertex_input_state| {
|
||||
if (vertex_input_state.p_vertex_attribute_descriptions) |vertex_attribute_descriptions| {
|
||||
break :blk allocator.dupe(vk.VertexInputAttributeDescription, vertex_attribute_descriptions[0..vertex_input_state.vertex_attribute_description_count]) catch return VkError.OutOfHostMemory;
|
||||
}
|
||||
} else {
|
||||
return VkError.ValidationFailed;
|
||||
}
|
||||
break :blk null;
|
||||
},
|
||||
.topology = if (info.p_input_assembly_state) |state| state.topology else return VkError.ValidationFailed,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
switch (self.mode) {
|
||||
.compute => {},
|
||||
.graphics => |graphics| {
|
||||
if (graphics.input_assembly.binding_description) |binding_description| {
|
||||
allocator.free(binding_description);
|
||||
}
|
||||
if (graphics.input_assembly.attribute_description) |attribute_description| {
|
||||
allocator.free(attribute_description);
|
||||
}
|
||||
},
|
||||
}
|
||||
self.vtable.destroy(self, allocator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user