Diligent Engine API Reference: D:/GitHub/DiligentEngine/DiligentCore/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h Source File

Diligent Engine API Reference

PipelineStateD3D12Impl.h
1 /* Copyright 2015-2018 Egor Yusov
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12 *
13 * In no event and under no legal theory, whether in tort (including negligence),
14 * contract, or otherwise, unless required by applicable law (such as deliberate
15 * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16 * liable for any damages, including any direct, indirect, special, incidental,
17 * or consequential damages of any character arising as a result of this License or
18 * out of the use or inability to use the software (including but not limited to damages
19 * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20 * all other commercial damages or losses), even if such Contributor has been advised
21 * of the possibility of such damages.
22 */
23
24 #pragma once
25
28
29 #include "RenderDeviceD3D12.h"
30 #include "PipelineStateD3D12.h"
31 #include "PipelineStateBase.h"
32 #include "RootSignature.h"
33 #include "ShaderResourceLayoutD3D12.h"
34 #include "AdaptiveFixedBlockAllocator.h"
35
37 namespace Diligent
38 {
39
40 class FixedBlockMemoryAllocator;
42 class PipelineStateD3D12Impl : public PipelineStateBase<IPipelineStateD3D12, IRenderDeviceD3D12>
43 {
44 public:
45 typedef PipelineStateBase<IPipelineStateD3D12, IRenderDeviceD3D12> TPipelineStateBase;
46
47 PipelineStateD3D12Impl( IReferenceCounters *pRefCounters, class RenderDeviceD3D12Impl *pDeviceD3D12, const PipelineStateDesc &PipelineDesc );
48 ~PipelineStateD3D12Impl();
49
50 virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface );
51
52 virtual ID3D12PipelineState *GetD3D12PipelineState()const override final{return m_pd3d12PSO;}
53
54 virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags )override;
55
56 virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding )override;
57
58 virtual ID3D12RootSignature *GetD3D12RootSignature()const override final{return m_RootSig.GetD3D12RootSignature(); }
59
60 ShaderResourceCacheD3D12* CommitAndTransitionShaderResources(IShaderResourceBinding *pShaderResourceBinding,
61 class CommandContext &Ctx,
62 bool CommitResources,
63 bool TransitionResources)const;
64
65 const RootSignature& GetRootSignature()const{return m_RootSig;}
66
67 const ShaderResourceLayoutD3D12& GetShaderResLayout(SHADER_TYPE ShaderType)const;
68
69 bool dbgContainsShaderResources()const;
70
71 IMemoryAllocator &GetResourceCacheDataAllocator(){return m_ResourceCacheDataAllocator;}
72 IMemoryAllocator &GetShaderResourceLayoutDataAllocator(Uint32 ActiveShaderInd)
73 {
74 VERIFY_EXPR(ActiveShaderInd < m_NumShaders);
75 auto *pAllocator = m_ResLayoutDataAllocators.GetAllocator(ActiveShaderInd);
76 return pAllocator != nullptr ? *pAllocator : GetRawAllocator();
77 }
78
79 IShaderVariable *GetDummyShaderVar(){return &m_DummyVar;}
80
81 private:
82
83 void ParseShaderResourceLayout(IShader *pShader);
84
86 CComPtr<ID3D12PipelineState> m_pd3d12PSO;
87 RootSignature m_RootSig;
88 DummyShaderVariable m_DummyVar;
89
90 // Looks like there may be a bug in msvc: when allocators are declared as
91 // an array and if an exception is thrown from constructor, the app crashes
92 class ResLayoutDataAllocators
93 {
94 public:
95 ~ResLayoutDataAllocators()
96 {
97 for(size_t i=0; i < _countof(m_pAllocators); ++i)
98 if(m_pAllocators[i] != nullptr)
99 DESTROY_POOL_OBJECT(m_pAllocators[i]);
100 }
101 void Init(Uint32 NumActiveShaders, Uint32 SRBAllocationGranularity)
102 {
103 VERIFY_EXPR(NumActiveShaders <= _countof(m_pAllocators) );
104 for(Uint32 i=0; i < NumActiveShaders; ++i)
105 m_pAllocators[i] = NEW_POOL_OBJECT(AdaptiveFixedBlockAllocator, "Shader resource layout data allocator", GetRawAllocator(), SRBAllocationGranularity);
106 }
107 AdaptiveFixedBlockAllocator *GetAllocator(Uint32 ActiveShaderInd)
108 {
109 VERIFY_EXPR(ActiveShaderInd < _countof(m_pAllocators) );
110 return m_pAllocators[ActiveShaderInd];
111 }
112 private:
113 AdaptiveFixedBlockAllocator *m_pAllocators[5] = {};
114 }m_ResLayoutDataAllocators; // Allocators must be defined before default SRB
115
116 ShaderResourceLayoutD3D12* m_pShaderResourceLayouts[6] = {};
117 AdaptiveFixedBlockAllocator m_ResourceCacheDataAllocator; // Use separate allocator for every shader stage
118
119 // Do not use strong reference to avoid cyclic references
120 // Default SRB must be defined after allocators
121 std::unique_ptr<class ShaderResourceBindingD3D12Impl, STDDeleter<ShaderResourceBindingD3D12Impl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
122 };
123
124 }
Diligent::PipelineStateBase
Template class implementing base functionality for a pipeline state object.
Definition: PipelineStateBase.h:46
Diligent::PipelineStateD3D12Impl::CreateShaderResourceBinding
virtual void CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding) override
Creates a shader resource binding object.
Definition: PipelineStateD3D12Impl.cpp:260
Diligent::PipelineStateD3D12Impl::GetD3D12PipelineState
virtual ID3D12PipelineState * GetD3D12PipelineState() const override final
Returns ID3D12PipelineState interface of the internal D3D12 pipeline state object object...
Definition: PipelineStateD3D12Impl.h:52
Diligent::SHADER_TYPE
SHADER_TYPE
Describes the shader type.
Definition: Shader.h:46
Diligent::RootSignature
Implementation of the Diligent::RootSignature class.
Definition: RootSignature.h:161
Diligent::PipelineStateD3D12Impl::BindShaderResources
virtual void BindShaderResources(IResourceMapping *pResourceMapping, Uint32 Flags) override
Binds resources for all shaders in the pipeline state.
Definition: PipelineStateD3D12Impl.cpp:244
Diligent
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Diligent::GetRawAllocator
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:46
Diligent::IResourceMapping
Resouce mapping.
Definition: ResourceMapping.h:80
Diligent::IShaderResourceBinding
Shader resource binding interface.
Definition: ShaderResourceBinding.h:40
Diligent::PipelineStateD3D12Impl
Implementation of the Diligent::IRenderDeviceD3D12 interface.
Definition: PipelineStateD3D12Impl.h:42
Diligent::PipelineStateBase< IPipelineStateD3D12, IRenderDeviceD3D12 >::m_NumShaders
Uint32 m_NumShaders
Number of shaders that this PSO uses.
Definition: PipelineStateBase.h:191
Diligent::PipelineStateD3D12Impl::GetD3D12RootSignature
virtual ID3D12RootSignature * GetD3D12RootSignature() const override final
Returns a pointer to the root signature object associated with this pipeline state.
Definition: PipelineStateD3D12Impl.h:58
Diligent::PipelineStateDesc
Pipeline state description.
Definition: PipelineState.h:179
Diligent::RenderDeviceD3D12Impl
Implementation of the Diligent::IRenderDeviceD3D12 interface.
Definition: RenderDeviceD3D12Impl.h:43