From d6edf7566b6e870e8aff927fcf6588b7c82ab5ae Mon Sep 17 00:00:00 2001 From: Andreew Gregory Date: Mon, 8 Dec 2025 19:57:46 +0300 Subject: [PATCH] Creating VkPipelines is not much easier --- src/l1/anne/lucy.h | 2 +- src/l1/anne/util_temp_very_base.h | 3 + src/l1/core/uint_segments.h | 5 + src/l1_5/anne/lucy.h | 4 +- src/l2/lucy/glyph_cache.h | 48 ++- src/l2/lucy/glyph_render.h | 52 +++ src/l2/margaret/vulkan_utils.h | 154 +++++++-- src/l2/tests/r0/r0.c | 550 +++++++----------------------- 8 files changed, 354 insertions(+), 464 deletions(-) create mode 100644 src/l2/lucy/glyph_render.h diff --git a/src/l1/anne/lucy.h b/src/l1/anne/lucy.h index 2a3352e..de57d28 100644 --- a/src/l1/anne/lucy.h +++ b/src/l1/anne/lucy.h @@ -11,7 +11,7 @@ void generate_l1_lucy_headers(){ .T = cstr("LucyImage"), .t_primitive = true}, true); generate_eve_span_company_for_primitive(l, ns, cstr("KVPU32ToLucyStoredGlyph"), true, false); generate_eve_span_company_for_primitive(l, ns, cstr("KVPU32ToLucyFaceFixedSize"), true, false); - + generate_eve_span_company_for_non_primitive_non_clonable(l, ns, cstr("LucyGlyphCachingRequest"), true, true); } #endif \ No newline at end of file diff --git a/src/l1/anne/util_temp_very_base.h b/src/l1/anne/util_temp_very_base.h index 5e071fb..5620da6 100644 --- a/src/l1/anne/util_temp_very_base.h +++ b/src/l1/anne/util_temp_very_base.h @@ -56,6 +56,9 @@ void generate_util_temp_very_base_headers() { generate_ResultType_templ_inst_guarded_header(cstr("l1"), cstr(""), cstr(""), cstr("SpanU8"), cstr("#include \"VecAndSpan_U8.h\""), true, true); + generate_guarded_span_company_for_primitive(cstr("l1"), cstr(""), cstr("U32Segment"), + cstr("#include \"../../src/l1/core/uint_segments.h\""), true, true); + /* Not very basic but definitely very common */ generate_guarded_span_company_for_non_primitive_clonable(cstr("l1"), cstr(""), cstr("TextureDataR8G8B8A8"), cstr("#include \"../../gen/l1/pixel_masses.h\"\n"), true, false); diff --git a/src/l1/core/uint_segments.h b/src/l1/core/uint_segments.h index ec78465..7628d04 100644 --- a/src/l1/core/uint_segments.h +++ b/src/l1/core/uint_segments.h @@ -8,6 +8,11 @@ typedef struct { U64 len; } U64Segment; +typedef struct{ + U32 start; + U32 len; +} U32Segment; + U64 U64Segment_get_length_resp_alignment(U64Segment self, U8 alignment_exp) { if (self.start & ((1ull << alignment_exp) - 1)) { U64 pad_left = (1ull << alignment_exp) - (self.start & ((1ull << alignment_exp) - 1)); diff --git a/src/l1_5/anne/lucy.h b/src/l1_5/anne/lucy.h index 6db735e..7504aca 100644 --- a/src/l1_5/anne/lucy.h +++ b/src/l1_5/anne/lucy.h @@ -8,8 +8,8 @@ void generate_l1_5_lucy_headers(){ mkdir_nofail("l1_5/eve/lucy"); generate_buf_rbtree_Map_templ_inst_eve_header(l, ns, (map_instantiation_op){ .K = cstr("U32"), .k_integer = true, .V = cstr("LucyStoredGlyph"), .v_primitive = true}); - generate_buf_rbtree_Map_templ_inst_eve_header(l, ns, (map_instantiation_op){ - .K = cstr("U32"), .k_integer = true, .V = cstr("LucyFaceFixedSize"), .v_primitive = true}); + generate_rbtree_Map_templ_inst_eve_header(l, ns, (map_instantiation_op){ + .K = cstr("U32"), .k_integer = true, .V = cstr("LucyFaceFixedSize"), .v_primitive = true}, true); } diff --git a/src/l2/lucy/glyph_cache.h b/src/l2/lucy/glyph_cache.h index e179a4e..14f106a 100644 --- a/src/l2/lucy/glyph_cache.h +++ b/src/l2/lucy/glyph_cache.h @@ -4,8 +4,7 @@ #include "../margaret/vulkan_utils.h" #include #include FT_FREETYPE_H - -/* Right now my glyph cache is static, but I am planning to change that */ +#include "../../../gen/l1/VecAndSpan_U32Segment.h" #include "../../l1_5/core/buff_rb_tree_node.h" @@ -33,16 +32,11 @@ typedef struct { BufRBTree_MapU32ToLucyStoredGlyph glyphs; } LucyFaceFixedSize; -typedef struct { - U32 key; - LucyFaceFixedSize value; -} KVPU64ToLucyFaceFixedSize; -#include "../../../gen/l1/eve/lucy/VecKVPU32ToLucyFaceFixedSize.h" -#include "../../../gen/l1_5/eve/lucy/BufRBTree_MapU32ToLucyFaceFixedSize.h" +#include "../../../gen/l1_5/eve/lucy/RBTree_MapU32ToLucyFaceFixedSize.h" typedef struct{ FT_Face ft_face; - BufRBTree_MapU32ToLucyFaceFixedSize sizes; + RBTree_MapU32ToLucyFaceFixedSize sizes; } LucyFace; typedef struct { @@ -50,14 +44,44 @@ typedef struct { VkCommandBuffer transfer_cmd_buffer; MargaretMAIterator staging_buffer; ListLucyImage images; + VkDescriptorSetLayout descriptor_set_layout; + VkDescriptorSet descriptor_set; } LucyGlyphCache; -LucyGlyphCache LucyGlyphCache_new(MargaretEngineReference ve){ - return (LucyGlyphCache){.ve = ve}; + +// todo: write +LucyGlyphCache LucyGlyphCache_new(MargaretEngineReference ve, VkCommandBuffer transfer_cmd_buffer, VkDescriptorSetLayout descriptor_set_layout){ + VkDescriptorSet descriptor_set = margaret_allocate_descriptor_set(ve.device, ve.descriptor_pool, descriptor_set_layout); + MargaretMAIterator staging_buffer = MargaretMemAllocatorRequests_alloc_buf(ve.host_visible_mem_requests, 8192, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, false); + return (LucyGlyphCache){.ve = ve, .transfer_cmd_buffer = transfer_cmd_buffer, .staging_buffer = staging_buffer, + .images = ListLucyImage_new(), .descriptor_set_layout = descriptor_set_layout, .descriptor_set = descriptor_set}; } -void LucyGlyphCache_add_glyphs(){ +typedef struct { + RBTreeNode_KVPU32ToLucyFaceFixedSize* sized_face; + VecU32Segment codepoint_ranges; +} LucyGlyphCachingRequest; +void LucyGlyphCachingRequest_drop(LucyGlyphCachingRequest self){ + VecU32Segment_drop(self.codepoint_ranges); +} + +#include "../../../gen/l1/eve/lucy/VecAndSpan_LucyGlyphCachingRequest.h" + +void LucyGlyphCache_add_glyphs(SpanLucyGlyphCachingRequest requests_for_faces){ + // todo: write it all + for (size_t fi = 0; fi < requests_for_faces.len; fi++) { + LucyGlyphCachingRequest req = requests_for_faces.data[fi]; + U32 font_height = req.sized_face->key; + BufRBTree_MapU32ToLucyStoredGlyph* glyph_set = &req.sized_face->value.glyphs; + for (size_t ri = 0; ri < req.codepoint_ranges.len; ri++) { + U32 range_start = req.codepoint_ranges.buf[ri].start; + U32 range_end = range_start + req.codepoint_ranges.buf[ri].len; + for (U32 codepoint = range_start; codepoint < range_end; codepoint++) { + // todo: render it all + } + } + } } void LucyGlyphCache_delete(LucyGlyphCache* self){ diff --git a/src/l2/lucy/glyph_render.h b/src/l2/lucy/glyph_render.h new file mode 100644 index 0000000..3939212 --- /dev/null +++ b/src/l2/lucy/glyph_render.h @@ -0,0 +1,52 @@ +#ifndef prototype1_src_l2_lucy_rendering_h +#define prototype1_src_l2_lucy_rendering_h + +#include "glyph_cache.h" + +typedef struct{ + LucyGlyphCache cache; + + VkPipelineLayout pipeline_layout; + VkPipeline pipeline; +} LucyGlyphRenderer; + +#define LUCY_MAX_DESCRIPTOR_COUNT 10 + +LucyGlyphRenderer LucyGlyphRenderer_new( + MargaretEngineReference engine_reference, VkCommandBuffer transfer_command_buffer, + VkRenderPass render_pass, U32 renderpass_subpass){ + VkDescriptorSetLayout descriptor_set_layout; + check(vkCreateDescriptorSetLayout(engine_reference.device, &(VkDescriptorSetLayoutCreateInfo){ + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + .bindingCount = 1, + .pBindings = (VkDescriptorSetLayoutBinding[]){{ + .binding = 0, + .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .descriptorCount = LUCY_MAX_DESCRIPTOR_COUNT, + .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, + }}, + }, NULL, &descriptor_set_layout) == VK_SUCCESS); + + + + LucyGlyphCache cache = LucyGlyphCache_new(engine_reference, transfer_command_buffer, descriptor_set_layout); + + VkPipelineLayout pipeline_layout; + check(vkCreatePipelineLayout(engine_reference.device, &(VkPipelineLayoutCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, + .setLayoutCount = 1, + .pSetLayouts = &descriptor_set_layout, + .pushConstantRangeCount = 1, + .pPushConstantRanges = (VkPushConstantRange[]){{ + .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .offset = 0, .size = sizeof(float) * 2 + }}, + }, NULL, &pipeline_layout) == VK_SUCCESS); + + /* Configuring font pipeline */ + + +// todo: create the actual pipeline + return (LucyGlyphRenderer){}; +} + +#endif \ No newline at end of file diff --git a/src/l2/margaret/vulkan_utils.h b/src/l2/margaret/vulkan_utils.h index da9daa9..c9858dd 100644 --- a/src/l2/margaret/vulkan_utils.h +++ b/src/l2/margaret/vulkan_utils.h @@ -821,34 +821,19 @@ void MargaretSwapchainBundle_drop_with_device(VkDevice device, MargaretSwapchain VkShaderModule margaret_VkShaderModule_new(VkDevice device, VecU8 code) { if (code.len < 4) abortf("Kill yourself, please\n"); - VkShaderModuleCreateInfo shad_mod_crinfo = { + VkShaderModule shad_module; + check(vkCreateShaderModule(device, &(VkShaderModuleCreateInfo){ .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, .codeSize = code.len, // Now this is funny, we can't put arbitrary byte-string here, it should be 4-byte aligned // Thanks goodness all the strings in VecU8 are allocated with calloc, which gives high alignment to // virtually everything .pCode = (const uint32_t*)code.buf - }; - VkShaderModule shad_module; - if (vkCreateShaderModule(device, &shad_mod_crinfo, NULL, &shad_module) != VK_SUCCESS) - abortf("vkCreateShaderModule\n"); + }, NULL, &shad_module) == VK_SUCCESS); + VecU8_drop(code); return shad_module; } -VkPipelineShaderStageCreateInfo margaret_shader_stage_vertex_crinfo(VkShaderModule module) { - return (VkPipelineShaderStageCreateInfo){ - .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .module = module, - .stage = VK_SHADER_STAGE_VERTEX_BIT, .pName = "main", - }; -} - -VkPipelineShaderStageCreateInfo margaret_shader_stage_fragment_crinfo(VkShaderModule module) { - return (VkPipelineShaderStageCreateInfo){ - .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .module = module, - .stage = VK_SHADER_STAGE_FRAGMENT_BIT, .pName = "main", - }; -} - VkCommandPool margaret_create_resettable_command_pool(VkDevice device, uint32_t wanted_queue_family) { VkCommandPoolCreateInfo crinfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -1012,8 +997,136 @@ void margaret_end_command_buffer(VkCommandBuffer command_buffer){ check(vkEndCommandBuffer(command_buffer) == VK_SUCCESS); } +VkPipelineShaderStageCreateInfo margaret_shader_stage_vertex_crinfo(VkShaderModule module) { + return (VkPipelineShaderStageCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .module = module, + .stage = VK_SHADER_STAGE_VERTEX_BIT, .pName = "main", + }; +} + +VkPipelineShaderStageCreateInfo margaret_shader_stage_fragment_crinfo(VkShaderModule module) { + return (VkPipelineShaderStageCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .module = module, + .stage = VK_SHADER_STAGE_FRAGMENT_BIT, .pName = "main", + }; +} + +typedef struct { + VkPipelineLayout pipeline_layout; + VecU8 vertex_shader_code; + VecU8 fragment_shader_code; + U32 vertexBindingDescriptionCount; + VkVertexInputBindingDescription* pVertexBindingDescriptions; + U32 vertexAttributeDescriptionCount; + VkVertexInputAttributeDescription* pVertexAttributeDescriptions; + bool depthTestEnable; + bool depthWriteEnable; + bool blendEnable; +} MargaretMostImportantPipelineOptions; + +VkPipeline margaret_create_triangle_pipeline_one_attachment( + VkDevice device, VkRenderPass render_pass, U32 renderpass_subpass, + MargaretMostImportantPipelineOptions op + ){ + + VkShaderModule vert_module = margaret_VkShaderModule_new(device, op.vertex_shader_code); + VkShaderModule frag_module = margaret_VkShaderModule_new(device, op.fragment_shader_code); + + + VkGraphicsPipelineCreateInfo pipeline_crinfo = { + .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .stageCount = 2, + .pStages = (VkPipelineShaderStageCreateInfo[]){ + margaret_shader_stage_vertex_crinfo(vert_module), + margaret_shader_stage_fragment_crinfo(frag_module) + }, + .pVertexInputState = &(VkPipelineVertexInputStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, + .vertexBindingDescriptionCount = op.vertexBindingDescriptionCount, + .pVertexBindingDescriptions = op.pVertexBindingDescriptions, + .vertexAttributeDescriptionCount = op.vertexAttributeDescriptionCount, + .pVertexAttributeDescriptions = op.pVertexAttributeDescriptions, + }, + .pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, + .primitiveRestartEnable = VK_FALSE, + }, + .pViewportState = &(VkPipelineViewportStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + // We are using dynamic viewport and scissors, that is why we do not attach viewport/scissor values + // when creating a rendering pipeline. We will do that later + .viewportCount = 1, + .scissorCount = 1, + }, + .pRasterizationState = &(VkPipelineRasterizationStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, + .depthClampEnable = VK_FALSE, + .polygonMode = VK_POLYGON_MODE_FILL, + // .cullMode = VK_CULL_MODE_BACK_BIT, + .cullMode = VK_CULL_MODE_NONE, + .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, + .depthBiasEnable = VK_FALSE, + .depthBiasConstantFactor = 0.0f, + .depthBiasClamp = 0.0f, + .depthBiasSlopeFactor = 0.0f, + .lineWidth = 1.0f, + }, + .pMultisampleState = &(VkPipelineMultisampleStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, + .sampleShadingEnable = VK_FALSE, + .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, + .minSampleShading = 1.0f, + .pSampleMask = NULL, + .alphaToCoverageEnable = VK_FALSE, + .alphaToOneEnable = VK_FALSE, + }, + .pDepthStencilState = &(VkPipelineDepthStencilStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, + .depthTestEnable = op.depthTestEnable, + .depthWriteEnable = op.depthWriteEnable, + .depthCompareOp = VK_COMPARE_OP_LESS + }, + .pColorBlendState = &(VkPipelineColorBlendStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, + .logicOpEnable = VK_FALSE, + .logicOp = VK_LOGIC_OP_COPY, + .attachmentCount = 1, + .pAttachments = &(VkPipelineColorBlendAttachmentState){ + .blendEnable = op.blendEnable, + .srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA, + .dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, + .colorBlendOp = VK_BLEND_OP_ADD, + .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, + .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, + .alphaBlendOp = VK_BLEND_OP_ADD, + .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | + VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT + }, + }, + .pDynamicState = &(VkPipelineDynamicStateCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = 2, + .pDynamicStates = (VkDynamicState[]){VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}, + }, + .layout = op.pipeline_layout, + .renderPass = render_pass, + .subpass = renderpass_subpass, + .basePipelineHandle = VK_NULL_HANDLE, + }; + + VkPipeline pipeline; + check(vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_crinfo, NULL, &pipeline) == VK_SUCCESS); + + vkDestroyShaderModule(device, frag_module, NULL); + vkDestroyShaderModule(device, vert_module, NULL); + return pipeline; +} + #include "vulkan_memory.h" +// todo: move image copying function here + // for users of memory that should be aware whether we are using two memory types or one typedef struct { VkDevice device; @@ -1022,8 +1135,7 @@ typedef struct { MargaretMemAllocator* device_local_mem; MargaretMemAllocatorRequests* device_local_mem_requests; bool device_local_is_host_visible; + VkDescriptorPool descriptor_pool; } MargaretEngineReference; -// todo: move image copying function here - #endif diff --git a/src/l2/tests/r0/r0.c b/src/l2/tests/r0/r0.c index 250137e..3cb46e5 100644 --- a/src/l2/tests/r0/r0.c +++ b/src/l2/tests/r0/r0.c @@ -13,7 +13,6 @@ #include "../../../../gen/l1/margaret/png_pixel_masses.h" #include "../../lucy/glyph_cache.h" -// todo: generate this structure in l2 typedef struct { VkPipelineLayout pipeline_layout; VkPipeline pipeline; @@ -27,7 +26,6 @@ void destroy_graphics_pipeline_hands(VkDevice device, PipelineHands hands) { vkDestroyDescriptorSetLayout(device, hands.descriptor_set_layout, NULL); } -// todo: generate this function in l2 VkRenderPass create_render_pass_0(VkDevice logical_device, VkFormat colorbuffer_format, VkFormat zbuffer_format) { VkAttachmentDescription all_attachments[2] = { { @@ -100,147 +98,6 @@ VkRenderPass create_render_pass_0(VkDevice logical_device, VkFormat colorbuffer_ PipelineHands create_graphics_pipeline_0( VkDevice device, VkRenderPass render_pass, uint32_t subpass ) { - VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/0/vert.spv"); - VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/0/frag.spv"); - VkShaderModule vert_module = margaret_VkShaderModule_new(device, vert_bin_code); - VkShaderModule frag_module = margaret_VkShaderModule_new(device, frag_bin_code); - VecU8_drop(vert_bin_code); - VecU8_drop(frag_bin_code); - - VkPipelineShaderStageCreateInfo shader_stages_crinfo[2] = { - margaret_shader_stage_vertex_crinfo(vert_module), - margaret_shader_stage_fragment_crinfo(frag_module) - }; - - VkVertexInputBindingDescription vertex_bindings[2] = { - { - .binding = 0, - .stride = sizeof(GenericMeshVertex), - .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, - }, - { - .binding = 1, - .stride = sizeof(GenericMeshInstance), - .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE, - } - }; - VkVertexInputAttributeDescription vertex_attributes[2 + 4] = { - { - .location = 0, - .binding = 0, - .format = VK_FORMAT_R32G32B32_SFLOAT, - .offset = offsetof(GenericMeshVertex, pos), - }, - { - .location = 1, - .binding = 0, - .format = VK_FORMAT_R32G32_SFLOAT, - .offset = offsetof(GenericMeshVertex, tex), - }, - - /* This is a mat4 datatype, so it will take 4 entire 'locations' */ - { - .location = 2, - .binding = 1, - .format = VK_FORMAT_R32G32B32A32_SFLOAT, - .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, x) - }, - { - .location = 3, - .binding = 1, - .format = VK_FORMAT_R32G32B32A32_SFLOAT, - .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, y) - }, - { - .location = 4, - .binding = 1, - .format = VK_FORMAT_R32G32B32A32_SFLOAT, - .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, z) - }, - { - .location = 5, - .binding = 1, - .format = VK_FORMAT_R32G32B32A32_SFLOAT, - .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, w) - }, - }; - - VkPipelineVertexInputStateCreateInfo vertex_input_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .vertexBindingDescriptionCount = ARRAY_SIZE(vertex_bindings), - .pVertexBindingDescriptions = vertex_bindings, - .vertexAttributeDescriptionCount = ARRAY_SIZE(vertex_attributes), - .pVertexAttributeDescriptions = vertex_attributes, - }; - - VkPipelineInputAssemblyStateCreateInfo input_assembly_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - .primitiveRestartEnable = VK_FALSE, - }; - - VkPipelineViewportStateCreateInfo viewport_state = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - // We are using dynamic viewport and scissors, that is why we do not attach viewport/scissor values - // when creating a rendering pipeline. We will do that later - .viewportCount = 1, - .scissorCount = 1, - }; - - VkPipelineRasterizationStateCreateInfo rasterizer_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .depthClampEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - // .cullMode = VK_CULL_MODE_BACK_BIT, - .cullMode = VK_CULL_MODE_NONE, - .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .depthBiasConstantFactor = 0.0f, - .depthBiasClamp = 0.0f, - .depthBiasSlopeFactor = 0.0f, - .lineWidth = 1.0f, - }; - - VkPipelineMultisampleStateCreateInfo multisampling_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .sampleShadingEnable = VK_FALSE, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .minSampleShading = 1.0f, - .pSampleMask = NULL, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; - - VkPipelineDepthStencilStateCreateInfo depth_stencil_state_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, - .depthTestEnable = VK_TRUE, - .depthWriteEnable = VK_TRUE, - .depthCompareOp = VK_COMPARE_OP_LESS - }; - - // For one framebuffer - VkPipelineColorBlendAttachmentState color_blend_attachments[1] = {(VkPipelineColorBlendAttachmentState){ - .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - .blendEnable = VK_FALSE, - }}; - - // For the entire pipeline - VkPipelineColorBlendStateCreateInfo color_blending_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = ARRAY_SIZE(color_blend_attachments), - .pAttachments = color_blend_attachments, - // Blend constants specified heres - }; - - VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; - VkPipelineDynamicStateCreateInfo dynamic_state_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .dynamicStateCount = ARRAY_SIZE(dynamic_states), - .pDynamicStates = dynamic_states, - }; - VkDescriptorSetLayoutBinding bindings_for_my_descr_set_layout[] = { { .binding = 0, @@ -299,47 +156,112 @@ PipelineHands create_graphics_pipeline_0( VkPipelineLayout pipeline_layout; if (vkCreatePipelineLayout(device, &layout_crinfo, NULL, &pipeline_layout) != VK_SUCCESS) abortf("vkCreatePipelineLayout"); - VkGraphicsPipelineCreateInfo pipeline_crinfo = { - .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, - .stageCount = ARRAY_SIZE(shader_stages_crinfo), - .pStages = shader_stages_crinfo, - .pVertexInputState = &vertex_input_crinfo, - .pInputAssemblyState = &input_assembly_crinfo, - .pViewportState = &viewport_state, - .pRasterizationState = &rasterizer_crinfo, - .pMultisampleState = &multisampling_crinfo, - .pDepthStencilState = &depth_stencil_state_crinfo, - .pColorBlendState = &color_blending_crinfo, - .pDynamicState = &dynamic_state_crinfo, - .layout = pipeline_layout, - .renderPass = render_pass, - .subpass = subpass, - .basePipelineHandle = VK_NULL_HANDLE, + + + VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/0/vert.spv"); + VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/0/frag.spv"); + + VkVertexInputBindingDescription vertex_bindings[2] = { + { + .binding = 0, + .stride = sizeof(GenericMeshVertex), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, + }, + { + .binding = 1, + .stride = sizeof(GenericMeshInstance), + .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE, + } + }; + VkVertexInputAttributeDescription vertex_attributes[2 + 4] = { + { + .location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32B32_SFLOAT, + .offset = offsetof(GenericMeshVertex, pos), + }, + { + .location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(GenericMeshVertex, tex), + }, + + /* This is a mat4 datatype, so it will take 4 entire 'locations' */ + { + .location = 2, + .binding = 1, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, x) + }, + { + .location = 3, + .binding = 1, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, y) + }, + { + .location = 4, + .binding = 1, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, z) + }, + { + .location = 5, + .binding = 1, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(GenericMeshInstance, model_t) + offsetof(mat4, w) + }, }; - VkPipeline pipeline; - if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_crinfo, NULL, &pipeline) != VK_SUCCESS) - abortf("vkCreateGraphicsPipelines"); - - vkDestroyShaderModule(device, frag_module, NULL); - vkDestroyShaderModule(device, vert_module, NULL); + VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(device, render_pass, subpass, + (MargaretMostImportantPipelineOptions){ + .pipeline_layout = pipeline_layout, + .vertex_shader_code = vert_bin_code, .fragment_shader_code = frag_bin_code, + .vertexBindingDescriptionCount = ARRAY_SIZE(vertex_bindings), vertex_bindings, + .vertexAttributeDescriptionCount = ARRAY_SIZE(vertex_attributes), vertex_attributes, + .depthTestEnable = true, .depthWriteEnable = true, .blendEnable = false + }); return (PipelineHands){.pipeline_layout = pipeline_layout, .pipeline = pipeline, .descriptor_set_layout = my_descriptor_set_layout}; } PipelineHands create_graphics_pipeline_0_b( VkDevice device, VkRenderPass render_pass, uint32_t subpass ) { + VkDescriptorSetLayout my_descriptor_set_layout; + check(vkCreateDescriptorSetLayout(device, &(VkDescriptorSetLayoutCreateInfo){ + .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, + .bindingCount = 1, + .pBindings = (VkDescriptorSetLayoutBinding[]){{ + .binding = 0, + .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, + .descriptorCount = 1, + .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, + }}, + }, NULL, &my_descriptor_set_layout) == VK_SUCCESS); + + VkPushConstantRange pc_ranges[] = { + { + .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, + .offset = 0, .size = sizeof(mat4) + }, + { + .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, + .offset = sizeof(mat4), .size = sizeof(vec3) + }}; + + VkPipelineLayout pipeline_layout; + check(vkCreatePipelineLayout(device, &(VkPipelineLayoutCreateInfo){ + .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, + .setLayoutCount = 1, + .pSetLayouts = (VkDescriptorSetLayout[]){my_descriptor_set_layout}, + .pushConstantRangeCount = ARRAY_SIZE(pc_ranges), + .pPushConstantRanges = pc_ranges, + }, NULL, &pipeline_layout) == VK_SUCCESS); + + VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/0b/vert.spv"); VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/0b/frag.spv"); - VkShaderModule vert_module = margaret_VkShaderModule_new(device, vert_bin_code); - VkShaderModule frag_module = margaret_VkShaderModule_new(device, frag_bin_code); - VecU8_drop(vert_bin_code); - VecU8_drop(frag_bin_code); - - VkPipelineShaderStageCreateInfo shader_stages_crinfo[2] = { - margaret_shader_stage_vertex_crinfo(vert_module), - margaret_shader_stage_fragment_crinfo(frag_module) - }; VkVertexInputBindingDescription vertex_bindings[2] = { { @@ -353,7 +275,7 @@ PipelineHands create_graphics_pipeline_0_b( .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE, } }; - VkVertexInputAttributeDescription vertex_attributes[2 + 6] = { + VkVertexInputAttributeDescription vertex_attributes[2 + 4 + 2] = { { .location = 0, .binding = 0, @@ -406,149 +328,19 @@ PipelineHands create_graphics_pipeline_0_b( }, }; - VkPipelineVertexInputStateCreateInfo vertex_input_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .vertexBindingDescriptionCount = ARRAY_SIZE(vertex_bindings), - .pVertexBindingDescriptions = vertex_bindings, - .vertexAttributeDescriptionCount = ARRAY_SIZE(vertex_attributes), - .pVertexAttributeDescriptions = vertex_attributes, - }; + VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(device, render_pass, subpass, + (MargaretMostImportantPipelineOptions){ + .pipeline_layout = pipeline_layout, + .vertex_shader_code = vert_bin_code, .fragment_shader_code = frag_bin_code, + .vertexBindingDescriptionCount = ARRAY_SIZE(vertex_bindings), vertex_bindings, + .vertexAttributeDescriptionCount = ARRAY_SIZE(vertex_attributes), vertex_attributes, + .depthTestEnable = true, .depthWriteEnable = true, .blendEnable = false + }); - VkPipelineInputAssemblyStateCreateInfo input_assembly_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - .primitiveRestartEnable = VK_FALSE, - }; - - VkPipelineViewportStateCreateInfo viewport_state = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .viewportCount = 1, - .scissorCount = 1, - }; - - VkPipelineRasterizationStateCreateInfo rasterizer_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .depthClampEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - // .cullMode = VK_CULL_MODE_BACK_BIT, - .cullMode = VK_CULL_MODE_NONE, - .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .depthBiasConstantFactor = 0.0f, - .depthBiasClamp = 0.0f, - .depthBiasSlopeFactor = 0.0f, - .lineWidth = 1.0f, - }; - - VkPipelineMultisampleStateCreateInfo multisampling_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .sampleShadingEnable = VK_FALSE, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .minSampleShading = 1.0f, - .pSampleMask = NULL, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; - - VkPipelineDepthStencilStateCreateInfo depth_stencil_state_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO, - .depthTestEnable = VK_TRUE, - .depthWriteEnable = VK_TRUE, - .depthCompareOp = VK_COMPARE_OP_LESS - }; - - // For one framebuffer - VkPipelineColorBlendAttachmentState color_blend_attachments[1] = {(VkPipelineColorBlendAttachmentState){ - .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - .blendEnable = VK_FALSE, - }}; - - // For the entire pipeline - VkPipelineColorBlendStateCreateInfo color_blending_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = ARRAY_SIZE(color_blend_attachments), - .pAttachments = color_blend_attachments, - // Blend constants specified heres - }; - - VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; - VkPipelineDynamicStateCreateInfo dynamic_state_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .dynamicStateCount = ARRAY_SIZE(dynamic_states), - .pDynamicStates = dynamic_states, - }; - - VkDescriptorSetLayoutBinding bindings_for_my_descr_set_layout[] = { - { - .binding = 0, - .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - // our shader variable is not an array of descriptors, so this stays 1 - .descriptorCount = 1, - .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, - }, - }; - VkDescriptorSetLayoutCreateInfo descriptor_set_layout_crinfo = { - .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, - .bindingCount = ARRAY_SIZE(bindings_for_my_descr_set_layout), - .pBindings = bindings_for_my_descr_set_layout, - }; - VkDescriptorSetLayout my_descriptor_set_layout; - if (vkCreateDescriptorSetLayout(device, &descriptor_set_layout_crinfo, NULL, &my_descriptor_set_layout) != VK_SUCCESS) - abortf("vkCreateDescriptorSetLayout"); - - VkPushConstantRange pc_ranges[] = { - { - .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, - .offset = 0, .size = sizeof(mat4) - }, - { - .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, - .offset = sizeof(mat4), .size = sizeof(vec3) - }, - - }; - - VkPipelineLayoutCreateInfo layout_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .setLayoutCount = 1, - .pSetLayouts = &my_descriptor_set_layout, - .pushConstantRangeCount = ARRAY_SIZE(pc_ranges), - .pPushConstantRanges = pc_ranges, - }; - VkPipelineLayout pipeline_layout; - if (vkCreatePipelineLayout(device, &layout_crinfo, NULL, &pipeline_layout) != VK_SUCCESS) - abortf("vkCreatePipelineLayout"); - VkGraphicsPipelineCreateInfo pipeline_crinfo = { - .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, - .stageCount = ARRAY_SIZE(shader_stages_crinfo), - .pStages = shader_stages_crinfo, - .pVertexInputState = &vertex_input_crinfo, - .pInputAssemblyState = &input_assembly_crinfo, - .pViewportState = &viewport_state, - .pRasterizationState = &rasterizer_crinfo, - .pMultisampleState = &multisampling_crinfo, - .pDepthStencilState = &depth_stencil_state_crinfo, - .pColorBlendState = &color_blending_crinfo, - .pDynamicState = &dynamic_state_crinfo, - .layout = pipeline_layout, - .renderPass = render_pass, - .subpass = subpass, - .basePipelineHandle = VK_NULL_HANDLE, - }; - - VkPipeline pipeline; - if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_crinfo, NULL, &pipeline) != VK_SUCCESS) - abortf("vkCreateGraphicsPipelines"); - - vkDestroyShaderModule(device, frag_module, NULL); - vkDestroyShaderModule(device, vert_module, NULL); return (PipelineHands){.pipeline_layout = pipeline_layout, .pipeline = pipeline, .descriptor_set_layout = my_descriptor_set_layout}; } -// todo: generate this function in l2 VkRenderPass create_render_pass_1(VkDevice logical_device, VkFormat image_format) { // Color attachments array for our render pass VkAttachmentDescription all_attachments[1] = { (VkAttachmentDescription){ @@ -601,89 +393,9 @@ VkRenderPass create_render_pass_1(VkDevice logical_device, VkFormat image_format } -// todo: generate this function in l2 PipelineHands create_graphics_pipeline_1( VkDevice device, VkRenderPass render_pass, uint32_t subpass ) { - VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/1/vert.spv"); - VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/1/frag.spv"); - VkShaderModule vert_module = margaret_VkShaderModule_new(device, vert_bin_code); - VkShaderModule frag_module = margaret_VkShaderModule_new(device, frag_bin_code); - VecU8_drop(vert_bin_code); - VecU8_drop(frag_bin_code); - - VkPipelineShaderStageCreateInfo shader_stages_crinfo[2] = { - margaret_shader_stage_vertex_crinfo(vert_module), - margaret_shader_stage_fragment_crinfo(frag_module) - }; - - VkPipelineVertexInputStateCreateInfo vertex_input_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .vertexBindingDescriptionCount = 0, - .pVertexBindingDescriptions = NULL, - .vertexAttributeDescriptionCount = 0, - .pVertexAttributeDescriptions = NULL, - }; - - VkPipelineInputAssemblyStateCreateInfo input_assembly_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - .primitiveRestartEnable = VK_FALSE, - }; - - VkPipelineViewportStateCreateInfo viewport_state = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - // We are using dynamic viewport and scissors, that is why we do not attach viewport/scissor values - // when creating a rendering pipeline. We will do that later - .viewportCount = 1, - .scissorCount = 1, - }; - - VkPipelineRasterizationStateCreateInfo rasterizer_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .depthClampEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - .cullMode = VK_CULL_MODE_BACK_BIT, - .frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .depthBiasConstantFactor = 0.0f, - .depthBiasClamp = 0.0f, - .depthBiasSlopeFactor = 0.0f, - .lineWidth = 1.0f, - }; - - VkPipelineMultisampleStateCreateInfo multisampling_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .sampleShadingEnable = VK_FALSE, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .minSampleShading = 1.0f, - .pSampleMask = NULL, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; - - // For one framebuffer - VkPipelineColorBlendAttachmentState color_blend_attachments[1] = {(VkPipelineColorBlendAttachmentState){ - .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - .blendEnable = VK_FALSE, - }}; - - // For the entire pipeline - VkPipelineColorBlendStateCreateInfo color_blending_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = ARRAY_SIZE(color_blend_attachments), - .pAttachments = color_blend_attachments, - // Blend constants specified here - }; - - VkDynamicState dynamic_states[2] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; - VkPipelineDynamicStateCreateInfo dynamic_state_crinfo = { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .dynamicStateCount = ARRAY_SIZE(dynamic_states), - .pDynamicStates = dynamic_states, - }; VkDescriptorSetLayoutBinding bindings_for_my_descr_set_layout[] = { { @@ -693,14 +405,12 @@ PipelineHands create_graphics_pipeline_1( .stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT, }, }; - VkDescriptorSetLayoutCreateInfo descriptor_set_layout_crinfo = { + VkDescriptorSetLayout my_descriptor_set_layout; + check(vkCreateDescriptorSetLayout(device, &(VkDescriptorSetLayoutCreateInfo){ .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .bindingCount = ARRAY_SIZE(bindings_for_my_descr_set_layout), .pBindings = bindings_for_my_descr_set_layout, - }; - VkDescriptorSetLayout my_descriptor_set_layout; - if (vkCreateDescriptorSetLayout(device, &descriptor_set_layout_crinfo, NULL, &my_descriptor_set_layout) != VK_SUCCESS) - abortf("vkCreateDescriptorSetLayout"); + }, NULL, &my_descriptor_set_layout) == VK_SUCCESS); VkPushConstantRange used_region_sz_push_const[2] = { { .stageFlags = VK_SHADER_STAGE_VERTEX_BIT, @@ -709,45 +419,29 @@ PipelineHands create_graphics_pipeline_1( .offset = sizeof(Pipeline1PushRangeVertex), .size = sizeof(Pipeline1PushRangeFragment) }, }; - VkPipelineLayoutCreateInfo layout_crinfo = { + VkPipelineLayout pipeline_layout; + check(vkCreatePipelineLayout(device, &(VkPipelineLayoutCreateInfo){ .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, .setLayoutCount = 1, .pSetLayouts = &my_descriptor_set_layout, .pushConstantRangeCount = ARRAY_SIZE(used_region_sz_push_const), .pPushConstantRanges = used_region_sz_push_const, - }; - VkPipelineLayout pipeline_layout; - if (vkCreatePipelineLayout(device, &layout_crinfo, NULL, &pipeline_layout) != VK_SUCCESS) - abortf("vkCreatePipelineLayout"); + }, NULL, &pipeline_layout) == VK_SUCCESS); - VkGraphicsPipelineCreateInfo pipeline_crinfo = { - .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, - .stageCount = ARRAY_SIZE(shader_stages_crinfo), - .pStages = shader_stages_crinfo, - .pVertexInputState = &vertex_input_crinfo, - .pInputAssemblyState = &input_assembly_crinfo, - .pViewportState = &viewport_state, - .pRasterizationState = &rasterizer_crinfo, - .pMultisampleState = &multisampling_crinfo, - .pDepthStencilState = NULL, - .pColorBlendState = &color_blending_crinfo, - .pDynamicState = &dynamic_state_crinfo, - .layout = pipeline_layout, - .renderPass = render_pass, - .subpass = subpass, - .basePipelineHandle = VK_NULL_HANDLE, - }; - VkPipeline pipeline; - if (vkCreateGraphicsPipelines(device, VK_NULL_HANDLE, 1, &pipeline_crinfo, NULL, &pipeline) != VK_SUCCESS) - abortf("vkCreateGraphicsPipelines"); + VecU8 vert_bin_code = read_whole_file_or_abort("shaders/spv/1/vert.spv"); + VecU8 frag_bin_code = read_whole_file_or_abort("shaders/spv/1/frag.spv"); - vkDestroyShaderModule(device, frag_module, NULL); - vkDestroyShaderModule(device, vert_module, NULL); + VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(device, render_pass, subpass, + (MargaretMostImportantPipelineOptions){ + .pipeline_layout = pipeline_layout, + .vertex_shader_code = vert_bin_code, .fragment_shader_code = frag_bin_code, + .vertexBindingDescriptionCount = 0, .pVertexBindingDescriptions = NULL, + .vertexAttributeDescriptionCount = 0, .pVertexAttributeDescriptions = NULL, + }); return (PipelineHands){.pipeline_layout = pipeline_layout, .pipeline = pipeline, .descriptor_set_layout = my_descriptor_set_layout}; } - VkFramebuffer create_IT1_framebuffer(VkDevice device, VkImageView IT1_view, VkImageView zbuffer_view, VkRenderPass render_pass_0, U32 MAX_WIN_WIDTH, U32 MAX_WIN_HEIGHT) { VkImageView attachments[2] = {IT1_view, zbuffer_view}; @@ -1585,6 +1279,7 @@ static void main_h_wl_keyboard_key( if (key_action == WL_KEYBOARD_KEY_STATE_RELEASED) { if (keysym == XKB_KEY_1) { vec3 p = state->vk.scene.cam.pos; + p.y += 1.5f; ShinyModelOnSceneMem* model = VecShinyModelOnSceneMem_mat(&state->vk.scene.shiny_models, 0); assert(model->instance_vec_len >= 1); ShinyMeshInstance* instances = (ShinyMeshInstance*)MargaretMAIterator_get_mapped(model->staging_instance_attr_buf); @@ -2126,14 +1821,13 @@ int main() { /* Will happen mid-frame */ vk->dt_transfer_required = true; - printf("ENTERING WAAYLAND MAINLOOP\n"); + printf("ENTERING WAYLAND MAINLOOP\n"); while (wl_display_dispatch(state.wl_display) >= 0) { if (state.closed) break; } - printf("CLOSING\n"); vkDeviceWaitIdle(vk->device); // The End