[hlsl-writer] Fix emission of struct aliases.
You can only typedef builtin types in HLSL. This Cl updates the struct emission to emit named structs instead of typedef'd structs. Bug: tint:7 Change-Id: I835b7f4d23bc225c730ef3f39c4572c043a58156 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26921 Commit-Queue: dan sinclair <dsinclair@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
parent
bfaa6f8e57
commit
1811639709
|
@ -137,11 +137,19 @@ std::string GeneratorImpl::current_ep_var_name(VarType type) {
|
||||||
|
|
||||||
bool GeneratorImpl::EmitAliasType(const ast::type::AliasType* alias) {
|
bool GeneratorImpl::EmitAliasType(const ast::type::AliasType* alias) {
|
||||||
make_indent();
|
make_indent();
|
||||||
|
|
||||||
|
if (alias->type()->IsStruct()) {
|
||||||
|
if (!EmitType(alias->type(), namer_.NameFor(alias->name()))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
out_ << ";" << std::endl;
|
||||||
|
} else {
|
||||||
out_ << "typedef ";
|
out_ << "typedef ";
|
||||||
if (!EmitType(alias->type(), "")) {
|
if (!EmitType(alias->type(), "")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl;
|
out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1268,7 +1276,12 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
||||||
// TODO(dsinclair): Block decoration?
|
// TODO(dsinclair): Block decoration?
|
||||||
// if (str->decoration() != ast::StructDecoration::kNone) {
|
// if (str->decoration() != ast::StructDecoration::kNone) {
|
||||||
// }
|
// }
|
||||||
out_ << "struct {" << std::endl;
|
out_ << "struct";
|
||||||
|
// If a name was provided for the struct emit it.
|
||||||
|
if (!name.empty()) {
|
||||||
|
out_ << " " << name;
|
||||||
|
}
|
||||||
|
out_ << " {" << std::endl;
|
||||||
|
|
||||||
increment_indent();
|
increment_indent();
|
||||||
for (const auto& mem : str->members()) {
|
for (const auto& mem : str->members()) {
|
||||||
|
|
|
@ -74,10 +74,10 @@ TEST_F(HlslGeneratorImplTest, EmitAliasType_Struct) {
|
||||||
ast::Module m;
|
ast::Module m;
|
||||||
GeneratorImpl g(&m);
|
GeneratorImpl g(&m);
|
||||||
ASSERT_TRUE(g.EmitAliasType(&alias)) << g.error();
|
ASSERT_TRUE(g.EmitAliasType(&alias)) << g.error();
|
||||||
EXPECT_EQ(g.result(), R"(typedef struct {
|
EXPECT_EQ(g.result(), R"(struct a {
|
||||||
float a;
|
float a;
|
||||||
int b;
|
int b;
|
||||||
} a;
|
};
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -402,9 +402,9 @@ TEST_F(HlslGeneratorImplTest, Emit_Function_EntryPoint_With_UniformStruct) {
|
||||||
|
|
||||||
GeneratorImpl g(&mod);
|
GeneratorImpl g(&mod);
|
||||||
ASSERT_TRUE(g.Generate()) << g.error();
|
ASSERT_TRUE(g.Generate()) << g.error();
|
||||||
EXPECT_EQ(g.result(), R"(typedef struct {
|
EXPECT_EQ(g.result(), R"(struct Uniforms {
|
||||||
vector<float, 4> coord;
|
vector<float, 4> coord;
|
||||||
} Uniforms;
|
};
|
||||||
|
|
||||||
ConstantBuffer<Uniforms> uniforms : register(b0);
|
ConstantBuffer<Uniforms> uniforms : register(b0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue