Move BuiltinValue to builtin/
This CL moves the BuiltinValue enum to the builtin/ folder. Change-Id: I9db5128c1bc272e8e8d5181d629e6724ac38322e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120361 Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
32cb509307
commit
6392579ee1
|
@ -431,6 +431,7 @@ libtint_source_set("libtint_transform_src") {
|
|||
deps = [
|
||||
":libtint_ast_src",
|
||||
":libtint_base_src",
|
||||
":libtint_builtins_src",
|
||||
":libtint_program_src",
|
||||
":libtint_sem_src",
|
||||
":libtint_text_src",
|
||||
|
@ -452,7 +453,6 @@ libtint_source_set("libtint_ast_hdrs") {
|
|||
"ast/break_if_statement.h",
|
||||
"ast/break_statement.h",
|
||||
"ast/builtin_attribute.h",
|
||||
"ast/builtin_value.h",
|
||||
"ast/call_expression.h",
|
||||
"ast/call_statement.h",
|
||||
"ast/case_selector.h",
|
||||
|
@ -519,6 +519,7 @@ libtint_source_set("libtint_ast_hdrs") {
|
|||
]
|
||||
deps = [
|
||||
":libtint_base_src",
|
||||
":libtint_builtins_src",
|
||||
":libtint_clone_context_hdrs",
|
||||
":libtint_type_src",
|
||||
]
|
||||
|
@ -538,7 +539,6 @@ libtint_source_set("libtint_ast_src") {
|
|||
"ast/break_if_statement.cc",
|
||||
"ast/break_statement.cc",
|
||||
"ast/builtin_attribute.cc",
|
||||
"ast/builtin_value.cc",
|
||||
"ast/call_expression.cc",
|
||||
"ast/call_statement.cc",
|
||||
"ast/case_selector.cc",
|
||||
|
@ -690,6 +690,13 @@ libtint_source_set("libtint_sem_src") {
|
|||
]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_builtins_src") {
|
||||
sources = [
|
||||
"builtin/builtin_value.cc",
|
||||
"builtin/builtin_value.h",
|
||||
]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_type_src") {
|
||||
sources = [
|
||||
"type/abstract_float.cc",
|
||||
|
@ -826,6 +833,7 @@ libtint_source_set("libtint_spv_reader_src") {
|
|||
deps = [
|
||||
":libtint_ast_src",
|
||||
":libtint_base_src",
|
||||
":libtint_builtins_src",
|
||||
":libtint_program_src",
|
||||
":libtint_reader_src",
|
||||
":libtint_sem_src",
|
||||
|
@ -1212,7 +1220,6 @@ if (tint_build_unittests) {
|
|||
"ast/builtin_attribute_test.cc",
|
||||
"ast/builtin_texture_helper_test.cc",
|
||||
"ast/builtin_texture_helper_test.h",
|
||||
"ast/builtin_value_test.cc",
|
||||
"ast/call_expression_test.cc",
|
||||
"ast/call_statement_test.cc",
|
||||
"ast/case_selector_test.cc",
|
||||
|
@ -1274,6 +1281,11 @@ if (tint_build_unittests) {
|
|||
}
|
||||
}
|
||||
|
||||
tint_unittests_source_set("tint_unittests_builtins_src") {
|
||||
sources = [ "builtin/builtin_value_test.cc" ]
|
||||
deps = [ ":libtint_builtins_src" ]
|
||||
}
|
||||
|
||||
tint_unittests_source_set("tint_unittests_diagnostic_src") {
|
||||
sources = [
|
||||
"diagnostic/diagnostic_test.cc",
|
||||
|
@ -1614,6 +1626,7 @@ if (tint_build_unittests) {
|
|||
|
||||
deps = [
|
||||
":libtint_base_src",
|
||||
":libtint_builtins_src",
|
||||
":libtint_spv_writer_src",
|
||||
":tint_unittests_ast_src",
|
||||
"${tint_spirv_tools_dir}/:spvtools",
|
||||
|
@ -1931,6 +1944,7 @@ if (tint_build_unittests) {
|
|||
":libtint_wgsl_writer_src",
|
||||
":tint_unittests_ast_src",
|
||||
":tint_unittests_base_src",
|
||||
":tint_unittests_builtins_src",
|
||||
":tint_unittests_constant_src",
|
||||
":tint_unittests_core_src",
|
||||
":tint_unittests_demangler_src",
|
||||
|
|
|
@ -548,7 +548,7 @@ list(APPEND TINT_LIB_SRCS
|
|||
writer/writer.h
|
||||
)
|
||||
|
||||
tint_generated(ast/builtin_value BENCH TEST)
|
||||
tint_generated(builtin/builtin_value BENCH TEST)
|
||||
tint_generated(ast/diagnostic_control BENCH TEST)
|
||||
tint_generated(ast/extension BENCH TEST)
|
||||
tint_generated(ast/interpolate_attribute BENCH TEST)
|
||||
|
|
|
@ -22,7 +22,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinAttribute);
|
|||
|
||||
namespace tint::ast {
|
||||
|
||||
BuiltinAttribute::BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, BuiltinValue b)
|
||||
BuiltinAttribute::BuiltinAttribute(ProgramID pid,
|
||||
NodeID nid,
|
||||
const Source& src,
|
||||
builtin::BuiltinValue b)
|
||||
: Base(pid, nid, src), builtin(b) {}
|
||||
|
||||
BuiltinAttribute::~BuiltinAttribute() = default;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
namespace tint::ast {
|
||||
|
||||
|
@ -30,7 +30,7 @@ class BuiltinAttribute final : public Castable<BuiltinAttribute, Attribute> {
|
|||
/// @param nid the unique node identifier
|
||||
/// @param src the source of this node
|
||||
/// @param builtin the builtin value
|
||||
BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, BuiltinValue builtin);
|
||||
BuiltinAttribute(ProgramID pid, NodeID nid, const Source& src, builtin::BuiltinValue builtin);
|
||||
~BuiltinAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
|
@ -43,7 +43,7 @@ class BuiltinAttribute final : public Castable<BuiltinAttribute, Attribute> {
|
|||
const BuiltinAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The builtin value
|
||||
const BuiltinValue builtin;
|
||||
const builtin::BuiltinValue builtin;
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
|
|
|
@ -20,8 +20,8 @@ namespace {
|
|||
using BuiltinAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(BuiltinAttributeTest, Creation) {
|
||||
auto* d = create<BuiltinAttribute>(BuiltinValue::kFragDepth);
|
||||
EXPECT_EQ(BuiltinValue::kFragDepth, d->builtin);
|
||||
auto* d = create<BuiltinAttribute>(builtin::BuiltinValue::kFragDepth);
|
||||
EXPECT_EQ(builtin::BuiltinValue::kFragDepth, d->builtin);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -93,7 +93,7 @@ TEST_F(VariableTest, Assert_DifferentProgramID_Initializer) {
|
|||
|
||||
TEST_F(VariableTest, WithAttributes) {
|
||||
auto* var = Var("my_var", ty.i32(), type::AddressSpace::kFunction, Location(1_u),
|
||||
Builtin(BuiltinValue::kPosition), Id(1200_u));
|
||||
Builtin(builtin::BuiltinValue::kPosition), Id(1200_u));
|
||||
|
||||
auto& attributes = var->attributes;
|
||||
EXPECT_TRUE(ast::HasAttribute<ast::LocationAttribute>(attributes));
|
||||
|
|
|
@ -15,14 +15,14 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// File generated by tools/src/cmd/gen
|
||||
// using the template:
|
||||
// src/tint/ast/builtin_value.cc.tmpl
|
||||
// src/tint/builtin/builtin_value.cc.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
|
||||
/// ParseBuiltinValue parses a BuiltinValue from a string.
|
||||
/// @param str the string to parse
|
||||
|
@ -101,4 +101,4 @@ std::ostream& operator<<(std::ostream& out, BuiltinValue value) {
|
|||
return out << "<unknown>";
|
||||
}
|
||||
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -11,12 +11,12 @@ See:
|
|||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "builtin_value") -}}
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
|
||||
{{ Eval "ParseEnum" $enum}}
|
||||
|
||||
{{ Eval "EnumOStream" $enum}}
|
||||
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -15,17 +15,17 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// File generated by tools/src/cmd/gen
|
||||
// using the template:
|
||||
// src/tint/ast/builtin_value.h.tmpl
|
||||
// src/tint/builtin/builtin_value.h.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#define SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#ifndef SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
||||
#define SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
|
||||
/// Builtin value defined with `@builtin(<name>)`.
|
||||
enum class BuiltinValue {
|
||||
|
@ -64,6 +64,6 @@ constexpr const char* kBuiltinValueStrings[] = {
|
|||
"vertex_index", "workgroup_id",
|
||||
};
|
||||
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
||||
|
||||
#endif // SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#endif // SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
|
@ -11,16 +11,16 @@ See:
|
|||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "builtin_value") -}}
|
||||
|
||||
#ifndef SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#define SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#ifndef SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
||||
#define SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
|
||||
/// Builtin value defined with `@builtin(<name>)`.
|
||||
{{ Eval "DeclareEnum" $enum}}
|
||||
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
||||
|
||||
#endif // SRC_TINT_AST_BUILTIN_VALUE_H_
|
||||
#endif // SRC_TINT_BUILTIN_BUILTIN_VALUE_H_
|
|
@ -15,18 +15,18 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// File generated by tools/src/cmd/gen
|
||||
// using the template:
|
||||
// src/tint/ast/builtin_value_bench.cc.tmpl
|
||||
// src/tint/builtin/builtin_value_bench.cc.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
namespace {
|
||||
|
||||
void BuiltinValueParser(::benchmark::State& state) {
|
||||
|
@ -127,4 +127,4 @@ void BuiltinValueParser(::benchmark::State& state) {
|
|||
BENCHMARK(BuiltinValueParser);
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -11,16 +11,16 @@ See:
|
|||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "builtin_value") -}}
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
namespace {
|
||||
|
||||
{{ Eval "BenchmarkParseEnum" $enum }}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -15,19 +15,20 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// File generated by tools/src/cmd/gen
|
||||
// using the template:
|
||||
// src/tint/ast/builtin_value_test.cc.tmpl
|
||||
// src/tint/builtin/builtin_value_test.cc.tmpl
|
||||
//
|
||||
// Do not modify this file directly
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
#include "src/tint/utils/string.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
namespace {
|
||||
|
||||
namespace parse_print_tests {
|
||||
|
@ -119,4 +120,4 @@ INSTANTIATE_TEST_SUITE_P(ValidCases, BuiltinValuePrintTest, testing::ValuesIn(kV
|
|||
} // namespace parse_print_tests
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -11,17 +11,18 @@ See:
|
|||
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
|
||||
{{- $enum := (Sem.Enum "builtin_value") -}}
|
||||
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
#include "src/tint/utils/string.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace tint::builtin {
|
||||
namespace {
|
||||
|
||||
{{ Eval "TestParsePrintEnum" $enum}}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::ast
|
||||
} // namespace tint::builtin
|
|
@ -216,15 +216,15 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) {
|
|||
param->Location(), entry_point.input_variables);
|
||||
|
||||
entry_point.input_position_used |= ContainsBuiltin(
|
||||
ast::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes);
|
||||
builtin::BuiltinValue::kPosition, param->Type(), param->Declaration()->attributes);
|
||||
entry_point.front_facing_used |= ContainsBuiltin(
|
||||
ast::BuiltinValue::kFrontFacing, param->Type(), param->Declaration()->attributes);
|
||||
builtin::BuiltinValue::kFrontFacing, param->Type(), param->Declaration()->attributes);
|
||||
entry_point.sample_index_used |= ContainsBuiltin(
|
||||
ast::BuiltinValue::kSampleIndex, param->Type(), param->Declaration()->attributes);
|
||||
builtin::BuiltinValue::kSampleIndex, param->Type(), param->Declaration()->attributes);
|
||||
entry_point.input_sample_mask_used |= ContainsBuiltin(
|
||||
ast::BuiltinValue::kSampleMask, param->Type(), param->Declaration()->attributes);
|
||||
builtin::BuiltinValue::kSampleMask, param->Type(), param->Declaration()->attributes);
|
||||
entry_point.num_workgroups_used |= ContainsBuiltin(
|
||||
ast::BuiltinValue::kNumWorkgroups, param->Type(), param->Declaration()->attributes);
|
||||
builtin::BuiltinValue::kNumWorkgroups, param->Type(), param->Declaration()->attributes);
|
||||
}
|
||||
|
||||
if (!sem->ReturnType()->Is<type::Void>()) {
|
||||
|
@ -232,9 +232,9 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) {
|
|||
sem->ReturnLocation(), entry_point.output_variables);
|
||||
|
||||
entry_point.output_sample_mask_used = ContainsBuiltin(
|
||||
ast::BuiltinValue::kSampleMask, sem->ReturnType(), func->return_type_attributes);
|
||||
builtin::BuiltinValue::kSampleMask, sem->ReturnType(), func->return_type_attributes);
|
||||
entry_point.frag_depth_used = ContainsBuiltin(
|
||||
ast::BuiltinValue::kFragDepth, sem->ReturnType(), func->return_type_attributes);
|
||||
builtin::BuiltinValue::kFragDepth, sem->ReturnType(), func->return_type_attributes);
|
||||
}
|
||||
|
||||
for (auto* var : sem->TransitivelyReferencedGlobals()) {
|
||||
|
@ -681,7 +681,7 @@ void Inspector::AddEntryPointInOutVariables(std::string name,
|
|||
variables.push_back(stage_variable);
|
||||
}
|
||||
|
||||
bool Inspector::ContainsBuiltin(ast::BuiltinValue builtin,
|
||||
bool Inspector::ContainsBuiltin(builtin::BuiltinValue builtin,
|
||||
const type::Type* type,
|
||||
utils::VectorRef<const ast::Attribute*> attributes) const {
|
||||
auto* unwrapped_type = type->UnwrapRef();
|
||||
|
|
|
@ -183,7 +183,7 @@ class Inspector {
|
|||
/// Recursively determine if the type contains builtin.
|
||||
/// If `type` is a struct, recurse into members to check for the attribute.
|
||||
/// Otherwise, check `attributes` for the attribute.
|
||||
bool ContainsBuiltin(ast::BuiltinValue builtin,
|
||||
bool ContainsBuiltin(builtin::BuiltinValue builtin,
|
||||
const type::Type* type,
|
||||
utils::VectorRef<const ast::Attribute*> attributes) const;
|
||||
|
||||
|
|
|
@ -464,7 +464,7 @@ TEST_F(InspectorGetEntryPointTest, MultipleEntryPointsInOutVariables) {
|
|||
TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
|
||||
auto* in_var0 = Param("in_var0", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
});
|
||||
auto* in_var1 = Param("in_var1", ty.f32(),
|
||||
utils::Vector{
|
||||
|
@ -478,7 +478,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltInsNotStageVariables) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
Inspector& inspector = Build();
|
||||
|
||||
|
@ -1049,7 +1049,7 @@ TEST_F(InspectorGetEntryPointTest, BuiltinNotReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) {
|
||||
auto* in_var = Param("in_var", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleMask),
|
||||
Builtin(builtin::BuiltinValue::kSampleMask),
|
||||
});
|
||||
Func("ep_func", utils::Vector{in_var}, ty.void_(),
|
||||
utils::Vector{
|
||||
|
@ -1069,7 +1069,8 @@ TEST_F(InspectorGetEntryPointTest, InputSampleMaskSimpleReferenced) {
|
|||
|
||||
TEST_F(InspectorGetEntryPointTest, InputSampleMaskStructReferenced) {
|
||||
utils::Vector members{
|
||||
Member("inner_position", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}),
|
||||
Member("inner_position", ty.u32(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}),
|
||||
};
|
||||
|
||||
Structure("in_struct", members);
|
||||
|
@ -1097,7 +1098,7 @@ TEST_F(InspectorGetEntryPointTest, InputSampleMaskStructReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) {
|
||||
Func("ep_func",
|
||||
utils::Vector{
|
||||
Param("in_var", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}),
|
||||
Param("in_var", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}),
|
||||
},
|
||||
ty.u32(),
|
||||
utils::Vector{
|
||||
|
@ -1107,7 +1108,7 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleMask),
|
||||
Builtin(builtin::BuiltinValue::kSampleMask),
|
||||
});
|
||||
|
||||
Inspector& inspector = Build();
|
||||
|
@ -1121,7 +1122,7 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskSimpleReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, OutputSampleMaskStructReferenced) {
|
||||
Structure("out_struct", utils::Vector{
|
||||
Member("inner_sample_mask", ty.u32(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kSampleMask)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kSampleMask)}),
|
||||
});
|
||||
|
||||
Func("ep_func", utils::Empty, ty("out_struct"),
|
||||
|
@ -1144,7 +1145,8 @@ TEST_F(InspectorGetEntryPointTest, OutputSampleMaskStructReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, InputPositionSimpleReferenced) {
|
||||
Func("ep_func",
|
||||
utils::Vector{
|
||||
Param("in_var", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Param("in_var", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
},
|
||||
ty.void_(),
|
||||
utils::Vector{
|
||||
|
@ -1165,7 +1167,7 @@ TEST_F(InspectorGetEntryPointTest, InputPositionSimpleReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, InputPositionStructReferenced) {
|
||||
Structure("in_struct", utils::Vector{
|
||||
Member("inner_position", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
});
|
||||
|
||||
Func("ep_func",
|
||||
|
@ -1191,7 +1193,8 @@ TEST_F(InspectorGetEntryPointTest, InputPositionStructReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, FrontFacingSimpleReferenced) {
|
||||
Func("ep_func",
|
||||
utils::Vector{
|
||||
Param("in_var", ty.bool_(), utils::Vector{Builtin(ast::BuiltinValue::kFrontFacing)}),
|
||||
Param("in_var", ty.bool_(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kFrontFacing)}),
|
||||
},
|
||||
ty.void_(),
|
||||
utils::Vector{
|
||||
|
@ -1212,7 +1215,7 @@ TEST_F(InspectorGetEntryPointTest, FrontFacingSimpleReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, FrontFacingStructReferenced) {
|
||||
Structure("in_struct", utils::Vector{
|
||||
Member("inner_position", ty.bool_(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kFrontFacing)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kFrontFacing)}),
|
||||
});
|
||||
|
||||
Func("ep_func",
|
||||
|
@ -1238,7 +1241,7 @@ TEST_F(InspectorGetEntryPointTest, FrontFacingStructReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, SampleIndexSimpleReferenced) {
|
||||
Func("ep_func",
|
||||
utils::Vector{
|
||||
Param("in_var", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}),
|
||||
Param("in_var", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}),
|
||||
},
|
||||
ty.void_(),
|
||||
utils::Vector{
|
||||
|
@ -1259,7 +1262,7 @@ TEST_F(InspectorGetEntryPointTest, SampleIndexSimpleReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, SampleIndexStructReferenced) {
|
||||
Structure("in_struct", utils::Vector{
|
||||
Member("inner_position", ty.u32(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
|
||||
Func("ep_func",
|
||||
|
@ -1286,7 +1289,7 @@ TEST_F(InspectorGetEntryPointTest, NumWorkgroupsSimpleReferenced) {
|
|||
Func("ep_func",
|
||||
utils::Vector{
|
||||
Param("in_var", ty.vec3<u32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kNumWorkgroups)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kNumWorkgroups)}),
|
||||
},
|
||||
ty.void_(),
|
||||
utils::Vector{
|
||||
|
@ -1303,10 +1306,11 @@ TEST_F(InspectorGetEntryPointTest, NumWorkgroupsSimpleReferenced) {
|
|||
}
|
||||
|
||||
TEST_F(InspectorGetEntryPointTest, NumWorkgroupsStructReferenced) {
|
||||
Structure("in_struct", utils::Vector{
|
||||
Member("inner_position", ty.vec3<u32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kNumWorkgroups)}),
|
||||
});
|
||||
Structure("in_struct",
|
||||
utils::Vector{
|
||||
Member("inner_position", ty.vec3<u32>(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kNumWorkgroups)}),
|
||||
});
|
||||
|
||||
Func("ep_func",
|
||||
utils::Vector{
|
||||
|
@ -1335,7 +1339,7 @@ TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
Inspector& inspector = Build();
|
||||
|
@ -1349,7 +1353,7 @@ TEST_F(InspectorGetEntryPointTest, FragDepthSimpleReferenced) {
|
|||
TEST_F(InspectorGetEntryPointTest, FragDepthStructReferenced) {
|
||||
Structure("out_struct", utils::Vector{
|
||||
Member("inner_frag_depth", ty.f32(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
|
||||
Func("ep_func", utils::Empty, ty("out_struct"),
|
||||
|
|
|
@ -3436,14 +3436,14 @@ class ProgramBuilder {
|
|||
/// @param source the source information
|
||||
/// @param builtin the builtin value
|
||||
/// @returns the builtin attribute pointer
|
||||
const ast::BuiltinAttribute* Builtin(const Source& source, ast::BuiltinValue builtin) {
|
||||
const ast::BuiltinAttribute* Builtin(const Source& source, builtin::BuiltinValue builtin) {
|
||||
return create<ast::BuiltinAttribute>(source, builtin);
|
||||
}
|
||||
|
||||
/// Creates an ast::BuiltinAttribute
|
||||
/// @param builtin the builtin value
|
||||
/// @returns the builtin attribute pointer
|
||||
const ast::BuiltinAttribute* Builtin(ast::BuiltinValue builtin) {
|
||||
const ast::BuiltinAttribute* Builtin(builtin::BuiltinValue builtin) {
|
||||
return create<ast::BuiltinAttribute>(source_, builtin);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,40 +64,40 @@ type::AddressSpace EnumConverter::ToAddressSpace(const spv::StorageClass sc) {
|
|||
return type::AddressSpace::kUndefined;
|
||||
}
|
||||
|
||||
ast::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) {
|
||||
builtin::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) {
|
||||
switch (b) {
|
||||
case spv::BuiltIn::Position:
|
||||
return ast::BuiltinValue::kPosition;
|
||||
return builtin::BuiltinValue::kPosition;
|
||||
case spv::BuiltIn::VertexIndex:
|
||||
return ast::BuiltinValue::kVertexIndex;
|
||||
return builtin::BuiltinValue::kVertexIndex;
|
||||
case spv::BuiltIn::InstanceIndex:
|
||||
return ast::BuiltinValue::kInstanceIndex;
|
||||
return builtin::BuiltinValue::kInstanceIndex;
|
||||
case spv::BuiltIn::FrontFacing:
|
||||
return ast::BuiltinValue::kFrontFacing;
|
||||
return builtin::BuiltinValue::kFrontFacing;
|
||||
case spv::BuiltIn::FragCoord:
|
||||
return ast::BuiltinValue::kPosition;
|
||||
return builtin::BuiltinValue::kPosition;
|
||||
case spv::BuiltIn::FragDepth:
|
||||
return ast::BuiltinValue::kFragDepth;
|
||||
return builtin::BuiltinValue::kFragDepth;
|
||||
case spv::BuiltIn::LocalInvocationId:
|
||||
return ast::BuiltinValue::kLocalInvocationId;
|
||||
return builtin::BuiltinValue::kLocalInvocationId;
|
||||
case spv::BuiltIn::LocalInvocationIndex:
|
||||
return ast::BuiltinValue::kLocalInvocationIndex;
|
||||
return builtin::BuiltinValue::kLocalInvocationIndex;
|
||||
case spv::BuiltIn::GlobalInvocationId:
|
||||
return ast::BuiltinValue::kGlobalInvocationId;
|
||||
return builtin::BuiltinValue::kGlobalInvocationId;
|
||||
case spv::BuiltIn::NumWorkgroups:
|
||||
return ast::BuiltinValue::kNumWorkgroups;
|
||||
return builtin::BuiltinValue::kNumWorkgroups;
|
||||
case spv::BuiltIn::WorkgroupId:
|
||||
return ast::BuiltinValue::kWorkgroupId;
|
||||
return builtin::BuiltinValue::kWorkgroupId;
|
||||
case spv::BuiltIn::SampleId:
|
||||
return ast::BuiltinValue::kSampleIndex;
|
||||
return builtin::BuiltinValue::kSampleIndex;
|
||||
case spv::BuiltIn::SampleMask:
|
||||
return ast::BuiltinValue::kSampleMask;
|
||||
return builtin::BuiltinValue::kSampleMask;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Fail() << "unknown SPIR-V builtin: " << uint32_t(b);
|
||||
return ast::BuiltinValue::kUndefined;
|
||||
return builtin::BuiltinValue::kUndefined;
|
||||
}
|
||||
|
||||
type::TextureDimension EnumConverter::ToDim(spv::Dim dim, bool arrayed) {
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
#include "spirv/unified1/spirv.h"
|
||||
#include "spirv/unified1/spirv.hpp11"
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/ast/pipeline_stage.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
#include "src/tint/reader/spirv/fail_stream.h"
|
||||
#include "src/tint/type/address_space.h"
|
||||
#include "src/tint/type/storage_texture.h"
|
||||
|
@ -51,7 +51,7 @@ class EnumConverter {
|
|||
/// On failure, logs an error and returns kNone
|
||||
/// @param b the SPIR-V builtin
|
||||
/// @returns a Tint AST builtin
|
||||
ast::BuiltinValue ToBuiltin(spv::BuiltIn b);
|
||||
builtin::BuiltinValue ToBuiltin(spv::BuiltIn b);
|
||||
|
||||
/// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension.
|
||||
/// On failure, logs an error and returns kNone
|
||||
|
|
|
@ -145,7 +145,7 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
|
|||
struct BuiltinCase {
|
||||
spv::BuiltIn builtin;
|
||||
bool expect_success;
|
||||
ast::BuiltinValue expected;
|
||||
builtin::BuiltinValue expected;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, BuiltinCase bc) {
|
||||
out << "BuiltinCase{ spv::BuiltIn::" << int(bc.builtin)
|
||||
|
@ -185,32 +185,35 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
EnumConverterGood_Input,
|
||||
SpvBuiltinTest,
|
||||
testing::Values(
|
||||
BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::InstanceIndex, true, ast::BuiltinValue::kInstanceIndex},
|
||||
BuiltinCase{spv::BuiltIn::FrontFacing, true, ast::BuiltinValue::kFrontFacing},
|
||||
BuiltinCase{spv::BuiltIn::FragCoord, true, ast::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::LocalInvocationId, true, ast::BuiltinValue::kLocalInvocationId},
|
||||
BuiltinCase{spv::BuiltIn::Position, true, builtin::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::InstanceIndex, true, builtin::BuiltinValue::kInstanceIndex},
|
||||
BuiltinCase{spv::BuiltIn::FrontFacing, true, builtin::BuiltinValue::kFrontFacing},
|
||||
BuiltinCase{spv::BuiltIn::FragCoord, true, builtin::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::LocalInvocationId, true,
|
||||
builtin::BuiltinValue::kLocalInvocationId},
|
||||
BuiltinCase{spv::BuiltIn::LocalInvocationIndex, true,
|
||||
ast::BuiltinValue::kLocalInvocationIndex},
|
||||
BuiltinCase{spv::BuiltIn::GlobalInvocationId, true, ast::BuiltinValue::kGlobalInvocationId},
|
||||
BuiltinCase{spv::BuiltIn::NumWorkgroups, true, ast::BuiltinValue::kNumWorkgroups},
|
||||
BuiltinCase{spv::BuiltIn::WorkgroupId, true, ast::BuiltinValue::kWorkgroupId},
|
||||
BuiltinCase{spv::BuiltIn::SampleId, true, ast::BuiltinValue::kSampleIndex},
|
||||
BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask}));
|
||||
builtin::BuiltinValue::kLocalInvocationIndex},
|
||||
BuiltinCase{spv::BuiltIn::GlobalInvocationId, true,
|
||||
builtin::BuiltinValue::kGlobalInvocationId},
|
||||
BuiltinCase{spv::BuiltIn::NumWorkgroups, true, builtin::BuiltinValue::kNumWorkgroups},
|
||||
BuiltinCase{spv::BuiltIn::WorkgroupId, true, builtin::BuiltinValue::kWorkgroupId},
|
||||
BuiltinCase{spv::BuiltIn::SampleId, true, builtin::BuiltinValue::kSampleIndex},
|
||||
BuiltinCase{spv::BuiltIn::SampleMask, true, builtin::BuiltinValue::kSampleMask}));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
EnumConverterGood_Output,
|
||||
SpvBuiltinTest,
|
||||
testing::Values(BuiltinCase{spv::BuiltIn::Position, true, ast::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::FragDepth, true, ast::BuiltinValue::kFragDepth},
|
||||
BuiltinCase{spv::BuiltIn::SampleMask, true, ast::BuiltinValue::kSampleMask}));
|
||||
testing::Values(BuiltinCase{spv::BuiltIn::Position, true, builtin::BuiltinValue::kPosition},
|
||||
BuiltinCase{spv::BuiltIn::FragDepth, true, builtin::BuiltinValue::kFragDepth},
|
||||
BuiltinCase{spv::BuiltIn::SampleMask, true,
|
||||
builtin::BuiltinValue::kSampleMask}));
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(EnumConverterBad,
|
||||
SpvBuiltinTest,
|
||||
testing::Values(BuiltinCase{static_cast<spv::BuiltIn>(9999), false,
|
||||
ast::BuiltinValue::kUndefined},
|
||||
builtin::BuiltinValue::kUndefined},
|
||||
BuiltinCase{static_cast<spv::BuiltIn>(9999), false,
|
||||
ast::BuiltinValue::kUndefined}));
|
||||
builtin::BuiltinValue::kUndefined}));
|
||||
|
||||
// Dim
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "src/tint/ast/bitcast_expression.h"
|
||||
#include "src/tint/ast/break_statement.h"
|
||||
#include "src/tint/ast/builtin_attribute.h"
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/ast/call_statement.h"
|
||||
#include "src/tint/ast/continue_statement.h"
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
|
@ -32,6 +31,7 @@
|
|||
#include "src/tint/ast/switch_statement.h"
|
||||
#include "src/tint/ast/unary_op_expression.h"
|
||||
#include "src/tint/ast/variable_decl_statement.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
#include "src/tint/sem/builtin_type.h"
|
||||
#include "src/tint/transform/spirv_atomic.h"
|
||||
#include "src/tint/type/depth_texture.h"
|
||||
|
@ -760,7 +760,7 @@ struct LoopStatementBuilder final : public Castable<LoopStatementBuilder, Statem
|
|||
/// @returns true if the decorations include a SampleMask builtin
|
||||
bool HasBuiltinSampleMask(utils::VectorRef<const ast::Attribute*> decos) {
|
||||
if (auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(decos)) {
|
||||
return builtin->builtin == ast::BuiltinValue::kSampleMask;
|
||||
return builtin->builtin == builtin::BuiltinValue::kSampleMask;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1331,7 +1331,7 @@ bool FunctionEmitter::EmitEntryPointAsWrapper() {
|
|||
// a gl_Position variable. Substitute the type.
|
||||
const Type* param_type = ty_.Vector(ty_.F32(), 4);
|
||||
AttributeList out_decos{
|
||||
create<ast::BuiltinAttribute>(source, ast::BuiltinValue::kPosition)};
|
||||
create<ast::BuiltinAttribute>(source, builtin::BuiltinValue::kPosition)};
|
||||
|
||||
const auto var_name = namer_.GetName(var_id);
|
||||
return_members.Push(
|
||||
|
|
|
@ -1699,7 +1699,7 @@ bool ParserImpl::ConvertDecorationsForVariable(uint32_t id,
|
|||
break;
|
||||
}
|
||||
auto ast_builtin = enum_converter_.ToBuiltin(spv_builtin);
|
||||
if (ast_builtin == ast::BuiltinValue::kUndefined) {
|
||||
if (ast_builtin == builtin::BuiltinValue::kUndefined) {
|
||||
// A diagnostic has already been emitted.
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1648,8 +1648,8 @@ Expect<ast::InterpolationType> ParserImpl::expect_interpolation_type_name() {
|
|||
// | sample_mask
|
||||
// | vertex_index
|
||||
// | workgroup_id
|
||||
Expect<ast::BuiltinValue> ParserImpl::expect_builtin() {
|
||||
return expect_enum("builtin", ast::ParseBuiltinValue, ast::kBuiltinValueStrings);
|
||||
Expect<builtin::BuiltinValue> ParserImpl::expect_builtin() {
|
||||
return expect_enum("builtin", builtin::ParseBuiltinValue, builtin::kBuiltinValueStrings);
|
||||
}
|
||||
|
||||
// compound_statement
|
||||
|
|
|
@ -540,7 +540,7 @@ class ParserImpl {
|
|||
/// Parses a builtin identifier, erroring if the next token does not match a
|
||||
/// valid builtin name.
|
||||
/// @returns the parsed builtin.
|
||||
Expect<ast::BuiltinValue> expect_builtin();
|
||||
Expect<builtin::BuiltinValue> expect_builtin();
|
||||
/// Parses a `compound_statement` grammar element, erroring on parse failure.
|
||||
/// @param use a description of what was being parsed if an error was raised
|
||||
/// @returns the parsed statements
|
||||
|
|
|
@ -102,7 +102,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) {
|
|||
auto attrs_0 = e.value[0]->attributes;
|
||||
ASSERT_EQ(attrs_0.Length(), 1u);
|
||||
EXPECT_TRUE(attrs_0[0]->Is<ast::BuiltinAttribute>());
|
||||
EXPECT_EQ(attrs_0[0]->As<ast::BuiltinAttribute>()->builtin, ast::BuiltinValue::kPosition);
|
||||
EXPECT_EQ(attrs_0[0]->As<ast::BuiltinAttribute>()->builtin, builtin::BuiltinValue::kPosition);
|
||||
|
||||
ASSERT_EQ(e.value[0]->source.range.begin.line, 1u);
|
||||
ASSERT_EQ(e.value[0]->source.range.begin.column, 20u);
|
||||
|
|
|
@ -38,7 +38,7 @@ TEST_F(ParserImplTest, AttributeList_Parses) {
|
|||
EXPECT_EQ(exp->value, 4u);
|
||||
|
||||
ASSERT_TRUE(attr_1->Is<ast::BuiltinAttribute>());
|
||||
EXPECT_EQ(attr_1->As<ast::BuiltinAttribute>()->builtin, ast::BuiltinValue::kPosition);
|
||||
EXPECT_EQ(attr_1->As<ast::BuiltinAttribute>()->builtin, builtin::BuiltinValue::kPosition);
|
||||
}
|
||||
|
||||
TEST_F(ParserImplTest, AttributeList_Invalid) {
|
||||
|
|
|
@ -217,7 +217,7 @@ TEST_F(ParserImplTest, Attribute_Location_MissingInvalid) {
|
|||
|
||||
struct BuiltinData {
|
||||
const char* input;
|
||||
ast::BuiltinValue result;
|
||||
builtin::BuiltinValue result;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, BuiltinData data) {
|
||||
out << std::string(data.input);
|
||||
|
@ -261,18 +261,19 @@ TEST_P(BuiltinTest, Attribute_Builtin_TrailingComma) {
|
|||
INSTANTIATE_TEST_SUITE_P(
|
||||
ParserImplTest,
|
||||
BuiltinTest,
|
||||
testing::Values(BuiltinData{"position", ast::BuiltinValue::kPosition},
|
||||
BuiltinData{"vertex_index", ast::BuiltinValue::kVertexIndex},
|
||||
BuiltinData{"instance_index", ast::BuiltinValue::kInstanceIndex},
|
||||
BuiltinData{"front_facing", ast::BuiltinValue::kFrontFacing},
|
||||
BuiltinData{"frag_depth", ast::BuiltinValue::kFragDepth},
|
||||
BuiltinData{"local_invocation_id", ast::BuiltinValue::kLocalInvocationId},
|
||||
BuiltinData{"local_invocation_index", ast::BuiltinValue::kLocalInvocationIndex},
|
||||
BuiltinData{"global_invocation_id", ast::BuiltinValue::kGlobalInvocationId},
|
||||
BuiltinData{"workgroup_id", ast::BuiltinValue::kWorkgroupId},
|
||||
BuiltinData{"num_workgroups", ast::BuiltinValue::kNumWorkgroups},
|
||||
BuiltinData{"sample_index", ast::BuiltinValue::kSampleIndex},
|
||||
BuiltinData{"sample_mask", ast::BuiltinValue::kSampleMask}));
|
||||
testing::Values(BuiltinData{"position", builtin::BuiltinValue::kPosition},
|
||||
BuiltinData{"vertex_index", builtin::BuiltinValue::kVertexIndex},
|
||||
BuiltinData{"instance_index", builtin::BuiltinValue::kInstanceIndex},
|
||||
BuiltinData{"front_facing", builtin::BuiltinValue::kFrontFacing},
|
||||
BuiltinData{"frag_depth", builtin::BuiltinValue::kFragDepth},
|
||||
BuiltinData{"local_invocation_id", builtin::BuiltinValue::kLocalInvocationId},
|
||||
BuiltinData{"local_invocation_index",
|
||||
builtin::BuiltinValue::kLocalInvocationIndex},
|
||||
BuiltinData{"global_invocation_id", builtin::BuiltinValue::kGlobalInvocationId},
|
||||
BuiltinData{"workgroup_id", builtin::BuiltinValue::kWorkgroupId},
|
||||
BuiltinData{"num_workgroups", builtin::BuiltinValue::kNumWorkgroups},
|
||||
BuiltinData{"sample_index", builtin::BuiltinValue::kSampleIndex},
|
||||
BuiltinData{"sample_mask", builtin::BuiltinValue::kSampleMask}));
|
||||
|
||||
TEST_F(ParserImplTest, Attribute_Builtin_MissingLeftParen) {
|
||||
auto p = parser("builtin position)");
|
||||
|
|
|
@ -95,7 +95,7 @@ static utils::Vector<const ast::Attribute*, 2> createAttributes(const Source& so
|
|||
case AttributeKind::kBinding:
|
||||
return {builder.Binding(source, 1_a)};
|
||||
case AttributeKind::kBuiltin:
|
||||
return {builder.Builtin(source, ast::BuiltinValue::kPosition)};
|
||||
return {builder.Builtin(source, builtin::BuiltinValue::kPosition)};
|
||||
case AttributeKind::kDiagnostic:
|
||||
return {builder.DiagnosticAttribute(source, ast::DiagnosticSeverity::kInfo,
|
||||
"chromium_unreachable_code")};
|
||||
|
@ -257,7 +257,7 @@ TEST_P(FragmentShaderParameterAttributeTest, IsValid) {
|
|||
auto& params = GetParam();
|
||||
auto attrs = createAttributes(Source{{12, 34}}, *this, params.kind);
|
||||
if (params.kind != AttributeKind::kBuiltin && params.kind != AttributeKind::kLocation) {
|
||||
attrs.Push(Builtin(Source{{34, 56}}, ast::BuiltinValue::kPosition));
|
||||
attrs.Push(Builtin(Source{{34, 56}}, builtin::BuiltinValue::kPosition));
|
||||
}
|
||||
auto* p = Param("a", ty.vec4<f32>(), attrs);
|
||||
Func("frag_main", utils::Vector{p}, ty.void_(), utils::Empty,
|
||||
|
@ -306,7 +306,7 @@ TEST_P(VertexShaderParameterAttributeTest, IsValid) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
if (params.should_pass) {
|
||||
|
@ -453,7 +453,7 @@ TEST_P(VertexShaderReturnTypeAttributeTest, IsValid) {
|
|||
auto attrs = createAttributes(Source{{12, 34}}, *this, params.kind);
|
||||
// a vertex shader must include the 'position' builtin in its return type
|
||||
if (params.kind != AttributeKind::kBuiltin) {
|
||||
attrs.Push(Builtin(Source{{34, 56}}, ast::BuiltinValue::kPosition));
|
||||
attrs.Push(Builtin(Source{{34, 56}}, builtin::BuiltinValue::kPosition));
|
||||
}
|
||||
Func("vertex_main", utils::Empty, ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
|
@ -654,7 +654,7 @@ TEST_F(StructMemberAttributeTest, InvariantAttributeWithPosition) {
|
|||
Member("a", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Invariant(),
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
}),
|
||||
});
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -1374,7 +1374,7 @@ TEST_F(InvariantAttributeTests, InvariantWithPosition) {
|
|||
auto* param = Param("p", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Invariant(Source{{12, 34}}),
|
||||
Builtin(Source{{56, 78}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{56, 78}}, builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
Func("main", utils::Vector{param}, ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
|
@ -1619,7 +1619,7 @@ TEST_F(InterpolateTest, VertexOutput_Integer_MissingFlatInterpolation) {
|
|||
auto* s = Structure(
|
||||
"S",
|
||||
utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
Member(Source{{12, 34}}, "u", ty.u32(), utils::Vector{Location(0_a)}),
|
||||
});
|
||||
Func("main", utils::Empty, ty.Of(s),
|
||||
|
@ -1642,7 +1642,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_Parameter) {
|
|||
utils::Vector{
|
||||
Param("a", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||
ast::InterpolationSampling::kUndefined),
|
||||
}),
|
||||
|
@ -1666,7 +1666,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_ReturnType) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||
ast::InterpolationSampling::kUndefined),
|
||||
});
|
||||
|
|
|
@ -33,67 +33,79 @@ class ResolverBuiltinsValidationTest : public resolver::TestHelper, public testi
|
|||
namespace StageTest {
|
||||
struct Params {
|
||||
builder::ast_type_func_ptr type;
|
||||
ast::BuiltinValue builtin;
|
||||
builtin::BuiltinValue builtin;
|
||||
ast::PipelineStage stage;
|
||||
bool is_valid;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr Params ParamsFor(ast::BuiltinValue builtin, ast::PipelineStage stage, bool is_valid) {
|
||||
constexpr Params ParamsFor(builtin::BuiltinValue builtin, ast::PipelineStage stage, bool is_valid) {
|
||||
return Params{DataType<T>::AST, builtin, stage, is_valid};
|
||||
}
|
||||
static constexpr Params cases[] = {
|
||||
ParamsFor<vec4<f32>>(ast::BuiltinValue::kPosition, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec4<f32>>(ast::BuiltinValue::kPosition, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<vec4<f32>>(ast::BuiltinValue::kPosition, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<vec4<f32>>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec4<f32>>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<vec4<f32>>(builtin::BuiltinValue::kPosition, ast::PipelineStage::kCompute, false),
|
||||
|
||||
ParamsFor<u32>(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kVertex, true),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kVertexIndex, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kVertex, true),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kVertexIndex, ast::PipelineStage::kCompute, false),
|
||||
|
||||
ParamsFor<u32>(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kVertex, true),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kInstanceIndex, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kVertex, true),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kInstanceIndex, ast::PipelineStage::kCompute, false),
|
||||
|
||||
ParamsFor<bool>(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<bool>(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<bool>(ast::BuiltinValue::kFrontFacing, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<bool>(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<bool>(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<bool>(builtin::BuiltinValue::kFrontFacing, ast::PipelineStage::kCompute, false),
|
||||
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kLocalInvocationId,
|
||||
ast::PipelineStage::kFragment,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kLocalInvocationId, ast::PipelineStage::kCompute, true),
|
||||
|
||||
ParamsFor<u32>(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kLocalInvocationIndex, ast::PipelineStage::kCompute, true),
|
||||
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kGlobalInvocationId,
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kLocalInvocationId,
|
||||
ast::PipelineStage::kVertex,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kGlobalInvocationId,
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kLocalInvocationId,
|
||||
ast::PipelineStage::kFragment,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kGlobalInvocationId,
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kLocalInvocationId,
|
||||
ast::PipelineStage::kCompute,
|
||||
true),
|
||||
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kWorkgroupId, ast::PipelineStage::kCompute, true),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kLocalInvocationIndex,
|
||||
ast::PipelineStage::kVertex,
|
||||
false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kLocalInvocationIndex,
|
||||
ast::PipelineStage::kFragment,
|
||||
false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kLocalInvocationIndex,
|
||||
ast::PipelineStage::kCompute,
|
||||
true),
|
||||
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<vec3<u32>>(ast::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kCompute, true),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kGlobalInvocationId,
|
||||
ast::PipelineStage::kVertex,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kGlobalInvocationId,
|
||||
ast::PipelineStage::kFragment,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kGlobalInvocationId,
|
||||
ast::PipelineStage::kCompute,
|
||||
true),
|
||||
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleIndex, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kFragment, false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kWorkgroupId, ast::PipelineStage::kCompute, true),
|
||||
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<u32>(ast::BuiltinValue::kSampleMask, ast::PipelineStage::kCompute, false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kNumWorkgroups,
|
||||
ast::PipelineStage::kFragment,
|
||||
false),
|
||||
ParamsFor<vec3<u32>>(builtin::BuiltinValue::kNumWorkgroups, ast::PipelineStage::kCompute, true),
|
||||
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleIndex, ast::PipelineStage::kCompute, false),
|
||||
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kVertex, false),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kFragment, true),
|
||||
ParamsFor<u32>(builtin::BuiltinValue::kSampleMask, ast::PipelineStage::kCompute, false),
|
||||
};
|
||||
|
||||
using ResolverBuiltinsStageTest = ResolverTestWithParam<Params>;
|
||||
|
@ -108,7 +120,7 @@ TEST_P(ResolverBuiltinsStageTest, All_input) {
|
|||
Func("main", utils::Vector{input}, ty.vec4<f32>(), utils::Vector{Return(p)},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
break;
|
||||
case ast::PipelineStage::kFragment:
|
||||
|
@ -152,7 +164,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsInput_Fail) {
|
|||
utils::Vector{
|
||||
Param("fd", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth),
|
||||
}),
|
||||
},
|
||||
ty.f32(),
|
||||
|
@ -182,7 +194,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsInputStruct_Fail) {
|
|||
utils::Vector{
|
||||
Member("frag_depth", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth),
|
||||
}),
|
||||
});
|
||||
|
||||
|
@ -217,7 +229,7 @@ TEST_F(ResolverBuiltinsValidationTest, StructBuiltinInsideEntryPoint_Ignored) {
|
|||
Structure("S", utils::Vector{
|
||||
Member("idx", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kVertexIndex),
|
||||
Builtin(builtin::BuiltinValue::kVertexIndex),
|
||||
}),
|
||||
});
|
||||
|
||||
|
@ -241,7 +253,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionNotF32_Struct_Fail) {
|
|||
utils::Vector{
|
||||
Member("position", ty.vec4<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition),
|
||||
}),
|
||||
});
|
||||
Func("fragShader",
|
||||
|
@ -272,7 +284,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionNotF32_ReturnType_Fail) {
|
|||
},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -290,7 +302,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthNotF32_Struct_Fail) {
|
|||
utils::Vector{
|
||||
Member("frag_depth", ty.i32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth),
|
||||
}),
|
||||
});
|
||||
Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(),
|
||||
|
@ -315,13 +327,13 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskNotU32_Struct_Fail) {
|
|||
// @fragment
|
||||
// fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; }
|
||||
|
||||
auto* s = Structure("MyInputs",
|
||||
utils::Vector{
|
||||
Member("m", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask),
|
||||
}),
|
||||
});
|
||||
auto* s = Structure(
|
||||
"MyInputs", utils::Vector{
|
||||
Member("m", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask),
|
||||
}),
|
||||
});
|
||||
Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(),
|
||||
utils::Vector{
|
||||
Return(1_f),
|
||||
|
@ -345,7 +357,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskNotU32_ReturnType_Fail) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -361,7 +373,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleMaskIsNotU32_Fail) {
|
|||
utils::Vector{
|
||||
Param("arg", ty.bool_(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleMask),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleMask),
|
||||
}),
|
||||
},
|
||||
ty.f32(),
|
||||
|
@ -385,13 +397,13 @@ TEST_F(ResolverBuiltinsValidationTest, SampleIndexIsNotU32_Struct_Fail) {
|
|||
// @fragment
|
||||
// fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; }
|
||||
|
||||
auto* s = Structure("MyInputs",
|
||||
utils::Vector{
|
||||
Member("m", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleIndex),
|
||||
}),
|
||||
});
|
||||
auto* s = Structure(
|
||||
"MyInputs", utils::Vector{
|
||||
Member("m", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleIndex),
|
||||
}),
|
||||
});
|
||||
Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(),
|
||||
utils::Vector{
|
||||
Return(1_f),
|
||||
|
@ -416,7 +428,7 @@ TEST_F(ResolverBuiltinsValidationTest, SampleIndexIsNotU32_Fail) {
|
|||
utils::Vector{
|
||||
Param("arg", ty.bool_(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kSampleIndex),
|
||||
}),
|
||||
},
|
||||
ty.f32(),
|
||||
|
@ -442,7 +454,7 @@ TEST_F(ResolverBuiltinsValidationTest, PositionIsNotF32_Fail) {
|
|||
utils::Vector{
|
||||
Param("p", ty.vec3<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kPosition),
|
||||
}),
|
||||
},
|
||||
ty.f32(),
|
||||
|
@ -472,7 +484,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragDepthIsNotF32_Fail) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFragDepth),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(frag_depth) must be 'f32'");
|
||||
|
@ -486,18 +498,18 @@ TEST_F(ResolverBuiltinsValidationTest, VertexIndexIsNotU32_Fail) {
|
|||
// ) -> @builtin(kPosition) vec4<f32> { return vec4<f32>(); }
|
||||
auto* p = Param("p", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
auto* vi = Param("vi", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kVertexIndex),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kVertexIndex),
|
||||
});
|
||||
Func("main", utils::Vector{vi, p}, ty.vec4<f32>(), utils::Vector{Return(Expr("p"))},
|
||||
utils::Vector{
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(vertex_index) must be 'u32'");
|
||||
|
@ -511,18 +523,18 @@ TEST_F(ResolverBuiltinsValidationTest, InstanceIndexIsNotU32) {
|
|||
// ) -> @builtin(kPosition) vec4<f32> { return vec4<f32>(); }
|
||||
auto* p = Param("p", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
auto* ii = Param("ii", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kInstanceIndex),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kInstanceIndex),
|
||||
});
|
||||
Func("main", utils::Vector{ii, p}, ty.vec4<f32>(), utils::Vector{Return(Expr("p"))},
|
||||
utils::Vector{
|
||||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(), "12:34 error: store type of builtin(instance_index) must be 'u32'");
|
||||
|
@ -538,19 +550,19 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltin_Pass) {
|
|||
// ) -> @builtin(frag_depth) f32 { var fd: f32; return fd; }
|
||||
auto* p = Param("p", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
auto* ff = Param("ff", ty.bool_(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFrontFacing),
|
||||
Builtin(builtin::BuiltinValue::kFrontFacing),
|
||||
});
|
||||
auto* si = Param("si", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
});
|
||||
auto* sm = Param("sm", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleMask),
|
||||
Builtin(builtin::BuiltinValue::kSampleMask),
|
||||
});
|
||||
auto* var_fd = Var("fd", ty.f32());
|
||||
Func("fs_main", utils::Vector{p, ff, si, sm}, ty.f32(),
|
||||
|
@ -562,7 +574,7 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltin_Pass) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
}
|
||||
|
@ -575,12 +587,12 @@ TEST_F(ResolverBuiltinsValidationTest, VertexBuiltin_Pass) {
|
|||
// ) -> @builtin(position) vec4<f32> { var p :vec4<f32>; return p; }
|
||||
auto* vi = Param("vi", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kVertexIndex),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kVertexIndex),
|
||||
});
|
||||
|
||||
auto* ii = Param("ii", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kInstanceIndex),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kInstanceIndex),
|
||||
});
|
||||
auto* p = Var("p", ty.vec4<f32>());
|
||||
Func("main", utils::Vector{vi, ii}, ty.vec4<f32>(),
|
||||
|
@ -590,7 +602,7 @@ TEST_F(ResolverBuiltinsValidationTest, VertexBuiltin_Pass) {
|
|||
},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -608,23 +620,23 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_Pass) {
|
|||
|
||||
auto* li_id = Param("li_id", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kLocalInvocationId),
|
||||
Builtin(builtin::BuiltinValue::kLocalInvocationId),
|
||||
});
|
||||
auto* li_index = Param("li_index", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kLocalInvocationIndex),
|
||||
Builtin(builtin::BuiltinValue::kLocalInvocationIndex),
|
||||
});
|
||||
auto* gi = Param("gi", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kGlobalInvocationId),
|
||||
Builtin(builtin::BuiltinValue::kGlobalInvocationId),
|
||||
});
|
||||
auto* wi = Param("wi", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kWorkgroupId),
|
||||
Builtin(builtin::BuiltinValue::kWorkgroupId),
|
||||
});
|
||||
auto* nwgs = Param("nwgs", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kNumWorkgroups),
|
||||
Builtin(builtin::BuiltinValue::kNumWorkgroups),
|
||||
});
|
||||
|
||||
Func("main", utils::Vector{li_id, li_index, gi, wi, nwgs}, ty.void_(), utils::Empty,
|
||||
|
@ -637,7 +649,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_Pass) {
|
|||
TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_WorkGroupIdNotVec3U32) {
|
||||
auto* wi = Param("wi", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kWorkgroupId),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kWorkgroupId),
|
||||
});
|
||||
Func("main", utils::Vector{wi}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -652,7 +664,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_WorkGroupIdNotVec3U32) {
|
|||
TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_NumWorkgroupsNotVec3U32) {
|
||||
auto* nwgs = Param("nwgs", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kNumWorkgroups),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kNumWorkgroups),
|
||||
});
|
||||
Func("main", utils::Vector{nwgs}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -667,7 +679,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_NumWorkgroupsNotVec3U32) {
|
|||
TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_GlobalInvocationNotVec3U32) {
|
||||
auto* gi = Param("gi", ty.vec3<i32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kGlobalInvocationId),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kGlobalInvocationId),
|
||||
});
|
||||
Func("main", utils::Vector{gi}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -680,10 +692,11 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_GlobalInvocationNotVec3U32
|
|||
}
|
||||
|
||||
TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationIndexNotU32) {
|
||||
auto* li_index = Param("li_index", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kLocalInvocationIndex),
|
||||
});
|
||||
auto* li_index =
|
||||
Param("li_index", ty.vec3<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kLocalInvocationIndex),
|
||||
});
|
||||
Func("main", utils::Vector{li_index}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute),
|
||||
WorkgroupSize(Expr(Source{Source::Location{12, 34}}, 2_i))});
|
||||
|
@ -697,7 +710,7 @@ TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationIndexNotU32
|
|||
TEST_F(ResolverBuiltinsValidationTest, ComputeBuiltin_LocalInvocationNotVec3U32) {
|
||||
auto* li_id = Param("li_id", ty.vec2<u32>(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kLocalInvocationId),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kLocalInvocationId),
|
||||
});
|
||||
Func("main", utils::Vector{li_id}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute),
|
||||
|
@ -722,19 +735,19 @@ TEST_F(ResolverBuiltinsValidationTest, FragmentBuiltinStruct_Pass) {
|
|||
auto* s = Structure("MyInputs", utils::Vector{
|
||||
Member("position", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
}),
|
||||
Member("front_facing", ty.bool_(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFrontFacing),
|
||||
Builtin(builtin::BuiltinValue::kFrontFacing),
|
||||
}),
|
||||
Member("sample_index", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
}),
|
||||
Member("sample_mask", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleMask),
|
||||
Builtin(builtin::BuiltinValue::kSampleMask),
|
||||
}),
|
||||
});
|
||||
Func("fragShader", utils::Vector{Param("arg", ty.Of(s))}, ty.f32(),
|
||||
|
@ -758,7 +771,7 @@ TEST_F(ResolverBuiltinsValidationTest, FrontFacingParamIsNotBool_Fail) {
|
|||
|
||||
auto* is_front = Param("is_front", ty.i32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFrontFacing),
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFrontFacing),
|
||||
});
|
||||
Func("fs_main", utils::Vector{is_front}, ty.f32(),
|
||||
utils::Vector{
|
||||
|
@ -782,13 +795,13 @@ TEST_F(ResolverBuiltinsValidationTest, FrontFacingMemberIsNotBool_Fail) {
|
|||
// @fragment
|
||||
// fn fragShader(is_front: MyInputs) -> @location(0) f32 { return 1.0; }
|
||||
|
||||
auto* s = Structure("MyInputs",
|
||||
utils::Vector{
|
||||
Member("pos", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, ast::BuiltinValue::kFrontFacing),
|
||||
}),
|
||||
});
|
||||
auto* s = Structure(
|
||||
"MyInputs", utils::Vector{
|
||||
Member("pos", ty.f32(),
|
||||
utils::Vector{
|
||||
Builtin(Source{{12, 34}}, builtin::BuiltinValue::kFrontFacing),
|
||||
}),
|
||||
});
|
||||
Func("fragShader", utils::Vector{Param("is_front", ty.Of(s))}, ty.f32(),
|
||||
utils::Vector{
|
||||
Return(1_f),
|
||||
|
|
|
@ -74,7 +74,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Builtin) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -111,7 +111,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Multiple) {
|
|||
},
|
||||
utils::Vector{
|
||||
Location(Source{{13, 43}}, 0_a),
|
||||
Builtin(Source{{14, 52}}, ast::BuiltinValue::kPosition),
|
||||
Builtin(Source{{14, 52}}, builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
@ -129,10 +129,11 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_Valid) {
|
|||
// return Output();
|
||||
// }
|
||||
auto* output = Structure(
|
||||
"Output", utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
"Output",
|
||||
utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output),
|
||||
utils::Vector{
|
||||
Return(Call(ty.Of(output))),
|
||||
|
@ -157,7 +158,7 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_MemberMultipleAttribu
|
|||
utils::Vector{
|
||||
Member("a", ty.f32(),
|
||||
utils::Vector{Location(Source{{13, 43}}, 0_a),
|
||||
Builtin(Source{{14, 52}}, ast::BuiltinValue::kFragDepth)}),
|
||||
Builtin(Source{{14, 52}}, builtin::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output),
|
||||
utils::Vector{
|
||||
|
@ -211,10 +212,11 @@ TEST_F(ResolverEntryPointValidationTest, ReturnType_Struct_DuplicateBuiltins) {
|
|||
// return Output();
|
||||
// }
|
||||
auto* output = Structure(
|
||||
"Output", utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
"Output",
|
||||
utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output),
|
||||
utils::Vector{
|
||||
Return(Call(ty.Of(output))),
|
||||
|
@ -272,7 +274,7 @@ TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Multiple) {
|
|||
auto* param = Param("param", ty.u32(),
|
||||
utils::Vector{
|
||||
Location(Source{{13, 43}}, 0_a),
|
||||
Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(Source{{14, 52}}, builtin::BuiltinValue::kSampleIndex),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main",
|
||||
utils::Vector{
|
||||
|
@ -296,10 +298,11 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_Valid) {
|
|||
// @fragment
|
||||
// fn main(param : Input) {}
|
||||
auto* input = Structure(
|
||||
"Input", utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
"Input",
|
||||
utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
auto* param = Param("param", ty.Of(input));
|
||||
Func(Source{{12, 34}}, "main",
|
||||
utils::Vector{
|
||||
|
@ -324,7 +327,7 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_MemberMultipleAttribut
|
|||
utils::Vector{
|
||||
Member("a", ty.u32(),
|
||||
utils::Vector{Location(Source{{13, 43}}, 0_a),
|
||||
Builtin(Source{{14, 52}}, ast::BuiltinValue::kSampleIndex)}),
|
||||
Builtin(Source{{14, 52}}, builtin::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
auto* param = Param("param", ty.Of(input));
|
||||
Func(Source{{12, 34}}, "main",
|
||||
|
@ -375,11 +378,11 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_DuplicateBuiltins) {
|
|||
// @builtin(sample_index) param_b : u32) {}
|
||||
auto* param_a = Param("param_a", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
});
|
||||
auto* param_b = Param("param_b", ty.u32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main",
|
||||
utils::Vector{
|
||||
|
@ -409,12 +412,12 @@ TEST_F(ResolverEntryPointValidationTest, Parameter_Struct_DuplicateBuiltins) {
|
|||
auto* input_a = Structure(
|
||||
"InputA",
|
||||
utils::Vector{
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}),
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
auto* input_b = Structure(
|
||||
"InputB",
|
||||
utils::Vector{
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)}),
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)}),
|
||||
});
|
||||
auto* param_a = Param("param_a", ty.Of(input_a));
|
||||
auto* param_b = Param("param_b", ty.Of(input_b));
|
||||
|
@ -984,10 +987,11 @@ TEST_F(LocationAttributeTests, ReturnType_Struct_Valid) {
|
|||
// return Output();
|
||||
// }
|
||||
auto* output = Structure(
|
||||
"Output", utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(ast::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
"Output",
|
||||
utils::Vector{
|
||||
Member("a", ty.f32(), utils::Vector{Location(0_a)}),
|
||||
Member("b", ty.f32(), utils::Vector{Builtin(builtin::BuiltinValue::kFragDepth)}),
|
||||
});
|
||||
Func(Source{{12, 34}}, "main", utils::Empty, ty.Of(output),
|
||||
utils::Vector{
|
||||
Return(Call(ty.Of(output))),
|
||||
|
|
|
@ -188,7 +188,7 @@ TEST_F(ResolverFunctionValidationTest, DiscardCalledDirectlyFromVertexEntryPoint
|
|||
Return(Call(ty.vec4<f32>())),
|
||||
},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)});
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
|
|
|
@ -873,7 +873,8 @@ TEST_F(ResolverTest, Function_Parameters) {
|
|||
|
||||
TEST_F(ResolverTest, Function_Parameters_Locations) {
|
||||
auto* param_a = Param("a", ty.f32(), utils::Vector{Location(3_a)});
|
||||
auto* param_b = Param("b", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kVertexIndex)});
|
||||
auto* param_b =
|
||||
Param("b", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)});
|
||||
auto* param_c = Param("c", ty.u32(), utils::Vector{Location(1_a)});
|
||||
|
||||
GlobalVar("my_vec", ty.vec4<f32>(), type::AddressSpace::kPrivate);
|
||||
|
@ -891,7 +892,7 @@ TEST_F(ResolverTest, Function_Parameters_Locations) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
@ -974,7 +975,7 @@ TEST_F(ResolverTest, Function_ReturnType_NoLocation) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
|
|
@ -69,7 +69,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderParam) {
|
|||
Func("main", utils::Vector{Param("param", ty.Of(s))}, ty.vec4<f32>(),
|
||||
utils::Vector{Return(Call(ty.vec4<f32>()))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)},
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)});
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
|
||||
ASSERT_TRUE(r()->Resolve()) << r()->error();
|
||||
|
||||
|
@ -80,9 +80,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderParam) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsVertexShaderReturnType) {
|
||||
auto* s =
|
||||
Structure("S", utils::Vector{Member("a", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)})});
|
||||
auto* s = Structure(
|
||||
"S", utils::Vector{Member("a", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})});
|
||||
|
||||
Func("main", utils::Empty, ty.Of(s), utils::Vector{Return(Call(ty.Of(s)))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)});
|
||||
|
@ -125,8 +125,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsFragmentShaderReturnType) {
|
|||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) {
|
||||
auto* s = Structure(
|
||||
"S", utils::Vector{Member(
|
||||
"a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kLocalInvocationIndex)})});
|
||||
"S",
|
||||
utils::Vector{Member(
|
||||
"a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kLocalInvocationIndex)})});
|
||||
|
||||
Func("main", utils::Vector{Param("param", ty.Of(s))}, ty.void_(), utils::Empty,
|
||||
utils::Vector{Stage(ast::PipelineStage::kCompute), WorkgroupSize(1_i)});
|
||||
|
@ -140,9 +141,9 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsComputeShaderParam) {
|
|||
}
|
||||
|
||||
TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) {
|
||||
auto* s =
|
||||
Structure("S", utils::Vector{Member("a", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)})});
|
||||
auto* s = Structure(
|
||||
"S", utils::Vector{Member("a", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})});
|
||||
|
||||
Func("vert_main", utils::Empty, ty.Of(s), utils::Vector{Return(Call(ty.Of(s)))},
|
||||
utils::Vector{Stage(ast::PipelineStage::kVertex)});
|
||||
|
|
|
@ -1148,8 +1148,8 @@ class UniformityGraph {
|
|||
auto has_nonuniform_entry_point_attribute = [](auto* obj) {
|
||||
// Only the num_workgroups and workgroup_id builtins are uniform.
|
||||
if (auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(obj->attributes)) {
|
||||
if (builtin->builtin == ast::BuiltinValue::kNumWorkgroups ||
|
||||
builtin->builtin == ast::BuiltinValue::kWorkgroupId) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kNumWorkgroups ||
|
||||
builtin->builtin == builtin::BuiltinValue::kWorkgroupId) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ TEST_F(ResolverValidationTest, WorkgroupMemoryUsedInVertexStage) {
|
|||
Stage(ast::PipelineStage::kVertex),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
|
|
|
@ -868,7 +868,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
bool is_stage_mismatch = false;
|
||||
bool is_output = !is_input;
|
||||
switch (attr->builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!((is_input && stage == ast::PipelineStage::kFragment) ||
|
||||
(is_output && stage == ast::PipelineStage::kVertex))) {
|
||||
|
@ -880,10 +880,10 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case ast::BuiltinValue::kNumWorkgroups:
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kNumWorkgroups:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kCompute && is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -894,7 +894,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kFragment && !is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -904,7 +904,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kFragment && is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -914,7 +914,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kCompute && is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -924,8 +924,8 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kVertex && is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -935,7 +935,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
if (stage != ast::PipelineStage::kNone && !(stage == ast::PipelineStage::kFragment)) {
|
||||
is_stage_mismatch = true;
|
||||
}
|
||||
|
@ -944,7 +944,7 @@ bool Validator::BuiltinAttribute(const ast::BuiltinAttribute* attr,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
if (stage != ast::PipelineStage::kNone &&
|
||||
!(stage == ast::PipelineStage::kFragment && is_input)) {
|
||||
is_stage_mismatch = true;
|
||||
|
@ -1076,7 +1076,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
|
|||
// order to catch conflicts.
|
||||
// TODO(jrprice): This state could be stored in sem::Function instead, and then passed to
|
||||
// sem::Function since it would be useful there too.
|
||||
utils::Hashset<ast::BuiltinValue, 4> builtins;
|
||||
utils::Hashset<builtin::BuiltinValue, 4> builtins;
|
||||
utils::Hashset<uint32_t, 8> locations;
|
||||
enum class ParamOrRetType {
|
||||
kParameter,
|
||||
|
@ -1211,7 +1211,7 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
|
|||
bool has_position = false;
|
||||
if (pipeline_io_attribute) {
|
||||
if (auto* builtin = pipeline_io_attribute->As<ast::BuiltinAttribute>()) {
|
||||
has_position = (builtin->builtin == ast::BuiltinValue::kPosition);
|
||||
has_position = (builtin->builtin == builtin::BuiltinValue::kPosition);
|
||||
}
|
||||
}
|
||||
if (!has_position) {
|
||||
|
@ -1275,13 +1275,13 @@ bool Validator::EntryPoint(const sem::Function* func, ast::PipelineStage stage)
|
|||
}
|
||||
|
||||
if (decl->PipelineStage() == ast::PipelineStage::kVertex &&
|
||||
!builtins.Contains(ast::BuiltinValue::kPosition)) {
|
||||
!builtins.Contains(builtin::BuiltinValue::kPosition)) {
|
||||
// Check module-scope variables, as the SPIR-V sanitizer generates these.
|
||||
bool found = false;
|
||||
for (auto* global : func->TransitivelyReferencedGlobals()) {
|
||||
if (auto* builtin =
|
||||
ast::GetAttribute<ast::BuiltinAttribute>(global->Declaration()->attributes)) {
|
||||
if (builtin->builtin == ast::BuiltinValue::kPosition) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kPosition) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -2123,7 +2123,7 @@ bool Validator::Structure(const sem::Struct* str, ast::PipelineStage stage) cons
|
|||
/* is_input */ false)) {
|
||||
return false;
|
||||
}
|
||||
if (builtin->builtin == ast::BuiltinValue::kPosition) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kPosition) {
|
||||
has_position = true;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -47,33 +47,33 @@ struct MemberInfo {
|
|||
|
||||
/// FXC is sensitive to field order in structures, this is used by StructMemberComparator to ensure
|
||||
/// that FXC is happy with the order of emitted fields.
|
||||
uint32_t BuiltinOrder(ast::BuiltinValue builtin) {
|
||||
uint32_t BuiltinOrder(builtin::BuiltinValue builtin) {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
return 1;
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
return 2;
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
return 3;
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
return 4;
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
return 5;
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
return 6;
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
return 7;
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
return 8;
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
return 9;
|
||||
case ast::BuiltinValue::kNumWorkgroups:
|
||||
case builtin::BuiltinValue::kNumWorkgroups:
|
||||
return 10;
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
return 11;
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
return 12;
|
||||
case ast::BuiltinValue::kPointSize:
|
||||
case builtin::BuiltinValue::kPointSize:
|
||||
return 13;
|
||||
default:
|
||||
break;
|
||||
|
@ -118,7 +118,7 @@ bool IsShaderIOAttribute(const ast::Attribute* attr) {
|
|||
// Returns true if `attrs` contains a `sample_mask` builtin.
|
||||
bool HasSampleMask(utils::VectorRef<const ast::Attribute*> attrs) {
|
||||
auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(attrs);
|
||||
return builtin && builtin->builtin == ast::BuiltinValue::kSampleMask;
|
||||
return builtin && builtin->builtin == builtin::BuiltinValue::kSampleMask;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -244,7 +244,7 @@ struct CanonicalizeEntryPointIO::State {
|
|||
if (builtin) {
|
||||
if (cfg.shader_style == ShaderStyle::kGlsl) {
|
||||
value = FromGLSLBuiltin(builtin->builtin, value, ast_type);
|
||||
} else if (builtin->builtin == ast::BuiltinValue::kSampleMask) {
|
||||
} else if (builtin->builtin == builtin::BuiltinValue::kSampleMask) {
|
||||
// Vulkan requires the type of a SampleMask builtin to be an array.
|
||||
// Declare it as array<u32, 1> and then load the first element.
|
||||
ast_type = ctx.dst->ty.array(ast_type, 1_u);
|
||||
|
@ -422,7 +422,7 @@ struct CanonicalizeEntryPointIO::State {
|
|||
// No existing sample mask builtin was found, so create a new output value
|
||||
// using the fixed sample mask.
|
||||
AddOutput("fixed_sample_mask", ctx.dst->create<type::U32>(), std::nullopt,
|
||||
{ctx.dst->Builtin(ast::BuiltinValue::kSampleMask)},
|
||||
{ctx.dst->Builtin(builtin::BuiltinValue::kSampleMask)},
|
||||
ctx.dst->Expr(u32(cfg.fixed_sample_mask)));
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ struct CanonicalizeEntryPointIO::State {
|
|||
void AddVertexPointSize() {
|
||||
// Create a new output value and assign it a literal 1.0 value.
|
||||
AddOutput("vertex_point_size", ctx.dst->create<type::F32>(), std::nullopt,
|
||||
{ctx.dst->Builtin(ast::BuiltinValue::kPointSize)}, ctx.dst->Expr(1_f));
|
||||
{ctx.dst->Builtin(builtin::BuiltinValue::kPointSize)}, ctx.dst->Expr(1_f));
|
||||
}
|
||||
|
||||
/// Create an expression for gl_Position.[component]
|
||||
|
@ -675,11 +675,11 @@ struct CanonicalizeEntryPointIO::State {
|
|||
/// @param stage the current pipeline stage
|
||||
/// @param address_space the address space (input or output)
|
||||
/// @returns the gl_ string corresponding to that builtin
|
||||
const char* GLSLBuiltinToString(ast::BuiltinValue builtin,
|
||||
const char* GLSLBuiltinToString(builtin::BuiltinValue builtin,
|
||||
ast::PipelineStage stage,
|
||||
type::AddressSpace address_space) {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
switch (stage) {
|
||||
case ast::PipelineStage::kVertex:
|
||||
return "gl_Position";
|
||||
|
@ -688,27 +688,27 @@ struct CanonicalizeEntryPointIO::State {
|
|||
default:
|
||||
return "";
|
||||
}
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
return "gl_VertexID";
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
return "gl_InstanceID";
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
return "gl_FrontFacing";
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
return "gl_FragDepth";
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
return "gl_LocalInvocationID";
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
return "gl_LocalInvocationIndex";
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
return "gl_GlobalInvocationID";
|
||||
case ast::BuiltinValue::kNumWorkgroups:
|
||||
case builtin::BuiltinValue::kNumWorkgroups:
|
||||
return "gl_NumWorkGroups";
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
return "gl_WorkGroupID";
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
return "gl_SampleID";
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
if (address_space == type::AddressSpace::kIn) {
|
||||
return "gl_SampleMaskIn";
|
||||
} else {
|
||||
|
@ -725,18 +725,18 @@ struct CanonicalizeEntryPointIO::State {
|
|||
/// @param ast_type (inout) the incoming WGSL and outgoing GLSL types
|
||||
/// @returns an expression representing the GLSL builtin converted to what
|
||||
/// WGSL expects
|
||||
const ast::Expression* FromGLSLBuiltin(ast::BuiltinValue builtin,
|
||||
const ast::Expression* FromGLSLBuiltin(builtin::BuiltinValue builtin,
|
||||
const ast::Expression* value,
|
||||
ast::Type& ast_type) {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
// GLSL uses i32 for these, so bitcast to u32.
|
||||
value = ctx.dst->Bitcast(ast_type, value);
|
||||
ast_type = ctx.dst->ty.i32();
|
||||
break;
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
// gl_SampleMask is an array of i32. Retrieve the first element and
|
||||
// bitcast it to u32.
|
||||
value = ctx.dst->IndexAccessor(value, 0_i);
|
||||
|
@ -755,14 +755,14 @@ struct CanonicalizeEntryPointIO::State {
|
|||
/// @param value the value to convert
|
||||
/// @param type (out) the type to which the value was converted
|
||||
/// @returns the converted value which can be assigned to the GLSL builtin
|
||||
const ast::Expression* ToGLSLBuiltin(ast::BuiltinValue builtin,
|
||||
const ast::Expression* ToGLSLBuiltin(builtin::BuiltinValue builtin,
|
||||
const ast::Expression* value,
|
||||
const type::Type*& type) {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
type = ctx.dst->create<type::I32>();
|
||||
value = ctx.dst->Bitcast(CreateASTTypeFor(ctx, type), value);
|
||||
break;
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/builtin_attribute.h"
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/ast/function.h"
|
||||
#include "src/tint/ast/module.h"
|
||||
#include "src/tint/ast/struct.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/sem/function.h"
|
||||
#include "src/tint/sem/statement.h"
|
||||
|
@ -38,7 +38,7 @@ namespace {
|
|||
bool ContainsFragDepth(utils::VectorRef<const ast::Attribute*> attributes) {
|
||||
for (auto* attribute : attributes) {
|
||||
if (auto* builtin_attribute = attribute->As<ast::BuiltinAttribute>()) {
|
||||
if (builtin_attribute->builtin == ast::BuiltinValue::kFragDepth) {
|
||||
if (builtin_attribute->builtin == builtin::BuiltinValue::kFragDepth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,13 +88,13 @@ Transform::ApplyResult FirstIndexOffset::Apply(const Program* src,
|
|||
if (auto* var = node->As<ast::Variable>()) {
|
||||
for (auto* attr : var->attributes) {
|
||||
if (auto* builtin_attr = attr->As<ast::BuiltinAttribute>()) {
|
||||
ast::BuiltinValue builtin = builtin_attr->builtin;
|
||||
if (builtin == ast::BuiltinValue::kVertexIndex) {
|
||||
builtin::BuiltinValue builtin = builtin_attr->builtin;
|
||||
if (builtin == builtin::BuiltinValue::kVertexIndex) {
|
||||
auto* sem_var = ctx.src->Sem().Get(var);
|
||||
builtin_vars.emplace(sem_var, kFirstVertexName);
|
||||
has_vertex_or_instance_index = true;
|
||||
}
|
||||
if (builtin == ast::BuiltinValue::kInstanceIndex) {
|
||||
if (builtin == builtin::BuiltinValue::kInstanceIndex) {
|
||||
auto* sem_var = ctx.src->Sem().Get(var);
|
||||
builtin_vars.emplace(sem_var, kFirstInstanceName);
|
||||
has_vertex_or_instance_index = true;
|
||||
|
@ -105,13 +105,13 @@ Transform::ApplyResult FirstIndexOffset::Apply(const Program* src,
|
|||
if (auto* member = node->As<ast::StructMember>()) {
|
||||
for (auto* attr : member->attributes) {
|
||||
if (auto* builtin_attr = attr->As<ast::BuiltinAttribute>()) {
|
||||
ast::BuiltinValue builtin = builtin_attr->builtin;
|
||||
if (builtin == ast::BuiltinValue::kVertexIndex) {
|
||||
builtin::BuiltinValue builtin = builtin_attr->builtin;
|
||||
if (builtin == builtin::BuiltinValue::kVertexIndex) {
|
||||
auto* sem_mem = ctx.src->Sem().Get(member);
|
||||
builtin_members.emplace(sem_mem, kFirstVertexName);
|
||||
has_vertex_or_instance_index = true;
|
||||
}
|
||||
if (builtin == ast::BuiltinValue::kInstanceIndex) {
|
||||
if (builtin == builtin::BuiltinValue::kInstanceIndex) {
|
||||
auto* sem_mem = ctx.src->Sem().Get(member);
|
||||
builtin_members.emplace(sem_mem, kFirstInstanceName);
|
||||
has_vertex_or_instance_index = true;
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace {
|
|||
bool ShouldRun(const Program* program) {
|
||||
for (auto* node : program->ASTNodes().Objects()) {
|
||||
if (auto* attr = node->As<ast::BuiltinAttribute>()) {
|
||||
if (attr->builtin == ast::BuiltinValue::kNumWorkgroups) {
|
||||
if (attr->builtin == builtin::BuiltinValue::kNumWorkgroups) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src,
|
|||
for (auto* member : str->Members()) {
|
||||
auto* builtin =
|
||||
ast::GetAttribute<ast::BuiltinAttribute>(member->Declaration()->attributes);
|
||||
if (!builtin || builtin->builtin != ast::BuiltinValue::kNumWorkgroups) {
|
||||
if (!builtin || builtin->builtin != builtin::BuiltinValue::kNumWorkgroups) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -778,11 +778,11 @@ struct VertexPulling::State {
|
|||
return;
|
||||
}
|
||||
// Check for existing vertex_index and instance_index builtins.
|
||||
if (builtin->builtin == ast::BuiltinValue::kVertexIndex) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kVertexIndex) {
|
||||
vertex_index_expr = [this, param]() {
|
||||
return b.Expr(ctx.Clone(param->name->symbol));
|
||||
};
|
||||
} else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) {
|
||||
} else if (builtin->builtin == builtin::BuiltinValue::kInstanceIndex) {
|
||||
instance_index_expr = [this, param]() {
|
||||
return b.Expr(ctx.Clone(param->name->symbol));
|
||||
};
|
||||
|
@ -831,9 +831,9 @@ struct VertexPulling::State {
|
|||
return;
|
||||
}
|
||||
// Check for existing vertex_index and instance_index builtins.
|
||||
if (builtin->builtin == ast::BuiltinValue::kVertexIndex) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kVertexIndex) {
|
||||
vertex_index_expr = member_expr;
|
||||
} else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) {
|
||||
} else if (builtin->builtin == builtin::BuiltinValue::kInstanceIndex) {
|
||||
instance_index_expr = member_expr;
|
||||
}
|
||||
members_to_clone.Push(member);
|
||||
|
@ -899,7 +899,7 @@ struct VertexPulling::State {
|
|||
auto name = b.Symbols().New("tint_pulling_vertex_index");
|
||||
new_function_parameters.Push(
|
||||
b.Param(name, b.ty.u32(),
|
||||
utils::Vector{b.Builtin(ast::BuiltinValue::kVertexIndex)}));
|
||||
utils::Vector{b.Builtin(builtin::BuiltinValue::kVertexIndex)}));
|
||||
vertex_index_expr = [this, name]() { return b.Expr(name); };
|
||||
break;
|
||||
}
|
||||
|
@ -911,7 +911,7 @@ struct VertexPulling::State {
|
|||
auto name = b.Symbols().New("tint_pulling_instance_index");
|
||||
new_function_parameters.Push(
|
||||
b.Param(name, b.ty.u32(),
|
||||
utils::Vector{b.Builtin(ast::BuiltinValue::kInstanceIndex)}));
|
||||
utils::Vector{b.Builtin(builtin::BuiltinValue::kInstanceIndex)}));
|
||||
instance_index_expr = [this, name]() { return b.Expr(name); };
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ struct ZeroInitWorkgroupMemory::State {
|
|||
std::function<const ast::Expression*()> local_index;
|
||||
for (auto* param : fn->params) {
|
||||
if (auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(param->attributes)) {
|
||||
if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kLocalInvocationIndex) {
|
||||
local_index = [=] { return b.Expr(ctx.Clone(param->name->symbol)); };
|
||||
break;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ struct ZeroInitWorkgroupMemory::State {
|
|||
for (auto* member : str->Members()) {
|
||||
if (auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(
|
||||
member->Declaration()->attributes)) {
|
||||
if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) {
|
||||
if (builtin->builtin == builtin::BuiltinValue::kLocalInvocationIndex) {
|
||||
local_index = [=] {
|
||||
auto* param_expr = b.Expr(ctx.Clone(param->name->symbol));
|
||||
auto* member_name = ctx.Clone(member->Declaration()->name);
|
||||
|
@ -185,7 +185,7 @@ struct ZeroInitWorkgroupMemory::State {
|
|||
// No existing local index parameter. Append one to the entry point.
|
||||
auto* param = b.Param(b.Symbols().New("local_invocation_index"), b.ty.u32(),
|
||||
utils::Vector{
|
||||
b.Builtin(ast::BuiltinValue::kLocalInvocationIndex),
|
||||
b.Builtin(builtin::BuiltinValue::kLocalInvocationIndex),
|
||||
});
|
||||
ctx.InsertBack(fn->params, param);
|
||||
local_index = [=] { return b.Expr(param->name->symbol); };
|
||||
|
|
|
@ -90,10 +90,10 @@ bool IsRelational(tint::ast::BinaryOp op) {
|
|||
op == tint::ast::BinaryOp::kGreaterThanEqual;
|
||||
}
|
||||
|
||||
bool RequiresOESSampleVariables(tint::ast::BuiltinValue builtin) {
|
||||
bool RequiresOESSampleVariables(tint::builtin::BuiltinValue builtin) {
|
||||
switch (builtin) {
|
||||
case tint::ast::BuiltinValue::kSampleIndex:
|
||||
case tint::ast::BuiltinValue::kSampleMask:
|
||||
case tint::builtin::BuiltinValue::kSampleIndex:
|
||||
case tint::builtin::BuiltinValue::kSampleMask:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
|
|
@ -471,11 +471,11 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// @param builtin the builtin to convert
|
||||
/// @param stage pipeline stage in which this builtin is used
|
||||
/// @returns the string name of the builtin or blank on error
|
||||
const char* builtin_to_string(ast::BuiltinValue builtin, ast::PipelineStage stage);
|
||||
const char* builtin_to_string(builtin::BuiltinValue builtin, ast::PipelineStage stage);
|
||||
/// Converts a builtin to a type::Type appropriate for GLSL.
|
||||
/// @param builtin the builtin to convert
|
||||
/// @returns the appropriate semantic type or null on error.
|
||||
type::Type* builtin_type(ast::BuiltinValue builtin);
|
||||
type::Type* builtin_type(builtin::BuiltinValue builtin);
|
||||
|
||||
private:
|
||||
enum class VarType { kIn, kOut };
|
||||
|
|
|
@ -166,7 +166,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built
|
|||
// return coord.x;
|
||||
// }
|
||||
auto* coord_in =
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)});
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
Func("frag_main",
|
||||
utils::Vector{
|
||||
coord_in,
|
||||
|
@ -179,7 +179,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -217,7 +217,7 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_Di
|
|||
auto* interface_struct = Structure(
|
||||
"Interface",
|
||||
utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
Member("col1", ty.f32(), utils::Vector{Location(1_a)}),
|
||||
Member("col2", ty.f32(), utils::Vector{Location(2_a)}),
|
||||
});
|
||||
|
@ -297,7 +297,7 @@ TEST_F(GlslGeneratorImplTest_Function,
|
|||
// }
|
||||
auto* vertex_output_struct = Structure(
|
||||
"VertexOutput",
|
||||
{Member("pos", ty.vec4<f32>(), {Builtin(ast::BuiltinValue::kPosition)})});
|
||||
{Member("pos", ty.vec4<f32>(), {Builtin(builtin::BuiltinValue::kPosition)})});
|
||||
|
||||
Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct),
|
||||
{Return(Call(ty.Of(vertex_output_struct),
|
||||
|
|
|
@ -59,7 +59,7 @@ void my_func() {
|
|||
TEST_F(GlslGeneratorImplTest, GenerateSampleIndexES) {
|
||||
GlobalVar("gl_SampleID", ty.i32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
Disable(ast::DisabledValidation::kIgnoreAddressSpace),
|
||||
},
|
||||
type::AddressSpace::kIn);
|
||||
|
@ -84,7 +84,7 @@ int my_func() {
|
|||
TEST_F(GlslGeneratorImplTest, GenerateSampleIndexDesktop) {
|
||||
GlobalVar("gl_SampleID", ty.i32(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kSampleIndex),
|
||||
Builtin(builtin::BuiltinValue::kSampleIndex),
|
||||
Disable(ast::DisabledValidation::kIgnoreAddressSpace),
|
||||
},
|
||||
type::AddressSpace::kIn);
|
||||
|
|
|
@ -3154,29 +3154,29 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string GeneratorImpl::builtin_to_attribute(ast::BuiltinValue builtin) const {
|
||||
std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) const {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
return "SV_Position";
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
return "SV_VertexID";
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
return "SV_InstanceID";
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
return "SV_IsFrontFace";
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
return "SV_Depth";
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
return "SV_GroupThreadID";
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
return "SV_GroupIndex";
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
return "SV_DispatchThreadID";
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
return "SV_GroupID";
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
return "SV_SampleIndex";
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
return "SV_Coverage";
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -495,7 +495,7 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// Converts a builtin to an attribute name
|
||||
/// @param builtin the builtin to convert
|
||||
/// @returns the string name of the builtin or blank on error
|
||||
std::string builtin_to_attribute(ast::BuiltinValue builtin) const;
|
||||
std::string builtin_to_attribute(builtin::BuiltinValue builtin) const;
|
||||
|
||||
/// Converts interpolation attributes to a HLSL modifiers
|
||||
/// @param type the interpolation type
|
||||
|
|
|
@ -157,7 +157,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built
|
|||
// return coord.x;
|
||||
// }
|
||||
auto* coord_in =
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)});
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
Func("frag_main", utils::Vector{coord_in}, ty.f32(),
|
||||
utils::Vector{
|
||||
Return(MemberAccessor("coord", "x")),
|
||||
|
@ -166,7 +166,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -209,7 +209,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_Di
|
|||
auto* interface_struct = Structure(
|
||||
"Interface",
|
||||
utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
Member("col1", ty.f32(), utils::Vector{Location(1_a)}),
|
||||
Member("col2", ty.f32(), utils::Vector{Location(2_a)}),
|
||||
});
|
||||
|
@ -292,7 +292,7 @@ TEST_F(HlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_He
|
|||
auto* vertex_output_struct =
|
||||
Structure("VertexOutput",
|
||||
utils::Vector{Member("pos", ty.vec4<f32>(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kPosition)})});
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kPosition)})});
|
||||
|
||||
Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct),
|
||||
utils::Vector{
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST_F(HlslGeneratorImplTest, Generate) {
|
|||
}
|
||||
|
||||
struct HlslBuiltinData {
|
||||
ast::BuiltinValue builtin;
|
||||
builtin::BuiltinValue builtin;
|
||||
const char* attribute_name;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, HlslBuiltinData data) {
|
||||
|
@ -66,17 +66,18 @@ TEST_P(HlslBuiltinConversionTest, Emit) {
|
|||
INSTANTIATE_TEST_SUITE_P(
|
||||
HlslGeneratorImplTest,
|
||||
HlslBuiltinConversionTest,
|
||||
testing::Values(HlslBuiltinData{ast::BuiltinValue::kPosition, "SV_Position"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kVertexIndex, "SV_VertexID"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kInstanceIndex, "SV_InstanceID"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kFrontFacing, "SV_IsFrontFace"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kFragDepth, "SV_Depth"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kLocalInvocationId, "SV_GroupThreadID"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kLocalInvocationIndex, "SV_GroupIndex"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kGlobalInvocationId, "SV_DispatchThreadID"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kWorkgroupId, "SV_GroupID"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kSampleIndex, "SV_SampleIndex"},
|
||||
HlslBuiltinData{ast::BuiltinValue::kSampleMask, "SV_Coverage"}));
|
||||
testing::Values(HlslBuiltinData{builtin::BuiltinValue::kPosition, "SV_Position"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kVertexIndex, "SV_VertexID"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kInstanceIndex, "SV_InstanceID"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kFrontFacing, "SV_IsFrontFace"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kFragDepth, "SV_Depth"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kLocalInvocationId, "SV_GroupThreadID"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, "SV_GroupIndex"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kGlobalInvocationId,
|
||||
"SV_DispatchThreadID"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kWorkgroupId, "SV_GroupID"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kSampleIndex, "SV_SampleIndex"},
|
||||
HlslBuiltinData{builtin::BuiltinValue::kSampleMask, "SV_Coverage"}));
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::writer::hlsl
|
||||
|
|
|
@ -1905,33 +1905,33 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string GeneratorImpl::builtin_to_attribute(ast::BuiltinValue builtin) const {
|
||||
std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) const {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
return "position";
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
return "vertex_id";
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
return "instance_id";
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
return "front_facing";
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
return "depth(any)";
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
return "thread_position_in_threadgroup";
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
return "thread_index_in_threadgroup";
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
return "thread_position_in_grid";
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
return "threadgroup_position_in_grid";
|
||||
case ast::BuiltinValue::kNumWorkgroups:
|
||||
case builtin::BuiltinValue::kNumWorkgroups:
|
||||
return "threadgroups_per_grid";
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
return "sample_id";
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
return "sample_mask";
|
||||
case ast::BuiltinValue::kPointSize:
|
||||
case builtin::BuiltinValue::kPointSize:
|
||||
return "point_size";
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -360,7 +360,7 @@ class GeneratorImpl : public TextGenerator {
|
|||
/// Converts a builtin to an attribute name
|
||||
/// @param builtin the builtin to convert
|
||||
/// @returns the string name of the builtin or blank on error
|
||||
std::string builtin_to_attribute(ast::BuiltinValue builtin) const;
|
||||
std::string builtin_to_attribute(builtin::BuiltinValue builtin) const;
|
||||
|
||||
/// Converts interpolation attributes to an MSL attribute
|
||||
/// @param type the interpolation type
|
||||
|
|
|
@ -136,7 +136,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_WithInOut_Builtins) {
|
|||
// return coord.x;
|
||||
// }
|
||||
auto* coord_in =
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)});
|
||||
Param("coord", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)});
|
||||
Func("frag_main", utils::Vector{coord_in}, ty.f32(),
|
||||
utils::Vector{
|
||||
Return(MemberAccessor("coord", "x")),
|
||||
|
@ -145,7 +145,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_WithInOut_Builtins) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
GeneratorImpl& gen = SanitizeAndBuild();
|
||||
|
@ -190,7 +190,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_DifferentSta
|
|||
utils::Vector{
|
||||
Member("col1", ty.f32(), utils::Vector{Location(1_a)}),
|
||||
Member("col2", ty.f32(), utils::Vector{Location(2_a)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
});
|
||||
|
||||
Func("vert_main", utils::Empty, ty.Of(interface_struct),
|
||||
|
@ -271,7 +271,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_HelperFuncti
|
|||
auto* vertex_output_struct = Structure(
|
||||
"VertexOutput",
|
||||
utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
});
|
||||
|
||||
Func("foo", utils::Vector{Param("x", ty.f32())}, ty.Of(vertex_output_struct),
|
||||
|
|
|
@ -61,7 +61,7 @@ kernel void my_func() {
|
|||
}
|
||||
|
||||
struct MslBuiltinData {
|
||||
ast::BuiltinValue builtin;
|
||||
builtin::BuiltinValue builtin;
|
||||
const char* attribute_name;
|
||||
};
|
||||
inline std::ostream& operator<<(std::ostream& out, MslBuiltinData data) {
|
||||
|
@ -80,25 +80,25 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
MslGeneratorImplTest,
|
||||
MslBuiltinConversionTest,
|
||||
testing::Values(
|
||||
MslBuiltinData{ast::BuiltinValue::kPosition, "position"},
|
||||
MslBuiltinData{ast::BuiltinValue::kVertexIndex, "vertex_id"},
|
||||
MslBuiltinData{ast::BuiltinValue::kInstanceIndex, "instance_id"},
|
||||
MslBuiltinData{ast::BuiltinValue::kFrontFacing, "front_facing"},
|
||||
MslBuiltinData{ast::BuiltinValue::kFragDepth, "depth(any)"},
|
||||
MslBuiltinData{ast::BuiltinValue::kLocalInvocationId, "thread_position_in_threadgroup"},
|
||||
MslBuiltinData{ast::BuiltinValue::kLocalInvocationIndex, "thread_index_in_threadgroup"},
|
||||
MslBuiltinData{ast::BuiltinValue::kGlobalInvocationId, "thread_position_in_grid"},
|
||||
MslBuiltinData{ast::BuiltinValue::kWorkgroupId, "threadgroup_position_in_grid"},
|
||||
MslBuiltinData{ast::BuiltinValue::kNumWorkgroups, "threadgroups_per_grid"},
|
||||
MslBuiltinData{ast::BuiltinValue::kSampleIndex, "sample_id"},
|
||||
MslBuiltinData{ast::BuiltinValue::kSampleMask, "sample_mask"},
|
||||
MslBuiltinData{ast::BuiltinValue::kPointSize, "point_size"}));
|
||||
MslBuiltinData{builtin::BuiltinValue::kPosition, "position"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kVertexIndex, "vertex_id"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kInstanceIndex, "instance_id"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kFrontFacing, "front_facing"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kFragDepth, "depth(any)"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kLocalInvocationId, "thread_position_in_threadgroup"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, "thread_index_in_threadgroup"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kGlobalInvocationId, "thread_position_in_grid"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kWorkgroupId, "threadgroup_position_in_grid"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kNumWorkgroups, "threadgroups_per_grid"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kSampleIndex, "sample_id"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kSampleMask, "sample_mask"},
|
||||
MslBuiltinData{builtin::BuiltinValue::kPointSize, "point_size"}));
|
||||
|
||||
TEST_F(MslGeneratorImplTest, HasInvariantAttribute_True) {
|
||||
auto* out = Structure("Out", utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
Invariant(),
|
||||
}),
|
||||
});
|
||||
|
@ -136,7 +136,7 @@ TEST_F(MslGeneratorImplTest, HasInvariantAttribute_False) {
|
|||
auto* out = Structure("Out", utils::Vector{
|
||||
Member("pos", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
}),
|
||||
});
|
||||
Func("vert_main", utils::Empty, ty.Of(out), utils::Vector{Return(Call(ty.Of(out)))},
|
||||
|
|
|
@ -549,7 +549,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
|
|||
}
|
||||
|
||||
for (auto builtin : func_sem->TransitivelyReferencedBuiltinVariables()) {
|
||||
if (builtin.second->builtin == ast::BuiltinValue::kFragDepth) {
|
||||
if (builtin.second->builtin == builtin::BuiltinValue::kFragDepth) {
|
||||
push_execution_mode(spv::Op::OpExecutionMode,
|
||||
{Operand(id), U32Operand(SpvExecutionModeDepthReplacing)});
|
||||
}
|
||||
|
@ -4004,9 +4004,9 @@ SpvStorageClass Builder::ConvertAddressSpace(type::AddressSpace klass) const {
|
|||
return SpvStorageClassMax;
|
||||
}
|
||||
|
||||
SpvBuiltIn Builder::ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace storage) {
|
||||
SpvBuiltIn Builder::ConvertBuiltin(builtin::BuiltinValue builtin, type::AddressSpace storage) {
|
||||
switch (builtin) {
|
||||
case ast::BuiltinValue::kPosition:
|
||||
case builtin::BuiltinValue::kPosition:
|
||||
if (storage == type::AddressSpace::kIn) {
|
||||
return SpvBuiltInFragCoord;
|
||||
} else if (TINT_LIKELY(storage == type::AddressSpace::kOut)) {
|
||||
|
@ -4015,32 +4015,32 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace
|
|||
TINT_ICE(Writer, builder_.Diagnostics()) << "invalid address space for builtin";
|
||||
break;
|
||||
}
|
||||
case ast::BuiltinValue::kVertexIndex:
|
||||
case builtin::BuiltinValue::kVertexIndex:
|
||||
return SpvBuiltInVertexIndex;
|
||||
case ast::BuiltinValue::kInstanceIndex:
|
||||
case builtin::BuiltinValue::kInstanceIndex:
|
||||
return SpvBuiltInInstanceIndex;
|
||||
case ast::BuiltinValue::kFrontFacing:
|
||||
case builtin::BuiltinValue::kFrontFacing:
|
||||
return SpvBuiltInFrontFacing;
|
||||
case ast::BuiltinValue::kFragDepth:
|
||||
case builtin::BuiltinValue::kFragDepth:
|
||||
return SpvBuiltInFragDepth;
|
||||
case ast::BuiltinValue::kLocalInvocationId:
|
||||
case builtin::BuiltinValue::kLocalInvocationId:
|
||||
return SpvBuiltInLocalInvocationId;
|
||||
case ast::BuiltinValue::kLocalInvocationIndex:
|
||||
case builtin::BuiltinValue::kLocalInvocationIndex:
|
||||
return SpvBuiltInLocalInvocationIndex;
|
||||
case ast::BuiltinValue::kGlobalInvocationId:
|
||||
case builtin::BuiltinValue::kGlobalInvocationId:
|
||||
return SpvBuiltInGlobalInvocationId;
|
||||
case ast::BuiltinValue::kPointSize:
|
||||
case builtin::BuiltinValue::kPointSize:
|
||||
return SpvBuiltInPointSize;
|
||||
case ast::BuiltinValue::kWorkgroupId:
|
||||
case builtin::BuiltinValue::kWorkgroupId:
|
||||
return SpvBuiltInWorkgroupId;
|
||||
case ast::BuiltinValue::kNumWorkgroups:
|
||||
case builtin::BuiltinValue::kNumWorkgroups:
|
||||
return SpvBuiltInNumWorkgroups;
|
||||
case ast::BuiltinValue::kSampleIndex:
|
||||
case builtin::BuiltinValue::kSampleIndex:
|
||||
push_capability(SpvCapabilitySampleRateShading);
|
||||
return SpvBuiltInSampleId;
|
||||
case ast::BuiltinValue::kSampleMask:
|
||||
case builtin::BuiltinValue::kSampleMask:
|
||||
return SpvBuiltInSampleMask;
|
||||
case ast::BuiltinValue::kUndefined:
|
||||
case builtin::BuiltinValue::kUndefined:
|
||||
break;
|
||||
}
|
||||
return SpvBuiltInMax;
|
||||
|
|
|
@ -213,7 +213,7 @@ class Builder {
|
|||
/// @param builtin the builtin to convert
|
||||
/// @param storage the address space that this builtin is being used with
|
||||
/// @returns the SPIR-V builtin or SpvBuiltInMax on error.
|
||||
SpvBuiltIn ConvertBuiltin(ast::BuiltinValue builtin, type::AddressSpace storage);
|
||||
SpvBuiltIn ConvertBuiltin(builtin::BuiltinValue builtin, type::AddressSpace storage);
|
||||
|
||||
/// Converts an interpolate attribute to SPIR-V decorations and pushes a
|
||||
/// capability if needed.
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "src/tint/ast/builtin_attribute.h"
|
||||
#include "src/tint/ast/builtin_value.h"
|
||||
#include "src/tint/ast/location_attribute.h"
|
||||
#include "src/tint/ast/return_statement.h"
|
||||
#include "src/tint/ast/stage_attribute.h"
|
||||
#include "src/tint/ast/variable.h"
|
||||
#include "src/tint/builtin/builtin_value.h"
|
||||
#include "src/tint/program.h"
|
||||
#include "src/tint/type/address_space.h"
|
||||
#include "src/tint/type/f32.h"
|
||||
|
@ -44,7 +44,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
|
|||
// }
|
||||
auto* coord = Param("coord", ty.vec4<f32>(),
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
auto* loc1 = Param("loc1", ty.f32(),
|
||||
utils::Vector{
|
||||
|
@ -212,7 +212,7 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) {
|
|||
"Interface",
|
||||
utils::Vector{
|
||||
Member("value", ty.f32(), utils::Vector{Location(1_u)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}),
|
||||
Member("pos", ty.vec4<f32>(), utils::Vector{Builtin(builtin::BuiltinValue::kPosition)}),
|
||||
});
|
||||
|
||||
auto* vert_retval = Call(ty.Of(interface), 42_f, vec4<f32>());
|
||||
|
@ -228,7 +228,7 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) {
|
|||
},
|
||||
utils::Vector{Stage(ast::PipelineStage::kFragment)},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
@ -322,7 +322,7 @@ OpFunctionEnd
|
|||
TEST_F(BuilderTest, SampleIndex_SampleRateShadingCapability) {
|
||||
Func("main",
|
||||
utils::Vector{Param("sample_index", ty.u32(),
|
||||
utils::Vector{Builtin(ast::BuiltinValue::kSampleIndex)})},
|
||||
utils::Vector{Builtin(builtin::BuiltinValue::kSampleIndex)})},
|
||||
ty.void_(), utils::Empty,
|
||||
utils::Vector{
|
||||
Stage(ast::PipelineStage::kFragment),
|
||||
|
|
|
@ -56,7 +56,7 @@ TEST_P(Attribute_StageTest, Emit) {
|
|||
utils::Vector<const ast::Statement*, 2> body;
|
||||
if (params.stage == ast::PipelineStage::kVertex) {
|
||||
ret_type = ty.vec4<f32>();
|
||||
ret_type_attrs.Push(Builtin(ast::BuiltinValue::kPosition));
|
||||
ret_type_attrs.Push(Builtin(builtin::BuiltinValue::kPosition));
|
||||
body.Push(Return(Call(ty.vec4<f32>())));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) {
|
|||
Stage(ast::PipelineStage::kFragment),
|
||||
},
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kFragDepth),
|
||||
Builtin(builtin::BuiltinValue::kFragDepth),
|
||||
});
|
||||
|
||||
spirv::Builder& b = SanitizeAndBuild();
|
||||
|
|
|
@ -251,7 +251,7 @@ OpDecorate %1 DescriptorSet 3
|
|||
}
|
||||
|
||||
struct BuiltinData {
|
||||
ast::BuiltinValue builtin;
|
||||
builtin::BuiltinValue builtin;
|
||||
type::AddressSpace storage;
|
||||
SpvBuiltIn result;
|
||||
};
|
||||
|
@ -271,32 +271,35 @@ INSTANTIATE_TEST_SUITE_P(
|
|||
BuilderTest_Type,
|
||||
BuiltinDataTest,
|
||||
testing::Values(
|
||||
BuiltinData{ast::BuiltinValue::kUndefined, type::AddressSpace::kNone, SpvBuiltInMax},
|
||||
BuiltinData{ast::BuiltinValue::kPosition, type::AddressSpace::kIn, SpvBuiltInFragCoord},
|
||||
BuiltinData{ast::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition},
|
||||
BuiltinData{builtin::BuiltinValue::kUndefined, type::AddressSpace::kNone, SpvBuiltInMax},
|
||||
BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kIn, SpvBuiltInFragCoord},
|
||||
BuiltinData{builtin::BuiltinValue::kPosition, type::AddressSpace::kOut, SpvBuiltInPosition},
|
||||
BuiltinData{
|
||||
ast::BuiltinValue::kVertexIndex,
|
||||
builtin::BuiltinValue::kVertexIndex,
|
||||
type::AddressSpace::kIn,
|
||||
SpvBuiltInVertexIndex,
|
||||
},
|
||||
BuiltinData{ast::BuiltinValue::kInstanceIndex, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kInstanceIndex, type::AddressSpace::kIn,
|
||||
SpvBuiltInInstanceIndex},
|
||||
BuiltinData{ast::BuiltinValue::kFrontFacing, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kFrontFacing, type::AddressSpace::kIn,
|
||||
SpvBuiltInFrontFacing},
|
||||
BuiltinData{ast::BuiltinValue::kFragDepth, type::AddressSpace::kOut, SpvBuiltInFragDepth},
|
||||
BuiltinData{ast::BuiltinValue::kLocalInvocationId, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kFragDepth, type::AddressSpace::kOut,
|
||||
SpvBuiltInFragDepth},
|
||||
BuiltinData{builtin::BuiltinValue::kLocalInvocationId, type::AddressSpace::kIn,
|
||||
SpvBuiltInLocalInvocationId},
|
||||
BuiltinData{ast::BuiltinValue::kLocalInvocationIndex, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kLocalInvocationIndex, type::AddressSpace::kIn,
|
||||
SpvBuiltInLocalInvocationIndex},
|
||||
BuiltinData{ast::BuiltinValue::kGlobalInvocationId, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kGlobalInvocationId, type::AddressSpace::kIn,
|
||||
SpvBuiltInGlobalInvocationId},
|
||||
BuiltinData{ast::BuiltinValue::kWorkgroupId, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kWorkgroupId, type::AddressSpace::kIn,
|
||||
SpvBuiltInWorkgroupId},
|
||||
BuiltinData{ast::BuiltinValue::kNumWorkgroups, type::AddressSpace::kIn,
|
||||
BuiltinData{builtin::BuiltinValue::kNumWorkgroups, type::AddressSpace::kIn,
|
||||
SpvBuiltInNumWorkgroups},
|
||||
BuiltinData{ast::BuiltinValue::kSampleIndex, type::AddressSpace::kIn, SpvBuiltInSampleId},
|
||||
BuiltinData{ast::BuiltinValue::kSampleMask, type::AddressSpace::kIn, SpvBuiltInSampleMask},
|
||||
BuiltinData{ast::BuiltinValue::kSampleMask, type::AddressSpace::kOut,
|
||||
BuiltinData{builtin::BuiltinValue::kSampleIndex, type::AddressSpace::kIn,
|
||||
SpvBuiltInSampleId},
|
||||
BuiltinData{builtin::BuiltinValue::kSampleMask, type::AddressSpace::kIn,
|
||||
SpvBuiltInSampleMask},
|
||||
BuiltinData{builtin::BuiltinValue::kSampleMask, type::AddressSpace::kOut,
|
||||
SpvBuiltInSampleMask}));
|
||||
|
||||
TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
|
||||
|
|
|
@ -112,7 +112,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) {
|
|||
auto vec4 = ty.vec4<f32>();
|
||||
auto* coord = Param("coord", vec4,
|
||||
utils::Vector{
|
||||
Builtin(ast::BuiltinValue::kPosition),
|
||||
Builtin(builtin::BuiltinValue::kPosition),
|
||||
});
|
||||
auto* loc1 = Param("loc1", ty.f32(),
|
||||
utils::Vector{
|
||||
|
|
|
@ -268,7 +268,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithAttribute) {
|
|||
TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointAttributes) {
|
||||
auto* s = Structure(
|
||||
"S", utils::Vector{
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(ast::BuiltinValue::kVertexIndex)}),
|
||||
Member("a", ty.u32(), utils::Vector{Builtin(builtin::BuiltinValue::kVertexIndex)}),
|
||||
Member("b", ty.f32(), utils::Vector{Location(2_a)}),
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue