diff --git a/qrenderdoc/Code/BufferFormatter.cpp b/qrenderdoc/Code/BufferFormatter.cpp index 7a6c01bbc..a0aa46c48 100644 --- a/qrenderdoc/Code/BufferFormatter.cpp +++ b/qrenderdoc/Code/BufferFormatter.cpp @@ -952,8 +952,8 @@ static void FillShaderVarData(ShaderVariable &var, const ShaderConstant &elem, c std::swap(outerCount, innerCount); } - QVariantList objs = GetVariants(GetInterpretedResourceFormat(elem), outerCount, - elem.type.descriptor.matrixByteStride, data, end); + QVariantList objs = + GetVariants(GetInterpretedResourceFormat(elem), elem.type.descriptor, data, end); if(objs.isEmpty()) { @@ -1174,14 +1174,14 @@ inline T readObj(const byte *&data, const byte *end, bool &ok) return ret; } -QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t rowByteStride, +QVariantList GetVariants(ResourceFormat format, const ShaderVariableDescriptor &varDesc, const byte *&data, const byte *end) { QVariantList ret; bool ok = true; - if(rowFormat.type == ResourceFormatType::R5G5B5A1) + if(format.type == ResourceFormatType::R5G5B5A1) { uint16_t packed = readObj(data, end, ok); @@ -1190,14 +1190,14 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r ret.push_back((float)((packed >> 10) & 0x1f) / 31.0f); ret.push_back(((packed & 0x8000) > 0) ? 1.0f : 0.0f); - if(rowFormat.BGRAOrder()) + if(format.BGRAOrder()) { QVariant tmp = ret[2]; ret[2] = ret[0]; ret[0] = tmp; } } - else if(rowFormat.type == ResourceFormatType::R5G6B5) + else if(format.type == ResourceFormatType::R5G6B5) { uint16_t packed = readObj(data, end, ok); @@ -1205,14 +1205,14 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r ret.push_back((float)((packed >> 5) & 0x3f) / 63.0f); ret.push_back((float)((packed >> 11) & 0x1f) / 31.0f); - if(rowFormat.BGRAOrder()) + if(format.BGRAOrder()) { QVariant tmp = ret[2]; ret[2] = ret[0]; ret[0] = tmp; } } - else if(rowFormat.type == ResourceFormatType::R4G4B4A4) + else if(format.type == ResourceFormatType::R4G4B4A4) { uint16_t packed = readObj(data, end, ok); @@ -1221,17 +1221,17 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r ret.push_back((float)((packed >> 8) & 0xf) / 15.0f); ret.push_back((float)((packed >> 12) & 0xf) / 15.0f); - if(rowFormat.BGRAOrder()) + if(format.BGRAOrder()) { QVariant tmp = ret[2]; ret[2] = ret[0]; ret[0] = tmp; } } - else if(rowFormat.type == ResourceFormatType::R10G10B10A2) + else if(format.type == ResourceFormatType::R10G10B10A2) { // allow for vectors of this format - for raw buffer viewer - for(int i = 0; i < int(rowFormat.compCount / 4); i++) + for(int i = 0; i < int(format.compCount / 4); i++) { uint32_t packed = readObj(data, end, ok); @@ -1240,29 +1240,29 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r uint32_t b = (packed >> 20) & 0x3ff; uint32_t a = (packed >> 30) & 0x003; - if(rowFormat.BGRAOrder()) + if(format.BGRAOrder()) { uint32_t tmp = b; b = r; r = tmp; } - if(rowFormat.compType == CompType::UInt) + if(format.compType == CompType::UInt) { ret.push_back(r); ret.push_back(g); ret.push_back(b); ret.push_back(a); } - else if(rowFormat.compType == CompType::UScaled) + else if(format.compType == CompType::UScaled) { ret.push_back((float)r); ret.push_back((float)g); ret.push_back((float)b); ret.push_back((float)a); } - else if(rowFormat.compType == CompType::SInt || rowFormat.compType == CompType::SScaled || - rowFormat.compType == CompType::SNorm) + else if(format.compType == CompType::SInt || format.compType == CompType::SScaled || + format.compType == CompType::SNorm) { int ir, ig, ib, ia; @@ -1288,21 +1288,21 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r else ia = ((int)a) - 4; - if(rowFormat.compType == CompType::SInt) + if(format.compType == CompType::SInt) { ret.push_back(ir); ret.push_back(ig); ret.push_back(ib); ret.push_back(ia); } - else if(rowFormat.compType == CompType::SScaled) + else if(format.compType == CompType::SScaled) { ret.push_back((float)ir); ret.push_back((float)ig); ret.push_back((float)ib); ret.push_back((float)ia); } - else if(rowFormat.compType == CompType::SNorm) + else if(format.compType == CompType::SNorm) { if(ir == -512) ir = -511; @@ -1328,7 +1328,7 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r } } } - else if(rowFormat.type == ResourceFormatType::R11G11B10) + else if(format.type == ResourceFormatType::R11G11B10) { uint32_t packed = readObj(data, end, ok); @@ -1381,86 +1381,89 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r { const byte *base = data; + uint32_t rowCount = varDesc.rows; + uint32_t colCount = varDesc.columns; + for(uint32_t row = 0; row < qMax(rowCount, 1U); row++) { - const byte *rowStart = base + row * rowByteStride; - - if(data < rowStart) - data = rowStart; - - for(int i = 0; i < rowFormat.compCount; i++) + for(uint32_t col = 0; col < qMax(colCount, 1U); col++) { - if(rowFormat.compType == CompType::Float) + if(varDesc.rowMajorStorage || rowCount == 1) + data = base + row * varDesc.matrixByteStride + col * format.compByteWidth; + else + data = base + col * varDesc.matrixByteStride + row * format.compByteWidth; + + if(format.compType == CompType::Float) { - if(rowFormat.compByteWidth == 8) + if(format.compByteWidth == 8) ret.push_back(readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 4) + else if(format.compByteWidth == 4) ret.push_back(readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) ret.push_back(RENDERDOC_HalfToFloat(readObj(data, end, ok))); } - else if(rowFormat.compType == CompType::SInt) + else if(format.compType == CompType::SInt) { - if(rowFormat.compByteWidth == 8) + if(format.compByteWidth == 8) ret.push_back((qlonglong)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 4) + else if(format.compByteWidth == 4) ret.push_back((int)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) ret.push_back((int)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 1) + else if(format.compByteWidth == 1) ret.push_back((int)readObj(data, end, ok)); } - else if(rowFormat.compType == CompType::UInt) + else if(format.compType == CompType::UInt) { - if(rowFormat.compByteWidth == 8) + if(format.compByteWidth == 8) ret.push_back((qulonglong)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 4) + else if(format.compByteWidth == 4) ret.push_back((uint32_t)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) ret.push_back((uint32_t)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 1) + else if(format.compByteWidth == 1) ret.push_back((uint32_t)readObj(data, end, ok)); } - else if(rowFormat.compType == CompType::UScaled) + else if(format.compType == CompType::UScaled) { - if(rowFormat.compByteWidth == 4) + if(format.compByteWidth == 4) ret.push_back((float)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) ret.push_back((float)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 1) + else if(format.compByteWidth == 1) ret.push_back((float)readObj(data, end, ok)); } - else if(rowFormat.compType == CompType::SScaled) + else if(format.compType == CompType::SScaled) { - if(rowFormat.compByteWidth == 4) + if(format.compByteWidth == 4) ret.push_back((float)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) ret.push_back((float)readObj(data, end, ok)); - else if(rowFormat.compByteWidth == 1) + else if(format.compByteWidth == 1) ret.push_back((float)readObj(data, end, ok)); } - else if(rowFormat.compType == CompType::Depth) + else if(format.compType == CompType::Depth) { - if(rowFormat.compByteWidth == 4) + if(format.compByteWidth == 4) { // 32-bit depth is native floats ret.push_back(readObj(data, end, ok)); } - else if(rowFormat.compByteWidth == 3) + else if(format.compByteWidth == 3) { // 32-bit depth is normalised, masked against non-stencil bits uint32_t f = readObj(data, end, ok); f &= 0x00ffffff; ret.push_back((float)f / (float)0x00ffffff); } - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) { // 16-bit depth is normalised float f = (float)readObj(data, end, ok); ret.push_back(f / (float)0x0000ffff); } } - else if(rowFormat.compType == CompType::Double) + else if(format.compType == CompType::Double) { ret.push_back(readObj(data, end, ok)); } @@ -1468,25 +1471,25 @@ QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t r { // unorm/snorm - if(rowFormat.compByteWidth == 4) + if(format.compByteWidth == 4) { // should never hit this - no 32bit unorm/snorm type qCritical() << "Unexpected 4-byte unorm/snorm value"; ret.push_back((float)readObj(data, end, ok) / (float)0xffffffff); } - else if(rowFormat.compByteWidth == 2) + else if(format.compByteWidth == 2) { - ret.push_back(interpret(rowFormat, readObj(data, end, ok))); + ret.push_back(interpret(format, readObj(data, end, ok))); } - else if(rowFormat.compByteWidth == 1) + else if(format.compByteWidth == 1) { - ret.push_back(interpret(rowFormat, readObj(data, end, ok))); + ret.push_back(interpret(format, readObj(data, end, ok))); } } } } - if(rowFormat.BGRAOrder()) + if(format.BGRAOrder()) { QVariant tmp = ret[2]; ret[2] = ret[0]; diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 01aad8947..42b54ee76 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -99,7 +99,7 @@ public: static QString DeclarePaddingBytes(uint32_t bytes); }; -QVariantList GetVariants(ResourceFormat rowFormat, uint32_t rowCount, uint32_t rowByteStride, +QVariantList GetVariants(ResourceFormat format, const ShaderVariableDescriptor &varDesc, const byte *&data, const byte *end); ResourceFormat GetInterpretedResourceFormat(const ShaderConstant &elem); void SetInterpretedResourceFormat(ShaderConstant &elem, ResourceFormatType interpretType, diff --git a/qrenderdoc/Windows/BufferViewer.cpp b/qrenderdoc/Windows/BufferViewer.cpp index 7af117950..b337cffd3 100644 --- a/qrenderdoc/Windows/BufferViewer.cpp +++ b/qrenderdoc/Windows/BufferViewer.cpp @@ -826,9 +826,8 @@ public: else { const ShaderConstant &el = elementForColumn(section); - const BufferElementProperties &prop = propForColumn(section); - if(prop.format.compCount == 1 || role == columnGroupRole) + if(el.type.descriptor.columns == 1 || role == columnGroupRole) return el.name; QChar comps[] = {QLatin1Char('x'), QLatin1Char('y'), QLatin1Char('z'), QLatin1Char('w')}; @@ -949,8 +948,7 @@ public: // only slightly wasteful, we need to fetch all variants together // since some formats are packed and can't be read individually - QVariantList list = GetVariants(prop.format, el.type.descriptor.rows, - el.type.descriptor.matrixByteStride, data, end); + QVariantList list = GetVariants(prop.format, el.type.descriptor, data, end); if(!list.isEmpty()) { @@ -1073,8 +1071,7 @@ public: // only slightly wasteful, we need to fetch all variants together // since some formats are packed and can't be read individually - QVariantList list = GetVariants(prop.format, el.type.descriptor.rows, - el.type.descriptor.matrixByteStride, data, end); + QVariantList list = GetVariants(prop.format, el.type.descriptor, data, end); int comp = componentForIndex(col); @@ -1085,12 +1082,7 @@ public: if(rowdim == 1) { - QVariant v; - - if(el.type.descriptor.rowMajorStorage) - v = list[comp]; - else - v = list[comp * rowdim]; + QVariant v = list[comp]; if(el.type.descriptor.pointerTypeID != ~0U) { @@ -1116,10 +1108,7 @@ public: if(r > 0) ret += lit("\n"); - if(el.type.descriptor.rowMajorStorage) - ret += interpretVariant(list[comp + r * coldim], el, prop); - else - ret += interpretVariant(list[r + comp * rowdim], el, prop); + ret += interpretVariant(list[r * coldim + comp], el, prop); } return ret; @@ -1277,9 +1266,9 @@ private: for(int i = 0; i < config.columns.count(); i++) { - const BufferElementProperties &prop = config.props[i]; + uint32_t columnCount = config.columns[i].type.descriptor.columns; - for(uint32_t c = 0; c < prop.format.compCount; c++) + for(uint32_t c = 0; c < columnCount; c++) { columnLookup.push_back(i); componentLookup.push_back((int)c); @@ -1375,9 +1364,9 @@ void CacheDataForIteration(QVector &cache, const rdcarray 0) d.instIdx = inst / prop.instancerate; @@ -1416,6 +1405,7 @@ static void ConfigureColumnsForShader(ICaptureContext &ctx, const ShaderReflecti BufferElementProperties p; f.name = !sig.varName.isEmpty() ? sig.varName : sig.semanticIdxName; + f.type.descriptor.rows = 1; f.type.descriptor.columns = sig.compCount; p.buffer = 0; @@ -1451,7 +1441,7 @@ static void ConfigureColumnsForShader(ICaptureContext &ctx, const ShaderReflecti BufferElementProperties &prop = props[i]; ShaderConstant &el = columns[i]; - uint numComps = prop.format.compCount; + uint numComps = el.type.descriptor.columns; uint elemSize = prop.format.compType == CompType::Double ? 8U : 4U; if(ctx.CurPipelineState().HasAlignedPostVSData( @@ -1842,7 +1832,7 @@ static void UnrollConstant(rdcstr prefix, const ShaderConstant &constant, c.name = QFormatStr("%1[%2]").arg(baseName).arg(a); columns.push_back(c); props.push_back(prop); - c.byteOffset += prop.format.ElementSize() * constant.type.descriptor.rows; + c.byteOffset += constant.type.descriptor.arrayByteStride; } } else @@ -2229,8 +2219,8 @@ void BufferViewer::meshHeaderMenu(MeshDataStage stage, const QPoint &pos) m_CurView = tableForStage(stage); m_ContextColumn = modelForStage(stage)->elementIndexForColumn(col); - m_SelectSecondAlphaColumn->setEnabled(modelForStage(stage)->propForColumn(col).format.compCount == - 4); + m_SelectSecondAlphaColumn->setEnabled( + modelForStage(stage)->elementForColumn(col).type.descriptor.columns == 4); m_HeaderMenu->popup(tableForStage(stage)->horizontalHeader()->mapToGlobal(pos)); } @@ -2484,9 +2474,8 @@ void BufferViewer::OnEventChanged(uint32_t eventId) // calculate tight stride buf->stride = 0; - for(int i = 0; i < bufdata->vsinConfig.props.count(); i++) - buf->stride += bufdata->vsinConfig.props[i].format.ElementSize() * - bufdata->vsinConfig.columns[i].type.descriptor.rows; + for(int i = 0; i < bufdata->vsinConfig.columns.count(); i++) + buf->stride += bufdata->vsinConfig.columns[i].type.descriptor.arrayByteStride; buf->stride = qMax((size_t)1, buf->stride); @@ -2729,11 +2718,11 @@ void BufferViewer::calcBoundingData(CalcBoundingBoxData &bbox) { FloatVector maxvec(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX); - if(s.props[i].format.compCount == 1) + if(s.columns[i].type.descriptor.columns == 1) maxvec.y = maxvec.z = maxvec.w = 0.0; - else if(s.props[i].format.compCount == 2) + else if(s.columns[i].type.descriptor.columns == 2) maxvec.z = maxvec.w = 0.0; - else if(s.props[i].format.compCount == 3) + else if(s.columns[i].type.descriptor.columns == 3) maxvec.w = 0.0; minOutputList.push_back(maxvec); @@ -2775,8 +2764,7 @@ void BufferViewer::calcBoundingData(CalcBoundingBoxData &bbox) if(!prop->perinstance) bytes += d.stride * idx; - QVariantList list = GetVariants(prop->format, el->type.descriptor.rows, - el->type.descriptor.matrixByteStride, bytes, d.end); + QVariantList list = GetVariants(prop->format, el->type.descriptor, bytes, d.end); for(int comp = 0; comp < 4 && comp < list.count(); comp++) { @@ -2834,7 +2822,7 @@ void BufferViewer::UI_UpdateBoundingBoxLabels(int compCount) int posEl = model->posColumn(); if(posEl >= 0 && posEl < model->getConfig().columns.count()) { - compCount = model->getConfig().props[posEl].format.compCount; + compCount = model->getConfig().columns[posEl].type.descriptor.columns; } } } @@ -3199,7 +3187,7 @@ void BufferViewer::UpdateCurrentMeshConfig() m_Config.maxBounds = bbox.bounds[stage].Max[posEl]; m_Config.showBBox = !isCurrentRasterOut(); - int compCount = model->getConfig().props[posEl].format.compCount; + int compCount = model->getConfig().columns[posEl].type.descriptor.columns; UI_UpdateBoundingBoxLabels(compCount); } @@ -3590,6 +3578,7 @@ void BufferViewer::CalcColumnWidth(int maxNumRows) elem.name = headerText; elem.byteOffset = 0; elem.type.descriptor.rows = maxNumRows; + elem.type.descriptor.columns = 1; bufconfig.columns.clear(); @@ -4027,8 +4016,7 @@ void BufferViewer::exportData(const BufferExport ¶ms) // only slightly wasteful, we need to fetch all variants together // since some formats are packed and can't be read individually - QVariantList list = GetVariants(prop->format, el->type.descriptor.rows, - el->type.descriptor.matrixByteStride, data, end); + QVariantList list = GetVariants(prop->format, el->type.descriptor, data, end); for(int v = 0; v < list.count(); v++) {