mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 22:17:51 +00:00
Update builtin idx names.
This CL upldates the vertex_idx, instance_idx and global_invocation_idx builtins to use the full _index names. The original values still exist until we can update downstream users. Change-Id: Icd02601eeb15704d5463158541c07816d98e5383 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37940 Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: dan sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
4a110c2726
commit
d7335fa974
@@ -121,8 +121,8 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||
}
|
||||
};
|
||||
|
||||
// Clone the AST, renaming the kVertexIdx and kInstanceIdx builtins, and add
|
||||
// a CreateFirstIndexOffset() statement to each function that uses one of
|
||||
// Clone the AST, renaming the kVertexIndex and kInstanceIndex builtins, and
|
||||
// add a CreateFirstIndexOffset() statement to each function that uses one of
|
||||
// these builtins.
|
||||
|
||||
Output out;
|
||||
@@ -132,13 +132,13 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||
for (ast::VariableDecoration* dec : var->decorations()) {
|
||||
if (auto* blt_dec = dec->As<ast::BuiltinDecoration>()) {
|
||||
ast::Builtin blt_type = blt_dec->value();
|
||||
if (blt_type == ast::Builtin::kVertexIdx) {
|
||||
if (blt_type == ast::Builtin::kVertexIndex) {
|
||||
vertex_index_sym = var->symbol();
|
||||
has_vertex_index_ = true;
|
||||
return clone_variable_with_new_name(
|
||||
ctx, var,
|
||||
kIndexOffsetPrefix + in->SymbolToName(var->symbol()));
|
||||
} else if (blt_type == ast::Builtin::kInstanceIdx) {
|
||||
} else if (blt_type == ast::Builtin::kInstanceIndex) {
|
||||
instance_index_sym = var->symbol();
|
||||
has_instance_index_ = true;
|
||||
return clone_variable_with_new_name(
|
||||
@@ -160,11 +160,11 @@ Transform::Output FirstIndexOffset::Run(ast::Module* in) {
|
||||
ast::StatementList statements;
|
||||
for (const auto& data :
|
||||
func->local_referenced_builtin_variables()) {
|
||||
if (data.second->value() == ast::Builtin::kVertexIdx) {
|
||||
if (data.second->value() == ast::Builtin::kVertexIndex) {
|
||||
statements.emplace_back(CreateFirstIndexOffset(
|
||||
in->SymbolToName(vertex_index_sym), kFirstVertexName,
|
||||
buffer_var, ctx->mod));
|
||||
} else if (data.second->value() == ast::Builtin::kInstanceIdx) {
|
||||
} else if (data.second->value() == ast::Builtin::kInstanceIndex) {
|
||||
statements.emplace_back(CreateFirstIndexOffset(
|
||||
in->SymbolToName(instance_index_sym), kFirstInstanceName,
|
||||
buffer_var, ctx->mod));
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace tint {
|
||||
namespace transform {
|
||||
|
||||
/// Adds firstVertex/Instance (injected via root constants) to
|
||||
/// vertex/instance_idx builtins.
|
||||
/// vertex/instance index builtins.
|
||||
///
|
||||
/// This transform assumes that Name transform has been run before.
|
||||
///
|
||||
|
||||
@@ -28,7 +28,7 @@ using FirstIndexOffsetTest = TransformTest;
|
||||
|
||||
TEST_F(FirstIndexOffsetTest, Error_AlreadyTransformed) {
|
||||
auto* src = R"(
|
||||
[[builtin(vertex_idx)]] var<in> vert_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
||||
|
||||
fn test() -> u32 {
|
||||
return vert_idx;
|
||||
@@ -63,7 +63,7 @@ TEST_F(FirstIndexOffsetTest, EmptyModule) {
|
||||
|
||||
TEST_F(FirstIndexOffsetTest, BasicModuleVertexIndex) {
|
||||
auto* src = R"(
|
||||
[[builtin(vertex_idx)]] var<in> vert_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
||||
|
||||
fn test() -> u32 {
|
||||
return vert_idx;
|
||||
@@ -82,7 +82,7 @@ struct TintFirstIndexOffsetData {
|
||||
tint_first_vertex_index : u32;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[binding(1), group(2)]] var<uniform> tint_first_index_data : TintFirstIndexOffsetData;
|
||||
|
||||
fn test() -> u32 {
|
||||
@@ -103,7 +103,7 @@ fn entry() -> void {
|
||||
|
||||
TEST_F(FirstIndexOffsetTest, BasicModuleInstanceIndex) {
|
||||
auto* src = R"(
|
||||
[[builtin(instance_idx)]] var<in> inst_idx : u32;
|
||||
[[builtin(instance_index)]] var<in> inst_idx : u32;
|
||||
|
||||
fn test() -> u32 {
|
||||
return inst_idx;
|
||||
@@ -122,7 +122,7 @@ struct TintFirstIndexOffsetData {
|
||||
tint_first_instance_index : u32;
|
||||
};
|
||||
|
||||
[[builtin(instance_idx)]] var<in> tint_first_index_offset_inst_idx : u32;
|
||||
[[builtin(instance_index)]] var<in> tint_first_index_offset_inst_idx : u32;
|
||||
[[binding(1), group(7)]] var<uniform> tint_first_index_data : TintFirstIndexOffsetData;
|
||||
|
||||
fn test() -> u32 {
|
||||
@@ -143,8 +143,8 @@ fn entry() -> void {
|
||||
|
||||
TEST_F(FirstIndexOffsetTest, BasicModuleBothIndex) {
|
||||
auto* src = R"(
|
||||
[[builtin(instance_idx)]] var<in> instance_idx : u32;
|
||||
[[builtin(vertex_idx)]] var<in> vert_idx : u32;
|
||||
[[builtin(instance_index)]] var<in> instance_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
||||
|
||||
fn test() -> u32 {
|
||||
return instance_idx + vert_idx;
|
||||
@@ -165,8 +165,8 @@ struct TintFirstIndexOffsetData {
|
||||
tint_first_instance_index : u32;
|
||||
};
|
||||
|
||||
[[builtin(instance_idx)]] var<in> tint_first_index_offset_instance_idx : u32;
|
||||
[[builtin(vertex_idx)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[builtin(instance_index)]] var<in> tint_first_index_offset_instance_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[binding(1), group(2)]] var<uniform> tint_first_index_data : TintFirstIndexOffsetData;
|
||||
|
||||
fn test() -> u32 {
|
||||
@@ -188,7 +188,7 @@ fn entry() -> void {
|
||||
|
||||
TEST_F(FirstIndexOffsetTest, NestedCalls) {
|
||||
auto* src = R"(
|
||||
[[builtin(vertex_idx)]] var<in> vert_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> vert_idx : u32;
|
||||
|
||||
fn func1() -> u32 {
|
||||
return vert_idx;
|
||||
@@ -211,7 +211,7 @@ struct TintFirstIndexOffsetData {
|
||||
tint_first_vertex_index : u32;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[builtin(vertex_index)]] var<in> tint_first_index_offset_vert_idx : u32;
|
||||
[[binding(1), group(2)]] var<uniform> tint_first_index_data : TintFirstIndexOffsetData;
|
||||
|
||||
fn func1() -> u32 {
|
||||
|
||||
@@ -158,7 +158,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||
|
||||
for (auto* d : v->decorations()) {
|
||||
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
||||
if (builtin->value() == ast::Builtin::kVertexIdx) {
|
||||
if (builtin->value() == ast::Builtin::kVertexIndex) {
|
||||
vertex_index_name = in->SymbolToName(v->symbol());
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ void VertexPulling::State::FindOrInsertVertexIndexIfUsed() {
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kVertexIdx),
|
||||
ast::Builtin::kVertexIndex),
|
||||
});
|
||||
|
||||
out->AddGlobalVariable(var);
|
||||
@@ -205,7 +205,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||
|
||||
for (auto* d : v->decorations()) {
|
||||
if (auto* builtin = d->As<ast::BuiltinDecoration>()) {
|
||||
if (builtin->value() == ast::Builtin::kInstanceIdx) {
|
||||
if (builtin->value() == ast::Builtin::kInstanceIndex) {
|
||||
instance_index_name = in->SymbolToName(v->symbol());
|
||||
return;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ void VertexPulling::State::FindOrInsertInstanceIndexIfUsed() {
|
||||
ast::VariableDecorationList{
|
||||
// decorations
|
||||
out->create<ast::BuiltinDecoration>(Source{},
|
||||
ast::Builtin::kInstanceIdx),
|
||||
ast::Builtin::kInstanceIndex),
|
||||
});
|
||||
out->AddGlobalVariable(var);
|
||||
}
|
||||
|
||||
@@ -191,10 +191,10 @@ class VertexPulling : public Transform {
|
||||
/// @param index index to append to buffer name
|
||||
std::string GetVertexBufferName(uint32_t index) const;
|
||||
|
||||
/// Inserts vertex_idx binding, or finds the existing one
|
||||
/// Inserts vertex_index binding, or finds the existing one
|
||||
void FindOrInsertVertexIndexIfUsed();
|
||||
|
||||
/// Inserts instance_idx binding, or finds the existing one
|
||||
/// Inserts instance_index binding, or finds the existing one
|
||||
void FindOrInsertInstanceIndexIfUsed();
|
||||
|
||||
/// Converts var<in> with a location decoration to var<private>
|
||||
|
||||
@@ -133,7 +133,7 @@ struct TintVertexData {
|
||||
_tint_vertex_data : [[stride(4)]] array<u32>;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[binding(0), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
var<private> var_a : f32;
|
||||
|
||||
@@ -172,7 +172,7 @@ struct TintVertexData {
|
||||
_tint_vertex_data : [[stride(4)]] array<u32>;
|
||||
};
|
||||
|
||||
[[builtin(instance_idx)]] var<in> _tint_pulling_instance_index : i32;
|
||||
[[builtin(instance_index)]] var<in> _tint_pulling_instance_index : i32;
|
||||
[[binding(0), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
var<private> var_a : f32;
|
||||
|
||||
@@ -211,7 +211,7 @@ struct TintVertexData {
|
||||
_tint_vertex_data : [[stride(4)]] array<u32>;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[binding(0), group(5)]] var<storage_buffer> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
var<private> var_a : f32;
|
||||
|
||||
@@ -241,8 +241,8 @@ TEST_F(VertexPullingTest, ExistingVertexIndexAndInstanceIndex) {
|
||||
auto* src = R"(
|
||||
[[location(0)]] var<in> var_a : f32;
|
||||
[[location(1)]] var<in> var_b : f32;
|
||||
[[builtin(vertex_idx)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(instance_idx)]] var<in> custom_instance_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : i32;
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {}
|
||||
@@ -259,8 +259,8 @@ struct TintVertexData {
|
||||
[[binding(1), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_1 : TintVertexData;
|
||||
var<private> var_a : f32;
|
||||
var<private> var_b : f32;
|
||||
[[builtin(vertex_idx)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(instance_idx)]] var<in> custom_instance_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> custom_vertex_index : i32;
|
||||
[[builtin(instance_index)]] var<in> custom_instance_index : i32;
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn main() -> void {
|
||||
@@ -301,7 +301,7 @@ struct TintVertexData {
|
||||
_tint_vertex_data : [[stride(4)]] array<u32>;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[binding(0), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
var<private> var_a : f32;
|
||||
var<private> var_b : array<f32, 4>;
|
||||
@@ -347,7 +347,7 @@ struct TintVertexData {
|
||||
_tint_vertex_data : [[stride(4)]] array<u32>;
|
||||
};
|
||||
|
||||
[[builtin(vertex_idx)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[builtin(vertex_index)]] var<in> _tint_pulling_vertex_index : i32;
|
||||
[[binding(0), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_0 : TintVertexData;
|
||||
[[binding(1), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_1 : TintVertexData;
|
||||
[[binding(2), group(4)]] var<storage_buffer> _tint_pulling_vertex_buffer_2 : TintVertexData;
|
||||
|
||||
Reference in New Issue
Block a user