diff options
Diffstat (limited to 'src/video_core/renderer_vulkan')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 45 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 5 |
2 files changed, 44 insertions, 6 deletions
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 8385b5509..3aac3cfab 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -36,8 +36,10 @@ using VideoCommon::ImageFlagBits; | |||
| 36 | using VideoCommon::ImageInfo; | 36 | using VideoCommon::ImageInfo; |
| 37 | using VideoCommon::ImageType; | 37 | using VideoCommon::ImageType; |
| 38 | using VideoCommon::SubresourceRange; | 38 | using VideoCommon::SubresourceRange; |
| 39 | using VideoCore::Surface::BytesPerBlock; | ||
| 39 | using VideoCore::Surface::IsPixelFormatASTC; | 40 | using VideoCore::Surface::IsPixelFormatASTC; |
| 40 | using VideoCore::Surface::IsPixelFormatInteger; | 41 | using VideoCore::Surface::IsPixelFormatInteger; |
| 42 | using VideoCore::Surface::SurfaceType; | ||
| 41 | 43 | ||
| 42 | namespace { | 44 | namespace { |
| 43 | constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | 45 | constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { |
| @@ -130,7 +132,7 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 130 | [[nodiscard]] VkImageCreateInfo MakeImageCreateInfo(const Device& device, const ImageInfo& info) { | 132 | [[nodiscard]] VkImageCreateInfo MakeImageCreateInfo(const Device& device, const ImageInfo& info) { |
| 131 | const PixelFormat format = StorageFormat(info.format); | 133 | const PixelFormat format = StorageFormat(info.format); |
| 132 | const auto format_info = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, false, format); | 134 | const auto format_info = MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, false, format); |
| 133 | VkImageCreateFlags flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; | 135 | VkImageCreateFlags flags{}; |
| 134 | if (info.type == ImageType::e2D && info.resources.layers >= 6 && | 136 | if (info.type == ImageType::e2D && info.resources.layers >= 6 && |
| 135 | info.size.width == info.size.height && !device.HasBrokenCubeImageCompability()) { | 137 | info.size.width == info.size.height && !device.HasBrokenCubeImageCompability()) { |
| 136 | flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; | 138 | flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; |
| @@ -163,11 +165,24 @@ constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { | |||
| 163 | } | 165 | } |
| 164 | 166 | ||
| 165 | [[nodiscard]] vk::Image MakeImage(const Device& device, const MemoryAllocator& allocator, | 167 | [[nodiscard]] vk::Image MakeImage(const Device& device, const MemoryAllocator& allocator, |
| 166 | const ImageInfo& info) { | 168 | const ImageInfo& info, std::span<const VkFormat> view_formats) { |
| 167 | if (info.type == ImageType::Buffer) { | 169 | if (info.type == ImageType::Buffer) { |
| 168 | return vk::Image{}; | 170 | return vk::Image{}; |
| 169 | } | 171 | } |
| 170 | return allocator.CreateImage(MakeImageCreateInfo(device, info)); | 172 | VkImageCreateInfo image_ci = MakeImageCreateInfo(device, info); |
| 173 | const VkImageFormatListCreateInfo image_format_list = { | ||
| 174 | .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO, | ||
| 175 | .pNext = nullptr, | ||
| 176 | .viewFormatCount = static_cast<u32>(view_formats.size()), | ||
| 177 | .pViewFormats = view_formats.data(), | ||
| 178 | }; | ||
| 179 | if (view_formats.size() > 1) { | ||
| 180 | image_ci.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT; | ||
| 181 | if (device.IsKhrImageFormatListSupported()) { | ||
| 182 | image_ci.pNext = &image_format_list; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | return allocator.CreateImage(image_ci); | ||
| 171 | } | 186 | } |
| 172 | 187 | ||
| 173 | [[nodiscard]] VkImageAspectFlags ImageAspectMask(PixelFormat format) { | 188 | [[nodiscard]] VkImageAspectFlags ImageAspectMask(PixelFormat format) { |
| @@ -806,6 +821,23 @@ TextureCacheRuntime::TextureCacheRuntime(const Device& device_, Scheduler& sched | |||
| 806 | astc_decoder_pass.emplace(device, scheduler, descriptor_pool, staging_buffer_pool, | 821 | astc_decoder_pass.emplace(device, scheduler, descriptor_pool, staging_buffer_pool, |
| 807 | compute_pass_descriptor_queue, memory_allocator); | 822 | compute_pass_descriptor_queue, memory_allocator); |
| 808 | } | 823 | } |
| 824 | if (!device.IsKhrImageFormatListSupported()) { | ||
| 825 | return; | ||
| 826 | } | ||
| 827 | for (size_t index_a = 0; index_a < VideoCore::Surface::MaxPixelFormat; index_a++) { | ||
| 828 | const auto image_format = static_cast<PixelFormat>(index_a); | ||
| 829 | if (IsPixelFormatASTC(image_format) && !device.IsOptimalAstcSupported()) { | ||
| 830 | view_formats[index_a].push_back(VK_FORMAT_A8B8G8R8_UNORM_PACK32); | ||
| 831 | } | ||
| 832 | for (size_t index_b = 0; index_b < VideoCore::Surface::MaxPixelFormat; index_b++) { | ||
| 833 | const auto view_format = static_cast<PixelFormat>(index_b); | ||
| 834 | if (VideoCore::Surface::IsViewCompatible(image_format, view_format, false, true)) { | ||
| 835 | const auto view_info = | ||
| 836 | MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, view_format); | ||
| 837 | view_formats[index_a].push_back(view_info.format); | ||
| 838 | } | ||
| 839 | } | ||
| 840 | } | ||
| 809 | } | 841 | } |
| 810 | 842 | ||
| 811 | void TextureCacheRuntime::Finish() { | 843 | void TextureCacheRuntime::Finish() { |
| @@ -1265,8 +1297,8 @@ void TextureCacheRuntime::TickFrame() {} | |||
| 1265 | Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, | 1297 | Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, |
| 1266 | VAddr cpu_addr_) | 1298 | VAddr cpu_addr_) |
| 1267 | : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler}, | 1299 | : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler}, |
| 1268 | runtime{&runtime_}, | 1300 | runtime{&runtime_}, original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info, |
| 1269 | original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info)), | 1301 | runtime->ViewFormats(info.format))), |
| 1270 | aspect_mask(ImageAspectMask(info.format)) { | 1302 | aspect_mask(ImageAspectMask(info.format)) { |
| 1271 | if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { | 1303 | if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { |
| 1272 | if (Settings::values.async_astc.GetValue()) { | 1304 | if (Settings::values.async_astc.GetValue()) { |
| @@ -1471,7 +1503,8 @@ bool Image::ScaleUp(bool ignore) { | |||
| 1471 | auto scaled_info = info; | 1503 | auto scaled_info = info; |
| 1472 | scaled_info.size.width = scaled_width; | 1504 | scaled_info.size.width = scaled_width; |
| 1473 | scaled_info.size.height = scaled_height; | 1505 | scaled_info.size.height = scaled_height; |
| 1474 | scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info); | 1506 | scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info, |
| 1507 | runtime->ViewFormats(info.format)); | ||
| 1475 | ignore = false; | 1508 | ignore = false; |
| 1476 | } | 1509 | } |
| 1477 | current_image = *scaled_image; | 1510 | current_image = *scaled_image; |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 220943116..6621210ea 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -103,6 +103,10 @@ public: | |||
| 103 | 103 | ||
| 104 | [[nodiscard]] VkBuffer GetTemporaryBuffer(size_t needed_size); | 104 | [[nodiscard]] VkBuffer GetTemporaryBuffer(size_t needed_size); |
| 105 | 105 | ||
| 106 | std::span<const VkFormat> ViewFormats(PixelFormat format) { | ||
| 107 | return view_formats[static_cast<std::size_t>(format)]; | ||
| 108 | } | ||
| 109 | |||
| 106 | void BarrierFeedbackLoop(); | 110 | void BarrierFeedbackLoop(); |
| 107 | 111 | ||
| 108 | const Device& device; | 112 | const Device& device; |
| @@ -113,6 +117,7 @@ public: | |||
| 113 | RenderPassCache& render_pass_cache; | 117 | RenderPassCache& render_pass_cache; |
| 114 | std::optional<ASTCDecoderPass> astc_decoder_pass; | 118 | std::optional<ASTCDecoderPass> astc_decoder_pass; |
| 115 | const Settings::ResolutionScalingInfo& resolution; | 119 | const Settings::ResolutionScalingInfo& resolution; |
| 120 | std::array<std::vector<VkFormat>, VideoCore::Surface::MaxPixelFormat> view_formats; | ||
| 116 | 121 | ||
| 117 | static constexpr size_t indexing_slots = 8 * sizeof(size_t); | 122 | static constexpr size_t indexing_slots = 8 * sizeof(size_t); |
| 118 | std::array<vk::Buffer, indexing_slots> buffers{}; | 123 | std::array<vk::Buffer, indexing_slots> buffers{}; |