Fetch and store array stride with each constant block variable

This commit is contained in:
baldurk
2016-01-07 23:13:32 +01:00
parent a37f9d5242
commit 82faf93a27
6 changed files with 67 additions and 7 deletions
+1
View File
@@ -154,6 +154,7 @@ struct ShaderVariableType
uint32_t cols;
uint32_t elements;
bool32 rowMajorStorage;
uint32_t arrayStride;
rdctype::str name;
} descriptor;
+2 -1
View File
@@ -157,9 +157,10 @@ void Serialiser::Serialise(const char *name, ShaderVariableType &el)
Serialise("", el.descriptor.cols);
Serialise("", el.descriptor.elements);
Serialise("", el.descriptor.rowMajorStorage);
Serialise("", el.descriptor.arrayStride);
Serialise("", el.members);
SIZE_CHECK(ShaderVariableType, 36);
SIZE_CHECK(ShaderVariableType, 40);
}
template<>
+14
View File
@@ -884,6 +884,20 @@ ShaderVariableType MakeShaderVariableType(DXBC::CBufferVariableType type, uint32
ret.descriptor.elements = type.descriptor.elements;
ret.descriptor.name = type.descriptor.name;
ret.descriptor.rowMajorStorage = (type.descriptor.varClass == DXBC::CLASS_MATRIX_ROWS);
uint32_t baseElemSize = (ret.descriptor.type == eVar_Double) ? 8 : 4;
if(ret.descriptor.rowMajorStorage)
{
uint32_t primary = ret.descriptor.rows;
if(primary == 3) primary = 4;
ret.descriptor.arrayStride = baseElemSize*primary*ret.descriptor.cols;
}
else
{
uint32_t primary = ret.descriptor.cols;
if(primary == 3) primary = 4;
ret.descriptor.arrayStride = baseElemSize*primary*ret.descriptor.rows;
}
uint32_t o = offset;
+8 -3
View File
@@ -39,6 +39,7 @@ struct DynShaderVariableType
uint32_t cols;
uint32_t elements;
bool32 rowMajorStorage;
uint32_t arrayStride;
string name;
} descriptor;
@@ -91,6 +92,7 @@ void copy(rdctype::array<ShaderConstant> &outvars, const vector<DynShaderConstan
outvars[i].type.descriptor.cols = invars[i].type.descriptor.cols;
outvars[i].type.descriptor.elements = invars[i].type.descriptor.elements;
outvars[i].type.descriptor.rowMajorStorage = invars[i].type.descriptor.rowMajorStorage;
outvars[i].type.descriptor.arrayStride = invars[i].type.descriptor.arrayStride;
outvars[i].type.descriptor.name = invars[i].type.descriptor.name;
copy(outvars[i].type.members, invars[i].type.members);
}
@@ -411,10 +413,10 @@ void ReconstructVarTree(const GLHookSet &gl, GLenum query, GLuint sepProg, GLuin
GLint numParentBlocks, vector<DynShaderConstant> *parentBlocks,
vector<DynShaderConstant> *defaultBlock)
{
const size_t numProps = 7;
const size_t numProps = 8;
GLenum resProps[numProps] = {
eGL_TYPE, eGL_NAME_LENGTH, eGL_LOCATION, eGL_BLOCK_INDEX, eGL_ARRAY_SIZE, eGL_OFFSET, eGL_IS_ROW_MAJOR,
eGL_TYPE, eGL_NAME_LENGTH, eGL_LOCATION, eGL_BLOCK_INDEX, eGL_ARRAY_SIZE, eGL_OFFSET, eGL_IS_ROW_MAJOR, eGL_ARRAY_STRIDE
};
// GL_LOCATION not valid for buffer variables (it's only used if offset comes back -1, which will never
@@ -422,7 +424,7 @@ void ReconstructVarTree(const GLHookSet &gl, GLenum query, GLuint sepProg, GLuin
if(query == eGL_BUFFER_VARIABLE)
resProps[2] = eGL_OFFSET;
GLint values[numProps] = { -1, -1, -1, -1, -1, -1, -1 };
GLint values[numProps] = { -1, -1, -1, -1, -1, -1, -1, -1 };
gl.glGetProgramResourceiv(sepProg, query, varIdx, numProps, resProps, numProps, NULL, values);
DynShaderConstant var;
@@ -632,6 +634,7 @@ void ReconstructVarTree(const GLHookSet &gl, GLenum query, GLuint sepProg, GLuin
}
var.type.descriptor.rowMajorStorage = (values[6] > 0);
var.type.descriptor.arrayStride = values[7];
var.name.resize(values[1]-1);
gl.glGetProgramResourceName(sepProg, query, varIdx, values[1], NULL, &var.name[0]);
@@ -809,6 +812,7 @@ void MakeShaderReflection(const GLHookSet &gl, GLenum shadType, GLuint sepProg,
res.variableType.descriptor.cols = 4;
res.variableType.descriptor.elements = 0;
res.variableType.descriptor.rowMajorStorage = false;
res.variableType.descriptor.arrayStride = 0;
// float samplers
if(values[0] == eGL_SAMPLER_BUFFER)
@@ -1385,6 +1389,7 @@ void MakeShaderReflection(const GLHookSet &gl, GLenum shadType, GLuint sepProg,
res.variableType.descriptor.cols = 0;
res.variableType.descriptor.elements = len;
res.variableType.descriptor.rowMajorStorage = false;
res.variableType.descriptor.arrayStride = 0;
res.variableType.descriptor.name = "buffer";
res.variableType.descriptor.type = eVar_UInt;
res.bindPoint = (int32_t)rwresources.size();
@@ -2367,13 +2367,24 @@ void MakeConstantBlockVariables(SPVTypeData *type, rdctype::array<ShaderConstant
{
SPVTypeData *t = type->children[i].first;
cblock[i].name = type->children[i].second;
// TODO do we need to fill these out?
cblock[i].reg.vec = 0;
cblock[i].reg.comp = 0;
for(size_t d=0; d < type->childDecorations[i].size(); d++)
{
if(type->childDecorations[i][d].decoration == spv::DecorationOffset)
{
uint32_t byteOffset = type->childDecorations[i][d].val;
RDCASSERT(byteOffset%4 == 0); // assume uint32_t aligned
byteOffset /= 4;
cblock[i].reg.vec = byteOffset/4;
cblock[i].reg.comp = byteOffset%4;
break;
}
}
string suffix = "";
cblock[i].type.descriptor.elements = 1;
cblock[i].type.descriptor.arrayStride = 0;
if(t->type == SPVTypeData::eArray)
{
@@ -2387,6 +2398,28 @@ void MakeConstantBlockVariables(SPVTypeData *type, rdctype::array<ShaderConstant
suffix += StringFormat::Fmt("[%u]", t->arraySize);
cblock[i].type.descriptor.elements = t->arraySize;
}
bool foundArrayStride = false;
for(size_t d=0; d < type->childDecorations[i].size(); d++)
{
if(type->childDecorations[i][d].decoration == spv::DecorationArrayStride)
{
cblock[i].type.descriptor.arrayStride = type->childDecorations[i][d].val;
foundArrayStride = true;
break;
}
}
for(size_t d=0; !foundArrayStride && t->decorations && d < t->decorations->size(); d++)
{
if((*t->decorations)[d].decoration == spv::DecorationArrayStride)
{
cblock[i].type.descriptor.arrayStride = (*t->decorations)[d].val;
break;
}
}
t = t->baseType;
}
@@ -2405,8 +2438,13 @@ void MakeConstantBlockVariables(SPVTypeData *type, rdctype::array<ShaderConstant
cblock[i].type.descriptor.rowMajorStorage = false;
for(size_t d=0; d < type->childDecorations[i].size(); d++)
{
if(type->childDecorations[i][d].decoration == spv::DecorationRowMajor)
{
cblock[i].type.descriptor.rowMajorStorage = true;
break;
}
}
if(t->type == SPVTypeData::eMatrix)
{
+1
View File
@@ -296,6 +296,7 @@ namespace renderdoc
public UInt32 cols;
public UInt32 elements;
public bool rowMajorStorage;
public UInt32 arrayStride;
[CustomMarshalAs(CustomUnmanagedType.UTF8TemplatedString)]
public string name;
};