summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ameerj2021-10-12 00:35:01 -0400
committerGravatar Fernando Sahmkow2021-11-16 22:11:31 +0100
commitabd07e41582b6d8f7efdedb936cdd7a7fddf9912 (patch)
tree4b1b3c2a676abc935517b669566068270029b6d3 /src
parenttexture_cache: Fix image resolves when src/dst are not both scaled (diff)
downloadyuzu-abd07e41582b6d8f7efdedb936cdd7a7fddf9912.tar.gz
yuzu-abd07e41582b6d8f7efdedb936cdd7a7fddf9912.tar.xz
yuzu-abd07e41582b6d8f7efdedb936cdd7a7fddf9912.zip
video_core: Refactor resolution scale function
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.h14
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp8
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp19
-rw-r--r--src/video_core/texture_cache/texture_cache.h39
4 files changed, 34 insertions, 46 deletions
diff --git a/src/common/settings.h b/src/common/settings.h
index f629c7c56..09f7cdd84 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -72,6 +72,20 @@ struct ResolutionScalingInfo {
72 f32 up_factor{1.0f}; 72 f32 up_factor{1.0f};
73 f32 down_factor{1.0f}; 73 f32 down_factor{1.0f};
74 bool active{}; 74 bool active{};
75
76 s32 ScaleUp(s32 value) const {
77 if (value == 0) {
78 return 0;
79 }
80 return std::max((value * static_cast<s32>(up_scale)) >> static_cast<s32>(down_shift), 1);
81 }
82
83 u32 ScaleUp(u32 value) const {
84 if (value == 0U) {
85 return 0U;
86 }
87 return std::max((value * up_scale) >> down_shift, 1U);
88 }
75}; 89};
76 90
77/** The BasicSetting class is a simple resource manager. It defines a label and default value 91/** The BasicSetting class is a simple resource manager. It defines a label and default value
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 3dfd13d6a..ec1afd31a 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -924,12 +924,8 @@ bool Image::Scale() {
924 const GLenum filter = linear_color_format ? GL_LINEAR : GL_NEAREST; 924 const GLenum filter = linear_color_format ? GL_LINEAR : GL_NEAREST;
925 925
926 const auto& resolution = runtime->resolution; 926 const auto& resolution = runtime->resolution;
927 const u32 up = resolution.up_scale; 927 const u32 scaled_width = resolution.ScaleUp(info.size.width);
928 const u32 down = resolution.down_shift; 928 const u32 scaled_height = is_2d ? resolution.ScaleUp(info.size.height) : info.size.height;
929 const auto scale = [&](u32 value) { return std::max<u32>((value * up) >> down, 1U); };
930
931 const u32 scaled_width = scale(info.size.width);
932 const u32 scaled_height = is_2d ? scale(info.size.height) : info.size.height;
933 const u32 original_width = info.size.width; 929 const u32 original_width = info.size.width;
934 const u32 original_height = info.size.height; 930 const u32 original_height = info.size.height;
935 931
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index 65506f75e..caefce5fc 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -607,16 +607,13 @@ void BlitScale(VKScheduler& scheduler, VkImage src_image, VkImage dst_image, con
607 scheduler.RequestOutsideRenderPassOperationContext(); 607 scheduler.RequestOutsideRenderPassOperationContext();
608 scheduler.Record([dst_image, src_image, extent, resources, aspect_mask, resolution, type, 608 scheduler.Record([dst_image, src_image, extent, resources, aspect_mask, resolution, type,
609 scaling, vk_filter](vk::CommandBuffer cmdbuf) { 609 scaling, vk_filter](vk::CommandBuffer cmdbuf) {
610 const auto scale_up = [&](u32 value) {
611 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
612 };
613 const VkOffset2D src_size{ 610 const VkOffset2D src_size{
614 .x = static_cast<s32>(scaling ? extent.width : scale_up(extent.width)), 611 .x = static_cast<s32>(scaling ? extent.width : resolution.ScaleUp(extent.width)),
615 .y = static_cast<s32>(scaling ? extent.height : scale_up(extent.height)), 612 .y = static_cast<s32>(scaling ? extent.height : resolution.ScaleUp(extent.height)),
616 }; 613 };
617 const VkOffset2D dst_size{ 614 const VkOffset2D dst_size{
618 .x = static_cast<s32>(scaling ? scale_up(extent.width) : extent.width), 615 .x = static_cast<s32>(scaling ? resolution.ScaleUp(extent.width) : extent.width),
619 .y = static_cast<s32>(scaling ? scale_up(extent.height) : extent.height), 616 .y = static_cast<s32>(scaling ? resolution.ScaleUp(extent.height) : extent.height),
620 }; 617 };
621 boost::container::small_vector<VkImageBlit, 4> regions; 618 boost::container::small_vector<VkImageBlit, 4> regions;
622 regions.reserve(resources.levels); 619 regions.reserve(resources.levels);
@@ -1144,13 +1141,9 @@ bool Image::ScaleUp() {
1144 return false; 1141 return false;
1145 } 1142 }
1146 if (!scaled_image) { 1143 if (!scaled_image) {
1147 const u32 up = resolution.up_scale;
1148 const u32 down = resolution.down_shift;
1149 const auto scale = [&](u32 value) { return std::max<u32>((value * up) >> down, 1U); };
1150
1151 const bool is_2d = info.type == ImageType::e2D; 1144 const bool is_2d = info.type == ImageType::e2D;
1152 const u32 scaled_width = scale(info.size.width); 1145 const u32 scaled_width = resolution.ScaleUp(info.size.width);
1153 const u32 scaled_height = is_2d ? scale(info.size.height) : info.size.height; 1146 const u32 scaled_height = is_2d ? resolution.ScaleUp(info.size.height) : info.size.height;
1154 auto scaled_info = info; 1147 auto scaled_info = info;
1155 scaled_info.size.width = scaled_width; 1148 scaled_info.size.width = scaled_width;
1156 scaled_info.size.height = scaled_height; 1149 scaled_info.size.height = scaled_height;
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 38895c2e9..c77332b46 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -504,17 +504,11 @@ void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst,
504 is_dst_rescaled = True(dst_image.flags & ImageFlagBits::Rescaled); 504 is_dst_rescaled = True(dst_image.flags & ImageFlagBits::Rescaled);
505 } 505 }
506 const auto& resolution = Settings::values.resolution_info; 506 const auto& resolution = Settings::values.resolution_info;
507 const auto scale_up = [&](u32 value) -> u32 {
508 if (value == 0) {
509 return 0U;
510 }
511 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
512 };
513 const auto scale_region = [&](Region2D& region) { 507 const auto scale_region = [&](Region2D& region) {
514 region.start.x = scale_up(region.start.x); 508 region.start.x = resolution.ScaleUp(region.start.x);
515 region.start.y = scale_up(region.start.y); 509 region.start.y = resolution.ScaleUp(region.start.y);
516 region.end.x = scale_up(region.end.x); 510 region.end.x = resolution.ScaleUp(region.end.x);
517 region.end.y = scale_up(region.end.y); 511 region.end.y = resolution.ScaleUp(region.end.y);
518 }; 512 };
519 513
520 // TODO: Deduplicate 514 // TODO: Deduplicate
@@ -1721,20 +1715,14 @@ void TextureCache<P>::CopyImage(ImageId dst_id, ImageId src_id, std::vector<Imag
1721 ASSERT(True(dst.flags & ImageFlagBits::Rescaled)); 1715 ASSERT(True(dst.flags & ImageFlagBits::Rescaled));
1722 const bool both_2d{src.info.type == ImageType::e2D && dst.info.type == ImageType::e2D}; 1716 const bool both_2d{src.info.type == ImageType::e2D && dst.info.type == ImageType::e2D};
1723 const auto& resolution = Settings::values.resolution_info; 1717 const auto& resolution = Settings::values.resolution_info;
1724 const auto scale_up = [&](u32 value) -> u32 {
1725 if (value == 0) {
1726 return 0U;
1727 }
1728 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
1729 };
1730 for (auto& copy : copies) { 1718 for (auto& copy : copies) {
1731 copy.src_offset.x = scale_up(copy.src_offset.x); 1719 copy.src_offset.x = resolution.ScaleUp(copy.src_offset.x);
1732 copy.dst_offset.x = scale_up(copy.dst_offset.x); 1720 copy.dst_offset.x = resolution.ScaleUp(copy.dst_offset.x);
1733 copy.extent.width = scale_up(copy.extent.width); 1721 copy.extent.width = resolution.ScaleUp(copy.extent.width);
1734 if (both_2d) { 1722 if (both_2d) {
1735 copy.src_offset.y = scale_up(copy.src_offset.y); 1723 copy.src_offset.y = resolution.ScaleUp(copy.src_offset.y);
1736 copy.dst_offset.y = scale_up(copy.dst_offset.y); 1724 copy.dst_offset.y = resolution.ScaleUp(copy.dst_offset.y);
1737 copy.extent.height = scale_up(copy.extent.height); 1725 copy.extent.height = resolution.ScaleUp(copy.extent.height);
1738 } 1726 }
1739 } 1727 }
1740 } 1728 }
@@ -1812,12 +1800,9 @@ std::pair<FramebufferId, ImageViewId> TextureCache<P>::RenderTargetFromImage(
1812 Extent3D extent = MipSize(image.info.size, view_info.range.base.level); 1800 Extent3D extent = MipSize(image.info.size, view_info.range.base.level);
1813 if (is_rescaled) { 1801 if (is_rescaled) {
1814 const auto& resolution = Settings::values.resolution_info; 1802 const auto& resolution = Settings::values.resolution_info;
1815 const auto scale_up = [&](u32 value) { 1803 extent.width = resolution.ScaleUp(extent.width);
1816 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
1817 };
1818 extent.width = scale_up(extent.width);
1819 if (image.info.type == ImageType::e2D) { 1804 if (image.info.type == ImageType::e2D) {
1820 extent.height = scale_up(extent.height); 1805 extent.height = resolution.ScaleUp(extent.height);
1821 } 1806 }
1822 } 1807 }
1823 const u32 num_samples = image.info.num_samples; 1808 const u32 num_samples = image.info.num_samples;