1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-01 16:24:12 +01:00

[d3d11] Make D3D11 context methods more robust to null pointers

Assetto Corsa tries to do some questionable things when reflections
are disabled in the game options. Refs #648.
This commit is contained in:
Philip Rebohle 2018-09-19 11:59:53 +02:00
parent c1190e81b2
commit 35238ec4d1
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -63,10 +63,13 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource* pResource) { void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource* pResource) {
if (!pResource)
return;
// We don't support the Discard API for images
D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN; D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&resType); pResource->GetType(&resType);
// We don't support the Discard API for images
if (resType == D3D11_RESOURCE_DIMENSION_BUFFER) if (resType == D3D11_RESOURCE_DIMENSION_BUFFER)
DiscardBuffer(static_cast<D3D11Buffer*>(pResource)); DiscardBuffer(static_cast<D3D11Buffer*>(pResource));
} }
@ -197,7 +200,7 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) { void STDMETHODCALLTYPE D3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) {
if (pAsync == nullptr) if (!pAsync)
return; return;
Com<ID3D11Query> query; Com<ID3D11Query> query;
@ -217,7 +220,7 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::End(ID3D11Asynchronous *pAsync) { void STDMETHODCALLTYPE D3D11DeviceContext::End(ID3D11Asynchronous *pAsync) {
if (pAsync == nullptr) if (!pAsync)
return; return;
Com<ID3D11Query> query; Com<ID3D11Query> query;
@ -508,6 +511,9 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::CopyResource( void STDMETHODCALLTYPE D3D11DeviceContext::CopyResource(
ID3D11Resource* pDstResource, ID3D11Resource* pDstResource,
ID3D11Resource* pSrcResource) { ID3D11Resource* pSrcResource) {
if (!pDstResource || !pSrcResource)
return;
D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
@ -606,6 +612,9 @@ namespace dxvk {
auto buf = static_cast<D3D11Buffer*>(pDstBuffer); auto buf = static_cast<D3D11Buffer*>(pDstBuffer);
auto uav = static_cast<D3D11UnorderedAccessView*>(pSrcView); auto uav = static_cast<D3D11UnorderedAccessView*>(pSrcView);
if (!buf || !uav)
return;
EmitCs([ EmitCs([
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset), cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
cSrcSlice = uav->GetCounterSlice() cSrcSlice = uav->GetCounterSlice()
@ -625,7 +634,7 @@ namespace dxvk {
const FLOAT ColorRGBA[4]) { const FLOAT ColorRGBA[4]) {
auto rtv = static_cast<D3D11RenderTargetView*>(pRenderTargetView); auto rtv = static_cast<D3D11RenderTargetView*>(pRenderTargetView);
if (rtv == nullptr) if (!rtv)
return; return;
const Rc<DxvkImageView> view = rtv->GetImageView(); const Rc<DxvkImageView> view = rtv->GetImageView();
@ -653,7 +662,7 @@ namespace dxvk {
const UINT Values[4]) { const UINT Values[4]) {
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView); auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
if (uav == nullptr) if (!uav)
return; return;
// Gather UAV format info. We'll use this to determine // Gather UAV format info. We'll use this to determine
@ -746,7 +755,7 @@ namespace dxvk {
const FLOAT Values[4]) { const FLOAT Values[4]) {
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView); auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);
if (uav == nullptr) if (!uav)
return; return;
VkClearValue clearValue; VkClearValue clearValue;
@ -786,7 +795,7 @@ namespace dxvk {
UINT8 Stencil) { UINT8 Stencil) {
auto dsv = static_cast<D3D11DepthStencilView*>(pDepthStencilView); auto dsv = static_cast<D3D11DepthStencilView*>(pDepthStencilView);
if (dsv == nullptr) if (!dsv)
return; return;
// Figure out which aspects to clear based // Figure out which aspects to clear based
@ -966,8 +975,8 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) { void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) {
auto view = static_cast<D3D11ShaderResourceView*>(pShaderResourceView); auto view = static_cast<D3D11ShaderResourceView*>(pShaderResourceView);
if (view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) if (!view || view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER)
return; return;
EmitCs([cDstImageView = view->GetImageView()] EmitCs([cDstImageView = view->GetImageView()]
@ -998,6 +1007,9 @@ namespace dxvk {
UINT SrcRowPitch, UINT SrcRowPitch,
UINT SrcDepthPitch, UINT SrcDepthPitch,
UINT CopyFlags) { UINT CopyFlags) {
if (!pDstResource)
return;
// We need a different code path for buffers // We need a different code path for buffers
D3D11_RESOURCE_DIMENSION resourceType; D3D11_RESOURCE_DIMENSION resourceType;
pDstResource->GetType(&resourceType); pDstResource->GetType(&resourceType);
@ -1134,6 +1146,9 @@ namespace dxvk {
ID3D11Resource* pSrcResource, ID3D11Resource* pSrcResource,
UINT SrcSubresource, UINT SrcSubresource,
DXGI_FORMAT Format) { DXGI_FORMAT Format) {
if (!pDstResource || !pSrcResource)
return;
D3D11_RESOURCE_DIMENSION dstResourceType; D3D11_RESOURCE_DIMENSION dstResourceType;
D3D11_RESOURCE_DIMENSION srcResourceType; D3D11_RESOURCE_DIMENSION srcResourceType;