From 5c987ea3d163b2e3925a906b9027224b05626946 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Wed, 31 Jul 2024 11:50:31 -0600 Subject: [PATCH] [d3d9] Handle map failure in texture initializer --- src/d3d9/d3d9_common_texture.cpp | 2 ++ src/d3d9/d3d9_initializer.cpp | 21 +++++++++++++++------ src/d3d9/d3d9_initializer.h | 5 +++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index ba8a3140..be7474b5 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -194,6 +194,8 @@ namespace dxvk { m_data.Map(); uint8_t* ptr = reinterpret_cast(m_data.Ptr()); + if (ptr == nullptr) + return nullptr; ptr += m_memoryOffset[Subresource]; return ptr; } diff --git a/src/d3d9/d3d9_initializer.cpp b/src/d3d9/d3d9_initializer.cpp index 26dae412..ece83bd7 100644 --- a/src/d3d9/d3d9_initializer.cpp +++ b/src/d3d9/d3d9_initializer.cpp @@ -44,11 +44,21 @@ namespace dxvk { if (pTexture->GetMapMode() == D3D9_COMMON_TEXTURE_MAP_MODE_NONE) return; + void* mapPtr = nullptr; + + if (pTexture->Desc()->Pool != D3DPOOL_DEFAULT) { + mapPtr = pTexture->GetData(0); + if (mapPtr == nullptr) + throw DxvkError("D3D9: InitTexture: map failed"); + } + if (pTexture->GetImage() != nullptr) InitDeviceLocalTexture(pTexture); - if (pTexture->Desc()->Pool != D3DPOOL_DEFAULT) - InitHostVisibleTexture(pTexture, pInitialData); + if (mapPtr != nullptr) { + InitHostVisibleTexture(pTexture, pInitialData, mapPtr); + pTexture->UnmapData(); + } } @@ -109,11 +119,11 @@ namespace dxvk { void D3D9Initializer::InitHostVisibleTexture( D3D9CommonTexture* pTexture, - void* pInitialData) { + void* pInitialData, + void* mapPtr) { // If the buffer is mapped, we can write data directly // to the mapped memory region instead of doing it on // the GPU. Same goes for zero-initialization. - void* mapPtr = pTexture->GetData(0); if (pInitialData) { // Initial data is only supported for textures with 1 subresource VkExtent3D mipExtent = pTexture->GetExtentMip(0); @@ -141,7 +151,6 @@ namespace dxvk { mapPtr, 0, pTexture->GetTotalSize()); } - pTexture->UnmapData(); } @@ -159,4 +168,4 @@ namespace dxvk { m_transferMemory = 0; } -} \ No newline at end of file +} diff --git a/src/d3d9/d3d9_initializer.h b/src/d3d9/d3d9_initializer.h index 59802f95..69ce5d33 100644 --- a/src/d3d9/d3d9_initializer.h +++ b/src/d3d9/d3d9_initializer.h @@ -52,11 +52,12 @@ namespace dxvk { void InitHostVisibleTexture( D3D9CommonTexture* pTexture, - void* pInitialData); + void* pInitialData, + void* mapPtr); void FlushImplicit(); void FlushInternal(); }; -} \ No newline at end of file +}