diff options
| author | 2021-04-22 21:05:10 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:29 -0400 | |
| commit | 7a1f296cda32bdb8996f25fd1862b422ac2bfe48 (patch) | |
| tree | 521d086aeb329efbbdf6d906a7978aad7b1e360b /src | |
| parent | shader: Increase the maximum number of storage buffers (diff) | |
| download | yuzu-7a1f296cda32bdb8996f25fd1862b422ac2bfe48.tar.gz yuzu-7a1f296cda32bdb8996f25fd1862b422ac2bfe48.tar.xz yuzu-7a1f296cda32bdb8996f25fd1862b422ac2bfe48.zip | |
shader: Fix render targets with null attachments
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | 18 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_render_pass_cache.cpp | 42 |
2 files changed, 34 insertions, 26 deletions
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index b7688aef9..e43db280f 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -105,6 +105,17 @@ RenderPassKey MakeRenderPassKey(const FixedPipelineState& state) { | |||
| 105 | key.samples = MaxwellToVK::MsaaMode(state.msaa_mode); | 105 | key.samples = MaxwellToVK::MsaaMode(state.msaa_mode); |
| 106 | return key; | 106 | return key; |
| 107 | } | 107 | } |
| 108 | |||
| 109 | size_t NumAttachments(const FixedPipelineState& state) { | ||
| 110 | size_t num{}; | ||
| 111 | for (size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { | ||
| 112 | const auto format{static_cast<Tegra::RenderTargetFormat>(state.color_formats[index])}; | ||
| 113 | if (format != Tegra::RenderTargetFormat::NONE) { | ||
| 114 | num = index + 1; | ||
| 115 | } | ||
| 116 | } | ||
| 117 | return num; | ||
| 118 | } | ||
| 108 | } // Anonymous namespace | 119 | } // Anonymous namespace |
| 109 | 120 | ||
| 110 | GraphicsPipeline::GraphicsPipeline(Tegra::Engines::Maxwell3D& maxwell3d_, | 121 | GraphicsPipeline::GraphicsPipeline(Tegra::Engines::Maxwell3D& maxwell3d_, |
| @@ -418,17 +429,14 @@ void GraphicsPipeline::MakePipeline(const Device& device, VkRenderPass render_pa | |||
| 418 | .maxDepthBounds = 0.0f, | 429 | .maxDepthBounds = 0.0f, |
| 419 | }; | 430 | }; |
| 420 | static_vector<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments; | 431 | static_vector<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments; |
| 421 | for (size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { | 432 | const size_t num_attachments{NumAttachments(state)}; |
| 433 | for (size_t index = 0; index < num_attachments; ++index) { | ||
| 422 | static constexpr std::array mask_table{ | 434 | static constexpr std::array mask_table{ |
| 423 | VK_COLOR_COMPONENT_R_BIT, | 435 | VK_COLOR_COMPONENT_R_BIT, |
| 424 | VK_COLOR_COMPONENT_G_BIT, | 436 | VK_COLOR_COMPONENT_G_BIT, |
| 425 | VK_COLOR_COMPONENT_B_BIT, | 437 | VK_COLOR_COMPONENT_B_BIT, |
| 426 | VK_COLOR_COMPONENT_A_BIT, | 438 | VK_COLOR_COMPONENT_A_BIT, |
| 427 | }; | 439 | }; |
| 428 | const auto format{static_cast<Tegra::RenderTargetFormat>(state.color_formats[index])}; | ||
| 429 | if (format == Tegra::RenderTargetFormat::NONE) { | ||
| 430 | continue; | ||
| 431 | } | ||
| 432 | const auto& blend{state.attachments[index]}; | 440 | const auto& blend{state.attachments[index]}; |
| 433 | const std::array mask{blend.Mask()}; | 441 | const std::array mask{blend.Mask()}; |
| 434 | VkColorComponentFlags write_mask{}; | 442 | VkColorComponentFlags write_mask{}; |
diff --git a/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp b/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp index 991afe521..451ffe019 100644 --- a/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_render_pass_cache.cpp | |||
| @@ -16,18 +16,6 @@ namespace Vulkan { | |||
| 16 | namespace { | 16 | namespace { |
| 17 | using VideoCore::Surface::PixelFormat; | 17 | using VideoCore::Surface::PixelFormat; |
| 18 | 18 | ||
| 19 | constexpr std::array ATTACHMENT_REFERENCES{ | ||
| 20 | VkAttachmentReference{0, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 21 | VkAttachmentReference{1, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 22 | VkAttachmentReference{2, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 23 | VkAttachmentReference{3, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 24 | VkAttachmentReference{4, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 25 | VkAttachmentReference{5, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 26 | VkAttachmentReference{6, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 27 | VkAttachmentReference{7, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 28 | VkAttachmentReference{8, VK_IMAGE_LAYOUT_GENERAL}, | ||
| 29 | }; | ||
| 30 | |||
| 31 | VkAttachmentDescription AttachmentDescription(const Device& device, PixelFormat format, | 19 | VkAttachmentDescription AttachmentDescription(const Device& device, PixelFormat format, |
| 32 | VkSampleCountFlagBits samples) { | 20 | VkSampleCountFlagBits samples) { |
| 33 | using MaxwellToVK::SurfaceFormat; | 21 | using MaxwellToVK::SurfaceFormat; |
| @@ -54,17 +42,29 @@ VkRenderPass RenderPassCache::Get(const RenderPassKey& key) { | |||
| 54 | return *pair->second; | 42 | return *pair->second; |
| 55 | } | 43 | } |
| 56 | boost::container::static_vector<VkAttachmentDescription, 9> descriptions; | 44 | boost::container::static_vector<VkAttachmentDescription, 9> descriptions; |
| 45 | std::array<VkAttachmentReference, 8> references{}; | ||
| 46 | u32 num_attachments{}; | ||
| 47 | u32 num_colors{}; | ||
| 57 | for (size_t index = 0; index < key.color_formats.size(); ++index) { | 48 | for (size_t index = 0; index < key.color_formats.size(); ++index) { |
| 58 | const PixelFormat format{key.color_formats[index]}; | 49 | const PixelFormat format{key.color_formats[index]}; |
| 59 | if (format == PixelFormat::Invalid) { | 50 | const bool is_valid{format != PixelFormat::Invalid}; |
| 60 | continue; | 51 | references[index] = VkAttachmentReference{ |
| 52 | .attachment = is_valid ? num_colors : VK_ATTACHMENT_UNUSED, | ||
| 53 | .layout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 54 | }; | ||
| 55 | if (is_valid) { | ||
| 56 | descriptions.push_back(AttachmentDescription(*device, format, key.samples)); | ||
| 57 | num_attachments = static_cast<u32>(index + 1); | ||
| 58 | ++num_colors; | ||
| 61 | } | 59 | } |
| 62 | descriptions.push_back(AttachmentDescription(*device, format, key.samples)); | ||
| 63 | } | 60 | } |
| 64 | const size_t num_colors{descriptions.size()}; | 61 | const bool has_depth{key.depth_format != PixelFormat::Invalid}; |
| 65 | const VkAttachmentReference* depth_attachment{}; | 62 | VkAttachmentReference depth_reference{}; |
| 66 | if (key.depth_format != PixelFormat::Invalid) { | 63 | if (key.depth_format != PixelFormat::Invalid) { |
| 67 | depth_attachment = &ATTACHMENT_REFERENCES[num_colors]; | 64 | depth_reference = VkAttachmentReference{ |
| 65 | .attachment = num_colors, | ||
| 66 | .layout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 67 | }; | ||
| 68 | descriptions.push_back(AttachmentDescription(*device, key.depth_format, key.samples)); | 68 | descriptions.push_back(AttachmentDescription(*device, key.depth_format, key.samples)); |
| 69 | } | 69 | } |
| 70 | const VkSubpassDescription subpass{ | 70 | const VkSubpassDescription subpass{ |
| @@ -72,10 +72,10 @@ VkRenderPass RenderPassCache::Get(const RenderPassKey& key) { | |||
| 72 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | 72 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 73 | .inputAttachmentCount = 0, | 73 | .inputAttachmentCount = 0, |
| 74 | .pInputAttachments = nullptr, | 74 | .pInputAttachments = nullptr, |
| 75 | .colorAttachmentCount = static_cast<u32>(num_colors), | 75 | .colorAttachmentCount = num_attachments, |
| 76 | .pColorAttachments = num_colors != 0 ? ATTACHMENT_REFERENCES.data() : nullptr, | 76 | .pColorAttachments = references.data(), |
| 77 | .pResolveAttachments = nullptr, | 77 | .pResolveAttachments = nullptr, |
| 78 | .pDepthStencilAttachment = depth_attachment, | 78 | .pDepthStencilAttachment = has_depth ? &depth_reference : nullptr, |
| 79 | .preserveAttachmentCount = 0, | 79 | .preserveAttachmentCount = 0, |
| 80 | .pPreserveAttachments = nullptr, | 80 | .pPreserveAttachments = nullptr, |
| 81 | }; | 81 | }; |