Skip to content

Commit

Permalink
[d3d11] Make D3D11 context methods more robust to null pointers
Browse files Browse the repository at this point in the history
Assetto Corsa tries to do some questionable things when reflections
are disabled in the game options. Refs #648.
  • Loading branch information
doitsujin committed Sep 19, 2018
1 parent c1190e8 commit a95f292
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/d3d11/d3d11_context.cpp
Expand Up @@ -63,10 +63,13 @@ namespace dxvk {


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;
pResource->GetType(&resType);

// We don't support the Discard API for images
if (resType == D3D11_RESOURCE_DIMENSION_BUFFER)
DiscardBuffer(static_cast<D3D11Buffer*>(pResource));
}
Expand Down Expand Up @@ -197,7 +200,7 @@ namespace dxvk {


void STDMETHODCALLTYPE D3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) {
if (pAsync == nullptr)
if (!pAsync)
return;

Com<ID3D11Query> query;
Expand All @@ -217,7 +220,7 @@ namespace dxvk {


void STDMETHODCALLTYPE D3D11DeviceContext::End(ID3D11Asynchronous *pAsync) {
if (pAsync == nullptr)
if (!pAsync)
return;

Com<ID3D11Query> query;
Expand Down Expand Up @@ -508,6 +511,9 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11DeviceContext::CopyResource(
ID3D11Resource* pDstResource,
ID3D11Resource* pSrcResource) {
if (!pDstResource || !pSrcResource)
return;

D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;

Expand Down Expand Up @@ -606,6 +612,9 @@ namespace dxvk {
auto buf = static_cast<D3D11Buffer*>(pDstBuffer);
auto uav = static_cast<D3D11UnorderedAccessView*>(pSrcView);

if (!buf || !uav)
return;

EmitCs([
cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset),
cSrcSlice = uav->GetCounterSlice()
Expand All @@ -625,7 +634,7 @@ namespace dxvk {
const FLOAT ColorRGBA[4]) {
auto rtv = static_cast<D3D11RenderTargetView*>(pRenderTargetView);

if (rtv == nullptr)
if (!rtv)
return;

const Rc<DxvkImageView> view = rtv->GetImageView();
Expand Down Expand Up @@ -653,7 +662,7 @@ namespace dxvk {
const UINT Values[4]) {
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);

if (uav == nullptr)
if (!uav)
return;

// Gather UAV format info. We'll use this to determine
Expand Down Expand Up @@ -746,7 +755,7 @@ namespace dxvk {
const FLOAT Values[4]) {
auto uav = static_cast<D3D11UnorderedAccessView*>(pUnorderedAccessView);

if (uav == nullptr)
if (!uav)
return;

VkClearValue clearValue;
Expand Down Expand Up @@ -786,7 +795,7 @@ namespace dxvk {
UINT8 Stencil) {
auto dsv = static_cast<D3D11DepthStencilView*>(pDepthStencilView);

if (dsv == nullptr)
if (!dsv)
return;

// Figure out which aspects to clear based
Expand Down Expand Up @@ -966,8 +975,8 @@ namespace dxvk {

void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) {
auto view = static_cast<D3D11ShaderResourceView*>(pShaderResourceView);
if (view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER)

if (!view || view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER)
return;

EmitCs([cDstImageView = view->GetImageView()]
Expand Down Expand Up @@ -998,6 +1007,9 @@ namespace dxvk {
UINT SrcRowPitch,
UINT SrcDepthPitch,
UINT CopyFlags) {
if (!pDstResource || !pSrcResource)
return;

// We need a different code path for buffers
D3D11_RESOURCE_DIMENSION resourceType;
pDstResource->GetType(&resourceType);
Expand Down Expand Up @@ -1134,6 +1146,9 @@ namespace dxvk {
ID3D11Resource* pSrcResource,
UINT SrcSubresource,
DXGI_FORMAT Format) {
if (!pDstResource || !pSrcResource)
return;

D3D11_RESOURCE_DIMENSION dstResourceType;
D3D11_RESOURCE_DIMENSION srcResourceType;

Expand Down

0 comments on commit a95f292

Please sign in to comment.