summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp168
1 files changed, 62 insertions, 106 deletions
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
index d95eeafb9..720247b4e 100644
--- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp
@@ -594,12 +594,67 @@ struct RangedBarrierRange {
594 return VK_FORMAT_R32_UINT; 594 return VK_FORMAT_R32_UINT;
595} 595}
596 596
597void BlitScale(VKScheduler& scheduler, VkImage src_image, VkImage dst_image, 597void BlitScale(VKScheduler& scheduler, VkImage src_image, VkImage dst_image, const ImageInfo& info,
598 boost::container::small_vector<VkImageBlit, 4>&& blit_regions, 598 VkImageAspectFlags aspect_mask, const Settings::ResolutionScalingInfo& resolution) {
599 VkImageAspectFlags aspect_mask) { 599 const auto type = info.type;
600 const auto resources = info.resources;
601 const VkExtent2D extent{
602 .width = info.size.width,
603 .height = info.size.height,
604 };
600 scheduler.RequestOutsideRenderPassOperationContext(); 605 scheduler.RequestOutsideRenderPassOperationContext();
601 scheduler.Record([dst_image, src_image, aspect_mask, 606 scheduler.Record([dst_image, src_image, extent, resources, aspect_mask, resolution,
602 regions = std::move(blit_regions)](vk::CommandBuffer cmdbuf) { 607 type](vk::CommandBuffer cmdbuf) {
608 const auto scale_up = [&](u32 value) {
609 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
610 };
611 const bool is_2d = type == ImageType::e2D;
612 const VkOffset2D mip0_size{
613 .x = static_cast<s32>(scale_up(extent.width)),
614 .y = static_cast<s32>(is_2d ? scale_up(extent.height) : extent.height),
615 };
616 boost::container::small_vector<VkImageBlit, 4> regions;
617 regions.reserve(resources.levels);
618 for (s32 level = 0; level < resources.levels; level++) {
619 regions.push_back({
620 .srcSubresource{
621 .aspectMask = aspect_mask,
622 .mipLevel = static_cast<u32>(level),
623 .baseArrayLayer = 0,
624 .layerCount = static_cast<u32>(resources.layers),
625 },
626 .srcOffsets{
627 {
628 .x = 0,
629 .y = 0,
630 .z = 0,
631 },
632 {
633 .x = static_cast<s32>(extent.width),
634 .y = static_cast<s32>(extent.height),
635 .z = 1,
636 },
637 },
638 .dstSubresource{
639 .aspectMask = aspect_mask,
640 .mipLevel = static_cast<u32>(level),
641 .baseArrayLayer = 0,
642 .layerCount = static_cast<u32>(resources.layers),
643 },
644 .dstOffsets{
645 {
646 .x = 0,
647 .y = 0,
648 .z = 0,
649 },
650 {
651 .x = std::max(1, mip0_size.x >> level),
652 .y = std::max(1, mip0_size.y >> level),
653 .z = 1,
654 },
655 },
656 });
657 }
603 const VkImageSubresourceRange subresource_range{ 658 const VkImageSubresourceRange subresource_range{
604 .aspectMask = aspect_mask, 659 .aspectMask = aspect_mask,
605 .baseMipLevel = 0, 660 .baseMipLevel = 0,
@@ -1102,57 +1157,7 @@ bool Image::ScaleUp(bool save_as_backup) {
1102 if (aspect_mask == 0) { 1157 if (aspect_mask == 0) {
1103 aspect_mask = ImageAspectMask(info.format); 1158 aspect_mask = ImageAspectMask(info.format);
1104 } 1159 }
1105 1160 BlitScale(*scheduler, *image, *rescaled_image, info, aspect_mask, resolution);
1106 const auto scale_up = [&](u32 value) {
1107 return std::max<u32>((value * resolution.up_scale) >> resolution.down_shift, 1U);
1108 };
1109
1110 const bool is_2d = info.type == ImageType::e2D;
1111 boost::container::small_vector<VkImageBlit, 4> regions;
1112 regions.reserve(info.resources.levels);
1113 for (s32 level = 0; level < info.resources.levels; level++) {
1114 regions.push_back({
1115 .srcSubresource{
1116 .aspectMask = aspect_mask,
1117 .mipLevel = u32(level),
1118 .baseArrayLayer = 0,
1119 .layerCount = u32(info.resources.layers),
1120 },
1121 .srcOffsets{
1122 {
1123 .x = 0,
1124 .y = 0,
1125 .z = 0,
1126 },
1127 {
1128 .x = static_cast<s32>(info.size.width),
1129 .y = static_cast<s32>(info.size.height),
1130 .z = 1,
1131 },
1132 },
1133 .dstSubresource{
1134 .aspectMask = aspect_mask,
1135 .mipLevel = u32(level),
1136 .baseArrayLayer = 0,
1137 .layerCount = u32(info.resources.layers),
1138 },
1139 .dstOffsets{
1140 {
1141 .x = 0,
1142 .y = 0,
1143 .z = 0,
1144 },
1145 {
1146 .x = std::max(1, static_cast<s32>(scale_up(info.size.width)) >> level),
1147 .y = std::max(1, static_cast<s32>(is_2d ? scale_up(info.size.height)
1148 : info.size.height) >>
1149 level),
1150 .z = 1,
1151 },
1152 },
1153 });
1154 }
1155 BlitScale(*scheduler, *image, *rescaled_image, std::move(regions), aspect_mask);
1156 return true; 1161 return true;
1157} 1162}
1158 1163
@@ -1183,60 +1188,11 @@ bool Image::ScaleDown(bool save_as_backup) {
1183 MemoryCommit new_commit( 1188 MemoryCommit new_commit(
1184 runtime->memory_allocator.Commit(downscaled_image, MemoryUsage::DeviceLocal)); 1189 runtime->memory_allocator.Commit(downscaled_image, MemoryUsage::DeviceLocal));
1185 1190
1186 const auto scale_up = [&](u32 value) {
1187 return (value * resolution.up_scale) >> resolution.down_shift;
1188 };
1189
1190 if (aspect_mask == 0) { 1191 if (aspect_mask == 0) {
1191 aspect_mask = ImageAspectMask(info.format); 1192 aspect_mask = ImageAspectMask(info.format);
1192 } 1193 }
1194 BlitScale(*scheduler, *image, *downscaled_image, info, aspect_mask, resolution);
1193 1195
1194 const bool is_2d = info.type == ImageType::e2D;
1195 boost::container::small_vector<VkImageBlit, 4> regions;
1196 regions.reserve(info.resources.levels);
1197 for (s32 level = 0; level < info.resources.levels; level++) {
1198 regions.push_back({
1199 .srcSubresource{
1200 .aspectMask = aspect_mask,
1201 .mipLevel = static_cast<u32>(level),
1202 .baseArrayLayer = 0,
1203 .layerCount = static_cast<u32>(info.resources.layers),
1204 },
1205 .srcOffsets{
1206 {
1207 .x = 0,
1208 .y = 0,
1209 .z = 0,
1210 },
1211 {
1212 .x = std::max(1, static_cast<s32>(scale_up(info.size.width)) >> level),
1213 .y = std::max(1, static_cast<s32>(is_2d ? scale_up(info.size.height)
1214 : info.size.height) >>
1215 level),
1216 .z = 1,
1217 },
1218 },
1219 .dstSubresource{
1220 .aspectMask = aspect_mask,
1221 .mipLevel = static_cast<u32>(level),
1222 .baseArrayLayer = 0,
1223 .layerCount = static_cast<u32>(info.resources.layers),
1224 },
1225 .dstOffsets{
1226 {
1227 .x = 0,
1228 .y = 0,
1229 .z = 0,
1230 },
1231 {
1232 .x = std::max(1, static_cast<s32>(info.size.width) >> level),
1233 .y = std::max(1, static_cast<s32>(info.size.height) >> level),
1234 .z = 1,
1235 },
1236 },
1237 });
1238 }
1239 BlitScale(*scheduler, *image, *downscaled_image, std::move(regions), aspect_mask);
1240 if (save_as_backup) { 1196 if (save_as_backup) {
1241 backup_image = std::move(image); 1197 backup_image = std::move(image);
1242 backup_commit = std::move(commit); 1198 backup_commit = std::move(commit);