From 2354deccb54b7e26ed241e4e461ff68b0544ad25 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 13 Dec 2018 16:04:02 +0000 Subject: [PATCH] When clearing initial states on D3D11, handle YUV view formats --- renderdoc/driver/d3d11/d3d11_initstate.cpp | 51 ++++++++++++++++++---- renderdoc/driver/d3d11/d3d11_manager.h | 13 +++--- 2 files changed, 50 insertions(+), 14 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_initstate.cpp b/renderdoc/driver/d3d11/d3d11_initstate.cpp index c467ab797..5211a3ef1 100644 --- a/renderdoc/driver/d3d11/d3d11_initstate.cpp +++ b/renderdoc/driver/d3d11/d3d11_initstate.cpp @@ -1168,19 +1168,50 @@ void WrappedID3D11Device::Create_InitialState(ResourceId id, ID3D11DeviceChild * if(isMS) rdesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS; - ID3D11RenderTargetView *clearRTV = NULL; + ID3D11RenderTargetView *clearRTV = NULL, *clear2RTV = NULL; - HRESULT hr = m_pDevice->CreateRenderTargetView(UNWRAP(WrappedID3D11Texture2D1, tex2D), &rdesc, - &clearRTV); - - if(FAILED(hr)) + if(IsYUVFormat(desc.Format)) { - RDCERR("Failed to create fast-clear RTV while creating initial states HRESULT: %s", - ToStr(hr).c_str()); + rdesc.Format = GetYUVViewPlane0Format(desc.Format); + + HRESULT hr = m_pDevice->CreateRenderTargetView(UNWRAP(WrappedID3D11Texture2D1, tex2D), + &rdesc, &clearRTV); + + if(SUCCEEDED(hr)) + { + rdesc.Format = GetYUVViewPlane1Format(desc.Format); + + if(rdesc.Format != DXGI_FORMAT_UNKNOWN) + hr = m_pDevice->CreateRenderTargetView(UNWRAP(WrappedID3D11Texture2D1, tex2D), &rdesc, + &clear2RTV); + } + + if(FAILED(hr)) + { + RDCERR( + "Failed to create fast-clear RTVs while creating initial states for YUV texture %s " + "HRESULT: %s", + ToStr(desc.Format).c_str(), ToStr(hr).c_str()); + } + else + { + m_ResourceManager->SetInitialContents(id, D3D11InitialContents(type, clearRTV, clear2RTV)); + } } else { - m_ResourceManager->SetInitialContents(id, D3D11InitialContents(type, clearRTV)); + HRESULT hr = m_pDevice->CreateRenderTargetView(UNWRAP(WrappedID3D11Texture2D1, tex2D), + &rdesc, &clearRTV); + + if(FAILED(hr)) + { + RDCERR("Failed to create fast-clear RTV while creating initial states HRESULT: %s", + ToStr(hr).c_str()); + } + else + { + m_ResourceManager->SetInitialContents(id, D3D11InitialContents(type, clearRTV)); + } } } else if(!hasData && desc.MipLevels == 1 && (desc.BindFlags & D3D11_BIND_DEPTH_STENCIL)) @@ -1305,6 +1336,10 @@ void WrappedID3D11Device::Apply_InitialState(ID3D11DeviceChild *live, D3D11Initi float emptyCol[] = {0.0f, 0.0f, 0.0f, 0.0f}; m_pImmediateContext->GetReal()->ClearRenderTargetView( (ID3D11RenderTargetView *)initial.resource, emptyCol); + + if(initial.resource2) + m_pImmediateContext->GetReal()->ClearRenderTargetView( + (ID3D11RenderTargetView *)initial.resource2, emptyCol); } else if(initial.tag == D3D11InitialContents::ClearDSV) { diff --git a/renderdoc/driver/d3d11/d3d11_manager.h b/renderdoc/driver/d3d11/d3d11_manager.h index 6f38f4bbd..69d775aae 100644 --- a/renderdoc/driver/d3d11/d3d11_manager.h +++ b/renderdoc/driver/d3d11/d3d11_manager.h @@ -203,19 +203,19 @@ struct D3D11InitialContents UAVCount, }; D3D11InitialContents(D3D11ResourceType t, ID3D11DeviceChild *r) - : resourceType(t), tag(Copy), resource(r), uavCount(0) + : resourceType(t), tag(Copy), resource(r), resource2(NULL), uavCount(0) { } - D3D11InitialContents(D3D11ResourceType t, ID3D11RenderTargetView *r) - : resourceType(t), tag(ClearRTV), resource(r), uavCount(0) + D3D11InitialContents(D3D11ResourceType t, ID3D11RenderTargetView *r, ID3D11RenderTargetView *r2) + : resourceType(t), tag(ClearRTV), resource(r), resource2(r2), uavCount(0) { } D3D11InitialContents(D3D11ResourceType t, ID3D11DepthStencilView *r) - : resourceType(t), tag(ClearDSV), resource(r), uavCount(0) + : resourceType(t), tag(ClearDSV), resource(r), resource2(NULL), uavCount(0) { } D3D11InitialContents(D3D11ResourceType t, uint32_t c) - : resourceType(t), tag(UAVCount), resource(NULL), uavCount(c) + : resourceType(t), tag(UAVCount), resource(NULL), resource2(NULL), uavCount(c) { } D3D11InitialContents() : resourceType(Resource_Unknown), tag(Copy), resource(NULL), uavCount(0) {} @@ -223,11 +223,12 @@ struct D3D11InitialContents void Free(ResourceManager *rm) { SAFE_RELEASE(resource); + SAFE_RELEASE(resource2); } D3D11ResourceType resourceType; Tag tag; - ID3D11DeviceChild *resource; + ID3D11DeviceChild *resource, *resource2; uint32_t uavCount; };