[ast] Rename Builtin::kSampleId to Builtin::kSampleIndex
Other builtins use WGSL terms instead of SPIR-V terms too, and the WGSL writer is relying on the output of `operator<<(Builtin)`, which just stringifies the name of the enum. This also matches the equivalent `semantic::Usage::kSampleIndex` enum. Added test coverage for WGSL builtin generation. Bug: tint:372 Change-Id: I8077d22c4a5ddf67b1ad07e7365453db74db8e7d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41660 Reviewed-by: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org> Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: James Price <jrprice@google.com>
This commit is contained in:
parent
d086c147d0
commit
e7dab3c9ea
|
@ -59,8 +59,8 @@ std::ostream& operator<<(std::ostream& out, Builtin builtin) {
|
||||||
out << "global_invocation_id";
|
out << "global_invocation_id";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Builtin::kSampleId: {
|
case Builtin::kSampleIndex: {
|
||||||
out << "sample_id";
|
out << "sample_index";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Builtin::kSampleMaskIn: {
|
case Builtin::kSampleMaskIn: {
|
||||||
|
|
|
@ -32,7 +32,7 @@ enum class Builtin {
|
||||||
kLocalInvocationId,
|
kLocalInvocationId,
|
||||||
kLocalInvocationIndex,
|
kLocalInvocationIndex,
|
||||||
kGlobalInvocationId,
|
kGlobalInvocationId,
|
||||||
kSampleId,
|
kSampleIndex,
|
||||||
kSampleMaskIn,
|
kSampleMaskIn,
|
||||||
kSampleMaskOut,
|
kSampleMaskOut,
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ ast::Builtin EnumConverter::ToBuiltin(SpvBuiltIn b, ast::StorageClass sc) {
|
||||||
case SpvBuiltInGlobalInvocationId:
|
case SpvBuiltInGlobalInvocationId:
|
||||||
return ast::Builtin::kGlobalInvocationId;
|
return ast::Builtin::kGlobalInvocationId;
|
||||||
case SpvBuiltInSampleId:
|
case SpvBuiltInSampleId:
|
||||||
return ast::Builtin::kSampleId;
|
return ast::Builtin::kSampleIndex;
|
||||||
case SpvBuiltInSampleMask:
|
case SpvBuiltInSampleMask:
|
||||||
return sc == ast::StorageClass::kInput ? ast::Builtin::kSampleMaskIn
|
return sc == ast::StorageClass::kInput ? ast::Builtin::kSampleMaskIn
|
||||||
: ast::Builtin::kSampleMaskOut;
|
: ast::Builtin::kSampleMaskOut;
|
||||||
|
|
|
@ -225,7 +225,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
BuiltinCase{SpvBuiltInGlobalInvocationId, ast::StorageClass::kInput,
|
BuiltinCase{SpvBuiltInGlobalInvocationId, ast::StorageClass::kInput,
|
||||||
true, ast::Builtin::kGlobalInvocationId},
|
true, ast::Builtin::kGlobalInvocationId},
|
||||||
BuiltinCase{SpvBuiltInSampleId, ast::StorageClass::kInput, true,
|
BuiltinCase{SpvBuiltInSampleId, ast::StorageClass::kInput, true,
|
||||||
ast::Builtin::kSampleId},
|
ast::Builtin::kSampleIndex},
|
||||||
BuiltinCase{SpvBuiltInSampleMask, ast::StorageClass::kInput, true,
|
BuiltinCase{SpvBuiltInSampleMask, ast::StorageClass::kInput, true,
|
||||||
ast::Builtin::kSampleMaskIn}));
|
ast::Builtin::kSampleMaskIn}));
|
||||||
|
|
||||||
|
|
|
@ -2062,7 +2062,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_Direct) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2104,7 +2104,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_CopyObject) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2146,7 +2146,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_I32_Load_AccessChain) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2213,7 +2213,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_Direct) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2252,7 +2252,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_CopyObject) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2301,7 +2301,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_Load_AccessChain) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
@ -2349,7 +2349,7 @@ TEST_F(SpvModuleScopeVarParserTest, SampleId_U32_FunctParam) {
|
||||||
EXPECT_THAT(module_str, HasSubstr(R"(
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
Variable{
|
Variable{
|
||||||
Decorations{
|
Decorations{
|
||||||
BuiltinDecoration{sample_id}
|
BuiltinDecoration{sample_index}
|
||||||
}
|
}
|
||||||
x_1
|
x_1
|
||||||
in
|
in
|
||||||
|
|
|
@ -1776,7 +1776,7 @@ std::string GeneratorImpl::builtin_to_attribute(ast::Builtin builtin) const {
|
||||||
return "SV_GroupIndex";
|
return "SV_GroupIndex";
|
||||||
case ast::Builtin::kGlobalInvocationId:
|
case ast::Builtin::kGlobalInvocationId:
|
||||||
return "SV_DispatchThreadID";
|
return "SV_DispatchThreadID";
|
||||||
case ast::Builtin::kSampleId:
|
case ast::Builtin::kSampleIndex:
|
||||||
return "SV_SampleIndex";
|
return "SV_SampleIndex";
|
||||||
case ast::Builtin::kSampleMaskIn:
|
case ast::Builtin::kSampleMaskIn:
|
||||||
return "SV_Coverage";
|
return "SV_Coverage";
|
||||||
|
|
|
@ -96,7 +96,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
HlslBuiltinData{ast::Builtin::kLocalInvocationIndex, "SV_GroupIndex"},
|
HlslBuiltinData{ast::Builtin::kLocalInvocationIndex, "SV_GroupIndex"},
|
||||||
HlslBuiltinData{ast::Builtin::kGlobalInvocationId,
|
HlslBuiltinData{ast::Builtin::kGlobalInvocationId,
|
||||||
"SV_DispatchThreadID"},
|
"SV_DispatchThreadID"},
|
||||||
HlslBuiltinData{ast::Builtin::kSampleId, "SV_SampleIndex"},
|
HlslBuiltinData{ast::Builtin::kSampleIndex, "SV_SampleIndex"},
|
||||||
HlslBuiltinData{ast::Builtin::kSampleMaskIn, "SV_Coverage"},
|
HlslBuiltinData{ast::Builtin::kSampleMaskIn, "SV_Coverage"},
|
||||||
HlslBuiltinData{ast::Builtin::kSampleMaskOut, "SV_Coverage"}));
|
HlslBuiltinData{ast::Builtin::kSampleMaskOut, "SV_Coverage"}));
|
||||||
|
|
||||||
|
|
|
@ -1455,7 +1455,7 @@ std::string GeneratorImpl::builtin_to_attribute(ast::Builtin builtin) const {
|
||||||
return "thread_index_in_threadgroup";
|
return "thread_index_in_threadgroup";
|
||||||
case ast::Builtin::kGlobalInvocationId:
|
case ast::Builtin::kGlobalInvocationId:
|
||||||
return "thread_position_in_grid";
|
return "thread_position_in_grid";
|
||||||
case ast::Builtin::kSampleId:
|
case ast::Builtin::kSampleIndex:
|
||||||
return "sample_id";
|
return "sample_id";
|
||||||
case ast::Builtin::kSampleMaskIn:
|
case ast::Builtin::kSampleMaskIn:
|
||||||
return "sample_mask";
|
return "sample_mask";
|
||||||
|
|
|
@ -120,7 +120,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
"thread_index_in_threadgroup"},
|
"thread_index_in_threadgroup"},
|
||||||
MslBuiltinData{ast::Builtin::kGlobalInvocationId,
|
MslBuiltinData{ast::Builtin::kGlobalInvocationId,
|
||||||
"thread_position_in_grid"},
|
"thread_position_in_grid"},
|
||||||
MslBuiltinData{ast::Builtin::kSampleId, "sample_id"},
|
MslBuiltinData{ast::Builtin::kSampleIndex, "sample_id"},
|
||||||
MslBuiltinData{ast::Builtin::kSampleMaskIn, "sample_mask"},
|
MslBuiltinData{ast::Builtin::kSampleMaskIn, "sample_mask"},
|
||||||
MslBuiltinData{ast::Builtin::kSampleMaskOut,
|
MslBuiltinData{ast::Builtin::kSampleMaskOut,
|
||||||
"sample_mask"}));
|
"sample_mask"}));
|
||||||
|
|
|
@ -3194,7 +3194,7 @@ SpvBuiltIn Builder::ConvertBuiltin(ast::Builtin builtin) const {
|
||||||
return SpvBuiltInGlobalInvocationId;
|
return SpvBuiltInGlobalInvocationId;
|
||||||
case ast::Builtin::kPointSize:
|
case ast::Builtin::kPointSize:
|
||||||
return SpvBuiltInPointSize;
|
return SpvBuiltInPointSize;
|
||||||
case ast::Builtin::kSampleId: // TODO(dneto)
|
case ast::Builtin::kSampleIndex: // TODO(dneto)
|
||||||
case ast::Builtin::kSampleMaskIn: // TODO(dneto)
|
case ast::Builtin::kSampleMaskIn: // TODO(dneto)
|
||||||
case ast::Builtin::kSampleMaskOut: // TODO(dneto)
|
case ast::Builtin::kSampleMaskOut: // TODO(dneto)
|
||||||
case ast::Builtin::kNone:
|
case ast::Builtin::kNone:
|
||||||
|
|
|
@ -18,7 +18,9 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/function.h"
|
#include "src/ast/function.h"
|
||||||
|
#include "src/ast/variable.h"
|
||||||
#include "src/program.h"
|
#include "src/program.h"
|
||||||
|
#include "src/semantic/variable.h"
|
||||||
#include "src/type/void_type.h"
|
#include "src/type/void_type.h"
|
||||||
#include "src/writer/wgsl/test_helper.h"
|
#include "src/writer/wgsl/test_helper.h"
|
||||||
|
|
||||||
|
@ -41,6 +43,50 @@ TEST_F(WgslGeneratorImplTest, Generate) {
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct WgslBuiltinData {
|
||||||
|
ast::Builtin builtin;
|
||||||
|
const char* attribute_name;
|
||||||
|
};
|
||||||
|
inline std::ostream& operator<<(std::ostream& out, WgslBuiltinData data) {
|
||||||
|
out << data.builtin;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
using WgslBuiltinConversionTest = TestParamHelper<WgslBuiltinData>;
|
||||||
|
TEST_P(WgslBuiltinConversionTest, Emit) {
|
||||||
|
auto params = GetParam();
|
||||||
|
|
||||||
|
auto* var = Global("a", ast::StorageClass::kNone, ty.f32(), nullptr,
|
||||||
|
ast::VariableDecorationList{
|
||||||
|
create<ast::BuiltinDecoration>(params.builtin),
|
||||||
|
});
|
||||||
|
|
||||||
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
gen.EmitVariableDecorations(program->Sem().Get(var));
|
||||||
|
|
||||||
|
EXPECT_EQ(gen.result(),
|
||||||
|
"[[builtin(" + std::string(params.attribute_name) + ")]] ");
|
||||||
|
}
|
||||||
|
INSTANTIATE_TEST_SUITE_P(
|
||||||
|
WgslGeneratorImplTest,
|
||||||
|
WgslBuiltinConversionTest,
|
||||||
|
testing::Values(
|
||||||
|
WgslBuiltinData{ast::Builtin::kPosition, "position"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kVertexIndex, "vertex_index"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kInstanceIndex, "instance_index"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kFrontFacing, "front_facing"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kFragCoord, "frag_coord"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kFragDepth, "frag_depth"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kLocalInvocationId,
|
||||||
|
"local_invocation_id"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kLocalInvocationIndex,
|
||||||
|
"local_invocation_index"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kGlobalInvocationId,
|
||||||
|
"global_invocation_id"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kSampleIndex, "sample_index"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kSampleMaskIn, "sample_mask_in"},
|
||||||
|
WgslBuiltinData{ast::Builtin::kSampleMaskOut, "sample_mask_out"}));
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
|
|
|
@ -43,16 +43,17 @@ class TestHelperBase : public BASE, public ProgramBuilder {
|
||||||
if (gen_) {
|
if (gen_) {
|
||||||
return *gen_;
|
return *gen_;
|
||||||
}
|
}
|
||||||
program_ = std::make_unique<Program>(std::move(*this));
|
program = std::make_unique<Program>(std::move(*this));
|
||||||
gen_ = std::make_unique<GeneratorImpl>(program_.get());
|
gen_ = std::make_unique<GeneratorImpl>(program.get());
|
||||||
return *gen_;
|
return *gen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type determiner
|
/// The type determiner
|
||||||
TypeDeterminer td;
|
TypeDeterminer td;
|
||||||
|
// The program built with a call to Build()
|
||||||
|
std::unique_ptr<Program> program;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Program> program_;
|
|
||||||
std::unique_ptr<GeneratorImpl> gen_;
|
std::unique_ptr<GeneratorImpl> gen_;
|
||||||
};
|
};
|
||||||
using TestHelper = TestHelperBase<testing::Test>;
|
using TestHelper = TestHelperBase<testing::Test>;
|
||||||
|
|
Loading…
Reference in New Issue