From 1164bd4b0fc4d611158d32b3bf929b6365bfe02f Mon Sep 17 00:00:00 2001 From: antopilo Date: Wed, 25 Dec 2024 17:47:06 -0500 Subject: [PATCH] Cleaned up pipeline builder code --- Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp | 25 ++++--------------- Resources/Shaders/Vulkan/triangle.vert | 5 ++-- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp b/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp index f6832fac..cd2af6b1 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp +++ b/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp @@ -449,43 +449,26 @@ void VkRenderer::InitTrianglePipeline() VkDescriptorSetLayout layouts[] = { CameraBufferDescriptorLayout, TriangleBufferDescriptorLayout }; VkPipelineLayoutCreateInfo pipeline_layout_info = VulkanInit::PipelineLayoutCreateInfo(); - //pipeline_layout_info.pPushConstantRanges = &bufferRange; + pipeline_layout_info.pPushConstantRanges = &bufferRange; pipeline_layout_info.pushConstantRangeCount = 0; pipeline_layout_info.pSetLayouts = layouts; pipeline_layout_info.setLayoutCount = 2; - VK_CALL(vkCreatePipelineLayout(Device, &pipeline_layout_info, nullptr, &TrianglePipelineLayout)); - PipelineBuilder pipelineBuilder; - //use the triangle layout we created + PipelineBuilder pipelineBuilder; pipelineBuilder.PipelineLayout = TrianglePipelineLayout; - //connecting the vertex and pixel shaders to the pipeline pipelineBuilder.SetShaders(TriangleVertShader->GetModule(), TriangleFragShader->GetModule()); - //it will draw triangles pipelineBuilder.SetInputTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); - //filled triangles pipelineBuilder.SetPolygonMode(VK_POLYGON_MODE_FILL); - //no backface culling pipelineBuilder.SetCullMode(VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE); - //no multisampling pipelineBuilder.SetMultiSamplingNone(); - //no blending pipelineBuilder.DisableBlending(); - //no depth testing pipelineBuilder.DisableDepthTest(); - - //connect the image format we will draw into, from draw image pipelineBuilder.SetColorAttachment(static_cast(DrawImage->GetFormat())); pipelineBuilder.SetDepthFormat(VK_FORMAT_UNDEFINED); - - //finally build the pipeline TrianglePipeline = pipelineBuilder.BuildPipeline(Device); - //clean structures - //vkDestroyShaderModule(Device, Triangl, nullptr); - //vkDestroyShaderModule(Device, TriangleVertexShader, nullptr); - MainDeletionQueue.push_function([&]() { vkDestroyPipelineLayout(Device, TrianglePipelineLayout, nullptr); vkDestroyPipeline(Device, TrianglePipeline, nullptr); @@ -523,6 +506,8 @@ void VkRenderer::DrawGeometry(VkCommandBuffer cmd) vkCmdSetScissor(cmd, 0, 1, &scissor); + + vkCmdBindIndexBuffer(cmd, rectangle->GetIndexBuffer()->GetBuffer(), 0, VK_INDEX_TYPE_UINT32); vkCmdDrawIndexed(cmd, 6, 1, 0, 0, 0); @@ -743,10 +728,10 @@ void VkRenderer::Draw() // Transition rendering iamge to transfert onto swapchain images //VulkanUtil::TransitionImage(cmd, DrawImage->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + VulkanUtil::TransitionImage(cmd, SwapchainImages[swapchainImageIndex], VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); DrawGeometry(cmd); - VulkanUtil::TransitionImage(cmd, DrawImage->GetImage(), VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); //draw imgui into the swapchain image diff --git a/Resources/Shaders/Vulkan/triangle.vert b/Resources/Shaders/Vulkan/triangle.vert index a9c36d78..7d450b4c 100644 --- a/Resources/Shaders/Vulkan/triangle.vert +++ b/Resources/Shaders/Vulkan/triangle.vert @@ -14,7 +14,8 @@ struct Vertex float uv_x; float3 normal; float uv_y; - float4 color; + float4 tangent; + float4 bitangent; }; [[vk::binding(0, 1)]] @@ -44,7 +45,7 @@ VSOutput main(uint vertexIndex : SV_VertexID) // Output the position of each vertex output.Position = mul(worldData.proj, mul(worldData.view, mul(worldData.model, float4(v.position, 1.0f)))); - output.Color = float3(v.color.xyz); + output.Color = float3(v.normal.xyz); return output; } \ No newline at end of file