Skip to content

Commit

Permalink
[d3d9] Handle map failure in texture initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Gofman authored and doitsujin committed Aug 8, 2024
1 parent e38693c commit 5c987ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ namespace dxvk {

m_data.Map();
uint8_t* ptr = reinterpret_cast<uint8_t*>(m_data.Ptr());
if (ptr == nullptr)
return nullptr;
ptr += m_memoryOffset[Subresource];
return ptr;
}
Expand Down
21 changes: 15 additions & 6 deletions src/d3d9/d3d9_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -141,7 +151,6 @@ namespace dxvk {
mapPtr, 0,
pTexture->GetTotalSize());
}
pTexture->UnmapData();
}


Expand All @@ -159,4 +168,4 @@ namespace dxvk {
m_transferMemory = 0;
}

}
}
5 changes: 3 additions & 2 deletions src/d3d9/d3d9_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ namespace dxvk {

void InitHostVisibleTexture(
D3D9CommonTexture* pTexture,
void* pInitialData);
void* pInitialData,
void* mapPtr);

void FlushImplicit();
void FlushInternal();

};

}
}

0 comments on commit 5c987ea

Please sign in to comment.