mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 10:51:50 -05:00
vk_renderpass_cache: Make use of designated initializers where applicable
This commit is contained in:
parent
01f297f2e0
commit
8ebd6a21c5
1 changed files with 69 additions and 58 deletions
|
@ -39,10 +39,14 @@ VkRenderPass VKRenderPassCache::GetRenderPass(const RenderPassParams& params) {
|
||||||
|
|
||||||
vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& params) const {
|
vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& params) const {
|
||||||
using namespace VideoCore::Surface;
|
using namespace VideoCore::Surface;
|
||||||
std::vector<VkAttachmentDescription> descriptors;
|
|
||||||
std::vector<VkAttachmentReference> color_references;
|
|
||||||
|
|
||||||
const std::size_t num_attachments = static_cast<std::size_t>(params.num_color_attachments);
|
const std::size_t num_attachments = static_cast<std::size_t>(params.num_color_attachments);
|
||||||
|
|
||||||
|
std::vector<VkAttachmentDescription> descriptors;
|
||||||
|
descriptors.reserve(num_attachments);
|
||||||
|
|
||||||
|
std::vector<VkAttachmentReference> color_references;
|
||||||
|
color_references.reserve(num_attachments);
|
||||||
|
|
||||||
for (std::size_t rt = 0; rt < num_attachments; ++rt) {
|
for (std::size_t rt = 0; rt < num_attachments; ++rt) {
|
||||||
const auto guest_format = static_cast<Tegra::RenderTargetFormat>(params.color_formats[rt]);
|
const auto guest_format = static_cast<Tegra::RenderTargetFormat>(params.color_formats[rt]);
|
||||||
const PixelFormat pixel_format = PixelFormatFromRenderTargetFormat(guest_format);
|
const PixelFormat pixel_format = PixelFormatFromRenderTargetFormat(guest_format);
|
||||||
|
@ -54,20 +58,22 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
|
||||||
const VkImageLayout color_layout = ((params.texceptions >> rt) & 1) != 0
|
const VkImageLayout color_layout = ((params.texceptions >> rt) & 1) != 0
|
||||||
? VK_IMAGE_LAYOUT_GENERAL
|
? VK_IMAGE_LAYOUT_GENERAL
|
||||||
: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
: VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
VkAttachmentDescription& descriptor = descriptors.emplace_back();
|
descriptors.push_back({
|
||||||
descriptor.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT;
|
.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT,
|
||||||
descriptor.format = format.format;
|
.format = format.format,
|
||||||
descriptor.samples = VK_SAMPLE_COUNT_1_BIT;
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
descriptor.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
||||||
descriptor.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
descriptor.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
|
||||||
descriptor.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
|
||||||
descriptor.initialLayout = color_layout;
|
.initialLayout = color_layout,
|
||||||
descriptor.finalLayout = color_layout;
|
.finalLayout = color_layout,
|
||||||
|
});
|
||||||
|
|
||||||
VkAttachmentReference& reference = color_references.emplace_back();
|
color_references.push_back({
|
||||||
reference.attachment = static_cast<u32>(rt);
|
.attachment = static_cast<u32>(rt),
|
||||||
reference.layout = color_layout;
|
.layout = color_layout,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
VkAttachmentReference zeta_attachment_ref;
|
VkAttachmentReference zeta_attachment_ref;
|
||||||
|
@ -82,32 +88,36 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
|
||||||
const VkImageLayout zeta_layout = params.zeta_texception != 0
|
const VkImageLayout zeta_layout = params.zeta_texception != 0
|
||||||
? VK_IMAGE_LAYOUT_GENERAL
|
? VK_IMAGE_LAYOUT_GENERAL
|
||||||
: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
VkAttachmentDescription& descriptor = descriptors.emplace_back();
|
descriptors.push_back({
|
||||||
descriptor.flags = 0;
|
.flags = 0,
|
||||||
descriptor.format = format.format;
|
.format = format.format,
|
||||||
descriptor.samples = VK_SAMPLE_COUNT_1_BIT;
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
descriptor.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
||||||
descriptor.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
descriptor.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
|
||||||
descriptor.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||||
descriptor.initialLayout = zeta_layout;
|
.initialLayout = zeta_layout,
|
||||||
descriptor.finalLayout = zeta_layout;
|
.finalLayout = zeta_layout,
|
||||||
|
});
|
||||||
|
|
||||||
zeta_attachment_ref.attachment = static_cast<u32>(num_attachments);
|
zeta_attachment_ref = {
|
||||||
zeta_attachment_ref.layout = zeta_layout;
|
.attachment = static_cast<u32>(num_attachments),
|
||||||
|
.layout = zeta_layout,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubpassDescription subpass_description;
|
const VkSubpassDescription subpass_description{
|
||||||
subpass_description.flags = 0;
|
.flags = 0,
|
||||||
subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
subpass_description.inputAttachmentCount = 0;
|
.inputAttachmentCount = 0,
|
||||||
subpass_description.pInputAttachments = nullptr;
|
.pInputAttachments = nullptr,
|
||||||
subpass_description.colorAttachmentCount = static_cast<u32>(color_references.size());
|
.colorAttachmentCount = static_cast<u32>(color_references.size()),
|
||||||
subpass_description.pColorAttachments = color_references.data();
|
.pColorAttachments = color_references.data(),
|
||||||
subpass_description.pResolveAttachments = nullptr;
|
.pResolveAttachments = nullptr,
|
||||||
subpass_description.pDepthStencilAttachment = has_zeta ? &zeta_attachment_ref : nullptr;
|
.pDepthStencilAttachment = has_zeta ? &zeta_attachment_ref : nullptr,
|
||||||
subpass_description.preserveAttachmentCount = 0;
|
.preserveAttachmentCount = 0,
|
||||||
subpass_description.pPreserveAttachments = nullptr;
|
.pPreserveAttachments = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
VkAccessFlags access = 0;
|
VkAccessFlags access = 0;
|
||||||
VkPipelineStageFlags stage = 0;
|
VkPipelineStageFlags stage = 0;
|
||||||
|
@ -122,26 +132,27 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
|
||||||
stage |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
stage |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubpassDependency subpass_dependency;
|
const VkSubpassDependency subpass_dependency{
|
||||||
subpass_dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
||||||
subpass_dependency.dstSubpass = 0;
|
.dstSubpass = 0,
|
||||||
subpass_dependency.srcStageMask = stage;
|
.srcStageMask = stage,
|
||||||
subpass_dependency.dstStageMask = stage;
|
.dstStageMask = stage,
|
||||||
subpass_dependency.srcAccessMask = 0;
|
.srcAccessMask = 0,
|
||||||
subpass_dependency.dstAccessMask = access;
|
.dstAccessMask = access,
|
||||||
subpass_dependency.dependencyFlags = 0;
|
.dependencyFlags = 0,
|
||||||
|
};
|
||||||
|
|
||||||
VkRenderPassCreateInfo ci;
|
return device.GetLogical().CreateRenderPass({
|
||||||
ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
ci.attachmentCount = static_cast<u32>(descriptors.size());
|
.attachmentCount = static_cast<u32>(descriptors.size()),
|
||||||
ci.pAttachments = descriptors.data();
|
.pAttachments = descriptors.data(),
|
||||||
ci.subpassCount = 1;
|
.subpassCount = 1,
|
||||||
ci.pSubpasses = &subpass_description;
|
.pSubpasses = &subpass_description,
|
||||||
ci.dependencyCount = 1;
|
.dependencyCount = 1,
|
||||||
ci.pDependencies = &subpass_dependency;
|
.pDependencies = &subpass_dependency,
|
||||||
return device.GetLogical().CreateRenderPass(ci);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|
Loading…
Reference in a new issue