summaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_vulkan/vk_renderpass_cache.cpp129
1 files changed, 70 insertions, 59 deletions
diff --git a/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp b/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp
index 3f71d005e..80284cf92 100644
--- a/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_renderpass_cache.cpp
@@ -39,10 +39,14 @@ VkRenderPass VKRenderPassCache::GetRenderPass(const RenderPassParams& params) {
39 39
40vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& params) const { 40vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& params) const {
41 using namespace VideoCore::Surface; 41 using namespace VideoCore::Surface;
42 const std::size_t num_attachments = static_cast<std::size_t>(params.num_color_attachments);
43
42 std::vector<VkAttachmentDescription> descriptors; 44 std::vector<VkAttachmentDescription> descriptors;
45 descriptors.reserve(num_attachments);
46
43 std::vector<VkAttachmentReference> color_references; 47 std::vector<VkAttachmentReference> color_references;
48 color_references.reserve(num_attachments);
44 49
45 const std::size_t num_attachments = static_cast<std::size_t>(params.num_color_attachments);
46 for (std::size_t rt = 0; rt < num_attachments; ++rt) { 50 for (std::size_t rt = 0; rt < num_attachments; ++rt) {
47 const auto guest_format = static_cast<Tegra::RenderTargetFormat>(params.color_formats[rt]); 51 const auto guest_format = static_cast<Tegra::RenderTargetFormat>(params.color_formats[rt]);
48 const PixelFormat pixel_format = PixelFormatFromRenderTargetFormat(guest_format); 52 const PixelFormat pixel_format = PixelFormatFromRenderTargetFormat(guest_format);
@@ -54,20 +58,22 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
54 const VkImageLayout color_layout = ((params.texceptions >> rt) & 1) != 0 58 const VkImageLayout color_layout = ((params.texceptions >> rt) & 1) != 0
55 ? VK_IMAGE_LAYOUT_GENERAL 59 ? VK_IMAGE_LAYOUT_GENERAL
56 : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; 60 : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
57 VkAttachmentDescription& descriptor = descriptors.emplace_back(); 61 descriptors.push_back({
58 descriptor.flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT; 62 .flags = VK_ATTACHMENT_DESCRIPTION_MAY_ALIAS_BIT,
59 descriptor.format = format.format; 63 .format = format.format,
60 descriptor.samples = VK_SAMPLE_COUNT_1_BIT; 64 .samples = VK_SAMPLE_COUNT_1_BIT,
61 descriptor.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; 65 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
62 descriptor.storeOp = VK_ATTACHMENT_STORE_OP_STORE; 66 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
63 descriptor.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; 67 .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
64 descriptor.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; 68 .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
65 descriptor.initialLayout = color_layout; 69 .initialLayout = color_layout,
66 descriptor.finalLayout = color_layout; 70 .finalLayout = color_layout,
67 71 });
68 VkAttachmentReference& reference = color_references.emplace_back(); 72
69 reference.attachment = static_cast<u32>(rt); 73 color_references.push_back({
70 reference.layout = color_layout; 74 .attachment = static_cast<u32>(rt),
75 .layout = color_layout,
76 });
71 } 77 }
72 78
73 VkAttachmentReference zeta_attachment_ref; 79 VkAttachmentReference zeta_attachment_ref;
@@ -82,32 +88,36 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
82 const VkImageLayout zeta_layout = params.zeta_texception != 0 88 const VkImageLayout zeta_layout = params.zeta_texception != 0
83 ? VK_IMAGE_LAYOUT_GENERAL 89 ? VK_IMAGE_LAYOUT_GENERAL
84 : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; 90 : VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
85 VkAttachmentDescription& descriptor = descriptors.emplace_back(); 91 descriptors.push_back({
86 descriptor.flags = 0; 92 .flags = 0,
87 descriptor.format = format.format; 93 .format = format.format,
88 descriptor.samples = VK_SAMPLE_COUNT_1_BIT; 94 .samples = VK_SAMPLE_COUNT_1_BIT,
89 descriptor.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; 95 .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
90 descriptor.storeOp = VK_ATTACHMENT_STORE_OP_STORE; 96 .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
91 descriptor.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; 97 .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
92 descriptor.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; 98 .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE,
93 descriptor.initialLayout = zeta_layout; 99 .initialLayout = zeta_layout,
94 descriptor.finalLayout = zeta_layout; 100 .finalLayout = zeta_layout,
95 101 });
96 zeta_attachment_ref.attachment = static_cast<u32>(num_attachments); 102
97 zeta_attachment_ref.layout = zeta_layout; 103 zeta_attachment_ref = {
104 .attachment = static_cast<u32>(num_attachments),
105 .layout = zeta_layout,
106 };
98 } 107 }
99 108
100 VkSubpassDescription subpass_description; 109 const VkSubpassDescription subpass_description{
101 subpass_description.flags = 0; 110 .flags = 0,
102 subpass_description.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; 111 .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
103 subpass_description.inputAttachmentCount = 0; 112 .inputAttachmentCount = 0,
104 subpass_description.pInputAttachments = nullptr; 113 .pInputAttachments = nullptr,
105 subpass_description.colorAttachmentCount = static_cast<u32>(color_references.size()); 114 .colorAttachmentCount = static_cast<u32>(color_references.size()),
106 subpass_description.pColorAttachments = color_references.data(); 115 .pColorAttachments = color_references.data(),
107 subpass_description.pResolveAttachments = nullptr; 116 .pResolveAttachments = nullptr,
108 subpass_description.pDepthStencilAttachment = has_zeta ? &zeta_attachment_ref : nullptr; 117 .pDepthStencilAttachment = has_zeta ? &zeta_attachment_ref : nullptr,
109 subpass_description.preserveAttachmentCount = 0; 118 .preserveAttachmentCount = 0,
110 subpass_description.pPreserveAttachments = nullptr; 119 .pPreserveAttachments = nullptr,
120 };
111 121
112 VkAccessFlags access = 0; 122 VkAccessFlags access = 0;
113 VkPipelineStageFlags stage = 0; 123 VkPipelineStageFlags stage = 0;
@@ -122,26 +132,27 @@ vk::RenderPass VKRenderPassCache::CreateRenderPass(const RenderPassParams& param
122 stage |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; 132 stage |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
123 } 133 }
124 134
125 VkSubpassDependency subpass_dependency; 135 const VkSubpassDependency subpass_dependency{
126 subpass_dependency.srcSubpass = VK_SUBPASS_EXTERNAL; 136 .srcSubpass = VK_SUBPASS_EXTERNAL,
127 subpass_dependency.dstSubpass = 0; 137 .dstSubpass = 0,
128 subpass_dependency.srcStageMask = stage; 138 .srcStageMask = stage,
129 subpass_dependency.dstStageMask = stage; 139 .dstStageMask = stage,
130 subpass_dependency.srcAccessMask = 0; 140 .srcAccessMask = 0,
131 subpass_dependency.dstAccessMask = access; 141 .dstAccessMask = access,
132 subpass_dependency.dependencyFlags = 0; 142 .dependencyFlags = 0,
133 143 };
134 VkRenderPassCreateInfo ci; 144
135 ci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; 145 return device.GetLogical().CreateRenderPass({
136 ci.pNext = nullptr; 146 .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
137 ci.flags = 0; 147 .pNext = nullptr,
138 ci.attachmentCount = static_cast<u32>(descriptors.size()); 148 .flags = 0,
139 ci.pAttachments = descriptors.data(); 149 .attachmentCount = static_cast<u32>(descriptors.size()),
140 ci.subpassCount = 1; 150 .pAttachments = descriptors.data(),
141 ci.pSubpasses = &subpass_description; 151 .subpassCount = 1,
142 ci.dependencyCount = 1; 152 .pSubpasses = &subpass_description,
143 ci.pDependencies = &subpass_dependency; 153 .dependencyCount = 1,
144 return device.GetLogical().CreateRenderPass(ci); 154 .pDependencies = &subpass_dependency,
155 });
145} 156}
146 157
147} // namespace Vulkan 158} // namespace Vulkan