diff options
| author | 2023-07-02 17:38:21 -0400 | |
|---|---|---|
| committer | 2023-07-02 17:38:21 -0400 | |
| commit | 5e3695ecaa4a3b62249b67df13b7ceccc20ce92e (patch) | |
| tree | 3e4b85ba87828fbde889d35b598019bf3e866cc0 /src | |
| parent | Merge pull request #10969 from Morph1984/k-synchronize (diff) | |
| parent | renderer_vulkan: Fix some missing view formats (diff) | |
| download | yuzu-5e3695ecaa4a3b62249b67df13b7ceccc20ce92e.tar.gz yuzu-5e3695ecaa4a3b62249b67df13b7ceccc20ce92e.tar.xz yuzu-5e3695ecaa4a3b62249b67df13b7ceccc20ce92e.zip | |
Merge pull request #10479 from GPUCode/format-list
Add support for VK_KHR_image_format_list
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/compatible_formats.cpp | 6 | ||||
| -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 | ||||
| -rw-r--r-- | src/video_core/texture_cache/types.h | 1 | ||||
| -rw-r--r-- | src/video_core/texture_cache/util.cpp | 9 | ||||
| -rw-r--r-- | src/video_core/vulkan_common/vulkan_device.h | 6 |
6 files changed, 58 insertions, 14 deletions
diff --git a/src/video_core/compatible_formats.cpp b/src/video_core/compatible_formats.cpp index ab4f4d407..87d69ebc5 100644 --- a/src/video_core/compatible_formats.cpp +++ b/src/video_core/compatible_formats.cpp | |||
| @@ -272,6 +272,9 @@ constexpr Table MakeNonNativeBgrCopyTable() { | |||
| 272 | 272 | ||
| 273 | bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_views, | 273 | bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_views, |
| 274 | bool native_bgr) { | 274 | bool native_bgr) { |
| 275 | if (format_a == format_b) { | ||
| 276 | return true; | ||
| 277 | } | ||
| 275 | if (broken_views) { | 278 | if (broken_views) { |
| 276 | // If format views are broken, only accept formats that are identical. | 279 | // If format views are broken, only accept formats that are identical. |
| 277 | return format_a == format_b; | 280 | return format_a == format_b; |
| @@ -282,6 +285,9 @@ bool IsViewCompatible(PixelFormat format_a, PixelFormat format_b, bool broken_vi | |||
| 282 | } | 285 | } |
| 283 | 286 | ||
| 284 | bool IsCopyCompatible(PixelFormat format_a, PixelFormat format_b, bool native_bgr) { | 287 | bool IsCopyCompatible(PixelFormat format_a, PixelFormat format_b, bool native_bgr) { |
| 288 | if (format_a == format_b) { | ||
| 289 | return true; | ||
| 290 | } | ||
| 285 | static constexpr Table BGR_TABLE = MakeNativeBgrCopyTable(); | 291 | static constexpr Table BGR_TABLE = MakeNativeBgrCopyTable(); |
| 286 | static constexpr Table NO_BGR_TABLE = MakeNonNativeBgrCopyTable(); | 292 | static constexpr Table NO_BGR_TABLE = MakeNonNativeBgrCopyTable(); |
| 287 | return IsSupported(native_bgr ? BGR_TABLE : NO_BGR_TABLE, format_a, format_b); | 293 | return IsSupported(native_bgr ? BGR_TABLE : NO_BGR_TABLE, format_a, format_b); |
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{}; |
diff --git a/src/video_core/texture_cache/types.h b/src/video_core/texture_cache/types.h index a0e10643f..0453456b4 100644 --- a/src/video_core/texture_cache/types.h +++ b/src/video_core/texture_cache/types.h | |||
| @@ -54,7 +54,6 @@ enum class RelaxedOptions : u32 { | |||
| 54 | Format = 1 << 1, | 54 | Format = 1 << 1, |
| 55 | Samples = 1 << 2, | 55 | Samples = 1 << 2, |
| 56 | ForceBrokenViews = 1 << 3, | 56 | ForceBrokenViews = 1 << 3, |
| 57 | FormatBpp = 1 << 4, | ||
| 58 | }; | 57 | }; |
| 59 | DECLARE_ENUM_FLAG_OPERATORS(RelaxedOptions) | 58 | DECLARE_ENUM_FLAG_OPERATORS(RelaxedOptions) |
| 60 | 59 | ||
diff --git a/src/video_core/texture_cache/util.cpp b/src/video_core/texture_cache/util.cpp index 9a618a57a..0de6ed09d 100644 --- a/src/video_core/texture_cache/util.cpp +++ b/src/video_core/texture_cache/util.cpp | |||
| @@ -1201,8 +1201,7 @@ std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const | |||
| 1201 | // Format checking is relaxed, but we still have to check for matching bytes per block. | 1201 | // Format checking is relaxed, but we still have to check for matching bytes per block. |
| 1202 | // This avoids creating a view for blits on UE4 titles where formats with different bytes | 1202 | // This avoids creating a view for blits on UE4 titles where formats with different bytes |
| 1203 | // per block are aliased. | 1203 | // per block are aliased. |
| 1204 | if (BytesPerBlock(existing.format) != BytesPerBlock(candidate.format) && | 1204 | if (BytesPerBlock(existing.format) != BytesPerBlock(candidate.format)) { |
| 1205 | False(options & RelaxedOptions::FormatBpp)) { | ||
| 1206 | return std::nullopt; | 1205 | return std::nullopt; |
| 1207 | } | 1206 | } |
| 1208 | } else { | 1207 | } else { |
| @@ -1233,11 +1232,7 @@ std::optional<SubresourceBase> FindSubresource(const ImageInfo& candidate, const | |||
| 1233 | } | 1232 | } |
| 1234 | const bool strict_size = False(options & RelaxedOptions::Size); | 1233 | const bool strict_size = False(options & RelaxedOptions::Size); |
| 1235 | if (!IsBlockLinearSizeCompatible(existing, candidate, base->level, 0, strict_size)) { | 1234 | if (!IsBlockLinearSizeCompatible(existing, candidate, base->level, 0, strict_size)) { |
| 1236 | if (False(options & RelaxedOptions::FormatBpp)) { | 1235 | return std::nullopt; |
| 1237 | return std::nullopt; | ||
| 1238 | } else if (!IsBlockLinearSizeCompatibleBPPRelaxed(existing, candidate, base->level, 0)) { | ||
| 1239 | return std::nullopt; | ||
| 1240 | } | ||
| 1241 | } | 1236 | } |
| 1242 | // TODO: compare block sizes | 1237 | // TODO: compare block sizes |
| 1243 | return base; | 1238 | return base; |
diff --git a/src/video_core/vulkan_common/vulkan_device.h b/src/video_core/vulkan_common/vulkan_device.h index 1f17265d5..3ace1fb03 100644 --- a/src/video_core/vulkan_common/vulkan_device.h +++ b/src/video_core/vulkan_common/vulkan_device.h | |||
| @@ -77,6 +77,7 @@ VK_DEFINE_HANDLE(VmaAllocator) | |||
| 77 | EXTENSION(KHR, SPIRV_1_4, spirv_1_4) \ | 77 | EXTENSION(KHR, SPIRV_1_4, spirv_1_4) \ |
| 78 | EXTENSION(KHR, SWAPCHAIN, swapchain) \ | 78 | EXTENSION(KHR, SWAPCHAIN, swapchain) \ |
| 79 | EXTENSION(KHR, SWAPCHAIN_MUTABLE_FORMAT, swapchain_mutable_format) \ | 79 | EXTENSION(KHR, SWAPCHAIN_MUTABLE_FORMAT, swapchain_mutable_format) \ |
| 80 | EXTENSION(KHR, IMAGE_FORMAT_LIST, image_format_list) \ | ||
| 80 | EXTENSION(NV, DEVICE_DIAGNOSTICS_CONFIG, device_diagnostics_config) \ | 81 | EXTENSION(NV, DEVICE_DIAGNOSTICS_CONFIG, device_diagnostics_config) \ |
| 81 | EXTENSION(NV, GEOMETRY_SHADER_PASSTHROUGH, geometry_shader_passthrough) \ | 82 | EXTENSION(NV, GEOMETRY_SHADER_PASSTHROUGH, geometry_shader_passthrough) \ |
| 82 | EXTENSION(NV, VIEWPORT_ARRAY2, viewport_array2) \ | 83 | EXTENSION(NV, VIEWPORT_ARRAY2, viewport_array2) \ |
| @@ -408,6 +409,11 @@ public: | |||
| 408 | return extensions.workgroup_memory_explicit_layout; | 409 | return extensions.workgroup_memory_explicit_layout; |
| 409 | } | 410 | } |
| 410 | 411 | ||
| 412 | /// Returns true if the device supports VK_KHR_image_format_list. | ||
| 413 | bool IsKhrImageFormatListSupported() const { | ||
| 414 | return extensions.image_format_list || instance_version >= VK_API_VERSION_1_2; | ||
| 415 | } | ||
| 416 | |||
| 411 | /// Returns true if the device supports VK_EXT_primitive_topology_list_restart. | 417 | /// Returns true if the device supports VK_EXT_primitive_topology_list_restart. |
| 412 | bool IsTopologyListPrimitiveRestartSupported() const { | 418 | bool IsTopologyListPrimitiveRestartSupported() const { |
| 413 | return features.primitive_topology_list_restart.primitiveTopologyListRestart; | 419 | return features.primitive_topology_list_restart.primitiveTopologyListRestart; |