diff options
Diffstat (limited to 'src')
7 files changed, 65 insertions, 63 deletions
diff --git a/src/video_core/renderer_vulkan/pipeline_helper.h b/src/video_core/renderer_vulkan/pipeline_helper.h index 0a59aa659..eebe5d569 100644 --- a/src/video_core/renderer_vulkan/pipeline_helper.h +++ b/src/video_core/renderer_vulkan/pipeline_helper.h | |||
| @@ -35,49 +35,52 @@ struct TextureHandle { | |||
| 35 | u32 sampler; | 35 | u32 sampler; |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | struct DescriptorLayoutTuple { | ||
| 39 | vk::DescriptorSetLayout descriptor_set_layout; | ||
| 40 | vk::PipelineLayout pipeline_layout; | ||
| 41 | vk::DescriptorUpdateTemplateKHR descriptor_update_template; | ||
| 42 | }; | ||
| 43 | |||
| 44 | class DescriptorLayoutBuilder { | 38 | class DescriptorLayoutBuilder { |
| 45 | public: | 39 | public: |
| 46 | DescriptorLayoutTuple Create(const vk::Device& device) { | 40 | DescriptorLayoutBuilder(const vk::Device& device_) : device{&device_} {} |
| 47 | DescriptorLayoutTuple result; | 41 | |
| 48 | if (!bindings.empty()) { | 42 | vk::DescriptorSetLayout CreateDescriptorSetLayout() const { |
| 49 | result.descriptor_set_layout = device.CreateDescriptorSetLayout({ | 43 | if (bindings.empty()) { |
| 50 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, | 44 | return nullptr; |
| 51 | .pNext = nullptr, | ||
| 52 | .flags = 0, | ||
| 53 | .bindingCount = static_cast<u32>(bindings.size()), | ||
| 54 | .pBindings = bindings.data(), | ||
| 55 | }); | ||
| 56 | } | 45 | } |
| 57 | result.pipeline_layout = device.CreatePipelineLayout({ | 46 | return device->CreateDescriptorSetLayout({ |
| 47 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, | ||
| 48 | .pNext = nullptr, | ||
| 49 | .flags = 0, | ||
| 50 | .bindingCount = static_cast<u32>(bindings.size()), | ||
| 51 | .pBindings = bindings.data(), | ||
| 52 | }); | ||
| 53 | } | ||
| 54 | |||
| 55 | vk::DescriptorUpdateTemplateKHR CreateTemplate(VkDescriptorSetLayout descriptor_set_layout, | ||
| 56 | VkPipelineLayout pipeline_layout) const { | ||
| 57 | if (entries.empty()) { | ||
| 58 | return nullptr; | ||
| 59 | } | ||
| 60 | return device->CreateDescriptorUpdateTemplateKHR({ | ||
| 61 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR, | ||
| 62 | .pNext = nullptr, | ||
| 63 | .flags = 0, | ||
| 64 | .descriptorUpdateEntryCount = static_cast<u32>(entries.size()), | ||
| 65 | .pDescriptorUpdateEntries = entries.data(), | ||
| 66 | .templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR, | ||
| 67 | .descriptorSetLayout = descriptor_set_layout, | ||
| 68 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | ||
| 69 | .pipelineLayout = pipeline_layout, | ||
| 70 | .set = 0, | ||
| 71 | }); | ||
| 72 | } | ||
| 73 | |||
| 74 | vk::PipelineLayout CreatePipelineLayout(VkDescriptorSetLayout descriptor_set_layout) const { | ||
| 75 | return device->CreatePipelineLayout({ | ||
| 58 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, | 76 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 59 | .pNext = nullptr, | 77 | .pNext = nullptr, |
| 60 | .flags = 0, | 78 | .flags = 0, |
| 61 | .setLayoutCount = result.descriptor_set_layout ? 1U : 0U, | 79 | .setLayoutCount = descriptor_set_layout ? 1U : 0U, |
| 62 | .pSetLayouts = bindings.empty() ? nullptr : result.descriptor_set_layout.address(), | 80 | .pSetLayouts = bindings.empty() ? nullptr : &descriptor_set_layout, |
| 63 | .pushConstantRangeCount = 0, | 81 | .pushConstantRangeCount = 0, |
| 64 | .pPushConstantRanges = nullptr, | 82 | .pPushConstantRanges = nullptr, |
| 65 | }); | 83 | }); |
| 66 | if (!entries.empty()) { | ||
| 67 | result.descriptor_update_template = device.CreateDescriptorUpdateTemplateKHR({ | ||
| 68 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR, | ||
| 69 | .pNext = nullptr, | ||
| 70 | .flags = 0, | ||
| 71 | .descriptorUpdateEntryCount = static_cast<u32>(entries.size()), | ||
| 72 | .pDescriptorUpdateEntries = entries.data(), | ||
| 73 | .templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR, | ||
| 74 | .descriptorSetLayout = *result.descriptor_set_layout, | ||
| 75 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, | ||
| 76 | .pipelineLayout = *result.pipeline_layout, | ||
| 77 | .set = 0, | ||
| 78 | }); | ||
| 79 | } | ||
| 80 | return result; | ||
| 81 | } | 84 | } |
| 82 | 85 | ||
| 83 | void Add(const Shader::Info& info, VkShaderStageFlags stage) { | 86 | void Add(const Shader::Info& info, VkShaderStageFlags stage) { |
| @@ -113,6 +116,7 @@ private: | |||
| 113 | offset += sizeof(DescriptorUpdateEntry); | 116 | offset += sizeof(DescriptorUpdateEntry); |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 119 | const vk::Device* device{}; | ||
| 116 | boost::container::small_vector<VkDescriptorSetLayoutBinding, 32> bindings; | 120 | boost::container::small_vector<VkDescriptorSetLayoutBinding, 32> bindings; |
| 117 | boost::container::small_vector<VkDescriptorUpdateTemplateEntryKHR, 32> entries; | 121 | boost::container::small_vector<VkDescriptorUpdateTemplateEntryKHR, 32> entries; |
| 118 | u32 binding{}; | 122 | u32 binding{}; |
diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp index a444d55d3..760857839 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp | |||
| @@ -237,7 +237,7 @@ VkDescriptorSet VKComputePass::CommitDescriptorSet( | |||
| 237 | return nullptr; | 237 | return nullptr; |
| 238 | } | 238 | } |
| 239 | const VkDescriptorSet set = descriptor_allocator->Commit(); | 239 | const VkDescriptorSet set = descriptor_allocator->Commit(); |
| 240 | update_descriptor_queue.Send(*descriptor_template, set); | 240 | update_descriptor_queue.Send(descriptor_template.address(), set); |
| 241 | return set; | 241 | return set; |
| 242 | } | 242 | } |
| 243 | 243 | ||
diff --git a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp index 1c3249e3c..fb19bb4b9 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pipeline.cpp | |||
| @@ -17,13 +17,6 @@ | |||
| 17 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 17 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 18 | 18 | ||
| 19 | namespace Vulkan { | 19 | namespace Vulkan { |
| 20 | namespace { | ||
| 21 | DescriptorLayoutTuple CreateLayout(const Device& device, const Shader::Info& info) { | ||
| 22 | DescriptorLayoutBuilder builder; | ||
| 23 | builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT); | ||
| 24 | return builder.Create(device.GetLogical()); | ||
| 25 | } | ||
| 26 | } // Anonymous namespace | ||
| 27 | 20 | ||
| 28 | ComputePipeline::ComputePipeline(const Device& device, VKDescriptorPool& descriptor_pool, | 21 | ComputePipeline::ComputePipeline(const Device& device, VKDescriptorPool& descriptor_pool, |
| 29 | VKUpdateDescriptorQueue& update_descriptor_queue_, | 22 | VKUpdateDescriptorQueue& update_descriptor_queue_, |
| @@ -31,10 +24,12 @@ ComputePipeline::ComputePipeline(const Device& device, VKDescriptorPool& descrip | |||
| 31 | vk::ShaderModule spv_module_) | 24 | vk::ShaderModule spv_module_) |
| 32 | : update_descriptor_queue{update_descriptor_queue_}, info{info_}, | 25 | : update_descriptor_queue{update_descriptor_queue_}, info{info_}, |
| 33 | spv_module(std::move(spv_module_)) { | 26 | spv_module(std::move(spv_module_)) { |
| 34 | DescriptorLayoutTuple tuple{CreateLayout(device, info)}; | 27 | DescriptorLayoutBuilder builder{device.GetLogical()}; |
| 35 | descriptor_set_layout = std::move(tuple.descriptor_set_layout); | 28 | builder.Add(info, VK_SHADER_STAGE_COMPUTE_BIT); |
| 36 | pipeline_layout = std::move(tuple.pipeline_layout); | 29 | |
| 37 | descriptor_update_template = std::move(tuple.descriptor_update_template); | 30 | descriptor_set_layout = builder.CreateDescriptorSetLayout(); |
| 31 | pipeline_layout = builder.CreatePipelineLayout(*descriptor_set_layout); | ||
| 32 | descriptor_update_template = builder.CreateTemplate(*descriptor_set_layout, *pipeline_layout); | ||
| 38 | descriptor_allocator = DescriptorAllocator(descriptor_pool, *descriptor_set_layout); | 33 | descriptor_allocator = DescriptorAllocator(descriptor_pool, *descriptor_set_layout); |
| 39 | 34 | ||
| 40 | auto func{[this, &device] { | 35 | auto func{[this, &device] { |
| @@ -128,7 +123,7 @@ void ComputePipeline::Configure(Tegra::Engines::KeplerCompute& kepler_compute, | |||
| 128 | return; | 123 | return; |
| 129 | } | 124 | } |
| 130 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; | 125 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; |
| 131 | update_descriptor_queue.Send(*descriptor_update_template, descriptor_set); | 126 | update_descriptor_queue.Send(descriptor_update_template.address(), descriptor_set); |
| 132 | scheduler.Record([this, descriptor_set](vk::CommandBuffer cmdbuf) { | 127 | scheduler.Record([this, descriptor_set](vk::CommandBuffer cmdbuf) { |
| 133 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0, | 128 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_COMPUTE, *pipeline_layout, 0, |
| 134 | descriptor_set, nullptr); | 129 | descriptor_set, nullptr); |
diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index ddc08b8c4..d17b79e02 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | |||
| @@ -27,8 +27,8 @@ using VideoCore::Surface::PixelFormat; | |||
| 27 | using VideoCore::Surface::PixelFormatFromDepthFormat; | 27 | using VideoCore::Surface::PixelFormatFromDepthFormat; |
| 28 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; | 28 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; |
| 29 | 29 | ||
| 30 | DescriptorLayoutTuple CreateLayout(const Device& device, std::span<const Shader::Info> infos) { | 30 | DescriptorLayoutBuilder MakeBuilder(const Device& device, std::span<const Shader::Info> infos) { |
| 31 | DescriptorLayoutBuilder builder; | 31 | DescriptorLayoutBuilder builder{device.GetLogical()}; |
| 32 | for (size_t index = 0; index < infos.size(); ++index) { | 32 | for (size_t index = 0; index < infos.size(); ++index) { |
| 33 | static constexpr std::array stages{ | 33 | static constexpr std::array stages{ |
| 34 | VK_SHADER_STAGE_VERTEX_BIT, | 34 | VK_SHADER_STAGE_VERTEX_BIT, |
| @@ -39,7 +39,7 @@ DescriptorLayoutTuple CreateLayout(const Device& device, std::span<const Shader: | |||
| 39 | }; | 39 | }; |
| 40 | builder.Add(infos[index], stages.at(index)); | 40 | builder.Add(infos[index], stages.at(index)); |
| 41 | } | 41 | } |
| 42 | return builder.Create(device.GetLogical()); | 42 | return builder; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | template <class StencilFace> | 45 | template <class StencilFace> |
| @@ -124,13 +124,15 @@ GraphicsPipeline::GraphicsPipeline(Tegra::Engines::Maxwell3D& maxwell3d_, | |||
| 124 | std::ranges::transform(infos, stage_infos.begin(), | 124 | std::ranges::transform(infos, stage_infos.begin(), |
| 125 | [](const Shader::Info* info) { return info ? *info : Shader::Info{}; }); | 125 | [](const Shader::Info* info) { return info ? *info : Shader::Info{}; }); |
| 126 | 126 | ||
| 127 | DescriptorLayoutTuple tuple{CreateLayout(device, stage_infos)}; | 127 | DescriptorLayoutBuilder builder{MakeBuilder(device, stage_infos)}; |
| 128 | descriptor_set_layout = std::move(tuple.descriptor_set_layout); | 128 | descriptor_set_layout = builder.CreateDescriptorSetLayout(); |
| 129 | pipeline_layout = std::move(tuple.pipeline_layout); | ||
| 130 | descriptor_update_template = std::move(tuple.descriptor_update_template); | ||
| 131 | descriptor_allocator = DescriptorAllocator(descriptor_pool, *descriptor_set_layout); | 129 | descriptor_allocator = DescriptorAllocator(descriptor_pool, *descriptor_set_layout); |
| 132 | 130 | ||
| 133 | auto func{[this, &device, &render_pass_cache] { | 131 | auto func{[this, &device, &render_pass_cache, builder] { |
| 132 | const VkDescriptorSetLayout set_layout{*descriptor_set_layout}; | ||
| 133 | pipeline_layout = builder.CreatePipelineLayout(set_layout); | ||
| 134 | descriptor_update_template = builder.CreateTemplate(set_layout, *pipeline_layout); | ||
| 135 | |||
| 134 | const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(state))}; | 136 | const VkRenderPass render_pass{render_pass_cache.Get(MakeRenderPassKey(state))}; |
| 135 | MakePipeline(device, render_pass); | 137 | MakePipeline(device, render_pass); |
| 136 | building_flag.test_and_set(); | 138 | building_flag.test_and_set(); |
| @@ -206,11 +208,11 @@ void GraphicsPipeline::Configure(bool is_indexed) { | |||
| 206 | return; | 208 | return; |
| 207 | } | 209 | } |
| 208 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; | 210 | const VkDescriptorSet descriptor_set{descriptor_allocator.Commit()}; |
| 209 | update_descriptor_queue.Send(*descriptor_update_template, descriptor_set); | 211 | update_descriptor_queue.Send(descriptor_update_template.address(), descriptor_set); |
| 210 | 212 | ||
| 211 | scheduler.Record([descriptor_set, layout = *pipeline_layout](vk::CommandBuffer cmdbuf) { | 213 | scheduler.Record([this, descriptor_set](vk::CommandBuffer cmdbuf) { |
| 212 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, layout, 0, descriptor_set, | 214 | cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline_layout, 0, |
| 213 | nullptr); | 215 | descriptor_set, nullptr); |
| 214 | }); | 216 | }); |
| 215 | } | 217 | } |
| 216 | 218 | ||
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index e3d9debf4..597261964 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -620,7 +620,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, Tegra::GPU& gpu_, | |||
| 620 | kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_}, device{device_}, | 620 | kepler_compute{kepler_compute_}, gpu_memory{gpu_memory_}, device{device_}, |
| 621 | scheduler{scheduler_}, descriptor_pool{descriptor_pool_}, | 621 | scheduler{scheduler_}, descriptor_pool{descriptor_pool_}, |
| 622 | update_descriptor_queue{update_descriptor_queue_}, render_pass_cache{render_pass_cache_}, | 622 | update_descriptor_queue{update_descriptor_queue_}, render_pass_cache{render_pass_cache_}, |
| 623 | buffer_cache{buffer_cache_}, texture_cache{texture_cache_}, workers(11, "PipelineBuilder") { | 623 | buffer_cache{buffer_cache_}, texture_cache{texture_cache_}, |
| 624 | workers(11, "yuzu:PipelineBuilder") { | ||
| 624 | const auto& float_control{device.FloatControlProperties()}; | 625 | const auto& float_control{device.FloatControlProperties()}; |
| 625 | const VkDriverIdKHR driver_id{device.GetDriverID()}; | 626 | const VkDriverIdKHR driver_id{device.GetDriverID()}; |
| 626 | base_profile = Shader::Profile{ | 627 | base_profile = Shader::Profile{ |
diff --git a/src/video_core/renderer_vulkan/vk_update_descriptor.cpp b/src/video_core/renderer_vulkan/vk_update_descriptor.cpp index dc45fdcb1..bea9b8012 100644 --- a/src/video_core/renderer_vulkan/vk_update_descriptor.cpp +++ b/src/video_core/renderer_vulkan/vk_update_descriptor.cpp | |||
| @@ -36,12 +36,12 @@ void VKUpdateDescriptorQueue::Acquire() { | |||
| 36 | upload_start = payload_cursor; | 36 | upload_start = payload_cursor; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | void VKUpdateDescriptorQueue::Send(VkDescriptorUpdateTemplateKHR update_template, | 39 | void VKUpdateDescriptorQueue::Send(const VkDescriptorUpdateTemplateKHR* update_template, |
| 40 | VkDescriptorSet set) { | 40 | VkDescriptorSet set) { |
| 41 | const void* const data = upload_start; | 41 | const void* const data = upload_start; |
| 42 | const vk::Device* const logical = &device.GetLogical(); | 42 | const vk::Device* const logical = &device.GetLogical(); |
| 43 | scheduler.Record([data, logical, set, update_template](vk::CommandBuffer) { | 43 | scheduler.Record([data, logical, set, update_template](vk::CommandBuffer) { |
| 44 | logical->UpdateDescriptorSet(set, update_template, data); | 44 | logical->UpdateDescriptorSet(set, *update_template, data); |
| 45 | }); | 45 | }); |
| 46 | } | 46 | } |
| 47 | 47 | ||
diff --git a/src/video_core/renderer_vulkan/vk_update_descriptor.h b/src/video_core/renderer_vulkan/vk_update_descriptor.h index d35e77c44..82bc9920c 100644 --- a/src/video_core/renderer_vulkan/vk_update_descriptor.h +++ b/src/video_core/renderer_vulkan/vk_update_descriptor.h | |||
| @@ -39,7 +39,7 @@ public: | |||
| 39 | 39 | ||
| 40 | void Acquire(); | 40 | void Acquire(); |
| 41 | 41 | ||
| 42 | void Send(VkDescriptorUpdateTemplateKHR update_template, VkDescriptorSet set); | 42 | void Send(const VkDescriptorUpdateTemplateKHR* update_template, VkDescriptorSet set); |
| 43 | 43 | ||
| 44 | void AddSampledImage(VkImageView image_view, VkSampler sampler) { | 44 | void AddSampledImage(VkImageView image_view, VkSampler sampler) { |
| 45 | *(payload_cursor++) = VkDescriptorImageInfo{ | 45 | *(payload_cursor++) = VkDescriptorImageInfo{ |