diff options
| author | 2022-04-15 12:29:49 +0200 | |
|---|---|---|
| committer | 2022-10-06 21:00:53 +0200 | |
| commit | ada09778d97d39d83353ca54d0d6c9abd5eefc60 (patch) | |
| tree | 88758ebac615e8f835cd0f3487e313ec01fa5a6b /src | |
| parent | ImageBase: Basic fixes. (diff) | |
| download | yuzu-ada09778d97d39d83353ca54d0d6c9abd5eefc60.tar.gz yuzu-ada09778d97d39d83353ca54d0d6c9abd5eefc60.tar.xz yuzu-ada09778d97d39d83353ca54d0d6c9abd5eefc60.zip | |
Vulkan Texture Cache: Limit render area to the max width/height of the targets.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 30 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 5 | ||||
| -rw-r--r-- | src/video_core/texture_cache/render_targets.h | 1 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 2 |
4 files changed, 29 insertions, 9 deletions
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 8d2728cd7..305ad8aee 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -1474,13 +1474,14 @@ bool Image::BlitScaleHelper(bool scale_up) { | |||
| 1474 | }; | 1474 | }; |
| 1475 | const VkExtent2D extent{ | 1475 | const VkExtent2D extent{ |
| 1476 | .width = std::max(scaled_width, info.size.width), | 1476 | .width = std::max(scaled_width, info.size.width), |
| 1477 | .height = std::max(scaled_height, info.size.width), | 1477 | .height = std::max(scaled_height, info.size.height), |
| 1478 | }; | 1478 | }; |
| 1479 | 1479 | ||
| 1480 | auto* view_ptr = blit_view.get(); | 1480 | auto* view_ptr = blit_view.get(); |
| 1481 | if (aspect_mask == VK_IMAGE_ASPECT_COLOR_BIT) { | 1481 | if (aspect_mask == VK_IMAGE_ASPECT_COLOR_BIT) { |
| 1482 | if (!blit_framebuffer) { | 1482 | if (!blit_framebuffer) { |
| 1483 | blit_framebuffer = std::make_unique<Framebuffer>(*runtime, view_ptr, nullptr, extent); | 1483 | blit_framebuffer = |
| 1484 | std::make_unique<Framebuffer>(*runtime, view_ptr, nullptr, extent, scale_up); | ||
| 1484 | } | 1485 | } |
| 1485 | const auto color_view = blit_view->Handle(Shader::TextureType::Color2D); | 1486 | const auto color_view = blit_view->Handle(Shader::TextureType::Color2D); |
| 1486 | 1487 | ||
| @@ -1488,7 +1489,8 @@ bool Image::BlitScaleHelper(bool scale_up) { | |||
| 1488 | src_region, operation, BLIT_OPERATION); | 1489 | src_region, operation, BLIT_OPERATION); |
| 1489 | } else if (aspect_mask == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { | 1490 | } else if (aspect_mask == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) { |
| 1490 | if (!blit_framebuffer) { | 1491 | if (!blit_framebuffer) { |
| 1491 | blit_framebuffer = std::make_unique<Framebuffer>(*runtime, nullptr, view_ptr, extent); | 1492 | blit_framebuffer = |
| 1493 | std::make_unique<Framebuffer>(*runtime, nullptr, view_ptr, extent, scale_up); | ||
| 1492 | } | 1494 | } |
| 1493 | runtime->blit_image_helper.BlitDepthStencil(blit_framebuffer.get(), blit_view->DepthView(), | 1495 | runtime->blit_image_helper.BlitDepthStencil(blit_framebuffer.get(), blit_view->DepthView(), |
| 1494 | blit_view->StencilView(), dst_region, | 1496 | blit_view->StencilView(), dst_region, |
| @@ -1756,34 +1758,42 @@ Framebuffer::Framebuffer(TextureCacheRuntime& runtime, std::span<ImageView*, NUM | |||
| 1756 | .width = key.size.width, | 1758 | .width = key.size.width, |
| 1757 | .height = key.size.height, | 1759 | .height = key.size.height, |
| 1758 | }} { | 1760 | }} { |
| 1759 | CreateFramebuffer(runtime, color_buffers, depth_buffer); | 1761 | CreateFramebuffer(runtime, color_buffers, depth_buffer, key.is_rescaled); |
| 1760 | if (runtime.device.HasDebuggingToolAttached()) { | 1762 | if (runtime.device.HasDebuggingToolAttached()) { |
| 1761 | framebuffer.SetObjectNameEXT(VideoCommon::Name(key).c_str()); | 1763 | framebuffer.SetObjectNameEXT(VideoCommon::Name(key).c_str()); |
| 1762 | } | 1764 | } |
| 1763 | } | 1765 | } |
| 1764 | 1766 | ||
| 1765 | Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, | 1767 | Framebuffer::Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, |
| 1766 | ImageView* depth_buffer, VkExtent2D extent) | 1768 | ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled) |
| 1767 | : render_area{extent} { | 1769 | : render_area{extent} { |
| 1768 | std::array<ImageView*, NUM_RT> color_buffers{color_buffer}; | 1770 | std::array<ImageView*, NUM_RT> color_buffers{color_buffer}; |
| 1769 | CreateFramebuffer(runtime, color_buffers, depth_buffer); | 1771 | CreateFramebuffer(runtime, color_buffers, depth_buffer, is_rescaled); |
| 1770 | } | 1772 | } |
| 1771 | 1773 | ||
| 1772 | Framebuffer::~Framebuffer() = default; | 1774 | Framebuffer::~Framebuffer() = default; |
| 1773 | 1775 | ||
| 1774 | void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, | 1776 | void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, |
| 1775 | std::span<ImageView*, NUM_RT> color_buffers, | 1777 | std::span<ImageView*, NUM_RT> color_buffers, |
| 1776 | ImageView* depth_buffer) { | 1778 | ImageView* depth_buffer, bool is_rescaled) { |
| 1777 | std::vector<VkImageView> attachments; | 1779 | std::vector<VkImageView> attachments; |
| 1778 | RenderPassKey renderpass_key{}; | 1780 | RenderPassKey renderpass_key{}; |
| 1779 | s32 num_layers = 1; | 1781 | s32 num_layers = 1; |
| 1780 | 1782 | ||
| 1783 | const auto& resolution = runtime.resolution; | ||
| 1784 | |||
| 1785 | u32 width = 0; | ||
| 1786 | u32 height = 0; | ||
| 1781 | for (size_t index = 0; index < NUM_RT; ++index) { | 1787 | for (size_t index = 0; index < NUM_RT; ++index) { |
| 1782 | const ImageView* const color_buffer = color_buffers[index]; | 1788 | const ImageView* const color_buffer = color_buffers[index]; |
| 1783 | if (!color_buffer) { | 1789 | if (!color_buffer) { |
| 1784 | renderpass_key.color_formats[index] = PixelFormat::Invalid; | 1790 | renderpass_key.color_formats[index] = PixelFormat::Invalid; |
| 1785 | continue; | 1791 | continue; |
| 1786 | } | 1792 | } |
| 1793 | width = std::max(width, is_rescaled ? resolution.ScaleUp(color_buffer->size.width) | ||
| 1794 | : color_buffer->size.width); | ||
| 1795 | height = std::max(height, is_rescaled ? resolution.ScaleUp(color_buffer->size.height) | ||
| 1796 | : color_buffer->size.height); | ||
| 1787 | attachments.push_back(color_buffer->RenderTarget()); | 1797 | attachments.push_back(color_buffer->RenderTarget()); |
| 1788 | renderpass_key.color_formats[index] = color_buffer->format; | 1798 | renderpass_key.color_formats[index] = color_buffer->format; |
| 1789 | num_layers = std::max(num_layers, color_buffer->range.extent.layers); | 1799 | num_layers = std::max(num_layers, color_buffer->range.extent.layers); |
| @@ -1794,6 +1804,10 @@ void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, | |||
| 1794 | } | 1804 | } |
| 1795 | const size_t num_colors = attachments.size(); | 1805 | const size_t num_colors = attachments.size(); |
| 1796 | if (depth_buffer) { | 1806 | if (depth_buffer) { |
| 1807 | width = std::max(width, is_rescaled ? resolution.ScaleUp(depth_buffer->size.width) | ||
| 1808 | : depth_buffer->size.width); | ||
| 1809 | height = std::max(height, is_rescaled ? resolution.ScaleUp(depth_buffer->size.height) | ||
| 1810 | : depth_buffer->size.height); | ||
| 1797 | attachments.push_back(depth_buffer->RenderTarget()); | 1811 | attachments.push_back(depth_buffer->RenderTarget()); |
| 1798 | renderpass_key.depth_format = depth_buffer->format; | 1812 | renderpass_key.depth_format = depth_buffer->format; |
| 1799 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); | 1813 | num_layers = std::max(num_layers, depth_buffer->range.extent.layers); |
| @@ -1810,6 +1824,8 @@ void Framebuffer::CreateFramebuffer(TextureCacheRuntime& runtime, | |||
| 1810 | renderpass_key.samples = samples; | 1824 | renderpass_key.samples = samples; |
| 1811 | 1825 | ||
| 1812 | renderpass = runtime.render_pass_cache.Get(renderpass_key); | 1826 | renderpass = runtime.render_pass_cache.Get(renderpass_key); |
| 1827 | render_area.width = std::min(render_area.width, width); | ||
| 1828 | render_area.height = std::min(render_area.height, height); | ||
| 1813 | 1829 | ||
| 1814 | num_color_buffers = static_cast<u32>(num_colors); | 1830 | num_color_buffers = static_cast<u32>(num_colors); |
| 1815 | framebuffer = runtime.device.GetLogical().CreateFramebuffer({ | 1831 | framebuffer = runtime.device.GetLogical().CreateFramebuffer({ |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 69f06ee7b..0b7ac0df1 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -268,7 +268,7 @@ public: | |||
| 268 | ImageView* depth_buffer, const VideoCommon::RenderTargets& key); | 268 | ImageView* depth_buffer, const VideoCommon::RenderTargets& key); |
| 269 | 269 | ||
| 270 | explicit Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, | 270 | explicit Framebuffer(TextureCacheRuntime& runtime, ImageView* color_buffer, |
| 271 | ImageView* depth_buffer, VkExtent2D extent); | 271 | ImageView* depth_buffer, VkExtent2D extent, bool is_rescaled); |
| 272 | 272 | ||
| 273 | ~Framebuffer(); | 273 | ~Framebuffer(); |
| 274 | 274 | ||
| @@ -279,7 +279,8 @@ public: | |||
| 279 | Framebuffer& operator=(Framebuffer&&) = default; | 279 | Framebuffer& operator=(Framebuffer&&) = default; |
| 280 | 280 | ||
| 281 | void CreateFramebuffer(TextureCacheRuntime& runtime, | 281 | void CreateFramebuffer(TextureCacheRuntime& runtime, |
| 282 | std::span<ImageView*, NUM_RT> color_buffers, ImageView* depth_buffer); | 282 | std::span<ImageView*, NUM_RT> color_buffers, ImageView* depth_buffer, |
| 283 | bool is_rescaled = false); | ||
| 283 | 284 | ||
| 284 | [[nodiscard]] VkFramebuffer Handle() const noexcept { | 285 | [[nodiscard]] VkFramebuffer Handle() const noexcept { |
| 285 | return *framebuffer; | 286 | return *framebuffer; |
diff --git a/src/video_core/texture_cache/render_targets.h b/src/video_core/texture_cache/render_targets.h index da8ffe9ec..1efbd6507 100644 --- a/src/video_core/texture_cache/render_targets.h +++ b/src/video_core/texture_cache/render_targets.h | |||
| @@ -26,6 +26,7 @@ struct RenderTargets { | |||
| 26 | ImageViewId depth_buffer_id{}; | 26 | ImageViewId depth_buffer_id{}; |
| 27 | std::array<u8, NUM_RT> draw_buffers{}; | 27 | std::array<u8, NUM_RT> draw_buffers{}; |
| 28 | Extent2D size{}; | 28 | Extent2D size{}; |
| 29 | bool is_rescaled{}; | ||
| 29 | }; | 30 | }; |
| 30 | 31 | ||
| 31 | } // namespace VideoCommon | 32 | } // namespace VideoCommon |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 66de41f04..9a835cefc 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -357,6 +357,7 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) { | |||
| 357 | (maxwell3d->regs.render_area.width * up_scale) >> down_shift, | 357 | (maxwell3d->regs.render_area.width * up_scale) >> down_shift, |
| 358 | (maxwell3d->regs.render_area.height * up_scale) >> down_shift, | 358 | (maxwell3d->regs.render_area.height * up_scale) >> down_shift, |
| 359 | }; | 359 | }; |
| 360 | render_targets.is_rescaled = is_rescaling; | ||
| 360 | 361 | ||
| 361 | flags[Dirty::DepthBiasGlobal] = true; | 362 | flags[Dirty::DepthBiasGlobal] = true; |
| 362 | } | 363 | } |
| @@ -1962,6 +1963,7 @@ std::pair<FramebufferId, ImageViewId> TextureCache<P>::RenderTargetFromImage( | |||
| 1962 | .color_buffer_ids = {color_view_id}, | 1963 | .color_buffer_ids = {color_view_id}, |
| 1963 | .depth_buffer_id = depth_view_id, | 1964 | .depth_buffer_id = depth_view_id, |
| 1964 | .size = {extent.width >> samples_x, extent.height >> samples_y}, | 1965 | .size = {extent.width >> samples_x, extent.height >> samples_y}, |
| 1966 | .is_rescaled = is_rescaled, | ||
| 1965 | }); | 1967 | }); |
| 1966 | return {framebuffer_id, view_id}; | 1968 | return {framebuffer_id, view_id}; |
| 1967 | } | 1969 | } |