From e713c82dcd4586b8a5f77d32b66a598195e069d2 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 30 Oct 2019 16:32:08 +0000 Subject: [PATCH] The slice parameter for 3D textures should be mip-relative too --- qrenderdoc/Windows/TextureViewer.cpp | 6 ------ renderdoc/driver/d3d11/d3d11_pixelhistory.cpp | 5 ++++- .../driver/d3d11/d3d11_rendertexture.cpp | 4 ++-- renderdoc/driver/d3d11/d3d11_replay.cpp | 18 +++++++++--------- .../driver/d3d12/d3d12_rendertexture.cpp | 8 ++++++-- renderdoc/driver/d3d12/d3d12_replay.cpp | 19 ++++++++++--------- renderdoc/driver/gl/gl_debug.cpp | 14 ++++++++------ renderdoc/driver/gl/gl_rendertexture.cpp | 10 ++++------ renderdoc/driver/vulkan/vk_rendertexture.cpp | 5 ++--- renderdoc/driver/vulkan/vk_replay.cpp | 14 ++++++++------ renderdoc/replay/replay_controller.cpp | 10 +++++++++- 11 files changed, 62 insertions(+), 51 deletions(-) diff --git a/qrenderdoc/Windows/TextureViewer.cpp b/qrenderdoc/Windows/TextureViewer.cpp index ba17552d8..6a7592103 100644 --- a/qrenderdoc/Windows/TextureViewer.cpp +++ b/qrenderdoc/Windows/TextureViewer.cpp @@ -3530,9 +3530,6 @@ void TextureViewer::on_sliceFace_currentIndexChanged(int index) TextureDescription &tex = *texptr; m_TexDisplay.sliceFace = (uint32_t)qMax(0, index); - if(tex.depth > 1) - m_TexDisplay.sliceFace = (uint32_t)(qMax(0, index) << (int)m_TexDisplay.mip); - INVOKE_MEMFN(RT_UpdateVisualRange); if(m_Output != NULL && m_PickedPoint.x() >= 0 && m_PickedPoint.y() >= 0) @@ -3618,9 +3615,6 @@ void TextureViewer::on_saveTex_clicked() m_SaveConfig.slice.sliceIndex = (int)m_TexDisplay.sliceFace; m_SaveConfig.mip = (int)m_TexDisplay.mip; - if(texptr->depth > 1) - m_SaveConfig.slice.sliceIndex = (int)m_TexDisplay.sliceFace >> (int)m_TexDisplay.mip; - m_SaveConfig.channelExtract = -1; if(m_TexDisplay.red && !m_TexDisplay.green && !m_TexDisplay.blue && !m_TexDisplay.alpha) m_SaveConfig.channelExtract = 0; diff --git a/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp b/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp index 5f3547039..e5b1d58ca 100644 --- a/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp +++ b/renderdoc/driver/d3d11/d3d11_pixelhistory.cpp @@ -632,7 +632,10 @@ std::vector D3D11Replay::PixelHistory(std::vector colourCopyParams.intTex = intTex; colourCopyParams.srcxyCBuf = srcxyCBuf; colourCopyParams.storexyCBuf = storexyCBuf; - colourCopyParams.subres = details.texArraySize * slice + mip; + if(details.texType == eTexType_3D) + colourCopyParams.subres = mip; + else + colourCopyParams.subres = details.texArraySize * slice + mip; CopyPixelParams depthCopyParams = colourCopyParams; diff --git a/renderdoc/driver/d3d11/d3d11_rendertexture.cpp b/renderdoc/driver/d3d11/d3d11_rendertexture.cpp index c070cea0e..80b583799 100644 --- a/renderdoc/driver/d3d11/d3d11_rendertexture.cpp +++ b/renderdoc/driver/d3d11/d3d11_rendertexture.cpp @@ -703,12 +703,12 @@ bool D3D11Replay::RenderTextureInternal(TextureDisplay cfg, bool blendAlpha) pixelData.MipLevel = (float)cfg.mip; pixelData.OutputDisplayFormat = RESTYPE_TEX2D; - pixelData.Slice = float(RDCCLAMP(cfg.sliceFace, 0U, details.texArraySize - 1)); + pixelData.Slice = float(RDCCLAMP(cfg.sliceFace, 0U, details.texArraySize - 1) + 0.001f); if(details.texType == eTexType_3D) { pixelData.OutputDisplayFormat = RESTYPE_TEX3D; - pixelData.Slice = float(cfg.sliceFace >> cfg.mip); + pixelData.Slice = float(RDCCLAMP(cfg.sliceFace, 0U, (details.texDepth >> cfg.mip) - 1) + 0.001f); } else if(details.texType == eTexType_1D) { diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index 3c27e0b03..89f33b61d 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -1608,7 +1608,10 @@ bool D3D11Replay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mi cdata.HistogramTextureResolution.x = (float)RDCMAX(details.texWidth >> mip, 1U); cdata.HistogramTextureResolution.y = (float)RDCMAX(details.texHeight >> mip, 1U); cdata.HistogramTextureResolution.z = (float)RDCMAX(details.texDepth >> mip, 1U); - cdata.HistogramSlice = (float)sliceFace; + if(details.texType == eTexType_3D) + cdata.HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, (details.texDepth >> mip) - 1); + else + cdata.HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, details.texArraySize - 1); cdata.HistogramMip = mip; cdata.HistogramSample = (int)RDCCLAMP(sample, 0U, details.sampleCount - 1); if(sample == ~0U) @@ -1655,9 +1658,6 @@ bool D3D11Replay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mi intIdx = 2; } - if(details.texType == eTexType_3D) - cdata.HistogramSlice = float(sliceFace); - ID3D11Buffer *cbuf = GetDebugManager()->MakeCBuffer(&cdata, sizeof(cdata)); UINT zeroes[] = {0, 0, 0, 0}; @@ -1724,7 +1724,10 @@ bool D3D11Replay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, cdata.HistogramTextureResolution.x = (float)RDCMAX(details.texWidth >> mip, 1U); cdata.HistogramTextureResolution.y = (float)RDCMAX(details.texHeight >> mip, 1U); cdata.HistogramTextureResolution.z = (float)RDCMAX(details.texDepth >> mip, 1U); - cdata.HistogramSlice = (float)sliceFace; + if(details.texType == eTexType_3D) + cdata.HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, (details.texDepth >> mip) - 1); + else + cdata.HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, details.texArraySize - 1); cdata.HistogramMip = mip; cdata.HistogramSample = (int)RDCCLAMP(sample, 0U, details.sampleCount - 1); if(sample == ~0U) @@ -1760,9 +1763,6 @@ bool D3D11Replay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, intIdx = 2; } - if(details.texType == eTexType_3D) - cdata.HistogramSlice = float(sliceFace); - ID3D11Buffer *cbuf = GetDebugManager()->MakeCBuffer(&cdata, sizeof(cdata)); m_pImmediateContext->OMSetRenderTargetsAndUnorderedAccessViews(0, NULL, NULL, 0, 0, NULL, NULL); @@ -2282,7 +2282,7 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip texDisplay.mip = mip; texDisplay.sampleIdx = 0; texDisplay.customShaderId = ResourceId(); - texDisplay.sliceFace = i << mip; + texDisplay.sliceFace = i; texDisplay.rangeMin = params.blackPoint; texDisplay.rangeMax = params.whitePoint; texDisplay.resourceId = tex; diff --git a/renderdoc/driver/d3d12/d3d12_rendertexture.cpp b/renderdoc/driver/d3d12/d3d12_rendertexture.cpp index 335edc839..4beac460e 100644 --- a/renderdoc/driver/d3d12/d3d12_rendertexture.cpp +++ b/renderdoc/driver/d3d12/d3d12_rendertexture.cpp @@ -446,10 +446,14 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture pixelData.MipLevel = (float)cfg.mip; pixelData.OutputDisplayFormat = RESTYPE_TEX2D; - pixelData.Slice = float(RDCCLAMP(cfg.sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1))); if(resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - pixelData.Slice = float(cfg.sliceFace >> cfg.mip); + pixelData.Slice = + float(RDCCLAMP(cfg.sliceFace, 0U, uint32_t((resourceDesc.DepthOrArraySize >> cfg.mip) - 1)) + + 0.001f); + else + pixelData.Slice = + float(RDCCLAMP(cfg.sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1)) + 0.001f); std::vector barriers; int resType = 0; diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 840afca9d..a53e0c096 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -2267,10 +2267,12 @@ bool D3D12Replay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, if(resourceDesc.DepthOrArraySize > 1 && resourceDesc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D) cdata.HistogramTextureResolution.z = float(resourceDesc.DepthOrArraySize); - cdata.HistogramSlice = float(RDCCLAMP(sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1))); - if(resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - cdata.HistogramSlice = float(sliceFace) / float(resourceDesc.DepthOrArraySize); + cdata.HistogramSlice = + float(RDCCLAMP(sliceFace, 0U, uint32_t((resourceDesc.DepthOrArraySize >> mip) - 1))); + else + cdata.HistogramSlice = + float(RDCCLAMP(sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1))); cdata.HistogramMip = mip; cdata.HistogramSample = (int)RDCCLAMP(sample, 0U, resourceDesc.SampleDesc.Count - 1); @@ -2447,10 +2449,12 @@ bool D3D12Replay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mi if(resourceDesc.DepthOrArraySize > 1 && resourceDesc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE3D) cdata.HistogramTextureResolution.z = float(resourceDesc.DepthOrArraySize); - cdata.HistogramSlice = float(RDCCLAMP(sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1))); - if(resourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - cdata.HistogramSlice = float(sliceFace) / float(resourceDesc.DepthOrArraySize); + cdata.HistogramSlice = + float(RDCCLAMP(sliceFace, 0U, uint32_t((resourceDesc.DepthOrArraySize >> mip) - 1))); + else + cdata.HistogramSlice = + float(RDCCLAMP(sliceFace, 0U, uint32_t(resourceDesc.DepthOrArraySize - 1))); cdata.HistogramMip = mip; cdata.HistogramSample = (int)RDCCLAMP(sample, 0U, resourceDesc.SampleDesc.Count - 1); @@ -3138,9 +3142,6 @@ void D3D12Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip // scale here texDisplay.scale = 1.0f / float(1 << mip); - if(copyDesc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D) - texDisplay.sliceFace = loop << mip; - RenderTextureInternal(GetDebugManager()->GetCPUHandle(GET_TEX_RTV), texDisplay, flags); } diff --git a/renderdoc/driver/gl/gl_debug.cpp b/renderdoc/driver/gl/gl_debug.cpp index dc3ac5e9b..6a55cabc5 100644 --- a/renderdoc/driver/gl/gl_debug.cpp +++ b/renderdoc/driver/gl/gl_debug.cpp @@ -1485,10 +1485,11 @@ bool GLReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, uin cdata->HistogramTextureResolution.x = (float)RDCMAX(details.width >> mip, 1U); cdata->HistogramTextureResolution.y = (float)RDCMAX(details.height >> mip, 1U); cdata->HistogramTextureResolution.z = (float)RDCMAX(details.depth >> mip, 1U); - if(texDetails.curType != eGL_TEXTURE_3D) - cdata->HistogramSlice = (float)sliceFace + 0.001f; + if(texDetails.curType == eGL_TEXTURE_3D) + cdata->HistogramSlice = + (float)RDCCLAMP(sliceFace, 0U, uint32_t(details.depth >> mip) - 1) + 0.001f; else - cdata->HistogramSlice = (float)(sliceFace >> mip); + cdata->HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, details.arraysize - 1) + 0.001f; cdata->HistogramMip = (int)mip; cdata->HistogramNumSamples = texDetails.samples; cdata->HistogramSample = (int)RDCCLAMP(sample, 0U, details.msSamp - 1); @@ -1745,10 +1746,11 @@ bool GLReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t mip, cdata->HistogramTextureResolution.x = (float)RDCMAX(details.width >> mip, 1U); cdata->HistogramTextureResolution.y = (float)RDCMAX(details.height >> mip, 1U); cdata->HistogramTextureResolution.z = (float)RDCMAX(details.depth >> mip, 1U); - if(texDetails.curType != eGL_TEXTURE_3D) - cdata->HistogramSlice = (float)sliceFace + 0.001f; + if(texDetails.curType == eGL_TEXTURE_3D) + cdata->HistogramSlice = + (float)RDCCLAMP(sliceFace, 0U, uint32_t(details.depth >> mip) - 1) + 0.001f; else - cdata->HistogramSlice = (float)(sliceFace >> mip); + cdata->HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, details.arraysize - 1) + 0.001f; cdata->HistogramMip = mip; cdata->HistogramNumSamples = texDetails.samples; cdata->HistogramSample = (int)RDCCLAMP(sample, 0U, details.msSamp - 1); diff --git a/renderdoc/driver/gl/gl_rendertexture.cpp b/renderdoc/driver/gl/gl_rendertexture.cpp index 0e0ea2c13..36f3f155f 100644 --- a/renderdoc/driver/gl/gl_rendertexture.cpp +++ b/renderdoc/driver/gl/gl_rendertexture.cpp @@ -368,14 +368,12 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, int flags) ubo->MipLevel = (int)cfg.mip; if(texDetails.curType != eGL_TEXTURE_3D) { - uint32_t depth = RDCMAX((uint32_t)texDetails.depth, 1U); + uint32_t numSlices = RDCMAX((uint32_t)texDetails.depth, 1U); if(texDetails.curType == eGL_TEXTURE_CUBE_MAP) - depth *= 6; + numSlices *= 6; if(texDetails.curType == eGL_TEXTURE_1D_ARRAY) - depth = RDCMAX((uint32_t)texDetails.height, 1U); - - uint32_t numSlices = depth * RDCMAX((uint32_t)texDetails.samples, 1U); + numSlices = RDCMAX((uint32_t)texDetails.height, 1U); uint32_t sliceFace = RDCCLAMP(cfg.sliceFace, 0U, numSlices - 1); ubo->Slice = (float)sliceFace + 0.001f; @@ -383,7 +381,7 @@ bool GLReplay::RenderTextureInternal(TextureDisplay cfg, int flags) else { uint32_t sliceFace = RDCCLAMP(cfg.sliceFace, 0U, RDCMAX((uint32_t)texDetails.depth, 1U) - 1); - ubo->Slice = (float)(sliceFace >> cfg.mip); + ubo->Slice = (float)sliceFace + 0.001f; } ubo->OutputDisplayFormat = resType; diff --git a/renderdoc/driver/vulkan/vk_rendertexture.cpp b/renderdoc/driver/vulkan/vk_rendertexture.cpp index 2b3364a10..68a1d7d70 100644 --- a/renderdoc/driver/vulkan/vk_rendertexture.cpp +++ b/renderdoc/driver/vulkan/vk_rendertexture.cpp @@ -279,8 +279,7 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn data->Slice = 0; if(iminfo.type != VK_IMAGE_TYPE_3D) { - uint32_t numSlices = - RDCMAX((uint32_t)iminfo.arrayLayers, 1U) * RDCMAX((uint32_t)iminfo.samples, 1U); + uint32_t numSlices = RDCMAX((uint32_t)iminfo.arrayLayers, 1U); uint32_t sliceFace = RDCCLAMP(cfg.sliceFace, 0U, numSlices - 1); data->Slice = (float)sliceFace + 0.001f; @@ -288,7 +287,7 @@ bool VulkanReplay::RenderTextureInternal(TextureDisplay cfg, VkRenderPassBeginIn else { uint32_t sliceFace = RDCCLAMP(cfg.sliceFace, 0U, iminfo.extent.depth - 1); - data->Slice = (float)(sliceFace >> cfg.mip); + data->Slice = (float)sliceFace + 0.001f; } data->TextureResolutionPS.x = float(RDCMAX(1, tex_x >> cfg.mip)); diff --git a/renderdoc/driver/vulkan/vk_replay.cpp b/renderdoc/driver/vulkan/vk_replay.cpp index b4d93113a..55fe11a22 100644 --- a/renderdoc/driver/vulkan/vk_replay.cpp +++ b/renderdoc/driver/vulkan/vk_replay.cpp @@ -2328,10 +2328,11 @@ bool VulkanReplay::GetMinMax(ResourceId texid, uint32_t sliceFace, uint32_t mip, data->HistogramTextureResolution.x = (float)RDCMAX(uint32_t(iminfo.extent.width) >> mip, 1U); data->HistogramTextureResolution.y = (float)RDCMAX(uint32_t(iminfo.extent.height) >> mip, 1U); data->HistogramTextureResolution.z = (float)RDCMAX(uint32_t(iminfo.extent.depth) >> mip, 1U); - if(iminfo.type != VK_IMAGE_TYPE_3D) - data->HistogramSlice = (float)sliceFace + 0.001f; + if(iminfo.type == VK_IMAGE_TYPE_3D) + data->HistogramSlice = + (float)RDCCLAMP(sliceFace, 0U, uint32_t(iminfo.extent.depth >> mip) - 1) + 0.001f; else - data->HistogramSlice = (float)(sliceFace >> mip); + data->HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, (uint32_t)iminfo.arrayLayers - 1) + 0.001f; data->HistogramMip = (int)mip; data->HistogramNumSamples = iminfo.samples; data->HistogramSample = (int)RDCCLAMP(sample, 0U, uint32_t(iminfo.samples) - 1); @@ -2648,10 +2649,11 @@ bool VulkanReplay::GetHistogram(ResourceId texid, uint32_t sliceFace, uint32_t m data->HistogramTextureResolution.x = (float)RDCMAX(uint32_t(iminfo.extent.width) >> mip, 1U); data->HistogramTextureResolution.y = (float)RDCMAX(uint32_t(iminfo.extent.height) >> mip, 1U); data->HistogramTextureResolution.z = (float)RDCMAX(uint32_t(iminfo.extent.depth) >> mip, 1U); - if(iminfo.type != VK_IMAGE_TYPE_3D) - data->HistogramSlice = (float)sliceFace + 0.001f; + if(iminfo.type == VK_IMAGE_TYPE_3D) + data->HistogramSlice = + (float)RDCCLAMP(sliceFace, 0U, uint32_t(iminfo.extent.depth >> mip) - 1) + 0.001f; else - data->HistogramSlice = (float)(sliceFace >> mip); + data->HistogramSlice = (float)RDCCLAMP(sliceFace, 0U, (uint32_t)iminfo.arrayLayers - 1) + 0.001f; data->HistogramMip = (int)mip; data->HistogramNumSamples = iminfo.samples; data->HistogramSample = (int)RDCCLAMP(sample, 0U, uint32_t(iminfo.samples) - 1); diff --git a/renderdoc/replay/replay_controller.cpp b/renderdoc/replay/replay_controller.cpp index b780004eb..6460f56d6 100644 --- a/renderdoc/replay/replay_controller.cpp +++ b/renderdoc/replay/replay_controller.cpp @@ -1567,7 +1567,15 @@ rdcarray ReplayController::PixelHistory(ResourceId target, ui if(m_Textures[t].msSamp == 1) sampleIdx = ~0U; - slice = RDCCLAMP(slice, 0U, m_Textures[t].arraysize); + if(m_Textures[t].dimension == 3) + { + slice = RDCCLAMP(slice, 0U, m_Textures[t].depth >> mip); + } + else + { + slice = RDCCLAMP(slice, 0U, m_Textures[t].arraysize); + } + mip = RDCCLAMP(mip, 0U, m_Textures[t].mips); break;