mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 06:27:54 +00:00
Validate binary operations
This change validates that the operand types and result type of every binary operation is valid. * Added two unit tests which test all valid and invalid param combos. I also removed the old tests, many of which failed once I added this validation, and the rest are obviated by the new tests. * Fixed VertexPulling transform, as well as many tests, that were using invalid operand types for binary operations. Fixed: tint:354 Change-Id: Ia3f48384256993da61b341f17ba5583741011819 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/44341 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
1691401179
commit
be0fc4e929
@@ -104,7 +104,7 @@ TEST_F(BoundArrayAccessorsTest, Array_Idx_Expr) {
|
||||
auto* src = R"(
|
||||
var a : array<f32, 3>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[c + 2 - 3];
|
||||
@@ -114,7 +114,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : array<f32, 3>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
|
||||
@@ -196,7 +196,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Idx_Expr) {
|
||||
auto* src = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[c + 2 - 3];
|
||||
@@ -206,7 +206,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)];
|
||||
@@ -244,7 +244,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Var) {
|
||||
auto* src = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a.xy[c];
|
||||
@@ -254,7 +254,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a.xy[min(u32(c), 1u)];
|
||||
@@ -269,7 +269,7 @@ TEST_F(BoundArrayAccessorsTest, Vector_Swizzle_Idx_Expr) {
|
||||
auto* src = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a.xy[c + 2 - 3];
|
||||
@@ -279,7 +279,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : vec3<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a.xy[min(u32(((c + 2) - 3)), 1u)];
|
||||
@@ -361,7 +361,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Column) {
|
||||
auto* src = R"(
|
||||
var a : mat3x2<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[c + 2 - 3][1];
|
||||
@@ -371,7 +371,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : mat3x2<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[min(u32(((c + 2) - 3)), 2u)][1];
|
||||
@@ -387,7 +387,7 @@ TEST_F(BoundArrayAccessorsTest, Matrix_Idx_Expr_Row) {
|
||||
auto* src = R"(
|
||||
var a : mat3x2<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[1][c + 2 - 3];
|
||||
@@ -397,7 +397,7 @@ fn f() -> void {
|
||||
auto* expect = R"(
|
||||
var a : mat3x2<f32>;
|
||||
|
||||
var c : u32;
|
||||
var c : i32;
|
||||
|
||||
fn f() -> void {
|
||||
var b : f32 = a[1][min(u32(((c + 2) - 3)), 1u)];
|
||||
|
||||
@@ -132,7 +132,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||
Source{}, // source
|
||||
ctx.dst->Symbols().Register(vertex_index_name), // symbol
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
GetU32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::DecorationList{
|
||||
@@ -179,7 +179,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||
Source{}, // source
|
||||
ctx.dst->Symbols().Register(instance_index_name), // symbol
|
||||
ast::StorageClass::kInput, // storage_class
|
||||
GetI32Type(), // type
|
||||
GetU32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::DecorationList{
|
||||
@@ -273,7 +273,7 @@ ast::BlockStatement* VertexPulling::State::CreateVertexPullingPreamble() const {
|
||||
Source{}, // source
|
||||
ctx.dst->Symbols().Register(kPullingPosVarName), // symbol
|
||||
ast::StorageClass::kFunction, // storage_class
|
||||
GetI32Type(), // type
|
||||
GetU32Type(), // type
|
||||
false, // is_const
|
||||
nullptr, // constructor
|
||||
ast::DecorationList{})); // decorations
|
||||
|
||||
@@ -89,7 +89,7 @@ struct TintVertexData {
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
}
|
||||
}
|
||||
)";
|
||||
@@ -113,7 +113,7 @@ fn main() -> void {}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : u32;
|
||||
|
||||
[[binding(0), group(4)]] var<storage> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
|
||||
@@ -127,7 +127,7 @@ var<private> var_a : f32;
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u);
|
||||
var_a = bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[(_tint_pulling_pos / 4u)]);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ fn main() -> void {}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(instance_index)]] var<in> _tint_pulling_instance_index : i32;
|
||||
[[builtin(instance_index)]] var<in> _tint_pulling_instance_index : u32;
|
||||
|
||||
[[binding(0), group(4)]] var<storage> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
|
||||
@@ -169,7 +169,7 @@ var<private> var_a : f32;
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((_tint_pulling_instance_index * 4u) + 0u);
|
||||
var_a = bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[(_tint_pulling_pos / 4u)]);
|
||||
}
|
||||
@@ -197,7 +197,7 @@ fn main() -> void {}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : u32;
|
||||
|
||||
[[binding(0), group(5)]] var<storage> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
|
||||
@@ -211,7 +211,7 @@ var<private> var_a : f32;
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 4u) + 0u);
|
||||
var_a = bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[(_tint_pulling_pos / 4u)]);
|
||||
}
|
||||
@@ -236,8 +236,8 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
|
||||
auto* src = R"(
|
||||
[[location(0)]] var<in> var_a : f32;
|
||||
[[location(1)]] var<in> var_b : f32;
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : u32;
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : u32;
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {}
|
||||
@@ -257,14 +257,14 @@ var<private> var_a : f32;
|
||||
|
||||
var<private> var_b : f32;
|
||||
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : u32;
|
||||
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : i32;
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : u32;
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((custom_vertex_index * 4u) + 0u);
|
||||
var_a = bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[(_tint_pulling_pos / 4u)]);
|
||||
_tint_pulling_pos = ((custom_instance_index * 4u) + 0u);
|
||||
@@ -305,7 +305,7 @@ fn main() -> void {}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : u32;
|
||||
|
||||
[[binding(0), group(4)]] var<storage> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
|
||||
@@ -321,7 +321,7 @@ var<private> var_b : array<f32, 4>;
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 16u) + 0u);
|
||||
var_a = bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[(_tint_pulling_pos / 4u)]);
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 16u) + 0u);
|
||||
@@ -355,7 +355,7 @@ fn main() -> void {}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : u32;
|
||||
|
||||
[[binding(0), group(4)]] var<storage> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
|
||||
@@ -377,7 +377,7 @@ var<private> var_c : array<f32, 4>;
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
{
|
||||
var _tint_pulling_pos : i32;
|
||||
var _tint_pulling_pos : u32;
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 8u) + 0u);
|
||||
var_a = vec2<f32>(bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[((_tint_pulling_pos + 0u) / 4u)]), bitcast<f32>(_tint_pulling_vertex_buffer_0._tint_vertex_data[((_tint_pulling_pos + 4u) / 4u)]));
|
||||
_tint_pulling_pos = ((_tint_pulling_vertex_index * 12u) + 0u);
|
||||
|
||||
Reference in New Issue
Block a user