Resolver: Validate resource binding decorations

Validate that:
* That resource variables have resource bindings
* Only resource variables have resource bindings
* That a [[binding]] decoration is paired with a [[group]]
* That binding points are not reused in the same entry point

Fixed: tint:235
Fixed: tint:645
Bug: tint:645
Change-Id: I2542934b4c6a2b4bbde48242932c04c796033a90
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50500
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-05-10 19:16:46 +00:00
committed by Commit Bot service account
parent 6ba446fa5e
commit 3f968e7b05
26 changed files with 730 additions and 229 deletions

View File

@@ -1,70 +0,0 @@
// Copyright 2021 The Tint Authors.
//
// 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.
#ifndef SRC_TRANSFORM_BINDING_POINT_H_
#define SRC_TRANSFORM_BINDING_POINT_H_
#include <stdint.h>
#include <functional>
#include "src/utils/hash.h"
namespace tint {
namespace transform {
/// BindingPoint holds a group and binding index.
struct BindingPoint {
/// The `[[group]]` part of the binding point
uint32_t group = 0;
/// The `[[binding]]` part of the binding point
uint32_t binding = 0;
/// Equality operator
/// @param rhs the BindingPoint to compare against
/// @returns true if this BindingPoint is equal to `rhs`
inline bool operator==(const BindingPoint& rhs) const {
return group == rhs.group && binding == rhs.binding;
}
/// Inequality operator
/// @param rhs the BindingPoint to compare against
/// @returns true if this BindingPoint is not equal to `rhs`
inline bool operator!=(const BindingPoint& rhs) const {
return !(*this == rhs);
}
};
} // namespace transform
} // namespace tint
namespace std {
/// Custom std::hash specialization for tint::transform::BindingPoint so
/// BindingPoints can be used as keys for std::unordered_map and
/// std::unordered_set.
template <>
class hash<tint::transform::BindingPoint> {
public:
/// @param binding_point the binding point to create a hash for
/// @return the hash value
inline std::size_t operator()(
const tint::transform::BindingPoint& binding_point) const {
return tint::utils::Hash(binding_point.group, binding_point.binding);
}
};
} // namespace std
#endif // SRC_TRANSFORM_BINDING_POINT_H_

View File

@@ -18,12 +18,15 @@
#include <unordered_map>
#include "src/ast/access_control.h"
#include "src/transform/binding_point.h"
#include "src/sem/binding_point.h"
#include "src/transform/transform.h"
namespace tint {
namespace transform {
/// BindingPoint is an alias to sem::BindingPoint
using BindingPoint = sem::BindingPoint;
/// BindingRemapper is a transform used to remap resource binding points and
/// access controls.
class BindingRemapper : public Transform {

View File

@@ -540,7 +540,7 @@ struct S {
a : f32;
b : array<f32>;
};
var<storage> s : [[access(read)]] S;
[[group(0), binding(0)]] var<storage> s : [[access(read)]] S;
fn f() {
var d : f32 = s.b[25];
@@ -554,7 +554,7 @@ struct S {
b : array<f32>;
};
var<storage> s : [[access(read)]] S;
[[group(0), binding(0)]] var<storage> s : [[access(read)]] S;
fn f() {
var d : f32 = s.b[min(u32(25), (arrayLength(s.b) - 1u))];
@@ -601,7 +601,7 @@ struct S {
b : array<f32>;
};
var<storage> s : [[access(read)]] S;
[[group(0), binding(0)]] var<storage> s : [[access(read)]] S;
let c : u32 = 1u;
@@ -619,7 +619,7 @@ struct S {
b : array<f32>;
};
var<storage> s : [[access(read)]] S;
[[group(0), binding(0)]] var<storage> s : [[access(read)]] S;
let c : u32 = 1u;

View File

@@ -30,7 +30,7 @@ struct SB {
arr : array<i32>;
};
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -48,7 +48,7 @@ struct SB {
[[internal(intrinsic_buffer_size)]]
fn tint_symbol(buffer : SB, result : ptr<function, u32>)
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -72,7 +72,7 @@ struct SB {
arr : array<i32>;
};
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -92,7 +92,7 @@ struct SB {
[[internal(intrinsic_buffer_size)]]
fn tint_symbol(buffer : SB, result : ptr<function, u32>)
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -119,7 +119,7 @@ struct SB {
arr : [[stride(64)]] array<i32>;
};
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -138,7 +138,7 @@ struct SB {
[[internal(intrinsic_buffer_size)]]
fn tint_symbol(buffer : SB, result : ptr<function, u32>)
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -162,7 +162,7 @@ struct SB {
arr : array<i32>;
};
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -186,7 +186,7 @@ struct SB {
[[internal(intrinsic_buffer_size)]]
fn tint_symbol(buffer : SB, result : ptr<function, u32>)
var<storage> sb : [[access(read)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read)]] SB;
[[stage(compute)]]
fn main() {
@@ -225,9 +225,9 @@ struct SB2 {
arr2 : array<vec4<f32>>;
};
var<storage> sb1 : [[access(read)]] SB1;
[[group(0), binding(0)]] var<storage> sb1 : [[access(read)]] SB1;
var<storage> sb2 : [[access(read)]] SB2;
[[group(0), binding(1)]] var<storage> sb2 : [[access(read)]] SB2;
[[stage(compute)]]
fn main() {
@@ -256,9 +256,9 @@ struct SB2 {
[[internal(intrinsic_buffer_size)]]
fn tint_symbol_3(buffer : SB2, result : ptr<function, u32>)
var<storage> sb1 : [[access(read)]] SB1;
[[group(0), binding(0)]] var<storage> sb1 : [[access(read)]] SB1;
var<storage> sb2 : [[access(read)]] SB2;
[[group(0), binding(1)]] var<storage> sb2 : [[access(read)]] SB2;
[[stage(compute)]]
fn main() {

View File

@@ -50,7 +50,7 @@ struct SB {
v : array<vec3<f32>, 2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -182,7 +182,7 @@ fn tint_symbol_21(buffer : [[access(read_write)]] SB, offset : u32) -> array<vec
return array<vec3<f32>, 2>(tint_symbol_8(buffer, (offset + 0u)), tint_symbol_8(buffer, (offset + 16u)));
}
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -244,7 +244,7 @@ struct SB {
v : array<vec3<f32>, 2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -395,7 +395,7 @@ fn tint_symbol_21(buffer : [[access(read_write)]] SB, offset : u32, value : arra
tint_symbol_8(buffer, (offset + 16u), value[1u]);
}
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -457,7 +457,7 @@ struct SB {
v : array<vec3<f32>, 2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -572,7 +572,7 @@ fn tint_symbol_22(buffer : [[access(read_write)]] SB, offset : u32) -> SB {
return SB(tint_symbol(buffer, (offset + 0u)), tint_symbol_1(buffer, (offset + 4u)), tint_symbol_2(buffer, (offset + 8u)), tint_symbol_3(buffer, (offset + 16u)), tint_symbol_4(buffer, (offset + 24u)), tint_symbol_5(buffer, (offset + 32u)), tint_symbol_6(buffer, (offset + 48u)), tint_symbol_7(buffer, (offset + 64u)), tint_symbol_8(buffer, (offset + 80u)), tint_symbol_9(buffer, (offset + 96u)), tint_symbol_10(buffer, (offset + 112u)), tint_symbol_11(buffer, (offset + 128u)), tint_symbol_12(buffer, (offset + 144u)), tint_symbol_13(buffer, (offset + 160u)), tint_symbol_14(buffer, (offset + 192u)), tint_symbol_15(buffer, (offset + 224u)), tint_symbol_16(buffer, (offset + 256u)), tint_symbol_17(buffer, (offset + 304u)), tint_symbol_18(buffer, (offset + 352u)), tint_symbol_19(buffer, (offset + 384u)), tint_symbol_20(buffer, (offset + 448u)), tint_symbol_21(buffer, (offset + 512u)));
}
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -613,7 +613,7 @@ struct SB {
v : array<vec3<f32>, 2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -768,7 +768,7 @@ fn tint_symbol_22(buffer : [[access(read_write)]] SB, offset : u32, value : SB)
tint_symbol_21(buffer, (offset + 512u), value.v);
}
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -802,7 +802,7 @@ struct SB {
b : [[stride(256)]] array<S2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -840,7 +840,7 @@ struct SB {
[[internal(intrinsic_load_f32)]]
fn tint_symbol(buffer : [[access(read_write)]] SB, offset : u32) -> f32
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -874,7 +874,7 @@ struct SB {
b : [[stride(256)]] array<S2>;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -908,7 +908,7 @@ struct SB {
[[internal(intrinsic_load_f32)]]
fn tint_symbol(buffer : [[access(read_write)]] SB, offset : u32) -> f32
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -953,7 +953,7 @@ struct SB {
b : A2_Array;
};
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {
@@ -995,7 +995,7 @@ struct SB {
[[internal(intrinsic_load_f32)]]
fn tint_symbol(buffer : [[access(read_write)]] SB, offset : u32) -> f32
var<storage> sb : [[access(read_write)]] SB;
[[group(0), binding(0)]] var<storage> sb : [[access(read_write)]] SB;
[[stage(compute)]]
fn main() {