mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-11 22:44:04 +00:00
[resolver] Add entry point IO validation
Checks the following things: - Non-struct entry point parameters must have pipeline IO attributes - Non-struct entry point return type must have a pipeline IO attribute - Structs used as entry point parameters and return values much have pipeline IO attributes on every member - Structs used as entry point parameters and return values cannot have runtime array or nested struct members - Multiple pipeline IO attributes on a parameter, return type, or struct member is not allowed - Any given builtin and location attribute can only appear once for the return type, and across all parameters Removed tests for nested structs from the SPIR-V transform/backend. Fixed a couple of other tests with missing pipeline IO attributes. Fixed: tint:512 Change-Id: I4c48fe24099333c8c7fcd45934c09baa6830883c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46701 Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
09356cc3dc
commit
68f558f29c
@@ -83,7 +83,7 @@ fn _tint_3() -> void {
|
||||
TEST_F(RenamerTest, PreserveSwizzles) {
|
||||
auto* src = R"(
|
||||
[[stage(vertex)]]
|
||||
fn entry() -> vec4<f32> {
|
||||
fn entry() -> [[builtin(position)]] vec4<f32> {
|
||||
var v : vec4<f32>;
|
||||
var rgba : f32;
|
||||
var xyzw : f32;
|
||||
@@ -93,7 +93,7 @@ fn entry() -> vec4<f32> {
|
||||
|
||||
auto* expect = R"(
|
||||
[[stage(vertex)]]
|
||||
fn _tint_1() -> vec4<f32> {
|
||||
fn _tint_1() -> [[builtin(position)]] vec4<f32> {
|
||||
var _tint_2 : vec4<f32>;
|
||||
var _tint_3 : f32;
|
||||
var _tint_4 : f32;
|
||||
@@ -120,7 +120,7 @@ fn _tint_1() -> vec4<f32> {
|
||||
TEST_F(RenamerTest, PreserveIntrinsics) {
|
||||
auto* src = R"(
|
||||
[[stage(vertex)]]
|
||||
fn entry() -> vec4<f32> {
|
||||
fn entry() -> [[builtin(position)]] vec4<f32> {
|
||||
var blah : vec4<f32>;
|
||||
return abs(blah);
|
||||
}
|
||||
@@ -128,7 +128,7 @@ fn entry() -> vec4<f32> {
|
||||
|
||||
auto* expect = R"(
|
||||
[[stage(vertex)]]
|
||||
fn _tint_1() -> vec4<f32> {
|
||||
fn _tint_1() -> [[builtin(position)]] vec4<f32> {
|
||||
var _tint_2 : vec4<f32>;
|
||||
return abs(_tint_2);
|
||||
}
|
||||
|
||||
@@ -224,86 +224,10 @@ fn frag_main() -> void {
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructParameters_Nested) {
|
||||
auto* src = R"(
|
||||
struct Builtins {
|
||||
[[builtin(frag_coord)]] coord : vec4<f32>;
|
||||
};
|
||||
|
||||
struct Locations {
|
||||
[[location(2)]] l2 : f32;
|
||||
[[location(3)]] l3 : f32;
|
||||
};
|
||||
|
||||
struct Other {
|
||||
l : Locations;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
b : Builtins;
|
||||
o : Other;
|
||||
[[location(1)]] value : f32;
|
||||
};
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main(inputs : FragmentInput) -> void {
|
||||
var col : f32 = inputs.b.coord.x * inputs.value;
|
||||
var l : f32 = inputs.o.l.l2 + inputs.o.l.l3;
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct Builtins {
|
||||
coord : vec4<f32>;
|
||||
};
|
||||
|
||||
struct Locations {
|
||||
l2 : f32;
|
||||
l3 : f32;
|
||||
};
|
||||
|
||||
struct Other {
|
||||
l : Locations;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
b : Builtins;
|
||||
o : Other;
|
||||
value : f32;
|
||||
};
|
||||
|
||||
[[builtin(frag_coord)]] var<in> tint_symbol_12 : vec4<f32>;
|
||||
|
||||
[[location(2)]] var<in> tint_symbol_14 : f32;
|
||||
|
||||
[[location(3)]] var<in> tint_symbol_15 : f32;
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_18 : f32;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
const tint_symbol_13 : Builtins = Builtins(tint_symbol_12);
|
||||
const tint_symbol_16 : Locations = Locations(tint_symbol_14, tint_symbol_15);
|
||||
const tint_symbol_17 : Other = Other(tint_symbol_16);
|
||||
const tint_symbol_19 : FragmentInput = FragmentInput(tint_symbol_13, tint_symbol_17, tint_symbol_18);
|
||||
var col : f32 = (tint_symbol_19.b.coord.x * tint_symbol_19.value);
|
||||
var l : f32 = (tint_symbol_19.o.l.l2 + tint_symbol_19.o.l.l3);
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Spirv>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructParameters_EmptyBody) {
|
||||
auto* src = R"(
|
||||
struct Locations {
|
||||
[[location(1)]] value : f32;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
locations : Locations;
|
||||
[[location(1)]] value : f32;
|
||||
};
|
||||
|
||||
[[stage(fragment)]]
|
||||
@@ -312,15 +236,11 @@ fn frag_main(inputs : FragmentInput) -> void {
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct Locations {
|
||||
struct FragmentInput {
|
||||
value : f32;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
locations : Locations;
|
||||
};
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_5 : f32;
|
||||
[[location(1)]] var<in> tint_symbol_3 : f32;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
@@ -381,97 +301,6 @@ fn vert_main() -> void {
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_ReturnStruct_Nested) {
|
||||
auto* src = R"(
|
||||
struct Builtins {
|
||||
[[builtin(position)]] pos : vec4<f32>;
|
||||
};
|
||||
|
||||
struct Locations {
|
||||
[[location(2)]] l2 : f32;
|
||||
[[location(3)]] l3 : f32;
|
||||
};
|
||||
|
||||
struct Other {
|
||||
l : Locations;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
b : Builtins;
|
||||
o : Other;
|
||||
[[location(1)]] value : f32;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> VertexOutput {
|
||||
if (false) {
|
||||
return VertexOutput();
|
||||
}
|
||||
var output : VertexOutput = VertexOutput();
|
||||
output.b.pos = vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
||||
output.o.l.l2 = 4.0;
|
||||
output.o.l.l3 = 5.0;
|
||||
output.value = 6.0;
|
||||
return output;
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct Builtins {
|
||||
pos : vec4<f32>;
|
||||
};
|
||||
|
||||
struct Locations {
|
||||
l2 : f32;
|
||||
l3 : f32;
|
||||
};
|
||||
|
||||
struct Other {
|
||||
l : Locations;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
b : Builtins;
|
||||
o : Other;
|
||||
value : f32;
|
||||
};
|
||||
|
||||
[[builtin(position)]] var<out> tint_symbol_13 : vec4<f32>;
|
||||
|
||||
[[location(2)]] var<out> tint_symbol_14 : f32;
|
||||
|
||||
[[location(3)]] var<out> tint_symbol_15 : f32;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_16 : f32;
|
||||
|
||||
fn tint_symbol_17(tint_symbol_12 : VertexOutput) -> void {
|
||||
tint_symbol_13 = tint_symbol_12.b.pos;
|
||||
tint_symbol_14 = tint_symbol_12.o.l.l2;
|
||||
tint_symbol_15 = tint_symbol_12.o.l.l3;
|
||||
tint_symbol_16 = tint_symbol_12.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
if (false) {
|
||||
tint_symbol_17(VertexOutput());
|
||||
return;
|
||||
}
|
||||
var output : VertexOutput = VertexOutput();
|
||||
output.b.pos = vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
||||
output.o.l.l2 = 4.0;
|
||||
output.o.l.l3 = 5.0;
|
||||
output.value = 6.0;
|
||||
tint_symbol_17(output);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Spirv>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_SharedStruct_SameShader) {
|
||||
auto* src = R"(
|
||||
struct Interface {
|
||||
@@ -558,150 +387,6 @@ fn frag_main() -> void {
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_SharedSubStruct) {
|
||||
auto* src = R"(
|
||||
struct Interface {
|
||||
[[location(1)]] value : f32;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
[[builtin(position)]] pos : vec4<f32>;
|
||||
interface : Interface;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
[[builtin(sample_index)]] index : u32;
|
||||
interface : Interface;
|
||||
};
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> VertexOutput {
|
||||
return VertexOutput(vec4<f32>(), Interface(42.0));
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main(inputs : FragmentInput) -> void {
|
||||
var x : f32 = inputs.interface.value;
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
struct Interface {
|
||||
value : f32;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
pos : vec4<f32>;
|
||||
interface : Interface;
|
||||
};
|
||||
|
||||
struct FragmentInput {
|
||||
index : u32;
|
||||
interface : Interface;
|
||||
};
|
||||
|
||||
[[builtin(position)]] var<out> tint_symbol_9 : vec4<f32>;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_10 : f32;
|
||||
|
||||
fn tint_symbol_11(tint_symbol_8 : VertexOutput) -> void {
|
||||
tint_symbol_9 = tint_symbol_8.pos;
|
||||
tint_symbol_10 = tint_symbol_8.interface.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
tint_symbol_11(VertexOutput(vec4<f32>(), Interface(42.0)));
|
||||
return;
|
||||
}
|
||||
|
||||
[[builtin(sample_index)]] var<in> tint_symbol_13 : u32;
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_14 : f32;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn frag_main() -> void {
|
||||
const tint_symbol_15 : Interface = Interface(tint_symbol_14);
|
||||
const tint_symbol_16 : FragmentInput = FragmentInput(tint_symbol_13, tint_symbol_15);
|
||||
var x : f32 = tint_symbol_16.interface.value;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Spirv>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_NestedStruct_TypeAlias) {
|
||||
auto* src = R"(
|
||||
type myf32 = f32;
|
||||
|
||||
struct Location {
|
||||
[[location(2)]] l2 : myf32;
|
||||
};
|
||||
|
||||
type MyLocation = Location;
|
||||
|
||||
struct VertexIO {
|
||||
l : MyLocation;
|
||||
[[location(1)]] value : myf32;
|
||||
};
|
||||
|
||||
type MyVertexInput = VertexIO;
|
||||
|
||||
type MyVertexOutput = VertexIO;
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main(inputs : MyVertexInput) -> MyVertexOutput {
|
||||
return inputs;
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
type myf32 = f32;
|
||||
|
||||
struct Location {
|
||||
l2 : myf32;
|
||||
};
|
||||
|
||||
type MyLocation = Location;
|
||||
|
||||
struct VertexIO {
|
||||
l : MyLocation;
|
||||
value : myf32;
|
||||
};
|
||||
|
||||
type MyVertexInput = VertexIO;
|
||||
|
||||
type MyVertexOutput = VertexIO;
|
||||
|
||||
[[location(2)]] var<in> tint_symbol_8 : myf32;
|
||||
|
||||
[[location(1)]] var<in> tint_symbol_10 : myf32;
|
||||
|
||||
[[location(2)]] var<out> tint_symbol_14 : myf32;
|
||||
|
||||
[[location(1)]] var<out> tint_symbol_15 : myf32;
|
||||
|
||||
fn tint_symbol_17(tint_symbol_13 : MyVertexOutput) -> void {
|
||||
tint_symbol_14 = tint_symbol_13.l.l2;
|
||||
tint_symbol_15 = tint_symbol_13.value;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn vert_main() -> void {
|
||||
const tint_symbol_9 : MyLocation = MyLocation(tint_symbol_8);
|
||||
const tint_symbol_11 : MyVertexInput = MyVertexInput(tint_symbol_9, tint_symbol_10);
|
||||
tint_symbol_17(tint_symbol_11);
|
||||
return;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Spirv>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructLayoutDecorations) {
|
||||
auto* src = R"(
|
||||
[[block]]
|
||||
|
||||
Reference in New Issue
Block a user