diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 259 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 10 | ||||
| -rw-r--r-- | src/video_core/texture_cache/image_info.cpp | 3 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 84 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache_base.h | 3 |
6 files changed, 327 insertions, 42 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 1e594838f..cdd352aef 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -849,20 +849,22 @@ void Image::CopyImageToBuffer(const VideoCommon::BufferImageCopy& copy, size_t b | |||
| 849 | } | 849 | } |
| 850 | } | 850 | } |
| 851 | 851 | ||
| 852 | void Image::ScaleUp() { | 852 | bool Image::ScaleUp() { |
| 853 | if (True(flags & ImageFlagBits::Rescaled)) { | 853 | if (True(flags & ImageFlagBits::Rescaled)) { |
| 854 | return; | 854 | return false; |
| 855 | } | 855 | } |
| 856 | flags |= ImageFlagBits::Rescaled; | 856 | flags |= ImageFlagBits::Rescaled; |
| 857 | UNIMPLEMENTED(); | 857 | UNIMPLEMENTED(); |
| 858 | return true; | ||
| 858 | } | 859 | } |
| 859 | 860 | ||
| 860 | void Image::ScaleDown() { | 861 | bool Image::ScaleDown() { |
| 861 | if (False(flags & ImageFlagBits::Rescaled)) { | 862 | if (False(flags & ImageFlagBits::Rescaled)) { |
| 862 | return; | 863 | return false; |
| 863 | } | 864 | } |
| 864 | flags &= ~ImageFlagBits::Rescaled; | 865 | flags &= ~ImageFlagBits::Rescaled; |
| 865 | UNIMPLEMENTED(); | 866 | UNIMPLEMENTED(); |
| 867 | return true; | ||
| 866 | } | 868 | } |
| 867 | 869 | ||
| 868 | ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewInfo& info, | 870 | ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewInfo& info, |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index be5b1d84d..668554d1e 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -137,6 +137,7 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 137 | flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; | 137 | flags |= VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT; |
| 138 | } | 138 | } |
| 139 | const auto [samples_x, samples_y] = VideoCommon::SamplesLog2(info.num_samples); | 139 | const auto [samples_x, samples_y] = VideoCommon::SamplesLog2(info.num_samples); |
| 140 | const bool is_2d = info.type == ImageType::e2D; | ||
| 140 | return VkImageCreateInfo{ | 141 | return VkImageCreateInfo{ |
| 141 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, | 142 | .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, |
| 142 | .pNext = nullptr, | 143 | .pNext = nullptr, |
| @@ -144,9 +145,9 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 144 | .imageType = ConvertImageType(info.type), | 145 | .imageType = ConvertImageType(info.type), |
| 145 | .format = format_info.format, | 146 | .format = format_info.format, |
| 146 | .extent{ | 147 | .extent{ |
| 147 | .width = ((info.size.width << up) >> down) >> samples_x, | 148 | .width = ((info.size.width * up) >> down) >> samples_x, |
| 148 | .height = ((info.size.height << up) >> down) >> samples_y, | 149 | .height = (is_2d ? ((info.size.height * up) >> down) : info.size.height) >> samples_y, |
| 149 | .depth = (info.size.depth << up) >> down, | 150 | .depth = info.size.depth, |
| 150 | }, | 151 | }, |
| 151 | .mipLevels = static_cast<u32>(info.resources.levels), | 152 | .mipLevels = static_cast<u32>(info.resources.levels), |
| 152 | .arrayLayers = static_cast<u32>(info.resources.layers), | 153 | .arrayLayers = static_cast<u32>(info.resources.layers), |
| @@ -160,7 +161,7 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 160 | }; | 161 | }; |
| 161 | } | 162 | } |
| 162 | 163 | ||
| 163 | [[nodiscard]] vk::Image MakeImage(const Device& device, const ImageInfo& info, u32 up = 0, | 164 | [[nodiscard]] vk::Image MakeImage(const Device& device, const ImageInfo& info, u32 up = 1, |
| 164 | u32 down = 0) { | 165 | u32 down = 0) { |
| 165 | if (info.type == ImageType::Buffer) { | 166 | if (info.type == ImageType::Buffer) { |
| 166 | return vk::Image{}; | 167 | return vk::Image{}; |
| @@ -851,7 +852,6 @@ u64 TextureCacheRuntime::GetDeviceLocalMemory() const { | |||
| 851 | void TextureCacheRuntime::TickFrame() { | 852 | void TextureCacheRuntime::TickFrame() { |
| 852 | prescaled_images.Tick(); | 853 | prescaled_images.Tick(); |
| 853 | prescaled_commits.Tick(); | 854 | prescaled_commits.Tick(); |
| 854 | prescaled_views.Tick(); | ||
| 855 | } | 855 | } |
| 856 | 856 | ||
| 857 | Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, | 857 | Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, |
| @@ -923,7 +923,7 @@ void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImag | |||
| 923 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | 923 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { |
| 924 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 924 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 925 | if (is_rescaled) { | 925 | if (is_rescaled) { |
| 926 | ScaleDown(); | 926 | ScaleDown(true); |
| 927 | } | 927 | } |
| 928 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); | 928 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); |
| 929 | scheduler->RequestOutsideRenderPassOperationContext(); | 929 | scheduler->RequestOutsideRenderPassOperationContext(); |
| @@ -978,38 +978,253 @@ void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferIm | |||
| 978 | 0, memory_write_barrier, nullptr, image_write_barrier); | 978 | 0, memory_write_barrier, nullptr, image_write_barrier); |
| 979 | }); | 979 | }); |
| 980 | if (is_rescaled) { | 980 | if (is_rescaled) { |
| 981 | ScaleUp(); | 981 | SwapBackup(); |
| 982 | } | 982 | } |
| 983 | } | 983 | } |
| 984 | 984 | ||
| 985 | void Image::ScaleUp() { | 985 | void BlitScale(VKScheduler& scheduler, VkImage src_image, VkImage dst_image, |
| 986 | boost::container::small_vector<VkImageBlit, 4>& blit_regions, | ||
| 987 | VkImageAspectFlags aspect_mask) { | ||
| 988 | scheduler.RequestOutsideRenderPassOperationContext(); | ||
| 989 | scheduler.Record([dst_image, src_image, aspect_mask, | ||
| 990 | regions = std::move(blit_regions)](vk::CommandBuffer cmdbuf) { | ||
| 991 | const std::array read_barriers{ | ||
| 992 | VkImageMemoryBarrier{ | ||
| 993 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 994 | .pNext = nullptr, | ||
| 995 | .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT | | ||
| 996 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | | ||
| 997 | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 998 | .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, | ||
| 999 | .oldLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 1000 | .newLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 1001 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1002 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1003 | .image = src_image, | ||
| 1004 | .subresourceRange{ | ||
| 1005 | .aspectMask = aspect_mask, | ||
| 1006 | .baseMipLevel = 0, | ||
| 1007 | .levelCount = VK_REMAINING_MIP_LEVELS, | ||
| 1008 | .baseArrayLayer = 0, | ||
| 1009 | .layerCount = VK_REMAINING_ARRAY_LAYERS, | ||
| 1010 | }, | ||
| 1011 | }, | ||
| 1012 | VkImageMemoryBarrier{ | ||
| 1013 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 1014 | .pNext = nullptr, | ||
| 1015 | .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT | | ||
| 1016 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | | ||
| 1017 | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 1018 | .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 1019 | .oldLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 1020 | .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, | ||
| 1021 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1022 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1023 | .image = dst_image, | ||
| 1024 | .subresourceRange{ | ||
| 1025 | .aspectMask = aspect_mask, | ||
| 1026 | .baseMipLevel = 0, | ||
| 1027 | .levelCount = VK_REMAINING_MIP_LEVELS, | ||
| 1028 | .baseArrayLayer = 0, | ||
| 1029 | .layerCount = VK_REMAINING_ARRAY_LAYERS, | ||
| 1030 | }, | ||
| 1031 | }, | ||
| 1032 | }; | ||
| 1033 | VkImageMemoryBarrier write_barrier{ | ||
| 1034 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 1035 | .pNext = nullptr, | ||
| 1036 | .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 1037 | .dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT | | ||
| 1038 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | | ||
| 1039 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | | ||
| 1040 | VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 1041 | .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, | ||
| 1042 | .newLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 1043 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1044 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 1045 | .image = dst_image, | ||
| 1046 | .subresourceRange{ | ||
| 1047 | .aspectMask = aspect_mask, | ||
| 1048 | .baseMipLevel = 0, | ||
| 1049 | .levelCount = VK_REMAINING_MIP_LEVELS, | ||
| 1050 | .baseArrayLayer = 0, | ||
| 1051 | .layerCount = VK_REMAINING_ARRAY_LAYERS, | ||
| 1052 | }, | ||
| 1053 | }; | ||
| 1054 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, | ||
| 1055 | 0, nullptr, nullptr, read_barriers); | ||
| 1056 | const VkFilter vk_filter = VK_FILTER_NEAREST; | ||
| 1057 | cmdbuf.BlitImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, | ||
| 1058 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, regions, vk_filter); | ||
| 1059 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, | ||
| 1060 | 0, write_barrier); | ||
| 1061 | }); | ||
| 1062 | } | ||
| 1063 | |||
| 1064 | bool Image::ScaleUp(bool save_as_backup) { | ||
| 986 | if (True(flags & ImageFlagBits::Rescaled)) { | 1065 | if (True(flags & ImageFlagBits::Rescaled)) { |
| 987 | return; | 1066 | return false; |
| 988 | } | 1067 | } |
| 989 | ASSERT(info.type != ImageType::Linear); | 1068 | ASSERT(info.type != ImageType::Linear); |
| 990 | if (!runtime->is_rescaling_on) { | ||
| 991 | flags |= ImageFlagBits::Rescaled; | ||
| 992 | return; | ||
| 993 | } | ||
| 994 | flags |= ImageFlagBits::Rescaled; | ||
| 995 | scaling_count++; | 1069 | scaling_count++; |
| 996 | ASSERT(scaling_count < 10); | 1070 | ASSERT(scaling_count < 10); |
| 997 | return; | 1071 | flags |= ImageFlagBits::Rescaled; |
| 1072 | /*if (!runtime->is_rescaling_on) { | ||
| 1073 | return; | ||
| 1074 | }*/ | ||
| 1075 | const auto& resolution = runtime->resolution; | ||
| 1076 | vk::Image rescaled_image = | ||
| 1077 | MakeImage(runtime->device, info, resolution.up_scale, resolution.down_shift); | ||
| 1078 | MemoryCommit new_commit( | ||
| 1079 | runtime->memory_allocator.Commit(rescaled_image, MemoryUsage::DeviceLocal)); | ||
| 1080 | |||
| 1081 | const auto scale_up = [&](u32 value) { | ||
| 1082 | return (value * resolution.up_scale) >> resolution.down_shift; | ||
| 1083 | }; | ||
| 1084 | |||
| 1085 | const bool is_2d = info.type == ImageType::e2D; | ||
| 1086 | boost::container::small_vector<VkImageBlit, 4> vkRegions(info.resources.levels); | ||
| 1087 | for (s32 level = 0; level < info.resources.levels; level++) { | ||
| 1088 | VkImageBlit blit{ | ||
| 1089 | .srcSubresource{ | ||
| 1090 | .aspectMask = aspect_mask, | ||
| 1091 | .mipLevel = u32(level), | ||
| 1092 | .baseArrayLayer = 0, | ||
| 1093 | .layerCount = u32(info.resources.layers), | ||
| 1094 | }, | ||
| 1095 | .srcOffsets{ | ||
| 1096 | { | ||
| 1097 | .x = 0, | ||
| 1098 | .y = 0, | ||
| 1099 | .z = 0, | ||
| 1100 | }, | ||
| 1101 | { | ||
| 1102 | .x = s32(info.size.width), | ||
| 1103 | .y = s32(info.size.height), | ||
| 1104 | .z = 1, | ||
| 1105 | }, | ||
| 1106 | }, | ||
| 1107 | .dstSubresource{ | ||
| 1108 | .aspectMask = aspect_mask, | ||
| 1109 | .mipLevel = u32(level), | ||
| 1110 | .baseArrayLayer = 0, | ||
| 1111 | .layerCount = u32(info.resources.layers), | ||
| 1112 | }, | ||
| 1113 | .dstOffsets{ | ||
| 1114 | { | ||
| 1115 | .x = 0, | ||
| 1116 | .y = 0, | ||
| 1117 | .z = 0, | ||
| 1118 | }, | ||
| 1119 | { | ||
| 1120 | .x = s32(scale_up(info.size.width)), | ||
| 1121 | .y = is_2d ? s32(scale_up(info.size.height)) : s32(info.size.height), | ||
| 1122 | .z = 1, | ||
| 1123 | }, | ||
| 1124 | }, | ||
| 1125 | }; | ||
| 1126 | vkRegions.push_back(blit); | ||
| 1127 | } | ||
| 1128 | BlitScale(*scheduler, *image, *rescaled_image, vkRegions, aspect_mask); | ||
| 1129 | if (save_as_backup) { | ||
| 1130 | backup_image = std::move(image); | ||
| 1131 | backup_commit = std::move(commit); | ||
| 1132 | has_backup = true; | ||
| 1133 | } else { | ||
| 1134 | runtime->prescaled_images.Push(std::move(image)); | ||
| 1135 | runtime->prescaled_commits.Push(std::move(commit)); | ||
| 1136 | } | ||
| 1137 | image = std::move(rescaled_image); | ||
| 1138 | commit = std::move(new_commit); | ||
| 1139 | return true; | ||
| 998 | } | 1140 | } |
| 999 | 1141 | ||
| 1000 | void Image::ScaleDown() { | 1142 | void Image::SwapBackup() { |
| 1143 | ASSERT(has_backup); | ||
| 1144 | runtime->prescaled_images.Push(std::move(image)); | ||
| 1145 | runtime->prescaled_commits.Push(std::move(commit)); | ||
| 1146 | image = std::move(backup_image); | ||
| 1147 | commit = std::move(backup_commit); | ||
| 1148 | has_backup = false; | ||
| 1149 | } | ||
| 1150 | |||
| 1151 | bool Image::ScaleDown(bool save_as_backup) { | ||
| 1001 | if (False(flags & ImageFlagBits::Rescaled)) { | 1152 | if (False(flags & ImageFlagBits::Rescaled)) { |
| 1002 | return; | 1153 | return false; |
| 1003 | } | 1154 | } |
| 1004 | ASSERT(info.type != ImageType::Linear); | 1155 | ASSERT(info.type != ImageType::Linear); |
| 1005 | if (!runtime->is_rescaling_on) { | ||
| 1006 | flags &= ~ImageFlagBits::Rescaled; | ||
| 1007 | return; | ||
| 1008 | } | ||
| 1009 | flags &= ~ImageFlagBits::Rescaled; | 1156 | flags &= ~ImageFlagBits::Rescaled; |
| 1010 | scaling_count++; | 1157 | scaling_count++; |
| 1011 | ASSERT(scaling_count < 10); | 1158 | ASSERT(scaling_count < 10); |
| 1012 | return; | 1159 | /*if (!runtime->is_rescaling_on) { |
| 1160 | return false; | ||
| 1161 | }*/ | ||
| 1162 | |||
| 1163 | const auto& resolution = runtime->resolution; | ||
| 1164 | vk::Image downscaled_image = | ||
| 1165 | MakeImage(runtime->device, info, resolution.up_scale, resolution.down_shift); | ||
| 1166 | MemoryCommit new_commit( | ||
| 1167 | runtime->memory_allocator.Commit(downscaled_image, MemoryUsage::DeviceLocal)); | ||
| 1168 | |||
| 1169 | const auto scale_up = [&](u32 value) { | ||
| 1170 | return (value * resolution.up_scale) >> resolution.down_shift; | ||
| 1171 | }; | ||
| 1172 | |||
| 1173 | const bool is_2d = info.type == ImageType::e2D; | ||
| 1174 | boost::container::small_vector<VkImageBlit, 4> vkRegions(info.resources.levels); | ||
| 1175 | for (s32 level = 0; level < info.resources.levels; level++) { | ||
| 1176 | VkImageBlit blit{ | ||
| 1177 | .srcSubresource{ | ||
| 1178 | .aspectMask = aspect_mask, | ||
| 1179 | .mipLevel = u32(level), | ||
| 1180 | .baseArrayLayer = 0, | ||
| 1181 | .layerCount = u32(info.resources.layers), | ||
| 1182 | }, | ||
| 1183 | .srcOffsets{ | ||
| 1184 | { | ||
| 1185 | .x = 0, | ||
| 1186 | .y = 0, | ||
| 1187 | .z = 0, | ||
| 1188 | }, | ||
| 1189 | { | ||
| 1190 | .x = s32(scale_up(info.size.width)), | ||
| 1191 | .y = is_2d ? s32(scale_up(info.size.height)) : s32(info.size.height), | ||
| 1192 | .z = 1, | ||
| 1193 | }, | ||
| 1194 | }, | ||
| 1195 | .dstSubresource{ | ||
| 1196 | .aspectMask = aspect_mask, | ||
| 1197 | .mipLevel = u32(level), | ||
| 1198 | .baseArrayLayer = 0, | ||
| 1199 | .layerCount = u32(info.resources.layers), | ||
| 1200 | }, | ||
| 1201 | .dstOffsets{ | ||
| 1202 | { | ||
| 1203 | .x = 0, | ||
| 1204 | .y = 0, | ||
| 1205 | .z = 0, | ||
| 1206 | }, | ||
| 1207 | { | ||
| 1208 | .x = s32(info.size.width), | ||
| 1209 | .y = s32(info.size.height), | ||
| 1210 | .z = 1, | ||
| 1211 | }, | ||
| 1212 | }, | ||
| 1213 | }; | ||
| 1214 | vkRegions.push_back(blit); | ||
| 1215 | } | ||
| 1216 | BlitScale(*scheduler, *image, *downscaled_image, vkRegions, aspect_mask); | ||
| 1217 | if (save_as_backup) { | ||
| 1218 | backup_image = std::move(image); | ||
| 1219 | backup_commit = std::move(commit); | ||
| 1220 | has_backup = true; | ||
| 1221 | } else { | ||
| 1222 | runtime->prescaled_images.Push(std::move(image)); | ||
| 1223 | runtime->prescaled_commits.Push(std::move(commit)); | ||
| 1224 | } | ||
| 1225 | image = std::move(downscaled_image); | ||
| 1226 | commit = std::move(new_commit); | ||
| 1227 | return true; | ||
| 1013 | } | 1228 | } |
| 1014 | 1229 | ||
| 1015 | ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewInfo& info, | 1230 | ImageView::ImageView(TextureCacheRuntime& runtime, const VideoCommon::ImageViewInfo& info, |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index f7e782c44..958a64651 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -45,7 +45,6 @@ struct TextureCacheRuntime { | |||
| 45 | static constexpr size_t TICKS_TO_DESTROY = 6; | 45 | static constexpr size_t TICKS_TO_DESTROY = 6; |
| 46 | DelayedDestructionRing<vk::Image, TICKS_TO_DESTROY> prescaled_images; | 46 | DelayedDestructionRing<vk::Image, TICKS_TO_DESTROY> prescaled_images; |
| 47 | DelayedDestructionRing<MemoryCommit, TICKS_TO_DESTROY> prescaled_commits; | 47 | DelayedDestructionRing<MemoryCommit, TICKS_TO_DESTROY> prescaled_commits; |
| 48 | DelayedDestructionRing<vk::ImageView, TICKS_TO_DESTROY> prescaled_views; | ||
| 49 | Settings::ResolutionScalingInfo resolution; | 48 | Settings::ResolutionScalingInfo resolution; |
| 50 | bool is_rescaling_on{}; | 49 | bool is_rescaling_on{}; |
| 51 | 50 | ||
| @@ -126,9 +125,11 @@ public: | |||
| 126 | return std::exchange(initialized, true); | 125 | return std::exchange(initialized, true); |
| 127 | } | 126 | } |
| 128 | 127 | ||
| 129 | void ScaleUp(); | 128 | bool ScaleUp(bool save_as_backup = false); |
| 130 | 129 | ||
| 131 | void ScaleDown(); | 130 | bool ScaleDown(bool save_as_backup = false); |
| 131 | |||
| 132 | void SwapBackup(); | ||
| 132 | 133 | ||
| 133 | private: | 134 | private: |
| 134 | VKScheduler* scheduler; | 135 | VKScheduler* scheduler; |
| @@ -140,6 +141,9 @@ private: | |||
| 140 | bool initialized = false; | 141 | bool initialized = false; |
| 141 | TextureCacheRuntime* runtime; | 142 | TextureCacheRuntime* runtime; |
| 142 | u32 scaling_count{}; | 143 | u32 scaling_count{}; |
| 144 | vk::Image backup_image{}; | ||
| 145 | MemoryCommit backup_commit{}; | ||
| 146 | bool has_backup{}; | ||
| 143 | }; | 147 | }; |
| 144 | 148 | ||
| 145 | class ImageView : public VideoCommon::ImageViewBase { | 149 | class ImageView : public VideoCommon::ImageViewBase { |
diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index 64fd7010a..022ca9033 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp | |||
| @@ -41,6 +41,7 @@ ImageInfo::ImageInfo(const TICEntry& config) noexcept { | |||
| 41 | ASSERT(config.BaseLayer() == 0); | 41 | ASSERT(config.BaseLayer() == 0); |
| 42 | type = ImageType::e1D; | 42 | type = ImageType::e1D; |
| 43 | size.width = config.Width(); | 43 | size.width = config.Width(); |
| 44 | resources.layers = 1; | ||
| 44 | break; | 45 | break; |
| 45 | case TextureType::Texture1DArray: | 46 | case TextureType::Texture1DArray: |
| 46 | UNIMPLEMENTED_IF(config.BaseLayer() != 0); | 47 | UNIMPLEMENTED_IF(config.BaseLayer() != 0); |
| @@ -82,10 +83,12 @@ ImageInfo::ImageInfo(const TICEntry& config) noexcept { | |||
| 82 | size.width = config.Width(); | 83 | size.width = config.Width(); |
| 83 | size.height = config.Height(); | 84 | size.height = config.Height(); |
| 84 | size.depth = config.Depth(); | 85 | size.depth = config.Depth(); |
| 86 | resources.layers = 1; | ||
| 85 | break; | 87 | break; |
| 86 | case TextureType::Texture1DBuffer: | 88 | case TextureType::Texture1DBuffer: |
| 87 | type = ImageType::Buffer; | 89 | type = ImageType::Buffer; |
| 88 | size.width = config.Width(); | 90 | size.width = config.Width(); |
| 91 | resources.layers = 1; | ||
| 89 | break; | 92 | break; |
| 90 | default: | 93 | default: |
| 91 | UNREACHABLE_MSG("Invalid texture_type={}", static_cast<int>(config.texture_type.Value())); | 94 | UNREACHABLE_MSG("Invalid texture_type={}", static_cast<int>(config.texture_type.Value())); |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 560da4f16..95a9e8fe9 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -242,24 +242,36 @@ void TextureCache<P>::UpdateRenderTargets(bool is_clear) { | |||
| 242 | const auto scale_up = [this](ImageId image_id) { | 242 | const auto scale_up = [this](ImageId image_id) { |
| 243 | if (image_id != CORRUPT_ID) { | 243 | if (image_id != CORRUPT_ID) { |
| 244 | Image& image = slot_images[image_id]; | 244 | Image& image = slot_images[image_id]; |
| 245 | image.ScaleUp(); | 245 | return ScaleUp(image); |
| 246 | } | 246 | } |
| 247 | return false; | ||
| 247 | }; | 248 | }; |
| 248 | for (size_t index = 0; index < NUM_RT; ++index) { | 249 | for (size_t index = 0; index < NUM_RT; ++index) { |
| 249 | scale_up(tmp_color_images[index]); | 250 | if (scale_up(tmp_color_images[index])) { |
| 251 | BindRenderTarget(&render_targets.color_buffer_ids[index], | ||
| 252 | FindColorBuffer(index, is_clear)); | ||
| 253 | } | ||
| 254 | } | ||
| 255 | if (scale_up(tmp_depth_image)) { | ||
| 256 | BindRenderTarget(&render_targets.depth_buffer_id, FindDepthBuffer(is_clear)); | ||
| 250 | } | 257 | } |
| 251 | scale_up(tmp_depth_image); | ||
| 252 | } else { | 258 | } else { |
| 253 | const auto scale_down = [this](ImageId image_id) { | 259 | const auto scale_down = [this](ImageId image_id) { |
| 254 | if (image_id != CORRUPT_ID) { | 260 | if (image_id != CORRUPT_ID) { |
| 255 | Image& image = slot_images[image_id]; | 261 | Image& image = slot_images[image_id]; |
| 256 | image.ScaleDown(); | 262 | return ScaleDown(image); |
| 257 | } | 263 | } |
| 264 | return false; | ||
| 258 | }; | 265 | }; |
| 259 | for (size_t index = 0; index < NUM_RT; ++index) { | 266 | for (size_t index = 0; index < NUM_RT; ++index) { |
| 260 | scale_down(tmp_color_images[index]); | 267 | if (scale_down(tmp_color_images[index])) { |
| 268 | BindRenderTarget(&render_targets.color_buffer_ids[index], | ||
| 269 | FindColorBuffer(index, is_clear)); | ||
| 270 | } | ||
| 271 | } | ||
| 272 | if (scale_down(tmp_depth_image)) { | ||
| 273 | BindRenderTarget(&render_targets.depth_buffer_id, FindDepthBuffer(is_clear)); | ||
| 261 | } | 274 | } |
| 262 | scale_down(tmp_depth_image); | ||
| 263 | } | 275 | } |
| 264 | // Rescale End | 276 | // Rescale End |
| 265 | 277 | ||
| @@ -696,6 +708,47 @@ bool TextureCache<P>::ImageCanRescale(Image& image) { | |||
| 696 | } | 708 | } |
| 697 | 709 | ||
| 698 | template <class P> | 710 | template <class P> |
| 711 | void TextureCache<P>::InvalidateScale(Image& image, bool invalidate_rt) { | ||
| 712 | const std::span<const ImageViewId> image_view_ids = image.image_view_ids; | ||
| 713 | if (invalidate_rt) { | ||
| 714 | auto& dirty = maxwell3d.dirty.flags; | ||
| 715 | dirty[Dirty::RenderTargets] = true; | ||
| 716 | dirty[Dirty::ZetaBuffer] = true; | ||
| 717 | for (size_t rt = 0; rt < NUM_RT; ++rt) { | ||
| 718 | dirty[Dirty::ColorBuffer0 + rt] = true; | ||
| 719 | } | ||
| 720 | for (const ImageViewId image_view_id : image_view_ids) { | ||
| 721 | std::ranges::replace(render_targets.color_buffer_ids, image_view_id, ImageViewId{}); | ||
| 722 | if (render_targets.depth_buffer_id == image_view_id) { | ||
| 723 | render_targets.depth_buffer_id = ImageViewId{}; | ||
| 724 | } | ||
| 725 | } | ||
| 726 | } | ||
| 727 | RemoveImageViewReferences(image_view_ids); | ||
| 728 | RemoveFramebuffers(image_view_ids); | ||
| 729 | } | ||
| 730 | |||
| 731 | template <class P> | ||
| 732 | bool TextureCache<P>::ScaleUp(Image& image, bool invalidate_rt) { | ||
| 733 | const bool rescaled = image.ScaleUp(); | ||
| 734 | if (!rescaled) { | ||
| 735 | return false; | ||
| 736 | } | ||
| 737 | InvalidateScale(image, invalidate_rt); | ||
| 738 | return true; | ||
| 739 | } | ||
| 740 | |||
| 741 | template <class P> | ||
| 742 | bool TextureCache<P>::ScaleDown(Image& image, bool invalidate_rt) { | ||
| 743 | const bool rescaled = image.ScaleDown(); | ||
| 744 | if (!rescaled) { | ||
| 745 | return false; | ||
| 746 | } | ||
| 747 | InvalidateScale(image, invalidate_rt); | ||
| 748 | return true; | ||
| 749 | } | ||
| 750 | |||
| 751 | template <class P> | ||
| 699 | ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr, | 752 | ImageId TextureCache<P>::InsertImage(const ImageInfo& info, GPUVAddr gpu_addr, |
| 700 | RelaxedOptions options) { | 753 | RelaxedOptions options) { |
| 701 | std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); | 754 | std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); |
| @@ -793,33 +846,32 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 793 | 846 | ||
| 794 | bool can_rescale = | 847 | bool can_rescale = |
| 795 | (info.type == ImageType::e1D || info.type == ImageType::e2D) && info.block.depth == 0; | 848 | (info.type == ImageType::e1D || info.type == ImageType::e2D) && info.block.depth == 0; |
| 849 | bool any_rescaled = false; | ||
| 796 | for (const ImageId sibling_id : all_siblings) { | 850 | for (const ImageId sibling_id : all_siblings) { |
| 797 | if (!can_rescale) { | 851 | if (!can_rescale) { |
| 798 | break; | 852 | break; |
| 799 | } | 853 | } |
| 800 | Image& sibling = slot_images[sibling_id]; | 854 | Image& sibling = slot_images[sibling_id]; |
| 801 | can_rescale &= ImageCanRescale(sibling); | 855 | can_rescale &= ImageCanRescale(sibling); |
| 856 | any_rescaled |= True(sibling.flags & ImageFlagBits::Rescaled); | ||
| 802 | } | 857 | } |
| 803 | 858 | ||
| 859 | can_rescale &= any_rescaled; | ||
| 860 | |||
| 804 | if (can_rescale) { | 861 | if (can_rescale) { |
| 805 | for (const ImageId sibling_id : all_siblings) { | 862 | for (const ImageId sibling_id : all_siblings) { |
| 806 | Image& sibling = slot_images[sibling_id]; | 863 | Image& sibling = slot_images[sibling_id]; |
| 807 | sibling.ScaleUp(); | 864 | ScaleUp(sibling, true); |
| 808 | } | 865 | } |
| 809 | } else { | 866 | } else { |
| 810 | for (const ImageId sibling_id : all_siblings) { | 867 | for (const ImageId sibling_id : all_siblings) { |
| 811 | Image& sibling = slot_images[sibling_id]; | 868 | Image& sibling = slot_images[sibling_id]; |
| 812 | sibling.ScaleDown(); | 869 | ScaleDown(sibling, true); |
| 813 | } | 870 | } |
| 814 | } | 871 | } |
| 815 | 872 | ||
| 816 | const ImageId new_image_id = slot_images.insert(runtime, new_info, gpu_addr, cpu_addr); | 873 | const ImageId new_image_id = slot_images.insert(runtime, new_info, gpu_addr, cpu_addr); |
| 817 | Image& new_image = slot_images[new_image_id]; | 874 | Image& new_image = slot_images[new_image_id]; |
| 818 | if (can_rescale) { | ||
| 819 | new_image.ScaleUp(); | ||
| 820 | } else { | ||
| 821 | new_image.ScaleDown(); | ||
| 822 | } | ||
| 823 | 875 | ||
| 824 | if (!gpu_memory.IsContinousRange(new_image.gpu_addr, new_image.guest_size_bytes)) { | 876 | if (!gpu_memory.IsContinousRange(new_image.gpu_addr, new_image.guest_size_bytes)) { |
| 825 | new_image.flags |= ImageFlagBits::Sparse; | 877 | new_image.flags |= ImageFlagBits::Sparse; |
| @@ -840,6 +892,12 @@ ImageId TextureCache<P>::JoinImages(const ImageInfo& info, GPUVAddr gpu_addr, VA | |||
| 840 | // TODO: Only upload what we need | 892 | // TODO: Only upload what we need |
| 841 | RefreshContents(new_image, new_image_id); | 893 | RefreshContents(new_image, new_image_id); |
| 842 | 894 | ||
| 895 | if (can_rescale) { | ||
| 896 | new_image.ScaleUp(); | ||
| 897 | } else { | ||
| 898 | new_image.ScaleDown(); | ||
| 899 | } | ||
| 900 | |||
| 843 | for (const ImageId overlap_id : overlap_ids) { | 901 | for (const ImageId overlap_id : overlap_ids) { |
| 844 | Image& overlap = slot_images[overlap_id]; | 902 | Image& overlap = slot_images[overlap_id]; |
| 845 | if (overlap.info.num_samples != new_image.info.num_samples) { | 903 | if (overlap.info.num_samples != new_image.info.num_samples) { |
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index a4a2c0832..042678786 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -327,6 +327,9 @@ private: | |||
| 327 | [[nodiscard]] bool IsFullClear(ImageViewId id); | 327 | [[nodiscard]] bool IsFullClear(ImageViewId id); |
| 328 | 328 | ||
| 329 | bool ImageCanRescale(Image& image); | 329 | bool ImageCanRescale(Image& image); |
| 330 | void InvalidateScale(Image& image, bool invalidate_rt = false); | ||
| 331 | bool ScaleUp(Image& image, bool invalidate_rt = false); | ||
| 332 | bool ScaleDown(Image& image, bool invalidate_rt = false); | ||
| 330 | 333 | ||
| 331 | Runtime& runtime; | 334 | Runtime& runtime; |
| 332 | VideoCore::RasterizerInterface& rasterizer; | 335 | VideoCore::RasterizerInterface& rasterizer; |