1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d9] Use new flat shading state for DXSO shaders

This commit is contained in:
Philip Rebohle 2022-08-08 03:23:59 +02:00 committed by Philip Rebohle
parent dfdb729476
commit 8f1024c094
9 changed files with 29 additions and 112 deletions

View File

@ -2098,13 +2098,9 @@ namespace dxvk {
break;
case D3DRS_SHADEMODE:
if (m_state.pixelShader != nullptr) {
BindShader<DxsoProgramType::PixelShader>(
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<DxsoProgramTypes::PixelShader>(
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<DxsoProgramTypes::VertexShader>(
GetCommonShader(shader),
GetVertexShaderPermutation());
BindShader<DxsoProgramTypes::VertexShader>(GetCommonShader(shader));
m_vsShaderMasks = newShader->GetShaderMask();
}
else
@ -3204,10 +3196,7 @@ namespace dxvk {
if (shader != nullptr) {
m_flags.set(D3D9DeviceFlag::DirtyFFPixelShader);
BindShader<DxsoProgramTypes::PixelShader>(
GetCommonShader(shader),
GetPixelShaderPermutation());
BindShader<DxsoProgramTypes::PixelShader>(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<DxsoProgramType::VertexShader>(
GetCommonShader(m_state.vertexShader),
GetVertexShaderPermutation());
GetCommonShader(m_state.vertexShader));
}
UploadConstants<DxsoProgramTypes::VertexShader>();
@ -6123,10 +6112,9 @@ namespace dxvk {
template <DxsoProgramType ShaderStage>
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<stage>(std::move(cShader));

View File

@ -27,7 +27,6 @@
#include "d3d9_swvp_emu.h"
#include "d3d9_spec_constants.h"
#include "d3d9_shader_permutations.h"
#include <unordered_set>
#include <vector>
@ -871,8 +870,7 @@ namespace dxvk {
template <DxsoProgramType ShaderStage>
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);

View File

@ -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);
}

View File

@ -2,7 +2,6 @@
#include "d3d9_resource.h"
#include "../dxso/dxso_module.h"
#include "d3d9_shader_permutations.h"
#include "d3d9_util.h"
#include <array>
@ -33,12 +32,12 @@ namespace dxvk {
DxsoModule* pModule);
Rc<DxvkShader> GetShader(D3D9ShaderPermutation Permutation) const {
return m_shaders[Permutation];
Rc<DxvkShader> GetShader() const {
return m_shader;
}
std::string GetName() const {
return m_shaders[D3D9ShaderPermutations::None]->debugName();
return m_shader->debugName();
}
const std::vector<uint8_t>& GetBytecode() const {
@ -69,7 +68,7 @@ namespace dxvk {
DxsoDefinedConstants m_constants;
uint32_t m_maxDefinedConst;
DxsoPermutations m_shaders;
Rc<DxvkShader> m_shader;
std::vector<uint8_t> m_bytecode;

View File

@ -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<Rc<DxvkShader>, D3D9ShaderPermutations::Count>;
}

View File

@ -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<DxvkShader> DxsoCompiler::compileShader() {
Rc<DxvkShader> 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);

View File

@ -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<DxvkShader> 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<DxvkShader> compileShader();
///////////////////////////////
// Handle shader ops
void emitDcl(const DxsoInstructionContext& ctx);

View File

@ -21,7 +21,7 @@ namespace dxvk {
return info;
}
DxsoPermutations DxsoModule::compile(
Rc<DxvkShader> DxsoModule::compile(
const DxsoModuleInfo& moduleInfo,
const std::string& fileName,
const DxsoAnalysisInfo& analysis,

View File

@ -9,7 +9,6 @@
#include "dxso_analysis.h"
#include "../d3d9/d3d9_constant_layout.h"
#include "../d3d9/d3d9_shader_permutations.h"
#include <vector>
@ -42,7 +41,7 @@ namespace dxvk {
* the compiled SPIR-V for debugging purposes.
* \returns The compiled shader object
*/
DxsoPermutations compile(
Rc<DxvkShader> compile(
const DxsoModuleInfo& moduleInfo,
const std::string& fileName,
const DxsoAnalysisInfo& analysis,