Split BindingArray validation from CheckType Move binding array validation to a CheckBindingArray helper. Change-Id: I2c33018e647d27cfc3dd758085a9961ec8d9c92a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/320664 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/ir/structural_validator.cc b/src/tint/lang/core/ir/structural_validator.cc index e659852..4d58242 100644 --- a/src/tint/lang/core/ir/structural_validator.cc +++ b/src/tint/lang/core/ir/structural_validator.cc
@@ -704,31 +704,7 @@ return CheckSubgroupMatrix(m, diag, addrspace); }, [&](const core::type::BindingArray* t) { - if (!t->Count()->Is<core::type::ConstantArrayCount>()) { - diag() << "binding_array count must be a constant expression"; - return false; - } - - auto count = t->Count()->As<core::type::ConstantArrayCount>()->value; - if (count == 0) { - diag() << "binding array requires a constant array size > 0"; - return false; - } - - if (!(addrspace == AddressSpace::kUndefined || - addrspace == AddressSpace::kHandle) && - !ir_.properties.Contains(Property::kAllowMslEntryPointInterface)) { - diag() << "invalid address space for binding_array : " << addrspace; - return false; - } - - if (!ir_.properties.Contains(Property::kAllowNonCoreTypes)) { - if (!t->ElemType()->Is<core::type::SampledTexture>()) { - diag() << "binding_array element type must be a sampled texture type"; - return false; - } - } - return true; + return CheckBindingArray(t, diag, addrspace); }, [&](const core::type::Buffer*) { if (!ir_.properties.Contains(Property::kAllowBufferTypes)) { @@ -797,6 +773,35 @@ } } +bool Structural::CheckBindingArray(const core::type::BindingArray* ba, + std::function<diag::Diagnostic&()>& diag, + core::AddressSpace addrspace) { + if (!ba->Count()->Is<core::type::ConstantArrayCount>()) { + diag() << "binding_array count must be a constant expression"; + return false; + } + + auto count = ba->Count()->As<core::type::ConstantArrayCount>()->value; + if (count == 0) { + diag() << "binding array requires a constant array size > 0"; + return false; + } + + if (!(addrspace == AddressSpace::kUndefined || addrspace == AddressSpace::kHandle) && + !ir_.properties.Contains(Property::kAllowMslEntryPointInterface)) { + diag() << "invalid address space for binding_array : " << addrspace; + return false; + } + + if (!ir_.properties.Contains(Property::kAllowNonCoreTypes)) { + if (!ba->ElemType()->Is<core::type::SampledTexture>()) { + diag() << "binding_array element type must be a sampled texture type"; + return false; + } + } + return true; +} + bool Structural::CheckSubgroupMatrix(const core::type::SubgroupMatrix* m, std::function<diag::Diagnostic&()>& diag, core::AddressSpace addrspace) {
diff --git a/src/tint/lang/core/ir/structural_validator.h b/src/tint/lang/core/ir/structural_validator.h index b429027..e051458 100644 --- a/src/tint/lang/core/ir/structural_validator.h +++ b/src/tint/lang/core/ir/structural_validator.h
@@ -380,6 +380,13 @@ bool CheckSubgroupMatrix(const core::type::SubgroupMatrix* m, std::function<diag::Diagnostic&()>& diag, core::AddressSpace addrspace); + /// Checks that `ba` is a valid binding array + /// @param ba the binding array + /// @param diag a function that creates an error diagnostic for the source of the type + /// @param addrspace the address space of the root type + bool CheckBindingArray(const core::type::BindingArray* ba, + std::function<diag::Diagnostic&()>& diag, + core::AddressSpace addrspace); /// Checks that 8-bit types are permitted /// @param diag a function that creates an error diagnostic for the source of the type