diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 4bc5e738a..8b15b82c6 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2098,13 +2098,9 @@ namespace dxvk { break; case D3DRS_SHADEMODE: - if (m_state.pixelShader != nullptr) { - BindShader( - GetCommonShader(m_state.pixelShader), - GetPixelShaderPermutation()); - } - - m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader); + m_flags.set( + D3D9DeviceFlag::DirtyFFPixelShader, + D3D9DeviceFlag::DirtyRasterizerState); break; case D3DRS_TWEENFACTOR: @@ -2685,8 +2681,7 @@ namespace dxvk { if (m_state.pixelShader != nullptr) { BindShader( - GetCommonShader(m_state.pixelShader), - GetPixelShaderPermutation()); + GetCommonShader(m_state.pixelShader)); } if (dst->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER) { @@ -2873,10 +2868,7 @@ namespace dxvk { m_flags.clr(D3D9DeviceFlag::DirtyProgVertexShader); m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader); - BindShader( - GetCommonShader(shader), - GetVertexShaderPermutation()); - + BindShader(GetCommonShader(shader)); m_vsShaderMasks = newShader->GetShaderMask(); } else @@ -3204,10 +3196,7 @@ namespace dxvk { if (shader != nullptr) { m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader); - BindShader( - GetCommonShader(shader), - GetPixelShaderPermutation()); - + BindShader(GetCommonShader(shader)); m_psShaderMasks = newShader->GetShaderMask(); } else { @@ -5721,6 +5710,7 @@ namespace dxvk { state.depthClipEnable = true; state.frontFace = VK_FRONT_FACE_CLOCKWISE; state.polygonMode = DecodeFillMode(D3DFILLMODE(rs[D3DRS_FILLMODE])); + state.flatShading = m_state.renderStates[D3DRS_SHADEMODE] == D3DSHADE_FLAT; EmitCs([ cState = state @@ -6032,8 +6022,7 @@ namespace dxvk { m_flags.set(D3D9DeviceFlag::DirtyInputLayout); BindShader( - GetCommonShader(m_state.vertexShader), - GetVertexShaderPermutation()); + GetCommonShader(m_state.vertexShader)); } UploadConstants(); @@ -6123,10 +6112,9 @@ namespace dxvk { template void D3D9DeviceEx::BindShader( - const D3D9CommonShader* pShaderModule, - D3D9ShaderPermutation Permutation) { + const D3D9CommonShader* pShaderModule) { EmitCs([ - cShader = pShaderModule->GetShader(Permutation) + cShader = pShaderModule->GetShader() ] (DxvkContext* ctx) mutable { constexpr VkShaderStageFlagBits stage = GetShaderStage(ShaderStage); ctx->bindShader(std::move(cShader)); diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 487d038f6..a815699e2 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -27,7 +27,6 @@ #include "d3d9_swvp_emu.h" #include "d3d9_spec_constants.h" -#include "d3d9_shader_permutations.h" #include #include @@ -871,8 +870,7 @@ namespace dxvk { template void BindShader( - const D3D9CommonShader* pShaderModule, - D3D9ShaderPermutation Permutation); + const D3D9CommonShader* pShaderModule); void BindInputLayout(); @@ -973,17 +971,6 @@ namespace dxvk { return m_behaviorFlags & (D3DCREATE_MIXED_VERTEXPROCESSING | D3DCREATE_SOFTWARE_VERTEXPROCESSING); } - inline constexpr D3D9ShaderPermutation GetVertexShaderPermutation() { - return D3D9ShaderPermutations::None; - } - - inline D3D9ShaderPermutation GetPixelShaderPermutation() { - if (unlikely(m_state.renderStates[D3DRS_SHADEMODE] == D3DSHADE_FLAT)) - return D3D9ShaderPermutations::FlatShade; - - return D3D9ShaderPermutations::None; - } - void DetermineConstantLayouts(bool canSWVP); D3D9BufferSlice AllocUPBuffer(VkDeviceSize size); diff --git a/src/d3d9/d3d9_shader.cpp b/src/d3d9/d3d9_shader.cpp index 664ebbdbc..2aa2f444e 100644 --- a/src/d3d9/d3d9_shader.cpp +++ b/src/d3d9/d3d9_shader.cpp @@ -56,7 +56,7 @@ namespace dxvk { const D3D9ConstantLayout& constantLayout = ShaderStage == VK_SHADER_STAGE_VERTEX_BIT ? pDevice->GetVertexConstantLayout() : pDevice->GetPixelConstantLayout(); - m_shaders = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout); + m_shader = pModule->compile(*pDxsoModuleInfo, name, AnalysisInfo, constantLayout); m_isgn = pModule->isgn(); m_usedSamplers = pModule->usedSamplers(); @@ -73,25 +73,17 @@ namespace dxvk { m_constants = pModule->constants(); m_maxDefinedConst = pModule->maxDefinedConstant(); - m_shaders[0]->setShaderKey(Key); + m_shader->setShaderKey(Key); - if (m_shaders[1] != nullptr) { - // Lets lie about the shader key type for the state cache. - m_shaders[1]->setShaderKey({ VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, Key.sha1() }); - } - if (dumpPath.size() != 0) { std::ofstream dumpStream( str::tows(str::format(dumpPath, "/", name, ".spv").c_str()).c_str(), std::ios_base::binary | std::ios_base::trunc); - m_shaders[0]->dump(dumpStream); + m_shader->dump(dumpStream); } - pDevice->GetDXVKDevice()->registerShader(m_shaders[0]); - - if (m_shaders[1] != nullptr && m_shaders[1] != m_shaders[0]) - pDevice->GetDXVKDevice()->registerShader(m_shaders[1]); + pDevice->GetDXVKDevice()->registerShader(m_shader); } diff --git a/src/d3d9/d3d9_shader.h b/src/d3d9/d3d9_shader.h index d896f019c..fc281c502 100644 --- a/src/d3d9/d3d9_shader.h +++ b/src/d3d9/d3d9_shader.h @@ -2,7 +2,6 @@ #include "d3d9_resource.h" #include "../dxso/dxso_module.h" -#include "d3d9_shader_permutations.h" #include "d3d9_util.h" #include @@ -33,12 +32,12 @@ namespace dxvk { DxsoModule* pModule); - Rc GetShader(D3D9ShaderPermutation Permutation) const { - return m_shaders[Permutation]; + Rc GetShader() const { + return m_shader; } std::string GetName() const { - return m_shaders[D3D9ShaderPermutations::None]->debugName(); + return m_shader->debugName(); } const std::vector& GetBytecode() const { @@ -69,7 +68,7 @@ namespace dxvk { DxsoDefinedConstants m_constants; uint32_t m_maxDefinedConst; - DxsoPermutations m_shaders; + Rc m_shader; std::vector m_bytecode; diff --git a/src/d3d9/d3d9_shader_permutations.h b/src/d3d9/d3d9_shader_permutations.h deleted file mode 100644 index cf2301d29..000000000 --- a/src/d3d9/d3d9_shader_permutations.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "d3d9_include.h" - -namespace dxvk { - - class DxvkShader; - - namespace D3D9ShaderPermutations { - enum D3D9ShaderPermutation { - None, - FlatShade, - Count - }; - } - using D3D9ShaderPermutation = D3D9ShaderPermutations::D3D9ShaderPermutation; - - using DxsoPermutations = std::array, D3D9ShaderPermutations::Count>; - -} \ No newline at end of file diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index de5735d1c..d0e5fc452 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -219,32 +219,7 @@ namespace dxvk { } - DxsoPermutations DxsoCompiler::compile() { - DxsoPermutations permutations = { }; - - // Create the shader module object - permutations[D3D9ShaderPermutations::None] = compileShader(); - - // If we need to add more permuations, might be worth making a copy of module - // before we do anything more. :-) - if (m_programInfo.type() == DxsoProgramType::PixelShader) { - if (m_ps.diffuseColorIn) - m_module.decorate(m_ps.diffuseColorIn, spv::DecorationFlat); - - if (m_ps.specularColorIn) - m_module.decorate(m_ps.specularColorIn, spv::DecorationFlat); - - if (m_ps.diffuseColorIn || m_ps.specularColorIn) - permutations[D3D9ShaderPermutations::FlatShade] = compileShader(); - else - permutations[D3D9ShaderPermutations::FlatShade] = permutations[D3D9ShaderPermutations::None]; - } - - return permutations; - } - - - Rc DxsoCompiler::compileShader() { + Rc DxsoCompiler::compile() { DxvkShaderCreateInfo info; info.stage = m_programInfo.shaderStage(); info.bindingCount = m_bindings.size(); @@ -254,6 +229,9 @@ namespace dxvk { info.pushConstOffset = m_pushConstOffset; info.pushConstSize = m_pushConstSize; + if (m_programInfo.type() == DxsoProgramTypes::PixelShader) + info.flatShadingInputs = m_ps.flatShadingMask; + return new DxvkShader(info, m_module.compile()); } @@ -3396,10 +3374,8 @@ void DxsoCompiler::emitControlFlowGenericLoop( workingReg.id = m_module.opSelect(getVectorTypeId(workingReg.type), pointInfo.isSprite, pointCoord, workingReg.id); if (m_programInfo.type() == DxsoProgramType::PixelShader && elem.semantic.usage == DxsoUsage::Color) { - if (elem.semantic.usageIndex == 0) - m_ps.diffuseColorIn = inputPtr.id; - else if (elem.semantic.usageIndex == 1) - m_ps.specularColorIn = inputPtr.id; + if (elem.semantic.usageIndex < 2) + m_ps.flatShadingMask |= 1u << slot; } m_module.opStore(indexPtr.id, workingReg.id); diff --git a/src/dxso/dxso_compiler.h b/src/dxso/dxso_compiler.h index 4360e599e..eb16eeee6 100644 --- a/src/dxso/dxso_compiler.h +++ b/src/dxso/dxso_compiler.h @@ -7,7 +7,6 @@ #include "dxso_util.h" #include "../d3d9/d3d9_constant_layout.h" -#include "../d3d9/d3d9_shader_permutations.h" #include "../d3d9/d3d9_spec_constants.h" #include "../spirv/spirv_module.h" @@ -177,8 +176,7 @@ namespace dxvk { uint32_t killState = 0; uint32_t builtinLaneId = 0; - uint32_t diffuseColorIn = 0; - uint32_t specularColorIn = 0; + uint32_t flatShadingMask = 0; }; struct DxsoCfgBlockIf { @@ -243,7 +241,7 @@ namespace dxvk { * \brief Compiles the shader * \returns The final shader objects */ - DxsoPermutations compile(); + Rc compile(); const DxsoIsgn& isgn() { return m_isgn; } const DxsoIsgn& osgn() { return m_osgn; } @@ -626,8 +624,6 @@ namespace dxvk { return this->emitRegisterLoad(lookup, writeMask); } - Rc compileShader(); - /////////////////////////////// // Handle shader ops void emitDcl(const DxsoInstructionContext& ctx); diff --git a/src/dxso/dxso_module.cpp b/src/dxso/dxso_module.cpp index cf32cdaa2..4cc6eb3e7 100644 --- a/src/dxso/dxso_module.cpp +++ b/src/dxso/dxso_module.cpp @@ -21,7 +21,7 @@ namespace dxvk { return info; } - DxsoPermutations DxsoModule::compile( + Rc DxsoModule::compile( const DxsoModuleInfo& moduleInfo, const std::string& fileName, const DxsoAnalysisInfo& analysis, diff --git a/src/dxso/dxso_module.h b/src/dxso/dxso_module.h index 4b8238df3..b3de38632 100644 --- a/src/dxso/dxso_module.h +++ b/src/dxso/dxso_module.h @@ -9,7 +9,6 @@ #include "dxso_analysis.h" #include "../d3d9/d3d9_constant_layout.h" -#include "../d3d9/d3d9_shader_permutations.h" #include @@ -42,7 +41,7 @@ namespace dxvk { * the compiled SPIR-V for debugging purposes. * \returns The compiled shader object */ - DxsoPermutations compile( + Rc compile( const DxsoModuleInfo& moduleInfo, const std::string& fileName, const DxsoAnalysisInfo& analysis,