1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-05 20:52:11 +01:00
dxvk/src/d3d11/d3d11_context_common.h
2022-08-04 13:43:35 +02:00

293 lines
11 KiB
C++

#pragma once
#include <type_traits>
#include <vector>
#include "d3d11_buffer.h"
#include "d3d11_context.h"
#include "d3d11_texture.h"
namespace dxvk {
class D3D11DeferredContext;
class D3D11ImmediateContext;
template<bool IsDeferred>
struct D3D11ContextObjectForwarder;
/**
* \brief Object forwarder for immediate contexts
*
* Binding methods can use this to efficiently bind objects
* to the DXVK context without redundant reference counting.
*/
template<>
struct D3D11ContextObjectForwarder<false> {
template<typename T>
static T&& move(T& object) {
return std::move(object);
}
};
/**
* \brief Object forwarder for deferred contexts
*
* This forwarder will create a copy of the object passed
* into it, so that CS chunks can be reused if necessary.
*/
template<>
struct D3D11ContextObjectForwarder<true> {
template<typename T>
static T move(const T& object) {
return object;
}
};
/**
* \brief Common D3D11 device context implementation
*
* Implements all common device context methods, but since this is
* templates with the actual context type (deferred or immediate),
* all methods can call back into context-specific methods without
* having to use virtual methods.
*/
template<typename ContextType>
class D3D11CommonContext : public D3D11DeviceContext {
constexpr static bool IsDeferred = std::is_same_v<ContextType, D3D11DeferredContext>;
using Forwarder = D3D11ContextObjectForwarder<IsDeferred>;
public:
D3D11CommonContext(
D3D11Device* pParent,
const Rc<DxvkDevice>& Device,
DxvkCsChunkFlags CsFlags);
~D3D11CommonContext();
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject);
void STDMETHODCALLTYPE UpdateSubresource(
ID3D11Resource* pDstResource,
UINT DstSubresource,
const D3D11_BOX* pDstBox,
const void* pSrcData,
UINT SrcRowPitch,
UINT SrcDepthPitch);
void STDMETHODCALLTYPE UpdateSubresource1(
ID3D11Resource* pDstResource,
UINT DstSubresource,
const D3D11_BOX* pDstBox,
const void* pSrcData,
UINT SrcRowPitch,
UINT SrcDepthPitch,
UINT CopyFlags);
void STDMETHODCALLTYPE IASetInputLayout(
ID3D11InputLayout* pInputLayout);
void STDMETHODCALLTYPE IASetPrimitiveTopology(
D3D11_PRIMITIVE_TOPOLOGY Topology);
void STDMETHODCALLTYPE IASetVertexBuffers(
UINT StartSlot,
UINT NumBuffers,
ID3D11Buffer* const* ppVertexBuffers,
const UINT* pStrides,
const UINT* pOffsets);
void STDMETHODCALLTYPE IASetIndexBuffer(
ID3D11Buffer* pIndexBuffer,
DXGI_FORMAT Format,
UINT Offset);
void STDMETHODCALLTYPE IAGetInputLayout(
ID3D11InputLayout** ppInputLayout);
void STDMETHODCALLTYPE IAGetPrimitiveTopology(
D3D11_PRIMITIVE_TOPOLOGY* pTopology);
void STDMETHODCALLTYPE IAGetVertexBuffers(
UINT StartSlot,
UINT NumBuffers,
ID3D11Buffer** ppVertexBuffers,
UINT* pStrides,
UINT* pOffsets);
void STDMETHODCALLTYPE IAGetIndexBuffer(
ID3D11Buffer** ppIndexBuffer,
DXGI_FORMAT* pFormat,
UINT* pOffset);
void STDMETHODCALLTYPE OMSetRenderTargets(
UINT NumViews,
ID3D11RenderTargetView* const* ppRenderTargetViews,
ID3D11DepthStencilView* pDepthStencilView);
void STDMETHODCALLTYPE OMSetRenderTargetsAndUnorderedAccessViews(
UINT NumRTVs,
ID3D11RenderTargetView* const* ppRenderTargetViews,
ID3D11DepthStencilView* pDepthStencilView,
UINT UAVStartSlot,
UINT NumUAVs,
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
const UINT* pUAVInitialCounts);
void STDMETHODCALLTYPE OMSetBlendState(
ID3D11BlendState* pBlendState,
const FLOAT BlendFactor[4],
UINT SampleMask);
void STDMETHODCALLTYPE OMSetDepthStencilState(
ID3D11DepthStencilState* pDepthStencilState,
UINT StencilRef);
void STDMETHODCALLTYPE OMGetRenderTargets(
UINT NumViews,
ID3D11RenderTargetView** ppRenderTargetViews,
ID3D11DepthStencilView** ppDepthStencilView);
void STDMETHODCALLTYPE OMGetRenderTargetsAndUnorderedAccessViews(
UINT NumRTVs,
ID3D11RenderTargetView** ppRenderTargetViews,
ID3D11DepthStencilView** ppDepthStencilView,
UINT UAVStartSlot,
UINT NumUAVs,
ID3D11UnorderedAccessView** ppUnorderedAccessViews);
void STDMETHODCALLTYPE OMGetBlendState(
ID3D11BlendState** ppBlendState,
FLOAT BlendFactor[4],
UINT* pSampleMask);
void STDMETHODCALLTYPE OMGetDepthStencilState(
ID3D11DepthStencilState** ppDepthStencilState,
UINT* pStencilRef);
BOOL STDMETHODCALLTYPE IsAnnotationEnabled();
protected:
D3D11DeviceContextExt<ContextType> m_contextExt;
D3D11UserDefinedAnnotation<ContextType> m_annotation;
template<DxbcProgramType ShaderStage>
void BindShader(
const D3D11CommonShader* pShaderModule);
void BindFramebuffer();
void BindDrawBuffers(
D3D11Buffer* pBufferForArgs,
D3D11Buffer* pBufferForCount);
void BindVertexBuffer(
UINT Slot,
D3D11Buffer* pBuffer,
UINT Offset,
UINT Stride);
void BindIndexBuffer(
D3D11Buffer* pBuffer,
UINT Offset,
DXGI_FORMAT Format);
void BindXfbBuffer(
UINT Slot,
D3D11Buffer* pBuffer,
UINT Offset);
template<DxbcProgramType ShaderStage>
void BindConstantBuffer(
UINT Slot,
D3D11Buffer* pBuffer,
UINT Offset,
UINT Length);
template<DxbcProgramType ShaderStage>
void BindConstantBufferRange(
UINT Slot,
UINT Offset,
UINT Length);
template<DxbcProgramType ShaderStage>
void BindSampler(
UINT Slot,
D3D11SamplerState* pSampler);
template<DxbcProgramType ShaderStage>
void BindShaderResource(
UINT Slot,
D3D11ShaderResourceView* pResource);
template<DxbcProgramType ShaderStage>
void BindUnorderedAccessView(
UINT UavSlot,
D3D11UnorderedAccessView* pUav,
UINT CtrSlot,
UINT Counter);
template<DxbcProgramType ShaderStage, typename T>
void ResolveSrvHazards(
T* pView,
D3D11ShaderResourceBindings& Bindings);
template<typename T>
void ResolveCsSrvHazards(
T* pView);
template<typename T>
void ResolveOmSrvHazards(
T* pView);
bool ResolveOmRtvHazards(
D3D11UnorderedAccessView* pView);
void ResolveOmUavHazards(
D3D11RenderTargetView* pView);
void SetRenderTargetsAndUnorderedAccessViews(
UINT NumRTVs,
ID3D11RenderTargetView* const* ppRenderTargetViews,
ID3D11DepthStencilView* pDepthStencilView,
UINT UAVStartSlot,
UINT NumUAVs,
ID3D11UnorderedAccessView* const* ppUnorderedAccessViews,
const UINT* pUAVInitialCounts);
bool TestRtvUavHazards(
UINT NumRTVs,
ID3D11RenderTargetView* const* ppRTVs,
UINT NumUAVs,
ID3D11UnorderedAccessView* const* ppUAVs);
template<DxbcProgramType ShaderStage>
bool TestSrvHazards(
D3D11ShaderResourceView* pView);
void UpdateResource(
ID3D11Resource* pDstResource,
UINT DstSubresource,
const D3D11_BOX* pDstBox,
const void* pSrcData,
UINT SrcRowPitch,
UINT SrcDepthPitch,
UINT CopyFlags);
bool ValidateRenderTargets(
UINT NumViews,
ID3D11RenderTargetView* const* ppRenderTargetViews,
ID3D11DepthStencilView* pDepthStencilView);
private:
ContextType* GetTypedContext() {
return static_cast<ContextType*>(this);
}
};
}