From d06ea5b8a44b219a59b150c1a6eabfecb7399c9b Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 17 Oct 2018 12:48:18 +0100 Subject: [PATCH] Implement texture remapping to RGBA16/RGBA32 for D3D11/D3D12 --- renderdoc/driver/d3d11/d3d11_replay.cpp | 57 +++++++++++++------ renderdoc/driver/d3d12/d3d12_debug.cpp | 11 ++++ .../driver/d3d12/d3d12_rendertexture.cpp | 2 + renderdoc/driver/d3d12/d3d12_replay.cpp | 22 +++++-- renderdoc/driver/d3d12/d3d12_replay.h | 6 +- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index 974b02e44..b07d7493a 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -1775,10 +1775,20 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); + if(params.remap == RemapTexture::RGBA8) + { + desc.Format = IsSRGBFormat(desc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_R8G8B8A8_UNORM; + } + else if(params.remap == RemapTexture::RGBA16) + { + desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; + } + else if(params.remap == RemapTexture::RGBA32) + { + desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + } - desc.Format = - IsSRGBFormat(desc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; desc.ArraySize = 1; } @@ -1798,8 +1808,6 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); - subresource = mip; desc.CPUAccessFlags = 0; @@ -1911,11 +1919,21 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); + if(params.remap == RemapTexture::RGBA8) + { + desc.Format = (IsSRGBFormat(desc.Format) || wrapTex->m_RealDescriptor) + ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_R8G8B8A8_UNORM; + } + else if(params.remap == RemapTexture::RGBA16) + { + desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; + } + else if(params.remap == RemapTexture::RGBA32) + { + desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + } - desc.Format = (IsSRGBFormat(desc.Format) || wrapTex->m_RealDescriptor) - ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB - : DXGI_FORMAT_R8G8B8A8_UNORM; desc.ArraySize = 1; } @@ -1935,8 +1953,6 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); - subresource = mip; desc.CPUAccessFlags = 0; @@ -2063,10 +2079,19 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); - - desc.Format = - IsSRGBFormat(desc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM; + if(params.remap == RemapTexture::RGBA8) + { + desc.Format = IsSRGBFormat(desc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_R8G8B8A8_UNORM; + } + else if(params.remap == RemapTexture::RGBA16) + { + desc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; + } + else if(params.remap == RemapTexture::RGBA32) + { + desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + } } subresource = mip; @@ -2085,8 +2110,6 @@ void D3D11Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); - subresource = mip; desc.CPUAccessFlags = 0; diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index 3f325c06f..e8f70a951 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -1367,6 +1367,16 @@ void D3D12Replay::TextureRendering::Init(WrappedID3D12Device *device, D3D12Debug RDCERR("Couldn't create m_TexDisplayF32Pipe! HRESULT: %s", ToStr(hr).c_str()); } + pipeDesc.RTVFormats[0] = DXGI_FORMAT_R16G16B16A16_FLOAT; + + hr = device->CreateGraphicsPipelineState(&pipeDesc, __uuidof(ID3D12PipelineState), + (void **)&F16Pipe); + + if(FAILED(hr)) + { + RDCERR("Couldn't create m_TexDisplayF16Pipe! HRESULT: %s", ToStr(hr).c_str()); + } + SAFE_RELEASE(TexDisplayPS); } @@ -1378,6 +1388,7 @@ void D3D12Replay::TextureRendering::Release() SAFE_RELEASE(BlendPipe); SAFE_RELEASE(SRGBPipe); SAFE_RELEASE(LinearPipe); + SAFE_RELEASE(F16Pipe); SAFE_RELEASE(F32Pipe); SAFE_RELEASE(RootSig); SAFE_RELEASE(VS); diff --git a/renderdoc/driver/d3d12/d3d12_rendertexture.cpp b/renderdoc/driver/d3d12/d3d12_rendertexture.cpp index d5f7ce934..60236b55e 100644 --- a/renderdoc/driver/d3d12/d3d12_rendertexture.cpp +++ b/renderdoc/driver/d3d12/d3d12_rendertexture.cpp @@ -617,6 +617,8 @@ bool D3D12Replay::RenderTextureInternal(D3D12_CPU_DESCRIPTOR_HANDLE rtv, Texture { if(flags & eTexDisplay_F32Render) list->SetPipelineState(m_TexRender.F32Pipe); + else if(flags & eTexDisplay_F16Render) + list->SetPipelineState(m_TexRender.F16Pipe); else if(flags & eTexDisplay_LinearRender) list->SetPipelineState(m_TexRender.LinearPipe); else diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 532e921c2..5377661da 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -2935,11 +2935,20 @@ void D3D12Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip if(params.remap != RemapTexture::NoRemap) { - RDCASSERT(params.remap == RemapTexture::RGBA8); + if(params.remap == RemapTexture::RGBA8) + { + copyDesc.Format = IsSRGBFormat(copyDesc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB + : DXGI_FORMAT_R8G8B8A8_UNORM; + } + else if(params.remap == RemapTexture::RGBA16) + { + copyDesc.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; + } + else if(params.remap == RemapTexture::RGBA32) + { + copyDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + } - // force readback texture to RGBA8 unorm - copyDesc.Format = IsSRGBFormat(copyDesc.Format) ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB - : DXGI_FORMAT_R8G8B8A8_UNORM; // force to 1 array slice, 1 mip copyDesc.DepthOrArraySize = 1; copyDesc.MipLevels = 1; @@ -2961,6 +2970,11 @@ void D3D12Replay::GetTextureData(ResourceId tex, uint32_t arrayIdx, uint32_t mip TexDisplayFlags flags = IsSRGBFormat(copyDesc.Format) ? eTexDisplay_None : eTexDisplay_LinearRender; + if(copyDesc.Format == DXGI_FORMAT_R16G16B16A16_FLOAT) + flags = eTexDisplay_F16Render; + else if(copyDesc.Format == DXGI_FORMAT_R32G32B32A32_FLOAT) + flags = eTexDisplay_F32Render; + m_pDevice->CreateRenderTargetView(remapTexture, NULL, GetDebugManager()->GetCPUHandle(GET_TEX_RTV)); diff --git a/renderdoc/driver/d3d12/d3d12_replay.h b/renderdoc/driver/d3d12/d3d12_replay.h index b307bf73b..6741e610f 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.h +++ b/renderdoc/driver/d3d12/d3d12_replay.h @@ -43,8 +43,9 @@ enum TexDisplayFlags { eTexDisplay_None = 0, eTexDisplay_LinearRender = 0x1, - eTexDisplay_F32Render = 0x2, - eTexDisplay_BlendAlpha = 0x4, + eTexDisplay_F16Render = 0x2, + eTexDisplay_F32Render = 0x4, + eTexDisplay_BlendAlpha = 0x8, }; class D3D12Replay : public IReplayDriver @@ -334,6 +335,7 @@ private: ID3D12RootSignature *RootSig = NULL; ID3D12PipelineState *SRGBPipe = NULL; ID3D12PipelineState *LinearPipe = NULL; + ID3D12PipelineState *F16Pipe = NULL; ID3D12PipelineState *F32Pipe = NULL; ID3D12PipelineState *BlendPipe = NULL; } m_TexRender;