DX11:
Fix StateManager usage in ResetAPIState/RestoreAPIState. Fix screenshots (finally). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5745 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
ab1e5f8537
commit
64ffe0039a
|
@ -380,7 +380,6 @@ int CD3DFont::DrawTextScaled(float x, float y, float scale, float spacing, u32 d
|
|||
D3D::context->IASetVertexBuffers(0, 1, &m_pVB, &stride, &bufoffset);
|
||||
D3D::context->Draw(3 * dwNumTriangles, 0);
|
||||
}
|
||||
D3D::gfxstate->SetShaderResource(0, NULL);
|
||||
D3D::stateman->PopBlendState();
|
||||
D3D::stateman->PopRasterizerState();
|
||||
return S_OK;
|
||||
|
@ -498,7 +497,6 @@ void drawShadedTexQuad(ID3D11ShaderResourceView* texture,
|
|||
|
||||
ID3D11ShaderResourceView* texres = NULL;
|
||||
context->PSSetShaderResources(0, 1, &texres); // immediately unbind the texture
|
||||
D3D::gfxstate->SetShaderResource(0, NULL);
|
||||
|
||||
lastu1 = u1;
|
||||
lastv1 = v1;
|
||||
|
@ -555,7 +553,6 @@ void drawShadedTexSubQuad(ID3D11ShaderResourceView* texture,
|
|||
|
||||
ID3D11ShaderResourceView* texres = NULL;
|
||||
context->PSSetShaderResources(0, 1, &texres); // immediately unbind the texture
|
||||
D3D::gfxstate->SetShaderResource(0, NULL);
|
||||
|
||||
lastu1 = u1;
|
||||
lastv1 = v1;
|
||||
|
|
|
@ -193,7 +193,6 @@ void EmuGfxState::ApplyState()
|
|||
ID3D11BlendState* blstate;
|
||||
hr = device->CreateBlendState(&blenddesc, &blstate);
|
||||
if (FAILED(hr)) PanicAlert("Failed to create blend state at %s %d\n", __FILE__, __LINE__);
|
||||
// context->OMSetBlendState(blstate, NULL, 0xFFFFFFFF);
|
||||
stateman->PushBlendState(blstate);
|
||||
SetDebugObjectName((ID3D11DeviceChild*)blstate, "a blend state of EmuGfxState");
|
||||
blstate->Release();
|
||||
|
@ -203,7 +202,6 @@ void EmuGfxState::ApplyState()
|
|||
hr = device->CreateRasterizerState(&rastdesc, &raststate);
|
||||
if (FAILED(hr)) PanicAlert("Failed to create rasterizer state at %s %d\n", __FILE__, __LINE__);
|
||||
SetDebugObjectName((ID3D11DeviceChild*)raststate, "a rasterizer state of EmuGfxState");
|
||||
// context->RSSetState(raststate);
|
||||
stateman->PushRasterizerState(raststate);
|
||||
raststate->Release();
|
||||
|
||||
|
@ -211,7 +209,6 @@ void EmuGfxState::ApplyState()
|
|||
hr = device->CreateDepthStencilState(&depthdesc, &depth_state);
|
||||
if (SUCCEEDED(hr)) SetDebugObjectName((ID3D11DeviceChild*)depth_state, "a depth-stencil state of EmuGfxState");
|
||||
else PanicAlert("Failed to create depth state at %s %d\n", __FILE__, __LINE__);
|
||||
// context->OMSetDepthStencilState(depth_state, 0);
|
||||
D3D::stateman->PushDepthState(depth_state);
|
||||
depth_state->Release();
|
||||
|
||||
|
@ -234,14 +231,13 @@ void EmuGfxState::AlphaPass()
|
|||
HRESULT hr = device->CreateBlendState(&desc, &blstate);
|
||||
if (FAILED(hr)) PanicAlert("Failed to create blend state at %s %d\n", __FILE__, __LINE__);
|
||||
SetDebugObjectName((ID3D11DeviceChild*)blstate, "a blend state of EmuGfxState (created during alpha pass)");
|
||||
// context->OMSetBlendState(blstate, NULL, 0xFFFFFFFF);
|
||||
stateman->PushBlendState(blstate);
|
||||
blstate->Release();
|
||||
|
||||
stateman->Apply();
|
||||
}
|
||||
|
||||
void EmuGfxState::ResetShaderResources()
|
||||
void EmuGfxState::Reset()
|
||||
{
|
||||
for (unsigned int k = 0;k < 8;k++)
|
||||
SAFE_RELEASE(shader_resources[k]);
|
||||
|
@ -322,25 +318,34 @@ void StateManager::PopRasterizerState() { raststates.pop(); }
|
|||
void StateManager::Apply()
|
||||
{
|
||||
if (!blendstates.empty())
|
||||
{
|
||||
if (cur_blendstate != blendstates.top().GetPtr())
|
||||
{
|
||||
cur_blendstate = (ID3D11BlendState*)blendstates.top().GetPtr();
|
||||
D3D::context->OMSetBlendState(cur_blendstate, NULL, 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
else D3D::context->OMSetBlendState(NULL, NULL, 0xFFFFFFFF);
|
||||
|
||||
if (!depthstates.empty())
|
||||
{
|
||||
if (cur_depthstate != depthstates.top().GetPtr())
|
||||
{
|
||||
cur_depthstate = (ID3D11DepthStencilState*)depthstates.top().GetPtr();
|
||||
D3D::context->OMSetDepthStencilState(cur_depthstate, 0);
|
||||
}
|
||||
}
|
||||
else D3D::context->OMSetDepthStencilState(NULL, 0);
|
||||
|
||||
if (!raststates.empty())
|
||||
{
|
||||
if (cur_raststate != raststates.top().GetPtr())
|
||||
{
|
||||
cur_raststate = (ID3D11RasterizerState*)raststates.top().GetPtr();
|
||||
D3D::context->RSSetState(cur_raststate);
|
||||
}
|
||||
}
|
||||
else D3D::context->RSSetState(NULL);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
void ApplyState(); // apply current state
|
||||
void AlphaPass(); // only modify the current state to enable the alpha pass
|
||||
void ResetShaderResources(); // disable all shader resources
|
||||
void Reset();
|
||||
|
||||
// blend state
|
||||
void SetAlphaBlendEnable(bool enable);
|
||||
|
|
|
@ -906,9 +906,12 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|||
D3D::context->Map(buftex, 0, D3D11_MAP_READ_WRITE, 0, &map);
|
||||
for (unsigned int y = 0; y < D3D::GetBackBufferHeight(); ++y)
|
||||
{
|
||||
u32* ptr = (u32*)((u8*)map.pData + y * map.RowPitch);
|
||||
u8* ptr = (u8*)map.pData + y * map.RowPitch + 3;
|
||||
for (unsigned int x = 0; x < D3D::GetBackBufferWidth(); ++x)
|
||||
*(u8*)ptr++ = 0xFF;
|
||||
{
|
||||
*ptr = 0xFF;
|
||||
ptr += 4;
|
||||
}
|
||||
}
|
||||
D3D::context->Unmap(buftex, 0);
|
||||
|
||||
|
@ -1015,31 +1018,38 @@ void Renderer::Swap(u32 xfbAddr, FieldType field, u32 fbWidth, u32 fbHeight)
|
|||
XFBWrited = false;
|
||||
}
|
||||
|
||||
// TODO: Make sure that each ResetAPIState call matches an RestoreAPIState
|
||||
// That way we don't need to deal with the number of ResetAPIState calls anymore
|
||||
void Renderer::ResetAPIState()
|
||||
{
|
||||
resets++;
|
||||
D3D::gfxstate->Reset();
|
||||
D3D::stateman->PushBlendState(resetblendstate);
|
||||
D3D::stateman->PushDepthState(resetdepthstate);
|
||||
D3D::stateman->PushRasterizerState(resetraststate);
|
||||
D3D::stateman->Apply();
|
||||
}
|
||||
|
||||
void Renderer::RestoreAPIState()
|
||||
{
|
||||
// TODO: How much of this is actually needed?
|
||||
// gets us back into a more game-like state.
|
||||
|
||||
// TODO: check whether commenting these lines broke anything
|
||||
// D3D::gfxstate->rastdesc.ScissorEnable = TRUE;
|
||||
UpdateViewport();
|
||||
SetScissorRect();
|
||||
// if (bpmem.zmode.testenable) D3D::gfxstate->depthdesc.DepthEnable = TRUE;
|
||||
// if (bpmem.zmode.updateenable) D3D::gfxstate->depthdesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
SetColorMask();
|
||||
SetLogicOpMode();
|
||||
for (;resets;--resets)
|
||||
{
|
||||
D3D::stateman->PopBlendState();
|
||||
D3D::stateman->PopDepthState();
|
||||
D3D::stateman->PopRasterizerState();
|
||||
D3D::gfxstate->ApplyState();
|
||||
}
|
||||
D3D::gfxstate->rastdesc.ScissorEnable = TRUE;
|
||||
UpdateViewport();
|
||||
SetScissorRect();
|
||||
if (bpmem.zmode.testenable) D3D::gfxstate->depthdesc.DepthEnable = TRUE;
|
||||
if (bpmem.zmode.updateenable) D3D::gfxstate->depthdesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
SetColorMask();
|
||||
SetLogicOpMode();
|
||||
}
|
||||
|
||||
void Renderer::SetGenerationMode()
|
||||
|
|
|
@ -369,10 +369,10 @@ void Flush()
|
|||
// update alpha only
|
||||
Draw(stride, true);
|
||||
}
|
||||
gfxstate->Reset();
|
||||
|
||||
shader_fail:
|
||||
ResetBuffer();
|
||||
gfxstate->ResetShaderResources();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Reference in New Issue