Skip to content

Commit

Permalink
[d3d9] Make unmapping delay configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin committed Apr 19, 2022
1 parent 55ec417 commit 71c393d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
7 changes: 7 additions & 0 deletions dxvk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -546,3 +546,10 @@
# - True/False

# dxvk.enableDebugUtils = False

# Unmapping delay
#
# DXVK will unmap D3D9 managed data after a certain number of frames.
# 0 to disable unmapping.

# d3d9.unmapDelay = 16
15 changes: 15 additions & 0 deletions src/d3d9/d3d9_common_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,21 @@ namespace dxvk {
return VK_IMAGE_LAYOUT_GENERAL;
}

D3D9_COMMON_TEXTURE_MAP_MODE D3D9CommonTexture::DetermineMapMode() const {
if (m_desc.Format == D3D9Format::NULL_FORMAT)
return D3D9_COMMON_TEXTURE_MAP_MODE_NONE;

if (m_desc.Pool == D3DPOOL_SYSTEMMEM || m_desc.Pool == D3DPOOL_SCRATCH)
return D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM;

#ifdef D3D9_ALLOW_UNMAPPING
if (IsManaged() && m_device->GetOptions()->unmapDelay != 0)
return D3D9_COMMON_TEXTURE_MAP_MODE_UNMAPPABLE;
#endif

return D3D9_COMMON_TEXTURE_MAP_MODE_BACKED;
}


void D3D9CommonTexture::ExportImageInfo() {
/* From MSDN:
Expand Down
15 changes: 1 addition & 14 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,20 +570,7 @@ namespace dxvk {
VkFormat Format,
VkImageTiling Tiling) const;

D3D9_COMMON_TEXTURE_MAP_MODE DetermineMapMode() const {
if (m_desc.Format == D3D9Format::NULL_FORMAT)
return D3D9_COMMON_TEXTURE_MAP_MODE_NONE;

if (m_desc.Pool == D3DPOOL_SYSTEMMEM || m_desc.Pool == D3DPOOL_SCRATCH)
return D3D9_COMMON_TEXTURE_MAP_MODE_SYSTEMMEM;

#ifdef D3D9_ALLOW_UNMAPPING
if (IsManaged())
return D3D9_COMMON_TEXTURE_MAP_MODE_UNMAPPABLE;
#endif

return D3D9_COMMON_TEXTURE_MAP_MODE_BACKED;
}
D3D9_COMMON_TEXTURE_MAP_MODE DetermineMapMode() const;

VkImageLayout OptimizeLayout(
VkImageUsageFlags Usage) const;
Expand Down
5 changes: 4 additions & 1 deletion src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7415,9 +7415,12 @@ namespace dxvk {
void D3D9DeviceEx::UnmapTextures() {
// Will only be called inside the device lock
#ifdef D3D9_USE_MEM_FILE_FOR_MANAGED
if (m_d3d9Options.unmapDelay == 0)
return;

const bool force = m_memoryAllocator.MappedMemory() > 512 << 20;
for (auto iter = m_mappedTextures.begin(); iter != m_mappedTextures.end();) {
const bool mappingBufferUnused = (m_frameCounter - (*iter)->GetMappingFrame() > 16 || force) && !(*iter)->IsAnySubresourceLocked();
const bool mappingBufferUnused = (m_frameCounter - (*iter)->GetMappingFrame() > uint32_t(m_d3d9Options.unmapDelay) || force) && !(*iter)->IsAnySubresourceLocked();
if (!mappingBufferUnused) {
iter++;
continue;
Expand Down
1 change: 1 addition & 0 deletions src/d3d9/d3d9_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace dxvk {
this->apitraceMode = config.getOption<bool> ("d3d9.apitraceMode", false);
this->deviceLocalConstantBuffers = config.getOption<bool> ("d3d9.deviceLocalConstantBuffers", false);
this->allowDirectBufferMapping = config.getOption<bool> ("d3d9.allowDirectBufferMapping", true);
this->unmapDelay = config.getOption<int32_t> ("d3d9.unmapDelay", 16);

// If we are not Nvidia, enable general hazards.
this->generalHazards = adapter != nullptr
Expand Down
3 changes: 3 additions & 0 deletions src/d3d9/d3d9_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ namespace dxvk {

/// Disable direct buffer mapping
bool allowDirectBufferMapping;

/// How many frames need to pass before managed data gets unmapped
int32_t unmapDelay;
};

}

0 comments on commit 71c393d

Please sign in to comment.