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.
This commit is contained in:
baldurk
2015-05-22 21:45:31 +02:00
parent 03a3bafaf9
commit 346ce0a778
@@ -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<string, uint32_t> cbufferSlots;
uint32_t maxCBufferSlot = 0;
set<string> 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)
{