mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-09 06:35:54 +00:00
Replace VariableDecoration::(Is|As)Location with Castable
Change-Id: I3096045fc093f3782401ce8623a18e0bca49b22c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34309 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
0482b54782
commit
2c1d7d5be7
@ -14,8 +14,8 @@
|
|||||||
|
|
||||||
#include "src/ast/binding_decoration.h"
|
#include "src/ast/binding_decoration.h"
|
||||||
|
|
||||||
#include "src/ast/test_helper.h"
|
|
||||||
#include "src/ast/constant_id_decoration.h"
|
#include "src/ast/constant_id_decoration.h"
|
||||||
|
#include "src/ast/test_helper.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
@ -34,7 +34,7 @@ TEST_F(BindingDecorationTest, Is) {
|
|||||||
EXPECT_TRUE(d->Is<BindingDecoration>());
|
EXPECT_TRUE(d->Is<BindingDecoration>());
|
||||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||||
EXPECT_FALSE(bd.IsLocation());
|
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||||
EXPECT_FALSE(bd.IsSet());
|
EXPECT_FALSE(bd.IsSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ TEST_F(BuiltinDecorationTest, Is) {
|
|||||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||||
EXPECT_TRUE(d->Is<BuiltinDecoration>());
|
EXPECT_TRUE(d->Is<BuiltinDecoration>());
|
||||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||||
EXPECT_FALSE(bd.IsLocation());
|
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||||
EXPECT_FALSE(bd.IsSet());
|
EXPECT_FALSE(bd.IsSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ TEST_F(ConstantIdDecorationTest, Is) {
|
|||||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||||
EXPECT_TRUE(d->Is<ConstantIdDecoration>());
|
EXPECT_TRUE(d->Is<ConstantIdDecoration>());
|
||||||
EXPECT_FALSE(cd.IsLocation());
|
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||||
EXPECT_FALSE(cd.IsSet());
|
EXPECT_FALSE(cd.IsSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "src/ast/builtin_decoration.h"
|
#include "src/ast/builtin_decoration.h"
|
||||||
#include "src/ast/constant_id_decoration.h"
|
#include "src/ast/constant_id_decoration.h"
|
||||||
|
#include "src/ast/location_decoration.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
@ -33,7 +34,7 @@ DecoratedVariable::~DecoratedVariable() = default;
|
|||||||
|
|
||||||
bool DecoratedVariable::HasLocationDecoration() const {
|
bool DecoratedVariable::HasLocationDecoration() const {
|
||||||
for (auto* deco : decorations_) {
|
for (auto* deco : decorations_) {
|
||||||
if (deco->IsLocation()) {
|
if (deco->Is<LocationDecoration>()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,8 +89,8 @@ Function::referenced_location_variables() const {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto* deco : var->AsDecorated()->decorations()) {
|
for (auto* deco : var->AsDecorated()->decorations()) {
|
||||||
if (deco->IsLocation()) {
|
if (auto* location = deco->As<LocationDecoration>()) {
|
||||||
ret.push_back({var, deco->AsLocation()});
|
ret.push_back({var, location});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,6 @@ LocationDecoration::LocationDecoration(uint32_t val, const Source& source)
|
|||||||
|
|
||||||
LocationDecoration::~LocationDecoration() = default;
|
LocationDecoration::~LocationDecoration() = default;
|
||||||
|
|
||||||
bool LocationDecoration::IsLocation() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocationDecoration::to_str(std::ostream& out, size_t indent) const {
|
void LocationDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||||
make_indent(out, indent);
|
make_indent(out, indent);
|
||||||
out << "LocationDecoration{" << value_ << "}" << std::endl;
|
out << "LocationDecoration{" << value_ << "}" << std::endl;
|
||||||
|
@ -32,9 +32,6 @@ class LocationDecoration
|
|||||||
explicit LocationDecoration(uint32_t value, const Source& source);
|
explicit LocationDecoration(uint32_t value, const Source& source);
|
||||||
~LocationDecoration() override;
|
~LocationDecoration() override;
|
||||||
|
|
||||||
/// @returns true if this is a location decoration
|
|
||||||
bool IsLocation() const override;
|
|
||||||
|
|
||||||
/// @returns the location value
|
/// @returns the location value
|
||||||
uint32_t value() const { return value_; }
|
uint32_t value() const { return value_; }
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ TEST_F(LocationDecorationTest, Is) {
|
|||||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||||
EXPECT_TRUE(ld.IsLocation());
|
EXPECT_TRUE(d->Is<LocationDecoration>());
|
||||||
EXPECT_FALSE(ld.IsSet());
|
EXPECT_FALSE(ld.IsSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ TEST_F(SetDecorationTest, Is) {
|
|||||||
EXPECT_FALSE(d->Is<BindingDecoration>());
|
EXPECT_FALSE(d->Is<BindingDecoration>());
|
||||||
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
EXPECT_FALSE(d->Is<BuiltinDecoration>());
|
||||||
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
EXPECT_FALSE(d->Is<ConstantIdDecoration>());
|
||||||
EXPECT_FALSE(sd.IsLocation());
|
EXPECT_FALSE(d->Is<LocationDecoration>());
|
||||||
EXPECT_TRUE(sd.IsSet());
|
EXPECT_TRUE(sd.IsSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "src/ast/location_decoration.h"
|
|
||||||
#include "src/ast/set_decoration.h"
|
#include "src/ast/set_decoration.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
@ -32,19 +31,10 @@ DecorationKind VariableDecoration::GetKind() const {
|
|||||||
return Kind;
|
return Kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VariableDecoration::IsLocation() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool VariableDecoration::IsSet() const {
|
bool VariableDecoration::IsSet() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationDecoration* VariableDecoration::AsLocation() {
|
|
||||||
assert(IsLocation());
|
|
||||||
return static_cast<LocationDecoration*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetDecoration* VariableDecoration::AsSet() {
|
SetDecoration* VariableDecoration::AsSet() {
|
||||||
assert(IsSet());
|
assert(IsSet());
|
||||||
return static_cast<SetDecoration*>(this);
|
return static_cast<SetDecoration*>(this);
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
class ConstantIdDecoration;
|
|
||||||
class LocationDecoration;
|
|
||||||
class SetDecoration;
|
class SetDecoration;
|
||||||
|
|
||||||
/// A decoration attached to a variable
|
/// A decoration attached to a variable
|
||||||
@ -40,13 +38,9 @@ class VariableDecoration : public Castable<VariableDecoration, Decoration> {
|
|||||||
/// @return the decoration kind
|
/// @return the decoration kind
|
||||||
DecorationKind GetKind() const override;
|
DecorationKind GetKind() const override;
|
||||||
|
|
||||||
/// @returns true if this is a location decoration
|
|
||||||
virtual bool IsLocation() const;
|
|
||||||
/// @returns true if this is a set decoration
|
/// @returns true if this is a set decoration
|
||||||
virtual bool IsSet() const;
|
virtual bool IsSet() const;
|
||||||
|
|
||||||
/// @returns the decoration as a location decoration
|
|
||||||
LocationDecoration* AsLocation();
|
|
||||||
/// @returns the decoration as a set decoration
|
/// @returns the decoration as a set decoration
|
||||||
SetDecoration* AsSet();
|
SetDecoration* AsSet();
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ TEST_F(ParserImplTest, VariableDecorationList_Parses) {
|
|||||||
ASSERT_NE(deco_0, nullptr);
|
ASSERT_NE(deco_0, nullptr);
|
||||||
ASSERT_NE(deco_1, nullptr);
|
ASSERT_NE(deco_1, nullptr);
|
||||||
|
|
||||||
ASSERT_TRUE(deco_0->IsLocation());
|
ASSERT_TRUE(deco_0->Is<ast::LocationDecoration>());
|
||||||
EXPECT_EQ(deco_0->AsLocation()->value(), 4u);
|
EXPECT_EQ(deco_0->As<ast::LocationDecoration>()->value(), 4u);
|
||||||
ASSERT_TRUE(deco_1->Is<ast::BuiltinDecoration>());
|
ASSERT_TRUE(deco_1->Is<ast::BuiltinDecoration>());
|
||||||
EXPECT_EQ(deco_1->As<ast::BuiltinDecoration>()->value(),
|
EXPECT_EQ(deco_1->As<ast::BuiltinDecoration>()->value(),
|
||||||
ast::Builtin::kPosition);
|
ast::Builtin::kPosition);
|
||||||
|
@ -34,9 +34,9 @@ TEST_F(ParserImplTest, VariableDecoration_Location) {
|
|||||||
auto* var_deco = deco.value->As<ast::VariableDecoration>();
|
auto* var_deco = deco.value->As<ast::VariableDecoration>();
|
||||||
ASSERT_NE(var_deco, nullptr);
|
ASSERT_NE(var_deco, nullptr);
|
||||||
ASSERT_FALSE(p->has_error());
|
ASSERT_FALSE(p->has_error());
|
||||||
ASSERT_TRUE(var_deco->IsLocation());
|
ASSERT_TRUE(var_deco->Is<ast::LocationDecoration>());
|
||||||
|
|
||||||
auto* loc = var_deco->AsLocation();
|
auto* loc = var_deco->As<ast::LocationDecoration>();
|
||||||
EXPECT_EQ(loc->value(), 4u);
|
EXPECT_EQ(loc->value(), 4u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,18 +200,16 @@ void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto* d : v->AsDecorated()->decorations()) {
|
for (auto* d : v->AsDecorated()->decorations()) {
|
||||||
if (!d->IsLocation()) {
|
if (auto* l = d->As<ast::LocationDecoration>()) {
|
||||||
continue;
|
uint32_t location = l->value();
|
||||||
|
// This is where the replacement happens. Expressions use identifier
|
||||||
|
// strings instead of pointers, so we don't need to update any other
|
||||||
|
// place in the AST.
|
||||||
|
v = create<ast::Variable>(v->name(), ast::StorageClass::kPrivate,
|
||||||
|
v->type());
|
||||||
|
location_to_var_[location] = v;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t location = d->AsLocation()->value();
|
|
||||||
// This is where the replacement happens. Expressions use identifier
|
|
||||||
// strings instead of pointers, so we don't need to update any other place
|
|
||||||
// in the AST.
|
|
||||||
v = create<ast::Variable>(v->name(), ast::StorageClass::kPrivate,
|
|
||||||
v->type());
|
|
||||||
location_to_var_[location] = v;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1377,15 +1377,14 @@ bool GeneratorImpl::EmitEntryPointData(
|
|||||||
}
|
}
|
||||||
|
|
||||||
out << " " << var->name() << " : ";
|
out << " " << var->name() << " : ";
|
||||||
if (deco->IsLocation()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
if (func->pipeline_stage() == ast::PipelineStage::kCompute) {
|
if (func->pipeline_stage() == ast::PipelineStage::kCompute) {
|
||||||
error_ = "invalid location variable for pipeline stage";
|
error_ = "invalid location variable for pipeline stage";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out << "TEXCOORD" << deco->AsLocation()->value();
|
out << "TEXCOORD" << location->value();
|
||||||
} else if (deco->Is<ast::BuiltinDecoration>()) {
|
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
||||||
auto attr =
|
auto attr = builtin_to_attribute(builtin->value());
|
||||||
builtin_to_attribute(deco->As<ast::BuiltinDecoration>()->value());
|
|
||||||
if (attr.empty()) {
|
if (attr.empty()) {
|
||||||
error_ = "unsupported builtin";
|
error_ = "unsupported builtin";
|
||||||
return false;
|
return false;
|
||||||
@ -1424,8 +1423,8 @@ bool GeneratorImpl::EmitEntryPointData(
|
|||||||
|
|
||||||
out << " " << var->name() << " : ";
|
out << " " << var->name() << " : ";
|
||||||
|
|
||||||
if (deco->IsLocation()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
auto loc = deco->AsLocation()->value();
|
auto loc = location->value();
|
||||||
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
||||||
out << "TEXCOORD" << loc;
|
out << "TEXCOORD" << loc;
|
||||||
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
||||||
@ -1434,9 +1433,8 @@ bool GeneratorImpl::EmitEntryPointData(
|
|||||||
error_ = "invalid location variable for pipeline stage";
|
error_ = "invalid location variable for pipeline stage";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (deco->Is<ast::BuiltinDecoration>()) {
|
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
||||||
auto attr =
|
auto attr = builtin_to_attribute(builtin->value());
|
||||||
builtin_to_attribute(deco->As<ast::BuiltinDecoration>()->value());
|
|
||||||
if (attr.empty()) {
|
if (attr.empty()) {
|
||||||
error_ = "unsupported builtin";
|
error_ = "unsupported builtin";
|
||||||
return false;
|
return false;
|
||||||
|
@ -1060,8 +1060,8 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
|
|||||||
|
|
||||||
out_ << " " << var->name() << " [[";
|
out_ << " " << var->name() << " [[";
|
||||||
|
|
||||||
if (deco->IsLocation()) {
|
if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
auto loc = deco->AsLocation()->value();
|
auto loc = location->value();
|
||||||
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
if (func->pipeline_stage() == ast::PipelineStage::kVertex) {
|
||||||
out_ << "user(locn" << loc << ")";
|
out_ << "user(locn" << loc << ")";
|
||||||
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
} else if (func->pipeline_stage() == ast::PipelineStage::kFragment) {
|
||||||
@ -1070,9 +1070,8 @@ bool GeneratorImpl::EmitEntryPointData(ast::Function* func) {
|
|||||||
error_ = "invalid location variable for pipeline stage";
|
error_ = "invalid location variable for pipeline stage";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (deco->Is<ast::BuiltinDecoration>()) {
|
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
||||||
auto attr =
|
auto attr = builtin_to_attribute(builtin->value());
|
||||||
builtin_to_attribute(deco->As<ast::BuiltinDecoration>()->value());
|
|
||||||
if (attr.empty()) {
|
if (attr.empty()) {
|
||||||
error_ = "unsupported builtin";
|
error_ = "unsupported builtin";
|
||||||
return false;
|
return false;
|
||||||
|
@ -784,10 +784,10 @@ bool Builder::GenerateGlobalVariable(ast::Variable* var) {
|
|||||||
push_annot(spv::Op::OpDecorate,
|
push_annot(spv::Op::OpDecorate,
|
||||||
{Operand::Int(var_id), Operand::Int(SpvDecorationBuiltIn),
|
{Operand::Int(var_id), Operand::Int(SpvDecorationBuiltIn),
|
||||||
Operand::Int(ConvertBuiltin(builtin->value()))});
|
Operand::Int(ConvertBuiltin(builtin->value()))});
|
||||||
} else if (deco->IsLocation()) {
|
} else if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
push_annot(spv::Op::OpDecorate,
|
push_annot(spv::Op::OpDecorate,
|
||||||
{Operand::Int(var_id), Operand::Int(SpvDecorationLocation),
|
{Operand::Int(var_id), Operand::Int(SpvDecorationLocation),
|
||||||
Operand::Int(deco->AsLocation()->value())});
|
Operand::Int(location->value())});
|
||||||
} else if (auto* binding = deco->As<ast::BindingDecoration>()) {
|
} else if (auto* binding = deco->As<ast::BindingDecoration>()) {
|
||||||
push_annot(spv::Op::OpDecorate,
|
push_annot(spv::Op::OpDecorate,
|
||||||
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
|
{Operand::Int(var_id), Operand::Int(SpvDecorationBinding),
|
||||||
|
@ -645,8 +645,8 @@ bool GeneratorImpl::EmitVariableDecorations(ast::DecoratedVariable* var) {
|
|||||||
out_ << "binding(" << binding->value() << ")";
|
out_ << "binding(" << binding->value() << ")";
|
||||||
} else if (deco->IsSet()) {
|
} else if (deco->IsSet()) {
|
||||||
out_ << "set(" << deco->AsSet()->value() << ")";
|
out_ << "set(" << deco->AsSet()->value() << ")";
|
||||||
} else if (deco->IsLocation()) {
|
} else if (auto* location = deco->As<ast::LocationDecoration>()) {
|
||||||
out_ << "location(" << deco->AsLocation()->value() << ")";
|
out_ << "location(" << location->value() << ")";
|
||||||
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
} else if (auto* builtin = deco->As<ast::BuiltinDecoration>()) {
|
||||||
out_ << "builtin(" << builtin->value() << ")";
|
out_ << "builtin(" << builtin->value() << ")";
|
||||||
} else if (auto* cid = deco->As<ast::ConstantIdDecoration>()) {
|
} else if (auto* cid = deco->As<ast::ConstantIdDecoration>()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user