Diligent Engine API Reference
ShaderResourceBindingD3D12Impl.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 "ShaderResourceBindingD3D12.h"
30 #include "RenderDeviceD3D12.h"
31 #include "ShaderResourceBindingBase.h"
32 #include "ShaderBase.h"
33 #include "ShaderResourceCacheD3D12.h"
34 #include "ShaderResourceLayoutD3D12.h"
35 
36 namespace Diligent
37 {
38 
39 class FixedBlockMemoryAllocator;
41 class ShaderResourceBindingD3D12Impl : public ShaderResourceBindingBase<IShaderResourceBindingD3D12>
42 {
43 public:
45  ShaderResourceBindingD3D12Impl(IReferenceCounters *pRefCounters, class PipelineStateD3D12Impl *pPSO, bool IsPSOInternal);
47 
48  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
49 
50  virtual void BindResources(Uint32 ShaderFlags, IResourceMapping *pResMapping, Uint32 Flags)override;
51 
52  virtual IShaderVariable *GetVariable(SHADER_TYPE ShaderType, const char *Name)override;
53 
54  ShaderResourceLayoutD3D12& GetResourceLayout(SHADER_TYPE ResType)
55  {
56  auto ShaderInd = GetShaderTypeIndex(ResType);
57  auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
58  VERIFY(ResLayoutInd >= 0, "Shader resource layout is not initialized");
59  VERIFY_EXPR(ResLayoutInd < (Int32)m_NumShaders);
60  return m_pResourceLayouts[ResLayoutInd];
61  }
62  ShaderResourceCacheD3D12& GetResourceCache(){return m_ShaderResourceCache;}
63 
64 #ifdef VERIFY_SHADER_BINDINGS
65  void dbgVerifyResourceBindings(const PipelineStateD3D12Impl *pPSO);
66 #endif
67 
68  bool StaticResourcesInitialized()const{return m_bStaticResourcesInitialized;}
69  void InitializeStaticResources(const PipelineStateD3D12Impl *pPSO);
70 
71 private:
72 
73  ShaderResourceCacheD3D12 m_ShaderResourceCache;
74  ShaderResourceLayoutD3D12* m_pResourceLayouts = nullptr;
75  // Resource layout index in m_ResourceLayouts[] array for every shader stage
76  Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1};
77  bool m_bStaticResourcesInitialized = false;
78  Uint32 m_NumShaders = 0;
79 };
80 
81 }
virtual void BindResources(Uint32 ShaderFlags, IResourceMapping *pResMapping, Uint32 Flags) override
Binds all resource using the resource mapping.
Definition: ShaderResourceBindingD3D12Impl.cpp:73
Implementation of the Diligent::IShaderResourceBindingD3D12 interface.
Definition: ShaderResourceBindingD3D12Impl.h:41
Shader resource variable.
Definition: Shader.h:265
SHADER_TYPE
Describes the shader type.
Definition: Shader.h:46
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Resouce mapping.
Definition: ResourceMapping.h:80
Implementation of the Diligent::IRenderDeviceD3D12 interface.
Definition: PipelineStateD3D12Impl.h:42
Template class implementing base functionality for a shader resource binding.
Definition: ShaderResourceBindingBase.h:42
virtual IShaderVariable * GetVariable(SHADER_TYPE ShaderType, const char *Name) override
Returns variable.
Definition: ShaderResourceBindingD3D12Impl.cpp:88
Diligent::ShaderResourceLayoutD3D12 class.
Definition: ShaderResourceLayoutD3D12.h:125