diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 63bf7ce58..deac75996 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 3211c74e4..077354d4c 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 a3a2bf7e4..2e609d47b 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 a7c961fde..9617031ba 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);