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

[d3d11] Add common resource helper functions

This commit is contained in:
Philip Rebohle 2018-08-05 18:45:24 +02:00
parent 66e178756e
commit b87f3f5155
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 122 additions and 1 deletions

View File

@ -37,6 +37,10 @@ namespace dxvk {
void STDMETHODCALLTYPE GetDesc(
D3D11_BUFFER_DESC *pDesc) final;
const D3D11_BUFFER_DESC* Desc() const {
return &m_desc;
}
Rc<DxvkBuffer> GetBuffer() const {
return m_buffer;
}
@ -64,7 +68,7 @@ namespace dxvk {
void SetMappedSlice(const DxvkPhysicalBufferSlice& slice) {
m_mappedSlice = slice;
}
private:
const Com<D3D11Device> m_device;

View File

@ -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 */
}
}

View File

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

View File

@ -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',