diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_compute_pass.cpp | 194 |
1 files changed, 99 insertions, 95 deletions
diff --git a/src/video_core/renderer_vulkan/vk_compute_pass.cpp b/src/video_core/renderer_vulkan/vk_compute_pass.cpp index da71e710c..182461ed9 100644 --- a/src/video_core/renderer_vulkan/vk_compute_pass.cpp +++ b/src/video_core/renderer_vulkan/vk_compute_pass.cpp | |||
| @@ -115,32 +115,32 @@ constexpr u8 quad_array[] = { | |||
| 115 | 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; | 115 | 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; |
| 116 | 116 | ||
| 117 | VkDescriptorSetLayoutBinding BuildQuadArrayPassDescriptorSetLayoutBinding() { | 117 | VkDescriptorSetLayoutBinding BuildQuadArrayPassDescriptorSetLayoutBinding() { |
| 118 | VkDescriptorSetLayoutBinding binding; | 118 | return { |
| 119 | binding.binding = 0; | 119 | .binding = 0, |
| 120 | binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; | 120 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 121 | binding.descriptorCount = 1; | 121 | .descriptorCount = 1, |
| 122 | binding.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; | 122 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, |
| 123 | binding.pImmutableSamplers = nullptr; | 123 | .pImmutableSamplers = nullptr, |
| 124 | return binding; | 124 | }; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | VkDescriptorUpdateTemplateEntryKHR BuildQuadArrayPassDescriptorUpdateTemplateEntry() { | 127 | VkDescriptorUpdateTemplateEntryKHR BuildQuadArrayPassDescriptorUpdateTemplateEntry() { |
| 128 | VkDescriptorUpdateTemplateEntryKHR entry; | 128 | return { |
| 129 | entry.dstBinding = 0; | 129 | .dstBinding = 0, |
| 130 | entry.dstArrayElement = 0; | 130 | .dstArrayElement = 0, |
| 131 | entry.descriptorCount = 1; | 131 | .descriptorCount = 1, |
| 132 | entry.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; | 132 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 133 | entry.offset = 0; | 133 | .offset = 0, |
| 134 | entry.stride = sizeof(DescriptorUpdateEntry); | 134 | .stride = sizeof(DescriptorUpdateEntry), |
| 135 | return entry; | 135 | }; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { | 138 | VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { |
| 139 | VkPushConstantRange range; | 139 | return { |
| 140 | range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; | 140 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, |
| 141 | range.offset = 0; | 141 | .offset = 0, |
| 142 | range.size = static_cast<u32>(size); | 142 | .size = static_cast<u32>(size), |
| 143 | return range; | 143 | }; |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | // Uint8 SPIR-V module. Generated from the "shaders/" directory. | 146 | // Uint8 SPIR-V module. Generated from the "shaders/" directory. |
| @@ -344,29 +344,33 @@ constexpr u8 QUAD_INDEXED_SPV[] = { | |||
| 344 | 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; | 344 | 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; |
| 345 | 345 | ||
| 346 | std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBindings() { | 346 | std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBindings() { |
| 347 | std::array<VkDescriptorSetLayoutBinding, 2> bindings; | 347 | return {{ |
| 348 | bindings[0].binding = 0; | 348 | { |
| 349 | bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; | 349 | .binding = 0, |
| 350 | bindings[0].descriptorCount = 1; | 350 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 351 | bindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; | 351 | .descriptorCount = 1, |
| 352 | bindings[0].pImmutableSamplers = nullptr; | 352 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, |
| 353 | bindings[1].binding = 1; | 353 | .pImmutableSamplers = nullptr, |
| 354 | bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; | 354 | }, |
| 355 | bindings[1].descriptorCount = 1; | 355 | { |
| 356 | bindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; | 356 | .binding = 1, |
| 357 | bindings[1].pImmutableSamplers = nullptr; | 357 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 358 | return bindings; | 358 | .descriptorCount = 1, |
| 359 | .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT, | ||
| 360 | .pImmutableSamplers = nullptr, | ||
| 361 | }, | ||
| 362 | }}; | ||
| 359 | } | 363 | } |
| 360 | 364 | ||
| 361 | VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() { | 365 | VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() { |
| 362 | VkDescriptorUpdateTemplateEntryKHR entry; | 366 | return { |
| 363 | entry.dstBinding = 0; | 367 | .dstBinding = 0, |
| 364 | entry.dstArrayElement = 0; | 368 | .dstArrayElement = 0, |
| 365 | entry.descriptorCount = 2; | 369 | .descriptorCount = 2, |
| 366 | entry.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; | 370 | .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, |
| 367 | entry.offset = 0; | 371 | .offset = 0, |
| 368 | entry.stride = sizeof(DescriptorUpdateEntry); | 372 | .stride = sizeof(DescriptorUpdateEntry), |
| 369 | return entry; | 373 | }; |
| 370 | } | 374 | } |
| 371 | 375 | ||
| 372 | } // Anonymous namespace | 376 | } // Anonymous namespace |
| @@ -376,37 +380,37 @@ VKComputePass::VKComputePass(const VKDevice& device, VKDescriptorPool& descripto | |||
| 376 | vk::Span<VkDescriptorUpdateTemplateEntryKHR> templates, | 380 | vk::Span<VkDescriptorUpdateTemplateEntryKHR> templates, |
| 377 | vk::Span<VkPushConstantRange> push_constants, std::size_t code_size, | 381 | vk::Span<VkPushConstantRange> push_constants, std::size_t code_size, |
| 378 | const u8* code) { | 382 | const u8* code) { |
| 379 | VkDescriptorSetLayoutCreateInfo descriptor_layout_ci; | 383 | descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout({ |
| 380 | descriptor_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; | 384 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, |
| 381 | descriptor_layout_ci.pNext = nullptr; | 385 | .pNext = nullptr, |
| 382 | descriptor_layout_ci.flags = 0; | 386 | .flags = 0, |
| 383 | descriptor_layout_ci.bindingCount = bindings.size(); | 387 | .bindingCount = bindings.size(), |
| 384 | descriptor_layout_ci.pBindings = bindings.data(); | 388 | .pBindings = bindings.data(), |
| 385 | descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(descriptor_layout_ci); | 389 | }); |
| 386 | 390 | ||
| 387 | VkPipelineLayoutCreateInfo pipeline_layout_ci; | 391 | layout = device.GetLogical().CreatePipelineLayout({ |
| 388 | pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; | 392 | .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, |
| 389 | pipeline_layout_ci.pNext = nullptr; | 393 | .pNext = nullptr, |
| 390 | pipeline_layout_ci.flags = 0; | 394 | .flags = 0, |
| 391 | pipeline_layout_ci.setLayoutCount = 1; | 395 | .setLayoutCount = 1, |
| 392 | pipeline_layout_ci.pSetLayouts = descriptor_set_layout.address(); | 396 | .pSetLayouts = descriptor_set_layout.address(), |
| 393 | pipeline_layout_ci.pushConstantRangeCount = push_constants.size(); | 397 | .pushConstantRangeCount = push_constants.size(), |
| 394 | pipeline_layout_ci.pPushConstantRanges = push_constants.data(); | 398 | .pPushConstantRanges = push_constants.data(), |
| 395 | layout = device.GetLogical().CreatePipelineLayout(pipeline_layout_ci); | 399 | }); |
| 396 | 400 | ||
| 397 | if (!templates.empty()) { | 401 | if (!templates.empty()) { |
| 398 | VkDescriptorUpdateTemplateCreateInfoKHR template_ci; | 402 | descriptor_template = device.GetLogical().CreateDescriptorUpdateTemplateKHR({ |
| 399 | template_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR; | 403 | .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR, |
| 400 | template_ci.pNext = nullptr; | 404 | .pNext = nullptr, |
| 401 | template_ci.flags = 0; | 405 | .flags = 0, |
| 402 | template_ci.descriptorUpdateEntryCount = templates.size(); | 406 | .descriptorUpdateEntryCount = templates.size(), |
| 403 | template_ci.pDescriptorUpdateEntries = templates.data(); | 407 | .pDescriptorUpdateEntries = templates.data(), |
| 404 | template_ci.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR; | 408 | .templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR, |
| 405 | template_ci.descriptorSetLayout = *descriptor_set_layout; | 409 | .descriptorSetLayout = *descriptor_set_layout, |
| 406 | template_ci.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; | 410 | .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS, |
| 407 | template_ci.pipelineLayout = *layout; | 411 | .pipelineLayout = *layout, |
| 408 | template_ci.set = 0; | 412 | .set = 0, |
| 409 | descriptor_template = device.GetLogical().CreateDescriptorUpdateTemplateKHR(template_ci); | 413 | }); |
| 410 | 414 | ||
| 411 | descriptor_allocator.emplace(descriptor_pool, *descriptor_set_layout); | 415 | descriptor_allocator.emplace(descriptor_pool, *descriptor_set_layout); |
| 412 | } | 416 | } |
| @@ -414,32 +418,32 @@ VKComputePass::VKComputePass(const VKDevice& device, VKDescriptorPool& descripto | |||
| 414 | auto code_copy = std::make_unique<u32[]>(code_size / sizeof(u32) + 1); | 418 | auto code_copy = std::make_unique<u32[]>(code_size / sizeof(u32) + 1); |
| 415 | std::memcpy(code_copy.get(), code, code_size); | 419 | std::memcpy(code_copy.get(), code, code_size); |
| 416 | 420 | ||
| 417 | VkShaderModuleCreateInfo module_ci; | 421 | module = device.GetLogical().CreateShaderModule({ |
| 418 | module_ci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; | 422 | .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, |
| 419 | module_ci.pNext = nullptr; | 423 | .pNext = nullptr, |
| 420 | module_ci.flags = 0; | 424 | .flags = 0, |
| 421 | module_ci.codeSize = code_size; | 425 | .codeSize = code_size, |
| 422 | module_ci.pCode = code_copy.get(); | 426 | .pCode = code_copy.get(), |
| 423 | module = device.GetLogical().CreateShaderModule(module_ci); | 427 | }); |
| 424 | 428 | ||
| 425 | VkComputePipelineCreateInfo pipeline_ci; | 429 | pipeline = device.GetLogical().CreateComputePipeline({ |
| 426 | pipeline_ci.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; | 430 | .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, |
| 427 | pipeline_ci.pNext = nullptr; | 431 | .pNext = nullptr, |
| 428 | pipeline_ci.flags = 0; | 432 | .flags = 0, |
| 429 | pipeline_ci.layout = *layout; | 433 | .stage = |
| 430 | pipeline_ci.basePipelineHandle = nullptr; | 434 | { |
| 431 | pipeline_ci.basePipelineIndex = 0; | 435 | .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, |
| 432 | 436 | .pNext = nullptr, | |
| 433 | VkPipelineShaderStageCreateInfo& stage_ci = pipeline_ci.stage; | 437 | .flags = 0, |
| 434 | stage_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; | 438 | .stage = VK_SHADER_STAGE_COMPUTE_BIT, |
| 435 | stage_ci.pNext = nullptr; | 439 | .module = *module, |
| 436 | stage_ci.flags = 0; | 440 | .pName = "main", |
| 437 | stage_ci.stage = VK_SHADER_STAGE_COMPUTE_BIT; | 441 | .pSpecializationInfo = nullptr, |
| 438 | stage_ci.module = *module; | 442 | }, |
| 439 | stage_ci.pName = "main"; | 443 | .layout = *layout, |
| 440 | stage_ci.pSpecializationInfo = nullptr; | 444 | .basePipelineHandle = nullptr, |
| 441 | 445 | .basePipelineIndex = 0, | |
| 442 | pipeline = device.GetLogical().CreateComputePipeline(pipeline_ci); | 446 | }); |
| 443 | } | 447 | } |
| 444 | 448 | ||
| 445 | VKComputePass::~VKComputePass() = default; | 449 | VKComputePass::~VKComputePass() = default; |