vk_compute_pass: Make use of designated initializers where applicable

Note: Some barriers can't be converted over yet, as they ICE MSVC.
This commit is contained in:
Lioncash 2020-07-16 17:23:53 -04:00
parent a66a0a6a53
commit 757ddd8158

View file

@ -115,32 +115,32 @@ constexpr u8 quad_array[] = {
0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00};
VkDescriptorSetLayoutBinding BuildQuadArrayPassDescriptorSetLayoutBinding() { VkDescriptorSetLayoutBinding BuildQuadArrayPassDescriptorSetLayoutBinding() {
VkDescriptorSetLayoutBinding binding; return {
binding.binding = 0; .binding = 0,
binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
binding.descriptorCount = 1; .descriptorCount = 1,
binding.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
binding.pImmutableSamplers = nullptr; .pImmutableSamplers = nullptr,
return binding; };
} }
VkDescriptorUpdateTemplateEntryKHR BuildQuadArrayPassDescriptorUpdateTemplateEntry() { VkDescriptorUpdateTemplateEntryKHR BuildQuadArrayPassDescriptorUpdateTemplateEntry() {
VkDescriptorUpdateTemplateEntryKHR entry; return {
entry.dstBinding = 0; .dstBinding = 0,
entry.dstArrayElement = 0; .dstArrayElement = 0,
entry.descriptorCount = 1; .descriptorCount = 1,
entry.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
entry.offset = 0; .offset = 0,
entry.stride = sizeof(DescriptorUpdateEntry); .stride = sizeof(DescriptorUpdateEntry),
return entry; };
} }
VkPushConstantRange BuildComputePushConstantRange(std::size_t size) { VkPushConstantRange BuildComputePushConstantRange(std::size_t size) {
VkPushConstantRange range; return {
range.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
range.offset = 0; .offset = 0,
range.size = static_cast<u32>(size); .size = static_cast<u32>(size),
return range; };
} }
// Uint8 SPIR-V module. Generated from the "shaders/" directory. // Uint8 SPIR-V module. Generated from the "shaders/" directory.
@ -344,29 +344,33 @@ constexpr u8 QUAD_INDEXED_SPV[] = {
0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00}; 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00};
std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBindings() { std::array<VkDescriptorSetLayoutBinding, 2> BuildInputOutputDescriptorSetBindings() {
std::array<VkDescriptorSetLayoutBinding, 2> bindings; return {{
bindings[0].binding = 0; {
bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; .binding = 0,
bindings[0].descriptorCount = 1; .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
bindings[0].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; .descriptorCount = 1,
bindings[0].pImmutableSamplers = nullptr; .stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
bindings[1].binding = 1; .pImmutableSamplers = nullptr,
bindings[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; },
bindings[1].descriptorCount = 1; {
bindings[1].stageFlags = VK_SHADER_STAGE_COMPUTE_BIT; .binding = 1,
bindings[1].pImmutableSamplers = nullptr; .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
return bindings; .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
.pImmutableSamplers = nullptr,
},
}};
} }
VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() { VkDescriptorUpdateTemplateEntryKHR BuildInputOutputDescriptorUpdateTemplate() {
VkDescriptorUpdateTemplateEntryKHR entry; return {
entry.dstBinding = 0; .dstBinding = 0,
entry.dstArrayElement = 0; .dstArrayElement = 0,
entry.descriptorCount = 2; .descriptorCount = 2,
entry.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
entry.offset = 0; .offset = 0,
entry.stride = sizeof(DescriptorUpdateEntry); .stride = sizeof(DescriptorUpdateEntry),
return entry; };
} }
} // Anonymous namespace } // Anonymous namespace
@ -376,37 +380,37 @@ VKComputePass::VKComputePass(const VKDevice& device, VKDescriptorPool& descripto
vk::Span<VkDescriptorUpdateTemplateEntryKHR> templates, vk::Span<VkDescriptorUpdateTemplateEntryKHR> templates,
vk::Span<VkPushConstantRange> push_constants, std::size_t code_size, vk::Span<VkPushConstantRange> push_constants, std::size_t code_size,
const u8* code) { const u8* code) {
VkDescriptorSetLayoutCreateInfo descriptor_layout_ci; descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout({
descriptor_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
descriptor_layout_ci.pNext = nullptr; .pNext = nullptr,
descriptor_layout_ci.flags = 0; .flags = 0,
descriptor_layout_ci.bindingCount = bindings.size(); .bindingCount = bindings.size(),
descriptor_layout_ci.pBindings = bindings.data(); .pBindings = bindings.data(),
descriptor_set_layout = device.GetLogical().CreateDescriptorSetLayout(descriptor_layout_ci); });
VkPipelineLayoutCreateInfo pipeline_layout_ci; layout = device.GetLogical().CreatePipelineLayout({
pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
pipeline_layout_ci.pNext = nullptr; .pNext = nullptr,
pipeline_layout_ci.flags = 0; .flags = 0,
pipeline_layout_ci.setLayoutCount = 1; .setLayoutCount = 1,
pipeline_layout_ci.pSetLayouts = descriptor_set_layout.address(); .pSetLayouts = descriptor_set_layout.address(),
pipeline_layout_ci.pushConstantRangeCount = push_constants.size(); .pushConstantRangeCount = push_constants.size(),
pipeline_layout_ci.pPushConstantRanges = push_constants.data(); .pPushConstantRanges = push_constants.data(),
layout = device.GetLogical().CreatePipelineLayout(pipeline_layout_ci); });
if (!templates.empty()) { if (!templates.empty()) {
VkDescriptorUpdateTemplateCreateInfoKHR template_ci; descriptor_template = device.GetLogical().CreateDescriptorUpdateTemplateKHR({
template_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR; .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR,
template_ci.pNext = nullptr; .pNext = nullptr,
template_ci.flags = 0; .flags = 0,
template_ci.descriptorUpdateEntryCount = templates.size(); .descriptorUpdateEntryCount = templates.size(),
template_ci.pDescriptorUpdateEntries = templates.data(); .pDescriptorUpdateEntries = templates.data(),
template_ci.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR; .templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR,
template_ci.descriptorSetLayout = *descriptor_set_layout; .descriptorSetLayout = *descriptor_set_layout,
template_ci.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
template_ci.pipelineLayout = *layout; .pipelineLayout = *layout,
template_ci.set = 0; .set = 0,
descriptor_template = device.GetLogical().CreateDescriptorUpdateTemplateKHR(template_ci); });
descriptor_allocator.emplace(descriptor_pool, *descriptor_set_layout); descriptor_allocator.emplace(descriptor_pool, *descriptor_set_layout);
} }
@ -414,32 +418,32 @@ VKComputePass::VKComputePass(const VKDevice& device, VKDescriptorPool& descripto
auto code_copy = std::make_unique<u32[]>(code_size / sizeof(u32) + 1); auto code_copy = std::make_unique<u32[]>(code_size / sizeof(u32) + 1);
std::memcpy(code_copy.get(), code, code_size); std::memcpy(code_copy.get(), code, code_size);
VkShaderModuleCreateInfo module_ci; module = device.GetLogical().CreateShaderModule({
module_ci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
module_ci.pNext = nullptr; .pNext = nullptr,
module_ci.flags = 0; .flags = 0,
module_ci.codeSize = code_size; .codeSize = code_size,
module_ci.pCode = code_copy.get(); .pCode = code_copy.get(),
module = device.GetLogical().CreateShaderModule(module_ci); });
VkComputePipelineCreateInfo pipeline_ci; pipeline = device.GetLogical().CreateComputePipeline({
pipeline_ci.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
pipeline_ci.pNext = nullptr; .pNext = nullptr,
pipeline_ci.flags = 0; .flags = 0,
pipeline_ci.layout = *layout; .stage =
pipeline_ci.basePipelineHandle = nullptr; {
pipeline_ci.basePipelineIndex = 0; .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = nullptr,
VkPipelineShaderStageCreateInfo& stage_ci = pipeline_ci.stage; .flags = 0,
stage_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; .stage = VK_SHADER_STAGE_COMPUTE_BIT,
stage_ci.pNext = nullptr; .module = *module,
stage_ci.flags = 0; .pName = "main",
stage_ci.stage = VK_SHADER_STAGE_COMPUTE_BIT; .pSpecializationInfo = nullptr,
stage_ci.module = *module; },
stage_ci.pName = "main"; .layout = *layout,
stage_ci.pSpecializationInfo = nullptr; .basePipelineHandle = nullptr,
.basePipelineIndex = 0,
pipeline = device.GetLogical().CreateComputePipeline(pipeline_ci); });
} }
VKComputePass::~VKComputePass() = default; VKComputePass::~VKComputePass() = default;