diff options
| author | 2021-06-24 21:47:05 -0700 | |
|---|---|---|
| committer | 2021-06-24 21:47:05 -0700 | |
| commit | c805c0b395347b8094964924d85a3151ff2c6593 (patch) | |
| tree | c9f018055025fa3c973bacec5f056f68d8f8e67c /src/video_core/renderer_vulkan | |
| parent | Merge pull request #6519 from Wunkolo/mem-size-literal (diff) | |
| parent | util_shaders: Specify ASTC decoder memory barrier bits (diff) | |
| download | yuzu-c805c0b395347b8094964924d85a3151ff2c6593.tar.gz yuzu-c805c0b395347b8094964924d85a3151ff2c6593.tar.xz yuzu-c805c0b395347b8094964924d85a3151ff2c6593.zip | |
Merge pull request #6496 from ameerj/astc-fixes
astc: Various robustness enhancements for the gpu decoder
Diffstat (limited to 'src/video_core/renderer_vulkan')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_compute_pass.cpp | 107 |
1 files changed, 14 insertions, 93 deletions
diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp index e11406e58..205cd3b05 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp | |||
| @@ -30,19 +30,16 @@ | |||
| 30 | namespace Vulkan { | 30 | namespace Vulkan { |
| 31 | 31 | ||
| 32 | using Tegra::Texture::SWIZZLE_TABLE; | 32 | using Tegra::Texture::SWIZZLE_TABLE; |
| 33 | using Tegra::Texture::ASTC::EncodingsValues; | 33 | using Tegra::Texture::ASTC::ASTC_ENCODINGS_VALUES; |
| 34 | using namespace Tegra::Texture::ASTC; | 34 | using namespace Tegra::Texture::ASTC; |
| 35 | 35 | ||
| 36 | namespace { | 36 | namespace { |
| 37 | 37 | ||
| 38 | constexpr u32 ASTC_BINDING_INPUT_BUFFER = 0; | 38 | constexpr u32 ASTC_BINDING_INPUT_BUFFER = 0; |
| 39 | constexpr u32 ASTC_BINDING_ENC_BUFFER = 1; | 39 | constexpr u32 ASTC_BINDING_ENC_BUFFER = 1; |
| 40 | constexpr u32 ASTC_BINDING_6_TO_8_BUFFER = 2; | 40 | constexpr u32 ASTC_BINDING_SWIZZLE_BUFFER = 2; |
| 41 | constexpr u32 ASTC_BINDING_7_TO_8_BUFFER = 3; | 41 | constexpr u32 ASTC_BINDING_OUTPUT_IMAGE = 3; |
| 42 | constexpr u32 ASTC_BINDING_8_TO_8_BUFFER = 4; | 42 | constexpr size_t ASTC_NUM_BINDINGS = 4; |
| 43 | constexpr u32 ASTC_BINDING_BYTE_TO_16_BUFFER = 5; | ||
| 44 | constexpr u32 ASTC_BINDING_SWIZZLE_BUFFER = 6; | ||
| 45 | constexpr u32 ASTC_BINDING_OUTPUT_IMAGE = 7; | ||
| 46 | 43 | ||
| 47 | VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { | 44 | VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { |
| 48 | return { | 45 | return { |
| @@ -71,7 +68,7 @@ std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBinding | |||
| 71 | }}; | 68 | }}; |
| 72 | } | 69 | } |
| 73 | 70 | ||
| 74 | std::array<VkDescriptorSetLayoutBinding, 8> BuildASTCDescriptorSetBindings() { | 71 | std::array<VkDescriptorSetLayoutBinding, ASTC_NUM_BINDINGS> BuildASTCDescriptorSetBindings() { |
| 75 | return {{ | 72 | return {{ |
| 76 | { | 73 | { |
| 77 | .binding = ASTC_BINDING_INPUT_BUFFER, | 74 | .binding = ASTC_BINDING_INPUT_BUFFER, |
| @@ -88,34 +85,6 @@ std::array<VkDescriptorSetLayoutBinding, 8> BuildASTCDescriptorSetBindings() { | |||
| 88 | .pImmutableSamplers = nullptr, | 85 | .pImmutableSamplers = nullptr, |
| 89 | }, | 86 | }, |
| 90 | { | 87 | { |
| 91 | .binding = ASTC_BINDING_6_TO_8_BUFFER, | ||
| 92 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 93 | .descriptorCount = 1, | ||
| 94 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, | ||
| 95 | .pImmutableSamplers = nullptr, | ||
| 96 | }, | ||
| 97 | { | ||
| 98 | .binding = ASTC_BINDING_7_TO_8_BUFFER, | ||
| 99 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 100 | .descriptorCount = 1, | ||
| 101 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, | ||
| 102 | .pImmutableSamplers = nullptr, | ||
| 103 | }, | ||
| 104 | { | ||
| 105 | .binding = ASTC_BINDING_8_TO_8_BUFFER, | ||
| 106 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 107 | .descriptorCount = 1, | ||
| 108 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, | ||
| 109 | .pImmutableSamplers = nullptr, | ||
| 110 | }, | ||
| 111 | { | ||
| 112 | .binding = ASTC_BINDING_BYTE_TO_16_BUFFER, | ||
| 113 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 114 | .descriptorCount = 1, | ||
| 115 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, | ||
| 116 | .pImmutableSamplers = nullptr, | ||
| 117 | }, | ||
| 118 | { | ||
| 119 | .binding = ASTC_BINDING_SWIZZLE_BUFFER, | 88 | .binding = ASTC_BINDING_SWIZZLE_BUFFER, |
| 120 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | 89 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 121 | .descriptorCount = 1, | 90 | .descriptorCount = 1, |
| @@ -143,7 +112,8 @@ VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() { | |||
| 143 | }; | 112 | }; |
| 144 | } | 113 | } |
| 145 | 114 | ||
| 146 | std::array<VkDescriptorUpdateTemplateEntryKHR, 8> BuildASTCPassDescriptorUpdateTemplateEntry() { | 115 | std::array<VkDescriptorUpdateTemplateEntryKHR, ASTC_NUM_BINDINGS> |
| 116 | BuildASTCPassDescriptorUpdateTemplateEntry() { | ||
| 147 | return {{ | 117 | return {{ |
| 148 | { | 118 | { |
| 149 | .dstBinding = ASTC_BINDING_INPUT_BUFFER, | 119 | .dstBinding = ASTC_BINDING_INPUT_BUFFER, |
| @@ -162,38 +132,6 @@ std::array<VkDescriptorUpdateTemplateEntryKHR, 8> BuildASTCPassDescriptorUpdateT | |||
| 162 | .stride = sizeof(DescriptorUpdateEntry), | 132 | .stride = sizeof(DescriptorUpdateEntry), |
| 163 | }, | 133 | }, |
| 164 | { | 134 | { |
| 165 | .dstBinding = ASTC_BINDING_6_TO_8_BUFFER, | ||
| 166 | .dstArrayElement = 0, | ||
| 167 | .descriptorCount = 1, | ||
| 168 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 169 | .offset = ASTC_BINDING_6_TO_8_BUFFER * sizeof(DescriptorUpdateEntry), | ||
| 170 | .stride = sizeof(DescriptorUpdateEntry), | ||
| 171 | }, | ||
| 172 | { | ||
| 173 | .dstBinding = ASTC_BINDING_7_TO_8_BUFFER, | ||
| 174 | .dstArrayElement = 0, | ||
| 175 | .descriptorCount = 1, | ||
| 176 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 177 | .offset = ASTC_BINDING_7_TO_8_BUFFER * sizeof(DescriptorUpdateEntry), | ||
| 178 | .stride = sizeof(DescriptorUpdateEntry), | ||
| 179 | }, | ||
| 180 | { | ||
| 181 | .dstBinding = ASTC_BINDING_8_TO_8_BUFFER, | ||
| 182 | .dstArrayElement = 0, | ||
| 183 | .descriptorCount = 1, | ||
| 184 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 185 | .offset = ASTC_BINDING_8_TO_8_BUFFER * sizeof(DescriptorUpdateEntry), | ||
| 186 | .stride = sizeof(DescriptorUpdateEntry), | ||
| 187 | }, | ||
| 188 | { | ||
| 189 | .dstBinding = ASTC_BINDING_BYTE_TO_16_BUFFER, | ||
| 190 | .dstArrayElement = 0, | ||
| 191 | .descriptorCount = 1, | ||
| 192 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, | ||
| 193 | .offset = ASTC_BINDING_BYTE_TO_16_BUFFER * sizeof(DescriptorUpdateEntry), | ||
| 194 | .stride = sizeof(DescriptorUpdateEntry), | ||
| 195 | }, | ||
| 196 | { | ||
| 197 | .dstBinding = ASTC_BINDING_SWIZZLE_BUFFER, | 135 | .dstBinding = ASTC_BINDING_SWIZZLE_BUFFER, |
| 198 | .dstArrayElement = 0, | 136 | .dstArrayElement = 0, |
| 199 | .descriptorCount = 1, | 137 | .descriptorCount = 1, |
| @@ -222,15 +160,6 @@ struct AstcPushConstants { | |||
| 222 | u32 block_height_mask; | 160 | u32 block_height_mask; |
| 223 | }; | 161 | }; |
| 224 | 162 | ||
| 225 | struct AstcBufferData { | ||
| 226 | decltype(SWIZZLE_TABLE) swizzle_table_buffer = SWIZZLE_TABLE; | ||
| 227 | decltype(EncodingsValues) encoding_values = EncodingsValues; | ||
| 228 | decltype(REPLICATE_6_BIT_TO_8_TABLE) replicate_6_to_8 = REPLICATE_6_BIT_TO_8_TABLE; | ||
| 229 | decltype(REPLICATE_7_BIT_TO_8_TABLE) replicate_7_to_8 = REPLICATE_7_BIT_TO_8_TABLE; | ||
| 230 | decltype(REPLICATE_8_BIT_TO_8_TABLE) replicate_8_to_8 = REPLICATE_8_BIT_TO_8_TABLE; | ||
| 231 | decltype(REPLICATE_BYTE_TO_16_TABLE) replicate_byte_to_16 = REPLICATE_BYTE_TO_16_TABLE; | ||
| 232 | } constexpr ASTC_BUFFER_DATA; | ||
| 233 | |||
| 234 | } // Anonymous namespace | 163 | } // Anonymous namespace |
| 235 | 164 | ||
| 236 | VKComputePass::VKComputePass(const Device& device, VKDescriptorPool& descriptor_pool, | 165 | VKComputePass::VKComputePass(const Device& device, VKDescriptorPool& descriptor_pool, |
| @@ -423,7 +352,7 @@ ASTCDecoderPass::ASTCDecoderPass(const Device& device_, VKScheduler& scheduler_, | |||
| 423 | ASTCDecoderPass::~ASTCDecoderPass() = default; | 352 | ASTCDecoderPass::~ASTCDecoderPass() = default; |
| 424 | 353 | ||
| 425 | void ASTCDecoderPass::MakeDataBuffer() { | 354 | void ASTCDecoderPass::MakeDataBuffer() { |
| 426 | constexpr size_t TOTAL_BUFFER_SIZE = sizeof(ASTC_BUFFER_DATA) + sizeof(SWIZZLE_TABLE); | 355 | constexpr size_t TOTAL_BUFFER_SIZE = sizeof(ASTC_ENCODINGS_VALUES) + sizeof(SWIZZLE_TABLE); |
| 427 | data_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{ | 356 | data_buffer = device.GetLogical().CreateBuffer(VkBufferCreateInfo{ |
| 428 | .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, | 357 | .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, |
| 429 | .pNext = nullptr, | 358 | .pNext = nullptr, |
| @@ -437,9 +366,10 @@ void ASTCDecoderPass::MakeDataBuffer() { | |||
| 437 | data_buffer_commit = memory_allocator.Commit(data_buffer, MemoryUsage::Upload); | 366 | data_buffer_commit = memory_allocator.Commit(data_buffer, MemoryUsage::Upload); |
| 438 | 367 | ||
| 439 | const auto staging_ref = staging_buffer_pool.Request(TOTAL_BUFFER_SIZE, MemoryUsage::Upload); | 368 | const auto staging_ref = staging_buffer_pool.Request(TOTAL_BUFFER_SIZE, MemoryUsage::Upload); |
| 440 | std::memcpy(staging_ref.mapped_span.data(), &ASTC_BUFFER_DATA, sizeof(ASTC_BUFFER_DATA)); | 369 | std::memcpy(staging_ref.mapped_span.data(), &ASTC_ENCODINGS_VALUES, |
| 370 | sizeof(ASTC_ENCODINGS_VALUES)); | ||
| 441 | // Tack on the swizzle table at the end of the buffer | 371 | // Tack on the swizzle table at the end of the buffer |
| 442 | std::memcpy(staging_ref.mapped_span.data() + sizeof(ASTC_BUFFER_DATA), &SWIZZLE_TABLE, | 372 | std::memcpy(staging_ref.mapped_span.data() + sizeof(ASTC_ENCODINGS_VALUES), &SWIZZLE_TABLE, |
| 443 | sizeof(SWIZZLE_TABLE)); | 373 | sizeof(SWIZZLE_TABLE)); |
| 444 | 374 | ||
| 445 | scheduler.Record([src = staging_ref.buffer, offset = staging_ref.offset, dst = *data_buffer, | 375 | scheduler.Record([src = staging_ref.buffer, offset = staging_ref.offset, dst = *data_buffer, |
| @@ -509,18 +439,8 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map, | |||
| 509 | update_descriptor_queue.Acquire(); | 439 | update_descriptor_queue.Acquire(); |
| 510 | update_descriptor_queue.AddBuffer(map.buffer, input_offset, | 440 | update_descriptor_queue.AddBuffer(map.buffer, input_offset, |
| 511 | image.guest_size_bytes - swizzle.buffer_offset); | 441 | image.guest_size_bytes - swizzle.buffer_offset); |
| 512 | update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, encoding_values), | 442 | update_descriptor_queue.AddBuffer(*data_buffer, 0, sizeof(ASTC_ENCODINGS_VALUES)); |
| 513 | sizeof(AstcBufferData::encoding_values)); | 443 | update_descriptor_queue.AddBuffer(*data_buffer, sizeof(ASTC_ENCODINGS_VALUES), |
| 514 | update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_6_to_8), | ||
| 515 | sizeof(AstcBufferData::replicate_6_to_8)); | ||
| 516 | update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_7_to_8), | ||
| 517 | sizeof(AstcBufferData::replicate_7_to_8)); | ||
| 518 | update_descriptor_queue.AddBuffer(*data_buffer, offsetof(AstcBufferData, replicate_8_to_8), | ||
| 519 | sizeof(AstcBufferData::replicate_8_to_8)); | ||
| 520 | update_descriptor_queue.AddBuffer(*data_buffer, | ||
| 521 | offsetof(AstcBufferData, replicate_byte_to_16), | ||
| 522 | sizeof(AstcBufferData::replicate_byte_to_16)); | ||
| 523 | update_descriptor_queue.AddBuffer(*data_buffer, sizeof(AstcBufferData), | ||
| 524 | sizeof(SWIZZLE_TABLE)); | 444 | sizeof(SWIZZLE_TABLE)); |
| 525 | update_descriptor_queue.AddImage(image.StorageImageView(swizzle.level)); | 445 | update_descriptor_queue.AddImage(image.StorageImageView(swizzle.level)); |
| 526 | 446 | ||
| @@ -569,6 +489,7 @@ void ASTCDecoderPass::Assemble(Image& image, const StagingBufferRef& map, | |||
| 569 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, | 489 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, |
| 570 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, image_barrier); | 490 | VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, image_barrier); |
| 571 | }); | 491 | }); |
| 492 | scheduler.Finish(); | ||
| 572 | } | 493 | } |
| 573 | 494 | ||
| 574 | } // namespace Vulkan | 495 | } // namespace Vulkan |