mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
DX11 code maintenance, part 2:
Move depth state management from EmuGfxState to Renderer. Call stateman->Apply in Renderer::ApplyState instead of EmuGfxState::ApplyState. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6903 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
e0b757fe6a
commit
50c1baf8de
@ -67,7 +67,7 @@ public:
|
||||
virtual void SetInterlacingMode() = 0;
|
||||
|
||||
virtual void ApplyState() = 0;
|
||||
virtual void UnsetTextures() = 0;
|
||||
virtual void RestoreState() = 0;
|
||||
|
||||
// Real internal resolution:
|
||||
// D3D doesn't support viewports larger than the target size, so we need to resize the target to the viewport size for those.
|
||||
|
@ -40,14 +40,6 @@ EmuGfxState::EmuGfxState() : vertexshader(NULL), vsbytecode(NULL), pixelshader(N
|
||||
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
|
||||
blenddesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||
|
||||
memset(&depthdesc, 0, sizeof(depthdesc));
|
||||
depthdesc.DepthEnable = TRUE;
|
||||
depthdesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
depthdesc.DepthFunc = D3D11_COMPARISON_LESS;
|
||||
depthdesc.StencilEnable = FALSE;
|
||||
depthdesc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||
depthdesc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||
|
||||
// this probably must be changed once multisampling support gets added
|
||||
rastdesc = CD3D11_RASTERIZER_DESC(D3D11_FILL_SOLID, D3D11_CULL_NONE, false, 0, 0.f, 0, false, true, false, false);
|
||||
|
||||
@ -178,17 +170,9 @@ void EmuGfxState::ApplyState()
|
||||
stateman->PushRasterizerState(raststate);
|
||||
SAFE_RELEASE(raststate);
|
||||
|
||||
ID3D11DepthStencilState* depth_state;
|
||||
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__);
|
||||
D3D::stateman->PushDepthState(depth_state);
|
||||
SAFE_RELEASE(depth_state);
|
||||
|
||||
context->PSSetShader(pixelshader, NULL, 0);
|
||||
context->VSSetShader(vertexshader, NULL, 0);
|
||||
|
||||
stateman->Apply();
|
||||
apply_called = true;
|
||||
}
|
||||
|
||||
@ -197,7 +181,6 @@ void EmuGfxState::Reset()
|
||||
if (apply_called)
|
||||
{
|
||||
stateman->PopBlendState();
|
||||
stateman->PopDepthState();
|
||||
stateman->PopRasterizerState();
|
||||
apply_called = false;
|
||||
}
|
||||
|
@ -51,7 +51,6 @@ public:
|
||||
|
||||
|
||||
D3D11_RASTERIZER_DESC rastdesc;
|
||||
D3D11_DEPTH_STENCIL_DESC depthdesc;
|
||||
|
||||
float psconstants[C_PENVCONST_END*4];
|
||||
float vsconstants[C_VENVCONST_END*4];
|
||||
|
@ -68,6 +68,7 @@ ID3D11RasterizerState* resetraststate = NULL;
|
||||
struct
|
||||
{
|
||||
D3D11_SAMPLER_DESC sampdc[8];
|
||||
D3D11_DEPTH_STENCIL_DESC depthdc;
|
||||
} gx_state;
|
||||
|
||||
bool reset_called = false;
|
||||
@ -345,6 +346,14 @@ Renderer::Renderer()
|
||||
SetupDeviceObjects();
|
||||
|
||||
// Setup GX pipeline state
|
||||
memset(&gx_state.depthdc, 0, sizeof(gx_state.depthdc));
|
||||
gx_state.depthdc.DepthEnable = TRUE;
|
||||
gx_state.depthdc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
|
||||
gx_state.depthdc.DepthFunc = D3D11_COMPARISON_LESS;
|
||||
gx_state.depthdc.StencilEnable = FALSE;
|
||||
gx_state.depthdc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
|
||||
gx_state.depthdc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
|
||||
|
||||
for (unsigned int k = 0;k < 8;k++)
|
||||
{
|
||||
float border[4] = {0.f, 0.f, 0.f, 0.f};
|
||||
@ -1090,6 +1099,15 @@ void Renderer::RestoreAPIState()
|
||||
|
||||
void Renderer::ApplyState()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
ID3D11DepthStencilState* depth_state;
|
||||
hr = D3D::device->CreateDepthStencilState(&gx_state.depthdc, &depth_state);
|
||||
if (SUCCEEDED(hr)) D3D::SetDebugObjectName((ID3D11DeviceChild*)depth_state, "depth-stencil state used to emulate the GX pipeline");
|
||||
else PanicAlert("Failed to create depth state at %s %d\n", __FILE__, __LINE__);
|
||||
D3D::stateman->PushDepthState(depth_state);
|
||||
SAFE_RELEASE(depth_state);
|
||||
|
||||
ID3D11SamplerState* samplerstate[8];
|
||||
for (unsigned int stage = 0; stage < 8; stage++)
|
||||
{
|
||||
@ -1097,7 +1115,7 @@ void Renderer::ApplyState()
|
||||
//if (shader_resources[stage])
|
||||
{
|
||||
if(g_ActiveConfig.iMaxAnisotropy > 0) gx_state.sampdc[stage].Filter = D3D11_FILTER_ANISOTROPIC;
|
||||
HRESULT hr = D3D::device->CreateSamplerState(&gx_state.sampdc[stage], &samplerstate[stage]);
|
||||
hr = D3D::device->CreateSamplerState(&gx_state.sampdc[stage], &samplerstate[stage]);
|
||||
if (FAILED(hr)) PanicAlert("Fail %s %d, stage=%d\n", __FILE__, __LINE__, stage);
|
||||
else D3D::SetDebugObjectName((ID3D11DeviceChild*)samplerstate[stage], "sampler state used to emulate the GX pipeline");
|
||||
}
|
||||
@ -1106,12 +1124,16 @@ void Renderer::ApplyState()
|
||||
D3D::context->PSSetSamplers(0, 8, samplerstate);
|
||||
for (unsigned int stage = 0; stage < 8; stage++)
|
||||
SAFE_RELEASE(samplerstate[stage]);
|
||||
|
||||
D3D::stateman->Apply();
|
||||
}
|
||||
|
||||
void Renderer::UnsetTextures()
|
||||
void Renderer::RestoreState()
|
||||
{
|
||||
ID3D11ShaderResourceView* shader_resources[8] = { NULL };
|
||||
D3D::context->PSSetShaderResources(0, 8, shader_resources);
|
||||
|
||||
D3D::stateman->PopDepthState();
|
||||
}
|
||||
|
||||
void Renderer::SetGenerationMode()
|
||||
@ -1124,15 +1146,15 @@ void Renderer::SetDepthMode()
|
||||
{
|
||||
if (bpmem.zmode.testenable)
|
||||
{
|
||||
D3D::gfxstate->depthdesc.DepthEnable = TRUE;
|
||||
D3D::gfxstate->depthdesc.DepthWriteMask = bpmem.zmode.updateenable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
D3D::gfxstate->depthdesc.DepthFunc = d3dCmpFuncs[bpmem.zmode.func];
|
||||
gx_state.depthdc.DepthEnable = TRUE;
|
||||
gx_state.depthdc.DepthWriteMask = bpmem.zmode.updateenable ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
gx_state.depthdc.DepthFunc = d3dCmpFuncs[bpmem.zmode.func];
|
||||
}
|
||||
else
|
||||
{
|
||||
// if the test is disabled write is disabled too
|
||||
D3D::gfxstate->depthdesc.DepthEnable = FALSE;
|
||||
D3D::gfxstate->depthdesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
gx_state.depthdc.DepthEnable = FALSE;
|
||||
gx_state.depthdc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,9 @@ public:
|
||||
void SetSamplerState(int stage,int texindex);
|
||||
void SetInterlacingMode();
|
||||
|
||||
// TODO: Fix confusing names (see ResetAPIState and RestoreAPIState)
|
||||
void ApplyState();
|
||||
void UnsetTextures();
|
||||
void RestoreState();
|
||||
|
||||
void RenderText(const char* pstr, int left, int top, u32 color);
|
||||
|
||||
|
@ -234,7 +234,7 @@ void VertexManager::vFlush()
|
||||
g_renderer->ApplyState();
|
||||
LoadBuffers();
|
||||
Draw(stride);
|
||||
g_renderer->UnsetTextures();
|
||||
g_renderer->RestoreState();
|
||||
D3D::gfxstate->Reset();
|
||||
|
||||
GFX_DEBUGGER_PAUSE_AT(NEXT_FLUSH, true);
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
|
||||
// No need to implement these in D3D9
|
||||
void ApplyState() {}
|
||||
void UnsetTextures() {}
|
||||
void RestoreState() {}
|
||||
|
||||
void RenderText(const char* pstr, int left, int top, u32 color);
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
|
||||
// No need to implement these in OGL
|
||||
void ApplyState() {}
|
||||
void UnsetTextures() {}
|
||||
void RestoreState() {}
|
||||
|
||||
void RenderText(const char* pstr, int left, int top, u32 color);
|
||||
void DrawDebugInfo();
|
||||
|
Loading…
Reference in New Issue
Block a user