@@ -603,54 +603,30 @@ MaybeError ValidateCompatibilityOfSingleBindingWithLayout(const DeviceBase* devi
603
603
SingleShaderStage entryPointStage,
604
604
BindingNumber bindingNumber,
605
605
const ShaderBindingInfo& shaderInfo) {
606
+ // Check that the binding exists.
606
607
const BindGroupLayoutInternalBase::BindingMap& layoutBindings = layout->GetBindingMap ();
607
608
608
- // An external texture binding found in the shader will later be expanded into multiple
609
- // bindings at compile time. This expansion will have already happened in the bgl - so
610
- // the shader and bgl will always mismatch at this point. Expansion info is contained in
611
- // the bgl object, so we can still verify the bgl used to have an external texture in
612
- // the slot corresponding to the shader reflection.
613
- if (std::holds_alternative<ExternalTextureBindingInfo>(shaderInfo.bindingInfo )) {
614
- // If an external texture binding used to exist in the bgl, it will be found as a
615
- // key in the ExternalTextureBindingExpansions map.
616
- // TODO(dawn:563): Provide info about the binding types.
617
- DAWN_INVALID_IF (!layout->GetExternalTextureBindingExpansionMap ().contains (bindingNumber),
618
- " Binding type in the shader (texture_external) doesn't match the "
619
- " type in the layout." );
620
-
621
- return {};
622
- }
623
-
624
609
const auto & bindingIt = layoutBindings.find (bindingNumber);
625
610
DAWN_INVALID_IF (bindingIt == layoutBindings.end (), " Binding doesn't exist in %s." , layout);
626
611
627
612
APIBindingIndex bindingIndex (bindingIt->second );
628
613
const BindingInfo& layoutInfo = layout->GetAPIBindingInfo (bindingIndex);
629
614
630
- BindingInfoType bindingLayoutType = GetBindingInfoType (layoutInfo);
615
+ // Check that it is of the same type as in the layout.
631
616
BindingInfoType shaderBindingType = GetShaderBindingType (shaderInfo);
632
-
633
- if (bindingLayoutType == BindingInfoType::StaticSampler) {
634
- DAWN_INVALID_IF (shaderBindingType != BindingInfoType::Sampler,
635
- " Binding type in the shader (%s) doesn't match the required type of %s for "
636
- " the %s type in the layout." ,
637
- shaderBindingType, BindingInfoType::Sampler, bindingLayoutType);
638
- return {};
617
+ BindingInfoType requiredType = GetBindingInfoType (layoutInfo);
618
+ if (requiredType == BindingInfoType::StaticSampler) {
619
+ requiredType = BindingInfoType::Sampler;
639
620
}
640
-
641
- DAWN_INVALID_IF (bindingLayoutType != shaderBindingType,
621
+ DAWN_INVALID_IF (requiredType != shaderBindingType,
642
622
" Binding type in the shader (%s) doesn't match the type in the layout (%s)." ,
643
- shaderBindingType, bindingLayoutType);
644
-
645
- ExternalTextureBindingExpansionMap expansions = layout->GetExternalTextureBindingExpansionMap ();
646
- DAWN_INVALID_IF (expansions.contains (bindingNumber),
647
- " Binding type (buffer vs. texture vs. sampler vs. external) doesn't "
648
- " match the type in the layout." );
623
+ shaderBindingType, requiredType);
649
624
650
625
DAWN_INVALID_IF ((layoutInfo.visibility & StageBit (entryPointStage)) == 0 ,
651
626
" Entry point's stage (%s) is not in the binding visibility in the layout (%s)." ,
652
627
StageBit (entryPointStage), layoutInfo.visibility );
653
628
629
+ // Check the arraySize matches the layout and that the shader has the start of the array.
654
630
DAWN_INVALID_IF (layoutInfo.arraySize < shaderInfo.arraySize ,
655
631
" Binding type in the shader is a binding_array with %u elements but the "
656
632
" layout only provides %u elements" ,
@@ -661,6 +637,7 @@ MaybeError ValidateCompatibilityOfSingleBindingWithLayout(const DeviceBase* devi
661
637
shaderInfo.binding , layoutInfo.indexInArray ,
662
638
uint32_t (layoutInfo.binding ) - uint32_t (layoutInfo.indexInArray ));
663
639
640
+ // Validation specific to each type of binding.
664
641
return MatchVariant (
665
642
shaderInfo.bindingInfo ,
666
643
[&](const TextureBindingInfo& bindingInfo) -> MaybeError {
@@ -760,19 +737,26 @@ MaybeError ValidateCompatibilityOfSingleBindingWithLayout(const DeviceBase* devi
760
737
return {};
761
738
},
762
739
[&](const SamplerBindingInfo& bindingInfo) -> MaybeError {
763
- const SamplerBindingInfo& bindingLayout =
764
- std::get<SamplerBindingInfo>(layoutInfo.bindingLayout );
740
+ bool comparisonInShader = bindingInfo.type == wgpu::SamplerBindingType::Comparison;
741
+ bool comparisonInLayout;
742
+ if (auto * staticBindingLayout =
743
+ std::get_if<StaticSamplerBindingInfo>(&layoutInfo.bindingLayout )) {
744
+ comparisonInLayout = staticBindingLayout->sampler ->IsComparison ();
745
+ } else {
746
+ const SamplerBindingInfo& bindingLayout =
747
+ std::get<SamplerBindingInfo>(layoutInfo.bindingLayout );
748
+ comparisonInLayout = bindingLayout.type == wgpu::SamplerBindingType::Comparison;
749
+ }
750
+
765
751
DAWN_INVALID_IF (
766
- (bindingLayout.type == wgpu::SamplerBindingType::Comparison) !=
767
- (bindingInfo.type == wgpu::SamplerBindingType::Comparison),
752
+ comparisonInShader != comparisonInLayout,
768
753
" The sampler type in the shader (comparison: %u) doesn't match the type in "
769
754
" the layout (comparison: %u)." ,
770
- bindingInfo.type == wgpu::SamplerBindingType::Comparison,
771
- bindingLayout.type == wgpu::SamplerBindingType::Comparison);
755
+ comparisonInShader, comparisonInLayout);
772
756
return {};
773
757
},
774
758
[](const ExternalTextureBindingInfo&) -> MaybeError {
775
- DAWN_UNREACHABLE ();
759
+ // There are no other things to validate for the external textures.
776
760
return {};
777
761
},
778
762
[&](const InputAttachmentBindingInfo& bindingInfo) -> MaybeError {
0 commit comments