mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 07:36:15 +00:00
tint/writer/wgsl: Print @offset attributes as comment
We use WGSL to visualize the AST. Make sure we don't hide anything. Bug: tint:1776 Change-Id: Iedd7ca797fb745d9db7d0aba8a5718039241afbb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112602 Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Ben Clayton <bclayton@google.com> Auto-Submit: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
f745e4e2bf
commit
efb17b0254
@@ -953,7 +953,9 @@ TEST_F(SpvParserMemoryTest, RemapStorageBuffer_TypesAndVarDeclarations) {
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(type RTArr = @stride(4) array<u32>;
|
||||
|
||||
struct S {
|
||||
/* @offset(0) */
|
||||
field0 : u32,
|
||||
/* @offset(4) */
|
||||
field1 : RTArr,
|
||||
}
|
||||
|
||||
|
||||
@@ -1254,8 +1254,11 @@ TEST_F(SpvModuleScopeVarParserTest, StructMember_NonReadableDecoration_Dropped)
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(type Arr = @stride(4) array<u32, 2u>;
|
||||
|
||||
struct S {
|
||||
/* @offset(0) */
|
||||
field0 : u32,
|
||||
/* @offset(4) */
|
||||
field1 : f32,
|
||||
/* @offset(8) */
|
||||
field2 : Arr,
|
||||
}
|
||||
|
||||
@@ -1286,6 +1289,7 @@ TEST_F(SpvModuleScopeVarParserTest, ColMajorDecoration_Dropped) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
field0 : mat3x2<f32>,
|
||||
}
|
||||
|
||||
@@ -1316,6 +1320,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration_Natural_Dropped) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
field0 : mat3x2<f32>,
|
||||
}
|
||||
|
||||
@@ -1346,6 +1351,7 @@ TEST_F(SpvModuleScopeVarParserTest, MatrixStrideDecoration) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
@stride(64) @internal(disable_validation__ignore_stride)
|
||||
field0 : mat3x2<f32>,
|
||||
}
|
||||
@@ -1399,7 +1405,9 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_AllMembers) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
field0 : f32,
|
||||
/* @offset(4) */
|
||||
field1 : f32,
|
||||
}
|
||||
|
||||
@@ -1428,7 +1436,9 @@ TEST_F(SpvModuleScopeVarParserTest, StorageBuffer_NonWritable_NotAllMembers) {
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
field0 : f32,
|
||||
/* @offset(4) */
|
||||
field1 : f32,
|
||||
}
|
||||
|
||||
@@ -1459,7 +1469,9 @@ TEST_F(SpvModuleScopeVarParserTest,
|
||||
EXPECT_TRUE(p->error().empty());
|
||||
const auto module_str = test::ToString(p->program());
|
||||
EXPECT_THAT(module_str, HasSubstr(R"(struct S {
|
||||
/* @offset(0) */
|
||||
field0 : f32,
|
||||
/* @offset(4) */
|
||||
field1 : f32,
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
|
||||
struct S {
|
||||
@size(16)
|
||||
padding : u32,
|
||||
/* @offset(16) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -147,6 +148,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
|
||||
struct S {
|
||||
@size(16)
|
||||
padding : u32,
|
||||
/* @offset(16) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -199,6 +201,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
|
||||
struct S {
|
||||
@size(16)
|
||||
padding : u32,
|
||||
/* @offset(16u) */
|
||||
@stride(8) @internal(disable_validation__ignore_stride)
|
||||
m : mat2x2<f32>,
|
||||
}
|
||||
@@ -253,6 +256,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -311,6 +315,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
|
||||
struct S {
|
||||
@size(16)
|
||||
padding : u32,
|
||||
/* @offset(16) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -365,6 +370,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -422,6 +428,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -487,6 +494,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
m : @stride(32) array<vec2<f32>, 2u>,
|
||||
}
|
||||
|
||||
@@ -551,6 +559,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8u) */
|
||||
@stride(32) @internal(disable_validation__ignore_stride)
|
||||
m : mat2x2<f32>,
|
||||
}
|
||||
@@ -605,6 +614,7 @@ TEST_F(DecomposeStridedMatrixTest, WritePrivateMatrix) {
|
||||
struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8u) */
|
||||
@stride(32) @internal(disable_validation__ignore_stride)
|
||||
m : mat2x2<f32>,
|
||||
}
|
||||
|
||||
@@ -623,7 +623,14 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) {
|
||||
utils::Vector<const ast::Attribute*, 4> attributes_sanitized;
|
||||
attributes_sanitized.Reserve(mem->attributes.Length());
|
||||
for (auto* attr : mem->attributes) {
|
||||
if (!attr->Is<ast::StructMemberOffsetAttribute>()) {
|
||||
if (attr->Is<ast::StructMemberOffsetAttribute>()) {
|
||||
auto l = line();
|
||||
l << "/* ";
|
||||
if (!EmitAttributes(l, utils::Vector{attr})) {
|
||||
return false;
|
||||
}
|
||||
l << " */";
|
||||
} else {
|
||||
attributes_sanitized.Push(attr);
|
||||
}
|
||||
}
|
||||
@@ -792,6 +799,14 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out,
|
||||
out << ")";
|
||||
return true;
|
||||
},
|
||||
[&](const ast::StructMemberOffsetAttribute* offset) {
|
||||
out << "offset(";
|
||||
if (!EmitExpression(out, offset->expr)) {
|
||||
return false;
|
||||
}
|
||||
out << ")";
|
||||
return true;
|
||||
},
|
||||
[&](const ast::StructMemberSizeAttribute* size) {
|
||||
out << "size(";
|
||||
if (!EmitExpression(out, size->expr)) {
|
||||
|
||||
@@ -188,9 +188,11 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl) {
|
||||
EXPECT_EQ(gen.result(), R"(struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
a : i32,
|
||||
@size(4)
|
||||
padding_1 : u32,
|
||||
/* @offset(16) */
|
||||
b : f32,
|
||||
}
|
||||
)");
|
||||
@@ -209,9 +211,11 @@ TEST_F(WgslGeneratorImplTest, EmitType_StructOffsetDecl_WithSymbolCollisions) {
|
||||
EXPECT_EQ(gen.result(), R"(struct S {
|
||||
@size(8)
|
||||
padding : u32,
|
||||
/* @offset(8) */
|
||||
tint_0_padding : i32,
|
||||
@size(4)
|
||||
padding_1 : u32,
|
||||
/* @offset(16) */
|
||||
tint_2_padding : f32,
|
||||
}
|
||||
)");
|
||||
|
||||
Reference in New Issue
Block a user