From fefb6b25264f87ee84ce8a8485544f8f4a88763a Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 25 Jul 2016 11:13:19 +0200 Subject: [PATCH] Pass selected slice/face and sample idx to custom vis shaders. Refs #304 --- docs/how/how_custom_visualisation.rst | 24 ++++++++++++++++ renderdoc/core/image_viewer.cpp | 6 ++-- renderdoc/core/replay_proxy.h | 7 +++-- renderdoc/driver/d3d11/d3d11_analyse.cpp | 5 ++-- renderdoc/driver/d3d11/d3d11_debug.cpp | 36 ++++++++++++++++++++++-- renderdoc/driver/d3d11/d3d11_debug.h | 4 +-- renderdoc/driver/d3d11/d3d11_replay.cpp | 4 ++- renderdoc/driver/d3d11/d3d11_replay.h | 4 +-- renderdoc/driver/d3d12/d3d12_replay.cpp | 1 + renderdoc/driver/d3d12/d3d12_replay.h | 4 +-- renderdoc/driver/gl/gl_debug.cpp | 14 +++++++++ renderdoc/driver/gl/gl_replay.cpp | 5 ++-- renderdoc/driver/gl/gl_replay.h | 4 +-- renderdoc/driver/vulkan/vk_replay.cpp | 19 +++++++++---- renderdoc/driver/vulkan/vk_replay.h | 4 +-- renderdoc/replay/replay_driver.h | 1 + renderdoc/replay/replay_output.cpp | 3 +- 17 files changed, 115 insertions(+), 30 deletions(-) diff --git a/docs/how/how_custom_visualisation.rst b/docs/how/how_custom_visualisation.rst index 9c8d0e416..99c40c9a5 100644 --- a/docs/how/how_custom_visualisation.rst +++ b/docs/how/how_custom_visualisation.rst @@ -58,6 +58,8 @@ There are several constant parameters available, each detailed below with the va uvec4 TexDim; uint SelectedMip; uint TextureType; + uint SelectedSliceFace; + int SelectedSample; } RENDERDOC; In this way you can access the properties as ``RENDERDOC.TexDim`` insetad of ``RENDERDOC_TexDim``. @@ -89,6 +91,28 @@ Selected Mip level This variable will be filled out with the selected mip level in the UI. +Selected Slice/Face +``````````````````` + +.. highlight:: c++ +.. code:: c++ + + uint RENDERDOC_SelectedSliceFace; + +This variable will be filled out with the selected texture array slice (or cubemap face) in the UI. + +Selected Multisample sample +``````````````````````````` + +.. highlight:: c++ +.. code:: c++ + + int RENDERDOC_SelectedSample; + +This variable will be filled out with the selected multisample sample index as chosen in the UI. If the UI has 'average value' selected, this variable will be negative and with an absolute value equal to the number of samples. + +So for example in a 4x MSAA texture, the valid values are ``0``, ``1``, ``2``, ``3`` to select a sample, or ``-4`` for 'average value'. + Current texture type ```````````````````` diff --git a/renderdoc/core/image_viewer.cpp b/renderdoc/core/image_viewer.cpp index c54a41cf0..db8db780e 100644 --- a/renderdoc/core/image_viewer.cpp +++ b/renderdoc/core/image_viewer.cpp @@ -131,10 +131,10 @@ public: m_Proxy->BuildCustomShader(source, entry, compileFlags, type, id, errors); } void FreeCustomShader(ResourceId id) { m_Proxy->FreeTargetResource(id); } - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint) + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint) { - return m_Proxy->ApplyCustomShader(shader, m_TextureID, mip, typeHint); + return m_Proxy->ApplyCustomShader(shader, m_TextureID, mip, arrayIdx, sampleIdx, typeHint); } vector GetTextures() { return m_Proxy->GetTextures(); } FetchTexture GetTexture(ResourceId id) { return m_Proxy->GetTexture(m_TextureID); } diff --git a/renderdoc/core/replay_proxy.h b/renderdoc/core/replay_proxy.h index 4672208dc..0bfaee656 100644 --- a/renderdoc/core/replay_proxy.h +++ b/renderdoc/core/replay_proxy.h @@ -320,14 +320,15 @@ public: m_Proxy->FreeTargetResource(id); } - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint) + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint) { if(m_Proxy) { EnsureTexCached(texid, 0, mip); texid = m_ProxyTextureIds[texid]; - ResourceId customResourceId = m_Proxy->ApplyCustomShader(shader, texid, mip, typeHint); + ResourceId customResourceId = + m_Proxy->ApplyCustomShader(shader, texid, mip, arrayIdx, sampleIdx, typeHint); m_LocalTextures.insert(customResourceId); m_ProxyTextureIds[customResourceId] = customResourceId; return customResourceId; diff --git a/renderdoc/driver/d3d11/d3d11_analyse.cpp b/renderdoc/driver/d3d11/d3d11_analyse.cpp index eefbcfc3d..77aeaab65 100644 --- a/renderdoc/driver/d3d11/d3d11_analyse.cpp +++ b/renderdoc/driver/d3d11/d3d11_analyse.cpp @@ -2982,6 +2982,7 @@ byte *D3D11DebugManager::GetTextureData(ResourceId id, uint32_t arrayIdx, uint32 } ResourceId D3D11DebugManager::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) { TextureShaderDetails details = GetShaderDetails(texid, typeHint, false); @@ -3032,13 +3033,13 @@ ResourceId D3D11DebugManager::ApplyCustomShader(ResourceId shader, ResourceId te disp.HDRMul = -1.0f; disp.linearDisplayAsGamma = false; disp.mip = mip; - disp.sampleIdx = 0; + disp.sampleIdx = sampleIdx; disp.overlay = eTexOverlay_None; disp.rangemin = 0.0f; disp.rangemax = 1.0f; disp.rawoutput = false; disp.scale = 1.0f; - disp.sliceFace = 0; + disp.sliceFace = arrayIdx; SetOutputDimensions(RDCMAX(1U, details.texWidth >> mip), RDCMAX(1U, details.texHeight >> mip)); diff --git a/renderdoc/driver/d3d11/d3d11_debug.cpp b/renderdoc/driver/d3d11/d3d11_debug.cpp index dd06bc3de..15ee67c3d 100644 --- a/renderdoc/driver/d3d11/d3d11_debug.cpp +++ b/renderdoc/driver/d3d11/d3d11_debug.cpp @@ -3298,11 +3298,13 @@ bool D3D11DebugManager::RenderTexture(TextureDisplay cfg, bool blendAlpha) TextureShaderDetails details = GetShaderDetails(cfg.texid, cfg.typeHint, cfg.rawoutput ? true : false); - pixelData.SampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, details.sampleCount - 1); + int sampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, details.sampleCount - 1); // hacky resolve if(cfg.sampleIdx == ~0U) - pixelData.SampleIdx = -int(details.sampleCount); + sampleIdx = -int(details.sampleCount); + + pixelData.SampleIdx = sampleIdx; if(details.texFmt == DXGI_FORMAT_UNKNOWN) return false; @@ -3418,6 +3420,36 @@ bool D3D11DebugManager::RenderTexture(TextureDisplay cfg, bool blendAlpha) var.name.c_str()); } } + else if(var.name == "RENDERDOC_SelectedSliceFace") + { + if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 && + var.type.descriptor.type == DXBC::VARTYPE_UINT) + { + uint32_t *d = (uint32_t *)(byteData + var.descriptor.offset); + + d[0] = cfg.sliceFace; + } + else + { + RDCWARN("Custom shader: Variable recognised but type wrong, expected uint: %s", + var.name.c_str()); + } + } + else if(var.name == "RENDERDOC_SelectedSample") + { + if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 && + var.type.descriptor.type == DXBC::VARTYPE_INT) + { + int32_t *d = (int32_t *)(byteData + var.descriptor.offset); + + d[0] = cfg.sampleIdx; + } + else + { + RDCWARN("Custom shader: Variable recognised but type wrong, expected int: %s", + var.name.c_str()); + } + } else if(var.name == "RENDERDOC_TextureType") { if(var.type.descriptor.rows == 1 && var.type.descriptor.cols == 1 && diff --git a/renderdoc/driver/d3d11/d3d11_debug.h b/renderdoc/driver/d3d11/d3d11_debug.h index 36e125b39..1b73244f4 100644 --- a/renderdoc/driver/d3d11/d3d11_debug.h +++ b/renderdoc/driver/d3d11/d3d11_debug.h @@ -194,8 +194,8 @@ public: ResourceId RenderOverlay(ResourceId texid, FormatComponentType typeHint, TextureDisplayOverlay overlay, uint32_t eventID, const vector &passEvents); - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint); + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint); // don't need to differentiate arrays as we treat everything // as an array (potentially with only one element). diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index aa7fe55b9..084e7f1bc 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -1581,9 +1581,11 @@ ResourceId D3D11Replay::RenderOverlay(ResourceId texid, FormatComponentType type } ResourceId D3D11Replay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) { - return m_pDevice->GetDebugManager()->ApplyCustomShader(shader, texid, mip, typeHint); + return m_pDevice->GetDebugManager()->ApplyCustomShader(shader, texid, mip, arrayIdx, sampleIdx, + typeHint); } bool D3D11Replay::IsRenderOutput(ResourceId id) diff --git a/renderdoc/driver/d3d11/d3d11_replay.h b/renderdoc/driver/d3d11/d3d11_replay.h index 348f92aed..01753418b 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.h +++ b/renderdoc/driver/d3d11/d3d11_replay.h @@ -155,8 +155,8 @@ public: void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStageType type, ResourceId *id, string *errors); - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint); + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint); bool IsRenderOutput(ResourceId id); diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index bb8e62ebf..5feffe988 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -475,6 +475,7 @@ ResourceId D3D12Replay::RenderOverlay(ResourceId texid, FormatComponentType type } ResourceId D3D12Replay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) { return ResourceId(); diff --git a/renderdoc/driver/d3d12/d3d12_replay.h b/renderdoc/driver/d3d12/d3d12_replay.h index a408782c7..ce2c80d9a 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.h +++ b/renderdoc/driver/d3d12/d3d12_replay.h @@ -150,8 +150,8 @@ public: void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStageType type, ResourceId *id, string *errors); - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint); + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint); bool IsRenderOutput(ResourceId id); diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index 99b59b30d..580d5b534 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -1475,6 +1475,20 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha) if(loc >= 0) gl.glProgramUniform1ui(customProg, loc, cfg.mip); + loc = gl.glGetUniformLocation(customProg, "RENDERDOC_SelectedSliceFace"); + if(loc >= 0) + gl.glProgramUniform1ui(customProg, loc, cfg.sliceFace); + + loc = gl.glGetUniformLocation(customProg, "RENDERDOC_SelectedSample"); + if(loc >= 0) + { + if(cfg.sampleIdx == ~0U) + gl.glProgramUniform1i(customProg, loc, -texDetails.samples); + else + gl.glProgramUniform1i(customProg, loc, + (int)RDCCLAMP(cfg.sampleIdx, 0U, (uint32_t)texDetails.samples - 1)); + } + loc = gl.glGetUniformLocation(customProg, "RENDERDOC_TextureType"); if(loc >= 0) gl.glProgramUniform1ui(customProg, loc, resType); diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index 03fbd1f1b..b1151efe0 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -2611,6 +2611,7 @@ void GLReplay::BuildCustomShader(string source, string entry, const uint32_t com } ResourceId GLReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) { if(shader == ResourceId() || texid == ResourceId()) @@ -2647,13 +2648,13 @@ ResourceId GLReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint disp.HDRMul = -1.0f; disp.linearDisplayAsGamma = false; disp.mip = mip; - disp.sampleIdx = 0; + disp.sampleIdx = sampleIdx; disp.overlay = eTexOverlay_None; disp.rangemin = 0.0f; disp.rangemax = 1.0f; disp.rawoutput = false; disp.scale = 1.0f; - disp.sliceFace = 0; + disp.sliceFace = arrayIdx; RenderTextureInternal(disp, false); diff --git a/renderdoc/driver/gl/gl_replay.h b/renderdoc/driver/gl/gl_replay.h index 47cec570a..8d07a6a84 100644 --- a/renderdoc/driver/gl/gl_replay.h +++ b/renderdoc/driver/gl/gl_replay.h @@ -194,8 +194,8 @@ public: ResourceId RenderOverlay(ResourceId id, FormatComponentType typeHint, TextureDisplayOverlay overlay, uint32_t eventID, const vector &passEvents); - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint); + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint); ResourceId CreateProxyTexture(const FetchTexture &templateTex); void SetProxyTextureData(ResourceId texid, uint32_t arrayIdx, uint32_t mip, byte *data, diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index a6b401678..959c033cf 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -1226,10 +1226,14 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn data->Scale = cfg.scale * mipScale; - data->SampleIdx = cfg.sampleIdx; + int sampleIdx = (int)RDCCLAMP(cfg.sampleIdx, 0U, (uint32_t)SampleCount(iminfo.samples)); + + sampleIdx = cfg.sampleIdx; if(cfg.sampleIdx == ~0U) - data->SampleIdx = -SampleCount(iminfo.samples); + sampleIdx = -SampleCount(iminfo.samples); + + data->SampleIdx = sampleIdx; data->OutputRes.x = (float)m_DebugWidth; data->OutputRes.y = (float)m_DebugHeight; @@ -1273,7 +1277,8 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn Vec4u texDim; uint32_t selectedMip; uint32_t texType; - uint32_t padding[2]; + uint32_t selectedSliceFace; + int32_t selectedSample; }; CustomTexDisplayUBOData *customData = (CustomTexDisplayUBOData *)data; @@ -1283,7 +1288,8 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn customData->texDim.z = iminfo.extent.depth; customData->texDim.w = iminfo.mipLevels; customData->selectedMip = cfg.mip; - customData->padding[0] = customData->padding[1] = 0; + customData->selectedSliceFace = cfg.sliceFace; + customData->selectedSample = sampleIdx; customData->texType = (uint32_t)textype; } @@ -5357,6 +5363,7 @@ void VulkanReplay::FreeCustomShader(ResourceId id) } ResourceId VulkanReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) { if(shader == ResourceId() || texid == ResourceId()) @@ -5383,13 +5390,13 @@ ResourceId VulkanReplay::ApplyCustomShader(ResourceId shader, ResourceId texid, disp.HDRMul = -1.0f; disp.linearDisplayAsGamma = false; disp.mip = mip; - disp.sampleIdx = 0; + disp.sampleIdx = sampleIdx; disp.overlay = eTexOverlay_None; disp.rangemin = 0.0f; disp.rangemax = 1.0f; disp.rawoutput = false; disp.scale = 1.0f; - disp.sliceFace = 0; + disp.sliceFace = arrayIdx; VkClearValue clearval = {{{0.0f, 0.0f, 0.0f, 1.0f}}}; VkRenderPassBeginInfo rpbegin = { diff --git a/renderdoc/driver/vulkan/vk_replay.h b/renderdoc/driver/vulkan/vk_replay.h index 6a26df646..156d81901 100644 --- a/renderdoc/driver/vulkan/vk_replay.h +++ b/renderdoc/driver/vulkan/vk_replay.h @@ -196,8 +196,8 @@ public: ResourceId RenderOverlay(ResourceId cfg, FormatComponentType typeHint, TextureDisplayOverlay overlay, uint32_t eventID, const vector &passEvents); - ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, - FormatComponentType typeHint); + ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, uint32_t arrayIdx, + uint32_t sampleIdx, FormatComponentType typeHint); ResourceId CreateProxyTexture(const FetchTexture &templateTex); void SetProxyTextureData(ResourceId texid, uint32_t arrayIdx, uint32_t mip, byte *data, diff --git a/renderdoc/replay/replay_driver.h b/renderdoc/replay/replay_driver.h index 75818b4ca..58db5ad62 100644 --- a/renderdoc/replay/replay_driver.h +++ b/renderdoc/replay/replay_driver.h @@ -166,6 +166,7 @@ public: virtual void BuildCustomShader(string source, string entry, const uint32_t compileFlags, ShaderStageType type, ResourceId *id, string *errors) = 0; virtual ResourceId ApplyCustomShader(ResourceId shader, ResourceId texid, uint32_t mip, + uint32_t arrayIdx, uint32_t sampleIdx, FormatComponentType typeHint) = 0; virtual void FreeCustomShader(ResourceId id) = 0; diff --git a/renderdoc/replay/replay_output.cpp b/renderdoc/replay/replay_output.cpp index 3dccd2818..02bacee8f 100644 --- a/renderdoc/replay/replay_output.cpp +++ b/renderdoc/replay/replay_output.cpp @@ -566,7 +566,8 @@ void ReplayOutput::DisplayTex() if(m_RenderData.texDisplay.CustomShader != ResourceId()) { m_CustomShaderResourceId = m_pDevice->ApplyCustomShader( - m_RenderData.texDisplay.CustomShader, texDisplay.texid, texDisplay.mip, texDisplay.typeHint); + m_RenderData.texDisplay.CustomShader, texDisplay.texid, texDisplay.mip, + texDisplay.sliceFace, texDisplay.sampleIdx, texDisplay.typeHint); texDisplay.texid = m_pDevice->GetLiveID(m_CustomShaderResourceId); texDisplay.typeHint = eCompType_None;