create pipeline
This commit is contained in:
111
src/main.zig
111
src/main.zig
@@ -232,6 +232,117 @@ pub fn main() !void {
|
|||||||
_ = im.c.ImGui_ImplVulkan_CreateFontsTexture();
|
_ = im.c.ImGui_ImplVulkan_CreateFontsTexture();
|
||||||
defer im.c.ImGui_ImplVulkan_Shutdown();
|
defer im.c.ImGui_ImplVulkan_Shutdown();
|
||||||
|
|
||||||
|
const vert = try au.D.createShaderModule(&vk.ShaderModuleCreateInfo{
|
||||||
|
.code_size = shaders.triangle_vert.len,
|
||||||
|
.p_code = @ptrCast(&shaders.triangle_vert),
|
||||||
|
}, null);
|
||||||
|
defer au.D.destroyShaderModule(vert, null);
|
||||||
|
|
||||||
|
const frag = try au.D.createShaderModule(&vk.ShaderModuleCreateInfo{
|
||||||
|
.code_size = shaders.triangle_frag.len,
|
||||||
|
.p_code = @ptrCast(&shaders.triangle_frag),
|
||||||
|
}, null);
|
||||||
|
defer au.D.destroyShaderModule(frag, null);
|
||||||
|
|
||||||
|
const cache = try au.D.createPipelineCache(&vk.PipelineCacheCreateInfo{}, null);
|
||||||
|
defer au.D.destroyPipelineCache(cache, null);
|
||||||
|
|
||||||
|
const layout = try au.D.createPipelineLayout(&vk.PipelineLayoutCreateInfo{
|
||||||
|
// todo
|
||||||
|
}, null);
|
||||||
|
defer au.D.destroyPipelineLayout(layout, null);
|
||||||
|
|
||||||
|
const gpci: vk.GraphicsPipelineCreateInfo = .{
|
||||||
|
.stage_count = 2,
|
||||||
|
.p_stages = &.{
|
||||||
|
vk.PipelineShaderStageCreateInfo{ .stage = .{ .vertex_bit = true }, .module = vert, .p_name = "main" },
|
||||||
|
vk.PipelineShaderStageCreateInfo{ .stage = .{ .fragment_bit = true }, .module = frag, .p_name = "main" },
|
||||||
|
},
|
||||||
|
.p_vertex_input_state = &vk.PipelineVertexInputStateCreateInfo{
|
||||||
|
.vertex_binding_description_count = 1,
|
||||||
|
.p_vertex_binding_descriptions = @ptrCast(&Vertex.binding_description),
|
||||||
|
.vertex_attribute_description_count = Vertex.attribute_description.len,
|
||||||
|
.p_vertex_attribute_descriptions = &Vertex.attribute_description,
|
||||||
|
},
|
||||||
|
.p_input_assembly_state = &vk.PipelineInputAssemblyStateCreateInfo{
|
||||||
|
.topology = .triangle_list,
|
||||||
|
.primitive_restart_enable = vk.FALSE,
|
||||||
|
},
|
||||||
|
.p_tessellation_state = null,
|
||||||
|
.p_viewport_state = &vk.PipelineViewportStateCreateInfo{
|
||||||
|
.viewport_count = 1,
|
||||||
|
.scissor_count = 1,
|
||||||
|
},
|
||||||
|
.p_rasterization_state = &vk.PipelineRasterizationStateCreateInfo{
|
||||||
|
.depth_clamp_enable = vk.FALSE,
|
||||||
|
.rasterizer_discard_enable = vk.FALSE,
|
||||||
|
.polygon_mode = .fill,
|
||||||
|
.cull_mode = .{ .back_bit = true },
|
||||||
|
.front_face = .counter_clockwise,
|
||||||
|
.depth_bias_enable = vk.FALSE,
|
||||||
|
.depth_bias_constant_factor = 0.0,
|
||||||
|
.depth_bias_clamp = 0.0,
|
||||||
|
.depth_bias_slope_factor = 0.0,
|
||||||
|
.line_width = 1.0,
|
||||||
|
},
|
||||||
|
.p_multisample_state = &vk.PipelineMultisampleStateCreateInfo{
|
||||||
|
.rasterization_samples = .{ .@"1_bit" = true },
|
||||||
|
.sample_shading_enable = vk.FALSE,
|
||||||
|
.min_sample_shading = 1,
|
||||||
|
.alpha_to_coverage_enable = vk.FALSE,
|
||||||
|
.alpha_to_one_enable = vk.FALSE,
|
||||||
|
},
|
||||||
|
.p_depth_stencil_state = null,
|
||||||
|
.p_color_blend_state = &vk.PipelineColorBlendStateCreateInfo{
|
||||||
|
.logic_op_enable = vk.FALSE,
|
||||||
|
.logic_op = .copy,
|
||||||
|
.blend_constants = [_]f32{ 0, 0, 0, 0 },
|
||||||
|
.attachment_count = 1,
|
||||||
|
.p_attachments = &.{
|
||||||
|
vk.PipelineColorBlendAttachmentState{
|
||||||
|
.blend_enable = vk.FALSE,
|
||||||
|
.color_blend_op = .add,
|
||||||
|
.src_color_blend_factor = .one,
|
||||||
|
.dst_color_blend_factor = .zero,
|
||||||
|
.alpha_blend_op = .add,
|
||||||
|
.src_alpha_blend_factor = .one,
|
||||||
|
.dst_alpha_blend_factor = .zero,
|
||||||
|
.color_write_mask = .{ .r_bit = true, .g_bit = true, .b_bit = true, .a_bit = true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.p_dynamic_state = &vk.PipelineDynamicStateCreateInfo{
|
||||||
|
.flags = .{},
|
||||||
|
.dynamic_state_count = 2,
|
||||||
|
.p_dynamic_states = &.{
|
||||||
|
.viewport,
|
||||||
|
.scissor,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.layout = layout,
|
||||||
|
.render_pass = .null_handle, // set via dynamic rendering
|
||||||
|
.subpass = 0,
|
||||||
|
.base_pipeline_handle = .null_handle,
|
||||||
|
.base_pipeline_index = -1,
|
||||||
|
.p_next = &vk.PipelineRenderingCreateInfo{
|
||||||
|
.color_attachment_count = 1,
|
||||||
|
.p_color_attachment_formats = &.{au.device_config.format.format},
|
||||||
|
.depth_attachment_format = .undefined,
|
||||||
|
.stencil_attachment_format = .undefined,
|
||||||
|
.view_mask = 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
var pipeline: vk.Pipeline = undefined;
|
||||||
|
_ = try au.D.createGraphicsPipelines(
|
||||||
|
cache,
|
||||||
|
1,
|
||||||
|
@ptrCast(&gpci),
|
||||||
|
null,
|
||||||
|
@ptrCast(&pipeline),
|
||||||
|
);
|
||||||
|
defer au.D.destroyPipeline(pipeline, null);
|
||||||
|
|
||||||
while (!au.W.should_close()) {
|
while (!au.W.should_close()) {
|
||||||
im.c.ImGui_ImplGlfw_NewFrame();
|
im.c.ImGui_ImplGlfw_NewFrame();
|
||||||
im.c.ImGui_ImplVulkan_NewFrame();
|
im.c.ImGui_ImplVulkan_NewFrame();
|
||||||
|
Reference in New Issue
Block a user