2020-12-08 21:07:24 +00:00
|
|
|
// Copyright 2020 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/first_index_offset.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2021-01-06 12:57:41 +00:00
|
|
|
#include <vector>
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
#include "src/transform/test_helper.h"
|
2020-12-08 21:07:24 +00:00
|
|
|
|
|
|
|
namespace tint {
|
|
|
|
namespace transform {
|
|
|
|
namespace {
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
using FirstIndexOffsetTest = TransformTest;
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, EmptyModule) {
|
|
|
|
auto* src = "";
|
|
|
|
auto* expect = "";
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(0, 0);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, false);
|
|
|
|
EXPECT_EQ(data->has_instance_index, false);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn test(vert_idx : u32) -> u32 {
|
2021-01-06 12:57:41 +00:00
|
|
|
return vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
test(vert_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-04-09 16:19:48 +00:00
|
|
|
|
|
|
|
fn test(vert_idx : u32) -> u32 {
|
|
|
|
return vert_idx;
|
|
|
|
}
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
test((vert_idx + tint_symbol_1.first_vertex_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(1, 2);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, false);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn test(inst_idx : u32) -> u32 {
|
|
|
|
return inst_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
test(inst_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_instance_index : u32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(7)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-04-09 16:19:48 +00:00
|
|
|
|
|
|
|
fn test(inst_idx : u32) -> u32 {
|
|
|
|
return inst_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
test((inst_idx + tint_symbol_1.first_instance_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(1, 7);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, false);
|
2021-04-09 16:19:48 +00:00
|
|
|
EXPECT_EQ(data->has_instance_index, true);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FirstIndexOffsetTest, BasicModuleBothIndex) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn test(instance_idx : u32, vert_idx : u32) -> u32 {
|
|
|
|
return instance_idx + vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Inputs {
|
|
|
|
[[builtin(instance_index)]] instance_idx : u32;
|
|
|
|
[[builtin(vertex_index)]] vert_idx : u32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry(inputs : Inputs) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
test(inputs.instance_idx, inputs.vert_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
|
|
|
first_instance_index : u32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-04-09 16:19:48 +00:00
|
|
|
|
|
|
|
fn test(instance_idx : u32, vert_idx : u32) -> u32 {
|
|
|
|
return (instance_idx + vert_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Inputs {
|
|
|
|
[[builtin(instance_index)]]
|
|
|
|
instance_idx : u32;
|
|
|
|
[[builtin(vertex_index)]]
|
|
|
|
vert_idx : u32;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry(inputs : Inputs) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
test((inputs.instance_idx + tint_symbol_1.first_instance_index), (inputs.vert_idx + tint_symbol_1.first_vertex_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(1, 2);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, true);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
|
|
|
EXPECT_EQ(data->first_instance_offset, 4u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FirstIndexOffsetTest, NestedCalls) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn func1(vert_idx : u32) -> u32 {
|
|
|
|
return vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func2(vert_idx : u32) -> u32 {
|
|
|
|
return func1(vert_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
func2(vert_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-04-09 16:19:48 +00:00
|
|
|
|
|
|
|
fn func1(vert_idx : u32) -> u32 {
|
|
|
|
return vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func2(vert_idx : u32) -> u32 {
|
|
|
|
return func1(vert_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
func2((vert_idx + tint_symbol_1.first_vertex_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(1, 2);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(data->has_instance_index, false);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, MultipleEntryPoints) {
|
|
|
|
auto* src = R"(
|
|
|
|
fn func(i : u32) -> u32 {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_a([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
func(vert_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_b([[builtin(vertex_index)]] vert_idx : u32, [[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
func(vert_idx + inst_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_c([[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-09 16:19:48 +00:00
|
|
|
func(inst_idx);
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
|
|
|
first_instance_index : u32;
|
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-04-09 16:19:48 +00:00
|
|
|
|
|
|
|
fn func(i : u32) -> u32 {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_a([[builtin(vertex_index)]] vert_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
func((vert_idx + tint_symbol_1.first_vertex_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_b([[builtin(vertex_index)]] vert_idx : u32, [[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
func(((vert_idx + tint_symbol_1.first_vertex_index) + (inst_idx + tint_symbol_1.first_instance_index)));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-21 16:13:42 +00:00
|
|
|
fn entry_c([[builtin(instance_index)]] inst_idx : u32) -> [[builtin(position)]] vec4<f32> {
|
2021-04-13 20:07:57 +00:00
|
|
|
func((inst_idx + tint_symbol_1.first_instance_index));
|
2021-04-21 16:13:42 +00:00
|
|
|
return vec4<f32>();
|
2021-04-09 16:19:48 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
DataMap config;
|
|
|
|
config.Add<FirstIndexOffset::BindingPoint>(1, 2);
|
|
|
|
auto got = Run<FirstIndexOffset>(src, std::move(config));
|
|
|
|
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, true);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
|
|
|
EXPECT_EQ(data->first_instance_offset, 4u);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(FirstIndexOffsetTest, OLD_BasicModuleVertexIndex) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-01-18 15:51:13 +00:00
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn test() -> u32 {
|
|
|
|
return vert_idx;
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
2021-01-06 12:57:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn test() -> u32 {
|
2021-04-13 20:07:57 +00:00
|
|
|
return (vert_idx + tint_symbol_1.first_vertex_index);
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
2020-12-10 17:47:41 +00:00
|
|
|
)";
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-03-29 21:03:59 +00:00
|
|
|
auto got = Run(src, std::make_unique<FirstIndexOffset>(1, 2));
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, false);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, OLD_BasicModuleInstanceIndex) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-01-18 15:51:13 +00:00
|
|
|
[[builtin(instance_index)]] var<in> inst_idx : u32;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn test() -> u32 {
|
|
|
|
return inst_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_instance_index : u32;
|
2021-01-06 12:57:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(7)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[builtin(instance_index)]] var<in> inst_idx : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn test() -> u32 {
|
2021-04-13 20:07:57 +00:00
|
|
|
return (inst_idx + tint_symbol_1.first_instance_index);
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
2020-12-10 17:47:41 +00:00
|
|
|
)";
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-03-29 21:03:59 +00:00
|
|
|
auto got = Run(src, std::make_unique<FirstIndexOffset>(1, 7));
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, false);
|
|
|
|
EXPECT_EQ(data->has_instance_index, true);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, OLD_BasicModuleBothIndex) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-01-18 15:51:13 +00:00
|
|
|
[[builtin(instance_index)]] var<in> instance_idx : u32;
|
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
|
|
|
fn test() -> u32 {
|
|
|
|
return instance_idx + vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
2020-12-10 17:47:41 +00:00
|
|
|
)";
|
2020-12-08 21:07:24 +00:00
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
|
|
|
first_instance_index : u32;
|
2021-01-06 12:57:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[builtin(instance_index)]] var<in> instance_idx : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn test() -> u32 {
|
2021-04-13 20:07:57 +00:00
|
|
|
return ((instance_idx + tint_symbol_1.first_instance_index) + (vert_idx + tint_symbol_1.first_vertex_index));
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
test();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-03-29 21:03:59 +00:00
|
|
|
auto got = Run(src, std::make_unique<FirstIndexOffset>(1, 2));
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, true);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 4u);
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
TEST_F(FirstIndexOffsetTest, OLD_NestedCalls) {
|
2021-01-06 12:57:41 +00:00
|
|
|
auto* src = R"(
|
2021-01-18 15:51:13 +00:00
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
2021-01-06 12:57:41 +00:00
|
|
|
|
|
|
|
fn func1() -> u32 {
|
|
|
|
return vert_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func2() -> u32 {
|
|
|
|
return func1();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
func2();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
2020-12-10 17:47:41 +00:00
|
|
|
)";
|
2021-01-06 12:57:41 +00:00
|
|
|
|
|
|
|
auto* expect = R"(
|
|
|
|
[[block]]
|
2021-04-13 20:07:57 +00:00
|
|
|
struct tint_symbol {
|
2021-04-09 16:19:48 +00:00
|
|
|
first_vertex_index : u32;
|
2021-01-06 12:57:41 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 20:07:57 +00:00
|
|
|
[[binding(1), group(2)]] var<uniform> tint_symbol_1 : tint_symbol;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-09 16:19:48 +00:00
|
|
|
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
2021-03-17 09:26:04 +00:00
|
|
|
|
2021-04-21 16:13:42 +00:00
|
|
|
[[builtin(position)]] var<out> pos : vec4<f32>;
|
|
|
|
|
2021-01-06 12:57:41 +00:00
|
|
|
fn func1() -> u32 {
|
2021-04-13 20:07:57 +00:00
|
|
|
return (vert_idx + tint_symbol_1.first_vertex_index);
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn func2() -> u32 {
|
|
|
|
return func1();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[stage(vertex)]]
|
2021-04-08 14:39:47 +00:00
|
|
|
fn entry() {
|
2021-01-06 12:57:41 +00:00
|
|
|
func2();
|
2021-04-21 16:13:42 +00:00
|
|
|
pos = vec4<f32>();
|
2021-01-06 12:57:41 +00:00
|
|
|
}
|
|
|
|
)";
|
|
|
|
|
2021-03-29 21:03:59 +00:00
|
|
|
auto got = Run(src, std::make_unique<FirstIndexOffset>(1, 2));
|
2021-01-06 12:57:41 +00:00
|
|
|
|
2021-02-24 15:55:24 +00:00
|
|
|
EXPECT_EQ(expect, str(got));
|
|
|
|
|
|
|
|
auto* data = got.data.Get<FirstIndexOffset::Data>();
|
|
|
|
|
|
|
|
ASSERT_NE(data, nullptr);
|
|
|
|
EXPECT_EQ(data->has_vertex_index, true);
|
|
|
|
EXPECT_EQ(data->has_instance_index, false);
|
|
|
|
EXPECT_EQ(data->first_vertex_offset, 0u);
|
2021-02-25 14:11:50 +00:00
|
|
|
EXPECT_EQ(data->first_instance_offset, 0u);
|
2020-12-08 21:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace transform
|
|
|
|
} // namespace tint
|