From b87f3f51553198089c54be1c9068f682ae25b024 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 5 Aug 2018 18:45:24 +0200 Subject: [PATCH] [d3d11] Add common resource helper functions --- src/d3d11/d3d11_buffer.h | 6 +++- src/d3d11/d3d11_resource.cpp | 53 ++++++++++++++++++++++++++++++ src/d3d11/d3d11_resource.h | 63 ++++++++++++++++++++++++++++++++++++ src/d3d11/meson.build | 1 + 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/d3d11/d3d11_resource.cpp create mode 100644 src/d3d11/d3d11_resource.h diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index db4cdd0f..f4e508dc 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -37,6 +37,10 @@ namespace dxvk { void STDMETHODCALLTYPE GetDesc( D3D11_BUFFER_DESC *pDesc) final; + const D3D11_BUFFER_DESC* Desc() const { + return &m_desc; + } + Rc GetBuffer() const { return m_buffer; } @@ -64,7 +68,7 @@ namespace dxvk { void SetMappedSlice(const DxvkPhysicalBufferSlice& slice) { m_mappedSlice = slice; } - + private: const Com m_device; diff --git a/src/d3d11/d3d11_resource.cpp b/src/d3d11/d3d11_resource.cpp new file mode 100644 index 00000000..88002bd9 --- /dev/null +++ b/src/d3d11/d3d11_resource.cpp @@ -0,0 +1,53 @@ +#include "d3d11_resource.h" + +namespace dxvk { + + HRESULT GetCommonResourceDesc( + ID3D11Resource* pResource, + D3D11_COMMON_RESOURCE_DESC* pDesc) { + auto buffer = GetCommonBuffer (pResource); + auto texture = GetCommonTexture(pResource); + + if (buffer != nullptr) { + pDesc->Usage = buffer->Desc()->Usage; + pDesc->BindFlags = buffer->Desc()->BindFlags; + pDesc->CPUAccessFlags = buffer->Desc()->CPUAccessFlags; + pDesc->MiscFlags = buffer->Desc()->MiscFlags; + return S_OK; + } else if (texture != nullptr) { + pDesc->Usage = texture->Desc()->Usage; + pDesc->BindFlags = texture->Desc()->BindFlags; + pDesc->CPUAccessFlags = texture->Desc()->CPUAccessFlags; + pDesc->MiscFlags = texture->Desc()->MiscFlags; + return S_OK; + } else { + pDesc->Usage = D3D11_USAGE_DEFAULT; + pDesc->BindFlags = 0; + pDesc->CPUAccessFlags = 0; + pDesc->MiscFlags = 0; + return E_INVALIDARG; + } + } + + + BOOL CheckResourceBindFlags( + ID3D11Resource* pResource, + UINT BindFlags) { + D3D11_COMMON_RESOURCE_DESC desc; + GetCommonResourceDesc(pResource, &desc); + + return (desc.BindFlags & BindFlags) == BindFlags; + } + + + BOOL CheckResourceViewFormatCompatibility( + ID3D11Resource* pResource, + DXGI_FORMAT Format) { + auto texture = GetCommonTexture(pResource); + + return texture != nullptr + ? texture->CheckViewFormatCompatibility(Format) + : true; /* for buffers */ + } + +} \ No newline at end of file diff --git a/src/d3d11/d3d11_resource.h b/src/d3d11/d3d11_resource.h new file mode 100644 index 00000000..5f93590a --- /dev/null +++ b/src/d3d11/d3d11_resource.h @@ -0,0 +1,63 @@ +#pragma once + +#include "d3d11_buffer.h" +#include "d3d11_texture.h" + +namespace dxvk { + + /** + * \brief Common resource description + * + * Stores the usage and bind flags of a resource + * Can be used to quickly determine whether it is + * legal to create a view for a given resource. + */ + struct D3D11_COMMON_RESOURCE_DESC { + D3D11_USAGE Usage; + UINT BindFlags; + UINT CPUAccessFlags; + UINT MiscFlags; + }; + + + /** + * \brief Queries common resource description + * + * \param [in] pResource The resource to query + * \param [out] pDesc Resource description + * \returns \c S_OK on success, or \c E_INVALIDARG + */ + HRESULT GetCommonResourceDesc( + ID3D11Resource* pResource, + D3D11_COMMON_RESOURCE_DESC* pDesc); + + /** + * \brief Checks whether a resource has the given bind flags + * + * Convenience method that checks whether a resource + * was created with \c all the specified bind flags + * set. Can be used to check whether a specific type + * of view can be created for this resource. + * \param [in] pResource The resource to check + * \param [in] BindFlags Bind flags to check + * \returns \c true if the resource supports the flags + */ + BOOL CheckResourceBindFlags( + ID3D11Resource* pResource, + UINT BindFlags); + + /** + * \brief Checks whether a format can be used to view a resource + * + * Depending on whether the resource is a buffer or a + * texture, certain restrictions apply on which formats + * can be used to view the resource. + * \param [in] pResource The resource to check + * \param [in] Format The desired view format + * \returns \c true if the format is compatible + */ + BOOL CheckResourceViewFormatCompatibility( + ID3D11Resource* pResource, + DXGI_FORMAT Format); + +} \ No newline at end of file diff --git a/src/d3d11/meson.build b/src/d3d11/meson.build index db007a57..3efc6e44 100644 --- a/src/d3d11/meson.build +++ b/src/d3d11/meson.build @@ -18,6 +18,7 @@ d3d11_src = [ 'd3d11_present.cpp', 'd3d11_query.cpp', 'd3d11_rasterizer.cpp', + 'd3d11_resource.cpp', 'd3d11_sampler.cpp', 'd3d11_shader.cpp', 'd3d11_state.cpp',