Tidy up pixel history a bit, move shaders & states into common

This commit is contained in:
baldurk
2014-08-20 23:52:45 +01:00
parent b38e7f20d3
commit f36636998a
4 changed files with 96 additions and 92 deletions
+20
View File
@@ -388,3 +388,23 @@ float4 RENDERDOC_QOResolvePS(float4 vpos : SV_POSITION) : SV_Target0
// http://blog.selfshadow.com/2012/11/12/counting-quads/
// https://github.com/selfshadow/demos/blob/master/QuadShading/QuadShading.fx
////////////////////////////////////////////////////////////////////////////////////////////
cbuffer cb0 : register(b0) { uint2 src_coord; uint2 padding0; };
cbuffer cb1 : register(b1) { uint2 dst_coord; uint copy_stencil; uint padding1; };
Texture2D<float2> depth_src : register(t0);
Texture2D<uint2> stencil_src : register(t1);
RWTexture2D<float2> depth_out : register(u0);
[numthreads(1, 1, 1)]
void RENDERDOC_PixelHistoryUnused()
{
depth_out[dst_coord.xy].rg = float2(-1.0f, -1.0f);
}
[numthreads(1, 1, 1)]
void RENDERDOC_PixelHistoryCopyDepthStencil()
{
depth_out[dst_coord.xy].rg = float2(
depth_src[src_coord.xy].r,
copy_stencil > 0 ? (float)stencil_src[src_coord.xy].g : -1.0f);
}
+21 -89
View File
@@ -3025,44 +3025,12 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
copyStencilSRVDesc.Texture2D.MipLevels = 1;
copyStencilSRVDesc.Texture2D.MostDetailedMip = 0;
string unusedDepthHLSL =
"cbuffer cb0 : register(b0) { uint2 src_coord; uint2 padding0; };\n" \
"cbuffer cb1 : register(b1) { uint2 dst_coord; uint copy_stencil; uint padding1; };\n" \
"Texture2D<float2> depth_src : register(t0);\n" \
"Texture2D<uint2> stencil_src : register(t1);\n" \
"RWTexture2D<float2> depth_out : register(u0);\n" \
"\n" \
"[numthreads(1, 1, 1)]\n" \
"void main()\n";
string copyDepthStencilHLSL = unusedDepthHLSL;
unusedDepthHLSL += "{ depth_out[dst_coord.xy].rg = float2(-1.0f, -1.0f); }";
copyDepthStencilHLSL +=
"{ depth_out[dst_coord.xy].rg = float2(" \
"depth_src[src_coord.xy].r, " \
"copy_stencil > 0 ? (float)stencil_src[src_coord.xy].g : -1.0f); }";
ID3D11ComputeShader *unusedDepthCS = MakeCShader(unusedDepthHLSL.c_str(), "main", "cs_5_0");
ID3D11ComputeShader *copyDepthStencilCS = MakeCShader(copyDepthStencilHLSL.c_str(), "main", "cs_5_0");
ID3D11Buffer *srcxyCBuf = NULL;
ID3D11Buffer *storexyCBuf = NULL;
uint32_t srcxyData[4] = { x, y, 0, 0 };
D3D11_BUFFER_DESC cbufDesc = {
sizeof(uint32_t)*4,
D3D11_USAGE_DEFAULT,
D3D11_BIND_CONSTANT_BUFFER,
0,
0,
0
};
D3D11_SUBRESOURCE_DATA data = { srcxyData, sizeof(uint32_t)*4, sizeof(uint32_t)*4 };
m_pDevice->CreateBuffer(&cbufDesc, &data, &srcxyCBuf);
m_pDevice->CreateBuffer(&cbufDesc, NULL, &storexyCBuf);
ID3D11Buffer *srcxyCBuf = MakeCBuffer((float *)srcxyData, sizeof(srcxyData));
ID3D11Buffer *storexyCBuf = MakeCBuffer((float *)srcxyData, sizeof(srcxyData));
// so we do:
// per sample: orig depth --copy--> depthCopyXXX (created/upsized on demand) --CS pixel copy--> pixstoreDepth
@@ -3123,36 +3091,6 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
for(size_t i=0; i < ARRAY_COUNT(testQueries); i++)
m_pDevice->CreateQuery(&occlDesc, &testQueries[i]);
D3D11_BLEND_DESC nopBlendStateDesc = {0}; // no blending enabled anywhere, 0 write mask
ID3D11BlendState *nopBlendState = NULL;
m_pDevice->CreateBlendState(&nopBlendStateDesc, &nopBlendState);
D3D11_DEPTH_STENCIL_DESC nopDSStateDesc = { // no tests enabled, no writing enabled
FALSE, // DepthEnable;
D3D11_DEPTH_WRITE_MASK_ZERO, // DepthWriteMask;
D3D11_COMPARISON_ALWAYS, // DepthFunc;
FALSE, // StencilEnable;
0, // StencilReadMask;
0, // StencilWriteMask;
{ D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_COMPARISON_ALWAYS }, // FrontFace;
{ D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_COMPARISON_ALWAYS }, // BackFace;
};
ID3D11DepthStencilState *nopDSState = NULL;
m_pDevice->CreateDepthStencilState(&nopDSStateDesc, &nopDSState);
D3D11_DEPTH_STENCIL_DESC allpassDSStateDesc = { // tests enabled to trivially pass, writing enabled
TRUE, // DepthEnable;
D3D11_DEPTH_WRITE_MASK_ALL, // DepthWriteMask;
D3D11_COMPARISON_ALWAYS, // DepthFunc;
TRUE, // StencilEnable;
0xff, // StencilReadMask;
0xff, // StencilWriteMask;
{ D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_COMPARISON_ALWAYS }, // FrontFace;
{ D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_STENCIL_OP_KEEP, D3D11_COMPARISON_ALWAYS }, // BackFace;
};
ID3D11DepthStencilState *allpassDSState = NULL;
m_pDevice->CreateDepthStencilState(&allpassDSStateDesc, &allpassDSState);
m_WrappedDevice->ReplayLog(frameID, 0, events[0], eReplay_WithoutDraw);
D3D11_VIEWPORT viewport = { (float)x, (float)y, 10.0f, 10.0f, 0.0f, 1.0f }; // 1x1 viewport of our destination pixel
@@ -3327,8 +3265,8 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(nopDSState, stencilRef);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(m_DebugRender.NopDepthState, stencilRef);
for(UINT i=0; i < curNumViews; i++)
{
@@ -3501,7 +3439,7 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
if(copyDepthSRV) m_pImmediateContext->CSSetShaderResources(0, 1, copyDepthSRV);
if(copyStencilSRV) m_pImmediateContext->CSSetShaderResources(1, 1, copyStencilSRV);
m_pImmediateContext->CSSetShader(depthBound ? copyDepthStencilCS : unusedDepthCS, NULL, 0);
m_pImmediateContext->CSSetShader(depthBound ? m_DebugRender.PixelHistoryDepthCopyCS : m_DebugRender.PixelHistoryUnusedCS, NULL, 0);
m_pImmediateContext->Dispatch(1, 1, 1);
m_pImmediateContext->CSSetShader(curCS, curCSInst, curCSNumInst);
@@ -3578,7 +3516,7 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
if(copyDepthSRV) m_pImmediateContext->CSSetShaderResources(0, 1, copyDepthSRV);
if(copyStencilSRV) m_pImmediateContext->CSSetShaderResources(1, 1, copyStencilSRV);
m_pImmediateContext->CSSetShader(depthBound ? copyDepthStencilCS : unusedDepthCS, NULL, 0);
m_pImmediateContext->CSSetShader(depthBound ? m_DebugRender.PixelHistoryDepthCopyCS : m_DebugRender.PixelHistoryUnusedCS, NULL, 0);
m_pImmediateContext->Dispatch(1, 1, 1);
m_pImmediateContext->CSSetShader(curCS, curCSInst, curCSNumInst);
@@ -3901,8 +3839,8 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(allpassDSState, stencilRef);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(m_DebugRender.AllPassDepthState, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumViews, newScissors);
@@ -3928,8 +3866,8 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(allpassDSState, stencilRef);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(m_DebugRender.AllPassDepthState, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumViews, newScissors);
@@ -3955,8 +3893,8 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(allpassDSState, stencilRef);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(m_DebugRender.AllPassDepthState, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumViews, newScissors);
@@ -4007,8 +3945,8 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(allpassDSState, stencilRef);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(m_DebugRender.AllPassDepthState, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumScissors, intersectScissors);
@@ -4037,15 +3975,17 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
dsd.StencilEnable = TRUE;
dsd.StencilReadMask = 0xff;
dsd.StencilWriteMask = 0xff;
dsd.FrontFace = allpassDSStateDesc.FrontFace;
dsd.BackFace = allpassDSStateDesc.BackFace;
dsd.FrontFace.StencilDepthFailOp = dsd.FrontFace.StencilFailOp = dsd.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
dsd.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
dsd.BackFace.StencilDepthFailOp = dsd.BackFace.StencilFailOp = dsd.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
dsd.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
m_pDevice->CreateDepthStencilState(&dsd, &newDS);
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(newDS, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumViews, newScissors);
@@ -4077,7 +4017,7 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
m_WrappedDevice->ReplayLog(frameID, 0, events[i], eReplay_WithoutDraw);
m_pImmediateContext->PSSetShader(m_DebugRender.OverlayPS, NULL, 0);
m_pImmediateContext->OMSetBlendState(nopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetBlendState(m_DebugRender.NopBlendState, blendFactor, curSample);
m_pImmediateContext->OMSetDepthStencilState(newDS, stencilRef);
m_pImmediateContext->RSSetState(newRS);
m_pImmediateContext->RSSetScissorRects(curNumViews, newScissors);
@@ -4201,9 +4141,6 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
for(size_t i=0; i < ARRAY_COUNT(testQueries); i++)
SAFE_RELEASE(testQueries[i]);
SAFE_RELEASE(nopBlendState);
SAFE_RELEASE(nopDSState);
SAFE_RELEASE(pixstore);
SAFE_RELEASE(pixstoreDepthReadback);
@@ -4224,10 +4161,5 @@ vector<PixelModification> D3D11DebugManager::PixelHistory(uint32_t frameID, vect
SAFE_RELEASE(depthCopyD16);
SAFE_RELEASE(depthCopyD16_DepthSRV);
SAFE_RELEASE(unusedDepthCS);
SAFE_RELEASE(copyDepthStencilCS);
SAFE_RELEASE(srcxyCBuf);
SAFE_RELEASE(storexyCBuf);
return history;
}
+35
View File
@@ -783,6 +783,9 @@ bool D3D11DebugManager::InitDebugRendering()
m_DebugRender.QuadOverdrawPS = MakePShader(displayhlsl.c_str(), "RENDERDOC_QuadOverdrawPS", "ps_5_0");
m_DebugRender.QOResolvePS = MakePShader(displayhlsl.c_str(), "RENDERDOC_QOResolvePS", "ps_5_0");
m_DebugRender.PixelHistoryUnusedCS = MakeCShader(displayhlsl.c_str(), "RENDERDOC_PixelHistoryUnused", "cs_5_0");
m_DebugRender.PixelHistoryDepthCopyCS = MakeCShader(displayhlsl.c_str(), "RENDERDOC_PixelHistoryCopyDepthStencil", "cs_5_0");
string multisamplehlsl = GetEmbeddedResource(multisample_hlsl);
@@ -852,6 +855,16 @@ bool D3D11DebugManager::InitDebugRendering()
{
RDCERR("Failed to create default blendstate %08x", hr);
}
blendDesc.RenderTarget[0].BlendEnable = FALSE;
blendDesc.RenderTarget[0].RenderTargetWriteMask = 0;
hr = m_pDevice->CreateBlendState(&blendDesc, &m_DebugRender.NopBlendState);
if(FAILED(hr))
{
RDCERR("Failed to create nop blendstate %08x", hr);
}
D3D11_RASTERIZER_DESC rastDesc;
RDCEraseEl(rastDesc);
@@ -923,6 +936,28 @@ bool D3D11DebugManager::InitDebugRendering()
{
RDCERR("Failed to create less-equal depthstencilstate %08x", hr);
}
desc.DepthFunc = D3D11_COMPARISON_ALWAYS;
desc.StencilEnable = TRUE;
hr = m_pDevice->CreateDepthStencilState(&desc, &m_DebugRender.AllPassDepthState);
if(FAILED(hr))
{
RDCERR("Failed to create always pass depthstencilstate %08x", hr);
}
desc.DepthEnable = FALSE;
desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
desc.StencilReadMask = desc.StencilWriteMask = 0;
desc.StencilEnable = FALSE;
hr = m_pDevice->CreateDepthStencilState(&desc, &m_DebugRender.NopDepthState);
if(FAILED(hr))
{
RDCERR("Failed to create nop depthstencilstate %08x", hr);
}
}
{
+20 -3
View File
@@ -359,10 +359,13 @@ class D3D11DebugManager
SAFE_RELEASE(OutlineStripVB);
SAFE_RELEASE(RastState);
SAFE_RELEASE(BlendState);
SAFE_RELEASE(NopBlendState);
SAFE_RELEASE(PointSampState);
SAFE_RELEASE(LinearSampState);
SAFE_RELEASE(NoDepthState);
SAFE_RELEASE(LEqualDepthState);
SAFE_RELEASE(NopDepthState);
SAFE_RELEASE(AllPassDepthState);
SAFE_RELEASE(GenericLayout);
SAFE_RELEASE(GenericHomogLayout);
@@ -375,11 +378,24 @@ class D3D11DebugManager
SAFE_RELEASE(MeshVS);
SAFE_RELEASE(MeshGS);
SAFE_RELEASE(MeshPS);
SAFE_RELEASE(FullscreenVS);
SAFE_RELEASE(WireframeVS);
SAFE_RELEASE(WireframeHomogVS);
SAFE_RELEASE(WireframePS);
SAFE_RELEASE(OverlayPS);
SAFE_RELEASE(CopyMSToArrayPS);
SAFE_RELEASE(CopyArrayToMSPS);
SAFE_RELEASE(FloatCopyMSToArrayPS);
SAFE_RELEASE(FloatCopyArrayToMSPS);
SAFE_RELEASE(DepthCopyMSToArrayPS);
SAFE_RELEASE(DepthCopyArrayToMSPS);
SAFE_RELEASE(PixelHistoryUnusedCS);
SAFE_RELEASE(PixelHistoryDepthCopyCS);
SAFE_RELEASE(QuadOverdrawPS);
SAFE_RELEASE(QOResolvePS);
SAFE_RELEASE(tileResultBuff);
SAFE_RELEASE(resultBuff);
SAFE_RELEASE(resultStageBuff);
@@ -424,8 +440,8 @@ class D3D11DebugManager
ID3D11Buffer *PosBuffer, *OutlineStripVB;
ID3D11RasterizerState *RastState;
ID3D11SamplerState *PointSampState, *LinearSampState;
ID3D11BlendState *BlendState;
ID3D11DepthStencilState *NoDepthState, *LEqualDepthState;
ID3D11BlendState *BlendState, *NopBlendState;
ID3D11DepthStencilState *NoDepthState, *LEqualDepthState, *NopDepthState, *AllPassDepthState;
ID3D11InputLayout *GenericLayout, *GenericHomogLayout;
ID3D11Buffer *GenericVSCBuffer;
@@ -438,6 +454,7 @@ class D3D11DebugManager
ID3D11PixelShader *CopyMSToArrayPS, *CopyArrayToMSPS;
ID3D11PixelShader *FloatCopyMSToArrayPS, *FloatCopyArrayToMSPS;
ID3D11PixelShader *DepthCopyMSToArrayPS, *DepthCopyArrayToMSPS;
ID3D11ComputeShader *PixelHistoryUnusedCS, *PixelHistoryDepthCopyCS;
ID3D11PixelShader *QuadOverdrawPS, *QOResolvePS;