2018-08-05 18:45:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-27 19:13:55 +02:00
|
|
|
#include "d3d11_include.h"
|
2018-08-05 18:45:24 +02:00
|
|
|
|
|
|
|
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 {
|
2018-08-10 02:15:30 +02:00
|
|
|
D3D11_RESOURCE_DIMENSION Dim;
|
|
|
|
DXGI_FORMAT Format;
|
|
|
|
D3D11_USAGE Usage;
|
|
|
|
UINT BindFlags;
|
|
|
|
UINT CPUAccessFlags;
|
|
|
|
UINT MiscFlags;
|
2021-02-12 01:52:20 +01:00
|
|
|
UINT DxgiUsage;
|
2018-08-05 18:45:24 +02:00
|
|
|
};
|
2019-04-27 19:13:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief IDXGIResource implementation for D3D11 resources
|
|
|
|
*/
|
|
|
|
class D3D11DXGIResource : public IDXGIResource1 {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
D3D11DXGIResource(
|
|
|
|
ID3D11Resource* pResource);
|
|
|
|
|
|
|
|
~D3D11DXGIResource();
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE AddRef();
|
|
|
|
|
|
|
|
ULONG STDMETHODCALLTYPE Release();
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE QueryInterface(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetPrivateData(
|
|
|
|
REFGUID Name,
|
|
|
|
UINT* pDataSize,
|
|
|
|
void* pData);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE SetPrivateData(
|
|
|
|
REFGUID Name,
|
|
|
|
UINT DataSize,
|
|
|
|
const void* pData);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
|
|
|
|
REFGUID Name,
|
|
|
|
const IUnknown* pUnknown);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetParent(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppParent);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetDevice(
|
|
|
|
REFIID riid,
|
|
|
|
void** ppDevice);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetEvictionPriority(
|
|
|
|
UINT* pEvictionPriority);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetSharedHandle(
|
|
|
|
HANDLE* pSharedHandle);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE GetUsage(
|
|
|
|
DXGI_USAGE* pUsage);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE SetEvictionPriority(
|
|
|
|
UINT EvictionPriority);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CreateSharedHandle(
|
|
|
|
const SECURITY_ATTRIBUTES* pAttributes,
|
|
|
|
DWORD dwAccess,
|
|
|
|
LPCWSTR lpName,
|
|
|
|
HANDLE* pHandle);
|
|
|
|
|
|
|
|
HRESULT STDMETHODCALLTYPE CreateSubresourceSurface(
|
|
|
|
UINT index,
|
|
|
|
IDXGISurface2** ppSurface);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
ID3D11Resource* m_resource;
|
|
|
|
|
|
|
|
};
|
2018-08-05 18:45:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \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 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
|
2021-05-20 16:50:15 +02:00
|
|
|
* \param [in] BindFlags Bind flags required for the view
|
2018-08-05 18:45:24 +02:00
|
|
|
* \param [in] Format The desired view format
|
2021-05-20 16:50:15 +02:00
|
|
|
* \param [in] Plane Plane slice for planar formats
|
2018-08-05 18:45:24 +02:00
|
|
|
* \returns \c true if the format is compatible
|
|
|
|
*/
|
2018-08-09 21:58:58 +02:00
|
|
|
BOOL CheckResourceViewCompatibility(
|
2018-08-05 18:45:24 +02:00
|
|
|
ID3D11Resource* pResource,
|
2018-08-09 21:58:58 +02:00
|
|
|
UINT BindFlags,
|
2021-05-20 16:50:15 +02:00
|
|
|
DXGI_FORMAT Format,
|
|
|
|
UINT Plane);
|
2018-08-05 20:55:16 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Increments private reference count of a resource
|
|
|
|
*
|
|
|
|
* Helper method that figures out the exact type of
|
|
|
|
* the resource and calls its \c AddRefPrivate method.
|
|
|
|
* \param [in] pResource The resource to reference
|
2022-02-09 03:55:39 +01:00
|
|
|
* \param [in] Type Resource type
|
2018-08-05 20:55:16 +02:00
|
|
|
* \returns \c S_OK, or \c E_INVALIDARG for an invalid resource
|
|
|
|
*/
|
|
|
|
HRESULT ResourceAddRefPrivate(
|
2022-02-09 03:55:39 +01:00
|
|
|
ID3D11Resource* pResource,
|
|
|
|
D3D11_RESOURCE_DIMENSION Type);
|
2018-08-05 20:55:16 +02:00
|
|
|
|
2022-02-09 03:55:39 +01:00
|
|
|
HRESULT ResourceAddRefPrivate(
|
|
|
|
ID3D11Resource* pResource);
|
|
|
|
|
2018-08-05 20:55:16 +02:00
|
|
|
/**
|
|
|
|
* \brief Decrements private reference count of a resource
|
|
|
|
*
|
|
|
|
* Helper method that figures out the exact type of
|
|
|
|
* the resource and calls its \c ReleasePrivate method.
|
|
|
|
* \param [in] pResource The resource to reference
|
2022-02-09 03:55:39 +01:00
|
|
|
* \param [in] Type Resource type
|
2018-08-05 20:55:16 +02:00
|
|
|
* \returns \c S_OK, or \c E_INVALIDARG for an invalid resource
|
|
|
|
*/
|
2022-02-09 03:55:39 +01:00
|
|
|
HRESULT ResourceReleasePrivate(
|
|
|
|
ID3D11Resource* pResource,
|
|
|
|
D3D11_RESOURCE_DIMENSION Type);
|
|
|
|
|
2018-08-05 20:55:16 +02:00
|
|
|
HRESULT ResourceReleasePrivate(
|
|
|
|
ID3D11Resource* pResource);
|
2018-08-05 18:45:24 +02:00
|
|
|
|
2022-02-09 04:07:55 +01:00
|
|
|
/**
|
|
|
|
* \brief Typed private resource pointer
|
|
|
|
*
|
|
|
|
* Stores a resource and its type, in order to avoid
|
|
|
|
* unnecessary GetType calls. Also optionally stores
|
|
|
|
* a subresource index to avoid struct padding.
|
|
|
|
*/
|
|
|
|
class D3D11ResourceRef {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
D3D11ResourceRef()
|
|
|
|
: m_type(D3D11_RESOURCE_DIMENSION_UNKNOWN),
|
|
|
|
m_subresource(0), m_resource(nullptr) { }
|
|
|
|
|
|
|
|
D3D11ResourceRef(ID3D11Resource* pResource)
|
2022-02-10 14:23:24 +01:00
|
|
|
: D3D11ResourceRef(pResource, 0) { }
|
|
|
|
|
|
|
|
D3D11ResourceRef(ID3D11Resource* pResource, UINT Subresource)
|
2022-02-09 04:07:55 +01:00
|
|
|
: m_type(D3D11_RESOURCE_DIMENSION_UNKNOWN),
|
2022-02-10 14:23:24 +01:00
|
|
|
m_subresource(Subresource), m_resource(pResource) {
|
2022-02-09 04:07:55 +01:00
|
|
|
if (m_resource) {
|
|
|
|
m_resource->GetType(&m_type);
|
|
|
|
ResourceAddRefPrivate(m_resource, m_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-10 14:23:24 +01:00
|
|
|
D3D11ResourceRef(ID3D11Resource* pResource, UINT Subresource, D3D11_RESOURCE_DIMENSION Type)
|
2022-02-09 04:07:55 +01:00
|
|
|
: m_type(Type), m_subresource(Subresource), m_resource(pResource) {
|
|
|
|
if (m_resource)
|
|
|
|
ResourceAddRefPrivate(m_resource, m_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11ResourceRef(D3D11ResourceRef&& other)
|
2022-02-15 12:59:40 +01:00
|
|
|
: m_type(other.m_type), m_subresource(other.m_subresource), m_resource(other.m_resource) {
|
2022-02-09 04:07:55 +01:00
|
|
|
other.m_type = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
2022-02-15 12:59:40 +01:00
|
|
|
other.m_subresource = 0;
|
2022-02-09 04:07:55 +01:00
|
|
|
other.m_resource = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11ResourceRef(const D3D11ResourceRef& other)
|
2022-02-15 12:59:40 +01:00
|
|
|
: m_type(other.m_type), m_subresource(other.m_subresource), m_resource(other.m_resource) {
|
2022-02-09 04:07:55 +01:00
|
|
|
if (m_resource)
|
|
|
|
ResourceAddRefPrivate(m_resource, m_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
~D3D11ResourceRef() {
|
|
|
|
if (m_resource)
|
|
|
|
ResourceReleasePrivate(m_resource, m_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11ResourceRef& operator = (D3D11ResourceRef&& other) {
|
|
|
|
if (m_resource)
|
|
|
|
ResourceReleasePrivate(m_resource, m_type);
|
|
|
|
|
|
|
|
m_type = other.m_type;
|
2022-02-15 12:59:40 +01:00
|
|
|
m_subresource = other.m_subresource;
|
2022-02-09 04:07:55 +01:00
|
|
|
m_resource = other.m_resource;
|
|
|
|
|
|
|
|
other.m_type = D3D11_RESOURCE_DIMENSION_UNKNOWN;
|
2022-02-15 12:59:40 +01:00
|
|
|
other.m_subresource = 0;
|
2022-02-09 04:07:55 +01:00
|
|
|
other.m_resource = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11ResourceRef& operator = (const D3D11ResourceRef& other) {
|
|
|
|
if (other.m_resource)
|
|
|
|
ResourceAddRefPrivate(other.m_resource, other.m_type);
|
|
|
|
|
|
|
|
if (m_resource)
|
|
|
|
ResourceReleasePrivate(m_resource, m_type);
|
|
|
|
|
|
|
|
m_type = other.m_type;
|
2022-02-15 12:59:40 +01:00
|
|
|
m_subresource = other.m_subresource;
|
2022-02-09 04:07:55 +01:00
|
|
|
m_resource = other.m_resource;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3D11_RESOURCE_DIMENSION GetType() const {
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT GetSubresource() const {
|
|
|
|
return m_subresource;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3D11Resource* Get() const {
|
|
|
|
return m_resource;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
D3D11_RESOURCE_DIMENSION m_type;
|
|
|
|
UINT m_subresource;
|
|
|
|
ID3D11Resource* m_resource;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-08-05 18:45:24 +02:00
|
|
|
}
|