diff options
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 3400066a6..9afe49387 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -1053,6 +1053,10 @@ Image::~Image() = default; | |||
| 1053 | 1053 | ||
| 1054 | void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | 1054 | void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { |
| 1055 | // TODO: Move this to another API | 1055 | // TODO: Move this to another API |
| 1056 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | ||
| 1057 | if (is_rescaled) { | ||
| 1058 | ScaleDown(true); | ||
| 1059 | } | ||
| 1056 | scheduler->RequestOutsideRenderPassOperationContext(); | 1060 | scheduler->RequestOutsideRenderPassOperationContext(); |
| 1057 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); | 1061 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); |
| 1058 | const VkBuffer src_buffer = map.buffer; | 1062 | const VkBuffer src_buffer = map.buffer; |
| @@ -1063,6 +1067,9 @@ void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImag | |||
| 1063 | vk_copies](vk::CommandBuffer cmdbuf) { | 1067 | vk_copies](vk::CommandBuffer cmdbuf) { |
| 1064 | CopyBufferToImage(cmdbuf, src_buffer, vk_image, vk_aspect_mask, is_initialized, vk_copies); | 1068 | CopyBufferToImage(cmdbuf, src_buffer, vk_image, vk_aspect_mask, is_initialized, vk_copies); |
| 1065 | }); | 1069 | }); |
| 1070 | if (is_rescaled) { | ||
| 1071 | ScaleUp(true); | ||
| 1072 | } | ||
| 1066 | } | 1073 | } |
| 1067 | 1074 | ||
| 1068 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | 1075 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { |
| @@ -1133,17 +1140,23 @@ bool Image::ScaleUp(bool save_as_backup) { | |||
| 1133 | } | 1140 | } |
| 1134 | ASSERT(info.type != ImageType::Linear); | 1141 | ASSERT(info.type != ImageType::Linear); |
| 1135 | scaling_count++; | 1142 | scaling_count++; |
| 1136 | ASSERT(scaling_count < 10); | ||
| 1137 | flags |= ImageFlagBits::Rescaled; | 1143 | flags |= ImageFlagBits::Rescaled; |
| 1138 | /*if (!runtime->is_rescaling_on) { | 1144 | if (!runtime->is_rescaling_on) { |
| 1139 | return; | 1145 | return true; |
| 1140 | }*/ | 1146 | } |
| 1147 | |||
| 1141 | const auto& resolution = runtime->resolution; | 1148 | const auto& resolution = runtime->resolution; |
| 1142 | vk::Image rescaled_image = | 1149 | vk::Image rescaled_image = |
| 1143 | MakeImage(runtime->device, info, resolution.up_scale, resolution.down_shift); | 1150 | has_backup ? std::move(backup_image) |
| 1144 | MemoryCommit new_commit( | 1151 | : MakeImage(runtime->device, info, resolution.up_scale, resolution.down_shift); |
| 1145 | runtime->memory_allocator.Commit(rescaled_image, MemoryUsage::DeviceLocal)); | 1152 | MemoryCommit new_commit = has_backup ? std::move(backup_commit) |
| 1153 | : MemoryCommit(runtime->memory_allocator.Commit( | ||
| 1154 | rescaled_image, MemoryUsage::DeviceLocal)); | ||
| 1155 | has_backup = false; | ||
| 1146 | 1156 | ||
| 1157 | if (aspect_mask == 0) { | ||
| 1158 | aspect_mask = ImageAspectMask(info.format); | ||
| 1159 | } | ||
| 1147 | SCOPE_EXIT({ | 1160 | SCOPE_EXIT({ |
| 1148 | if (save_as_backup) { | 1161 | if (save_as_backup) { |
| 1149 | backup_image = std::move(image); | 1162 | backup_image = std::move(image); |
| @@ -1175,6 +1188,9 @@ bool Image::ScaleUp(bool save_as_backup) { | |||
| 1175 | } | 1188 | } |
| 1176 | 1189 | ||
| 1177 | void Image::SwapBackup() { | 1190 | void Image::SwapBackup() { |
| 1191 | if (!runtime->is_rescaling_on) { | ||
| 1192 | return; | ||
| 1193 | } | ||
| 1178 | ASSERT(has_backup); | 1194 | ASSERT(has_backup); |
| 1179 | runtime->prescaled_images.Push(std::move(image)); | 1195 | runtime->prescaled_images.Push(std::move(image)); |
| 1180 | runtime->prescaled_commits.Push(std::move(commit)); | 1196 | runtime->prescaled_commits.Push(std::move(commit)); |
| @@ -1190,16 +1206,18 @@ bool Image::ScaleDown(bool save_as_backup) { | |||
| 1190 | ASSERT(info.type != ImageType::Linear); | 1206 | ASSERT(info.type != ImageType::Linear); |
| 1191 | flags &= ~ImageFlagBits::Rescaled; | 1207 | flags &= ~ImageFlagBits::Rescaled; |
| 1192 | scaling_count++; | 1208 | scaling_count++; |
| 1193 | ASSERT(scaling_count < 10); | 1209 | if (!runtime->is_rescaling_on) { |
| 1194 | /*if (!runtime->is_rescaling_on) { | 1210 | return true; |
| 1195 | return false; | 1211 | } |
| 1196 | }*/ | ||
| 1197 | 1212 | ||
| 1198 | const auto& resolution = runtime->resolution; | 1213 | const auto& resolution = runtime->resolution; |
| 1199 | vk::Image downscaled_image = MakeImage(runtime->device, info); | 1214 | vk::Image downscaled_image = |
| 1200 | MemoryCommit new_commit( | 1215 | has_backup ? std::move(backup_image) : MakeImage(runtime->device, info); |
| 1201 | runtime->memory_allocator.Commit(downscaled_image, MemoryUsage::DeviceLocal)); | 1216 | MemoryCommit new_commit = has_backup ? std::move(backup_commit) |
| 1217 | : MemoryCommit(runtime->memory_allocator.Commit( | ||
| 1218 | downscaled_image, MemoryUsage::DeviceLocal)); | ||
| 1202 | 1219 | ||
| 1220 | has_backup = false; | ||
| 1203 | if (aspect_mask == 0) { | 1221 | if (aspect_mask == 0) { |
| 1204 | aspect_mask = ImageAspectMask(info.format); | 1222 | aspect_mask = ImageAspectMask(info.format); |
| 1205 | } | 1223 | } |