From be7a70a307e84843dc3edb2b63140066f8d2e9a5 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 7 Dec 2017 13:31:32 +0100 Subject: [PATCH] [d3d11] Implemented buffer creation --- src/d3d11/d3d11_buffer.cpp | 12 +++++++++++ src/d3d11/d3d11_buffer.h | 4 ++++ src/d3d11/d3d11_device.cpp | 43 +++++++++++++++++++++++++++++++------- src/d3d11/d3d11_device.h | 2 ++ 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 3037721d1..cd1c8c3e3 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -39,6 +39,18 @@ namespace dxvk { } + UINT D3D11Buffer::GetEvictionPriority() { + UINT EvictionPriority = DXGI_RESOURCE_PRIORITY_NORMAL; + m_resource->GetEvictionPriority(&EvictionPriority); + return EvictionPriority; + } + + + void D3D11Buffer::SetEvictionPriority(UINT EvictionPriority) { + m_resource->SetEvictionPriority(EvictionPriority); + } + + void D3D11Buffer::GetType(D3D11_RESOURCE_DIMENSION* pResourceDimension) { *pResourceDimension = D3D11_RESOURCE_DIMENSION_BUFFER; } diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index eef869a3f..c4563fe46 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -30,6 +30,10 @@ namespace dxvk { void GetType( D3D11_RESOURCE_DIMENSION *pResourceDimension) final; + UINT GetEvictionPriority() final; + + void SetEvictionPriority(UINT EvictionPriority) final; + void GetDesc( D3D11_BUFFER_DESC *pDesc) final; diff --git a/src/d3d11/d3d11_device.cpp b/src/d3d11/d3d11_device.cpp index 4c7b811bc..105cf0917 100644 --- a/src/d3d11/d3d11_device.cpp +++ b/src/d3d11/d3d11_device.cpp @@ -62,6 +62,7 @@ namespace dxvk { const D3D11_BUFFER_DESC* pDesc, const D3D11_SUBRESOURCE_DATA* pInitialData, ID3D11Buffer** ppBuffer) { + // Gather usage information DxvkBufferCreateInfo info; info.size = pDesc->ByteWidth; @@ -85,14 +86,14 @@ namespace dxvk { if (pDesc->BindFlags & D3D11_BIND_CONSTANT_BUFFER) { info.usage |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; - info.stages |= enabledShaderPipelineStages; + info.stages |= GetEnabledShaderStages(); info.access |= VK_ACCESS_SHADER_READ_BIT; } if (pDesc->BindFlags & D3D11_BIND_SHADER_RESOURCE) { info.usage |= VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT | VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT; - info.stages |= enabledShaderPipelineStages; + info.stages |= GetEnabledShaderStages(); info.access |= VK_ACCESS_SHADER_READ_BIT; } @@ -110,18 +111,26 @@ namespace dxvk { | VK_ACCESS_SHADER_WRITE_BIT; } - if (info.MiscFlags & D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS) { + if (pDesc->MiscFlags & D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS) { info.usage |= VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT; info.stages |= VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT; info.access |= VK_ACCESS_INDIRECT_COMMAND_READ_BIT; } - // Find the optimal memory type for the - // resource based on the usage pattern. - - + // Create the buffer if the application requests it if (ppBuffer != nullptr) { - DXGICreateBufferResourcePrivate + Com buffer; + + HRESULT hr = DXGICreateBufferResourcePrivate( + m_dxgiDevice.ptr(), &info, + GetMemoryFlagsForUsage(pDesc->Usage), 0, + &buffer); + + if (FAILED(hr)) + return hr; + + *ppBuffer = ref(new D3D11Buffer( + this, buffer.ptr(), *pDesc)); } return S_OK; @@ -799,6 +808,24 @@ namespace dxvk { } + VkPipelineStageFlags D3D11Device::GetEnabledShaderStages() const { + VkPipelineStageFlags enabledShaderPipelineStages + = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT + | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT + | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; + + if (m_dxvkDevice->features().geometryShader) + enabledShaderPipelineStages |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT; + + if (m_dxvkDevice->features().tessellationShader) { + enabledShaderPipelineStages |= VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT + | VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT; + } + + return enabledShaderPipelineStages; + } + + VkMemoryPropertyFlags D3D11Device::GetMemoryFlagsForUsage(D3D11_USAGE usage) const { VkMemoryPropertyFlags memoryFlags = 0; diff --git a/src/d3d11/d3d11_device.h b/src/d3d11/d3d11_device.h index d794a0fc1..c703ce489 100644 --- a/src/d3d11/d3d11_device.h +++ b/src/d3d11/d3d11_device.h @@ -252,6 +252,8 @@ namespace dxvk { size_t BytecodeLength, ID3D11ClassLinkage* pClassLinkage); + VkPipelineStageFlags GetEnabledShaderStages() const; + VkMemoryPropertyFlags GetMemoryFlagsForUsage( D3D11_USAGE usage) const;