From 2cdbe2e6df7063809f3191039f10678dc1f4456c Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 17 Sep 2019 17:21:10 +0200 Subject: [PATCH] [d3d11] Move GetMemoryFlagsForUsage into D3D11Buffer D3D11Buffer is the only user of this function and the code sharing potential is limited. This allows us to implement the memory type selection for buffers in one single place rather than two. --- src/d3d11/d3d11_buffer.cpp | 55 +++++++++++++++++++++++++------------- src/d3d11/d3d11_buffer.h | 2 ++ src/d3d11/d3d11_util.cpp | 25 ----------------- src/d3d11/d3d11_util.h | 3 --- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 63bf7ce5..deac7599 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -79,26 +79,9 @@ namespace dxvk { D3D11_RESOURCE_MISC_BUFFER_STRUCTURED)) info.usage |= VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; - // Default constant buffers may get updated frequently, in which - // case mapping the buffer is faster than using update commands. - VkMemoryPropertyFlags memoryFlags = GetMemoryFlagsForUsage(pDesc->Usage); - - if ((pDesc->Usage == D3D11_USAGE_DEFAULT) && (pDesc->BindFlags & D3D11_BIND_CONSTANT_BUFFER)) { - info.stages |= VK_PIPELINE_STAGE_HOST_BIT; - info.access |= VK_ACCESS_HOST_WRITE_BIT; - - memoryFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - } - - // AMD cards have a device-local, host-visible memory type where - // we can put dynamic resources that need fast access by the GPU - if (pDesc->Usage == D3D11_USAGE_DYNAMIC && pDesc->BindFlags) - memoryFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; - // Create the buffer and set the entire buffer slice as mapped, // so that we only have to update it when invalidating th buffer - m_buffer = m_device->GetDXVKDevice()->createBuffer(info, memoryFlags); + m_buffer = m_device->GetDXVKDevice()->createBuffer(info, GetMemoryFlags()); m_mapped = m_buffer->getSliceHandle(); // For Stream Output buffers we need a counter @@ -228,6 +211,42 @@ namespace dxvk { VkFormatProperties properties = m_device->GetDXVKDevice()->adapter()->formatProperties(Format); return (properties.bufferFeatures & Features) == Features; } + + + VkMemoryPropertyFlags D3D11Buffer::GetMemoryFlags() const { + VkMemoryPropertyFlags memoryFlags = 0; + + switch (m_desc.Usage) { + case D3D11_USAGE_IMMUTABLE: + memoryFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + break; + + case D3D11_USAGE_DEFAULT: + memoryFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + + if (m_desc.BindFlags & D3D11_BIND_CONSTANT_BUFFER) { + memoryFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + } + break; + + case D3D11_USAGE_DYNAMIC: + memoryFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + + if (m_desc.BindFlags) + memoryFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + break; + + case D3D11_USAGE_STAGING: + memoryFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT + | VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + break; + } + + return memoryFlags; + } D3D11Buffer* GetCommonBuffer(ID3D11Resource* pResource) { diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 3211c74e..077354d4 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -137,6 +137,8 @@ namespace dxvk { VkFormat Format, VkFormatFeatureFlags Features) const; + VkMemoryPropertyFlags GetMemoryFlags() const; + }; diff --git a/src/d3d11/d3d11_util.cpp b/src/d3d11/d3d11_util.cpp index a3a2bf7e..2e609d47 100644 --- a/src/d3d11/d3d11_util.cpp +++ b/src/d3d11/d3d11_util.cpp @@ -64,31 +64,6 @@ namespace dxvk { } - VkMemoryPropertyFlags GetMemoryFlagsForUsage(D3D11_USAGE Usage) { - VkMemoryPropertyFlags memoryFlags = 0; - - switch (Usage) { - case D3D11_USAGE_DEFAULT: - case D3D11_USAGE_IMMUTABLE: - memoryFlags |= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; - break; - - case D3D11_USAGE_DYNAMIC: - memoryFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - break; - - case D3D11_USAGE_STAGING: - memoryFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT - | VK_MEMORY_PROPERTY_HOST_CACHED_BIT; - break; - } - - return memoryFlags; - } - - VkShaderStageFlagBits GetShaderStage(DxbcProgramType ProgramType) { switch (ProgramType) { case DxbcProgramType::VertexShader: return VK_SHADER_STAGE_VERTEX_BIT; diff --git a/src/d3d11/d3d11_util.h b/src/d3d11/d3d11_util.h index a7c961fd..9617031b 100644 --- a/src/d3d11/d3d11_util.h +++ b/src/d3d11/d3d11_util.h @@ -31,9 +31,6 @@ namespace dxvk { VkCompareOp DecodeCompareOp( D3D11_COMPARISON_FUNC Mode); - VkMemoryPropertyFlags GetMemoryFlagsForUsage( - D3D11_USAGE Usage); - VkShaderStageFlagBits GetShaderStage( DxbcProgramType ProgramType);