render pass first work

This commit is contained in:
2026-08-26 21:07:12 +03:00
parent 8055881fef
commit a6818a6cf4
18 changed files with 342 additions and 84 deletions
+69 -4
View File
@@ -81,6 +81,8 @@ void CVkShader::Build()
VkPipelineRenderingCreateInfo render = {};
CUtlVector<VkPipelineColorBlendAttachmentState> attachments = {};
VkDynamicState dynamicStates[] = {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT,
VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT,
};
@@ -178,6 +180,8 @@ void CVkShader::Build()
rasterState.frontFace = VK_FRONT_FACE_CLOCKWISE;
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewportState.viewportCount = 1;
viewportState.scissorCount = 1;
msaa.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
msaa.rasterizationSamples = CVkImage::GetMultisampling(m_eMultiSampling);
@@ -186,10 +190,70 @@ void CVkShader::Build()
for ( uint32_t i = 0; i < m_formats.GetSize(); i++ )
formats[i] = m_formats[i].m_eFormat;
render.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
render.colorAttachmentCount = formats.GetSize();
render.pColorAttachmentFormats = formats.GetData();
if (! (vkCmdBeginRendering || vkCmdBeginRenderingKHR) )
{
CUtlVector<VkAttachmentDescription> attachments = {};
CUtlVector<VkAttachmentReference> input_refs = {};
attachments.Resize(formats.GetSize());
input_refs.Resize(formats.GetSize());
uint32_t i = 0;
for (auto f: formats)
{
/* fuck vulkan 1.0*/
/* anyway we create compatible render passes somewhere */
VkAttachmentDescription desc = {};
desc.format = f;
desc.samples = CVkImage::GetMultisampling(m_eMultiSampling);
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[i] = desc;
VkAttachmentReference ref = {};
ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
ref.attachment = i;
input_refs[i] = ref;
i++;
}
if (m_eDepthFormat == VK_FORMAT_D32_SFLOAT)
{
VkAttachmentDescription desc = {};
desc.format = m_eDepthFormat;
desc.samples = CVkImage::GetMultisampling(m_eMultiSampling);
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments.AppendTail(desc);
}
VkAttachmentReference depthRef;
depthRef.attachment = attachments.GetSize() - 1;
depthRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = input_refs.GetSize();
subpass.pColorAttachments = input_refs.GetData();
if (m_eDepthFormat == VK_FORMAT_D32_SFLOAT)
{
subpass.pDepthStencilAttachment = &depthRef;
}
VkRenderPassCreateInfo rpci = {};
rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
rpci.attachmentCount = attachments.GetSize();
rpci.pAttachments = attachments.GetData();
rpci.subpassCount = 1;
rpci.pSubpasses = &subpass;
vkCreateRenderPass(m_hDevice, &rpci, NULL, &m_hRenderPass);
createInfo.renderPass = m_hRenderPass;
}
else
{
render.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
render.colorAttachmentCount = formats.GetSize();
render.pColorAttachmentFormats = formats.GetData();
if (m_eDepthFormat == VK_FORMAT_D32_SFLOAT)
render.depthAttachmentFormat = m_eDepthFormat;
}
depthStencil.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
if (m_eDepthFormat == VK_FORMAT_D32_SFLOAT)
{
@@ -235,7 +299,8 @@ void CVkShader::Build()
createInfo.pDepthStencilState = &depthStencil;
createInfo.pColorBlendState = &blend;
createInfo.pMultisampleState = &msaa;
createInfo.pNext = &render;
if (vkCmdBeginRendering || vkCmdBeginRenderingKHR)
createInfo.pNext = &render;
vkCreateGraphicsPipelines(m_hDevice, NULL, 1, &createInfo, NULL, &m_hPipeline);
}