Merge pull request #6791 from unknownbrackets/d3d

d3d: Enable state caching, fix another color issue, fix scale
This commit is contained in:
Henrik Rydgård 2014-08-26 17:26:24 +02:00
commit 141d3b657a
7 changed files with 123 additions and 62 deletions

View File

@ -647,12 +647,12 @@ namespace DX9 {
if (g_Config.iBufFilter == SCALE_LINEAR) {
dxstate.texMagFilter.set(D3DTEXF_LINEAR);
dxstate.texMinFilter.set(D3DTEXF_LINEAR);
dxstate.texMipFilter.set(D3DTEXF_NONE);
} else {
dxstate.texMagFilter.set(D3DTEXF_POINT);
dxstate.texMinFilter.set(D3DTEXF_POINT);
dxstate.texMipFilter.set(D3DTEXF_NONE);
}
dxstate.texMipFilter.set(D3DTEXF_NONE);
dxstate.texMipLodBias.set(0);
DrawActiveTexture(colorTexture, x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, false, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
}
/*

View File

@ -491,15 +491,13 @@ void TextureCacheDX9::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
bool noMip = (gstate.texlevel & 0xFFFFFF) == 0x000001 || (gstate.texlevel & 0xFFFFFF) == 0x100001 ; // Fix texlevel at 0
float lodBias = 0.0;
if (entry.maxLevel == 0) {
// Enforce no mip filtering, for safety.
minFilt &= 1; // no mipmaps yet
} else {
// TODO: Is this a signed value? Which direction?
float lodBias = 0.0; // -(float)((gstate.texlevel >> 16) & 0xFF) / 16.0f;
if (force || entry.lodBias != lodBias) {
entry.lodBias = lodBias;
}
// Texture lod bias should be signed.
lodBias = (float)(int)(s8)((gstate.texlevel >> 16) & 0xFF) / 16.0f;
}
if ((g_Config.iTexFiltering == LINEAR || (g_Config.iTexFiltering == LINEARFMV && g_iNumVideos)) && !gstate.isColorTestEnabled()) {
@ -519,6 +517,7 @@ void TextureCacheDX9::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
dxstate.texMinFilter.set(MinFilt[minFilt]);
dxstate.texMipFilter.set(MipFilt[minFilt]);
dxstate.texMipLodBias.set(lodBias);
dxstate.texMagFilter.set(MagFilt[magFilt]);
dxstate.texAddressU.set(sClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
dxstate.texAddressV.set(tClamp ? D3DTADDRESS_CLAMP : D3DTADDRESS_WRAP);
@ -939,7 +938,6 @@ void TextureCacheDX9::SetTexture(bool force) {
entry->lastFrame = gpuStats.numFlips;
entry->framebuffer = 0;
entry->maxLevel = maxLevel;
entry->lodBias = 0.0f;
entry->dim = gstate.getTextureDimension(0);
entry->bufw = bufw;

View File

@ -104,7 +104,6 @@ private:
u32 fullhash;
u32 cluthash;
int maxLevel;
float lodBias;
bool Matches(u16 dim2, u8 format2, int maxLevel2);
void ReleaseTexture() {

View File

@ -224,11 +224,7 @@ static const DeclTypeInfo VComp[] = {
static void VertexAttribSetup(D3DVERTEXELEMENT9 * VertexElement, u8 fmt, u8 offset, u8 usage, u8 usage_index = 0) {
memset(VertexElement, 0, sizeof(D3DVERTEXELEMENT9));
VertexElement->Offset = offset;
if (usage == D3DDECLUSAGE_COLOR && fmt == DEC_U8_4) {
VertexElement->Type = D3DDECLTYPE_D3DCOLOR;
} else {
VertexElement->Type = VComp[fmt].type;
}
VertexElement->Type = VComp[fmt].type;
VertexElement->Usage = usage;
VertexElement->UsageIndex = usage_index;
}

View File

@ -494,7 +494,7 @@ void VertexDecoderDX9::Step_PosS8() const
float *v = (float *)(decoded_ + decFmt.posoff);
const s8 *sv = (const s8*)(ptr_ + posoff);
for (int j = 0; j < 3; j++)
v[j] = (float)sv[j] * 1.0f / 127.0f;
v[j] = (float)sv[j] * (1.0f / 128.0f);
v[3] = 0;
#endif
}
@ -569,7 +569,7 @@ void VertexDecoderDX9::Step_PosS8Morph() const
float *v = (float *)(decoded_ + decFmt.posoff);
memset(v, 0, sizeof(float) * 3);
for (int n = 0; n < morphcount; n++) {
float multiplier = 1.0f / 127.0f;
float multiplier = 1.0f / 128.0f;
const s8 *sv = (const s8*)(ptr_ + onesize_*n + posoff);
for (int j = 0; j < 3; j++)
v[j] += (float)sv[j] * (multiplier * gstate_c.morphWeights[n]);
@ -581,7 +581,7 @@ void VertexDecoderDX9::Step_PosS16Morph() const
float *v = (float *)(decoded_ + decFmt.posoff);
memset(v, 0, sizeof(float) * 3);
for (int n = 0; n < morphcount; n++) {
float multiplier = 1.0f / 32767.0f;
float multiplier = 1.0f / 32768.0f;
const s16_le *sv = (const s16_le*)(ptr_ + onesize_*n + posoff);
for (int j = 0; j < 3; j++)
v[j] += (float)sv[j] * (multiplier * gstate_c.morphWeights[n]);

View File

@ -54,6 +54,7 @@ void DirectxState::Restore() {
texMinFilter.restore(); count++;
texMagFilter.restore(); count++;
texMipFilter.restore(); count++;
texMipLodBias.restore(); count++;
texAddressU.restore(); count++;
texAddressV.restore(); count++;

View File

@ -17,8 +17,10 @@ private:
}
inline void set(bool value) {
_value = value;
pD3Ddevice->SetRenderState(cap, value);
if (_value != value) {
_value = value;
pD3Ddevice->SetRenderState(cap, value);
}
}
inline void enable() {
set(true);
@ -47,8 +49,10 @@ private:
}
inline void set(DWORD newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
}
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
@ -65,14 +69,40 @@ private:
}
inline void set(DWORD newp1) {
p1 = newp1;
pD3Ddevice->SetSamplerState(0, _state1, p1);
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetSamplerState(0, _state1, p1);
}
}
void restore() {
pD3Ddevice->SetSamplerState(0, _state1, p1);
}
};
// Can't have FLOAT template parameters...
template<D3DSAMPLERSTATETYPE state1, DWORD p1def>
class DxSampler0State1Float {
D3DSAMPLERSTATETYPE _state1;
union {
FLOAT p1;
DWORD p1d;
};
public:
DxSampler0State1Float() : _state1(state1), p1d(p1def) {
DirectxState::state_count++;
}
inline void set(FLOAT newp1) {
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetSamplerState(0, _state1, p1d);
}
}
void restore() {
pD3Ddevice->SetSamplerState(0, _state1, p1d);
}
};
template<D3DRENDERSTATETYPE state1, DWORD p1def, D3DRENDERSTATETYPE state2, DWORD p2def>
class DxState2 {
D3DRENDERSTATETYPE _state1;
@ -85,10 +115,14 @@ private:
}
inline void set(DWORD newp1, DWORD newp2) {
p1 = newp1;
p2 = newp2;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
}
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
@ -111,12 +145,18 @@ private:
}
inline void set(DWORD newp1, DWORD newp2, DWORD newp3) {
p1 = newp1;
p2 = newp2;
p3 = newp3;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice->SetRenderState(_state3, p3);
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
}
if (p3 != newp3) {
p3 = newp3;
pD3Ddevice->SetRenderState(_state3, p3);
}
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
@ -142,14 +182,22 @@ private:
}
inline void set(DWORD newp1, DWORD newp2, DWORD newp3, DWORD newp4) {
p1 = newp1;
p2 = newp2;
p3 = newp3;
p4 = newp4;
pD3Ddevice->SetRenderState(_state1, p1);
pD3Ddevice->SetRenderState(_state2, p2);
pD3Ddevice->SetRenderState(_state3, p3);
pD3Ddevice->SetRenderState(_state4, p4);
if (p1 != newp1) {
p1 = newp1;
pD3Ddevice->SetRenderState(_state1, p1);
}
if (p2 != newp2) {
p2 = newp2;
pD3Ddevice->SetRenderState(_state2, p2);
}
if (p3 != newp3) {
p3 = newp3;
pD3Ddevice->SetRenderState(_state3, p3);
}
if (p4 != newp4) {
p4 = newp4;
pD3Ddevice->SetRenderState(_state4, p4);
}
}
void restore() {
pD3Ddevice->SetRenderState(_state1, p1);
@ -168,8 +216,11 @@ private:
DirectxState::state_count++;
}
inline void set(const float v[4]) {
c = D3DCOLOR_COLORVALUE(v[0], v[1], v[2], v[3]);
pD3Ddevice->SetRenderState(D3DRS_BLENDFACTOR, c);
DWORD newc = D3DCOLOR_COLORVALUE(v[0], v[1], v[2], v[3]);
if (c != newc) {
c = newc;
pD3Ddevice->SetRenderState(D3DRS_BLENDFACTOR, c);
}
}
inline void restore() {
pD3Ddevice->SetRenderState(D3DRS_BLENDFACTOR, c);
@ -185,20 +236,23 @@ private:
}
inline void set(bool r, bool g, bool b, bool a) {
mask = 0;
DWORD newmask = 0;
if (r) {
mask |= D3DCOLORWRITEENABLE_RED;
newmask |= D3DCOLORWRITEENABLE_RED;
}
if (g) {
mask |= D3DCOLORWRITEENABLE_GREEN;
newmask |= D3DCOLORWRITEENABLE_GREEN;
}
if (b) {
mask |= D3DCOLORWRITEENABLE_BLUE;
newmask |= D3DCOLORWRITEENABLE_BLUE;
}
if (a) {
mask |= D3DCOLORWRITEENABLE_ALPHA;
newmask |= D3DCOLORWRITEENABLE_ALPHA;
}
if (mask != newmask) {
mask = newmask;
pD3Ddevice->SetRenderState(D3DRS_COLORWRITEENABLE, mask);
}
pD3Ddevice->SetRenderState(D3DRS_COLORWRITEENABLE, mask);
}
inline void restore() {
@ -231,14 +285,18 @@ private:
D3DVIEWPORT9 viewport;
public:
inline void set(int x, int y, int w, int h, float n = 0.f, float f = 1.f) {
viewport.X=x;
viewport.Y=y;
viewport.Width=w;
viewport.Height=h;
viewport.MinZ=n;
viewport.MaxZ=f;
D3DVIEWPORT9 newviewport;
newviewport.X = x;
newviewport.Y = y;
newviewport.Width = w;
newviewport.Height = h;
newviewport.MinZ = n;
newviewport.MaxZ = f;
pD3Ddevice->SetViewport(&viewport);
if (memcmp(&viewport, &newviewport, sizeof(viewport))) {
viewport = newviewport;
pD3Ddevice->SetViewport(&viewport);
}
}
inline void restore() {
@ -247,14 +305,18 @@ private:
};
class StateScissor {
RECT rect;
public:
inline void set(int x1, int y1, int x2, int y2) {
RECT rect = {x1, y1, x2, y2};
pD3Ddevice->SetScissorRect(&rect);
RECT newrect = {x1, y1, x2, y2};
if (memcmp(&rect, &newrect, sizeof(rect))) {
rect = newrect;
pD3Ddevice->SetScissorRect(&rect);
}
}
inline void restore() {
pD3Ddevice->SetScissorRect(&rect);
}
};
@ -262,14 +324,18 @@ private:
DWORD cull;
public:
inline void set(int wantcull, int cullmode) {
DWORD newcull;
if (!wantcull) {
// disable
cull = D3DCULL_NONE;
newcull = D3DCULL_NONE;
} else {
// add front face ...
cull = cullmode==0 ? D3DCULL_CW:D3DCULL_CCW;
newcull = cullmode==0 ? D3DCULL_CW:D3DCULL_CCW;
}
if (cull != newcull) {
cull = newcull;
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, cull);
}
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, cull);
}
inline void restore() {
pD3Ddevice->SetRenderState(D3DRS_CULLMODE, cull);
@ -318,6 +384,7 @@ public:
DxSampler0State1<D3DSAMP_MINFILTER, D3DTEXF_POINT> texMinFilter;
DxSampler0State1<D3DSAMP_MAGFILTER, D3DTEXF_POINT> texMagFilter;
DxSampler0State1<D3DSAMP_MIPFILTER, D3DTEXF_NONE> texMipFilter;
DxSampler0State1Float<D3DSAMP_MIPMAPLODBIAS, 0> texMipLodBias;
DxSampler0State1<D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP> texAddressU;
DxSampler0State1<D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP> texAddressV;