Commit d7610d5a authored by Joshua Ashton's avatar Joshua Ashton 🐸

[d3d9] Refactor fixed function keys

parent f4933905
......@@ -5713,40 +5713,40 @@ namespace dxvk {
m_flags.clr(D3D9DeviceFlag::DirtyFFVertexShader);
D3D9FFShaderKeyVS key;
key.data.HasPositionT = hasPositionT;
key.data.HasColor0 = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor0) : false;
key.data.HasColor1 = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor1) : false;
key.data.HasPointSize = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasPointSize) : false;
key.data.HasFog = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasFog) : false;
key.Data.Contents.HasPositionT = hasPositionT;
key.Data.Contents.HasColor0 = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor0) : false;
key.Data.Contents.HasColor1 = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor1) : false;
key.Data.Contents.HasPointSize = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasPointSize) : false;
key.Data.Contents.HasFog = m_state.vertexDecl != nullptr ? m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasFog) : false;
bool lighting = m_state.renderStates[D3DRS_LIGHTING] != 0 && !key.data.HasPositionT;
bool lighting = m_state.renderStates[D3DRS_LIGHTING] != 0 && !key.Data.Contents.HasPositionT;
bool colorVertex = m_state.renderStates[D3DRS_COLORVERTEX] != 0;
uint32_t mask = (lighting && colorVertex)
? (key.data.HasColor0 ? D3DMCS_COLOR1 : D3DMCS_MATERIAL)
| (key.data.HasColor1 ? D3DMCS_COLOR2 : D3DMCS_MATERIAL)
? (key.Data.Contents.HasColor0 ? D3DMCS_COLOR1 : D3DMCS_MATERIAL)
| (key.Data.Contents.HasColor1 ? D3DMCS_COLOR2 : D3DMCS_MATERIAL)
: 0;
key.data.UseLighting = lighting;
key.data.NormalizeNormals = m_state.renderStates[D3DRS_NORMALIZENORMALS];
key.data.LocalViewer = m_state.renderStates[D3DRS_LOCALVIEWER] && lighting;
key.Data.Contents.UseLighting = lighting;
key.Data.Contents.NormalizeNormals = m_state.renderStates[D3DRS_NORMALIZENORMALS];
key.Data.Contents.LocalViewer = m_state.renderStates[D3DRS_LOCALVIEWER] && lighting;
key.data.RangeFog = m_state.renderStates[D3DRS_RANGEFOGENABLE];
key.Data.Contents.RangeFog = m_state.renderStates[D3DRS_RANGEFOGENABLE];
key.data.DiffuseSource = m_state.renderStates[D3DRS_DIFFUSEMATERIALSOURCE] & mask;
key.data.AmbientSource = m_state.renderStates[D3DRS_AMBIENTMATERIALSOURCE] & mask;
key.data.SpecularSource = m_state.renderStates[D3DRS_SPECULARMATERIALSOURCE] & mask;
key.data.EmissiveSource = m_state.renderStates[D3DRS_EMISSIVEMATERIALSOURCE] & mask;
key.Data.Contents.DiffuseSource = m_state.renderStates[D3DRS_DIFFUSEMATERIALSOURCE] & mask;
key.Data.Contents.AmbientSource = m_state.renderStates[D3DRS_AMBIENTMATERIALSOURCE] & mask;
key.Data.Contents.SpecularSource = m_state.renderStates[D3DRS_SPECULARMATERIALSOURCE] & mask;
key.Data.Contents.EmissiveSource = m_state.renderStates[D3DRS_EMISSIVEMATERIALSOURCE] & mask;
uint32_t lightCount = 0;
if (key.data.UseLighting) {
if (key.Data.Contents.UseLighting) {
for (uint32_t i = 0; i < caps::MaxEnabledLights; i++) {
if (m_state.enabledLightIndices[i] != UINT32_MAX)
lightCount++;
}
}
key.data.LightCount = lightCount;
key.Data.Contents.LightCount = lightCount;
for (uint32_t i = 0; i < caps::MaxTextureBlendStages; i++) {
uint32_t transformFlags = m_state.textureStages[i][D3DTSS_TEXTURETRANSFORMFLAGS] & ~(D3DTTFF_PROJECTED);
......@@ -5756,12 +5756,12 @@ namespace dxvk {
transformFlags &= 0b111;
index &= 0b111;
key.data.TransformFlags |= transformFlags << (i * 3);
key.data.TexcoordFlags |= indexFlags << (i * 3);
key.data.TexcoordIndices |= index << (i * 3);
key.Data.Contents.TransformFlags |= transformFlags << (i * 3);
key.Data.Contents.TexcoordFlags |= indexFlags << (i * 3);
key.Data.Contents.TexcoordIndices |= index << (i * 3);
}
key.data.TexcoordDeclMask = m_state.vertexDecl != nullptr ? m_state.vertexDecl->GetTexcoordMask() : 0;
key.Data.Contents.TexcoordDeclMask = m_state.vertexDecl != nullptr ? m_state.vertexDecl->GetTexcoordMask() : 0;
EmitCs([
this,
......@@ -5879,7 +5879,7 @@ namespace dxvk {
uint32_t idx;
for (idx = 0; idx < caps::TextureStageCount; idx++) {
auto& stage = key.Stages[idx].data;
auto& stage = key.Stages[idx].Contents;
auto& data = m_state.textureStages[idx];
// Subsequent stages do not occur if this is true.
......@@ -5917,7 +5917,7 @@ namespace dxvk {
stage.ProjectedCount = (ttff & D3DTTFF_PROJECTED) ? count : 0;
}
auto& stage0 = key.Stages[0].data;
auto& stage0 = key.Stages[0].Contents;
if (stage0.ResultIsTemp &&
stage0.ColorOp != D3DTOP_DISABLE &&
......@@ -5931,7 +5931,7 @@ namespace dxvk {
// The last stage *always* writes to current.
if (idx >= 1)
key.Stages[idx - 1].data.ResultIsTemp = false;
key.Stages[idx - 1].Contents.ResultIsTemp = false;
EmitCs([
this,
......
This diff is collapsed.
......@@ -66,53 +66,52 @@ namespace dxvk {
constexpr uint32_t TCIOffset = 16;
constexpr uint32_t TCIMask = 0b111 << TCIOffset;
struct D3D9FFShaderKeyVS {
D3D9FFShaderKeyVS() {
// memcmp safety
std::memset(this, 0, sizeof(*this));
}
struct D3D9FFShaderKeyVSData {
union {
struct {
uint32_t TexcoordIndices : 24;
uint32_t TexcoordIndices : 24;
uint32_t HasPositionT : 1;
uint32_t HasPositionT : 1;
uint32_t HasColor0 : 1; // Diffuse
uint32_t HasColor1 : 1; // Specular
uint32_t HasColor0 : 1; // Diffuse
uint32_t HasColor1 : 1; // Specular
uint32_t HasPointSize : 1;
uint32_t HasPointSize : 1;
uint32_t UseLighting : 1;
uint32_t UseLighting : 1;
uint32_t NormalizeNormals : 1;
uint32_t LocalViewer : 1;
uint32_t RangeFog : 1;
uint32_t LocalViewer : 1;
uint32_t RangeFog : 1;
uint32_t TexcoordFlags : 24;
uint32_t TexcoordFlags : 24;
uint32_t DiffuseSource : 2;
uint32_t AmbientSource : 2;
uint32_t SpecularSource : 2;
uint32_t EmissiveSource : 2;
uint32_t DiffuseSource : 2;
uint32_t AmbientSource : 2;
uint32_t SpecularSource : 2;
uint32_t EmissiveSource : 2;
uint32_t TransformFlags : 24;
uint32_t TransformFlags : 24;
uint32_t LightCount : 4;
uint32_t LightCount : 4;
uint32_t TexcoordDeclMask : 24;
uint32_t HasFog : 1;
} data;
uint32_t TexcoordDeclMask : 24;
uint32_t HasFog : 1;
} Contents;
struct {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} primitive;
uint32_t Primitive[4];
};
};
struct D3D9FFShaderKeyVS {
D3D9FFShaderKeyVS() {
// memcmp safety
std::memset(&Data, 0, sizeof(Data));
}
D3D9FFShaderKeyVSData Data;
};
constexpr uint32_t TextureArgCount = 3;
struct D3D9FFShaderStage {
......@@ -138,25 +137,21 @@ namespace dxvk {
// Affects all stages.
uint32_t GlobalSpecularEnable : 1;
uint32_t GlobalFlatShade : 1;
} data;
} Contents;
struct {
uint32_t a;
uint32_t b;
} primitive;
uint32_t Primitive[2];
};
};
struct D3D9FFShaderKeyFS {
D3D9FFShaderKeyFS() {
// memcmp safety
std::memset(this, 0, sizeof(*this));
std::memset(Stages, 0, sizeof(Stages));
// Normalize this. DISABLE != 0.
for (uint32_t i = 0; i < caps::TextureStageCount; i++) {
auto& stage = Stages[i].data;
stage.ColorOp = D3DTOP_DISABLE;
stage.AlphaOp = D3DTOP_DISABLE;
Stages[i].Contents.ColorOp = D3DTOP_DISABLE;
Stages[i].Contents.AlphaOp = D3DTOP_DISABLE;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment