From f15466a2c51f8cada604bed9df59716b0b8020cf Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 17 Jul 2022 14:08:47 +0200 Subject: [PATCH] [dxvk] Remove remaining built-in specialization constants --- src/d3d9/d3d9_fixed_function.cpp | 12 ++++++------ src/dxso/dxso_compiler.cpp | 16 ++++++++-------- src/dxvk/dxvk_compute.cpp | 2 +- src/dxvk/dxvk_context.h | 5 ++--- src/dxvk/dxvk_graphics.cpp | 2 +- src/dxvk/dxvk_shader.h | 15 --------------- src/dxvk/dxvk_spec_const.h | 13 ------------- 7 files changed, 18 insertions(+), 47 deletions(-) diff --git a/src/d3d9/d3d9_fixed_function.cpp b/src/d3d9/d3d9_fixed_function.cpp index 69198eace..8c7aeb2a1 100644 --- a/src/d3d9/d3d9_fixed_function.cpp +++ b/src/d3d9/d3d9_fixed_function.cpp @@ -45,16 +45,16 @@ namespace dxvk { if (!fogCtx.IsPixel) { spvModule.setDebugName(fogMode, "vertex_fog_mode"); - spvModule.decorateSpecId(fogMode, getSpecId(D3D9SpecConstantId::VertexFogMode)); + spvModule.decorateSpecId(fogMode, D3D9SpecConstantId::VertexFogMode); } else { spvModule.setDebugName(fogMode, "pixel_fog_mode"); - spvModule.decorateSpecId(fogMode, getSpecId(D3D9SpecConstantId::PixelFogMode)); + spvModule.decorateSpecId(fogMode, D3D9SpecConstantId::PixelFogMode); } uint32_t fogEnabled = spvModule.specConstBool(false); spvModule.setDebugName(fogEnabled, "fog_enabled"); - spvModule.decorateSpecId(fogEnabled, getSpecId(D3D9SpecConstantId::FogEnabled)); + spvModule.decorateSpecId(fogEnabled, D3D9SpecConstantId::FogEnabled); uint32_t doFog = spvModule.allocateId(); uint32_t skipFog = spvModule.allocateId(); @@ -272,7 +272,7 @@ namespace dxvk { if (isFixedFunction) { uint32_t pointMode = spvModule.specConst32(uint32Type, 0); spvModule.setDebugName(pointMode, "point_mode"); - spvModule.decorateSpecId(pointMode, getSpecId(D3D9SpecConstantId::PointMode)); + spvModule.decorateSpecId(pointMode, D3D9SpecConstantId::PointMode); uint32_t scaleBit = spvModule.opBitFieldUExtract(uint32Type, pointMode, spvModule.consti32(0), spvModule.consti32(1)); uint32_t isScale = spvModule.opIEqual(boolType, scaleBit, spvModule.constu32(1)); @@ -325,7 +325,7 @@ namespace dxvk { uint32_t pointMode = spvModule.specConst32(uint32Type, 0); spvModule.setDebugName(pointMode, "point_mode"); - spvModule.decorateSpecId(pointMode, getSpecId(D3D9SpecConstantId::PointMode)); + spvModule.decorateSpecId(pointMode, D3D9SpecConstantId::PointMode); uint32_t spriteBit = spvModule.opBitFieldUExtract(uint32Type, pointMode, spvModule.consti32(1), spvModule.consti32(1)); uint32_t isSprite = spvModule.opIEqual(boolType, spriteBit, spvModule.constu32(1)); @@ -2190,7 +2190,7 @@ namespace dxvk { // Declare spec constants for render states uint32_t alphaFuncId = m_module.specConst32(m_module.defIntType(32, 0), 0); m_module.setDebugName(alphaFuncId, "alpha_func"); - m_module.decorateSpecId(alphaFuncId, getSpecId(D3D9SpecConstantId::AlphaCompareOp)); + m_module.decorateSpecId(alphaFuncId, D3D9SpecConstantId::AlphaCompareOp); // Implement alpha test auto oC0 = m_ps.out.COLOR; diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index b17c4c556..289ef90ed 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -270,11 +270,11 @@ namespace dxvk { } m_nullSpecConstant = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_nullSpecConstant, getSpecId(D3D9SpecConstantId::SamplerNull)); + m_module.decorateSpecId(m_nullSpecConstant, D3D9SpecConstantId::SamplerNull); m_module.setDebugName(m_nullSpecConstant, "nullSamplers"); m_depthSpecConstant = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_depthSpecConstant, getSpecId(D3D9SpecConstantId::SamplerDepthMode)); + m_module.decorateSpecId(m_depthSpecConstant, D3D9SpecConstantId::SamplerDepthMode); m_module.setDebugName(m_depthSpecConstant, "depthSamplers"); this->emitDclInputArray(); @@ -339,10 +339,10 @@ namespace dxvk { m_bindings.push_back(binding); m_boolSpecConstant = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_boolSpecConstant, getSpecId( + m_module.decorateSpecId(m_boolSpecConstant, m_programInfo.type() == DxsoProgramType::VertexShader ? D3D9SpecConstantId::VertexShaderBools - : D3D9SpecConstantId::PixelShaderBools)); + : D3D9SpecConstantId::PixelShaderBools); m_module.setDebugName(m_boolSpecConstant, "boolConstants"); } @@ -534,18 +534,18 @@ namespace dxvk { if (m_programInfo.majorVersion() < 2 || m_moduleInfo.options.forceSamplerTypeSpecConstants) { m_ps.samplerTypeSpec = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_ps.samplerTypeSpec, getSpecId(D3D9SpecConstantId::SamplerType)); + m_module.decorateSpecId(m_ps.samplerTypeSpec, D3D9SpecConstantId::SamplerType); m_module.setDebugName(m_ps.samplerTypeSpec, "s_sampler_types"); if (m_programInfo.majorVersion() < 2) { m_ps.projectionSpec = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_ps.projectionSpec, getSpecId(D3D9SpecConstantId::ProjectionType)); + m_module.decorateSpecId(m_ps.projectionSpec, D3D9SpecConstantId::ProjectionType); m_module.setDebugName(m_ps.projectionSpec, "s_projections"); } } m_ps.fetch4Spec = m_module.specConst32(m_module.defIntType(32, 0), 0); - m_module.decorateSpecId(m_ps.fetch4Spec, getSpecId(D3D9SpecConstantId::Fetch4)); + m_module.decorateSpecId(m_ps.fetch4Spec, D3D9SpecConstantId::Fetch4); m_module.setDebugName(m_ps.fetch4Spec, "s_fetch4"); this->setupRenderStateInfo(); @@ -3759,7 +3759,7 @@ void DxsoCompiler::emitControlFlowGenericLoop( uint32_t alphaFuncId = m_module.specConst32(m_module.defIntType(32, 0), 0); m_module.setDebugName (alphaFuncId, "alpha_func"); - m_module.decorateSpecId (alphaFuncId, getSpecId(D3D9SpecConstantId::AlphaCompareOp)); + m_module.decorateSpecId (alphaFuncId, D3D9SpecConstantId::AlphaCompareOp); // Implement alpha test and fog DxsoRegister color0; diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index c8eb4a999..bbf8a27f2 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -109,7 +109,7 @@ namespace dxvk { DxvkSpecConstants specData; for (uint32_t i = 0; i < MaxNumSpecConstants; i++) - specData.set(getSpecId(i), state.sc.specConstants[i], 0u); + specData.set(i, state.sc.specConstants[i], 0u); VkSpecializationInfo specInfo = specData.getSpecInfo(); diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 2ebe37f7c..c783544d1 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -1024,9 +1024,8 @@ namespace dxvk { /** * \brief Sets specialization constants * - * Replaces current specialization constants with - * the given list of constant entries. The specId - * in the shader can be computed with \c getSpecId. + * Replaces current specialization constants + * with the given list of constant entries. * \param [in] pipeline Graphics or Compute pipeline * \param [in] index Constant index * \param [in] value Constant value diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 0d00184f7..948cee55d 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -805,7 +805,7 @@ namespace dxvk { DxvkSpecConstants specData; for (uint32_t i = 0; i < MaxNumSpecConstants; i++) - specData.set(getSpecId(i), state.sc.specConstants[i], 0u); + specData.set(i, state.sc.specConstants[i], 0u); VkSpecializationInfo specInfo = specData.getSpecInfo(); diff --git a/src/dxvk/dxvk_shader.h b/src/dxvk/dxvk_shader.h index 905c8ed91..4ff2ffb45 100644 --- a/src/dxvk/dxvk_shader.h +++ b/src/dxvk/dxvk_shader.h @@ -18,21 +18,6 @@ namespace dxvk { class DxvkPipelineManager; struct DxvkPipelineStats; - /** - * \brief Built-in specialization constants - * - * These specialization constants allow the SPIR-V - * shaders to access some pipeline state like D3D - * shaders do. They need to be filled in by the - * implementation at pipeline compilation time. - */ - enum class DxvkSpecConstantId : uint32_t { - FirstPipelineConstant = 0, - /// Special constant ranges that do not count - /// towards the spec constant min/max values - ColorComponentMappings = DxvkLimits::MaxNumSpecConstants, - }; - /** * \brief Shader flags * diff --git a/src/dxvk/dxvk_spec_const.h b/src/dxvk/dxvk_spec_const.h index df4f041cb..3e5ec4abe 100644 --- a/src/dxvk/dxvk_spec_const.h +++ b/src/dxvk/dxvk_spec_const.h @@ -74,18 +74,5 @@ namespace dxvk { void setAsUint32(uint32_t specId, uint32_t value); }; - - - /** - * \brief Computes specialization constant ID - * - * Computest the specId to use within shaders - * for a given pipeline specialization constant. - * \param [in] index Spec constant index - * \returns Specialization constant ID - */ - inline uint32_t getSpecId(uint32_t index) { - return uint32_t(DxvkSpecConstantId::FirstPipelineConstant) + index; - } } \ No newline at end of file