Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- //
- // CommandSignature.h
- //
- // Defines the command signature for indirect rendering. Indirect rendering requires command
- // signature to interpret what are the parameters in single record of indirect buffer.
- //
- // This is done through indirect parameters which define type of each parameter (field) in the
- // buffer.
- //
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- #ifndef __COMMAND_SIGNATURE__H__
- #define __COMMAND_SIGNATURE__H__
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // Header section
- #include <d3d12.h>
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // Class & Structures definition
- namespace Engine
- {
- class D3DRenderer;
- class RootSignature;
- /// <summary>
- /// Defines single indirect parameter in the command signature for indirect rendering.
- ///
- /// There is a special requirement - all indirect parameters with any root parameter index have to
- /// be placed in increasing order of root parameter index.
- /// </summary>
- class IndirectParameter
- {
- friend class CommandSignature;
- protected:
- /// <summary>
- /// Direct3D 12 indirect argument description
- /// </summary>
- D3D12_INDIRECT_ARGUMENT_DESC mIndirectParam;
- public:
- /// <summary>
- /// Default constructor. Set type to invalid.
- /// </summary>
- IndirectParameter()
- {
- mIndirectParam.Type = (D3D12_INDIRECT_ARGUMENT_TYPE)0xFFFFFFFF;
- }
- /// <summary>
- /// Draw command indirect parameter
- /// </summary>
- void Draw()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW;
- }
- /// <summary>
- /// Draw indexed command indirect parameter
- /// </summary>
- void DrawIndexed()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DRAW_INDEXED;
- }
- /// <summary>
- /// Dispatch kernel command indirect parameter
- /// </summary>
- void Dispatch()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
- }
- /// <summary>
- /// Vertex buffer view indirect parameter
- /// </summary>
- void VertexBufferView()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_VERTEX_BUFFER_VIEW;
- mIndirectParam.VertexBuffer.Slot = 0;
- }
- /// <summary>
- /// Index buffer view indirect parameter
- /// </summary>
- void IndexBufferView()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_INDEX_BUFFER_VIEW;
- }
- /// <summary>
- /// Create constant indirect parameter type
- /// </summary>
- /// <param name="rootParameterIndex">Index of root parameter in root signature</param>
- /// <param name="destOffset">Offset in 32 bit values (in root parameter)</param>
- /// <param name="numValues">Number of 32 bit values set (in root parameter)</param>
- void Constant(unsigned int rootParameterIndex, unsigned int destOffset, unsigned int numValues)
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT;
- mIndirectParam.Constant.RootParameterIndex = rootParameterIndex;
- mIndirectParam.Constant.DestOffsetIn32BitValues = destOffset;
- mIndirectParam.Constant.Num32BitValuesToSet = numValues;
- }
- /// <summary>
- /// Constant buffer view indirect parameter
- /// </summary>
- /// <param name="rootParameterIndex">Root signature parameter index for given constant buffer view</param>
- void ConstantBufferView(unsigned int rootParameterIndex)
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_CONSTANT_BUFFER_VIEW;
- mIndirectParam.ConstantBufferView.RootParameterIndex = rootParameterIndex;
- }
- /// <summary>
- /// Shader resource view indirect parameter
- /// </summary>
- /// <param name="rootParameterIndex">Root signature parameter index for given shader resource view</param>
- void ShaderResourceView(unsigned int rootParameterIndex)
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_SHADER_RESOURCE_VIEW;
- mIndirectParam.ShaderResourceView.RootParameterIndex = rootParameterIndex;
- }
- /// <summary>
- /// Unordered access view indirect parameter
- /// </summary>
- /// <param name="rootParameterIndex">Root signature parameter index for given unordered access view</param>
- void UnorderedAccessView(unsigned int rootParameterIndex)
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_UNORDERED_ACCESS_VIEW;
- mIndirectParam.UnorderedAccessView.RootParameterIndex = rootParameterIndex;
- }
- /// <summary>
- /// Dispatch mesh command indirect parameter
- /// </summary>
- void DispatchMesh()
- {
- mIndirectParam.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH_MESH;
- }
- /// <summary>
- /// Get D3D12 indirect argument description for this indirect parameter
- /// </summary>
- /// <returns>Direct3D 12 indirect argument description</returns>
- const D3D12_INDIRECT_ARGUMENT_DESC& Get() const
- {
- return mIndirectParam;
- }
- };
- /// <summary>
- /// Command signature
- ///
- /// Defines the command signature for indirect rendering. Holds N indirect parameters defining
- /// what each record of indirect buffer contains.
- /// </summary>
- class CommandSignature
- {
- protected:
- /// <summary>
- /// Is the command signature finalized?
- /// </summary>
- bool mFinalized;
- /// <summary>
- /// Number of indirect parameters in the command signature
- /// </summary>
- unsigned int mNumParameters;
- /// <summary>
- /// Pointer to buffer of indirect parameters
- /// </summary>
- IndirectParameter* mParameters;
- /// <summary>
- /// Direct3D 12 command signature
- /// </summary>
- ID3D12CommandSignature* mSignature;
- public:
- /// <summary>
- /// Default constructor
- /// </summary>
- /// <param name="numParams">Number of indirect parameters in command signature</param>
- CommandSignature(unsigned int numParams = 0)
- {
- mFinalized = false;
- mNumParameters = numParams;
- Reset(mNumParameters);
- }
- /// <summary>
- /// Default destructor
- /// </summary>
- ~CommandSignature()
- {
- if (mSignature != nullptr)
- {
- mSignature->Release();
- mSignature = nullptr;
- }
- delete[] mParameters;
- mParameters = nullptr;
- }
- /// <summary>
- /// Reset the command signature
- /// </summary>
- /// <param name="numParams">New number of parameters in command signature</param>
- void Reset(unsigned int numParams)
- {
- if (mNumParameters > 0)
- {
- mParameters = new IndirectParameter[mNumParameters];
- }
- else
- {
- mParameters = nullptr;
- }
- mNumParameters = numParams;
- }
- /// <summary>
- /// Get indirect parameter by index
- /// </summary>
- /// <param name="index">Index of indirect parameter</param>
- /// <returns>Reference to indirect parameter at given index</returns>
- IndirectParameter& operator[] (size_t index)
- {
- return mParameters[index];
- }
- /// <summary>
- /// Get indirect parameter by index (read-only)
- /// </summary>
- /// <param name="index">Index of indirect parameter</param>
- /// <returns>Const reference to indirect parameter at given index</returns>
- const IndirectParameter& operator[] (size_t index) const
- {
- return mParameters[index];
- }
- /// <summary>
- /// Initialize Direct3D 12 command signature object
- /// </summary>
- /// <param name="device">Direct3D 12 device</param>
- /// <param name="stride">Record stride</param>
- /// <param name="rootSignature">Root signature for this command signature</param>
- void Init(ID3D12Device* device, size_t stride, RootSignature* rootSignature = nullptr);
- /// <summary>
- /// Initialize Direct3D 12 command signature object
- /// </summary>
- /// <param name="renderer">Direct3D 12 renderer</param>
- /// <param name="stride">Record stride</param>
- /// <param name="rootSignature">Root signature for this command signature</param>
- void Init(D3DRenderer* renderer, size_t stride, RootSignature* rootSignature = nullptr);
- /// <summary>
- /// Get Direct3D 12 command signature
- /// </summary>
- /// <returns>Direct3D 12 command signature</returns>
- ID3D12CommandSignature* Get()
- {
- return mSignature;
- }
- };
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // EOH
- #endif
Advertisement
Add Comment
Please, Sign In to add comment