mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-03 22:24:13 +01:00
[d3d11] Add common resource helper functions
This commit is contained in:
parent
66e178756e
commit
b87f3f5155
@ -37,6 +37,10 @@ namespace dxvk {
|
|||||||
void STDMETHODCALLTYPE GetDesc(
|
void STDMETHODCALLTYPE GetDesc(
|
||||||
D3D11_BUFFER_DESC *pDesc) final;
|
D3D11_BUFFER_DESC *pDesc) final;
|
||||||
|
|
||||||
|
const D3D11_BUFFER_DESC* Desc() const {
|
||||||
|
return &m_desc;
|
||||||
|
}
|
||||||
|
|
||||||
Rc<DxvkBuffer> GetBuffer() const {
|
Rc<DxvkBuffer> GetBuffer() const {
|
||||||
return m_buffer;
|
return m_buffer;
|
||||||
}
|
}
|
||||||
@ -64,7 +68,7 @@ namespace dxvk {
|
|||||||
void SetMappedSlice(const DxvkPhysicalBufferSlice& slice) {
|
void SetMappedSlice(const DxvkPhysicalBufferSlice& slice) {
|
||||||
m_mappedSlice = slice;
|
m_mappedSlice = slice;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const Com<D3D11Device> m_device;
|
const Com<D3D11Device> m_device;
|
||||||
|
53
src/d3d11/d3d11_resource.cpp
Normal file
53
src/d3d11/d3d11_resource.cpp
Normal 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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
63
src/d3d11/d3d11_resource.h
Normal file
63
src/d3d11/d3d11_resource.h
Normal 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);
|
||||||
|
|
||||||
|
}
|
@ -18,6 +18,7 @@ d3d11_src = [
|
|||||||
'd3d11_present.cpp',
|
'd3d11_present.cpp',
|
||||||
'd3d11_query.cpp',
|
'd3d11_query.cpp',
|
||||||
'd3d11_rasterizer.cpp',
|
'd3d11_rasterizer.cpp',
|
||||||
|
'd3d11_resource.cpp',
|
||||||
'd3d11_sampler.cpp',
|
'd3d11_sampler.cpp',
|
||||||
'd3d11_shader.cpp',
|
'd3d11_shader.cpp',
|
||||||
'd3d11_state.cpp',
|
'd3d11_state.cpp',
|
||||||
|
Loading…
Reference in New Issue
Block a user