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

[d3d9] Respect input texcoord size in texcoord transform

Make 1 in range TexcoordInputSize - TexcoordRasterizerSize, and 0 greater than/equal to TexcoordRasterizerSize.

Closes #83
parent d2ff4629
......@@ -2507,7 +2507,8 @@ namespace dxvk {
if (!dirtyFFShader)
dirtyFFShader |= decl->TestFlag(D3D9VertexDeclFlag::HasPositionT) != m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasPositionT)
|| decl->TestFlag(D3D9VertexDeclFlag::HasColor0) != m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor0)
|| decl->TestFlag(D3D9VertexDeclFlag::HasColor1) != m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor1);
|| decl->TestFlag(D3D9VertexDeclFlag::HasColor1) != m_state.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor1)
|| decl->GetTexcoordMask() != m_state.vertexDecl->GetTexcoordMask();
if (dirtyFFShader)
m_flags.set(D3D9DeviceFlag::DirtyFFVertexShader);
......@@ -6030,6 +6031,8 @@ namespace dxvk {
key.data.TexcoordIndices |= index << (i * 3);
}
key.data.TexcoordDeclMask = m_state.vertexDecl != nullptr ? m_state.vertexDecl->GetTexcoordMask() : 0;
EmitCs([
this,
cKey = key,
......
......@@ -826,10 +826,17 @@ namespace dxvk {
uint32_t type = flags;
if (type != D3DTTFF_DISABLE) {
if (!m_vsKey.data.HasPositionT) {
uint32_t one = m_module.constf32(1.0f);
for (uint32_t i = count; i < 4; i++)
transformed = m_module.opCompositeInsert(m_vec4Type, one, transformed, 1, &i);
for (uint32_t j = count; j < 4; j++) {
// If we're outside the component count of the vertex decl for this texcoord then we pad with zeroes.
// Otherwise, pad with ones.
// Very weird quirk in order to get texcoord transforms to work like they do in native.
// In future, maybe we could sort this out properly by chopping matrices of different sizes, but thats
// a project for another day.
uint32_t texcoordCount = (m_vsKey.data.TexcoordDeclMask >> (3 * inputIndex)) & 0x7;
uint32_t value = j > texcoordCount ? m_module.constf32(0) : m_module.constf32(1);
transformed = m_module.opCompositeInsert(m_vec4Type, value, transformed, 1, &j);
}
transformed = m_module.opVectorTimesMatrix(m_vec4Type, transformed, m_vs.constants.texcoord[i]);
}
......@@ -1978,6 +1985,7 @@ namespace dxvk {
state.add(uint32hash(key.primitive.a));
state.add(uint32hash(key.primitive.b));
state.add(uint32hash(key.primitive.c));
state.add(uint32hash(key.primitive.d));
return state;
}
......
......@@ -95,12 +95,15 @@ namespace dxvk {
uint32_t TransformFlags : 24;
uint32_t LightCount : 4;
uint32_t TexcoordDeclMask : 24;
} data;
struct {
uint32_t a;
uint32_t b;
uint32_t c;
uint32_t d;
} primitive;
};
};
......
......@@ -371,6 +371,30 @@ namespace dxvk {
}
uint32_t GetDecltypeCount(D3DDECLTYPE Type) {
switch (Type) {
case D3DDECLTYPE_FLOAT1: return 1;
case D3DDECLTYPE_FLOAT2: return 2;
case D3DDECLTYPE_FLOAT3: return 3;
case D3DDECLTYPE_FLOAT4: return 4;
case D3DDECLTYPE_D3DCOLOR: return 4;
case D3DDECLTYPE_UBYTE4: return 4;
case D3DDECLTYPE_SHORT2: return 2;
case D3DDECLTYPE_SHORT4: return 4;
case D3DDECLTYPE_UBYTE4N: return 4;
case D3DDECLTYPE_SHORT2N: return 2;
case D3DDECLTYPE_SHORT4N: return 4;
case D3DDECLTYPE_USHORT2N: return 2;
case D3DDECLTYPE_USHORT4N: return 4;
case D3DDECLTYPE_UDEC3: return 3;
case D3DDECLTYPE_DEC3N: return 3;
case D3DDECLTYPE_FLOAT16_2: return 2;
case D3DDECLTYPE_FLOAT16_4: return 4;
default: return 0;
}
}
bool IsDepthFormat(D3D9Format Format) {
return Format == D3D9Format::D16_LOCKABLE
|| Format == D3D9Format::D32
......
......@@ -179,6 +179,8 @@ namespace dxvk {
uint32_t GetDecltypeSize(D3DDECLTYPE Type);
uint32_t GetDecltypeCount(D3DDECLTYPE Type);
void ConvertBox(D3DBOX box, VkOffset3D& offset, VkExtent3D& extent);
void ConvertRect(RECT rect, VkOffset3D& offset, VkExtent3D& extent);
......
......@@ -215,6 +215,9 @@ namespace dxvk {
m_flags.set(D3D9VertexDeclFlag::HasPositionT);
else if (element.Usage == D3DDECLUSAGE_PSIZE)
m_flags.set(D3D9VertexDeclFlag::HasPointSize);
if (element.Usage == D3DDECLUSAGE_TEXCOORD)
m_texcoordMask |= GetDecltypeCount(D3DDECLTYPE(element.Type)) << (element.UsageIndex * 3);
}
}
......
......@@ -58,6 +58,10 @@ namespace dxvk {
return m_flags.test(flag);
}
uint32_t GetTexcoordMask() const {
return m_texcoordMask;
}
private:
void Classify();
......@@ -68,6 +72,8 @@ namespace dxvk {
DWORD m_fvf;
uint32_t m_texcoordMask = 0;
};
}
\ No newline at end of file
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