Remove some unused fields in DXBC reflection

* These are present in the DXBC file itself but we don't use them
This commit is contained in:
baldurk
2020-06-18 17:22:43 +01:00
parent fc5c58a6c9
commit 2f10c52b0c
8 changed files with 48 additions and 120 deletions
@@ -617,7 +617,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 4 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = details.texWidth;
d[1] = details.texHeight;
@@ -632,13 +632,13 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
}
else if(var.name == "RENDERDOC_YUVDownsampleRate")
{
Vec4u *d = (Vec4u *)(byteData + var.descriptor.offset);
Vec4u *d = (Vec4u *)(byteData + var.offset);
*d = details.YUVDownsampleRate;
}
else if(var.name == "RENDERDOC_YUVAChannels")
{
Vec4u *d = (Vec4u *)(byteData + var.descriptor.offset);
Vec4u *d = (Vec4u *)(byteData + var.offset);
*d = details.YUVAChannels;
}
@@ -647,7 +647,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = cfg.subresource.mip;
}
@@ -662,7 +662,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = cfg.subresource.slice;
}
@@ -677,7 +677,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_INT)
{
int32_t *d = (int32_t *)(byteData + var.descriptor.offset);
int32_t *d = (int32_t *)(byteData + var.offset);
d[0] = cfg.subresource.sample;
}
@@ -692,7 +692,7 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, TexDisplayFlags flag
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = details.texType;
}
@@ -544,7 +544,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 4 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = (uint32_t)resourceDesc.Width;
d[1] = resourceDesc.Height;
@@ -563,13 +563,13 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
}
else if(var.name == "RENDERDOC_YUVDownsampleRate")
{
Vec4u *d = (Vec4u *)(byteData + var.descriptor.offset);
Vec4u *d = (Vec4u *)(byteData + var.offset);
*d = YUVDownsampleRate;
}
else if(var.name == "RENDERDOC_YUVAChannels")
{
Vec4u *d = (Vec4u *)(byteData + var.descriptor.offset);
Vec4u *d = (Vec4u *)(byteData + var.offset);
*d = YUVAChannels;
}
@@ -578,7 +578,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = cfg.subresource.mip;
}
@@ -593,7 +593,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = cfg.subresource.slice;
}
@@ -608,7 +608,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_INT)
{
int32_t *d = (int32_t *)(byteData + var.descriptor.offset);
int32_t *d = (int32_t *)(byteData + var.offset);
d[0] = cfg.subresource.sample;
}
@@ -623,7 +623,7 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture
if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 &&
var.type.descriptor.type == DXBC::VARTYPE_UINT)
{
uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset);
uint32_t *d = (uint32_t *)(byteData + var.offset);
d[0] = resType;
}
@@ -93,10 +93,9 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = dcl.samplerMode == SAMPLER_MODE_COMPARISON ? 2 : 0;
desc.retType = DXBC::RETURN_TYPE_UNKNOWN;
desc.dimension = DXBC::ShaderInputBind::DIM_UNKNOWN;
desc.numSamples = 0;
desc.numComps = 0;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -119,7 +118,6 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = 0;
desc.retType = dcl.resType[0];
switch(dcl.dim)
@@ -154,11 +152,8 @@ DXBC::Reflection *Program::GuessReflection()
break;
default: desc.dimension = DXBC::ShaderInputBind::DIM_UNKNOWN; break;
}
desc.numSamples = dcl.sampleCount;
// can't tell, fxc seems to default to 4
if(desc.dimension == DXBC::ShaderInputBind::DIM_BUFFER)
desc.numSamples = 4;
desc.numComps = 4;
RDCASSERT(desc.dimension != DXBC::ShaderInputBind::DIM_UNKNOWN);
@@ -188,10 +183,9 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = 0;
desc.retType = DXBC::RETURN_TYPE_MIXED;
desc.dimension = DXBC::ShaderInputBind::DIM_BUFFER;
desc.numSamples = 0;
desc.numComps = 0;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -217,10 +211,9 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = 0;
desc.retType = DXBC::RETURN_TYPE_MIXED;
desc.dimension = DXBC::ShaderInputBind::DIM_BUFFER;
desc.numSamples = dcl.stride;
desc.numComps = dcl.stride;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -248,10 +241,9 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = 0;
desc.retType = DXBC::RETURN_TYPE_MIXED;
desc.dimension = DXBC::ShaderInputBind::DIM_BUFFER;
desc.numSamples = dcl.stride;
desc.numComps = dcl.stride;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -274,7 +266,6 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = idx;
desc.bindCount = 1;
desc.flags = 0;
desc.retType = dcl.resType[0];
switch(dcl.dim)
@@ -309,7 +300,7 @@ DXBC::Reflection *Program::GuessReflection()
break;
default: desc.dimension = DXBC::ShaderInputBind::DIM_UNKNOWN; break;
}
desc.numSamples = (uint32_t)-1;
desc.numComps = 4;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -339,10 +330,9 @@ DXBC::Reflection *Program::GuessReflection()
desc.space = dcl.space;
desc.reg = reg;
desc.bindCount = 1;
desc.flags = 1;
desc.retType = DXBC::RETURN_TYPE_UNKNOWN;
desc.dimension = DXBC::ShaderInputBind::DIM_UNKNOWN;
desc.numSamples = 0;
desc.numComps = 0;
HandleResourceArrayIndices(dcl.operand.indices, desc);
@@ -355,11 +345,8 @@ DXBC::Reflection *Program::GuessReflection()
cb.reg = reg;
cb.bindCount = desc.bindCount;
cb.descriptor.name = cb.name;
cb.descriptor.byteSize = numVecs * 4 * sizeof(float);
cb.descriptor.type = DXBC::CBuffer::Descriptor::TYPE_CBUFFER;
cb.descriptor.flags = 0;
cb.descriptor.numVars = numVecs;
bool isArray = desc.bindCount > 1;
if(isArray)
@@ -369,15 +356,12 @@ DXBC::Reflection *Program::GuessReflection()
// information is not stripped.
DXBC::CBufferVariable var;
var.name = cb.name;
var.descriptor.name = cb.name;
var.descriptor.offset = 0;
var.descriptor.flags = D3D_SVF_USED;
var.offset = 0;
var.type.descriptor.varClass = DXBC::VariableClass::CLASS_STRUCT;
var.type.descriptor.type = DXBC::VariableType::VARTYPE_VOID;
var.type.descriptor.rows = 1;
var.type.descriptor.cols = 4;
var.type.descriptor.elements = 1;
var.type.descriptor.members = 1;
var.type.descriptor.bytesize = 4 * sizeof(float);
var.type.descriptor.name = "struct";
cb.variables.push_back(var);
@@ -392,22 +376,12 @@ DXBC::Reflection *Program::GuessReflection()
var.name = StringFormat::Fmt("cb%u_v%u", cb.identifier, v);
var.descriptor.defaultValue.resize(4 * sizeof(float));
var.descriptor.name = var.name;
var.descriptor.offset = 4 * sizeof(float) * v;
var.descriptor.flags = 0;
var.descriptor.startTexture = (uint32_t)-1;
var.descriptor.startSampler = (uint32_t)-1;
var.descriptor.numSamplers = 0;
var.descriptor.numTextures = 0;
var.offset = 4 * sizeof(float) * v;
var.type.descriptor.bytesize = 4 * sizeof(float);
var.type.descriptor.rows = 1;
var.type.descriptor.cols = 4;
var.type.descriptor.elements = 0;
var.type.descriptor.members = 0;
var.type.descriptor.type = DXBC::VARTYPE_FLOAT;
var.type.descriptor.varClass = DXBC::CLASS_VECTOR;
var.type.descriptor.name = TypeName(var.type.descriptor);
+2 -19
View File
@@ -239,7 +239,6 @@ struct ShaderInputBind
uint32_t reg;
uint32_t bindCount;
uint32_t flags;
DXBC::ResourceRetType retType;
enum Dimension
@@ -258,7 +257,7 @@ struct ShaderInputBind
DIM_BUFFEREX,
} dimension;
uint32_t numSamples;
uint32_t numComps;
};
struct CBufferVariable;
@@ -284,7 +283,6 @@ struct CBufferVariableType
uint32_t rows;
uint32_t cols;
uint32_t elements;
uint32_t members;
uint32_t bytesize;
rdcstr name;
} descriptor;
@@ -298,18 +296,7 @@ struct CBufferVariableType
struct CBufferVariable
{
rdcstr name;
struct
{
rdcstr name;
uint32_t offset; // offset in parent (cbuffer or nested struct)
uint32_t flags;
rdcarray<uint8_t> defaultValue;
uint32_t startTexture; // first texture
uint32_t numTextures;
uint32_t startSampler; // first sampler
uint32_t numSamplers;
} descriptor;
uint32_t offset; // offset in parent (cbuffer or nested struct)
// type details of this variable
CBufferVariableType type;
@@ -326,8 +313,6 @@ struct CBuffer
struct Descriptor
{
rdcstr name;
enum Type
{
TYPE_CBUFFER = 0,
@@ -336,9 +321,7 @@ struct CBuffer
TYPE_RESOURCE_BIND_INFO,
} type;
uint32_t numVars;
uint32_t byteSize;
uint32_t flags;
} descriptor;
rdcarray<CBufferVariable> variables;
@@ -397,7 +397,6 @@ CBufferVariableType DXBCContainer::ParseRDEFType(const RDEFHeader *h, const byte
ret.descriptor.varClass = (VariableClass)type->varClass;
ret.descriptor.cols = type->cols;
ret.descriptor.elements = type->numElems;
ret.descriptor.members = type->numMembers;
ret.descriptor.rows = type->rows;
ret.descriptor.type = (VariableType)type->varType;
@@ -443,17 +442,9 @@ CBufferVariableType DXBCContainer::ParseRDEFType(const RDEFHeader *h, const byte
v.name = (const char *)(chunkContents + members[j].nameOffset);
v.type = ParseRDEFType(h, chunkContents, members[j].typeOffset);
v.descriptor.offset = members[j].memberOffset;
v.offset = members[j].memberOffset;
ret.descriptor.bytesize = v.descriptor.offset + v.type.descriptor.bytesize;
// N/A
v.descriptor.flags = 0;
v.descriptor.startTexture = 0;
v.descriptor.numTextures = 0;
v.descriptor.startSampler = 0;
v.descriptor.numSamplers = 0;
v.descriptor.defaultValue.clear();
ret.descriptor.bytesize = v.offset + v.type.descriptor.bytesize;
ret.members.push_back(v);
}
@@ -895,22 +886,16 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
desc.space = h->targetVersion >= 0x501 ? res->space : 0;
desc.reg = res->bindPoint;
desc.bindCount = res->bindCount;
desc.flags = res->flags;
desc.retType = (DXBC::ResourceRetType)res->retType;
desc.dimension = (ShaderInputBind::Dimension)res->dimension;
desc.numSamples = res->sampleCount;
// Bindless resources report a bind count of 0 from the shader bytecode, but many other
// places in this codebase assume ~0U means bindless. Patch it up now.
if(h->targetVersion >= 0x501 && desc.bindCount == 0)
desc.bindCount = ~0U;
if(desc.numSamples == ~0 && desc.retType != RETURN_TYPE_MIXED &&
desc.retType != RETURN_TYPE_UNKNOWN && desc.retType != RETURN_TYPE_CONTINUED)
{
// uint, uint2, uint3, uint4 seem to be in these bits of flags.
desc.numSamples = 1 + ((desc.flags & 0xC) >> 2);
}
// component count seem to be in these lower bits of flags.
desc.numComps = 1 + ((res->flags & 0xC) >> 2);
// for cbuffers the names can be duplicated, so handle this by assuming
// the order will match between binding declaration and cbuffer declaration
@@ -1006,11 +991,8 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
cb.name = (const char *)(chunkContents + cbuf->nameOffset);
cb.descriptor.name = (const char *)(chunkContents + cbuf->nameOffset);
cb.descriptor.byteSize = cbuf->size;
cb.descriptor.type = (CBuffer::Descriptor::Type)cbuf->type;
cb.descriptor.flags = cbuf->flags;
cb.descriptor.numVars = cbuf->variables.count;
cb.variables.reserve(cbuf->variables.count);
@@ -1048,22 +1030,8 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
v.name = (const char *)(chunkContents + var->nameOffset);
v.descriptor.defaultValue.resize(var->size);
if(var->defaultValueOffset && var->defaultValueOffset != ~0U)
{
memcpy(&v.descriptor.defaultValue[0], chunkContents + var->defaultValueOffset, var->size);
}
v.descriptor.name = v.name;
// v.descriptor.bytesize = var->size; // size with cbuffer padding
v.descriptor.offset = var->startOffset;
v.descriptor.flags = var->flags;
v.descriptor.startTexture = (uint32_t)-1;
v.descriptor.startSampler = (uint32_t)-1;
v.descriptor.numSamplers = 0;
v.descriptor.numTextures = 0;
// var->size; // size with cbuffer padding
v.offset = var->startOffset;
v.type = ParseRDEFType(h, chunkContents, var->typeOffset);
@@ -1098,7 +1066,7 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
else
{
RDCDEBUG("Unused information, buffer %d: %s", cb.descriptor.type,
cb.descriptor.name.c_str());
(const char *)(chunkContents + cbuf->nameOffset));
}
}
}
@@ -1416,12 +1384,10 @@ DXBCContainer::DXBCContainer(const void *ByteCode, size_t ByteCodeLength)
}
// make sure to fetch the dispatch threads dimension from disassembly
if(m_Type == DXBC::ShaderType::Compute)
if(m_Type == DXBC::ShaderType::Compute && m_DXBCByteCode)
{
if(m_DXBCByteCode)
m_DXBCByteCode->FetchComputeProperties(m_Reflection);
else if(m_DXILByteCode)
m_DXILByteCode->FetchComputeProperties(m_Reflection);
}
// initialise debug chunks last
+1 -1
View File
@@ -4648,7 +4648,7 @@ void LookupSRVFormatFromShaderReflection(const DXBC::Reflection &reflection,
bind.retType < DXBC::RETURN_TYPE_MIXED && bind.retType != DXBC::RETURN_TYPE_UNKNOWN)
{
viewFmt.byteWidth = 4;
viewFmt.numComps = bind.numSamples;
viewFmt.numComps = bind.numComps;
if(bind.retType == DXBC::RETURN_TYPE_UNORM)
viewFmt.fmt = CompType::UNorm;
@@ -828,7 +828,7 @@ const DXBC::CBufferVariable *FindCBufferVar(const uint32_t minOffset, const uint
for(const DXBC::CBufferVariable &v : variables)
{
// absolute byte offset of this variable in the cbuffer
const uint32_t voffs = byteOffset + v.descriptor.offset;
const uint32_t voffs = byteOffset + v.offset;
// does minOffset-maxOffset reside in this variable? We don't handle the case where the range
// crosses a variable (and I don't think FXC emits that anyway).
@@ -1136,7 +1136,7 @@ rdcstr Operand::toString(const DXBC::Reflection *reflection, ToString flags) con
}
// rebase swizzle if necessary
uint32_t vecOffset = (var->descriptor.offset & 0xf);
uint32_t vecOffset = (var->offset & 0xf);
if(vecOffset > 0)
{
for(int i = 0; i < 4; i++)
@@ -1658,6 +1658,12 @@ bool Program::ExtractDecl(uint32_t *&tokenStream, Declaration &retDecl, bool fri
retDecl.str += "_";
retDecl.str += ToStr(retDecl.dim);
if(retDecl.sampleCount > 0)
{
retDecl.str += "(";
retDecl.str += ToStr(retDecl.sampleCount);
retDecl.str += ")";
}
retDecl.str += " ";
retDecl.str += "(";
@@ -96,7 +96,7 @@ static ShaderConstant MakeConstantBufferVariable(const DXBC::CBufferVariable &va
ShaderConstant ret;
ret.name = var.name;
ret.byteOffset = var.descriptor.offset;
ret.byteOffset = var.offset;
ret.defaultValue = 0;
ret.type = MakeShaderVariableType(var.type);
@@ -150,7 +150,7 @@ static void MakeResourceList(bool srv, DXBC::DXBCContainer *dxbc,
r.retType != DXBC::RETURN_TYPE_CONTINUED)
{
res.variableType.descriptor.rows = 1;
res.variableType.descriptor.columns = (uint8_t)r.numSamples;
res.variableType.descriptor.columns = (uint8_t)r.numComps;
res.variableType.descriptor.elements = 1;
rdcstr name;
@@ -166,8 +166,8 @@ static void MakeResourceList(bool srv, DXBC::DXBCContainer *dxbc,
default: name = "unknown"; break;
}
if(r.numSamples > 1)
name += StringFormat::Fmt("%u", r.numSamples);
if(r.numComps > 1)
name += StringFormat::Fmt("%u", r.numComps);
res.variableType.descriptor.name = name;
}
@@ -316,11 +316,10 @@ void MakeShaderReflection(DXBC::DXBCContainer *dxbc, ShaderReflection *refl,
uint32_t numInterfaces = 0;
for(size_t i = 0; i < dxbc->GetReflection()->Interfaces.variables.size(); i++)
numInterfaces =
RDCMAX(dxbc->GetReflection()->Interfaces.variables[i].descriptor.offset + 1, numInterfaces);
numInterfaces = RDCMAX(dxbc->GetReflection()->Interfaces.variables[i].offset + 1, numInterfaces);
refl->interfaces.resize(numInterfaces);
for(size_t i = 0; i < dxbc->GetReflection()->Interfaces.variables.size(); i++)
refl->interfaces[dxbc->GetReflection()->Interfaces.variables[i].descriptor.offset] =
refl->interfaces[dxbc->GetReflection()->Interfaces.variables[i].offset] =
dxbc->GetReflection()->Interfaces.variables[i].name;
}