mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-29 21:30:53 +00:00
When opening buffer textures, auto-generate a reasonable buffer format.
This commit is contained in:
@@ -442,6 +442,84 @@ QList<FormatElement> 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 <typename T>
|
||||
inline T readObj(const byte *&data, const byte *end, bool &ok)
|
||||
{
|
||||
|
||||
@@ -83,6 +83,8 @@ public:
|
||||
static QList<FormatElement> 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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user