Diligent Engine API Reference
PipelineStateD3D11Impl.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 "PipelineStateD3D11.h"
30 #include "RenderDeviceD3D11.h"
31 #include "PipelineStateBase.h"
32 #include "ShaderD3D11Impl.h"
33 #include "AdaptiveFixedBlockAllocator.h"
34 
35 namespace Diligent
36 {
37 
38 class FixedBlockMemoryAllocator;
40 class PipelineStateD3D11Impl : public PipelineStateBase<IPipelineStateD3D11, IRenderDeviceD3D11>
41 {
42 public:
44 
45  PipelineStateD3D11Impl(IReferenceCounters *pRefCounters, class RenderDeviceD3D11Impl *pDeviceD3D11, const PipelineStateDesc& PipelineDesc);
47 
48  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override final;
49 
51  virtual ID3D11BlendState* GetD3D11BlendState()override final;
52 
54  virtual ID3D11RasterizerState* GetD3D11RasterizerState()override final;
55 
57  virtual ID3D11DepthStencilState* GetD3D11DepthStencilState()override final;
58 
59  virtual ID3D11InputLayout* GetD3D11InputLayout()override final;
60 
61  virtual ID3D11VertexShader* GetD3D11VertexShader()override final;
62  virtual ID3D11PixelShader* GetD3D11PixelShader()override final;
63  virtual ID3D11GeometryShader* GetD3D11GeometryShader()override final;
64  virtual ID3D11DomainShader* GetD3D11DomainShader()override final;
65  virtual ID3D11HullShader* GetD3D11HullShader()override final;
66  virtual ID3D11ComputeShader* GetD3D11ComputeShader()override final;
67 
68  virtual void BindShaderResources( IResourceMapping *pResourceMapping, Uint32 Flags )override final;
69 
70  virtual void CreateShaderResourceBinding( IShaderResourceBinding **ppShaderResourceBinding )override final;
71 
72  class ShaderResourceBindingD3D11Impl* GetDefaultResourceBinding(){return m_pDefaultShaderResBinding.get();}
73  IMemoryAllocator &GetResourceCacheDataAllocator(Uint32 ActiveShaderInd)
74  {
75  VERIFY_EXPR(ActiveShaderInd < m_NumShaders);
76  auto *pAllocator = m_Allocators.GetResourceCacheDataAllocator(ActiveShaderInd);
77  return pAllocator != nullptr ? *pAllocator : GetRawAllocator();
78  }
79  IMemoryAllocator &GetShaderResLayoutDataAllocators(Uint32 ActiveShaderInd)
80  {
81  VERIFY_EXPR(ActiveShaderInd < m_NumShaders);
82  auto *pAllocator = m_Allocators.GetShaderResLayoutDataAllocator(ActiveShaderInd);
83  return pAllocator != nullptr ? *pAllocator : GetRawAllocator();
84  }
85  IShaderVariable* GetDummyShaderVariable(){return &m_DummyShaderVar;}
86 
87 private:
88  CComPtr<ID3D11BlendState> m_pd3d11BlendState;
89  CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState;
90  CComPtr<ID3D11DepthStencilState> m_pd3d11DepthStencilState;
91  CComPtr<ID3D11InputLayout> m_pd3d11InputLayout;
92 
93  class DataAllocators
94  {
95  public:
96  ~DataAllocators();
97  void Init(size_t NumActiveShaders, Uint32 SRBAllocationGranularity);
98  AdaptiveFixedBlockAllocator* GetShaderResLayoutDataAllocator(Uint32 Ind)
99  {
100  VERIFY_EXPR(Ind < _countof(m_pShaderResLayoutDataAllocators));
101  return m_pShaderResLayoutDataAllocators[Ind];
102  }
103  AdaptiveFixedBlockAllocator* GetResourceCacheDataAllocator(Uint32 Ind)
104  {
105  VERIFY_EXPR(Ind < _countof(m_pResourceCacheDataAllocators));
106  return m_pResourceCacheDataAllocators[Ind];
107  }
108  private:
109  AdaptiveFixedBlockAllocator* m_pShaderResLayoutDataAllocators[5] = {}; // Use separate allocator for every shader stage
110  AdaptiveFixedBlockAllocator* m_pResourceCacheDataAllocators[5] = {}; // Use separate allocator for every shader stage
111  }m_Allocators; // Allocators must be defined before the default shader res binding
112 
113  // Do not use strong reference to avoid cyclic references
114  // Must be declared after the data allocators
115  std::unique_ptr<class ShaderResourceBindingD3D11Impl, STDDeleter<ShaderResourceBindingD3D11Impl, FixedBlockMemoryAllocator> > m_pDefaultShaderResBinding;
116 
117  DummyShaderVariable m_DummyShaderVar;
118 };
119 
120 }
Shader resource variable.
Definition: Shader.h:265
Template class implementing base functionality for a pipeline state object.
Definition: PipelineStateBase.h:46
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
virtual ID3D11BlendState * GetD3D11BlendState() override final
Implementation of the IPipelineStateD3D11::GetD3D11BlendState() method.
Definition: PipelineStateD3D11Impl.cpp:145
virtual ID3D11GeometryShader * GetD3D11GeometryShader() override final
Returns a pointer to the ID3D11GeometryShader interface of the internal geometry shader object...
Definition: PipelineStateD3D11Impl.cpp:204
virtual ID3D11InputLayout * GetD3D11InputLayout() override final
Returns a pointer to the ID3D11InputLayout interface of the internal Direct3D11 object.
Definition: PipelineStateD3D11Impl.cpp:160
IMemoryAllocator & GetRawAllocator()
Returns raw memory allocator.
Definition: EngineMemory.cpp:46
Resouce mapping.
Definition: ResourceMapping.h:80
Shader resource binding interface.
Definition: ShaderResourceBinding.h:40
virtual ID3D11DepthStencilState * GetD3D11DepthStencilState() override final
Implementation of the IPipelineStateD3D11::GetD3D11DepthStencilState() method.
Definition: PipelineStateD3D11Impl.cpp:155
Implementation of a dummy shader variable that silently ignores all operations.
Definition: ShaderBase.h:146
Implementation of the Diligent::IShaderResourceBindingD3D11 interface.
Definition: ShaderResourceBindingD3D11Impl.h:41
virtual ID3D11RasterizerState * GetD3D11RasterizerState() override final
Implementation of the IPipelineStateD3D11::GetD3D11RasterizerState() method.
Definition: PipelineStateD3D11Impl.cpp:150
Implementation of the Diligent::IPipelineStateD3D11 interface.
Definition: PipelineStateD3D11Impl.h:40
Uint32 m_NumShaders
Number of shaders that this PSO uses.
Definition: PipelineStateBase.h:191
virtual void CreateShaderResourceBinding(IShaderResourceBinding **ppShaderResourceBinding) override final
Creates a shader resource binding object.
Definition: PipelineStateD3D11Impl.cpp:181
Implementation of the Diligent::IRenderDeviceD3D11 interface.
Definition: RenderDeviceD3D11Impl.h:38
virtual ID3D11DomainShader * GetD3D11DomainShader() override final
Returns a pointer to the ID3D11DomainShader interface of the internal domain shader object...
Definition: PipelineStateD3D11Impl.cpp:211
virtual void BindShaderResources(IResourceMapping *pResourceMapping, Uint32 Flags) override final
Binds resources for all shaders in the pipeline state.
Definition: PipelineStateD3D11Impl.cpp:165
virtual ID3D11ComputeShader * GetD3D11ComputeShader() override final
Returns a pointer to the ID3D11ComputeShader interface of the internal compute shader object...
Definition: PipelineStateD3D11Impl.cpp:225
virtual ID3D11HullShader * GetD3D11HullShader() override final
Returns a pointer to the ID3D11HullShader interface of the internal hull shader object.
Definition: PipelineStateD3D11Impl.cpp:218
virtual ID3D11PixelShader * GetD3D11PixelShader() override final
Returns a pointer to the ID3D11PixelShader interface of the internal pixel shader object...
Definition: PipelineStateD3D11Impl.cpp:197
Pipeline state description.
Definition: PipelineState.h:179
virtual ID3D11VertexShader * GetD3D11VertexShader() override final
Returns a pointer to the ID3D11VertexShader interface of the internal vertex shader object...
Definition: PipelineStateD3D11Impl.cpp:190