When clearing initial states on D3D11, handle YUV view formats

This commit is contained in:
baldurk
2018-12-13 16:04:02 +00:00
parent a6a2a7f20c
commit 2354deccb5
2 changed files with 50 additions and 14 deletions
+43 -8
View File
@@ -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)
{
+7 -6
View File
@@ -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<Configuration> *rm)
{
SAFE_RELEASE(resource);
SAFE_RELEASE(resource2);
}
D3D11ResourceType resourceType;
Tag tag;
ID3D11DeviceChild *resource;
ID3D11DeviceChild *resource, *resource2;
uint32_t uavCount;
};