summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.cpp46
-rw-r--r--src/video_core/renderer_vulkan/vk_texture_cache.h5
-rw-r--r--src/video_core/texture_cache/types.h1
-rw-r--r--src/video_core/texture_cache/util.cpp9
-rw-r--r--src/video_core/vulkan_common/vulkan_device.h6
5 files changed, 53 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 8385b5509..f1b696e01 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;
36using VideoCommon::ImageInfo; 36using VideoCommon::ImageInfo;
37using VideoCommon::ImageType; 37using VideoCommon::ImageType;
38using VideoCommon::SubresourceRange; 38using VideoCommon::SubresourceRange;
39using VideoCore::Surface::BytesPerBlock;
39using VideoCore::Surface::IsPixelFormatASTC; 40using VideoCore::Surface::IsPixelFormatASTC;
40using VideoCore::Surface::IsPixelFormatInteger; 41using VideoCore::Surface::IsPixelFormatInteger;
42using VideoCore::Surface::SurfaceType;
41 43
42namespace { 44namespace {
43constexpr VkBorderColor ConvertBorderColor(const std::array<float, 4>& color) { 45constexpr 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,24 @@ 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 const auto type_a = VideoCore::Surface::GetFormatType(image_format);
830 if (type_a != SurfaceType::ColorTexture) {
831 continue;
832 }
833 for (size_t index_b = 0; index_b < VideoCore::Surface::MaxPixelFormat; index_b++) {
834 const auto view_format = static_cast<PixelFormat>(index_b);
835 if (VideoCore::Surface::IsViewCompatible(image_format, view_format, false, true)) {
836 const auto view_info =
837 MaxwellToVK::SurfaceFormat(device, FormatType::Optimal, true, view_format);
838 view_formats[index_a].push_back(view_info.format);
839 }
840 }
841 }
809} 842}
810 843
811void TextureCacheRuntime::Finish() { 844void TextureCacheRuntime::Finish() {
@@ -1265,8 +1298,8 @@ void TextureCacheRuntime::TickFrame() {}
1265Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_, 1298Image::Image(TextureCacheRuntime& runtime_, const ImageInfo& info_, GPUVAddr gpu_addr_,
1266 VAddr cpu_addr_) 1299 VAddr cpu_addr_)
1267 : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler}, 1300 : VideoCommon::ImageBase(info_, gpu_addr_, cpu_addr_), scheduler{&runtime_.scheduler},
1268 runtime{&runtime_}, 1301 runtime{&runtime_}, original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info,
1269 original_image(MakeImage(runtime_.device, runtime_.memory_allocator, info)), 1302 runtime->ViewFormats(info.format))),
1270 aspect_mask(ImageAspectMask(info.format)) { 1303 aspect_mask(ImageAspectMask(info.format)) {
1271 if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) { 1304 if (IsPixelFormatASTC(info.format) && !runtime->device.IsOptimalAstcSupported()) {
1272 if (Settings::values.async_astc.GetValue()) { 1305 if (Settings::values.async_astc.GetValue()) {
@@ -1471,7 +1504,8 @@ bool Image::ScaleUp(bool ignore) {
1471 auto scaled_info = info; 1504 auto scaled_info = info;
1472 scaled_info.size.width = scaled_width; 1505 scaled_info.size.width = scaled_width;
1473 scaled_info.size.height = scaled_height; 1506 scaled_info.size.height = scaled_height;
1474 scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info); 1507 scaled_image = MakeImage(runtime->device, runtime->memory_allocator, scaled_info,
1508 runtime->ViewFormats(info.format));
1475 ignore = false; 1509 ignore = false;
1476 } 1510 }
1477 current_image = *scaled_image; 1511 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};
59DECLARE_ENUM_FLAG_OPERATORS(RelaxedOptions) 58DECLARE_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;