From 29a2cb9a5e99d706bb9ad992829f7ebef6de4b37 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 7 Aug 2022 14:59:05 +0200 Subject: [PATCH] [d3d9,d3d11] Make GetShaderStage functions constexpr --- src/d3d11/d3d11_context.cpp | 2 +- src/d3d11/d3d11_util.cpp | 13 ------------- src/d3d11/d3d11_util.h | 21 ++++++++++++++++++--- src/d3d9/d3d9_device.cpp | 3 ++- src/d3d9/d3d9_util.h | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 7a9df8bb..c9110bc7 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -3120,7 +3120,7 @@ namespace dxvk { ? pShaderModule->GetShader() : nullptr ] (DxvkContext* ctx) mutable { - VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); + constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); uint32_t slotId = computeConstantBufferBinding(ShaderStage, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); diff --git a/src/d3d11/d3d11_util.cpp b/src/d3d11/d3d11_util.cpp index d4448c54..92f5f6d4 100644 --- a/src/d3d11/d3d11_util.cpp +++ b/src/d3d11/d3d11_util.cpp @@ -78,19 +78,6 @@ namespace dxvk { } - VkShaderStageFlagBits GetShaderStage(DxbcProgramType ProgramType) { - switch (ProgramType) { - case DxbcProgramType::VertexShader: return VK_SHADER_STAGE_VERTEX_BIT; - case DxbcProgramType::HullShader: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; - case DxbcProgramType::DomainShader: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; - case DxbcProgramType::GeometryShader: return VK_SHADER_STAGE_GEOMETRY_BIT; - case DxbcProgramType::PixelShader: return VK_SHADER_STAGE_FRAGMENT_BIT; - case DxbcProgramType::ComputeShader: return VK_SHADER_STAGE_COMPUTE_BIT; - default: return VkShaderStageFlagBits(0); - } - } - - VkFormatFeatureFlags GetBufferFormatFeatures(UINT BindFlags) { VkFormatFeatureFlags features = 0; diff --git a/src/d3d11/d3d11_util.h b/src/d3d11/d3d11_util.h index 749dc8be..8913d2c3 100644 --- a/src/d3d11/d3d11_util.h +++ b/src/d3d11/d3d11_util.h @@ -31,9 +31,6 @@ namespace dxvk { VkConservativeRasterizationModeEXT DecodeConservativeRasterizationMode( D3D11_CONSERVATIVE_RASTERIZATION_MODE Mode); - VkShaderStageFlagBits GetShaderStage( - DxbcProgramType ProgramType); - VkFormatFeatureFlags GetBufferFormatFeatures( UINT BindFlags); @@ -43,4 +40,22 @@ namespace dxvk { VkFormat GetPackedDepthStencilFormat( DXGI_FORMAT Format); + /** + * \brief Translates D3D11 shader stage to corresponding Vulkan stage + * + * \param [in] ProgramType DXBC program type + * \returns Corresponding Vulkan shader stage + */ + constexpr VkShaderStageFlagBits GetShaderStage(DxbcProgramType ProgramType) { + switch (ProgramType) { + case DxbcProgramType::VertexShader: return VK_SHADER_STAGE_VERTEX_BIT; + case DxbcProgramType::HullShader: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; + case DxbcProgramType::DomainShader: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; + case DxbcProgramType::GeometryShader: return VK_SHADER_STAGE_GEOMETRY_BIT; + case DxbcProgramType::PixelShader: return VK_SHADER_STAGE_FRAGMENT_BIT; + case DxbcProgramType::ComputeShader: return VK_SHADER_STAGE_COMPUTE_BIT; + default: return VkShaderStageFlagBits(0); + } + } + } \ No newline at end of file diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index f32abf62..95cade41 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -6130,7 +6130,8 @@ namespace dxvk { EmitCs([ cShader = pShaderModule->GetShader(Permutation) ] (DxvkContext* ctx) mutable { - ctx->bindShader(GetShaderStage(ShaderStage), std::move(cShader)); + constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); + ctx->bindShader(stage, std::move(cShader)); }); } diff --git a/src/d3d9/d3d9_util.h b/src/d3d9/d3d9_util.h index 5899cd4c..bbde19ad 100644 --- a/src/d3d9/d3d9_util.h +++ b/src/d3d9/d3d9_util.h @@ -110,7 +110,7 @@ namespace dxvk { return srgb ? srgbFormat : format; } - inline VkShaderStageFlagBits GetShaderStage(DxsoProgramType ProgramType) { + constexpr VkShaderStageFlagBits GetShaderStage(DxsoProgramType ProgramType) { switch (ProgramType) { case DxsoProgramTypes::VertexShader: return VK_SHADER_STAGE_VERTEX_BIT; case DxsoProgramTypes::PixelShader: return VK_SHADER_STAGE_FRAGMENT_BIT;