Program Listing for File directx11-utilities.h
↰ Return to documentation for file (include\utility\directx11-utilities.h
)
/******************************************************************************
© Intel Corporation.
This software and the related documents are Intel copyrighted materials,
and your use of them is governed by the express license under which they
were provided to you ("License"). Unless the License provides otherwise,
you may not use, modify, copy, publish, distribute, disclose or transmit
this software or the related documents without Intel's prior written
permission.
This software and the related documents are provided as is, with no express
or implied warranties, other than those that are expressly stated in the
License.
******************************************************************************/
#pragma once
#include <d3d11_4.h>
#include <array>
#include <inttypes.h>
#include <atlbase.h>
#include <atlsafe.h>
namespace gpa {
namespace utility {
namespace directx {
#define MAX_NUM_INSTANCES 256
#define MAX_SO_OUPUTS 4
#define CComPtrArray(TYPE, COUNT) std::array<CComPtr<TYPE>, COUNT>
template<typename ID3D11ShaderType>
struct D3D11ShaderStageBlock
{
CComPtrArray(ID3D11Buffer, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT) constantBuffers;
UINT firstConstants[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]{};
UINT numConstants[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]{};
CComPtrArray(ID3D11SamplerState, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT) samplerStates;
CComPtr<ID3D11ShaderType> shader;
CComPtr<ID3D11ClassInstance> instance;
CComPtrArray(ID3D11ClassInstance, MAX_NUM_INSTANCES) classInstances;
UINT classInstancesNum{0};
CComPtrArray(ID3D11ShaderResourceView, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT) shaderResources;
CComPtrArray(ID3D11UnorderedAccessView, D3D11_1_UAV_SLOT_COUNT) uavs;
UINT uavsInitialCounts[D3D11_1_UAV_SLOT_COUNT]{};
};
class D3D11StateBlock
{
private:
ID3D11DeviceContext3* mDeviceContext{nullptr};
D3D11ShaderStageBlock<ID3D11ComputeShader> mCS;
D3D11ShaderStageBlock<ID3D11DomainShader> mDS;
D3D11ShaderStageBlock<ID3D11GeometryShader> mGS;
D3D11ShaderStageBlock<ID3D11HullShader> mHS;
D3D11ShaderStageBlock<ID3D11PixelShader> mPS;
D3D11ShaderStageBlock<ID3D11VertexShader> mVS;
CComPtr<ID3D11Predicate> mPredication;
BOOL mPredicateValue{FALSE};
CComPtr<ID3D11InputLayout> mInputLayout;
CComPtr<ID3D11Buffer> mIndexBuffer;
DXGI_FORMAT mIndexBufferFormat{DXGI_FORMAT_UNKNOWN};
uint32_t mIndexBufferOffset{0};
D3D11_PRIMITIVE_TOPOLOGY mPrimitiveTopology{};
std::array<CComPtr<ID3D11Buffer>, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT> mVertexBuffers;
uint32_t mStrides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]{};
uint32_t mOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]{};
CComPtr<ID3D11BlendState> mBlendState;
float mBlendFactor[4]{};
uint32_t mSampleMask{0};
CComPtr<ID3D11DepthStencilState> mDepthStencilState;
uint32_t mStencilRef{0};
CComPtrArray(ID3D11RenderTargetView, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT) mRenderTargetViews;
CComPtrArray(ID3D11UnorderedAccessView, D3D11_1_UAV_SLOT_COUNT) mUAVs;
UINT mUAVSStartSlot{D3D11_KEEP_UNORDERED_ACCESS_VIEWS};
UINT mUavsInitialCounts[D3D11_1_UAV_SLOT_COUNT]{};
CComPtr<ID3D11DepthStencilView> mDepthStencilView;
CComPtr<ID3D11RasterizerState> mRasterizerState;
uint32_t mNumScissorRects{0};
D3D11_RECT mScissorRects[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]{};
uint32_t mNumViewports{0};
D3D11_VIEWPORT mViewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]{};
CComPtrArray(ID3D11Buffer, MAX_SO_OUPUTS) mSOTargets;
uint32_t mMaxUAVSlotCount{0};
public:
D3D11StateBlock(ID3D11DeviceContext3* pDeviceContext);
~D3D11StateBlock();
void Capture();
void Apply();
};
} // namespace directx
} // namespace utility
} // namespace gpa