[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) {
|
||||
make_indent();
|
||||
|
||||
if (alias->type()->IsStruct()) {
|
||||
if (!EmitType(alias->type(), namer_.NameFor(alias->name()))) {
|
||||
return false;
|
||||
}
|
||||
out_ << ";" << std::endl;
|
||||
} else {
|
||||
out_ << "typedef ";
|
||||
if (!EmitType(alias->type(), "")) {
|
||||
return false;
|
||||
}
|
||||
out_ << " " << namer_.NameFor(alias->name()) << ";" << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1268,7 +1276,12 @@ bool GeneratorImpl::EmitType(ast::type::Type* type, const std::string& name) {
|
|||
// TODO(dsinclair): Block decoration?
|
||||
// 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();
|
||||
for (const auto& mem : str->members()) {
|
||||
|
|
|
@ -74,10 +74,10 @@ TEST_F(HlslGeneratorImplTest, EmitAliasType_Struct) {
|
|||
ast::Module m;
|
||||
GeneratorImpl g(&m);
|
||||
ASSERT_TRUE(g.EmitAliasType(&alias)) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(typedef struct {
|
||||
EXPECT_EQ(g.result(), R"(struct a {
|
||||
float a;
|
||||
int b;
|
||||
} a;
|
||||
};
|
||||
)");
|
||||
}
|
||||
|
||||
|
|
|
@ -402,9 +402,9 @@ TEST_F(HlslGeneratorImplTest, Emit_Function_EntryPoint_With_UniformStruct) {
|
|||
|
||||
GeneratorImpl g(&mod);
|
||||
ASSERT_TRUE(g.Generate()) << g.error();
|
||||
EXPECT_EQ(g.result(), R"(typedef struct {
|
||||
EXPECT_EQ(g.result(), R"(struct Uniforms {
|
||||
vector<float, 4> coord;
|
||||
} Uniforms;
|
||||
};
|
||||
|
||||
ConstantBuffer<Uniforms> uniforms : register(b0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue