From 346ce0a778e72365347c525650d842e6d356af48 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 22 May 2015 21:45:31 +0200 Subject: [PATCH] Handle case where two cbuffers have identical names, assume same order * Normally the cbuffers when listed in resources (to give the bind point info) and the cbuffers listed with their variables are not necessarily in the same order, so we match them up by name. It's possible to get multiple cbuffers with the same name though, so in this case we just have to assume they come in the same order in both lists. * We do this by appending _s to each duplicate name (so handling many duplicates) in both iterations. --- .../driver/d3d11/shaders/dxbc_inspect.cpp | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/d3d11/shaders/dxbc_inspect.cpp b/renderdoc/driver/d3d11/shaders/dxbc_inspect.cpp index 8c6cc9b8f..c01cee2ed 100644 --- a/renderdoc/driver/d3d11/shaders/dxbc_inspect.cpp +++ b/renderdoc/driver/d3d11/shaders/dxbc_inspect.cpp @@ -520,9 +520,16 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength) m_Resources.reserve(h->resources.count); + // we have to use this map to match up cbuffers to their bind point, as + // it's not guaranteed that the resources and cbuffers will come in the + // same order. However it's possible for two cbuffers to have the same + // name, so in that case we assume they will come in matching order + // and just append _ to subsequent cbuffers with the same name. map cbufferSlots; uint32_t maxCBufferSlot = 0; + set cbuffernames; + for(int32_t i = 0; i < h->resources.count; i++) { RDEFResource *res = (RDEFResource *)(chunkContents + h->resources.offset + i*sizeof(RDEFResource)); @@ -549,13 +556,22 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength) if(desc.type == ShaderInputBind::TYPE_CBUFFER) { - cbufferSlots[desc.name] = desc.bindPoint; + string cname = desc.name; + + while(cbuffernames.find(cname) != cbuffernames.end()) + cname += "_"; + + cbuffernames.insert(cname); + + cbufferSlots[cname] = desc.bindPoint; maxCBufferSlot = RDCMAX(maxCBufferSlot, desc.bindPoint); } m_Resources.push_back(desc); } + cbuffernames.clear(); + if(h->cbuffers.count > 0) m_CBuffers.resize(maxCBufferSlot+1); @@ -634,10 +650,17 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength) cb.variables.push_back(v); } + string cname = cb.name; + + while(cbuffernames.find(cname) != cbuffernames.end()) + cname += "_"; + + cbuffernames.insert(cname); + if(cb.descriptor.type == CBuffer::Descriptor::TYPE_CBUFFER) { - RDCASSERT(cbufferSlots.find(cb.name) != cbufferSlots.end()); - m_CBuffers[cbufferSlots[cb.name]] = cb; + RDCASSERT(cbufferSlots.find(cname) != cbufferSlots.end()); + m_CBuffers[cbufferSlots[cname]] = cb; } else if(cb.descriptor.type == CBuffer::Descriptor::TYPE_RESOURCE_BIND_INFO) {