diff options
| author | 2021-06-16 21:14:57 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:38 -0400 | |
| commit | ca67077ca87772b4b4ac61d08f5b2c60616348e0 (patch) | |
| tree | 2a861de6f5be92cbed1542f115a99e646a1793c9 /src/video_core/renderer_vulkan | |
| parent | glsl: Fix cbuf component indexing bug falback (diff) | |
| download | yuzu-ca67077ca87772b4b4ac61d08f5b2c60616348e0.tar.gz yuzu-ca67077ca87772b4b4ac61d08f5b2c60616348e0.tar.xz yuzu-ca67077ca87772b4b4ac61d08f5b2c60616348e0.zip | |
vk_graphics_pipeline: Use VK_KHR_push_descriptor when available
~51% faster on Nvidia compared to previous method.
Diffstat (limited to 'src/video_core/renderer_vulkan')
4 files changed, 45 insertions, 24 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h index c6e5e059b..4847db6b6 100644 --- a/src/video_core/renderer_vulkan/pipeline_helper.h +++ b/src/video_core/renderer_vulkan/pipeline_helper.h | |||
| @@ -16,38 +16,50 @@ | |||
| 16 | #include "video_core/texture_cache/texture_cache.h" | 16 | #include "video_core/texture_cache/texture_cache.h" |
| 17 | #include "video_core/texture_cache/types.h" | 17 | #include "video_core/texture_cache/types.h" |
| 18 | #include "video_core/textures/texture.h" | 18 | #include "video_core/textures/texture.h" |
| 19 | #include "video_core/vulkan_common/vulkan_device.h" | ||
| 19 | 20 | ||
| 20 | namespace Vulkan { | 21 | namespace Vulkan { |
| 21 | 22 | ||
| 22 | class DescriptorLayoutBuilder { | 23 | class DescriptorLayoutBuilder { |
| 23 | public: | 24 | public: |
| 24 | DescriptorLayoutBuilder(const vk::Device& device_) : device{&device_} {} | 25 | DescriptorLayoutBuilder(const Device& device_) : device{&device_} {} |
| 25 | 26 | ||
| 26 | vk::DescriptorSetLayout CreateDescriptorSetLayout() const { | 27 | bool CanUsePushDescriptor() const noexcept { |
| 28 | return device->IsKhrPushDescriptorSupported() && | ||
| 29 | num_descriptors <= device->MaxPushDescriptors(); | ||
| 30 | } | ||
| 31 | |||
| 32 | vk::DescriptorSetLayout CreateDescriptorSetLayout(bool use_push_descriptor) const { | ||
| 27 | if (bindings.empty()) { | 33 | if (bindings.empty()) { |
| 28 | return nullptr; | 34 | return nullptr; |
| 29 | } | 35 | } |
| 30 | return device->CreateDescriptorSetLayout({ | 36 | const VkDescriptorSetLayoutCreateFlags flags = |
| 37 | use_push_descriptor ? VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR : 0; | ||
| 38 | return device->GetLogical().CreateDescriptorSetLayout({ | ||
| 31 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, | 39 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 32 | .pNext = nullptr, | 40 | .pNext = nullptr, |
| 33 | .flags = 0, | 41 | .flags = flags, |
| 34 | .bindingCount = static_cast<u32>(bindings.size()), | 42 | .bindingCount = static_cast<u32>(bindings.size()), |
| 35 | .pBindings = bindings.data(), | 43 | .pBindings = bindings.data(), |
| 36 | }); | 44 | }); |
| 37 | } | 45 | } |
| 38 | 46 | ||
| 39 | vk::DescriptorUpdateTemplateKHR CreateTemplate(VkDescriptorSetLayout descriptor_set_layout, | 47 | vk::DescriptorUpdateTemplateKHR CreateTemplate(VkDescriptorSetLayout descriptor_set_layout, |
| 40 | VkPipelineLayout pipeline_layout) const { | 48 | VkPipelineLayout pipeline_layout, |
| 49 | bool use_push_descriptor) const { | ||
| 41 | if (entries.empty()) { | 50 | if (entries.empty()) { |
| 42 | return nullptr; | 51 | return nullptr; |
| 43 | } | 52 | } |
| 44 | return device->CreateDescriptorUpdateTemplateKHR({ | 53 | const VkDescriptorUpdateTemplateType type = |
| 54 | use_push_descriptor ? VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR | ||
| 55 | : VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR; | ||
| 56 | return device->GetLogical().CreateDescriptorUpdateTemplateKHR({ | ||
| 45 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR, | 57 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR, |
| 46 | .pNext = nullptr, | 58 | .pNext = nullptr, |
| 47 | .flags = 0, | 59 | .flags = 0, |
| 48 | .descriptorUpdateEntryCount = static_cast<u32>(entries.size()), | 60 | .descriptorUpdateEntryCount = static_cast<u32>(entries.size()), |
| 49 | .pDescriptorUpdateEntries = entries.data(), | 61 | .pDescriptorUpdateEntries = entries.data(), |
| 50 | .templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR, | 62 | .templateType = type, |
| 51 | .descriptorSetLayout = descriptor_set_layout, | 63 | .descriptorSetLayout = descriptor_set_layout, |
| 52 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | 64 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 53 | .pipelineLayout = pipeline_layout, | 65 | .pipelineLayout = pipeline_layout, |
| @@ -56,7 +68,7 @@ public: | |||
| 56 | } | 68 | } |
| 57 | 69 | ||
| 58 | vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { | 70 | vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { |
| 59 | return device->CreatePipelineLayout({ | 71 | return device->GetLogical().CreatePipelineLayout({ |
| 60 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, | 72 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 61 | .pNext = nullptr, | 73 | .pNext = nullptr, |
| 62 | .flags = 0, | 74 | .flags = 0, |
| @@ -97,14 +109,16 @@ private: | |||
| 97 | .stride = sizeof(DescriptorUpdateEntry), | 109 | .stride = sizeof(DescriptorUpdateEntry), |
| 98 | }); | 110 | }); |
| 99 | ++binding; | 111 | ++binding; |
| 112 | num_descriptors += descriptors[i].count; | ||
| 100 | offset += sizeof(DescriptorUpdateEntry); | 113 | offset += sizeof(DescriptorUpdateEntry); |
| 101 | } | 114 | } |
| 102 | } | 115 | } |
| 103 | 116 | ||
| 104 | const vk::Device* device{}; | 117 | const Device* device{}; |
| 105 | boost::container::small_vector<VkDescriptorSetLayoutBinding, 32> bindings; | 118 | boost::container::small_vector<VkDescriptorSetLayoutBinding, 32> bindings; |
| 106 | boost::container::small_vector<VkDescriptorUpdateTemplateEntryKHR, 32> entries; | 119 | boost::container::small_vector<VkDescriptorUpdateTemplateEntryKHR, 32> entries; |
| 107 | u32 binding{}; | 120 | u32 binding{}; |
| 121 | u32 num_descriptors{}; | ||
| 108 | size_t offset{}; | 122 | size_t offset{}; |
| 109 | }; | 123 | }; |
| 110 | 124 | ||
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp index cc855a62e..70b84c7a6 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp | |||
| @@ -37,15 +37,14 @@ ComputePipeline::ComputePipeline(const Device& device_, DescriptorPool& descript | |||
| 37 | uniform_buffer_sizes.begin()); | 37 | uniform_buffer_sizes.begin()); |
| 38 | 38 | ||
| 39 | auto func{[this, &descriptor_pool, shader_notify] { | 39 | auto func{[this, &descriptor_pool, shader_notify] { |
| 40 | DescriptorLayoutBuilder builder{device.GetLogical()}; | 40 | DescriptorLayoutBuilder builder{device}; |
| 41 | builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT); | 41 | builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT); |
| 42 | 42 | ||
| 43 | descriptor_set_layout = builder.CreateDescriptorSetLayout(); | 43 | descriptor_set_layout = builder.CreateDescriptorSetLayout(false); |
| 44 | pipeline_layout = builder.CreatePipelineLayout(*descriptor_set_layout); | 44 | pipeline_layout = builder.CreatePipelineLayout(*descriptor_set_layout); |
| 45 | descriptor_update_template = | 45 | descriptor_update_template = |
| 46 | builder.CreateTemplate(*descriptor_set_layout, *pipeline_layout); | 46 | builder.CreateTemplate(*descriptor_set_layout, *pipeline_layout, false); |
| 47 | descriptor_allocator = descriptor_pool.Allocator(*descriptor_set_layout, info); | 47 | descriptor_allocator = descriptor_pool.Allocator(*descriptor_set_layout, info); |
| 48 | |||
| 49 | const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroup_size_ci{ | 48 | const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroup_size_ci{ |
| 50 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT, | 49 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT, |
| 51 | .pNext = nullptr, | 50 | .pNext = nullptr, |
| @@ -186,7 +185,6 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute, | |||
| 186 | const void* const descriptor_data{update_descriptor_queue.UpdateData()}; | 185 | const void* const descriptor_data{update_descriptor_queue.UpdateData()}; |
| 187 | scheduler.Record([this, descriptor_data](vk::CommandBuffer cmdbuf) { | 186 | scheduler.Record([this, descriptor_data](vk::CommandBuffer cmdbuf) { |
| 188 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); | 187 | cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline); |
| 189 | |||
| 190 | if (!descriptor_set_layout) { | 188 | if (!descriptor_set_layout) { |
| 191 | return; | 189 | return; |
| 192 | } | 190 | } |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index e02b1b7ab..2b59a9d88 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -40,7 +40,7 @@ constexpr size_t NUM_STAGES = Maxwell::MaxShaderStage; | |||
| 40 | constexpr size_t MAX_IMAGE_ELEMENTS = 64; | 40 | constexpr size_t MAX_IMAGE_ELEMENTS = 64; |
| 41 | 41 | ||
| 42 | DescriptorLayoutBuilder MakeBuilder(const Device& device, std::span<const Shader::Info> infos) { | 42 | DescriptorLayoutBuilder MakeBuilder(const Device& device, std::span<const Shader::Info> infos) { |
| 43 | DescriptorLayoutBuilder builder{device.GetLogical()}; | 43 | DescriptorLayoutBuilder builder{device}; |
| 44 | for (size_t index = 0; index < infos.size(); ++index) { | 44 | for (size_t index = 0; index < infos.size(); ++index) { |
| 45 | static constexpr std::array stages{ | 45 | static constexpr std::array stages{ |
| 46 | VK_SHADER_STAGE_VERTEX_BIT, | 46 | VK_SHADER_STAGE_VERTEX_BIT, |
| @@ -229,12 +229,15 @@ GraphicsPipeline::GraphicsPipeline( | |||
| 229 | } | 229 | } |
| 230 | auto func{[this, shader_notify, &render_pass_cache, &descriptor_pool] { | 230 | auto func{[this, shader_notify, &render_pass_cache, &descriptor_pool] { |
| 231 | DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)}; | 231 | DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)}; |
| 232 | descriptor_set_layout = builder.CreateDescriptorSetLayout(); | 232 | uses_push_descriptor = builder.CanUsePushDescriptor(); |
| 233 | descriptor_allocator = descriptor_pool.Allocator(*descriptor_set_layout, stage_infos); | 233 | descriptor_set_layout = builder.CreateDescriptorSetLayout(uses_push_descriptor); |
| 234 | 234 | if (!uses_push_descriptor) { | |
| 235 | descriptor_allocator = descriptor_pool.Allocator(*descriptor_set_layout, stage_infos); | ||
| 236 | } | ||
| 235 | const VkDescriptorSetLayout set_layout{*descriptor_set_layout}; | 237 | const VkDescriptorSetLayout set_layout{*descriptor_set_layout}; |
| 236 | pipeline_layout = builder.CreatePipelineLayout(set_layout); | 238 | pipeline_layout = builder.CreatePipelineLayout(set_layout); |
| 237 | descriptor_update_template = builder.CreateTemplate(set_layout, *pipeline_layout); | 239 | descriptor_update_template = |
| 240 | builder.CreateTemplate(set_layout, *pipeline_layout, uses_push_descriptor); | ||
| 238 | 241 | ||
| 239 | const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(key.state))}; | 242 | const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(key.state))}; |
| 240 | Validate(); | 243 | Validate(); |
| @@ -462,11 +465,16 @@ void GraphicsPipeline::ConfigureDraw() { | |||
| 462 | if (!descriptor_set_layout) { | 465 | if (!descriptor_set_layout) { |
| 463 | return; | 466 | return; |
| 464 | } | 467 | } |
| 465 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; | 468 | if (uses_push_descriptor) { |
| 466 | const vk::Device& dev{device.GetLogical()}; | 469 | cmdbuf.PushDescriptorSetWithTemplateKHR(*descriptor_update_template, *pipeline_layout, |
| 467 | dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data); | 470 | 0, descriptor_data); |
| 468 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline_layout, 0, | 471 | } else { |
| 469 | descriptor_set, nullptr); | 472 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; |
| 473 | const vk::Device& dev{device.GetLogical()}; | ||
| 474 | dev.UpdateDescriptorSet(descriptor_set, *descriptor_update_template, descriptor_data); | ||
| 475 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline_layout, 0, | ||
| 476 | descriptor_set, nullptr); | ||
| 477 | } | ||
| 470 | }); | 478 | }); |
| 471 | } | 479 | } |
| 472 | 480 | ||
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h index 40d1edabd..622267147 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.h +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.h | |||
| @@ -148,6 +148,7 @@ private: | |||
| 148 | std::condition_variable build_condvar; | 148 | std::condition_variable build_condvar; |
| 149 | std::mutex build_mutex; | 149 | std::mutex build_mutex; |
| 150 | std::atomic_bool is_built{false}; | 150 | std::atomic_bool is_built{false}; |
| 151 | bool uses_push_descriptor{false}; | ||
| 151 | }; | 152 | }; |
| 152 | 153 | ||
| 153 | } // namespace Vulkan | 154 | } // namespace Vulkan |