Diligent Engine API Reference
ShaderResourcesD3D11.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 
30 // ShaderResourcesD3D11 are created by ShaderD3D11Impl instances. They are then referenced by ShaderResourceLayoutD3D11 objects, which are in turn
31 // created by instances of ShaderResourceBindingsD3D11Impl (and ShaderD3D11Impl too)
32 //
33 // _________________
34 // | |
35 // | ShaderD3D11Impl |
36 // |_________________|
37 // |
38 // |shared_ptr
39 // ________V_____________ _____________________________________________________________________
40 // | | unique_ptr | | | | | | |
41 // | ShaderResourcesD3D11 |--------------->| CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers |
42 // |______________________| |________|___________|___________|___________|___________|____________|
43 // A A A A A A A
44 // | \ \ \ \ \ |
45 // |shared_ptr Ref Ref Ref Ref Ref |
46 // ________|__________________ ____\_________\__________\__________\___________\_______ |
47 // | | unique_ptr | | | | | | |
48 // | ShaderResourceLayoutD3D11 |--------------->| CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | |
49 // |___________________________| |________|___________|___________|___________|___________| |
50 // | Ref
51 // |______________________________________________|
52 //
53 //
54 // One ShaderResources instance can be referenced by multiple objects
55 //
56 //
57 // ____<m_pResourceLayouts>___ ________________________________
58 // | | | |
59 // ----| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl |
60 // | |___________________________| |________________________________|
61 // |
62 // |
63 // _________________ ______________________ | ____<m_pResourceLayouts>___ ________________________________
64 // | | shared_ptr | | shared_ptr| | | | |
65 // | ShaderD3D11Impl |--------------->| ShaderResourcesD3D11 |<---------------| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl |
66 // |_________________| |______________________| | |___________________________| |________________________________|
67 // | A |
68 // V | |
69 // ____<m_StaticResLayout>____ | | ____<m_pResourceLayouts>___ ________________________________
70 // | | shared_ptr | | | | | |
71 // | ShaderResourceLayoutD3D11 |------------------- ----| ShaderResourceLayoutD3D11 |<-----| ShaderResourceBindingD3D11Impl |
72 // |___________________________| |___________________________| |________________________________|
73 //
74 //
75 
76 
77 #include "ShaderResources.h"
78 
79 namespace Diligent
80 {
81 
83 class ShaderResourcesD3D11 : public ShaderResources
84 {
85 public:
86  // Loads shader resources from the compiled shader bytecode
87  ShaderResourcesD3D11(class RenderDeviceD3D11Impl *pDeviceD3D11Impl, ID3DBlob *pShaderBytecode, const ShaderDesc &ShdrDesc);
89 
90  __forceinline Int32 GetMaxCBBindPoint() const{return m_MaxCBBindPoint; }
91  __forceinline Int32 GetMaxSRVBindPoint() const{return m_MaxSRVBindPoint; }
92  __forceinline Int32 GetMaxSamplerBindPoint()const{return m_MaxSamplerBindPoint; }
93  __forceinline Int32 GetMaxUAVBindPoint() const{return m_MaxUAVBindPoint; }
94 
95 #ifdef VERIFY_SHADER_BINDINGS
96  void dbgVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[],
97  ID3D11ShaderResourceView* CommittedD3D11SRVs[],
98  ID3D11Resource* CommittedD3D11SRVResources[],
99  ID3D11SamplerState* CommittedD3D11Samplers[],
100  ID3D11UnorderedAccessView* CommittedD3D11UAVs[],
101  ID3D11Resource* CommittedD3D11UAVResources[],
102  class ShaderResourceCacheD3D11 &ResourceCache)const;
103 #endif
104 
105  const Char *GetShaderName()const{return m_ShaderName;}
106 
107  void InitStaticSamplers(class ShaderResourceCacheD3D11 &ResourceCache)const;
108 
109 private:
110  typedef Int8 MaxBindPointType;
111 
112  MaxBindPointType m_MaxCBBindPoint = -1; // Max == 13
113  MaxBindPointType m_MaxSRVBindPoint = -1; // Max == 127
114  MaxBindPointType m_MaxSamplerBindPoint = -1; // Max == 15
115  MaxBindPointType m_MaxUAVBindPoint = -1; // Max == 7
116  Uint8 m_NumStaticSamplers = 0; // Max == 16
117 
118  static constexpr UINT MaxAllowedBindPoint = std::numeric_limits<MaxBindPointType>::max();
119  static_assert(D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max CB slot" );
120  static_assert(D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max SRV slot");
121  static_assert(D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max Sampler slot");
122  static_assert(D3D11_PS_CS_UAV_REGISTER_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max UAV slot");
123 
124  // ShaderResourcesD3D11 is part of the ShaderD3D11Impl object, so we can simply
125  // reference shader name without the need to copy it
126  const Char* m_ShaderName;
127 
128  typedef std::pair<const D3DShaderResourceAttribs*, RefCntAutoPtr<ISampler> > StaticSamplerAttribs;
129  StaticSamplerAttribs& GetStaticSampler(Uint32 n)
130  {
131  VERIFY_EXPR(n < m_NumStaticSamplers);
132  return reinterpret_cast< StaticSamplerAttribs* >(m_StaticSamplers.get())[n];
133  }
134 
135  // We have to use void, because we will be calling destructors manually
136  std::unique_ptr< void, STDDeleterRawMem<void > > m_StaticSamplers;
137 };
138 
139 }
Shader description.
Definition: Shader.h:152
The class implements a cache that holds resources bound to a specific shader stage.
Definition: ShaderResourceCacheD3D11.h:46
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Diligent::ShaderResources class.
Definition: ShaderResourcesD3D11.h:83
Implementation of the Diligent::IRenderDeviceD3D11 interface.
Definition: RenderDeviceD3D11Impl.h:38