diff --git a/qrenderdoc/Code/FormatElement.cpp b/qrenderdoc/Code/FormatElement.cpp index 674d48afc..3a0c9bb7f 100644 --- a/qrenderdoc/Code/FormatElement.cpp +++ b/qrenderdoc/Code/FormatElement.cpp @@ -442,6 +442,84 @@ QList FormatElement::ParseFormatString(const QString &formatStrin return elems; } +QString FormatElement::GenerateTextureBufferFormat(const TextureDescription &tex) +{ + QString baseType; + + QString varName = lit("pixels"); + + uint32_t w = tex.width; + + switch(tex.format.type) + { + case ResourceFormatType::BC1: + case ResourceFormatType::BC2: + case ResourceFormatType::BC3: + case ResourceFormatType::BC4: + case ResourceFormatType::BC5: + case ResourceFormatType::BC6: + case ResourceFormatType::BC7: + case ResourceFormatType::ETC2: + case ResourceFormatType::EAC: + case ResourceFormatType::ASTC: + case ResourceFormatType::PVRTC: + varName = lit("block"); + // display a 4x4 block at a time + w /= 4; + default: break; + } + + switch(tex.format.type) + { + case ResourceFormatType::Regular: + { + if(tex.format.compByteWidth == 1) + baseType = lit("byte"); + else if(tex.format.compByteWidth == 2) + baseType = lit("short"); + else + baseType = lit("int"); + + baseType = QFormatStr("rgb x%1%2").arg(baseType).arg(tex.format.compCount); + + break; + } + // 2x4 byte block, for 64-bit block formats + case ResourceFormatType::BC1: + case ResourceFormatType::BC4: + case ResourceFormatType::ETC2: + case ResourceFormatType::EAC: + case ResourceFormatType::PVRTC: + baseType = lit("row_major xint2x1"); + break; + // 4x4 byte block, for 128-bit block formats + case ResourceFormatType::BC2: + case ResourceFormatType::BC3: + case ResourceFormatType::BC5: + case ResourceFormatType::BC6: + case ResourceFormatType::BC7: + case ResourceFormatType::ASTC: baseType = lit("row_major xint4x1"); break; + case ResourceFormatType::R10G10B10A2: baseType = lit("uintten"); break; + case ResourceFormatType::R11G11B10: baseType = lit("rgb floateleven"); break; + case ResourceFormatType::R5G6B5: + case ResourceFormatType::R5G5B5A1: baseType = lit("xshort"); break; + case ResourceFormatType::R9G9B9E5: baseType = lit("xint"); break; + case ResourceFormatType::R4G4B4A4: baseType = lit("xbyte2"); break; + case ResourceFormatType::R4G4: baseType = lit("xbyte"); break; + case ResourceFormatType::D16S8: + case ResourceFormatType::D24S8: + case ResourceFormatType::D32S8: + case ResourceFormatType::YUV: baseType = lit("xint4"); break; + case ResourceFormatType::S8: + case ResourceFormatType::Undefined: baseType = lit("xbyte"); break; + } + + if(tex.type == TextureType::Buffer) + return QFormatStr("%1 %2;").arg(baseType).arg(varName); + + return QFormatStr("%1 %2[%3];").arg(baseType).arg(varName).arg(w); +} + template inline T readObj(const byte *&data, const byte *end, bool &ok) { diff --git a/qrenderdoc/Code/QRDUtils.h b/qrenderdoc/Code/QRDUtils.h index 2b4a1a3d4..7de3b4805 100644 --- a/qrenderdoc/Code/QRDUtils.h +++ b/qrenderdoc/Code/QRDUtils.h @@ -83,6 +83,8 @@ public: static QList ParseFormatString(const QString &formatString, uint64_t maxLen, bool tightPacking, QString &errors); + static QString GenerateTextureBufferFormat(const TextureDescription &tex); + QVariantList GetVariants(const byte *&data, const byte *end) const; ShaderVariable GetShaderVar(const byte *&data, const byte *end) const; diff --git a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp index 0ec47f03e..10683bd48 100644 --- a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp @@ -1902,7 +1902,8 @@ void D3D11PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in { if(tex->type == TextureType::Buffer) { - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(0, 0, tex->resourceId); + IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer( + 0, 0, tex->resourceId, FormatElement::GenerateTextureBufferFormat(*tex)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); } diff --git a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp index 4f068b4e8..7c54f8b21 100644 --- a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp @@ -1809,7 +1809,8 @@ void D3D12PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in { if(tex->type == TextureType::Buffer) { - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(0, 0, tex->resourceId); + IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer( + 0, 0, tex->resourceId, FormatElement::GenerateTextureBufferFormat(*tex)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); } diff --git a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp index 5ab299e82..9f87a7e2e 100644 --- a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp @@ -2082,7 +2082,8 @@ void GLPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, int c { if(tex->type == TextureType::Buffer) { - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(0, 0, tex->resourceId); + IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer( + 0, 0, tex->resourceId, FormatElement::GenerateTextureBufferFormat(*tex)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); } diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp index cce635283..49f8e12fe 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp @@ -2175,7 +2175,8 @@ void VulkanPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, i { if(tex->type == TextureType::Buffer) { - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(0, 0, tex->resourceId); + IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer( + 0, 0, tex->resourceId, FormatElement::GenerateTextureBufferFormat(*tex)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); } diff --git a/qrenderdoc/Windows/ResourceInspector.cpp b/qrenderdoc/Windows/ResourceInspector.cpp index 897a59a78..817e7da25 100644 --- a/qrenderdoc/Windows/ResourceInspector.cpp +++ b/qrenderdoc/Windows/ResourceInspector.cpp @@ -449,7 +449,8 @@ void ResourceInspector::on_viewContents_clicked() { if(tex->type == TextureType::Buffer) { - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(0, 0, tex->resourceId); + IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer( + 0, 0, tex->resourceId, FormatElement::GenerateTextureBufferFormat(*tex)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); } diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 8fb0ec113..8d9fbba9b 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -3350,80 +3350,9 @@ void TextureViewer::on_viewTexBuffer_clicked() if(texptr) { - QString baseType; - - QString varName = lit("pixels"); - - uint32_t w = texptr->width; - - switch(texptr->format.type) - { - case ResourceFormatType::BC1: - case ResourceFormatType::BC2: - case ResourceFormatType::BC3: - case ResourceFormatType::BC4: - case ResourceFormatType::BC5: - case ResourceFormatType::BC6: - case ResourceFormatType::BC7: - case ResourceFormatType::ETC2: - case ResourceFormatType::EAC: - case ResourceFormatType::ASTC: - case ResourceFormatType::PVRTC: - varName = lit("block"); - // display a 4x4 block at a time - w /= 4; - default: break; - } - - switch(texptr->format.type) - { - case ResourceFormatType::Regular: - { - if(texptr->format.compByteWidth == 1) - baseType = lit("byte"); - else if(texptr->format.compByteWidth == 2) - baseType = lit("short"); - else - baseType = lit("int"); - - baseType = QFormatStr("rgb x%1%2").arg(baseType).arg(texptr->format.compCount); - - break; - } - // 2x4 byte block, for 64-bit block formats - case ResourceFormatType::BC1: - case ResourceFormatType::BC4: - case ResourceFormatType::ETC2: - case ResourceFormatType::EAC: - case ResourceFormatType::PVRTC: - baseType = lit("row_major xint2x1"); - break; - // 4x4 byte block, for 128-bit block formats - case ResourceFormatType::BC2: - case ResourceFormatType::BC3: - case ResourceFormatType::BC5: - case ResourceFormatType::BC6: - case ResourceFormatType::BC7: - case ResourceFormatType::ASTC: baseType = lit("row_major xint4x1"); break; - case ResourceFormatType::R10G10B10A2: baseType = lit("uintten"); break; - case ResourceFormatType::R11G11B10: baseType = lit("rgb floateleven"); break; - case ResourceFormatType::R5G6B5: - case ResourceFormatType::R5G5B5A1: baseType = lit("xshort"); break; - case ResourceFormatType::R9G9B9E5: baseType = lit("xint"); break; - case ResourceFormatType::R4G4B4A4: baseType = lit("xbyte2"); break; - case ResourceFormatType::R4G4: baseType = lit("xbyte"); break; - case ResourceFormatType::D16S8: - case ResourceFormatType::D24S8: - case ResourceFormatType::D32S8: - case ResourceFormatType::YUV: baseType = lit("xint4"); break; - case ResourceFormatType::S8: - case ResourceFormatType::Undefined: baseType = lit("xbyte"); break; - } - - QString format = QFormatStr("%1 %2[%3];").arg(baseType).arg(varName).arg(w); - - IBufferViewer *viewer = m_Ctx.ViewTextureAsBuffer(m_TexDisplay.sliceFace, m_TexDisplay.mip, - texptr->resourceId, format); + IBufferViewer *viewer = + m_Ctx.ViewTextureAsBuffer(m_TexDisplay.sliceFace, m_TexDisplay.mip, texptr->resourceId, + FormatElement::GenerateTextureBufferFormat(*texptr)); m_Ctx.AddDockWindow(viewer->Widget(), DockReference::AddTo, this); }