From f9e096e9541ab0326b89a7a3cc00322f7b3c45fd Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 9 Aug 2018 23:37:41 +0200 Subject: [PATCH] [d3d11] Validate buffer view format compatibility Prevents the app from creating illegal buffer views. --- src/d3d11/d3d11_buffer.cpp | 16 ++++++++++++++-- src/d3d11/d3d11_buffer.h | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/d3d11/d3d11_buffer.cpp b/src/d3d11/d3d11_buffer.cpp index 62be0f449..b741d9401 100644 --- a/src/d3d11/d3d11_buffer.cpp +++ b/src/d3d11/d3d11_buffer.cpp @@ -74,8 +74,12 @@ namespace dxvk { if ((m_buffer->info().usage & usage) != usage) return false; - // TODO implement format validation - return true; + // Check whether the given combination of buffer view + // type and view format is supported by the device + DXGI_VK_FORMAT_INFO viewFormat = m_device->LookupFormat(Format, DXGI_VK_FORMAT_MODE_ANY); + VkFormatFeatureFlags features = GetBufferFormatFeatures(BindFlags); + + return CheckFormatFeatureSupport(viewFormat.Format, features); } @@ -163,6 +167,14 @@ namespace dxvk { return m_device->GetDXVKDevice()->createBuffer(info, memoryFlags); } + + + BOOL D3D11Buffer::CheckFormatFeatureSupport( + VkFormat Format, + VkFormatFeatureFlags Features) const { + VkFormatProperties properties = m_device->GetDXVKDevice()->adapter()->formatProperties(Format); + return (properties.bufferFeatures & Features) == Features; + } D3D11Buffer* GetCommonBuffer(ID3D11Resource* pResource) { diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index e10b8b951..1e1ac21a2 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -82,7 +82,11 @@ namespace dxvk { DxvkPhysicalBufferSlice m_mappedSlice; Rc CreateBuffer( - const D3D11_BUFFER_DESC* pDesc) const; + const D3D11_BUFFER_DESC* pDesc) const; + + BOOL CheckFormatFeatureSupport( + VkFormat Format, + VkFormatFeatureFlags Features) const; };