1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-03 04:24:11 +01:00

[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.
This commit is contained in:
Philip Rebohle 2019-09-17 17:21:10 +02:00
parent f7b311499c
commit 2cdbe2e6df
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 39 additions and 46 deletions

View File

@ -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) {

View File

@ -137,6 +137,8 @@ namespace dxvk {
VkFormat Format,
VkFormatFeatureFlags Features) const;
VkMemoryPropertyFlags GetMemoryFlags() const;
};

View File

@ -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;

View File

@ -31,9 +31,6 @@ namespace dxvk {
VkCompareOp DecodeCompareOp(
D3D11_COMPARISON_FUNC Mode);
VkMemoryPropertyFlags GetMemoryFlagsForUsage(
D3D11_USAGE Usage);
VkShaderStageFlagBits GetShaderStage(
DxbcProgramType ProgramType);