git.s-ol.nu ~forks/DiligentCore / fff2114
ShaderVariableManagerD3D11: some code updates assiduous 6 months ago
3 changed file(s) with 56 addition(s) and 98 deletion(s). Raw diff Collapse all Expand all
8282 const ResourceAttribs& GetAttribs(Uint32 Index) const;
8383
8484
85 template <typename ThisImplType>
85 template <typename ThisImplType, D3D11_RESOURCE_RANGE ResRange>
8686 struct ShaderVariableD3D11Base : ShaderVariableBase<ThisImplType, ShaderVariableManagerD3D11, IShaderResourceVariableD3D>
8787 {
8888 public:
118118 GetResourceDesc(HLSLResDesc);
119119 HLSLResDesc.ShaderRegister = GetAttribs().BindPoints[m_ParentManager.m_ShaderTypeIndex];
120120 }
121 };
122
123 struct ConstBuffBindInfo final : ShaderVariableD3D11Base<ConstBuffBindInfo>
124 {
125 ConstBuffBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
126 ShaderVariableD3D11Base<ConstBuffBindInfo>{ParentLayout, ResIndex}
127 {}
128
129 // Non-virtual function
130 __forceinline void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex);
131121
132122 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
133123 {
134124 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
135 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_CBV>(GetAttribs().BindPoints + ArrayIndex);
125 return m_ParentManager.m_ResourceCache.IsResourceBound<ResRange>(GetAttribs().BindPoints + ArrayIndex);
136126 }
137127 };
138128
139 struct TexSRVBindInfo final : ShaderVariableD3D11Base<TexSRVBindInfo>
129 struct ConstBuffBindInfo final : ShaderVariableD3D11Base<ConstBuffBindInfo, D3D11_RESOURCE_RANGE_CBV>
130 {
131 ConstBuffBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
132 ShaderVariableD3D11Base<ConstBuffBindInfo, D3D11_RESOURCE_RANGE_CBV>{ParentLayout, ResIndex}
133 {}
134
135 __forceinline void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex);
136 };
137
138 struct TexSRVBindInfo final : ShaderVariableD3D11Base<TexSRVBindInfo, D3D11_RESOURCE_RANGE_SRV>
140139 {
141140 TexSRVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
142 ShaderVariableD3D11Base<TexSRVBindInfo>{ParentLayout, ResIndex}
143 {}
144
145 // Non-virtual function
146 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
147
148 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
149 {
150 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
151 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SRV>(GetAttribs().BindPoints + ArrayIndex);
152 }
153 };
154
155 struct TexUAVBindInfo final : ShaderVariableD3D11Base<TexUAVBindInfo>
141 ShaderVariableD3D11Base<TexSRVBindInfo, D3D11_RESOURCE_RANGE_SRV>{ParentLayout, ResIndex}
142 {}
143
144 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
145 };
146
147 struct TexUAVBindInfo final : ShaderVariableD3D11Base<TexUAVBindInfo, D3D11_RESOURCE_RANGE_UAV>
156148 {
157149 TexUAVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
158 ShaderVariableD3D11Base<TexUAVBindInfo>{ParentLayout, ResIndex}
159 {}
160
161 // Provide non-virtual function
162 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
163
164 __forceinline virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
165 {
166 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
167 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_UAV>(GetAttribs().BindPoints + ArrayIndex);
168 }
169 };
170
171 struct BuffUAVBindInfo final : ShaderVariableD3D11Base<BuffUAVBindInfo>
150 ShaderVariableD3D11Base<TexUAVBindInfo, D3D11_RESOURCE_RANGE_UAV>{ParentLayout, ResIndex}
151 {}
152
153 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
154 };
155
156 struct BuffUAVBindInfo final : ShaderVariableD3D11Base<BuffUAVBindInfo, D3D11_RESOURCE_RANGE_UAV>
172157 {
173158 BuffUAVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
174 ShaderVariableD3D11Base<BuffUAVBindInfo>{ParentLayout, ResIndex}
175 {}
176
177 // Non-virtual function
178 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
179
180 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
181 {
182 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
183 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_UAV>(GetAttribs().BindPoints + ArrayIndex);
184 }
185 };
186
187 struct BuffSRVBindInfo final : ShaderVariableD3D11Base<BuffSRVBindInfo>
159 ShaderVariableD3D11Base<BuffUAVBindInfo, D3D11_RESOURCE_RANGE_UAV>{ParentLayout, ResIndex}
160 {}
161
162 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
163 };
164
165 struct BuffSRVBindInfo final : ShaderVariableD3D11Base<BuffSRVBindInfo, D3D11_RESOURCE_RANGE_SRV>
188166 {
189167 BuffSRVBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
190 ShaderVariableD3D11Base<BuffSRVBindInfo>{ParentLayout, ResIndex}
191 {}
192
193 // Non-virtual function
194 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
195
196 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
197 {
198 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
199 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SRV>(GetAttribs().BindPoints + ArrayIndex);
200 }
201 };
202
203 struct SamplerBindInfo final : ShaderVariableD3D11Base<SamplerBindInfo>
168 ShaderVariableD3D11Base<BuffSRVBindInfo, D3D11_RESOURCE_RANGE_SRV>{ParentLayout, ResIndex}
169 {}
170
171 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
172 };
173
174 struct SamplerBindInfo final : ShaderVariableD3D11Base<SamplerBindInfo, D3D11_RESOURCE_RANGE_SAMPLER>
204175 {
205176 SamplerBindInfo(ShaderVariableManagerD3D11& ParentLayout, Uint32 ResIndex) :
206 ShaderVariableD3D11Base<SamplerBindInfo>{ParentLayout, ResIndex}
207 {}
208
209 // Non-virtual function
210 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
211
212 virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
213 {
214 VERIFY_EXPR(ArrayIndex < GetDesc().ArraySize);
215 return m_ParentManager.m_ResourceCache.IsResourceBound<D3D11_RESOURCE_RANGE_SAMPLER>(GetAttribs().BindPoints + ArrayIndex);
216 }
177 ShaderVariableD3D11Base<SamplerBindInfo, D3D11_RESOURCE_RANGE_SAMPLER>{ParentLayout, ResIndex}
178 {}
179
180 __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex);
217181 };
218182
219183 void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags);
250250 }
251251 }
252252
253 // Add bindings for immutable samplers that is not assigned to texture or separate sampler.
253 // Add bindings for immutable samplers that are not assigned to texture or separate sampler.
254254 for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
255255 {
256256 const auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
236236 {
237237 case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
238238 // Initialize current CB in place, increment CB counter
239 new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo(*this, Index);
239 new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo{*this, Index};
240240 break;
241241
242242 case SHADER_RESOURCE_TYPE_TEXTURE_SRV:
247247
248248 case SHADER_RESOURCE_TYPE_BUFFER_SRV:
249249 // Initialize buff SRV in place, increment counter of buff SRVs
250 new (&GetResource<BuffSRVBindInfo>(bufSrv++)) BuffSRVBindInfo(*this, Index);
250 new (&GetResource<BuffSRVBindInfo>(bufSrv++)) BuffSRVBindInfo{*this, Index};
251251 break;
252252
253253 case SHADER_RESOURCE_TYPE_TEXTURE_UAV:
254254 // Initialize tex UAV in place, increment counter of tex UAVs
255 new (&GetResource<TexUAVBindInfo>(texUav++)) TexUAVBindInfo(*this, Index);
255 new (&GetResource<TexUAVBindInfo>(texUav++)) TexUAVBindInfo{*this, Index};
256256 break;
257257
258258 case SHADER_RESOURCE_TYPE_BUFFER_UAV:
259259 // Initialize buff UAV in place, increment counter of buff UAVs
260 new (&GetResource<BuffUAVBindInfo>(bufUav++)) BuffUAVBindInfo(*this, Index);
260 new (&GetResource<BuffUAVBindInfo>(bufUav++)) BuffUAVBindInfo{*this, Index};
261261 break;
262262
263263 case SHADER_RESOURCE_TYPE_SAMPLER:
264264 // Initialize current sampler in place, increment sampler counter
265 new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo(*this, Index);
265 new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo{*this, Index};
266266 break;
267267
268268 default:
289289
290290 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER);
291291
292 // We cannot use ValidatedCast<> here as the resource retrieved from the
293 // resource mapping can be of wrong type
292 // We cannot use ValidatedCast<> here as the resource can be of wrong type
294293 RefCntAutoPtr<BufferD3D11Impl> pBuffD3D11Impl{pBuffer, IID_BufferD3D11};
295294 #ifdef DILIGENT_DEVELOPMENT
296295 {
313312 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV ||
314313 Desc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT);
315314
316 // We cannot use ValidatedCast<> here as the resource retrieved from the
317 // resource mapping can be of wrong type
315 // We cannot use ValidatedCast<> here as the resource can be of wrong type
318316 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
319317 #ifdef DILIGENT_DEVELOPMENT
320318 {
375373
376374 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER);
377375
378 // We cannot use ValidatedCast<> here as the resource retrieved from the
379 // resource mapping can be of wrong type
376 // We cannot use ValidatedCast<> here as the resource can be of wrong type
380377 RefCntAutoPtr<SamplerD3D11Impl> pSamplerD3D11{pSampler, IID_SamplerD3D11};
381378
382379 #ifdef DILIGENT_DEVELOPMENT
419416
420417 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_SRV);
421418
422 // We cannot use ValidatedCast<> here as the resource retrieved from the
423 // resource mapping can be of wrong type
419 // We cannot use ValidatedCast<> here as the resource can be of wrong type
424420 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
425421 #ifdef DILIGENT_DEVELOPMENT
426422 {
445441
446442 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV);
447443
448 // We cannot use ValidatedCast<> here as the resource retrieved from the
449 // resource mapping can be of wrong type
444 // We cannot use ValidatedCast<> here as the resource can be of wrong type
450445 RefCntAutoPtr<TextureViewD3D11Impl> pViewD3D11{pView, IID_TextureViewD3D11};
451446 #ifdef DILIGENT_DEVELOPMENT
452447 {
470465
471466 VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_UAV);
472467
473 // We cannot use ValidatedCast<> here as the resource retrieved from the
474 // resource mapping can be of wrong type
468 // We cannot use ValidatedCast<> here as the resource can be of wrong type
475469 RefCntAutoPtr<BufferViewD3D11Impl> pViewD3D11{pView, IID_BufferViewD3D11};
476470 #ifdef DILIGENT_DEVELOPMENT
477471 {