git.s-ol.nu ~forks/DiligentCore / f496817
PipelineResourceSignatureD3D11Impl: reworked resource allocation assiduous 6 months ago
7 changed file(s) with 157 addition(s) and 136 deletion(s). Raw diff Collapse all Expand all
4848 D3D11_RESOURCE_RANGE_COUNT,
4949 D3D11_RESOURCE_RANGE_UNKNOWN = ~0u
5050 };
51 D3D11_RESOURCE_RANGE ShaderResourceToDescriptorRange(SHADER_RESOURCE_TYPE Type);
5251
5352
5453 /// Resource binding points in all shader stages.
5554 // sizeof(D3D11ResourceBindPoints) == 8, x64
5655 struct D3D11ResourceBindPoints
5756 {
58 /// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute)
57 /// The number of different shader types (Vertex, Pixel, Geometry, Hull, Domain, Compute)
5958 static constexpr Uint32 NumShaderTypes = 6;
6059
6160 D3D11ResourceBindPoints() noexcept
8079
8180 bool IsStageActive(Uint32 ShaderInd) const
8281 {
83 bool IsActive = (GetActiveStages() & (1u << ShaderInd)) != 0;
82 bool IsActive = (GetActiveStages() & GetShaderTypeFromIndex(ShaderInd)) != 0;
8483 VERIFY_EXPR((IsActive && Bindings[ShaderInd] != InvalidBindPoint ||
8584 !IsActive && Bindings[ShaderInd] == InvalidBindPoint));
8685 return IsActive;
8887
8988 Uint8 operator[](Uint32 ShaderInd) const
9089 {
90 VERIFY(IsStageActive(ShaderInd), "Requesting bind point for inactive shader stage");
9191 return Bindings[ShaderInd];
9292 }
9393
107107 D3D11ResourceBindPoints operator+(Uint32 value) const
108108 {
109109 D3D11ResourceBindPoints NewBindPoints{*this};
110 for (auto Stages = GetActiveStages(); Stages != 0;)
110 for (auto Stages = GetActiveStages(); Stages != SHADER_TYPE_UNKNOWN;)
111111 {
112112 auto ShaderInd = ExtractFirstShaderStageIndex(Stages);
113113 VERIFY_EXPR(Uint32{Bindings[ShaderInd]} + value < InvalidBindPoint);
127127
128128 // clang-format off
129129 StageAccessor (const StageAccessor&) = delete;
130 StageAccessor ( StageAccessor&&) = default;
130 StageAccessor ( StageAccessor&&) = delete;
131131 StageAccessor& operator=(const StageAccessor&) = delete;
132132 StageAccessor& operator=( StageAccessor&&) = delete;
133133 // clang-format on
150150 public:
151151 StageAccessor operator[](Uint32 ShaderInd)
152152 {
153 return StageAccessor{*this, ShaderInd};
153 return {*this, ShaderInd};
154154 }
155155
156156 private:
177177 /// Shader resource counters for one specific resource range
178178 struct D3D11ResourceRangeCounters
179179 {
180 static constexpr Uint32 NumShaderTypes = D3D11ResourceBindPoints::NumShaderTypes;
181
180182 Uint8 operator[](Uint32 Stage) const
181183 {
182 VERIFY_EXPR(Stage < D3D11ResourceBindPoints::NumShaderTypes);
184 VERIFY_EXPR(Stage < NumShaderTypes);
183185 return (PackedCounters >> (NumBitsPerStage * Stage)) & StageMask;
184186 }
185187
186188 D3D11ResourceRangeCounters& operator+=(const D3D11ResourceRangeCounters& rhs)
187189 {
188190 #ifdef DILIGENT_DEBUG
189 for (Uint32 s = 0; s < D3D11ResourceBindPoints::NumShaderTypes; ++s)
190 {
191 const Uint32 val0 = (*static_cast<const D3D11ResourceRangeCounters*>(this))[s];
191 for (Uint32 s = 0; s < NumShaderTypes; ++s)
192 {
193 const Uint32 val0 = static_cast<const D3D11ResourceRangeCounters&>(*this)[s];
192194 const Uint32 val1 = rhs[s];
193195 VERIFY(val0 + val1 <= MaxCounter, "The resulting value is out of range");
194196 }
213215
214216 // clang-format off
215217 StageAccessor (const StageAccessor&) = delete;
216 StageAccessor ( StageAccessor&&) = default;
218 StageAccessor ( StageAccessor&&) = delete;
217219 StageAccessor& operator=(const StageAccessor&) = delete;
218220 StageAccessor& operator=( StageAccessor&&) = delete;
219221 // clang-format on
242244 public:
243245 StageAccessor operator[](Uint32 ShaderInd)
244246 {
245 return StageAccessor{*this, ShaderInd};
246 }
247
247 return {*this, ShaderInd};
248 }
248249
249250 private:
250251 Uint8 Set(Uint32 ShaderInd, Uint32 Counter)
273274 struct PipelineResourceAttribsD3D11
274275 {
275276 private:
276 static constexpr Uint32 _SamplerIndBits = 10;
277 static constexpr Uint32 _SamplerIndBits = 31;
277278 static constexpr Uint32 _SamplerAssignedBits = 1;
278279
279280 public:
280281 static constexpr Uint32 InvalidSamplerInd = (1u << _SamplerIndBits) - 1;
281282
282283 // clang-format off
283 const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources.
284 const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag.
284 const Uint32 SamplerInd : _SamplerIndBits; // Index of the assigned sampler in m_Desc.Resources.
285 const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag.
286 // clang-format on
285287 D3D11ResourceBindPoints BindPoints;
286 // clang-format on
287288
288289 PipelineResourceAttribsD3D11(Uint32 _SamplerInd,
289290 bool _ImtblSamplerAssigned) noexcept :
7272 {
7373 public:
7474 RefCntAutoPtr<SamplerD3D11Impl> pSampler;
75 Uint32 ArraySize = 0;
75 Uint32 ArraySize = 1;
7676 D3D11ResourceBindPoints BindPoints;
7777
7878 ImmutableSamplerAttribs() noexcept {}
100100 void CopyStaticResources(ShaderResourceCacheD3D11& ResourceCache) const;
101101
102102 #ifdef DILIGENT_DEVELOPMENT
103 /// Verifies committed resource attribs using the SPIRV resource attributes from the PSO.
103 /// Verifies committed resource using the D3D resource attributes from the PSO.
104104 bool DvpValidateCommittedResource(const D3DShaderResourceAttribs& D3DAttribs,
105105 Uint32 ResIndex,
106106 const ShaderResourceCacheD3D11& ResourceCache,
2727 #include "pch.h"
2828
2929 #include "PipelineResourceSignatureD3D11Impl.hpp"
30
31 #include <algorithm>
32
3033 #include "RenderDeviceD3D11Impl.hpp"
3134 #include "ShaderVariableD3D.hpp"
3235
3336 namespace Diligent
3437 {
3538
36 D3D11_RESOURCE_RANGE ShaderResourceToDescriptorRange(SHADER_RESOURCE_TYPE Type)
39 namespace
40 {
41
42 D3D11_RESOURCE_RANGE ShaderResourceTypeToRange(SHADER_RESOURCE_TYPE Type)
3743 {
3844 static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
3945 switch (Type)
5460 }
5561
5662
63 void ValidatePipelineResourceSignatureDescD3D11(const PipelineResourceSignatureDesc& Desc) noexcept(false)
64 {
65 for (Uint32 i = 0; i < Desc.NumResources; ++i)
66 {
67 const auto& ResDesc = Desc.Resources[i];
68 const auto Range = ShaderResourceTypeToRange(ResDesc.ResourceType);
69
70 constexpr SHADER_TYPE UAVStages = SHADER_TYPE_PIXEL | SHADER_TYPE_COMPUTE;
71 if (Range == D3D11_RESOURCE_RANGE_UAV && (ResDesc.ShaderStages & ~UAVStages) != 0)
72 {
73 LOG_ERROR_AND_THROW("Description of a pipeline resource signature '", (Desc.Name ? Desc.Name : ""), "' is invalid: ",
74 "Desc.Resources[", i, "].ShaderStages (", GetShaderStagesString(ResDesc.ShaderStages),
75 ") is not valid in Direct3D11 as UAVs are not supported in shader stages ", GetShaderStagesString(ResDesc.ShaderStages & ~UAVStages));
76 }
77 }
78 }
79
80 } // namespace
81
5782 PipelineResourceSignatureD3D11Impl::PipelineResourceSignatureD3D11Impl(IReferenceCounters* pRefCounters,
5883 RenderDeviceD3D11Impl* pDeviceD3D11,
5984 const PipelineResourceSignatureDesc& Desc,
6287 {
6388 try
6489 {
90 ValidatePipelineResourceSignatureDescD3D11(Desc);
91
6592 auto& RawAllocator{GetRawAllocator()};
6693 auto MemPool = AllocateInternalObjects(RawAllocator, Desc,
6794 [&Desc](FixedLinearAllocator& MemPool) //
118145
119146 void PipelineResourceSignatureD3D11Impl::CreateLayout()
120147 {
121 const auto AllocBindPoints = [](D3D11ShaderResourceCounters& ResCounters, D3D11ResourceBindPoints& BindPoints, SHADER_TYPE ShaderStages, Uint32 ArraySize, D3D11_RESOURCE_RANGE Range) //
122 {
123 while (ShaderStages != 0)
124 {
125 auto Stage = ExtractLSB(ShaderStages);
126 auto ShaderInd = GetShaderTypeIndex(Stage);
127
148 const auto AllocBindPoints = [](D3D11ShaderResourceCounters& ResCounters,
149 D3D11ResourceBindPoints& BindPoints,
150 SHADER_TYPE ShaderStages,
151 Uint32 ArraySize,
152 D3D11_RESOURCE_RANGE Range) //
153 {
154 while (ShaderStages != SHADER_TYPE_UNKNOWN)
155 {
156 const auto ShaderInd = ExtractFirstShaderStageIndex(ShaderStages);
128157 BindPoints[ShaderInd] = ResCounters[Range][ShaderInd];
129158 ResCounters[Range][ShaderInd] += ArraySize;
130159 }
131160 };
132161
133 if (m_pStaticResCache)
134 {
135 D3D11ShaderResourceCounters StaticBindingsPerStage{};
136 const auto StaticResIdxRange = GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
137 for (Uint32 r = StaticResIdxRange.first; r < StaticResIdxRange.second; ++r)
138 {
139 const auto& ResDesc = m_Desc.Resources[r];
140 const auto Range = ShaderResourceToDescriptorRange(ResDesc.ResourceType);
141
142 D3D11ResourceBindPoints BindPoints;
143 AllocBindPoints(StaticBindingsPerStage, BindPoints, ResDesc.ShaderStages, ResDesc.ArraySize, Range);
144 }
145
146 m_pStaticResCache->Initialize(StaticBindingsPerStage, GetRawAllocator());
147 VERIFY_EXPR(m_pStaticResCache->IsInitialized());
148 }
149
150162 // Index of the assigned sampler, for every texture SRV in m_Desc.Resources, or InvalidSamplerInd.
151163 std::vector<Uint32> TextureSrvToAssignedSamplerInd(m_Desc.NumResources, ResourceAttribs::InvalidSamplerInd);
152 // Index of the immutable sampler for every sampler or texture in m_Desc.Resources, or InvalidImmutableSamplerIndex.
164 // Index of the immutable sampler for every sampler in m_Desc.Resources, or InvalidImmutableSamplerIndex.
153165 std::vector<Uint32> ResourceToImmutableSamplerInd(m_Desc.NumResources, InvalidImmutableSamplerIndex);
154166 for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
155167 {
156168 const auto& ResDesc = m_Desc.Resources[i];
157169
158 if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER ||
159 ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV)
160 {
161 const char* SamplerSuffix = ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER ? GetCombinedSamplerSuffix() : nullptr;
162 const auto SrcImmutableSamplerInd = Diligent::FindImmutableSampler(m_Desc.ImmutableSamplers, m_Desc.NumImmutableSamplers, ResDesc.ShaderStages, ResDesc.Name, SamplerSuffix);
170 if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER)
171 {
172 // We only need to search for immutable samplers for SHADER_RESOURCE_TYPE_SAMPLER.
173 // For SHADER_RESOURCE_TYPE_TEXTURE_SRV, we will look for the assigned sampler and check if it is immutable.
174
175 // If there is an immutable sampler that is not defined as resource, e.g.:
176 //
177 // PipelineResourceDesc Resources[] = {SHADER_TYPE_PIXEL, "g_Texture", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, ...}
178 // ImmutableSamplerDesc ImtblSams[] = {SHADER_TYPE_PIXEL, "g_Texture", ...}
179 //
180 // the sampler will not be assigned to the texture. It will be initialized directly in the SRB resource cache,
181 // will be added to bindings map by UpdateShaderResourceBindingMap and then properly mapped to the shader sampler register.
182
183 // Note that FindImmutableSampler() below will work properly both when combined texture samplers are used and when not.
184 const auto SrcImmutableSamplerInd = FindImmutableSampler(ResDesc.ShaderStages, ResDesc.Name);
163185 if (SrcImmutableSamplerInd != InvalidImmutableSamplerIndex)
164186 {
165187 ResourceToImmutableSamplerInd[i] = SrcImmutableSamplerInd;
166188 // Set the immutable sampler array size to match the resource array size
167189 auto& DstImtblSampAttribs = m_ImmutableSamplers[SrcImmutableSamplerInd];
168190 // One immutable sampler may be used by different arrays in different shader stages - use the maximum array size
169 const auto ImtblSampArraySize = std::max(DstImtblSampAttribs.ArraySize, ResDesc.ArraySize);
170 DstImtblSampAttribs.ArraySize = ImtblSampArraySize;
171 VERIFY(DstImtblSampAttribs.ArraySize == ImtblSampArraySize, "Immutable sampler array size exceeds maximum representable value");
172 }
173 }
174
175 if (ResourceToImmutableSamplerInd[i] == InvalidImmutableSamplerIndex &&
176 ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV)
191 DstImtblSampAttribs.ArraySize = std::max(DstImtblSampAttribs.ArraySize, ResDesc.ArraySize);
192 }
193 }
194
195 if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV)
177196 {
178197 TextureSrvToAssignedSamplerInd[i] = FindAssignedSampler(ResDesc, ResourceAttribs::InvalidSamplerInd);
179198 }
180199 }
181200
201 // Allocate registers for immutable samplers first
202 for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
203 {
204 const auto& ImtblSamp = GetImmutableSamplerDesc(i);
205 auto& ImtblSampAttribs = m_ImmutableSamplers[i];
206 AllocBindPoints(m_ResourceCounters, ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, D3D11_RESOURCE_RANGE_SAMPLER);
207 GetDevice()->CreateSampler(ImtblSamp.Desc, ImtblSampAttribs.pSampler.DblPtr<ISampler>());
208 }
209
210 D3D11ShaderResourceCounters StaticResCounters;
211
182212 for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
183213 {
184 const auto& ResDesc = m_Desc.Resources[i];
185 const auto Range = ShaderResourceToDescriptorRange(ResDesc.ResourceType);
214 const auto& ResDesc = GetResourceDesc(i);
186215 VERIFY(i == 0 || ResDesc.VarType >= m_Desc.Resources[i - 1].VarType, "Resources must be sorted by variable type");
216
217 const auto Range = ShaderResourceTypeToRange(ResDesc.ResourceType);
187218
188219 auto AssignedSamplerInd = TextureSrvToAssignedSamplerInd[i];
189220 auto SrcImmutableSamplerInd = ResourceToImmutableSamplerInd[i];
190221 if (AssignedSamplerInd != ResourceAttribs::InvalidSamplerInd)
191222 {
192223 VERIFY_EXPR(ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV);
224 VERIFY_EXPR(SrcImmutableSamplerInd == InvalidImmutableSamplerIndex);
193225 SrcImmutableSamplerInd = ResourceToImmutableSamplerInd[AssignedSamplerInd];
194226 }
195227
196 constexpr SHADER_TYPE UAVStages = SHADER_TYPE_PIXEL | SHADER_TYPE_COMPUTE;
197 if (Range == D3D11_RESOURCE_RANGE_UAV && (ResDesc.ShaderStages & ~UAVStages) != 0)
198 {
199 LOG_ERROR_AND_THROW("Description of a pipeline resource signature '", m_Desc.Name, "' is invalid: ",
200 "Desc.Resources[", i, "].ResourceType (", GetShaderResourceTypeLiteralName(ResDesc.ResourceType),
201 ") - UAV resource is not supported in shader stages ", GetShaderStagesString(ResDesc.ShaderStages & ~UAVStages));
202 }
203
204 // Allocate space for immutable sampler which is assigned to sampler or texture resource.
205 if (SrcImmutableSamplerInd != InvalidImmutableSamplerIndex)
206 {
207 const auto& ImtblSamp = GetImmutableSamplerDesc(SrcImmutableSamplerInd);
208 auto& ImtblSampAttribs = m_ImmutableSamplers[SrcImmutableSamplerInd];
209 VERIFY_EXPR(ResDesc.ArraySize <= ImtblSampAttribs.ArraySize);
210
211 if (!ImtblSampAttribs.IsAllocated())
212 {
213 AllocBindPoints(m_ResourceCounters, ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, D3D11_RESOURCE_RANGE_SAMPLER);
214 }
215 }
216
228 auto* const pAttrib = new (m_pResourceAttribs + i) ResourceAttribs //
229 {
230 AssignedSamplerInd,
231 SrcImmutableSamplerInd != InvalidImmutableSamplerIndex //
232 };
233
234 // Do not allocate resource slot for immutable samplers that are also defined as resource
217235 if (!(ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && SrcImmutableSamplerInd != InvalidImmutableSamplerIndex))
218236 {
219 auto* pAttrib = new (m_pResourceAttribs + i) ResourceAttribs //
220 {
221 AssignedSamplerInd,
222 SrcImmutableSamplerInd != InvalidImmutableSamplerIndex //
223 };
224237 AllocBindPoints(m_ResourceCounters, pAttrib->BindPoints, ResDesc.ShaderStages, ResDesc.ArraySize, Range);
238 if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
239 {
240 // Since resources in the static cache are indexed by the same bindings, we need to
241 // make sure that there is enough space in the cache.
242 const auto& SrcRangeCounters = m_ResourceCounters[Range];
243 auto& DstRangeCounters = StaticResCounters[Range];
244 for (auto ShaderStages = ResDesc.ShaderStages; ShaderStages != SHADER_TYPE_UNKNOWN;)
245 {
246 const auto ShaderInd = ExtractFirstShaderStageIndex(ShaderStages);
247 DstRangeCounters[ShaderInd] = std::max(Uint8{DstRangeCounters[ShaderInd]}, SrcRangeCounters[ShaderInd]);
248 }
249 }
225250 }
226251 else
227252 {
228253 VERIFY_EXPR(AssignedSamplerInd == ResourceAttribs::InvalidSamplerInd);
229
230 auto& ImtblSampAttribs = m_ImmutableSamplers[SrcImmutableSamplerInd];
231 auto* pAttrib = new (m_pResourceAttribs + i) ResourceAttribs //
232 {
233 ResourceAttribs::InvalidSamplerInd,
234 SrcImmutableSamplerInd != InvalidImmutableSamplerIndex //
235 };
236 pAttrib->BindPoints = ImtblSampAttribs.BindPoints;
254 pAttrib->BindPoints = m_ImmutableSamplers[SrcImmutableSamplerInd].BindPoints;
237255 VERIFY_EXPR(!pAttrib->BindPoints.IsEmpty());
238256 }
239257 }
240258
241 // Add bindings for immutable samplers that are not assigned to texture or separate sampler.
242 for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
243 {
244 const auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
245 const auto& ImtblSamp = GetImmutableSamplerDesc(i);
246 auto& ImtblSampAttribs = m_ImmutableSamplers[i];
247
248 if (IsUsingCombinedSamplers() && !ImtblSampAttribs.IsAllocated())
249 continue;
250
251 GetDevice()->CreateSampler(ImtblSamp.Desc, ImtblSampAttribs.pSampler.DblPtr<ISampler>());
252
253 // Add as separate sampler.
254 if (!ImtblSampAttribs.IsAllocated())
255 {
256 ImtblSampAttribs.ArraySize = 1;
257 AllocBindPoints(m_ResourceCounters, ImtblSampAttribs.BindPoints, ImtblSamp.ShaderStages, ImtblSampAttribs.ArraySize, Range);
258 }
259 if (m_pStaticResCache)
260 {
261 m_pStaticResCache->Initialize(StaticResCounters, GetRawAllocator());
262 VERIFY_EXPR(m_pStaticResCache->IsInitialized());
259263 }
260264 }
261265
299303 VERIFY_EXPR(ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC);
300304
301305 static_assert(D3D11_RESOURCE_RANGE_COUNT == 4, "Please update the switch below to handle the new descriptor range");
302 switch (ShaderResourceToDescriptorRange(ResDesc.ResourceType))
306 switch (ShaderResourceTypeToRange(ResDesc.ResourceType))
303307 {
304308 case D3D11_RESOURCE_RANGE_CBV:
305309 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
348352 for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
349353 {
350354 const auto& ImtblSampAttr = GetImmutableSamplerAttribs(i);
351
352 if (ImtblSampAttr.IsAllocated())
353 {
354 SamplerD3D11Impl* pSampler = ImtblSampAttr.pSampler.RawPtr<SamplerD3D11Impl>();
355 VERIFY_EXPR(ImtblSampAttr.pSampler != nullptr);
356 VERIFY_EXPR(ImtblSampAttr.ArraySize > 0);
357
358 for (Uint32 ArrInd = 0; ArrInd < ImtblSampAttr.ArraySize; ++ArrInd)
359 ResourceCache.SetSampler(ImtblSampAttr.BindPoints + ArrInd, pSampler);
360 }
355 VERIFY_EXPR(ImtblSampAttr.IsAllocated());
356 VERIFY_EXPR(ImtblSampAttr.pSampler != nullptr);
357 VERIFY_EXPR(ImtblSampAttr.ArraySize > 0);
358
359 SamplerD3D11Impl* pSampler = ImtblSampAttr.pSampler.RawPtr<SamplerD3D11Impl>();
360 for (Uint32 ArrInd = 0; ArrInd < ImtblSampAttr.ArraySize; ++ArrInd)
361 ResourceCache.SetSampler(ImtblSampAttr.BindPoints + ArrInd, pSampler);
361362 }
362363 }
363364
372373 {
373374 const auto& ResDesc = GetResourceDesc(r);
374375 const auto& ResAttr = GetResourceAttribs(r);
375 const auto Range = ShaderResourceToDescriptorRange(ResDesc.ResourceType);
376 const auto Range = ShaderResourceTypeToRange(ResDesc.ResourceType);
376377
377378 if ((ResDesc.ShaderStages & ShaderStage) != 0)
378379 {
379380 VERIFY_EXPR(ResAttr.BindPoints.IsStageActive(ShaderInd));
380381 ResourceBinding::BindInfo BindInfo //
381382 {
382 Uint32{BaseBindings[Range][ShaderInd]} + ResAttr.BindPoints[ShaderInd],
383 Uint32{BaseBindings[Range][ShaderInd]} + Uint32{ResAttr.BindPoints[ShaderInd]},
383384 0u, // register space is not supported
384385 ResDesc.ArraySize,
385386 ResDesc.ResourceType //
397398 const auto& SampAttr = GetImmutableSamplerAttribs(samp);
398399 const auto Range = D3D11_RESOURCE_RANGE_SAMPLER;
399400
400 if ((ImtblSam.ShaderStages & ShaderStage) != 0 && SampAttr.IsAllocated())
401 VERIFY_EXPR(SampAttr.IsAllocated());
402 if ((ImtblSam.ShaderStages & ShaderStage) != 0)
401403 {
402404 VERIFY_EXPR(SampAttr.BindPoints.IsStageActive(ShaderInd));
403405
407409
408410 ResourceBinding::BindInfo BindInfo //
409411 {
410 Uint32{BaseBindings[Range][ShaderInd]} + SampAttr.BindPoints[ShaderInd],
412 Uint32{BaseBindings[Range][ShaderInd]} + Uint32{SampAttr.BindPoints[ShaderInd]},
411413 0u, // register space is not supported
412414 SampAttr.ArraySize,
413415 SHADER_RESOURCE_TYPE_SAMPLER //
441443 VERIFY_EXPR(D3DAttribs.BindCount <= ResDesc.ArraySize);
442444
443445 bool BindingsOK = true;
444 switch (ShaderResourceToDescriptorRange(ResDesc.ResourceType))
446 switch (ShaderResourceTypeToRange(ResDesc.ResourceType))
445447 {
446448 case D3D11_RESOURCE_RANGE_CBV:
447449 for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
189189 {
190190 // Index of the assigned sampler, for every texture SRV in m_Desc.Resources, or InvalidSamplerInd.
191191 std::vector<Uint32> TextureSrvToAssignedSamplerInd(m_Desc.NumResources, ResourceAttribs::InvalidSamplerInd);
192 // Index of the immutable sampler for every sampler in m_Desc.Resources, or -1.
193 std::vector<Int32> ResourceToImmutableSamplerInd(m_Desc.NumResources, -1);
192 // Index of the immutable sampler for every sampler in m_Desc.Resources, or InvalidImmutableSamplerIndex.
193 std::vector<Uint32> ResourceToImmutableSamplerInd(m_Desc.NumResources, InvalidImmutableSamplerIndex);
194194 for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
195195 {
196196 const auto& ResDesc = m_Desc.Resources[i];
199199 {
200200 // We only need to search for immutable samplers for SHADER_RESOURCE_TYPE_SAMPLER.
201201 // For SHADER_RESOURCE_TYPE_TEXTURE_SRV, we will look for the assigned sampler and check if it is immutable.
202
203 // If there is an immutable sampler that is not defined as resource, e.g.:
204 //
205 // PipelineResourceDesc Resources[] = {SHADER_TYPE_PIXEL, "g_Texture", 1, SHADER_RESOURCE_TYPE_TEXTURE_SRV, ...}
206 // ImmutableSamplerDesc ImtblSams[] = {SHADER_TYPE_PIXEL, "g_Texture", ...}
207 //
208 // the sampler will not be assigned to the texture. It will be defined as static sampler when D3D12 PSO is created,
209 // will be added to bindings map by UpdateShaderResourceBindingMap and then properly mapped to the shader sampler register.
202210
203211 // Note that FindImmutableSampler() below will work properly both when combined texture samplers are used and when not:
204212 // - When combined texture samplers are used, sampler suffix will not be null,
252260 if (AssignedSamplerInd != ResourceAttribs::InvalidSamplerInd)
253261 {
254262 VERIFY_EXPR(ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV);
263 VERIFY_EXPR(SrcImmutableSamplerInd == InvalidImmutableSamplerIndex);
255264 SrcImmutableSamplerInd = ResourceToImmutableSamplerInd[AssignedSamplerInd];
256265 }
257266
266275
267276 auto d3d12RootParamType = static_cast<D3D12_ROOT_PARAMETER_TYPE>(D3D12_ROOT_PARAMETER_TYPE_UAV + 1);
268277 // Do not allocate resource slot for immutable samplers that are also defined as resource
269 if (!(ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && SrcImmutableSamplerInd >= 0))
278 if (!(ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER && SrcImmutableSamplerInd != InvalidImmutableSamplerIndex))
270279 {
271280 if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
272281 {
329338 }
330339 else
331340 {
341 VERIFY_EXPR(AssignedSamplerInd == ResourceAttribs::InvalidSamplerInd);
342 // Use register and space assigned to the immutable sampler
332343 const auto& ImtblSamAttribs = GetImmutableSamplerAttribs(SrcImmutableSamplerInd);
333344 VERIFY_EXPR(ImtblSamAttribs.IsValid());
334345 // Initialize space and register, which are required for register remapping
345356 SRBOffsetFromTableStart,
346357 SigRootIndex,
347358 SigOffsetFromTableStart,
348 SrcImmutableSamplerInd >= 0,
359 SrcImmutableSamplerInd != InvalidImmutableSamplerIndex,
349360 d3d12RootParamType //
350361 };
351362 }
9898 void InitSRBResourceCache(ShaderResourceCacheGL& ResourceCache);
9999
100100 #ifdef DILIGENT_DEVELOPMENT
101 /// Verifies committed resource attribs using the SPIRV resource attributes from the PSO.
101 /// Verifies committed resource using the resource attributes from the PSO.
102102 bool DvpValidateCommittedResource(const ShaderResourcesGL::GLResourceAttribs& GLAttribs,
103103 RESOURCE_DIMENSION ResourceDim,
104104 bool IsMultisample,
2626
2727 #include "pch.h"
2828 #include "PipelineResourceSignatureGLImpl.hpp"
29
30 #include <algorithm>
31
2932 #include "RenderDeviceGLImpl.hpp"
3033
3134 namespace Diligent
182185 CacheOffset += ResDesc.ArraySize;
183186
184187 if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC)
185 StaticResCounter[Range] += ResDesc.ArraySize;
188 {
189 // Since resources in the static cache are indexed by the same bindings, we need to
190 // make sure that there is enough space in the cache.
191 StaticResCounter[Range] = std::max(StaticResCounter[Range], CacheOffset);
192 }
186193 }
187194 }
188195
123123 VkDescriptorSet vkDynamicDescriptorSet) const;
124124
125125 #ifdef DILIGENT_DEVELOPMENT
126 /// Verifies committed resource attribs using the SPIRV resource attributes from the PSO.
126 /// Verifies committed resource using the SPIRV resource attributes from the PSO.
127127 bool DvpValidateCommittedResource(const SPIRVShaderResourceAttribs& SPIRVAttribs,
128128 Uint32 ResIndex,
129129 const ShaderResourceCacheVk& ResourceCache,