renderer_vulkan: Restore Vulkan version to 1.3 (#2827)

Co-authored-by: georgemoralis <giorgosmrls@gmail.com>
This commit is contained in:
squidbus 2025-04-23 03:28:31 -07:00 committed by GitHub
parent 5db162cbcd
commit aeee7706ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 55 additions and 75 deletions

View file

@ -335,8 +335,7 @@ void DefineEntryPoint(const Info& info, EmitContext& ctx, Id main) {
ctx.AddExecutionMode(main, spv::ExecutionMode::OriginUpperLeft); ctx.AddExecutionMode(main, spv::ExecutionMode::OriginUpperLeft);
} }
if (info.has_discard) { if (info.has_discard) {
ctx.AddExtension("SPV_EXT_demote_to_helper_invocation"); ctx.AddCapability(spv::Capability::DemoteToHelperInvocation);
ctx.AddCapability(spv::Capability::DemoteToHelperInvocationEXT);
} }
if (info.stores.GetAny(IR::Attribute::Depth)) { if (info.stores.GetAny(IR::Attribute::Depth)) {
ctx.AddExecutionMode(main, spv::ExecutionMode::DepthReplacing); ctx.AddExecutionMode(main, spv::ExecutionMode::DepthReplacing);

View file

@ -78,7 +78,7 @@ void PostProcessingPass::Create(vk::Device device) {
const std::array pp_color_formats{ const std::array pp_color_formats{
vk::Format::eB8G8R8A8Unorm, // swapchain.GetSurfaceFormat().format, vk::Format::eB8G8R8A8Unorm, // swapchain.GetSurfaceFormat().format,
}; };
const vk::PipelineRenderingCreateInfoKHR pipeline_rendering_ci{ const vk::PipelineRenderingCreateInfo pipeline_rendering_ci{
.colorAttachmentCount = pp_color_formats.size(), .colorAttachmentCount = pp_color_formats.size(),
.pColorAttachmentFormats = pp_color_formats.data(), .pColorAttachmentFormats = pp_color_formats.data(),
}; };

View file

@ -122,21 +122,21 @@ GraphicsPipeline::GraphicsPipeline(
}; };
boost::container::static_vector<vk::DynamicState, 20> dynamic_states = { boost::container::static_vector<vk::DynamicState, 20> dynamic_states = {
vk::DynamicState::eViewportWithCountEXT, vk::DynamicState::eScissorWithCountEXT, vk::DynamicState::eViewportWithCount, vk::DynamicState::eScissorWithCount,
vk::DynamicState::eBlendConstants, vk::DynamicState::eDepthTestEnableEXT, vk::DynamicState::eBlendConstants, vk::DynamicState::eDepthTestEnable,
vk::DynamicState::eDepthWriteEnableEXT, vk::DynamicState::eDepthCompareOpEXT, vk::DynamicState::eDepthWriteEnable, vk::DynamicState::eDepthCompareOp,
vk::DynamicState::eDepthBiasEnableEXT, vk::DynamicState::eDepthBias, vk::DynamicState::eDepthBiasEnable, vk::DynamicState::eDepthBias,
vk::DynamicState::eStencilTestEnableEXT, vk::DynamicState::eStencilReference, vk::DynamicState::eStencilTestEnable, vk::DynamicState::eStencilReference,
vk::DynamicState::eStencilCompareMask, vk::DynamicState::eStencilWriteMask, vk::DynamicState::eStencilCompareMask, vk::DynamicState::eStencilWriteMask,
vk::DynamicState::eStencilOpEXT, vk::DynamicState::eCullModeEXT, vk::DynamicState::eStencilOp, vk::DynamicState::eCullMode,
vk::DynamicState::eFrontFaceEXT, vk::DynamicState::eFrontFace,
}; };
if (instance.IsPrimitiveRestartDisableSupported()) { if (instance.IsPrimitiveRestartDisableSupported()) {
dynamic_states.push_back(vk::DynamicState::ePrimitiveRestartEnableEXT); dynamic_states.push_back(vk::DynamicState::ePrimitiveRestartEnable);
} }
if (instance.IsDepthBoundsSupported()) { if (instance.IsDepthBoundsSupported()) {
dynamic_states.push_back(vk::DynamicState::eDepthBoundsTestEnableEXT); dynamic_states.push_back(vk::DynamicState::eDepthBoundsTestEnable);
dynamic_states.push_back(vk::DynamicState::eDepthBounds); dynamic_states.push_back(vk::DynamicState::eDepthBounds);
} }
if (instance.IsDynamicColorWriteMaskSupported()) { if (instance.IsDynamicColorWriteMaskSupported()) {
@ -145,7 +145,7 @@ GraphicsPipeline::GraphicsPipeline(
if (instance.IsVertexInputDynamicState()) { if (instance.IsVertexInputDynamicState()) {
dynamic_states.push_back(vk::DynamicState::eVertexInputEXT); dynamic_states.push_back(vk::DynamicState::eVertexInputEXT);
} else if (!vertex_bindings.empty()) { } else if (!vertex_bindings.empty()) {
dynamic_states.push_back(vk::DynamicState::eVertexInputBindingStrideEXT); dynamic_states.push_back(vk::DynamicState::eVertexInputBindingStride);
} }
const vk::PipelineDynamicStateCreateInfo dynamic_info = { const vk::PipelineDynamicStateCreateInfo dynamic_info = {
@ -212,7 +212,7 @@ GraphicsPipeline::GraphicsPipeline(
}); });
} }
const vk::PipelineRenderingCreateInfoKHR pipeline_rendering_ci = { const vk::PipelineRenderingCreateInfo pipeline_rendering_ci = {
.colorAttachmentCount = key.num_color_attachments, .colorAttachmentCount = key.num_color_attachments,
.pColorAttachmentFormats = key.color_formats.data(), .pColorAttachmentFormats = key.color_formats.data(),
.depthAttachmentFormat = key.depth_format, .depthAttachmentFormat = key.depth_format,

View file

@ -203,12 +203,14 @@ std::string Instance::GetDriverVersionName() {
} }
bool Instance::CreateDevice() { bool Instance::CreateDevice() {
const vk::StructureChain feature_chain = physical_device.getFeatures2< const vk::StructureChain feature_chain =
vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features, physical_device
vk::PhysicalDeviceVulkan12Features, vk::PhysicalDeviceRobustness2FeaturesEXT, .getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan11Features,
vk::PhysicalDeviceExtendedDynamicState3FeaturesEXT, vk::PhysicalDeviceVulkan12Features, vk::PhysicalDeviceVulkan13Features,
vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT, vk::PhysicalDeviceRobustness2FeaturesEXT,
vk::PhysicalDevicePortabilitySubsetFeaturesKHR>(); vk::PhysicalDeviceExtendedDynamicState3FeaturesEXT,
vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT,
vk::PhysicalDevicePortabilitySubsetFeaturesKHR>();
features = feature_chain.get().features; features = feature_chain.get().features;
const vk::StructureChain properties_chain = physical_device.getProperties2< const vk::StructureChain properties_chain = physical_device.getProperties2<
@ -240,18 +242,6 @@ bool Instance::CreateDevice() {
return false; return false;
}; };
// These extensions are promoted by Vulkan 1.3, but for greater compatibility we use Vulkan 1.2
// with extensions.
ASSERT(add_extension(VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME));
ASSERT(add_extension(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME));
ASSERT(add_extension(VK_EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION_EXTENSION_NAME));
ASSERT(add_extension(VK_KHR_SYNCHRONIZATION_2_EXTENSION_NAME));
ASSERT(add_extension(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME));
ASSERT(add_extension(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME));
ASSERT(add_extension(VK_EXT_TOOLING_INFO_EXTENSION_NAME) ||
driver_id == vk::DriverId::eIntelProprietaryWindows);
ASSERT(add_extension(VK_KHR_MAINTENANCE_4_EXTENSION_NAME));
// Required // Required
ASSERT(add_extension(VK_KHR_SWAPCHAIN_EXTENSION_NAME)); ASSERT(add_extension(VK_KHR_SWAPCHAIN_EXTENSION_NAME));
ASSERT(add_extension(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME)); ASSERT(add_extension(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME));
@ -324,6 +314,7 @@ bool Instance::CreateDevice() {
feature_chain.get<vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>(); feature_chain.get<vk::PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT>();
const auto vk11_features = feature_chain.get<vk::PhysicalDeviceVulkan11Features>(); const auto vk11_features = feature_chain.get<vk::PhysicalDeviceVulkan11Features>();
const auto vk12_features = feature_chain.get<vk::PhysicalDeviceVulkan12Features>(); const auto vk12_features = feature_chain.get<vk::PhysicalDeviceVulkan12Features>();
const auto vk13_features = feature_chain.get<vk::PhysicalDeviceVulkan13Features>();
vk::StructureChain device_chain = { vk::StructureChain device_chain = {
vk::DeviceCreateInfo{ vk::DeviceCreateInfo{
.queueCreateInfoCount = 1u, .queueCreateInfoCount = 1u,
@ -372,26 +363,14 @@ bool Instance::CreateDevice() {
.hostQueryReset = vk12_features.hostQueryReset, .hostQueryReset = vk12_features.hostQueryReset,
.timelineSemaphore = vk12_features.timelineSemaphore, .timelineSemaphore = vk12_features.timelineSemaphore,
}, },
// Vulkan 1.3 promoted extensions vk::PhysicalDeviceVulkan13Features{
vk::PhysicalDeviceDynamicRenderingFeaturesKHR{ .robustImageAccess = vk13_features.robustImageAccess,
.dynamicRendering = true, .shaderDemoteToHelperInvocation = vk13_features.shaderDemoteToHelperInvocation,
.synchronization2 = vk13_features.synchronization2,
.dynamicRendering = vk13_features.dynamicRendering,
.maintenance4 = vk13_features.maintenance4,
}, },
vk::PhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT{ // Extensions
.shaderDemoteToHelperInvocation = true,
},
vk::PhysicalDeviceSynchronization2Features{
.synchronization2 = true,
},
vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT{
.extendedDynamicState = true,
},
vk::PhysicalDeviceExtendedDynamicState2FeaturesEXT{
.extendedDynamicState2 = true,
},
vk::PhysicalDeviceMaintenance4FeaturesKHR{
.maintenance4 = true,
},
// Other extensions
vk::PhysicalDeviceCustomBorderColorFeaturesEXT{ vk::PhysicalDeviceCustomBorderColorFeaturesEXT{
.customBorderColors = true, .customBorderColors = true,
.customBorderColorWithoutFormat = true, .customBorderColorWithoutFormat = true,
@ -547,7 +526,7 @@ void Instance::CollectToolingInfo() {
// Currently causes issues with Reshade on AMD proprietary, disabled until fix released. // Currently causes issues with Reshade on AMD proprietary, disabled until fix released.
return; return;
} }
const auto [tools_result, tools] = physical_device.getToolPropertiesEXT(); const auto [tools_result, tools] = physical_device.getToolProperties();
if (tools_result != vk::Result::eSuccess) { if (tools_result != vk::Result::eSuccess) {
LOG_ERROR(Render_Vulkan, "Could not get Vulkan tool properties: {}", LOG_ERROR(Render_Vulkan, "Could not get Vulkan tool properties: {}",
vk::to_string(tools_result)); vk::to_string(tools_result));

View file

@ -26,6 +26,8 @@ using Shader::LogicalStage;
using Shader::Stage; using Shader::Stage;
using Shader::VsOutput; using Shader::VsOutput;
constexpr static auto SpirvVersion1_6 = 0x00010600U;
constexpr static std::array DescriptorHeapSizes = { constexpr static std::array DescriptorHeapSizes = {
vk::DescriptorPoolSize{vk::DescriptorType::eUniformBuffer, 8192}, vk::DescriptorPoolSize{vk::DescriptorType::eUniformBuffer, 8192},
vk::DescriptorPoolSize{vk::DescriptorType::eStorageBuffer, 1024}, vk::DescriptorPoolSize{vk::DescriptorType::eStorageBuffer, 1024},
@ -192,7 +194,7 @@ PipelineCache::PipelineCache(const Instance& instance_, Scheduler& scheduler_,
desc_heap{instance, scheduler.GetMasterSemaphore(), DescriptorHeapSizes} { desc_heap{instance, scheduler.GetMasterSemaphore(), DescriptorHeapSizes} {
const auto& vk12_props = instance.GetVk12Properties(); const auto& vk12_props = instance.GetVk12Properties();
profile = Shader::Profile{ profile = Shader::Profile{
.supported_spirv = instance.ApiVersion() >= VK_API_VERSION_1_3 ? 0x00010600U : 0x00010500U, .supported_spirv = SpirvVersion1_6,
.subgroup_size = instance.SubgroupSize(), .subgroup_size = instance.SubgroupSize(),
.support_fp32_denorm_preserve = bool(vk12_props.shaderDenormPreserveFloat32), .support_fp32_denorm_preserve = bool(vk12_props.shaderDenormPreserveFloat32),
.support_fp32_denorm_flush = bool(vk12_props.shaderDenormFlushToZeroFloat32), .support_fp32_denorm_flush = bool(vk12_props.shaderDenormFlushToZeroFloat32),

View file

@ -18,7 +18,7 @@ class WindowSDL;
namespace Vulkan { namespace Vulkan {
constexpr u32 TargetVulkanApiVersion = VK_API_VERSION_1_2; constexpr u32 TargetVulkanApiVersion = VK_API_VERSION_1_3;
vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& emu_window); vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& emu_window);

View file

@ -170,29 +170,29 @@ void Scheduler::SubmitExecution(SubmitInfo& info) {
void DynamicState::Commit(const Instance& instance, const vk::CommandBuffer& cmdbuf) { void DynamicState::Commit(const Instance& instance, const vk::CommandBuffer& cmdbuf) {
if (dirty_state.viewports) { if (dirty_state.viewports) {
dirty_state.viewports = false; dirty_state.viewports = false;
cmdbuf.setViewportWithCountEXT(viewports); cmdbuf.setViewportWithCount(viewports);
} }
if (dirty_state.scissors) { if (dirty_state.scissors) {
dirty_state.scissors = false; dirty_state.scissors = false;
cmdbuf.setScissorWithCountEXT(scissors); cmdbuf.setScissorWithCount(scissors);
} }
if (dirty_state.depth_test_enabled) { if (dirty_state.depth_test_enabled) {
dirty_state.depth_test_enabled = false; dirty_state.depth_test_enabled = false;
cmdbuf.setDepthTestEnableEXT(depth_test_enabled); cmdbuf.setDepthTestEnable(depth_test_enabled);
} }
if (dirty_state.depth_write_enabled) { if (dirty_state.depth_write_enabled) {
dirty_state.depth_write_enabled = false; dirty_state.depth_write_enabled = false;
// Note that this must be set in a command buffer even if depth test is disabled. // Note that this must be set in a command buffer even if depth test is disabled.
cmdbuf.setDepthWriteEnableEXT(depth_write_enabled); cmdbuf.setDepthWriteEnable(depth_write_enabled);
} }
if (depth_test_enabled && dirty_state.depth_compare_op) { if (depth_test_enabled && dirty_state.depth_compare_op) {
dirty_state.depth_compare_op = false; dirty_state.depth_compare_op = false;
cmdbuf.setDepthCompareOpEXT(depth_compare_op); cmdbuf.setDepthCompareOp(depth_compare_op);
} }
if (dirty_state.depth_bounds_test_enabled) { if (dirty_state.depth_bounds_test_enabled) {
dirty_state.depth_bounds_test_enabled = false; dirty_state.depth_bounds_test_enabled = false;
if (instance.IsDepthBoundsSupported()) { if (instance.IsDepthBoundsSupported()) {
cmdbuf.setDepthBoundsTestEnableEXT(depth_bounds_test_enabled); cmdbuf.setDepthBoundsTestEnable(depth_bounds_test_enabled);
} }
} }
if (depth_bounds_test_enabled && dirty_state.depth_bounds) { if (depth_bounds_test_enabled && dirty_state.depth_bounds) {
@ -203,7 +203,7 @@ void DynamicState::Commit(const Instance& instance, const vk::CommandBuffer& cmd
} }
if (dirty_state.depth_bias_enabled) { if (dirty_state.depth_bias_enabled) {
dirty_state.depth_bias_enabled = false; dirty_state.depth_bias_enabled = false;
cmdbuf.setDepthBiasEnableEXT(depth_bias_enabled); cmdbuf.setDepthBiasEnable(depth_bias_enabled);
} }
if (depth_bias_enabled && dirty_state.depth_bias) { if (depth_bias_enabled && dirty_state.depth_bias) {
dirty_state.depth_bias = false; dirty_state.depth_bias = false;
@ -211,28 +211,28 @@ void DynamicState::Commit(const Instance& instance, const vk::CommandBuffer& cmd
} }
if (dirty_state.stencil_test_enabled) { if (dirty_state.stencil_test_enabled) {
dirty_state.stencil_test_enabled = false; dirty_state.stencil_test_enabled = false;
cmdbuf.setStencilTestEnableEXT(stencil_test_enabled); cmdbuf.setStencilTestEnable(stencil_test_enabled);
} }
if (stencil_test_enabled) { if (stencil_test_enabled) {
if (dirty_state.stencil_front_ops && dirty_state.stencil_back_ops && if (dirty_state.stencil_front_ops && dirty_state.stencil_back_ops &&
stencil_front_ops == stencil_back_ops) { stencil_front_ops == stencil_back_ops) {
dirty_state.stencil_front_ops = false; dirty_state.stencil_front_ops = false;
dirty_state.stencil_back_ops = false; dirty_state.stencil_back_ops = false;
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eFrontAndBack, cmdbuf.setStencilOp(vk::StencilFaceFlagBits::eFrontAndBack, stencil_front_ops.fail_op,
stencil_front_ops.fail_op, stencil_front_ops.pass_op, stencil_front_ops.pass_op, stencil_front_ops.depth_fail_op,
stencil_front_ops.depth_fail_op, stencil_front_ops.compare_op); stencil_front_ops.compare_op);
} else { } else {
if (dirty_state.stencil_front_ops) { if (dirty_state.stencil_front_ops) {
dirty_state.stencil_front_ops = false; dirty_state.stencil_front_ops = false;
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eFront, stencil_front_ops.fail_op, cmdbuf.setStencilOp(vk::StencilFaceFlagBits::eFront, stencil_front_ops.fail_op,
stencil_front_ops.pass_op, stencil_front_ops.depth_fail_op, stencil_front_ops.pass_op, stencil_front_ops.depth_fail_op,
stencil_front_ops.compare_op); stencil_front_ops.compare_op);
} }
if (dirty_state.stencil_back_ops) { if (dirty_state.stencil_back_ops) {
dirty_state.stencil_back_ops = false; dirty_state.stencil_back_ops = false;
cmdbuf.setStencilOpEXT(vk::StencilFaceFlagBits::eBack, stencil_back_ops.fail_op, cmdbuf.setStencilOp(vk::StencilFaceFlagBits::eBack, stencil_back_ops.fail_op,
stencil_back_ops.pass_op, stencil_back_ops.depth_fail_op, stencil_back_ops.pass_op, stencil_back_ops.depth_fail_op,
stencil_back_ops.compare_op); stencil_back_ops.compare_op);
} }
} }
if (dirty_state.stencil_front_reference && dirty_state.stencil_back_reference && if (dirty_state.stencil_front_reference && dirty_state.stencil_back_reference &&
@ -291,16 +291,16 @@ void DynamicState::Commit(const Instance& instance, const vk::CommandBuffer& cmd
if (dirty_state.primitive_restart_enable) { if (dirty_state.primitive_restart_enable) {
dirty_state.primitive_restart_enable = false; dirty_state.primitive_restart_enable = false;
if (instance.IsPrimitiveRestartDisableSupported()) { if (instance.IsPrimitiveRestartDisableSupported()) {
cmdbuf.setPrimitiveRestartEnableEXT(primitive_restart_enable); cmdbuf.setPrimitiveRestartEnable(primitive_restart_enable);
} }
} }
if (dirty_state.cull_mode) { if (dirty_state.cull_mode) {
dirty_state.cull_mode = false; dirty_state.cull_mode = false;
cmdbuf.setCullModeEXT(cull_mode); cmdbuf.setCullMode(cull_mode);
} }
if (dirty_state.front_face) { if (dirty_state.front_face) {
dirty_state.front_face = false; dirty_state.front_face = false;
cmdbuf.setFrontFaceEXT(front_face); cmdbuf.setFrontFace(front_face);
} }
if (dirty_state.blend_constants) { if (dirty_state.blend_constants) {
dirty_state.blend_constants = false; dirty_state.blend_constants = false;