diff --git a/qrenderdoc/Code/Interface/QRDInterface.h b/qrenderdoc/Code/Interface/QRDInterface.h index d1b1b6ff9..1b07c3dfd 100644 --- a/qrenderdoc/Code/Interface/QRDInterface.h +++ b/qrenderdoc/Code/Interface/QRDInterface.h @@ -255,9 +255,13 @@ struct ITextureViewer DOCUMENT(R"(Open a texture view, optionally raising this window to the foreground. :param ~renderdoc.ResourceId resourceId: The ID of the texture to view. +:param CompType typeCast: If possible interpret the texture with this type instead of its normal + type. If set to :data:`CompType.Typeless` then no cast is applied, otherwise where allowed the + texture data will be reinterpreted - e.g. from unsigned integers to floats, or to unsigned + normalised values. :param bool focus: ``True`` if the :class:`TextureViewer` should be raised. )"); - virtual void ViewTexture(ResourceId resourceId, bool focus) = 0; + virtual void ViewTexture(ResourceId resourceId, CompType typeCast, bool focus) = 0; DOCUMENT(R"(Highlights the given pixel location in the current texture. :param int x: The X co-ordinate. diff --git a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp index 6660f1e2f..020460a90 100644 --- a/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D11PipelineStateViewer.cpp @@ -1954,6 +1954,7 @@ void D3D11PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in TextureDescription *tex = NULL; BufferDescription *buf = NULL; + CompType typeCast = CompType::Typeless; if(tag.canConvert()) { @@ -1966,6 +1967,7 @@ void D3D11PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in D3D11ViewTag view = tag.value(); tex = m_Ctx.GetTexture(view.res.resourceResourceId); buf = m_Ctx.GetBuffer(view.res.resourceResourceId); + typeCast = view.res.viewFormat.compType; } if(tex) @@ -1982,7 +1984,7 @@ void D3D11PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in if(!m_Ctx.HasTextureViewer()) m_Ctx.ShowTextureViewer(); ITextureViewer *viewer = m_Ctx.GetTextureViewer(); - viewer->ViewTexture(tex->resourceId, true); + viewer->ViewTexture(tex->resourceId, typeCast, true); } return; diff --git a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp index dad74182b..cc55bf31d 100644 --- a/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/D3D12PipelineStateViewer.cpp @@ -1930,6 +1930,7 @@ void D3D12PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in TextureDescription *tex = NULL; BufferDescription *buf = NULL; + CompType typeCast = CompType::Typeless; if(tag.canConvert()) { @@ -1942,6 +1943,7 @@ void D3D12PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in D3D12ViewTag view = tag.value(); tex = m_Ctx.GetTexture(view.res.resourceId); buf = m_Ctx.GetBuffer(view.res.resourceId); + typeCast = view.res.viewFormat.compType; } if(tex) @@ -1958,7 +1960,7 @@ void D3D12PipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, in if(!m_Ctx.HasTextureViewer()) m_Ctx.ShowTextureViewer(); ITextureViewer *viewer = m_Ctx.GetTextureViewer(); - viewer->ViewTexture(tex->resourceId, true); + viewer->ViewTexture(tex->resourceId, typeCast, true); } return; diff --git a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp index a648cf479..bc718a63c 100644 --- a/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/GLPipelineStateViewer.cpp @@ -2204,7 +2204,7 @@ void GLPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, int c if(!m_Ctx.HasTextureViewer()) m_Ctx.ShowTextureViewer(); ITextureViewer *viewer = m_Ctx.GetTextureViewer(); - viewer->ViewTexture(tex->resourceId, true); + viewer->ViewTexture(tex->resourceId, CompType::Typeless, true); } return; diff --git a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp index 3fba6c468..f6b9fbe3b 100644 --- a/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp +++ b/qrenderdoc/Windows/PipelineState/VulkanPipelineStateViewer.cpp @@ -102,6 +102,20 @@ struct VulkanBufferTag Q_DECLARE_METATYPE(VulkanBufferTag); +struct VulkanTextureTag +{ + VulkanTextureTag() { compType = CompType::Typeless; } + VulkanTextureTag(ResourceId id, CompType ty) + { + ID = id; + compType = ty; + } + ResourceId ID; + CompType compType; +}; + +Q_DECLARE_METATYPE(VulkanTextureTag); + VulkanPipelineStateViewer::VulkanPipelineStateViewer(ICaptureContext &ctx, PipelineStateViewer &common, QWidget *parent) : QFrame(parent), ui(new Ui::VulkanPipelineStateViewer), m_Ctx(ctx), m_Common(common) @@ -1176,7 +1190,8 @@ void VulkanPipelineStateViewer::addResourceRow(ShaderReflection *shaderDetails, restype = tex->type; samples = tex->msSamp; - tag = QVariant::fromValue(descriptorBind->resourceResourceId); + tag = QVariant::fromValue(VulkanTextureTag(descriptorBind->resourceResourceId, + descriptorBind->viewFormat.compType)); } // if not a texture, it must be a buffer @@ -2487,7 +2502,8 @@ void VulkanPipelineStateViewer::setState() {slotname, p.imageResourceId, typeName, w, h, d, a, format, QString()}); if(tex) - node->setTag(QVariant::fromValue(p.imageResourceId)); + node->setTag( + QVariant::fromValue(VulkanTextureTag(p.imageResourceId, p.viewFormat.compType))); if(p.imageResourceId == ResourceId()) { @@ -2732,9 +2748,11 @@ void VulkanPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, i QVariant tag = item->tag(); - if(tag.canConvert()) + if(tag.canConvert()) { - TextureDescription *tex = m_Ctx.GetTexture(tag.value()); + VulkanTextureTag vtex = tag.value(); + + TextureDescription *tex = m_Ctx.GetTexture(vtex.ID); if(tex) { @@ -2750,7 +2768,7 @@ void VulkanPipelineStateViewer::resource_itemActivated(RDTreeWidgetItem *item, i if(!m_Ctx.HasTextureViewer()) m_Ctx.ShowTextureViewer(); ITextureViewer *viewer = m_Ctx.GetTextureViewer(); - viewer->ViewTexture(tex->resourceId, true); + viewer->ViewTexture(tex->resourceId, vtex.compType, true); } return; diff --git a/qrenderdoc/Windows/ResourceInspector.cpp b/qrenderdoc/Windows/ResourceInspector.cpp index 3e24c6a09..bea1f3d93 100644 --- a/qrenderdoc/Windows/ResourceInspector.cpp +++ b/qrenderdoc/Windows/ResourceInspector.cpp @@ -478,7 +478,7 @@ void ResourceInspector::on_viewContents_clicked() if(!m_Ctx.HasTextureViewer()) m_Ctx.ShowTextureViewer(); ITextureViewer *viewer = m_Ctx.GetTextureViewer(); - viewer->ViewTexture(tex->resourceId, true); + viewer->ViewTexture(tex->resourceId, CompType::Typeless, true); } } else if(buf) diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index 9d45c3445..d511d1e1b 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -1981,14 +1981,17 @@ void TextureViewer::GotoLocation(int x, int y) UI_UpdateStatusText(); } -void TextureViewer::ViewTexture(ResourceId ID, bool focus) +void TextureViewer::ViewTexture(ResourceId ID, CompType typeCast, bool focus) { if(QThread::currentThread() != QCoreApplication::instance()->thread()) { - GUIInvoke::call(this, [this, ID, focus] { this->ViewTexture(ID, focus); }); + GUIInvoke::call(this, [this, ID, typeCast, focus] { this->ViewTexture(ID, typeCast, focus); }); return; } + if(typeCast != CompType::Typeless) + m_TextureSettings[ID].typeCast = typeCast; + if(m_LockedTabs.contains(ID)) { if(focus) @@ -2062,10 +2065,15 @@ void TextureViewer::texContextItem_triggered() return; } - QVariant id = act->property("id"); - if(id.isValid()) + QVariant idvar = act->property("id"); + if(idvar.isValid()) { - ViewTexture(id.value(), false); + ResourceId id = idvar.value(); + CompType typeCast = CompType::Typeless; + if(m_TextureSettings.contains(id)) + typeCast = m_TextureSettings[id].typeCast; + + ViewTexture(id, typeCast, false); return; } } @@ -2361,7 +2369,9 @@ void TextureViewer::thumb_doubleClicked(QMouseEvent *e) ResourceId id = m_Following.GetResourceId(m_Ctx); if(id != ResourceId()) - ViewTexture(id, false); + { + ViewTexture(id, m_Following.GetTypeHint(m_Ctx), false); + } } } @@ -3996,7 +4006,10 @@ void TextureViewer::texture_itemActivated(RDTreeWidgetItem *item, int column) } else { - ViewTexture(tex->resourceId, true); + CompType typeCast = CompType::Typeless; + if(m_TextureSettings.contains(tex->resourceId)) + typeCast = m_TextureSettings[tex->resourceId].typeCast; + ViewTexture(tex->resourceId, typeCast, true); } } diff --git a/qrenderdoc/Windows/TextureViewer.h b/qrenderdoc/Windows/TextureViewer.h index 7c787f54c..5abb1b76e 100644 --- a/qrenderdoc/Windows/TextureViewer.h +++ b/qrenderdoc/Windows/TextureViewer.h @@ -144,7 +144,7 @@ public: // ITextureViewer QWidget *Widget() override { return this; } - void ViewTexture(ResourceId ID, bool focus) override; + void ViewTexture(ResourceId ID, CompType typeCast, bool focus) override; void GotoLocation(int x, int y) override; // ICaptureViewer