Make mesh viewer more robust if no ibuffer is bound on indexed draw

This commit is contained in:
baldurk
2017-11-10 18:36:05 +00:00
parent 988121ee65
commit 8133188a4c
5 changed files with 54 additions and 34 deletions
+12 -2
View File
@@ -1453,6 +1453,9 @@ void BufferViewer::OnEventChanged(uint32_t eventID)
guessSecondaryColumn(m_ModelGSOut);
}
// needs to happen here so the mesh config is accurate when highlighting data is cached.
updatePreviewColumns();
m_Ctx.Replay().AsyncInvoke([this, vsinHoriz, vsoutHoriz, gsoutHoriz](IReplayController *r) {
BufferData *buf = NULL;
@@ -1502,8 +1505,6 @@ void BufferViewer::OnEventChanged(uint32_t eventID)
m_ModelVSIn->buffers.push_back(buf);
}
updatePreviewColumns();
INVOKE_MEMFN(RT_UpdateAndDisplay);
m_ModelVSIn->endReset();
@@ -1566,6 +1567,12 @@ void BufferViewer::RT_FetchMeshData(IReplayController *r)
m_ModelVSIn->indices->data = (byte *)indices;
m_ModelVSIn->indices->end = (byte *)(indices + draw->numIndices);
}
else if(draw && (draw->flags & DrawFlags::UseIBuffer))
{
indices = new uint32_t[1];
m_ModelVSIn->indices->data = (byte *)indices;
m_ModelVSIn->indices->end = (byte *)indices;
}
uint32_t maxIndex = 0;
if(draw)
@@ -2103,6 +2110,9 @@ void BufferViewer::updatePreviewColumns()
m_VSInPosition.idxbuf = ib.first;
m_VSInPosition.idxoffs = ib.second + draw->indexOffset * draw->indexByteWidth;
if((draw->flags & DrawFlags::UseIBuffer) && m_VSInPosition.idxByteWidth == 0)
m_VSInPosition.idxByteWidth = 4U;
{
const FormatElement &el = m_ModelVSIn->columns[elIdx];
+15 -11
View File
@@ -2572,20 +2572,23 @@ uint32_t D3D11DebugManager::PickVertex(uint32_t eventID, const MeshDisplay &cfg,
RDCASSERT(cfg.position.idxoffs < 0xffffffff);
D3D11_BUFFER_DESC ibdesc;
ib->GetDesc(&ibdesc);
if(ib)
{
D3D11_BUFFER_DESC ibdesc;
ib->GetDesc(&ibdesc);
D3D11_BOX box;
box.front = 0;
box.back = 1;
box.left = (uint32_t)cfg.position.idxoffs;
box.right = (uint32_t)cfg.position.idxoffs + cfg.position.numVerts * cfg.position.idxByteWidth;
box.top = 0;
box.bottom = 1;
D3D11_BOX box;
box.front = 0;
box.back = 1;
box.left = (uint32_t)cfg.position.idxoffs;
box.right = (uint32_t)cfg.position.idxoffs + cfg.position.numVerts * cfg.position.idxByteWidth;
box.top = 0;
box.bottom = 1;
box.right = RDCMIN(box.right, ibdesc.ByteWidth - (uint32_t)cfg.position.idxoffs);
box.right = RDCMIN(box.right, ibdesc.ByteWidth - (uint32_t)cfg.position.idxoffs);
m_pImmediateContext->CopySubresourceRegion(m_DebugRender.PickIBBuf, 0, 0, 0, 0, ib, 0, &box);
m_pImmediateContext->CopySubresourceRegion(m_DebugRender.PickIBBuf, 0, 0, 0, 0, ib, 0, &box);
}
}
if(m_DebugRender.PickVBBuf == NULL ||
@@ -2629,6 +2632,7 @@ uint32_t D3D11DebugManager::PickVertex(uint32_t eventID, const MeshDisplay &cfg,
}
// unpack and linearise the data
if(vb)
{
FloatVector *vbData = new FloatVector[cfg.position.numVerts];
+1 -1
View File
@@ -4982,7 +4982,7 @@ void D3D11DebugManager::RenderMesh(uint32_t eventID, const vector<MeshFormat> &s
}
m_pImmediateContext->IASetVertexBuffers(0, 2, vbs, str, offs);
if(ibuf)
if(cfg.position.idxByteWidth)
m_pImmediateContext->IASetIndexBuffer(ibuf, ifmt, ioffs);
else
m_pImmediateContext->IASetIndexBuffer(NULL, DXGI_FORMAT_UNKNOWN, NULL);
+24 -18
View File
@@ -5519,18 +5519,21 @@ void D3D12DebugManager::RenderMesh(uint32_t eventID, const vector<MeshFormat> &s
if(PatchList_Count(fmt.topo) > 0)
list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_POINTLIST);
if(fmt.idxByteWidth && fmt.idxbuf != ResourceId())
if(fmt.idxByteWidth)
{
ID3D12Resource *ib =
m_WrappedDevice->GetResourceManager()->GetCurrentAs<ID3D12Resource>(fmt.idxbuf);
if(fmt.idxbuf != ResourceId())
{
ID3D12Resource *ib =
m_WrappedDevice->GetResourceManager()->GetCurrentAs<ID3D12Resource>(fmt.idxbuf);
D3D12_INDEX_BUFFER_VIEW iview;
iview.BufferLocation = ib->GetGPUVirtualAddress() + fmt.idxoffs;
iview.SizeInBytes = UINT(ib->GetDesc().Width - fmt.idxoffs);
iview.Format = fmt.idxByteWidth == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
list->IASetIndexBuffer(&iview);
D3D12_INDEX_BUFFER_VIEW iview;
iview.BufferLocation = ib->GetGPUVirtualAddress() + fmt.idxoffs;
iview.SizeInBytes = UINT(ib->GetDesc().Width - fmt.idxoffs);
iview.Format = fmt.idxByteWidth == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
list->IASetIndexBuffer(&iview);
list->DrawIndexedInstanced(fmt.numVerts, 1, 0, fmt.baseVertex, 0);
list->DrawIndexedInstanced(fmt.numVerts, 1, 0, fmt.baseVertex, 0);
}
}
else
{
@@ -5620,18 +5623,21 @@ void D3D12DebugManager::RenderMesh(uint32_t eventID, const vector<MeshFormat> &s
Vec4f colour(0.8f, 0.8f, 0.0f, 1.0f);
list->SetGraphicsRoot32BitConstants(3, 4, &colour.x, 0);
if(cfg.position.idxByteWidth && cfg.position.idxbuf != ResourceId())
if(cfg.position.idxByteWidth)
{
ID3D12Resource *ib =
m_WrappedDevice->GetResourceManager()->GetCurrentAs<ID3D12Resource>(cfg.position.idxbuf);
if(cfg.position.idxbuf != ResourceId())
{
ID3D12Resource *ib =
m_WrappedDevice->GetResourceManager()->GetCurrentAs<ID3D12Resource>(cfg.position.idxbuf);
D3D12_INDEX_BUFFER_VIEW view;
view.BufferLocation = ib->GetGPUVirtualAddress() + cfg.position.idxoffs;
view.SizeInBytes = UINT(ib->GetDesc().Width - cfg.position.idxoffs);
view.Format = cfg.position.idxByteWidth == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
list->IASetIndexBuffer(&view);
D3D12_INDEX_BUFFER_VIEW view;
view.BufferLocation = ib->GetGPUVirtualAddress() + cfg.position.idxoffs;
view.SizeInBytes = UINT(ib->GetDesc().Width - cfg.position.idxoffs);
view.Format = cfg.position.idxByteWidth == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT;
list->IASetIndexBuffer(&view);
list->DrawIndexedInstanced(cfg.position.numVerts, 1, 0, cfg.position.baseVertex, 0);
list->DrawIndexedInstanced(cfg.position.numVerts, 1, 0, cfg.position.baseVertex, 0);
}
}
else
{
+2 -2
View File
@@ -2978,7 +2978,7 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, CompType typeHint, DebugOve
gl.glEnableVertexAttribArray(0);
gl.glDisableVertexAttribArray(1);
if(postvs.idxbuf != ResourceId())
if(postvs.idxByteWidth)
{
GLenum idxtype = eGL_UNSIGNED_BYTE;
if(postvs.idxByteWidth == 2)
@@ -4811,7 +4811,7 @@ void GLReplay::RenderMesh(uint32_t eventID, const vector<MeshFormat> &secondaryD
GLenum secondarytopo = MakeGLPrimitiveTopology(fmt.topo);
if(fmt.idxbuf != ResourceId())
if(fmt.idxByteWidth)
{
GLuint ib = m_pDriver->GetResourceManager()->GetCurrentResource(fmt.idxbuf).name;
gl.glBindBuffer(eGL_ELEMENT_ARRAY_BUFFER, ib);