2021-02-16 21:44:13 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "src/transform/spirv.h"
|
|
|
|
|
|
|
|
#include "src/transform/test_helper.h"
|
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace transform {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using SpirvTest = TransformTest;
|
|
|
|
|
2021-03-11 15:57:21 +00:00
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_Parameters) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[stage(fragment)]]
|
2021-04-14 16:37:18 +00:00
|
|
|
fn frag_main([[builtin(position)]] coord : vec4<f32>,
|
2021-04-08 14:39:47 +00:00
|
|
|
[[location(1)]] loc1 : f32) {
|
2021-03-11 15:57:21 +00:00
|
|
|
var col : f32 = (coord.x * loc1);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(compute)]]
|
|
|
|
fn compute_main([[builtin(local_invocation_id)]] local_id : vec3<u32>,
|
2021-04-08 14:39:47 +00:00
|
|
|
[[builtin(local_invocation_index)]] local_index : u32) {
|
2021-03-11 15:57:21 +00:00
|
|
|
var id_x : u32 = local_id.x;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-14 16:37:18 +00:00
|
|
|
[[builtin(position)]] var<in> tint_symbol : vec4<f32>;
|
2021-03-11 15:57:21 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol_1 : f32;
|
2021-03-11 15:57:21 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
var col : f32 = (tint_symbol.x * tint_symbol_1);
|
2021-03-11 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[builtin(local_invocation_id)]] var<in> tint_symbol_2 : vec3<u32>;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[builtin(local_invocation_index)]] var<in> tint_symbol_3 : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-03-11 15:57:21 +00:00
|
|
|
[[stage(compute)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn compute_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
var id_x : u32 = tint_symbol_2.x;
|
2021-03-11 15:57:21 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-03-15 19:19:42 +00:00
|
|
|
auto got = Run<Spirv>(src);
|
2021-03-11 15:57:21 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-03-17 09:26:04 +00:00
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_Parameter_TypeAlias) {
|
|
|
|
auto* src = R"(
|
|
|
|
type myf32 = f32;
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main([[location(1)]] loc1 : myf32) {
|
2021-03-17 09:26:04 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
type myf32 = f32;
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol : myf32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-03-17 09:26:04 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-03-17 14:24:04 +00:00
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_ReturnBuiltin) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn vert_main() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
return vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-07 11:16:01 +00:00
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_2(tint_symbol : vec4<f32>) {
|
|
|
|
tint_symbol_1 = tint_symbol;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
2021-03-17 14:24:04 +00:00
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn vert_main() {
|
2021-04-07 11:16:01 +00:00
|
|
|
tint_symbol_2(vec4<f32>(1.0, 2.0, 3.0, 0.0));
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_ReturnLocation) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[stage(fragment)]]
|
|
|
|
fn frag_main([[location(0)]] loc_in : u32) -> [[location(0)]] f32 {
|
|
|
|
if (loc_in > 10u) {
|
|
|
|
return 0.5;
|
|
|
|
}
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(0)]] var<in> tint_symbol : u32;
|
2021-03-17 14:24:04 +00:00
|
|
|
|
2021-04-07 11:16:01 +00:00
|
|
|
[[location(0)]] var<out> tint_symbol_2 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_3(tint_symbol_1 : f32) {
|
|
|
|
tint_symbol_2 = tint_symbol_1;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
2021-03-17 14:24:04 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
if ((tint_symbol > 10u)) {
|
2021-04-07 11:16:01 +00:00
|
|
|
tint_symbol_3(0.5);
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-07 11:16:01 +00:00
|
|
|
tint_symbol_3(1.0);
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_ReturnLocation_TypeAlias) {
|
|
|
|
auto* src = R"(
|
|
|
|
type myf32 = f32;
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
|
|
|
fn frag_main([[location(0)]] loc_in : u32) -> [[location(0)]] myf32 {
|
|
|
|
if (loc_in > 10u) {
|
|
|
|
return 0.5;
|
|
|
|
}
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
type myf32 = f32;
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(0)]] var<in> tint_symbol : u32;
|
2021-03-17 14:24:04 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(0)]] var<out> tint_symbol_2 : myf32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_3(tint_symbol_1 : myf32) {
|
|
|
|
tint_symbol_2 = tint_symbol_1;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
2021-03-17 14:24:04 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
if ((tint_symbol > 10u)) {
|
|
|
|
tint_symbol_3(0.5);
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-13 20:07:57 +00:00
|
|
|
tint_symbol_3(1.0);
|
2021-03-24 17:08:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructParameters) {
|
|
|
|
auto* src = R"(
|
|
|
|
struct FragmentInput {
|
2021-04-14 16:37:18 +00:00
|
|
|
[[builtin(position)]] coord : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
[[location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main(inputs : FragmentInput) {
|
2021-03-24 17:08:06 +00:00
|
|
|
var col : f32 = inputs.coord.x * inputs.value;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
struct FragmentInput {
|
|
|
|
coord : vec4<f32>;
|
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-14 16:37:18 +00:00
|
|
|
[[builtin(position)]] var<in> tint_symbol : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol_1 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
let tint_symbol_2 : FragmentInput = FragmentInput(tint_symbol, tint_symbol_1);
|
|
|
|
var col : f32 = (tint_symbol_2.coord.x * tint_symbol_2.value);
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-04-06 15:51:47 +00:00
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructParameters_EmptyBody) {
|
2021-03-24 17:08:06 +00:00
|
|
|
auto* src = R"(
|
|
|
|
struct FragmentInput {
|
|
|
|
[[location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main(inputs : FragmentInput) {
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
struct FragmentInput {
|
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_ReturnStruct) {
|
|
|
|
auto* src = R"(
|
|
|
|
struct VertexOutput {
|
|
|
|
[[builtin(position)]] pos : vec4<f32>;
|
|
|
|
[[location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn vert_main() -> VertexOutput {
|
|
|
|
if (false) {
|
|
|
|
return VertexOutput();
|
|
|
|
}
|
|
|
|
var pos : vec4<f32> = vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
|
|
|
return VertexOutput(pos, 2.0);
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
struct VertexOutput {
|
|
|
|
pos : vec4<f32>;
|
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<out> tint_symbol_2 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_3(tint_symbol : VertexOutput) {
|
|
|
|
tint_symbol_1 = tint_symbol.pos;
|
|
|
|
tint_symbol_2 = tint_symbol.value;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn vert_main() {
|
2021-03-24 17:08:06 +00:00
|
|
|
if (false) {
|
2021-04-13 20:07:57 +00:00
|
|
|
tint_symbol_3(VertexOutput());
|
2021-03-24 17:08:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var pos : vec4<f32> = vec4<f32>(1.0, 2.0, 3.0, 0.0);
|
2021-04-13 20:07:57 +00:00
|
|
|
tint_symbol_3(VertexOutput(pos, 2.0));
|
2021-03-24 17:08:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_SharedStruct_SameShader) {
|
|
|
|
auto* src = R"(
|
|
|
|
struct Interface {
|
|
|
|
[[location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[stage(fragment)]]
|
|
|
|
fn frag_main(inputs : Interface) -> Interface {
|
2021-03-24 17:08:06 +00:00
|
|
|
return inputs;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
struct Interface {
|
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<out> tint_symbol_3 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_4(tint_symbol_2 : Interface) {
|
|
|
|
tint_symbol_3 = tint_symbol_2.value;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[stage(fragment)]]
|
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
let tint_symbol_1 : Interface = Interface(tint_symbol);
|
|
|
|
tint_symbol_4(tint_symbol_1);
|
2021-03-24 17:08:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_SharedStruct_DifferentShaders) {
|
|
|
|
auto* src = R"(
|
|
|
|
struct Interface {
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] pos : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
[[location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn vert_main() -> Interface {
|
2021-04-21 16:13:42 +00:00
|
|
|
return Interface(vec4<f32>(), 42.0);
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main(inputs : Interface) {
|
2021-03-24 17:08:06 +00:00
|
|
|
var x : f32 = inputs.value;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
struct Interface {
|
2021-04-21 16:13:42 +00:00
|
|
|
pos : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
|
|
|
|
|
|
|
[[location(1)]] var<out> tint_symbol_2 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
fn tint_symbol_3(tint_symbol : Interface) {
|
|
|
|
tint_symbol_1 = tint_symbol.pos;
|
|
|
|
tint_symbol_2 = tint_symbol.value;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn vert_main() {
|
2021-04-21 16:13:42 +00:00
|
|
|
tint_symbol_3(Interface(vec4<f32>(), 42.0));
|
2021-03-24 17:08:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<in> tint_symbol_4 : vec4<f32>;
|
|
|
|
|
|
|
|
[[location(1)]] var<in> tint_symbol_5 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-21 16:13:42 +00:00
|
|
|
let tint_symbol_6 : Interface = Interface(tint_symbol_4, tint_symbol_5);
|
|
|
|
var x : f32 = tint_symbol_6.value;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_StructLayoutDecorations) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[block]]
|
|
|
|
struct FragmentInput {
|
|
|
|
[[size(16), location(1)]] value : f32;
|
2021-04-14 16:37:18 +00:00
|
|
|
[[builtin(position)]] [[align(32)]] coord : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentOutput {
|
|
|
|
[[size(16), location(1)]] value : f32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
|
|
|
fn frag_main(inputs : FragmentInput) -> FragmentOutput {
|
|
|
|
return FragmentOutput(inputs.coord.x * inputs.value);
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
|
|
|
struct FragmentInput {
|
|
|
|
[[size(16)]]
|
|
|
|
value : f32;
|
|
|
|
[[align(32)]]
|
|
|
|
coord : vec4<f32>;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentOutput {
|
|
|
|
[[size(16)]]
|
|
|
|
value : f32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<in> tint_symbol : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-14 16:37:18 +00:00
|
|
|
[[builtin(position)]] var<in> tint_symbol_1 : vec4<f32>;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[location(1)]] var<out> tint_symbol_4 : f32;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_5(tint_symbol_3 : FragmentOutput) {
|
|
|
|
tint_symbol_4 = tint_symbol_3.value;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn frag_main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
let tint_symbol_2 : FragmentInput = FragmentInput(tint_symbol, tint_symbol_1);
|
|
|
|
tint_symbol_5(FragmentOutput((tint_symbol_2.coord.x * tint_symbol_2.value)));
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-04-06 17:31:27 +00:00
|
|
|
TEST_F(SpirvTest, HandleEntryPointIOTypes_WithPrivateGlobalVariable) {
|
|
|
|
// Test with a global variable to ensure that symbols are cloned correctly.
|
|
|
|
// crbug.com/tint/701
|
|
|
|
auto* src = R"(
|
|
|
|
var<private> x : f32;
|
|
|
|
|
|
|
|
struct VertexOutput {
|
|
|
|
[[builtin(position)]] Position : vec4<f32>;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main() -> VertexOutput {
|
|
|
|
return VertexOutput(vec4<f32>());
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
var<private> x : f32;
|
|
|
|
|
|
|
|
struct VertexOutput {
|
|
|
|
Position : vec4<f32>;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
2021-04-06 17:31:27 +00:00
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
fn tint_symbol_2(tint_symbol : VertexOutput) {
|
|
|
|
tint_symbol_1 = tint_symbol.Position;
|
2021-04-06 17:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn main() {
|
2021-04-13 20:07:57 +00:00
|
|
|
tint_symbol_2(VertexOutput(vec4<f32>()));
|
2021-04-06 17:31:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:44:13 +00:00
|
|
|
TEST_F(SpirvTest, HandleSampleMaskBuiltins_Basic) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[builtin(sample_index)]] var<in> sample_index : u32;
|
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<in> mask_in : u32;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<out> mask_out : u32;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn main() {
|
2021-02-16 21:44:13 +00:00
|
|
|
mask_out = mask_in;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[builtin(sample_index)]] var<in> sample_index : u32;
|
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<in> mask_in : array<u32, 1>;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<out> mask_out : array<u32, 1>;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn main() {
|
2021-02-16 21:44:13 +00:00
|
|
|
mask_out[0] = mask_in[0];
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-03-15 19:19:42 +00:00
|
|
|
auto got = Run<Spirv>(src);
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-02-16 21:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, HandleSampleMaskBuiltins_FunctionArg) {
|
|
|
|
auto* src = R"(
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<in> mask_in : u32;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<out> mask_out : u32;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
|
|
|
fn filter(mask: u32) -> u32 {
|
|
|
|
return (mask & 3u);
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn set_mask(input : u32) {
|
2021-02-16 21:44:13 +00:00
|
|
|
mask_out = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn main() {
|
2021-02-16 21:44:13 +00:00
|
|
|
set_mask(filter(mask_in));
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<in> mask_in : array<u32, 1>;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] var<out> mask_out : array<u32, 1>;
|
2021-02-16 21:44:13 +00:00
|
|
|
|
|
|
|
fn filter(mask : u32) -> u32 {
|
|
|
|
return (mask & 3u);
|
|
|
|
}
|
|
|
|
|
2021-04-08 14:39:47 +00:00
|
|
|
fn set_mask(input : u32) {
|
2021-02-16 21:44:13 +00:00
|
|
|
mask_out[0] = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(fragment)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn main() {
|
2021-02-16 21:44:13 +00:00
|
|
|
set_mask(filter(mask_in[0]));
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-03-15 19:19:42 +00:00
|
|
|
auto got = Run<Spirv>(src);
|
2021-02-16 21:44:13 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
2021-02-16 21:44:13 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 16:54:52 +00:00
|
|
|
TEST_F(SpirvTest, EmitVertexPointSize_Basic) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn non_entry_point() {
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
non_entry_point();
|
|
|
|
return vec4<f32>();
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[builtin(pointsize)]] var<out> tint_pointsize : f32;
|
|
|
|
|
|
|
|
fn non_entry_point() {
|
|
|
|
}
|
|
|
|
|
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
|
|
|
|
|
|
|
fn tint_symbol_2(tint_symbol : vec4<f32>) {
|
|
|
|
tint_symbol_1 = tint_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main() {
|
|
|
|
tint_pointsize = 1.0;
|
|
|
|
non_entry_point();
|
|
|
|
tint_symbol_2(vec4<f32>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap data;
|
|
|
|
data.Add<Spirv::Config>(true);
|
|
|
|
auto got = Run<Spirv>(src, data);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, EmitVertexPointSize_MultipleVertexShaders) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main1() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
return vec4<f32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main2() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
return vec4<f32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main3() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
return vec4<f32>();
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[builtin(pointsize)]] var<out> tint_pointsize : f32;
|
|
|
|
|
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
|
|
|
|
|
|
|
fn tint_symbol_2(tint_symbol : vec4<f32>) {
|
|
|
|
tint_symbol_1 = tint_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main1() {
|
|
|
|
tint_pointsize = 1.0;
|
|
|
|
tint_symbol_2(vec4<f32>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[builtin(position)]] var<out> tint_symbol_4 : vec4<f32>;
|
|
|
|
|
|
|
|
fn tint_symbol_5(tint_symbol_3 : vec4<f32>) {
|
|
|
|
tint_symbol_4 = tint_symbol_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main2() {
|
|
|
|
tint_pointsize = 1.0;
|
|
|
|
tint_symbol_5(vec4<f32>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[builtin(position)]] var<out> tint_symbol_7 : vec4<f32>;
|
|
|
|
|
|
|
|
fn tint_symbol_8(tint_symbol_6 : vec4<f32>) {
|
|
|
|
tint_symbol_7 = tint_symbol_6;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn main3() {
|
|
|
|
tint_pointsize = 1.0;
|
|
|
|
tint_symbol_8(vec4<f32>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap data;
|
|
|
|
data.Add<Spirv::Config>(true);
|
|
|
|
auto got = Run<Spirv>(src, data);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SpirvTest, EmitVertexPointSize_NoVertexShaders) {
|
|
|
|
auto* src = R"(
|
|
|
|
[[stage(compute)]]
|
|
|
|
fn main() {
|
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap data;
|
|
|
|
data.Add<Spirv::Config>(true);
|
|
|
|
auto got = Run<Spirv>(src, data);
|
|
|
|
|
|
|
|
EXPECT_EQ(src, str(got));
|
|
|
|
}
|
|
|
|
|
2021-04-01 22:07:37 +00:00
|
|
|
TEST_F(SpirvTest, AddEmptyEntryPoint) {
|
|
|
|
auto* src = R"()";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[stage(compute)]]
|
2021-05-17 14:48:37 +00:00
|
|
|
fn unused_entry_point() {
|
2021-04-01 22:07:37 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto got = Run<Spirv>(src);
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-03-11 15:57:21 +00:00
|
|
|
// Test that different transforms within the sanitizer interact correctly.
|
|
|
|
TEST_F(SpirvTest, MultipleTransforms) {
|
|
|
|
auto* src = R"(
|
2021-05-05 16:54:52 +00:00
|
|
|
[[stage(vertex)]]
|
|
|
|
fn vert_main() -> [[builtin(position)]] vec4<f32> {
|
|
|
|
return vec4<f32>();
|
|
|
|
}
|
|
|
|
|
2021-03-11 15:57:21 +00:00
|
|
|
[[stage(fragment)]]
|
2021-05-05 16:54:52 +00:00
|
|
|
fn frag_main([[builtin(sample_index)]] sample_index : u32,
|
2021-04-14 16:44:38 +00:00
|
|
|
[[builtin(sample_mask)]] mask_in : u32)
|
|
|
|
-> [[builtin(sample_mask)]] u32 {
|
2021-03-17 14:24:04 +00:00
|
|
|
return mask_in;
|
2021-03-11 15:57:21 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
2021-05-05 16:54:52 +00:00
|
|
|
[[builtin(pointsize)]] var<out> tint_pointsize : f32;
|
|
|
|
|
|
|
|
[[builtin(position)]] var<out> tint_symbol_1 : vec4<f32>;
|
|
|
|
|
|
|
|
fn tint_symbol_2(tint_symbol : vec4<f32>) {
|
|
|
|
tint_symbol_1 = tint_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
|
|
|
fn vert_main() {
|
|
|
|
tint_pointsize = 1.0;
|
|
|
|
tint_symbol_2(vec4<f32>());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[builtin(sample_index)]] var<in> tint_symbol_3 : u32;
|
2021-03-11 15:57:21 +00:00
|
|
|
|
2021-05-05 16:54:52 +00:00
|
|
|
[[builtin(sample_mask)]] var<in> tint_symbol_4 : array<u32, 1>;
|
2021-03-11 15:57:21 +00:00
|
|
|
|
2021-05-05 16:54:52 +00:00
|
|
|
[[builtin(sample_mask)]] var<out> tint_symbol_6 : array<u32, 1>;
|
2021-03-24 17:08:06 +00:00
|
|
|
|
2021-05-05 16:54:52 +00:00
|
|
|
fn tint_symbol_7(tint_symbol_5 : u32) {
|
|
|
|
tint_symbol_6[0] = tint_symbol_5;
|
2021-03-24 17:08:06 +00:00
|
|
|
}
|
2021-03-17 14:24:04 +00:00
|
|
|
|
2021-03-11 15:57:21 +00:00
|
|
|
[[stage(fragment)]]
|
2021-05-05 16:54:52 +00:00
|
|
|
fn frag_main() {
|
|
|
|
tint_symbol_7(tint_symbol_4[0]);
|
2021-03-17 14:24:04 +00:00
|
|
|
return;
|
2021-03-11 15:57:21 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-05-05 16:54:52 +00:00
|
|
|
DataMap data;
|
|
|
|
data.Add<Spirv::Config>(true);
|
|
|
|
auto got = Run<Spirv>(src, data);
|
2021-03-11 15:57:21 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:44:13 +00:00
|
|
|
} // namespace
|
|
|
|
} // namespace transform
|
|
|
|
} // namespace tint
|