Replace FunctionDecoration::(Is|As)Workgroup with Castable
Change-Id: Ia365504fd745579b3bd7bef0b6eda73d3164f539 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34312 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
75828dbaee
commit
731372f0b4
|
@ -55,8 +55,8 @@ Function::~Function() = default;
|
||||||
|
|
||||||
std::tuple<uint32_t, uint32_t, uint32_t> Function::workgroup_size() const {
|
std::tuple<uint32_t, uint32_t, uint32_t> Function::workgroup_size() const {
|
||||||
for (auto* deco : decorations_) {
|
for (auto* deco : decorations_) {
|
||||||
if (deco->IsWorkgroup()) {
|
if (auto* workgroup = deco->As<WorkgroupDecoration>()) {
|
||||||
return deco->AsWorkgroup()->values();
|
return workgroup->values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {1, 1, 1};
|
return {1, 1, 1};
|
||||||
|
|
|
@ -14,10 +14,6 @@
|
||||||
|
|
||||||
#include "src/ast/function_decoration.h"
|
#include "src/ast/function_decoration.h"
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "src/ast/workgroup_decoration.h"
|
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
|
@ -31,14 +27,5 @@ DecorationKind FunctionDecoration::GetKind() const {
|
||||||
return Kind;
|
return Kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionDecoration::IsWorkgroup() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const WorkgroupDecoration* FunctionDecoration::AsWorkgroup() const {
|
|
||||||
assert(IsWorkgroup());
|
|
||||||
return static_cast<const WorkgroupDecoration*>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace ast
|
} // namespace ast
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
|
||||||
class WorkgroupDecoration;
|
|
||||||
|
|
||||||
/// A decoration attached to a function
|
/// A decoration attached to a function
|
||||||
class FunctionDecoration : public Castable<FunctionDecoration, Decoration> {
|
class FunctionDecoration : public Castable<FunctionDecoration, Decoration> {
|
||||||
public:
|
public:
|
||||||
|
@ -37,12 +35,6 @@ class FunctionDecoration : public Castable<FunctionDecoration, Decoration> {
|
||||||
/// @return the decoration kind
|
/// @return the decoration kind
|
||||||
DecorationKind GetKind() const override;
|
DecorationKind GetKind() const override;
|
||||||
|
|
||||||
/// @returns true if this is a workgroup decoration
|
|
||||||
virtual bool IsWorkgroup() const;
|
|
||||||
|
|
||||||
/// @returns the decoration as a workgroup decoration
|
|
||||||
const WorkgroupDecoration* AsWorkgroup() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param source the source of this decoration
|
/// @param source the source of this decoration
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "src/ast/test_helper.h"
|
#include "src/ast/test_helper.h"
|
||||||
|
#include "src/ast/workgroup_decoration.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
|
@ -32,8 +33,8 @@ TEST_F(StageDecorationTest, Creation_1param) {
|
||||||
TEST_F(StageDecorationTest, Is) {
|
TEST_F(StageDecorationTest, Is) {
|
||||||
StageDecoration sd{ast::PipelineStage::kFragment, Source{}};
|
StageDecoration sd{ast::PipelineStage::kFragment, Source{}};
|
||||||
Decoration* d = &sd;
|
Decoration* d = &sd;
|
||||||
EXPECT_FALSE(sd.IsWorkgroup());
|
EXPECT_FALSE(d->Is<WorkgroupDecoration>());
|
||||||
EXPECT_TRUE(d->Is<ast::StageDecoration>());
|
EXPECT_TRUE(d->Is<StageDecoration>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(StageDecorationTest, ToStr) {
|
TEST_F(StageDecorationTest, ToStr) {
|
||||||
|
|
|
@ -33,10 +33,6 @@ WorkgroupDecoration::WorkgroupDecoration(uint32_t x,
|
||||||
|
|
||||||
WorkgroupDecoration::~WorkgroupDecoration() = default;
|
WorkgroupDecoration::~WorkgroupDecoration() = default;
|
||||||
|
|
||||||
bool WorkgroupDecoration::IsWorkgroup() const {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkgroupDecoration::to_str(std::ostream& out, size_t indent) const {
|
void WorkgroupDecoration::to_str(std::ostream& out, size_t indent) const {
|
||||||
make_indent(out, indent);
|
make_indent(out, indent);
|
||||||
out << "WorkgroupDecoration{" << x_ << " " << y_ << " " << z_ << "}"
|
out << "WorkgroupDecoration{" << x_ << " " << y_ << " " << z_ << "}"
|
||||||
|
|
|
@ -45,9 +45,6 @@ class WorkgroupDecoration
|
||||||
WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source);
|
WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source);
|
||||||
~WorkgroupDecoration() override;
|
~WorkgroupDecoration() override;
|
||||||
|
|
||||||
/// @returns true if this is a workgroup decoration
|
|
||||||
bool IsWorkgroup() const override;
|
|
||||||
|
|
||||||
/// @returns the workgroup dimensions
|
/// @returns the workgroup dimensions
|
||||||
std::tuple<uint32_t, uint32_t, uint32_t> values() const {
|
std::tuple<uint32_t, uint32_t, uint32_t> values() const {
|
||||||
return {x_, y_, z_};
|
return {x_, y_, z_};
|
||||||
|
|
|
@ -60,7 +60,7 @@ TEST_F(WorkgroupDecorationTest, Creation_3param) {
|
||||||
TEST_F(WorkgroupDecorationTest, Is) {
|
TEST_F(WorkgroupDecorationTest, Is) {
|
||||||
WorkgroupDecoration wd{2, 4, 6, Source{}};
|
WorkgroupDecoration wd{2, 4, 6, Source{}};
|
||||||
Decoration* d = &wd;
|
Decoration* d = &wd;
|
||||||
EXPECT_TRUE(wd.IsWorkgroup());
|
EXPECT_TRUE(d->Is<WorkgroupDecoration>());
|
||||||
EXPECT_FALSE(d->Is<StageDecoration>());
|
EXPECT_FALSE(d->Is<StageDecoration>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,12 +74,12 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) {
|
||||||
|
|
||||||
auto& decorations = f->decorations();
|
auto& decorations = f->decorations();
|
||||||
ASSERT_EQ(decorations.size(), 1u);
|
ASSERT_EQ(decorations.size(), 1u);
|
||||||
ASSERT_TRUE(decorations[0]->IsWorkgroup());
|
ASSERT_TRUE(decorations[0]->Is<ast::WorkgroupDecoration>());
|
||||||
|
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
std::tie(x, y, z) = decorations[0]->AsWorkgroup()->values();
|
std::tie(x, y, z) = decorations[0]->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 2u);
|
EXPECT_EQ(x, 2u);
|
||||||
EXPECT_EQ(y, 3u);
|
EXPECT_EQ(y, 3u);
|
||||||
EXPECT_EQ(z, 4u);
|
EXPECT_EQ(z, 4u);
|
||||||
|
@ -116,14 +116,14 @@ fn main() -> void { return; })");
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
ASSERT_TRUE(decorations[0]->IsWorkgroup());
|
ASSERT_TRUE(decorations[0]->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = decorations[0]->AsWorkgroup()->values();
|
std::tie(x, y, z) = decorations[0]->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 2u);
|
EXPECT_EQ(x, 2u);
|
||||||
EXPECT_EQ(y, 3u);
|
EXPECT_EQ(y, 3u);
|
||||||
EXPECT_EQ(z, 4u);
|
EXPECT_EQ(z, 4u);
|
||||||
|
|
||||||
ASSERT_TRUE(decorations[1]->IsWorkgroup());
|
ASSERT_TRUE(decorations[1]->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = decorations[1]->AsWorkgroup()->values();
|
std::tie(x, y, z) = decorations[1]->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 5u);
|
EXPECT_EQ(x, 5u);
|
||||||
EXPECT_EQ(y, 6u);
|
EXPECT_EQ(y, 6u);
|
||||||
EXPECT_EQ(z, 7u);
|
EXPECT_EQ(z, 7u);
|
||||||
|
@ -161,14 +161,14 @@ fn main() -> void { return; })");
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
ASSERT_TRUE(decos[0]->IsWorkgroup());
|
ASSERT_TRUE(decos[0]->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = decos[0]->AsWorkgroup()->values();
|
std::tie(x, y, z) = decos[0]->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 2u);
|
EXPECT_EQ(x, 2u);
|
||||||
EXPECT_EQ(y, 3u);
|
EXPECT_EQ(y, 3u);
|
||||||
EXPECT_EQ(z, 4u);
|
EXPECT_EQ(z, 4u);
|
||||||
|
|
||||||
ASSERT_TRUE(decos[1]->IsWorkgroup());
|
ASSERT_TRUE(decos[1]->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = decos[1]->AsWorkgroup()->values();
|
std::tie(x, y, z) = decos[1]->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 5u);
|
EXPECT_EQ(x, 5u);
|
||||||
EXPECT_EQ(y, 6u);
|
EXPECT_EQ(y, 6u);
|
||||||
EXPECT_EQ(z, 7u);
|
EXPECT_EQ(z, 7u);
|
||||||
|
|
|
@ -38,12 +38,12 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) {
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
ASSERT_TRUE(deco_0->IsWorkgroup());
|
ASSERT_TRUE(deco_0->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = deco_0->AsWorkgroup()->values();
|
std::tie(x, y, z) = deco_0->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 2u);
|
EXPECT_EQ(x, 2u);
|
||||||
|
|
||||||
ASSERT_TRUE(deco_1->IsWorkgroup());
|
ASSERT_TRUE(deco_1->Is<ast::WorkgroupDecoration>());
|
||||||
std::tie(x, y, z) = deco_1->AsWorkgroup()->values();
|
std::tie(x, y, z) = deco_1->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 3u);
|
EXPECT_EQ(x, 3u);
|
||||||
EXPECT_EQ(y, 4u);
|
EXPECT_EQ(y, 4u);
|
||||||
EXPECT_EQ(z, 5u);
|
EXPECT_EQ(z, 5u);
|
||||||
|
|
|
@ -32,12 +32,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup) {
|
||||||
ASSERT_FALSE(p->has_error());
|
ASSERT_FALSE(p->has_error());
|
||||||
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
||||||
ASSERT_NE(func_deco, nullptr);
|
ASSERT_NE(func_deco, nullptr);
|
||||||
ASSERT_TRUE(func_deco->IsWorkgroup());
|
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
|
||||||
|
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
std::tie(x, y, z) = func_deco->AsWorkgroup()->values();
|
std::tie(x, y, z) = func_deco->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 4u);
|
EXPECT_EQ(x, 4u);
|
||||||
EXPECT_EQ(y, 1u);
|
EXPECT_EQ(y, 1u);
|
||||||
EXPECT_EQ(z, 1u);
|
EXPECT_EQ(z, 1u);
|
||||||
|
@ -52,12 +52,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) {
|
||||||
ASSERT_FALSE(p->has_error());
|
ASSERT_FALSE(p->has_error());
|
||||||
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
||||||
ASSERT_NE(func_deco, nullptr) << p->error();
|
ASSERT_NE(func_deco, nullptr) << p->error();
|
||||||
ASSERT_TRUE(func_deco->IsWorkgroup());
|
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
|
||||||
|
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
std::tie(x, y, z) = func_deco->AsWorkgroup()->values();
|
std::tie(x, y, z) = func_deco->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 4u);
|
EXPECT_EQ(x, 4u);
|
||||||
EXPECT_EQ(y, 5u);
|
EXPECT_EQ(y, 5u);
|
||||||
EXPECT_EQ(z, 1u);
|
EXPECT_EQ(z, 1u);
|
||||||
|
@ -72,12 +72,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) {
|
||||||
ASSERT_FALSE(p->has_error());
|
ASSERT_FALSE(p->has_error());
|
||||||
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
auto* func_deco = deco.value->As<ast::FunctionDecoration>();
|
||||||
ASSERT_NE(func_deco, nullptr);
|
ASSERT_NE(func_deco, nullptr);
|
||||||
ASSERT_TRUE(func_deco->IsWorkgroup());
|
ASSERT_TRUE(func_deco->Is<ast::WorkgroupDecoration>());
|
||||||
|
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
std::tie(x, y, z) = func_deco->AsWorkgroup()->values();
|
std::tie(x, y, z) = func_deco->As<ast::WorkgroupDecoration>()->values();
|
||||||
EXPECT_EQ(x, 4u);
|
EXPECT_EQ(x, 4u);
|
||||||
EXPECT_EQ(y, 5u);
|
EXPECT_EQ(y, 5u);
|
||||||
EXPECT_EQ(z, 6u);
|
EXPECT_EQ(z, 6u);
|
||||||
|
|
|
@ -346,11 +346,11 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) {
|
||||||
for (auto* deco : func->decorations()) {
|
for (auto* deco : func->decorations()) {
|
||||||
make_indent();
|
make_indent();
|
||||||
out_ << "[[";
|
out_ << "[[";
|
||||||
if (deco->IsWorkgroup()) {
|
if (auto* workgroup = deco->As<ast::WorkgroupDecoration>()) {
|
||||||
uint32_t x = 0;
|
uint32_t x = 0;
|
||||||
uint32_t y = 0;
|
uint32_t y = 0;
|
||||||
uint32_t z = 0;
|
uint32_t z = 0;
|
||||||
std::tie(x, y, z) = deco->AsWorkgroup()->values();
|
std::tie(x, y, z) = workgroup->values();
|
||||||
out_ << "workgroup_size(" << std::to_string(x) << ", "
|
out_ << "workgroup_size(" << std::to_string(x) << ", "
|
||||||
<< std::to_string(y) << ", " << std::to_string(z) << ")";
|
<< std::to_string(y) << ", " << std::to_string(z) << ")";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue