mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-26 18:15:43 +01:00
vk_graphics_pipeline: Make use of designated initializers where applicable
Avoids redundant variable name repetitions.
This commit is contained in:
parent
b2305dcee0
commit
0475a167f8
@ -28,15 +28,15 @@ namespace {
|
|||||||
|
|
||||||
template <class StencilFace>
|
template <class StencilFace>
|
||||||
VkStencilOpState GetStencilFaceState(const StencilFace& face) {
|
VkStencilOpState GetStencilFaceState(const StencilFace& face) {
|
||||||
VkStencilOpState state;
|
return {
|
||||||
state.failOp = MaxwellToVK::StencilOp(face.ActionStencilFail());
|
.failOp = MaxwellToVK::StencilOp(face.ActionStencilFail()),
|
||||||
state.passOp = MaxwellToVK::StencilOp(face.ActionDepthPass());
|
.passOp = MaxwellToVK::StencilOp(face.ActionDepthPass()),
|
||||||
state.depthFailOp = MaxwellToVK::StencilOp(face.ActionDepthFail());
|
.depthFailOp = MaxwellToVK::StencilOp(face.ActionDepthFail()),
|
||||||
state.compareOp = MaxwellToVK::ComparisonOp(face.TestFunc());
|
.compareOp = MaxwellToVK::ComparisonOp(face.TestFunc()),
|
||||||
state.compareMask = 0;
|
.compareMask = 0,
|
||||||
state.writeMask = 0;
|
.writeMask = 0,
|
||||||
state.reference = 0;
|
.reference = 0,
|
||||||
return state;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SupportsPrimitiveRestart(VkPrimitiveTopology topology) {
|
bool SupportsPrimitiveRestart(VkPrimitiveTopology topology) {
|
||||||
@ -52,20 +52,21 @@ bool SupportsPrimitiveRestart(VkPrimitiveTopology topology) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VkViewportSwizzleNV UnpackViewportSwizzle(u16 swizzle) {
|
VkViewportSwizzleNV UnpackViewportSwizzle(u16 swizzle) {
|
||||||
union {
|
union Swizzle {
|
||||||
u32 raw;
|
u32 raw;
|
||||||
BitField<0, 3, Maxwell::ViewportSwizzle> x;
|
BitField<0, 3, Maxwell::ViewportSwizzle> x;
|
||||||
BitField<4, 3, Maxwell::ViewportSwizzle> y;
|
BitField<4, 3, Maxwell::ViewportSwizzle> y;
|
||||||
BitField<8, 3, Maxwell::ViewportSwizzle> z;
|
BitField<8, 3, Maxwell::ViewportSwizzle> z;
|
||||||
BitField<12, 3, Maxwell::ViewportSwizzle> w;
|
BitField<12, 3, Maxwell::ViewportSwizzle> w;
|
||||||
} const unpacked{swizzle};
|
};
|
||||||
|
const Swizzle unpacked{swizzle};
|
||||||
|
|
||||||
VkViewportSwizzleNV result;
|
return {
|
||||||
result.x = MaxwellToVK::ViewportSwizzle(unpacked.x);
|
.x = MaxwellToVK::ViewportSwizzle(unpacked.x),
|
||||||
result.y = MaxwellToVK::ViewportSwizzle(unpacked.y);
|
.y = MaxwellToVK::ViewportSwizzle(unpacked.y),
|
||||||
result.z = MaxwellToVK::ViewportSwizzle(unpacked.z);
|
.z = MaxwellToVK::ViewportSwizzle(unpacked.z),
|
||||||
result.w = MaxwellToVK::ViewportSwizzle(unpacked.w);
|
.w = MaxwellToVK::ViewportSwizzle(unpacked.w),
|
||||||
return result;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
@ -100,24 +101,26 @@ VkDescriptorSet VKGraphicsPipeline::CommitDescriptorSet() {
|
|||||||
|
|
||||||
vk::DescriptorSetLayout VKGraphicsPipeline::CreateDescriptorSetLayout(
|
vk::DescriptorSetLayout VKGraphicsPipeline::CreateDescriptorSetLayout(
|
||||||
vk::Span<VkDescriptorSetLayoutBinding> bindings) const {
|
vk::Span<VkDescriptorSetLayoutBinding> bindings) const {
|
||||||
VkDescriptorSetLayoutCreateInfo ci;
|
const VkDescriptorSetLayoutCreateInfo ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
ci.bindingCount = bindings.size();
|
.bindingCount = bindings.size(),
|
||||||
ci.pBindings = bindings.data();
|
.pBindings = bindings.data(),
|
||||||
|
};
|
||||||
return device.GetLogical().CreateDescriptorSetLayout(ci);
|
return device.GetLogical().CreateDescriptorSetLayout(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::PipelineLayout VKGraphicsPipeline::CreatePipelineLayout() const {
|
vk::PipelineLayout VKGraphicsPipeline::CreatePipelineLayout() const {
|
||||||
VkPipelineLayoutCreateInfo ci;
|
const VkPipelineLayoutCreateInfo ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
ci.setLayoutCount = 1;
|
.setLayoutCount = 1,
|
||||||
ci.pSetLayouts = descriptor_set_layout.address();
|
.pSetLayouts = descriptor_set_layout.address(),
|
||||||
ci.pushConstantRangeCount = 0;
|
.pushConstantRangeCount = 0,
|
||||||
ci.pPushConstantRanges = nullptr;
|
.pPushConstantRanges = nullptr,
|
||||||
|
};
|
||||||
return device.GetLogical().CreatePipelineLayout(ci);
|
return device.GetLogical().CreatePipelineLayout(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,26 +139,28 @@ vk::DescriptorUpdateTemplateKHR VKGraphicsPipeline::CreateDescriptorUpdateTempla
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
VkDescriptorUpdateTemplateCreateInfoKHR ci;
|
const VkDescriptorUpdateTemplateCreateInfoKHR ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR;
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO_KHR,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
ci.descriptorUpdateEntryCount = static_cast<u32>(template_entries.size());
|
.descriptorUpdateEntryCount = static_cast<u32>(template_entries.size()),
|
||||||
ci.pDescriptorUpdateEntries = template_entries.data();
|
.pDescriptorUpdateEntries = template_entries.data(),
|
||||||
ci.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR;
|
.templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR,
|
||||||
ci.descriptorSetLayout = *descriptor_set_layout;
|
.descriptorSetLayout = *descriptor_set_layout,
|
||||||
ci.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||||
ci.pipelineLayout = *layout;
|
.pipelineLayout = *layout,
|
||||||
ci.set = DESCRIPTOR_SET;
|
.set = DESCRIPTOR_SET,
|
||||||
|
};
|
||||||
return device.GetLogical().CreateDescriptorUpdateTemplateKHR(ci);
|
return device.GetLogical().CreateDescriptorUpdateTemplateKHR(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<vk::ShaderModule> VKGraphicsPipeline::CreateShaderModules(
|
std::vector<vk::ShaderModule> VKGraphicsPipeline::CreateShaderModules(
|
||||||
const SPIRVProgram& program) const {
|
const SPIRVProgram& program) const {
|
||||||
VkShaderModuleCreateInfo ci;
|
VkShaderModuleCreateInfo ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<vk::ShaderModule> modules;
|
std::vector<vk::ShaderModule> modules;
|
||||||
modules.reserve(Maxwell::MaxShaderStage);
|
modules.reserve(Maxwell::MaxShaderStage);
|
||||||
@ -204,15 +209,17 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
const bool instanced = state.binding_divisors[index] != 0;
|
const bool instanced = state.binding_divisors[index] != 0;
|
||||||
const auto rate = instanced ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX;
|
const auto rate = instanced ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX;
|
||||||
|
|
||||||
auto& vertex_binding = vertex_bindings.emplace_back();
|
vertex_bindings.push_back({
|
||||||
vertex_binding.binding = static_cast<u32>(index);
|
.binding = static_cast<u32>(index),
|
||||||
vertex_binding.stride = binding.stride;
|
.stride = binding.stride,
|
||||||
vertex_binding.inputRate = rate;
|
.inputRate = rate,
|
||||||
|
});
|
||||||
|
|
||||||
if (instanced) {
|
if (instanced) {
|
||||||
auto& binding_divisor = vertex_binding_divisors.emplace_back();
|
vertex_binding_divisors.push_back({
|
||||||
binding_divisor.binding = static_cast<u32>(index);
|
.binding = static_cast<u32>(index),
|
||||||
binding_divisor.divisor = state.binding_divisors[index];
|
.divisor = state.binding_divisors[index],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,116 +234,130 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
// Skip attributes not used by the vertex shaders.
|
// Skip attributes not used by the vertex shaders.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& vertex_attribute = vertex_attributes.emplace_back();
|
vertex_attributes.push_back({
|
||||||
vertex_attribute.location = static_cast<u32>(index);
|
.location = static_cast<u32>(index),
|
||||||
vertex_attribute.binding = attribute.buffer;
|
.binding = attribute.buffer,
|
||||||
vertex_attribute.format = MaxwellToVK::VertexFormat(attribute.Type(), attribute.Size());
|
.format = MaxwellToVK::VertexFormat(attribute.Type(), attribute.Size()),
|
||||||
vertex_attribute.offset = attribute.offset;
|
.offset = attribute.offset,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineVertexInputStateCreateInfo vertex_input_ci;
|
VkPipelineVertexInputStateCreateInfo vertex_input_ci{
|
||||||
vertex_input_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
||||||
vertex_input_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
vertex_input_ci.flags = 0;
|
.flags = 0,
|
||||||
vertex_input_ci.vertexBindingDescriptionCount = static_cast<u32>(vertex_bindings.size());
|
.vertexBindingDescriptionCount = static_cast<u32>(vertex_bindings.size()),
|
||||||
vertex_input_ci.pVertexBindingDescriptions = vertex_bindings.data();
|
.pVertexBindingDescriptions = vertex_bindings.data(),
|
||||||
vertex_input_ci.vertexAttributeDescriptionCount = static_cast<u32>(vertex_attributes.size());
|
.vertexAttributeDescriptionCount = static_cast<u32>(vertex_attributes.size()),
|
||||||
vertex_input_ci.pVertexAttributeDescriptions = vertex_attributes.data();
|
.pVertexAttributeDescriptions = vertex_attributes.data(),
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineVertexInputDivisorStateCreateInfoEXT input_divisor_ci;
|
const VkPipelineVertexInputDivisorStateCreateInfoEXT input_divisor_ci{
|
||||||
input_divisor_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT,
|
||||||
input_divisor_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
input_divisor_ci.vertexBindingDivisorCount = static_cast<u32>(vertex_binding_divisors.size());
|
.vertexBindingDivisorCount = static_cast<u32>(vertex_binding_divisors.size()),
|
||||||
input_divisor_ci.pVertexBindingDivisors = vertex_binding_divisors.data();
|
.pVertexBindingDivisors = vertex_binding_divisors.data(),
|
||||||
|
};
|
||||||
if (!vertex_binding_divisors.empty()) {
|
if (!vertex_binding_divisors.empty()) {
|
||||||
vertex_input_ci.pNext = &input_divisor_ci;
|
vertex_input_ci.pNext = &input_divisor_ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineInputAssemblyStateCreateInfo input_assembly_ci;
|
const auto input_assembly_topology = MaxwellToVK::PrimitiveTopology(device, dynamic.Topology());
|
||||||
input_assembly_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
|
const VkPipelineInputAssemblyStateCreateInfo input_assembly_ci{
|
||||||
input_assembly_ci.pNext = nullptr;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
||||||
input_assembly_ci.flags = 0;
|
.pNext = nullptr,
|
||||||
input_assembly_ci.topology = MaxwellToVK::PrimitiveTopology(device, dynamic.Topology());
|
.flags = 0,
|
||||||
input_assembly_ci.primitiveRestartEnable =
|
.topology = MaxwellToVK::PrimitiveTopology(device, dynamic.Topology()),
|
||||||
state.primitive_restart_enable != 0 && SupportsPrimitiveRestart(input_assembly_ci.topology);
|
.primitiveRestartEnable = state.primitive_restart_enable != 0 &&
|
||||||
|
SupportsPrimitiveRestart(input_assembly_topology),
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineTessellationStateCreateInfo tessellation_ci;
|
const VkPipelineTessellationStateCreateInfo tessellation_ci{
|
||||||
tessellation_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO,
|
||||||
tessellation_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
tessellation_ci.flags = 0;
|
.flags = 0,
|
||||||
tessellation_ci.patchControlPoints = state.patch_control_points_minus_one.Value() + 1;
|
.patchControlPoints = state.patch_control_points_minus_one.Value() + 1,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineViewportStateCreateInfo viewport_ci;
|
VkPipelineViewportStateCreateInfo viewport_ci{
|
||||||
viewport_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
||||||
viewport_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
viewport_ci.flags = 0;
|
.flags = 0,
|
||||||
viewport_ci.viewportCount = Maxwell::NumViewports;
|
.viewportCount = Maxwell::NumViewports,
|
||||||
viewport_ci.pViewports = nullptr;
|
.pViewports = nullptr,
|
||||||
viewport_ci.scissorCount = Maxwell::NumViewports;
|
.scissorCount = Maxwell::NumViewports,
|
||||||
viewport_ci.pScissors = nullptr;
|
.pScissors = nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
std::array<VkViewportSwizzleNV, Maxwell::NumViewports> swizzles;
|
std::array<VkViewportSwizzleNV, Maxwell::NumViewports> swizzles;
|
||||||
std::transform(viewport_swizzles.begin(), viewport_swizzles.end(), swizzles.begin(),
|
std::transform(viewport_swizzles.begin(), viewport_swizzles.end(), swizzles.begin(),
|
||||||
UnpackViewportSwizzle);
|
UnpackViewportSwizzle);
|
||||||
VkPipelineViewportSwizzleStateCreateInfoNV swizzle_ci;
|
VkPipelineViewportSwizzleStateCreateInfoNV swizzle_ci{
|
||||||
swizzle_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
|
||||||
swizzle_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
swizzle_ci.flags = 0;
|
.flags = 0,
|
||||||
swizzle_ci.viewportCount = Maxwell::NumViewports;
|
.viewportCount = Maxwell::NumViewports,
|
||||||
swizzle_ci.pViewportSwizzles = swizzles.data();
|
.pViewportSwizzles = swizzles.data(),
|
||||||
|
};
|
||||||
if (device.IsNvViewportSwizzleSupported()) {
|
if (device.IsNvViewportSwizzleSupported()) {
|
||||||
viewport_ci.pNext = &swizzle_ci;
|
viewport_ci.pNext = &swizzle_ci;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineRasterizationStateCreateInfo rasterization_ci;
|
const VkPipelineRasterizationStateCreateInfo rasterization_ci{
|
||||||
rasterization_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
||||||
rasterization_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
rasterization_ci.flags = 0;
|
.flags = 0,
|
||||||
rasterization_ci.depthClampEnable = state.depth_clamp_disabled == 0 ? VK_TRUE : VK_FALSE;
|
.depthClampEnable = state.depth_clamp_disabled == 0 ? VK_TRUE : VK_FALSE,
|
||||||
rasterization_ci.rasterizerDiscardEnable = state.rasterize_enable == 0 ? VK_TRUE : VK_FALSE;
|
.rasterizerDiscardEnable = state.rasterize_enable == 0 ? VK_TRUE : VK_FALSE,
|
||||||
rasterization_ci.polygonMode = VK_POLYGON_MODE_FILL;
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
||||||
rasterization_ci.cullMode =
|
.cullMode =
|
||||||
dynamic.cull_enable ? MaxwellToVK::CullFace(dynamic.CullFace()) : VK_CULL_MODE_NONE;
|
dynamic.cull_enable ? MaxwellToVK::CullFace(dynamic.CullFace()) : VK_CULL_MODE_NONE,
|
||||||
rasterization_ci.frontFace = MaxwellToVK::FrontFace(dynamic.FrontFace());
|
.frontFace = MaxwellToVK::FrontFace(dynamic.FrontFace()),
|
||||||
rasterization_ci.depthBiasEnable = state.depth_bias_enable;
|
.depthBiasEnable = state.depth_bias_enable,
|
||||||
rasterization_ci.depthBiasConstantFactor = 0.0f;
|
.depthBiasConstantFactor = 0.0f,
|
||||||
rasterization_ci.depthBiasClamp = 0.0f;
|
.depthBiasClamp = 0.0f,
|
||||||
rasterization_ci.depthBiasSlopeFactor = 0.0f;
|
.depthBiasSlopeFactor = 0.0f,
|
||||||
rasterization_ci.lineWidth = 1.0f;
|
.lineWidth = 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineMultisampleStateCreateInfo multisample_ci;
|
const VkPipelineMultisampleStateCreateInfo multisample_ci{
|
||||||
multisample_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
||||||
multisample_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
multisample_ci.flags = 0;
|
.flags = 0,
|
||||||
multisample_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
|
.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
multisample_ci.sampleShadingEnable = VK_FALSE;
|
.sampleShadingEnable = VK_FALSE,
|
||||||
multisample_ci.minSampleShading = 0.0f;
|
.minSampleShading = 0.0f,
|
||||||
multisample_ci.pSampleMask = nullptr;
|
.pSampleMask = nullptr,
|
||||||
multisample_ci.alphaToCoverageEnable = VK_FALSE;
|
.alphaToCoverageEnable = VK_FALSE,
|
||||||
multisample_ci.alphaToOneEnable = VK_FALSE;
|
.alphaToOneEnable = VK_FALSE,
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineDepthStencilStateCreateInfo depth_stencil_ci;
|
const VkPipelineDepthStencilStateCreateInfo depth_stencil_ci{
|
||||||
depth_stencil_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO,
|
||||||
depth_stencil_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
depth_stencil_ci.flags = 0;
|
.flags = 0,
|
||||||
depth_stencil_ci.depthTestEnable = dynamic.depth_test_enable;
|
.depthTestEnable = dynamic.depth_test_enable,
|
||||||
depth_stencil_ci.depthWriteEnable = dynamic.depth_write_enable;
|
.depthWriteEnable = dynamic.depth_write_enable,
|
||||||
depth_stencil_ci.depthCompareOp = dynamic.depth_test_enable
|
.depthCompareOp = dynamic.depth_test_enable
|
||||||
? MaxwellToVK::ComparisonOp(dynamic.DepthTestFunc())
|
? MaxwellToVK::ComparisonOp(dynamic.DepthTestFunc())
|
||||||
: VK_COMPARE_OP_ALWAYS;
|
: VK_COMPARE_OP_ALWAYS,
|
||||||
depth_stencil_ci.depthBoundsTestEnable = dynamic.depth_bounds_enable;
|
.depthBoundsTestEnable = dynamic.depth_bounds_enable,
|
||||||
depth_stencil_ci.stencilTestEnable = dynamic.stencil_enable;
|
.stencilTestEnable = dynamic.stencil_enable,
|
||||||
depth_stencil_ci.front = GetStencilFaceState(dynamic.front);
|
.front = GetStencilFaceState(dynamic.front),
|
||||||
depth_stencil_ci.back = GetStencilFaceState(dynamic.back);
|
.back = GetStencilFaceState(dynamic.back),
|
||||||
depth_stencil_ci.minDepthBounds = 0.0f;
|
.minDepthBounds = 0.0f,
|
||||||
depth_stencil_ci.maxDepthBounds = 0.0f;
|
.maxDepthBounds = 0.0f,
|
||||||
|
};
|
||||||
|
|
||||||
std::array<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments;
|
std::array<VkPipelineColorBlendAttachmentState, Maxwell::NumRenderTargets> cb_attachments;
|
||||||
const auto num_attachments = static_cast<std::size_t>(renderpass_params.num_color_attachments);
|
const auto num_attachments = static_cast<std::size_t>(renderpass_params.num_color_attachments);
|
||||||
for (std::size_t index = 0; index < num_attachments; ++index) {
|
for (std::size_t index = 0; index < num_attachments; ++index) {
|
||||||
static constexpr std::array COMPONENT_TABLE = {
|
static constexpr std::array COMPONENT_TABLE{
|
||||||
VK_COLOR_COMPONENT_R_BIT, VK_COLOR_COMPONENT_G_BIT, VK_COLOR_COMPONENT_B_BIT,
|
VK_COLOR_COMPONENT_R_BIT,
|
||||||
VK_COLOR_COMPONENT_A_BIT};
|
VK_COLOR_COMPONENT_G_BIT,
|
||||||
|
VK_COLOR_COMPONENT_B_BIT,
|
||||||
|
VK_COLOR_COMPONENT_A_BIT,
|
||||||
|
};
|
||||||
const auto& blend = state.attachments[index];
|
const auto& blend = state.attachments[index];
|
||||||
|
|
||||||
VkColorComponentFlags color_components = 0;
|
VkColorComponentFlags color_components = 0;
|
||||||
@ -346,35 +367,36 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineColorBlendAttachmentState& attachment = cb_attachments[index];
|
cb_attachments[index] = {
|
||||||
attachment.blendEnable = blend.enable != 0;
|
.blendEnable = blend.enable != 0,
|
||||||
attachment.srcColorBlendFactor = MaxwellToVK::BlendFactor(blend.SourceRGBFactor());
|
.srcColorBlendFactor = MaxwellToVK::BlendFactor(blend.SourceRGBFactor()),
|
||||||
attachment.dstColorBlendFactor = MaxwellToVK::BlendFactor(blend.DestRGBFactor());
|
.dstColorBlendFactor = MaxwellToVK::BlendFactor(blend.DestRGBFactor()),
|
||||||
attachment.colorBlendOp = MaxwellToVK::BlendEquation(blend.EquationRGB());
|
.colorBlendOp = MaxwellToVK::BlendEquation(blend.EquationRGB()),
|
||||||
attachment.srcAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.SourceAlphaFactor());
|
.srcAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.SourceAlphaFactor()),
|
||||||
attachment.dstAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.DestAlphaFactor());
|
.dstAlphaBlendFactor = MaxwellToVK::BlendFactor(blend.DestAlphaFactor()),
|
||||||
attachment.alphaBlendOp = MaxwellToVK::BlendEquation(blend.EquationAlpha());
|
.alphaBlendOp = MaxwellToVK::BlendEquation(blend.EquationAlpha()),
|
||||||
attachment.colorWriteMask = color_components;
|
.colorWriteMask = color_components,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineColorBlendStateCreateInfo color_blend_ci;
|
const VkPipelineColorBlendStateCreateInfo color_blend_ci{
|
||||||
color_blend_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
||||||
color_blend_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
color_blend_ci.flags = 0;
|
.flags = 0,
|
||||||
color_blend_ci.logicOpEnable = VK_FALSE;
|
.logicOpEnable = VK_FALSE,
|
||||||
color_blend_ci.logicOp = VK_LOGIC_OP_COPY;
|
.logicOp = VK_LOGIC_OP_COPY,
|
||||||
color_blend_ci.attachmentCount = static_cast<u32>(num_attachments);
|
.attachmentCount = static_cast<u32>(num_attachments),
|
||||||
color_blend_ci.pAttachments = cb_attachments.data();
|
.pAttachments = cb_attachments.data(),
|
||||||
std::memset(color_blend_ci.blendConstants, 0, sizeof(color_blend_ci.blendConstants));
|
};
|
||||||
|
|
||||||
std::vector dynamic_states = {
|
std::vector dynamic_states{
|
||||||
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR,
|
VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR,
|
||||||
VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_BLEND_CONSTANTS,
|
VK_DYNAMIC_STATE_DEPTH_BIAS, VK_DYNAMIC_STATE_BLEND_CONSTANTS,
|
||||||
VK_DYNAMIC_STATE_DEPTH_BOUNDS, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
|
VK_DYNAMIC_STATE_DEPTH_BOUNDS, VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK,
|
||||||
VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, VK_DYNAMIC_STATE_STENCIL_REFERENCE,
|
VK_DYNAMIC_STATE_STENCIL_WRITE_MASK, VK_DYNAMIC_STATE_STENCIL_REFERENCE,
|
||||||
};
|
};
|
||||||
if (device.IsExtExtendedDynamicStateSupported()) {
|
if (device.IsExtExtendedDynamicStateSupported()) {
|
||||||
static constexpr std::array extended = {
|
static constexpr std::array extended{
|
||||||
VK_DYNAMIC_STATE_CULL_MODE_EXT,
|
VK_DYNAMIC_STATE_CULL_MODE_EXT,
|
||||||
VK_DYNAMIC_STATE_FRONT_FACE_EXT,
|
VK_DYNAMIC_STATE_FRONT_FACE_EXT,
|
||||||
VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT,
|
VK_DYNAMIC_STATE_PRIMITIVE_TOPOLOGY_EXT,
|
||||||
@ -389,18 +411,19 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
dynamic_states.insert(dynamic_states.end(), extended.begin(), extended.end());
|
dynamic_states.insert(dynamic_states.end(), extended.begin(), extended.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineDynamicStateCreateInfo dynamic_state_ci;
|
const VkPipelineDynamicStateCreateInfo dynamic_state_ci{
|
||||||
dynamic_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||||
dynamic_state_ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
dynamic_state_ci.flags = 0;
|
.flags = 0,
|
||||||
dynamic_state_ci.dynamicStateCount = static_cast<u32>(dynamic_states.size());
|
.dynamicStateCount = static_cast<u32>(dynamic_states.size()),
|
||||||
dynamic_state_ci.pDynamicStates = dynamic_states.data();
|
.pDynamicStates = dynamic_states.data(),
|
||||||
|
};
|
||||||
|
|
||||||
VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroup_size_ci;
|
const VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT subgroup_size_ci{
|
||||||
subgroup_size_ci.sType =
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT,
|
||||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_REQUIRED_SUBGROUP_SIZE_CREATE_INFO_EXT;
|
.pNext = nullptr,
|
||||||
subgroup_size_ci.pNext = nullptr;
|
.requiredSubgroupSize = GuestWarpSize,
|
||||||
subgroup_size_ci.requiredSubgroupSize = GuestWarpSize;
|
};
|
||||||
|
|
||||||
std::vector<VkPipelineShaderStageCreateInfo> shader_stages;
|
std::vector<VkPipelineShaderStageCreateInfo> shader_stages;
|
||||||
std::size_t module_index = 0;
|
std::size_t module_index = 0;
|
||||||
@ -408,6 +431,7 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
if (!program[stage]) {
|
if (!program[stage]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo& stage_ci = shader_stages.emplace_back();
|
VkPipelineShaderStageCreateInfo& stage_ci = shader_stages.emplace_back();
|
||||||
stage_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
stage_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
||||||
stage_ci.pNext = nullptr;
|
stage_ci.pNext = nullptr;
|
||||||
@ -422,26 +446,27 @@ vk::Pipeline VKGraphicsPipeline::CreatePipeline(const RenderPassParams& renderpa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VkGraphicsPipelineCreateInfo ci;
|
const VkGraphicsPipelineCreateInfo ci{
|
||||||
ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||||
ci.pNext = nullptr;
|
.pNext = nullptr,
|
||||||
ci.flags = 0;
|
.flags = 0,
|
||||||
ci.stageCount = static_cast<u32>(shader_stages.size());
|
.stageCount = static_cast<u32>(shader_stages.size()),
|
||||||
ci.pStages = shader_stages.data();
|
.pStages = shader_stages.data(),
|
||||||
ci.pVertexInputState = &vertex_input_ci;
|
.pVertexInputState = &vertex_input_ci,
|
||||||
ci.pInputAssemblyState = &input_assembly_ci;
|
.pInputAssemblyState = &input_assembly_ci,
|
||||||
ci.pTessellationState = &tessellation_ci;
|
.pTessellationState = &tessellation_ci,
|
||||||
ci.pViewportState = &viewport_ci;
|
.pViewportState = &viewport_ci,
|
||||||
ci.pRasterizationState = &rasterization_ci;
|
.pRasterizationState = &rasterization_ci,
|
||||||
ci.pMultisampleState = &multisample_ci;
|
.pMultisampleState = &multisample_ci,
|
||||||
ci.pDepthStencilState = &depth_stencil_ci;
|
.pDepthStencilState = &depth_stencil_ci,
|
||||||
ci.pColorBlendState = &color_blend_ci;
|
.pColorBlendState = &color_blend_ci,
|
||||||
ci.pDynamicState = &dynamic_state_ci;
|
.pDynamicState = &dynamic_state_ci,
|
||||||
ci.layout = *layout;
|
.layout = *layout,
|
||||||
ci.renderPass = renderpass;
|
.renderPass = renderpass,
|
||||||
ci.subpass = 0;
|
.subpass = 0,
|
||||||
ci.basePipelineHandle = nullptr;
|
.basePipelineHandle = nullptr,
|
||||||
ci.basePipelineIndex = 0;
|
.basePipelineIndex = 0,
|
||||||
|
};
|
||||||
return device.GetLogical().CreateGraphicsPipeline(ci);
|
return device.GetLogical().CreateGraphicsPipeline(ci);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user