forked from DiligentGraphics/DiligentCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipelineStateWebGPUImpl.cpp
More file actions
966 lines (817 loc) · 45.9 KB
/
PipelineStateWebGPUImpl.cpp
File metadata and controls
966 lines (817 loc) · 45.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
/*
* Copyright 2024-2026 Diligent Graphics LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* In no event and under no legal theory, whether in tort (including negligence),
* contract, or otherwise, unless required by applicable law (such as deliberate
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
* liable for any damages, including any direct, indirect, special, incidental,
* or consequential damages of any character arising as a result of this License or
* out of the use or inability to use the software (including but not limited to damages
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
* all other commercial damages or losses), even if such Contributor has been advised
* of the possibility of such damages.
*/
#include "pch.h"
#include "PipelineStateWebGPUImpl.hpp"
#include "RenderDeviceWebGPUImpl.hpp"
#include "ShaderWebGPUImpl.hpp"
#include "RenderPassWebGPUImpl.hpp"
#include "WebGPUTypeConversions.hpp"
#include "WGSLUtils.hpp"
#include "Float16.hpp"
namespace Diligent
{
namespace
{
double ConvertSpecConstantToDouble(const void* pData, Uint32 DataSize, SHADER_CODE_BASIC_TYPE Type)
{
switch (Type)
{
case SHADER_CODE_BASIC_TYPE_BOOL:
{
// WGSL bool override: any non-zero value is true.
Uint32 Val = 0;
memcpy(&Val, pData, std::min(DataSize, Uint32{4}));
return Val != 0 ? 1.0 : 0.0;
}
case SHADER_CODE_BASIC_TYPE_INT:
{
Int32 Val = 0;
memcpy(&Val, pData, std::min(DataSize, Uint32{4}));
return static_cast<double>(Val);
}
case SHADER_CODE_BASIC_TYPE_UINT:
{
Uint32 Val = 0;
memcpy(&Val, pData, std::min(DataSize, Uint32{4}));
return static_cast<double>(Val);
}
case SHADER_CODE_BASIC_TYPE_FLOAT:
{
float Val = 0;
memcpy(&Val, pData, std::min(DataSize, Uint32{4}));
return static_cast<double>(Val);
}
case SHADER_CODE_BASIC_TYPE_FLOAT16:
{
Uint16 HalfBits = 0;
memcpy(&HalfBits, pData, std::min(DataSize, Uint32{2}));
return Float16::HalfBitsToFloat(HalfBits);
}
default:
UNEXPECTED("Unexpected specialization constant type ", GetShaderCodeBasicTypeString(Type));
return 0;
}
}
void BuildSpecializationDataWebGPU(PipelineStateWebGPUImpl::TShaderStages& ShaderStages,
Uint32 NumSpecializationConstants,
const SpecializationConstant* pSpecializationConstants,
const PipelineStateDesc& PSODesc)
{
if (NumSpecializationConstants == 0)
return;
for (size_t StageIdx = 0; StageIdx < ShaderStages.size(); ++StageIdx)
{
PipelineStateWebGPUImpl::ShaderStageInfo& Stage = ShaderStages[StageIdx];
const ShaderWebGPUImpl* pShader = Stage.pShader;
const std::shared_ptr<const WGSLShaderResources>& pShaderResources = pShader->GetShaderResources();
if (!pShaderResources)
continue;
for (Uint32 r = 0; r < pShaderResources->GetNumSpecConstants(); ++r)
{
const WGSLSpecializationConstantAttribs& ReflectedSC = pShaderResources->GetSpecConstant(r);
// Search for a matching user-provided constant by name and stage flag.
const SpecializationConstant* pUserConst = nullptr;
for (Uint32 sc = 0; sc < NumSpecializationConstants; ++sc)
{
const SpecializationConstant& Candidate = pSpecializationConstants[sc];
if ((Candidate.ShaderStages & Stage.Type) != 0 &&
strcmp(Candidate.Name, ReflectedSC.Name) == 0)
{
pUserConst = &Candidate;
break;
}
}
// No user constant for this reflected entry -- skip silently.
if (pUserConst == nullptr)
continue;
const SHADER_CODE_BASIC_TYPE ReflectedType = ReflectedSC.GetType();
const Uint32 ReflectedSize = GetShaderCodeBasicTypeBitSize(ReflectedType) / 8;
if (pUserConst->Size < ReflectedSize)
{
LOG_ERROR_AND_THROW("Description of ", GetPipelineTypeString(PSODesc.PipelineType),
" PSO '", (PSODesc.Name != nullptr ? PSODesc.Name : ""),
"' is invalid: specialization constant '", pUserConst->Name,
"' in ", GetShaderTypeLiteralName(Stage.Type),
" shader '", pShader->GetDesc().Name,
"' has insufficient data: user provided ", pUserConst->Size,
" bytes, but the shader declares ",
GetShaderCodeBasicTypeString(ReflectedType),
" (", ReflectedSize, " bytes).");
}
WGPUConstantEntry Entry{};
Entry.key = GetWGPUStringView(ReflectedSC.Name);
Entry.value = ConvertSpecConstantToDouble(pUserConst->pData, pUserConst->Size, ReflectedType);
Stage.SpecConstEntries.push_back(Entry);
}
}
}
} // anonymous namespace
constexpr INTERFACE_ID PipelineStateWebGPUImpl::IID_InternalImpl;
PipelineStateWebGPUImpl::PipelineStateWebGPUImpl(IReferenceCounters* pRefCounters,
RenderDeviceWebGPUImpl* pDevice,
const GraphicsPipelineStateCreateInfo& CreateInfo) :
TPipelineStateBase{pRefCounters, pDevice, CreateInfo}
{
Construct<ShaderWebGPUImpl>(CreateInfo);
}
PipelineStateWebGPUImpl::PipelineStateWebGPUImpl(IReferenceCounters* pRefCounters,
RenderDeviceWebGPUImpl* pDevice,
const ComputePipelineStateCreateInfo& CreateInfo) :
TPipelineStateBase{pRefCounters, pDevice, CreateInfo}
{
Construct<ShaderWebGPUImpl>(CreateInfo);
}
PipelineStateWebGPUImpl::~PipelineStateWebGPUImpl()
{
// Wait for asynchronous tasks to complete
TPipelineStateBase::GetStatus(/*WaitForCompletion =*/true);
// Note: we do not need to wait for the async callback to complete as
// it keeps a reference to the async pipeline builder object and
// can be called even if the pipeline is destroyed.
Destruct();
};
WGPURenderPipeline PipelineStateWebGPUImpl::GetWebGPURenderPipeline() const
{
return m_wgpuRenderPipeline.Get();
}
WGPUComputePipeline PipelineStateWebGPUImpl::GetWebGPUComputePipeline() const
{
return m_wgpuComputePipeline.Get();
}
void PipelineStateWebGPUImpl::Destruct()
{
TPipelineStateBase::Destruct();
}
template <typename PSOCreateInfoType>
std::vector<PipelineStateWebGPUImpl::ShaderStageInfo> PipelineStateWebGPUImpl::InitInternalObjects(const PSOCreateInfoType& CreateInfo)
{
std::vector<ShaderStageInfo> ShaderStages;
ExtractShaders<ShaderWebGPUImpl>(CreateInfo, ShaderStages, /*WaitUntilShadersReady = */ true);
VERIFY(!ShaderStages.empty(),
"There must be at least one shader stage in the pipeline. "
"This error should've been caught by PSO create info validation.");
// Memory must be released if an exception is thrown.
FixedLinearAllocator MemPool{GetRawAllocator()};
ReserveSpaceForPipelineDesc(CreateInfo, MemPool);
MemPool.Reserve();
InitializePipelineDesc(CreateInfo, MemPool);
InitPipelineLayout(CreateInfo, ShaderStages);
return ShaderStages;
}
void PipelineStateWebGPUImpl::RemapOrVerifyShaderResources(
TShaderStages& ShaderStages,
const RefCntAutoPtr<PipelineResourceSignatureWebGPUImpl> pSignatures[],
const Uint32 SignatureCount,
const TBindIndexToBindGroupIndex& BindIndexToBindGroupIndex,
bool bVerifyOnly,
const char* PipelineName,
TShaderResources* pDvpShaderResources,
TResourceAttibutions* pDvpResourceAttibutions) noexcept(false)
{
if (PipelineName == nullptr)
PipelineName = "<null>";
// Verify that pipeline layout is compatible with shader resources and
// remap resource bindings.
for (ShaderStageInfo& ShaderStage : ShaderStages)
{
const ShaderWebGPUImpl* pShader = ShaderStage.pShader;
std::string& PatchedWGSL = ShaderStage.PatchedWGSL;
const SHADER_TYPE ShaderType = ShaderStage.Type;
const auto& pShaderResources = pShader->GetShaderResources();
VERIFY_EXPR(pShaderResources);
if (pDvpShaderResources)
pDvpShaderResources->emplace_back(pShaderResources);
WGSLResourceMapping ResMapping;
pShaderResources->ProcessResources(
[&](const WGSLShaderResourceAttribs& WGSLAttribs, Uint32) //
{
const ResourceAttribution ResAttribution = GetResourceAttribution(WGSLAttribs.Name, ShaderType, pSignatures, SignatureCount);
if (!ResAttribution)
{
LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource '", WGSLAttribs.Name,
"' that is not present in any pipeline resource signature used to create pipeline state '",
PipelineName, "'.");
}
const PipelineResourceSignatureDesc& SignDesc = ResAttribution.pSignature->GetDesc();
const SHADER_RESOURCE_TYPE ResType = WGSLShaderResourceAttribs::GetShaderResourceType(WGSLAttribs.Type);
const PIPELINE_RESOURCE_FLAGS Flags = WGSLShaderResourceAttribs::GetPipelineResourceFlags(WGSLAttribs.Type);
Uint32 ResourceBinding = ~0u;
Uint32 BindGroup = ~0u;
Uint32 ArraySize = 1;
if (ResAttribution.ResourceIndex != ResourceAttribution::InvalidResourceIndex)
{
PipelineResourceDesc ResDesc = ResAttribution.pSignature->GetResourceDesc(ResAttribution.ResourceIndex);
if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT)
ResDesc.ResourceType = SHADER_RESOURCE_TYPE_TEXTURE_SRV;
ValidatePipelineResourceCompatibility(ResDesc, ResType, Flags, WGSLAttribs.ArraySize,
pShader->GetDesc().Name, SignDesc.Name);
const PipelineResourceAttribsWebGPU& ResAttribs{ResAttribution.pSignature->GetResourceAttribs(ResAttribution.ResourceIndex)};
ResourceBinding = ResAttribs.BindingIndex;
BindGroup = ResAttribs.BindGroup;
ArraySize = ResAttribs.ArraySize;
}
else if (ResAttribution.ImmutableSamplerIndex != ResourceAttribution::InvalidResourceIndex)
{
if (ResType != SHADER_RESOURCE_TYPE_SAMPLER)
{
LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource with name '", WGSLAttribs.Name,
"' and type '", GetShaderResourceTypeLiteralName(ResType),
"' that is not compatible with immutable sampler defined in pipeline resource signature '",
SignDesc.Name, "'.");
}
const ImmutableSamplerAttribsWebGPU& ImmtblSamAttribs{
ResAttribution.pSignature->GetImmutableSamplerAttribs(ResAttribution.ImmutableSamplerIndex)};
// Handle immutable samplers that do not have corresponding resources in m_Desc.Resources
BindGroup = ImmtblSamAttribs.BindGroup;
ResourceBinding = ImmtblSamAttribs.BindingIndex;
ArraySize = ImmtblSamAttribs.ArraySize;
}
else
{
UNEXPECTED("Either immutable sampler or resource index should be valid");
}
VERIFY_EXPR(ResourceBinding != ~0u && BindGroup != ~0u);
BindGroup += BindIndexToBindGroupIndex[SignDesc.BindingIndex];
if (bVerifyOnly)
{
if (WGSLAttribs.BindIndex != ResourceBinding)
{
LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' maps resource '", WGSLAttribs.Name,
"' to binding ", WGSLAttribs.BindIndex, ", but the same resource in pipeline resource signature '",
SignDesc.Name, "' is mapped to binding ", ResourceBinding, '.');
}
if (WGSLAttribs.BindGroup != BindGroup)
{
LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' maps resource '", WGSLAttribs.Name,
"' to bind group ", WGSLAttribs.BindGroup, ", but the same resource in pipeline resource signature '",
SignDesc.Name, "' is mapped to set ", BindGroup, '.');
}
}
else
{
ResMapping[WGSLAttribs.Name] = {BindGroup, ResourceBinding, ArraySize};
}
if (pDvpResourceAttibutions)
pDvpResourceAttibutions->emplace_back(ResAttribution);
});
if (!bVerifyOnly)
{
PatchedWGSL = RemapWGSLResourceBindings(pShader->GetWGSL(), ResMapping, pShader->GetEmulatedArrayIndexSuffix());
}
}
}
void PipelineStateWebGPUImpl::InitPipelineLayout(const PipelineStateCreateInfo& CreateInfo, TShaderStages& ShaderStages)
{
const PSO_CREATE_INTERNAL_FLAGS InternalFlags = GetInternalCreateFlags(CreateInfo);
if (m_UsingImplicitSignature && (InternalFlags & PSO_CREATE_INTERNAL_FLAG_IMPLICIT_SIGNATURE0) == 0)
{
const PipelineResourceSignatureDescWrapper SignDesc = GetDefaultResourceSignatureDesc(ShaderStages, m_Desc.Name, m_Desc.ResourceLayout, m_Desc.SRBAllocationGranularity);
InitDefaultSignature(SignDesc, GetActiveShaderStages(), false /*bIsDeviceInternal*/);
VERIFY_EXPR(m_Signatures[0]);
}
m_PipelineLayout.Create(GetDevice(), m_Signatures, m_SignatureCount);
const bool RemapResources = (CreateInfo.Flags & PSO_CREATE_FLAG_DONT_REMAP_SHADER_RESOURCES) == 0;
const bool VerifyBindings = !RemapResources && ((InternalFlags & PSO_CREATE_INTERNAL_FLAG_NO_SHADER_REFLECTION) == 0);
if (RemapResources || VerifyBindings)
{
VERIFY_EXPR(RemapResources ^ VerifyBindings);
TBindIndexToBindGroupIndex BindIndexToBindGroupIndex = {};
for (Uint32 i = 0; i < m_SignatureCount; ++i)
BindIndexToBindGroupIndex[i] = m_PipelineLayout.GetFirstBindGroupIndex(i);
// Note that we always need to strip reflection information when it is present
RemapOrVerifyShaderResources(ShaderStages,
m_Signatures,
m_SignatureCount,
BindIndexToBindGroupIndex,
VerifyBindings, // VerifyOnly
m_Desc.Name,
#ifdef DILIGENT_DEVELOPMENT
&m_ShaderResources, &m_ResourceAttibutions
#else
nullptr, nullptr
#endif
);
}
}
struct PipelineStateWebGPUImpl::AsyncPipelineBuilder : public ObjectBase<IObject>
{
TShaderStages ShaderStages;
// Shaders must be kept alive until the pipeline is created
std::vector<RefCntAutoPtr<IShader>> ShaderRefs;
WebGPURenderPipelineWrapper wgpuRenderPipeline;
WebGPUComputePipelineWrapper wgpuComputePipeline;
enum CallbackStatus : int
{
NotStarted,
InProgress,
Completed
};
std::atomic<CallbackStatus> Status{CallbackStatus::NotStarted};
AsyncPipelineBuilder(IReferenceCounters* pRefCounters,
TShaderStages&& _ShaderStages) :
ObjectBase<IObject>{pRefCounters},
ShaderStages{std::move(_ShaderStages)}
{
ShaderRefs.reserve(ShaderStages.size());
for (const ShaderStageInfo& ShaderStage : ShaderStages)
{
ShaderRefs.emplace_back(ShaderStage.pShader);
}
}
void InitializePipelines(WGPUCreatePipelineAsyncStatus PipelineStatus,
WGPURenderPipeline RenderPipeline,
WGPUComputePipeline ComputePipeline,
WGPUStringView Message)
{
VERIFY_EXPR(Status.load() == CallbackStatus::InProgress);
if (PipelineStatus == WGPUCreatePipelineAsyncStatus_Success)
{
wgpuRenderPipeline.Reset(RenderPipeline);
wgpuComputePipeline.Reset(ComputePipeline);
}
else
{
LOG_ERROR_MESSAGE("Failed to create WebGPU render pipeline: ", WGPUStringViewToString(Message));
}
Status.store(CallbackStatus::Completed);
Release();
}
static void CreateRenderPipelineCallback(WGPUCreatePipelineAsyncStatus Status,
WGPURenderPipeline Pipeline,
WGPUStringView Message,
void* pUserData)
{
static_cast<AsyncPipelineBuilder*>(pUserData)->InitializePipelines(Status, Pipeline, nullptr, Message);
}
static void CreateRenderPipelineCallback2(WGPUCreatePipelineAsyncStatus Status,
WGPURenderPipeline Pipeline,
WGPUStringView Message,
void* pUserData1,
void* pUserData2)
{
CreateRenderPipelineCallback(Status, Pipeline, Message, pUserData1);
}
static void CreateComputePipelineCallback(WGPUCreatePipelineAsyncStatus Status,
WGPUComputePipeline Pipeline,
WGPUStringView Message,
void* pUserData)
{
static_cast<AsyncPipelineBuilder*>(pUserData)->InitializePipelines(Status, nullptr, Pipeline, Message);
}
static void CreateComputePipelineCallback2(WGPUCreatePipelineAsyncStatus Status,
WGPUComputePipeline Pipeline,
WGPUStringView Message,
void* pUserData1,
void* pUserData2)
{
CreateComputePipelineCallback(Status, Pipeline, Message, pUserData1);
}
};
void PipelineStateWebGPUImpl::InitializePipeline(const GraphicsPipelineStateCreateInfo& CreateInfo)
{
TShaderStages ShaderStages = InitInternalObjects(CreateInfo);
// Build specialization constant entries while CreateInfo is still valid.
// The entries are stored per-stage in ShaderStageInfo::SpecConstEntries,
// which are moved into AsyncPipelineBuilder for async creation.
BuildSpecializationDataWebGPU(ShaderStages,
CreateInfo.NumSpecializationConstants,
CreateInfo.pSpecializationConstants,
m_Desc);
// NB: it is not safe to check m_AsyncInitializer here as, first, it is set after the async task is started,
// and second, it is not atomic or protected by mutex.
if ((CreateInfo.Flags & PSO_CREATE_FLAG_ASYNCHRONOUS) == 0)
{
InitializeWebGPURenderPipeline(ShaderStages);
}
else
{
m_AsyncBuilder = MakeNewRCObj<AsyncPipelineBuilder>()(std::move(ShaderStages));
}
}
void PipelineStateWebGPUImpl::InitializePipeline(const ComputePipelineStateCreateInfo& CreateInfo)
{
TShaderStages ShaderStages = InitInternalObjects(CreateInfo);
// Build specialization constant entries while CreateInfo is still valid.
BuildSpecializationDataWebGPU(ShaderStages,
CreateInfo.NumSpecializationConstants,
CreateInfo.pSpecializationConstants,
m_Desc);
// NB: it is not safe to check m_AsyncInitializer here as, first, it is set after the async task is started,
// and second, it is not atomic or protected by mutex.
if ((CreateInfo.Flags & PSO_CREATE_FLAG_ASYNCHRONOUS) == 0)
{
InitializeWebGPUComputePipeline(ShaderStages);
}
else
{
m_AsyncBuilder = MakeNewRCObj<AsyncPipelineBuilder>()(std::move(ShaderStages));
}
}
void PipelineStateWebGPUImpl::InitializeWebGPURenderPipeline(const TShaderStages& ShaderStages,
AsyncPipelineBuilder* AsyncBuilder)
{
VERIFY(!ShaderStages.empty() && ShaderStages.size() <= 2, "Incorrect shader count for graphics pipeline");
const GraphicsPipelineDesc& GraphicsPipeline = m_pGraphicsPipelineData->Desc;
WGPURenderPipelineDescriptor wgpuRenderPipelineDesc{};
wgpuRenderPipelineDesc.label = GetWGPUStringView(m_Desc.Name);
wgpuRenderPipelineDesc.layout = m_PipelineLayout.GetWebGPUPipelineLayout();
WGPUFragmentState wgpuFragmentState{};
std::vector<WebGPUShaderModuleWrapper> wgpuShaderModules{ShaderStages.size()};
for (size_t ShaderIdx = 0; ShaderIdx < ShaderStages.size(); ++ShaderIdx)
{
const ShaderStageInfo& Stage = ShaderStages[ShaderIdx];
WGPUShaderSourceWGSL wgpuShaderCodeDesc{};
wgpuShaderCodeDesc.chain.sType = WGPUSType_ShaderSourceWGSL;
wgpuShaderCodeDesc.code = GetWGPUStringView(Stage.GetWGSL());
WGPUShaderModuleDescriptor wgpuShaderModuleDesc{};
wgpuShaderModuleDesc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgpuShaderCodeDesc);
wgpuShaderModuleDesc.label = GetWGPUStringView(Stage.pShader->GetDesc().Name);
wgpuShaderModules[ShaderIdx].Reset(wgpuDeviceCreateShaderModule(m_pDevice->GetWebGPUDevice(), &wgpuShaderModuleDesc));
VERIFY(wgpuShaderModules[ShaderIdx], "Failed to create WGPU shader module for shader '", Stage.pShader->GetDesc().Name, "'.");
switch (Stage.Type)
{
case SHADER_TYPE_VERTEX:
VERIFY(wgpuRenderPipelineDesc.vertex.module == nullptr, "Only one vertex shader is allowed");
wgpuRenderPipelineDesc.vertex.module = wgpuShaderModules[ShaderIdx].Get();
wgpuRenderPipelineDesc.vertex.entryPoint = GetWGPUStringView(Stage.pShader->GetEntryPoint());
wgpuRenderPipelineDesc.vertex.constantCount = Stage.SpecConstEntries.size();
wgpuRenderPipelineDesc.vertex.constants = Stage.SpecConstEntries.empty() ? nullptr : Stage.SpecConstEntries.data();
break;
case SHADER_TYPE_PIXEL:
VERIFY(wgpuFragmentState.module == nullptr, "Only one vertex shader is allowed");
wgpuFragmentState.module = wgpuShaderModules[ShaderIdx].Get();
wgpuFragmentState.entryPoint = GetWGPUStringView(Stage.pShader->GetEntryPoint());
wgpuFragmentState.constantCount = Stage.SpecConstEntries.size();
wgpuFragmentState.constants = Stage.SpecConstEntries.empty() ? nullptr : Stage.SpecConstEntries.data();
wgpuRenderPipelineDesc.fragment = &wgpuFragmentState;
break;
default:
UNEXPECTED("Unsupported shader type ", GetShaderTypeLiteralName(Stage.Type));
}
}
std::array<std::vector<WGPUVertexAttribute>, MAX_LAYOUT_ELEMENTS> wgpuVertexAttributes{};
std::array<WGPUVertexBufferLayout, MAX_LAYOUT_ELEMENTS> wgpuVertexBufferLayouts{};
{
const InputLayoutDesc& InputLayout = GraphicsPipeline.InputLayout;
Uint32 MaxBufferSlot = 0;
for (Uint32 Idx = 0; Idx < InputLayout.NumElements; ++Idx)
{
const LayoutElement& Item = InputLayout.LayoutElements[Idx];
const Uint32 BufferSlot = Item.BufferSlot;
wgpuVertexBufferLayouts[BufferSlot].arrayStride = Item.Stride;
wgpuVertexBufferLayouts[BufferSlot].stepMode = InputElementFrequencyToWGPUVertexStepMode(Item.Frequency);
WGPUVertexAttribute wgpuVertexAttribute{};
wgpuVertexAttribute.format = VertexFormatAttribsToWGPUVertexFormat(Item.ValueType, Item.NumComponents, Item.IsNormalized);
wgpuVertexAttribute.offset = Item.RelativeOffset;
wgpuVertexAttribute.shaderLocation = Item.InputIndex;
wgpuVertexAttributes[BufferSlot].push_back(wgpuVertexAttribute);
MaxBufferSlot = std::max(MaxBufferSlot, BufferSlot);
}
for (size_t Idx = 0; Idx < MaxBufferSlot + 1; ++Idx)
{
wgpuVertexBufferLayouts[Idx].stepMode = !wgpuVertexAttributes[Idx].empty() ? wgpuVertexBufferLayouts[Idx].stepMode : WGPUVertexStepMode_VertexBufferNotUsed;
wgpuVertexBufferLayouts[Idx].attributeCount = static_cast<uint32_t>(wgpuVertexAttributes[Idx].size());
wgpuVertexBufferLayouts[Idx].attributes = wgpuVertexAttributes[Idx].data();
}
WGPUVertexState& wgpuVertexState = wgpuRenderPipelineDesc.vertex;
wgpuVertexState.bufferCount = InputLayout.NumElements > 0 ? MaxBufferSlot + 1 : 0;
wgpuVertexState.buffers = wgpuVertexBufferLayouts.data();
}
std::vector<WGPUColorTargetState> wgpuColorTargetStates(GraphicsPipeline.NumRenderTargets);
std::vector<WGPUBlendState> wgpuBlendStates(GraphicsPipeline.NumRenderTargets);
{
const BlendStateDesc& BlendDesc = GraphicsPipeline.BlendDesc;
const RenderTargetBlendDesc& RT0 = BlendDesc.RenderTargets[0];
for (Uint32 RTIndex = 0; RTIndex < GraphicsPipeline.NumRenderTargets; ++RTIndex)
{
const RenderTargetBlendDesc& RT = BlendDesc.RenderTargets[RTIndex];
WGPUColorTargetState& wgpuColorTargetState = wgpuColorTargetStates[RTIndex];
wgpuColorTargetState.format = TextureFormatToWGPUFormat(GraphicsPipeline.RTVFormats[RTIndex]);
wgpuColorTargetState.writeMask = ColorMaskToWGPUColorWriteMask(RT.RenderTargetWriteMask);
const bool RTBlendEnable = (RT0.BlendEnable && !BlendDesc.IndependentBlendEnable) || (RT.BlendEnable && BlendDesc.IndependentBlendEnable);
if (RTBlendEnable)
{
const RenderTargetBlendDesc& BlendRT = BlendDesc.IndependentBlendEnable ? RT : RT0;
WGPUBlendState& wgpuBlendState = wgpuBlendStates[RTIndex];
wgpuBlendState.color.operation = BlendOpToWGPUBlendOperation(BlendRT.BlendOp);
wgpuBlendState.color.srcFactor = BlendFactorToWGPUBlendFactor(BlendRT.SrcBlend);
wgpuBlendState.color.dstFactor = BlendFactorToWGPUBlendFactor(BlendRT.DestBlend);
wgpuBlendState.alpha.operation = BlendOpToWGPUBlendOperation(BlendRT.BlendOpAlpha);
wgpuBlendState.alpha.srcFactor = BlendFactorToWGPUBlendFactor(BlendRT.SrcBlendAlpha);
wgpuBlendState.alpha.dstFactor = BlendFactorToWGPUBlendFactor(BlendRT.DestBlendAlpha);
wgpuColorTargetState.blend = &wgpuBlendState;
}
}
wgpuFragmentState.targetCount = GraphicsPipeline.NumRenderTargets;
wgpuFragmentState.targets = wgpuColorTargetStates.data();
}
WGPUDepthStencilState wgpuDepthStencilState{};
if (GraphicsPipeline.DSVFormat != TEX_FORMAT_UNKNOWN)
{
const DepthStencilStateDesc& DepthStencilDesc = GraphicsPipeline.DepthStencilDesc;
wgpuDepthStencilState.format = TextureFormatToWGPUFormat(GraphicsPipeline.DSVFormat);
wgpuDepthStencilState.depthCompare = DepthStencilDesc.DepthEnable ? ComparisonFuncToWGPUCompareFunction(DepthStencilDesc.DepthFunc) : WGPUCompareFunction_Always;
wgpuDepthStencilState.depthWriteEnabled = DepthStencilDesc.DepthEnable ? BoolToWGPUOptionalBool(DepthStencilDesc.DepthWriteEnable) : WGPUOptionalBool_False;
wgpuDepthStencilState.stencilBack.compare = ComparisonFuncToWGPUCompareFunction(DepthStencilDesc.BackFace.StencilFunc);
wgpuDepthStencilState.stencilBack.failOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.BackFace.StencilFailOp);
wgpuDepthStencilState.stencilBack.depthFailOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.BackFace.StencilDepthFailOp);
wgpuDepthStencilState.stencilBack.passOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.BackFace.StencilPassOp);
wgpuDepthStencilState.stencilFront.compare = ComparisonFuncToWGPUCompareFunction(DepthStencilDesc.FrontFace.StencilFunc);
wgpuDepthStencilState.stencilFront.failOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.FrontFace.StencilFailOp);
wgpuDepthStencilState.stencilFront.depthFailOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.FrontFace.StencilDepthFailOp);
wgpuDepthStencilState.stencilFront.passOp = StencilOpToWGPUStencilOperation(DepthStencilDesc.FrontFace.StencilPassOp);
wgpuDepthStencilState.stencilReadMask = DepthStencilDesc.StencilReadMask;
wgpuDepthStencilState.stencilWriteMask = DepthStencilDesc.StencilWriteMask;
wgpuDepthStencilState.depthBias = static_cast<int32_t>(GraphicsPipeline.RasterizerDesc.DepthBias);
wgpuDepthStencilState.depthBiasSlopeScale = GraphicsPipeline.RasterizerDesc.SlopeScaledDepthBias;
wgpuDepthStencilState.depthBiasClamp = GraphicsPipeline.RasterizerDesc.DepthBiasClamp;
wgpuRenderPipelineDesc.depthStencil = &wgpuDepthStencilState;
}
#if PLATFORM_WEB
WGPUPrimitiveDepthClipControl wgpuDepthClipControl{};
#endif
{
const RasterizerStateDesc& RasterizerDesc = GraphicsPipeline.RasterizerDesc;
WGPUPrimitiveState& wgpuPrimitiveState = wgpuRenderPipelineDesc.primitive;
wgpuPrimitiveState.frontFace = RasterizerDesc.FrontCounterClockwise ? WGPUFrontFace_CCW : WGPUFrontFace_CW;
wgpuPrimitiveState.cullMode = CullModeToWGPUCullMode(RasterizerDesc.CullMode);
wgpuPrimitiveState.topology = PrimitiveTopologyWGPUPrimitiveType(GraphicsPipeline.PrimitiveTopology);
// For pipelines with strip topologies ("line-strip" or "triangle-strip"), the index buffer format and primitive restart value
// ("uint16"/0xFFFF or "uint32"/0xFFFFFFFF). Not allowed on pipelines with non-strip topologies.
wgpuPrimitiveState.stripIndexFormat =
(GraphicsPipeline.PrimitiveTopology == PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP ||
GraphicsPipeline.PrimitiveTopology == PRIMITIVE_TOPOLOGY_LINE_STRIP) ?
WGPUIndexFormat_Uint32 :
WGPUIndexFormat_Undefined;
if (!GraphicsPipeline.RasterizerDesc.DepthClipEnable)
{
if (m_pDevice->GetDeviceInfo().Features.DepthClamp)
{
#if PLATFORM_WEB
wgpuDepthClipControl.chain.sType = WGPUSType_PrimitiveDepthClipControl;
wgpuDepthClipControl.unclippedDepth = true;
wgpuPrimitiveState.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgpuDepthClipControl);
#else
wgpuPrimitiveState.unclippedDepth = true;
#endif
}
else
{
LOG_WARNING_MESSAGE("Depth clamping is not supported by the device. The depth clip control will be ignored.");
}
}
}
{
WGPUMultisampleState& wgpuMultisampleState = wgpuRenderPipelineDesc.multisample;
wgpuMultisampleState.alphaToCoverageEnabled = GraphicsPipeline.BlendDesc.AlphaToCoverageEnable;
wgpuMultisampleState.mask = GraphicsPipeline.SampleMask;
wgpuMultisampleState.count = GraphicsPipeline.SmplDesc.Count;
}
if (AsyncBuilder)
{
// The reference will be released from the callback.
AsyncBuilder->AddRef();
#if PLATFORM_WEB
wgpuDeviceCreateRenderPipelineAsync(m_pDevice->GetWebGPUDevice(), &wgpuRenderPipelineDesc, AsyncPipelineBuilder::CreateRenderPipelineCallback, AsyncBuilder);
#else
wgpuDeviceCreateRenderPipelineAsync2(m_pDevice->GetWebGPUDevice(), &wgpuRenderPipelineDesc,
{
nullptr,
WGPUCallbackMode_AllowSpontaneous,
AsyncPipelineBuilder::CreateRenderPipelineCallback2,
AsyncBuilder,
nullptr,
});
#endif
}
else
{
m_wgpuRenderPipeline.Reset(wgpuDeviceCreateRenderPipeline(m_pDevice->GetWebGPUDevice(), &wgpuRenderPipelineDesc));
if (!m_wgpuRenderPipeline)
LOG_ERROR_AND_THROW("Failed to create pipeline state");
}
}
void PipelineStateWebGPUImpl::InitializeWebGPUComputePipeline(const TShaderStages& ShaderStages,
AsyncPipelineBuilder* AsyncBuilder)
{
VERIFY(ShaderStages[0].Type == SHADER_TYPE_COMPUTE, "Incorrect shader type: compute shader is expected");
ShaderWebGPUImpl* pShaderWebGPU = ShaderStages[0].pShader;
WebGPUShaderModuleWrapper wgpuShaderModule{};
WGPUShaderSourceWGSL wgpuShaderCodeDesc{};
wgpuShaderCodeDesc.chain.sType = WGPUSType_ShaderSourceWGSL;
wgpuShaderCodeDesc.code = GetWGPUStringView(ShaderStages[0].GetWGSL());
WGPUShaderModuleDescriptor wgpuShaderModuleDesc{};
wgpuShaderModuleDesc.nextInChain = reinterpret_cast<WGPUChainedStruct*>(&wgpuShaderCodeDesc);
wgpuShaderModuleDesc.label = GetWGPUStringView(pShaderWebGPU->GetDesc().Name);
wgpuShaderModule.Reset(wgpuDeviceCreateShaderModule(m_pDevice->GetWebGPUDevice(), &wgpuShaderModuleDesc));
WGPUComputePipelineDescriptor wgpuComputePipelineDesc{};
wgpuComputePipelineDesc.label = GetWGPUStringView(m_Desc.Name);
wgpuComputePipelineDesc.compute.module = wgpuShaderModule.Get();
wgpuComputePipelineDesc.compute.entryPoint = GetWGPUStringView(pShaderWebGPU->GetEntryPoint());
wgpuComputePipelineDesc.layout = m_PipelineLayout.GetWebGPUPipelineLayout();
const std::vector<WGPUConstantEntry>& SpecConstEntries = ShaderStages[0].SpecConstEntries;
wgpuComputePipelineDesc.compute.constantCount = SpecConstEntries.size();
wgpuComputePipelineDesc.compute.constants = SpecConstEntries.empty() ? nullptr : SpecConstEntries.data();
if (AsyncBuilder)
{
// The reference will be released from the callback.
AsyncBuilder->AddRef();
#if PLATFORM_WEB
wgpuDeviceCreateComputePipelineAsync(m_pDevice->GetWebGPUDevice(), &wgpuComputePipelineDesc, AsyncPipelineBuilder::CreateComputePipelineCallback, AsyncBuilder);
#else
wgpuDeviceCreateComputePipelineAsync2(m_pDevice->GetWebGPUDevice(), &wgpuComputePipelineDesc,
{
nullptr,
WGPUCallbackMode_AllowSpontaneous,
AsyncPipelineBuilder::CreateComputePipelineCallback2,
AsyncBuilder,
nullptr,
});
#endif
}
else
{
m_wgpuComputePipeline.Reset(wgpuDeviceCreateComputePipeline(m_pDevice->GetWebGPUDevice(), &wgpuComputePipelineDesc));
if (!m_wgpuComputePipeline)
LOG_ERROR_AND_THROW("Failed to create pipeline state");
}
}
PIPELINE_STATE_STATUS PipelineStateWebGPUImpl::GetStatus(bool WaitForCompletion)
{
// Check the status of asynchronous tasks
PIPELINE_STATE_STATUS Status = TPipelineStateBase::GetStatus(WaitForCompletion);
if (Status != PIPELINE_STATE_STATUS_READY)
{
if (Status == PIPELINE_STATE_STATUS_FAILED && m_AsyncBuilder)
m_AsyncBuilder.Release();
return Status;
}
if (m_AsyncBuilder)
{
#if PLATFORM_WEB
if (WaitForCompletion)
{
LOG_ERROR_MESSAGE("Waiting for asynchronous pipeline initialization is not supported on the Web");
WaitForCompletion = false;
}
#endif
do
{
AsyncPipelineBuilder::CallbackStatus CallbackStatus = m_AsyncBuilder->Status.load();
switch (CallbackStatus)
{
case AsyncPipelineBuilder::CallbackStatus::NotStarted:
{
m_AsyncBuilder->Status.store(AsyncPipelineBuilder::CallbackStatus::InProgress);
if (m_Desc.IsAnyGraphicsPipeline())
InitializeWebGPURenderPipeline(m_AsyncBuilder->ShaderStages, m_AsyncBuilder);
else if (m_Desc.IsComputePipeline())
InitializeWebGPUComputePipeline(m_AsyncBuilder->ShaderStages, m_AsyncBuilder);
else
UNEXPECTED("Unexpected pipeline type");
// Do not change m_Status
Status = PIPELINE_STATE_STATUS_COMPILING;
}
break;
case AsyncPipelineBuilder::CallbackStatus::InProgress:
{
// Keep waiting
Status = PIPELINE_STATE_STATUS_COMPILING;
}
break;
case AsyncPipelineBuilder::CallbackStatus::Completed:
{
m_wgpuRenderPipeline = std::move(m_AsyncBuilder->wgpuRenderPipeline);
m_wgpuComputePipeline = std::move(m_AsyncBuilder->wgpuComputePipeline);
m_AsyncBuilder.Release();
Status = m_wgpuRenderPipeline || m_wgpuComputePipeline ? PIPELINE_STATE_STATUS_READY : PIPELINE_STATE_STATUS_FAILED;
m_Status.store(Status);
}
break;
default:
UNEXPECTED("Unexpected status");
}
// Note: DeviceTick() when WaitForCompletion == true is not required here since we use
// WGPUCallbackMode_AllowSpontaneous callback mode.
} while (WaitForCompletion && m_AsyncBuilder);
return Status;
}
return m_Status.load();
}
static void VerifyResourceMerge(const char* PSOName,
const WGSLShaderResourceAttribs& ExistingRes,
const WGSLShaderResourceAttribs& NewResAttribs)
{
#define LOG_RESOURCE_MERGE_ERROR_AND_THROW(PropertyName) \
LOG_ERROR_AND_THROW("Shader variable '", NewResAttribs.Name, \
"' is shared between multiple shaders in pipeline '", (PSOName ? PSOName : ""), \
"', but its " PropertyName " varies. A variable shared between multiple shaders " \
"must be defined identically in all shaders. Either use separate variables for " \
"different shader stages, change resource name or make sure that " PropertyName " is consistent.");
if (ExistingRes.Type != NewResAttribs.Type)
LOG_RESOURCE_MERGE_ERROR_AND_THROW("type");
if (ExistingRes.ResourceDim != NewResAttribs.ResourceDim)
LOG_RESOURCE_MERGE_ERROR_AND_THROW("resource dimension");
if (ExistingRes.ArraySize != NewResAttribs.ArraySize)
LOG_RESOURCE_MERGE_ERROR_AND_THROW("array size");
if (ExistingRes.SampleType != NewResAttribs.SampleType)
LOG_RESOURCE_MERGE_ERROR_AND_THROW("sample type");
if (ExistingRes.Format != NewResAttribs.Format)
LOG_RESOURCE_MERGE_ERROR_AND_THROW("texture format type");
#undef LOG_RESOURCE_MERGE_ERROR_AND_THROW
}
PipelineResourceSignatureDescWrapper PipelineStateWebGPUImpl::GetDefaultResourceSignatureDesc(const TShaderStages& ShaderStages,
const char* PSOName,
const PipelineResourceLayoutDesc& ResourceLayout,
Uint32 SRBAllocationGranularity)
{
PipelineResourceSignatureDescWrapper SignDesc{PSOName, ResourceLayout, SRBAllocationGranularity};
DefaultSignatureDescBuilder<WGSLShaderResourceAttribs> Builder{PSOName, ResourceLayout, VerifyResourceMerge, SignDesc};
for (const ShaderStageInfo& Stage : ShaderStages)
{
const ShaderWebGPUImpl* pShader = Stage.pShader;
const WGSLShaderResources& ShaderResources = *pShader->GetShaderResources();
ShaderResources.ProcessResources(
[&](const WGSLShaderResourceAttribs& Attribs, Uint32) //
{
if (Attribs.ArraySize == 0)
{
LOG_ERROR_AND_THROW("Resource '", Attribs.Name, "' in shader '", pShader->GetDesc().Name, "' is a runtime-sized array. ",
"You must use explicit resource signature to specify the array size.");
}
const char* const SamplerSuffix =
(ShaderResources.IsUsingCombinedSamplers() && (Attribs.Type == WGSLShaderResourceAttribs::ResourceType::Sampler || Attribs.Type == WGSLShaderResourceAttribs::ResourceType::ComparisonSampler)) ?
ShaderResources.GetCombinedSamplerSuffix() :
nullptr;
const ShaderResourceVariableDesc VarDesc = FindPipelineResourceLayoutVariable(ResourceLayout, Attribs.Name, Stage.Type, SamplerSuffix);
const PIPELINE_RESOURCE_FLAGS Flags = WGSLShaderResourceAttribs::GetPipelineResourceFlags(Attribs.Type) | ShaderVariableFlagsToPipelineResourceFlags(VarDesc.Flags);
const SHADER_RESOURCE_TYPE ResType = WGSLShaderResourceAttribs::GetShaderResourceType(Attribs.Type);
const WebGPUResourceAttribs WebGPUAttribs = Attribs.GetWebGPUAttribs(VarDesc.Flags);
const Uint32 ArraySize = (Flags & PIPELINE_RESOURCE_FLAG_INLINE_CONSTANTS) ?
Attribs.GetInlineConstantCountOrThrow() :
Attribs.ArraySize;
// Note that Attribs.Name != VarDesc.Name for combined samplers
Builder.AddResource(Attribs.Name, Attribs, VarDesc, ArraySize, ResType, Flags, WebGPUAttribs);
});
// Merge combined sampler suffixes
if (ShaderResources.IsUsingCombinedSamplers() && ShaderResources.GetNumSamplers() > 0)
{
SignDesc.SetCombinedSamplerSuffix(ShaderResources.GetCombinedSamplerSuffix());
}
}
return SignDesc;
}
#ifdef DILIGENT_DEVELOPMENT
void PipelineStateWebGPUImpl::DvpVerifySRBResources(const DeviceContextWebGPUImpl* pDeviceCtx, const ShaderResourceCacheArrayType& ResourceCaches) const
{
auto res_info = m_ResourceAttibutions.begin();
for (const auto& pResources : m_ShaderResources)
{
pResources->ProcessResources(
[&](const WGSLShaderResourceAttribs& ResAttribs, Uint32) //
{
VERIFY_EXPR(res_info->pSignature != nullptr);
VERIFY_EXPR(res_info->pSignature->GetDesc().BindingIndex == res_info->SignatureIndex);
const ShaderResourceCacheWebGPU* pResourceCache = ResourceCaches[res_info->SignatureIndex];
DEV_CHECK_ERR(pResourceCache != nullptr, "Resource cache at index ", res_info->SignatureIndex, " is null.");
if (res_info->IsImmutableSampler())
{
res_info->pSignature->DvpValidateImmutableSampler(ResAttribs, res_info->ImmutableSamplerIndex, *pResourceCache,
pResources->GetShaderName(), m_Desc.Name);
}
else
{
res_info->pSignature->DvpValidateCommittedResource(pDeviceCtx, ResAttribs, res_info->ResourceIndex, *pResourceCache,
pResources->GetShaderName(), m_Desc.Name);
}
++res_info;
} //
);
}
VERIFY_EXPR(res_info == m_ResourceAttibutions.end());
}
#endif
} // namespace Diligent