mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +00:00
GLSL: Change Add[Spirv]BlockAttribute to support GLSL
Modify the AddSpirvBlockAttribute transform to fix top-level structure access of uniform, storage and push-constant buffers for use in the GLSL backend. The small change to the transform makes the transform wrap host-sharable buffers, if they're also used as a non-host-sharable structure. Also rename the transform to AddBlockAttrbibute in order to reflect its wider applicability. Change-Id: Ib2bf4ebf6bce72790791dbae9387032be765e4b9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/101061 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
822de46c74
commit
863d9edf59
@@ -390,9 +390,9 @@ libtint_source_set("libtint_core_all_src") {
|
||||
"program_builder.h",
|
||||
"program_id.cc",
|
||||
"program_id.h",
|
||||
"reflection.h",
|
||||
"reader/reader.cc",
|
||||
"reader/reader.h",
|
||||
"reflection.h",
|
||||
"resolver/const_eval.cc",
|
||||
"resolver/const_eval.h",
|
||||
"resolver/ctor_conv_intrinsic.cc",
|
||||
@@ -470,10 +470,10 @@ libtint_source_set("libtint_core_all_src") {
|
||||
"text/unicode.cc",
|
||||
"text/unicode.h",
|
||||
"traits.h",
|
||||
"transform/add_block_attribute.cc",
|
||||
"transform/add_block_attribute.h",
|
||||
"transform/add_empty_entry_point.cc",
|
||||
"transform/add_empty_entry_point.h",
|
||||
"transform/add_spirv_block_attribute.cc",
|
||||
"transform/add_spirv_block_attribute.h",
|
||||
"transform/array_length_from_uniform.cc",
|
||||
"transform/array_length_from_uniform.h",
|
||||
"transform/binding_remapper.cc",
|
||||
@@ -1186,8 +1186,8 @@ if (tint_build_unittests) {
|
||||
|
||||
tint_unittests_source_set("tint_unittests_transform_src") {
|
||||
sources = [
|
||||
"transform/add_block_attribute_test.cc",
|
||||
"transform/add_empty_entry_point_test.cc",
|
||||
"transform/add_spirv_block_attribute_test.cc",
|
||||
"transform/array_length_from_uniform_test.cc",
|
||||
"transform/binding_remapper_test.cc",
|
||||
"transform/builtin_polyfill_test.cc",
|
||||
|
||||
@@ -384,8 +384,8 @@ set(TINT_LIB_SRCS
|
||||
traits.h
|
||||
transform/add_empty_entry_point.cc
|
||||
transform/add_empty_entry_point.h
|
||||
transform/add_spirv_block_attribute.cc
|
||||
transform/add_spirv_block_attribute.h
|
||||
transform/add_block_attribute.cc
|
||||
transform/add_block_attribute.h
|
||||
transform/array_length_from_uniform.cc
|
||||
transform/array_length_from_uniform.h
|
||||
transform/binding_remapper.cc
|
||||
@@ -1102,7 +1102,7 @@ if(TINT_BUILD_TESTS)
|
||||
if(${TINT_BUILD_WGSL_READER} AND ${TINT_BUILD_WGSL_WRITER})
|
||||
list(APPEND TINT_TEST_SRCS
|
||||
transform/add_empty_entry_point_test.cc
|
||||
transform/add_spirv_block_attribute_test.cc
|
||||
transform/add_block_attribute_test.cc
|
||||
transform/array_length_from_uniform_test.cc
|
||||
transform/binding_remapper_test.cc
|
||||
transform/builtin_polyfill_test.cc
|
||||
|
||||
@@ -26,13 +26,13 @@
|
||||
#include "src/tint/ast/texture.h"
|
||||
#include "src/tint/ast/u32.h"
|
||||
#include "src/tint/ast/vector.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
|
||||
namespace tint::ast {
|
||||
namespace {
|
||||
|
||||
using AstStructTest = TestHelper;
|
||||
using SpirvBlockAttribute = transform::AddSpirvBlockAttribute::SpirvBlockAttribute;
|
||||
using BlockAttribute = transform::AddBlockAttribute::BlockAttribute;
|
||||
|
||||
TEST_F(AstStructTest, Creation) {
|
||||
auto name = Sym("s");
|
||||
@@ -51,12 +51,12 @@ TEST_F(AstStructTest, Creation_WithAttributes) {
|
||||
|
||||
auto* s = create<Struct>(name, utils::Vector{Member("a", ty.i32())},
|
||||
utils::Vector{
|
||||
ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID()),
|
||||
ASTNodes().Create<BlockAttribute>(ID(), AllocateNodeID()),
|
||||
});
|
||||
EXPECT_EQ(s->name, name);
|
||||
EXPECT_EQ(s->members.Length(), 1u);
|
||||
ASSERT_EQ(s->attributes.Length(), 1u);
|
||||
EXPECT_TRUE(s->attributes[0]->Is<SpirvBlockAttribute>());
|
||||
EXPECT_TRUE(s->attributes[0]->Is<BlockAttribute>());
|
||||
EXPECT_EQ(s->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(s->source.range.begin.column, 0u);
|
||||
EXPECT_EQ(s->source.range.end.line, 0u);
|
||||
@@ -65,14 +65,14 @@ TEST_F(AstStructTest, Creation_WithAttributes) {
|
||||
|
||||
TEST_F(AstStructTest, CreationWithSourceAndAttributes) {
|
||||
auto name = Sym("s");
|
||||
auto* s = create<Struct>(
|
||||
Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, name,
|
||||
utils::Vector{Member("a", ty.i32())},
|
||||
utils::Vector{ASTNodes().Create<SpirvBlockAttribute>(ID(), AllocateNodeID())});
|
||||
auto* s =
|
||||
create<Struct>(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}},
|
||||
name, utils::Vector{Member("a", ty.i32())},
|
||||
utils::Vector{ASTNodes().Create<BlockAttribute>(ID(), AllocateNodeID())});
|
||||
EXPECT_EQ(s->name, name);
|
||||
EXPECT_EQ(s->members.Length(), 1u);
|
||||
ASSERT_EQ(s->attributes.Length(), 1u);
|
||||
EXPECT_TRUE(s->attributes[0]->Is<SpirvBlockAttribute>());
|
||||
EXPECT_TRUE(s->attributes[0]->Is<BlockAttribute>());
|
||||
EXPECT_EQ(s->source.range.begin.line, 27u);
|
||||
EXPECT_EQ(s->source.range.begin.column, 4u);
|
||||
EXPECT_EQ(s->source.range.end.line, 27u);
|
||||
@@ -115,9 +115,9 @@ TEST_F(AstStructTest, Assert_DifferentProgramID_Attribute) {
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<Struct>(b1.Sym("S"), utils::Vector{b1.Member("a", b1.ty.i32())},
|
||||
utils::Vector{b2.ASTNodes().Create<SpirvBlockAttribute>(
|
||||
b2.ID(), b2.AllocateNodeID())});
|
||||
b1.create<Struct>(
|
||||
b1.Sym("S"), utils::Vector{b1.Member("a", b1.ty.i32())},
|
||||
utils::Vector{b2.ASTNodes().Create<BlockAttribute>(b2.ID(), b2.AllocateNodeID())});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "src/tint/ast/disable_validation_attribute.h"
|
||||
#include "src/tint/resolver/resolver.h"
|
||||
#include "src/tint/resolver/resolver_test_helper.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
@@ -557,7 +557,7 @@ TEST_F(EntryPointReturnTypeAttributeTest, DuplicateInternalAttribute) {
|
||||
|
||||
namespace StructAndStructMemberTests {
|
||||
using StructAttributeTest = TestWithParams;
|
||||
using SpirvBlockAttribute = transform::AddSpirvBlockAttribute::SpirvBlockAttribute;
|
||||
using SpirvBlockAttribute = transform::AddBlockAttribute::BlockAttribute;
|
||||
TEST_P(StructAttributeTest, IsValid) {
|
||||
auto& params = GetParam();
|
||||
|
||||
|
||||
@@ -12,8 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
@@ -21,16 +22,29 @@
|
||||
#include "src/tint/utils/hashmap.h"
|
||||
#include "src/tint/utils/hashset.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::AddSpirvBlockAttribute);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::AddSpirvBlockAttribute::SpirvBlockAttribute);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::AddBlockAttribute);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::AddBlockAttribute::BlockAttribute);
|
||||
|
||||
namespace tint::transform {
|
||||
|
||||
AddSpirvBlockAttribute::AddSpirvBlockAttribute() = default;
|
||||
namespace {
|
||||
|
||||
AddSpirvBlockAttribute::~AddSpirvBlockAttribute() = default;
|
||||
bool IsUsedAsNonBuffer(const std::unordered_set<tint::ast::StorageClass>& uses) {
|
||||
for (auto use : uses) {
|
||||
if (!ast::IsHostShareable(use)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
|
||||
} // namespace
|
||||
|
||||
AddBlockAttribute::AddBlockAttribute() = default;
|
||||
|
||||
AddBlockAttribute::~AddBlockAttribute() = default;
|
||||
|
||||
void AddBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
|
||||
auto& sem = ctx.src->Sem();
|
||||
|
||||
// Collect the set of structs that are nested in other types.
|
||||
@@ -66,8 +80,10 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co
|
||||
|
||||
auto* ty = var->Type()->UnwrapRef();
|
||||
auto* str = ty->As<sem::Struct>();
|
||||
bool needs_wrapping = !str || // Type is not a structure
|
||||
nested_structs.Contains(str); // Structure is nested by another type
|
||||
bool needs_wrapping =
|
||||
!str || // Type is not a structure
|
||||
nested_structs.Contains(str) || // Structure is nested by another type
|
||||
IsUsedAsNonBuffer(str->StorageClassUsage()); // Structure is used as a non-buffer usage
|
||||
|
||||
if (needs_wrapping) {
|
||||
const char* kMemberName = "inner";
|
||||
@@ -75,8 +91,8 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co
|
||||
// This is a non-struct or a struct that is nested somewhere else, so we
|
||||
// need to wrap it first.
|
||||
auto* wrapper = wrapper_structs.GetOrCreate(ty, [&] {
|
||||
auto* block = ctx.dst->ASTNodes().Create<SpirvBlockAttribute>(
|
||||
ctx.dst->ID(), ctx.dst->AllocateNodeID());
|
||||
auto* block = ctx.dst->ASTNodes().Create<BlockAttribute>(ctx.dst->ID(),
|
||||
ctx.dst->AllocateNodeID());
|
||||
auto wrapper_name = ctx.src->Symbols().NameFor(global->symbol) + "_block";
|
||||
auto* ret = ctx.dst->create<ast::Struct>(
|
||||
ctx.dst->Symbols().New(wrapper_name),
|
||||
@@ -95,8 +111,8 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co
|
||||
}
|
||||
} else {
|
||||
// Add a block attribute to this struct directly.
|
||||
auto* block = ctx.dst->ASTNodes().Create<SpirvBlockAttribute>(
|
||||
ctx.dst->ID(), ctx.dst->AllocateNodeID());
|
||||
auto* block = ctx.dst->ASTNodes().Create<BlockAttribute>(ctx.dst->ID(),
|
||||
ctx.dst->AllocateNodeID());
|
||||
ctx.InsertFront(str->Declaration()->attributes, block);
|
||||
}
|
||||
}
|
||||
@@ -104,16 +120,16 @@ void AddSpirvBlockAttribute::Run(CloneContext& ctx, const DataMap&, DataMap&) co
|
||||
ctx.Clone();
|
||||
}
|
||||
|
||||
AddSpirvBlockAttribute::SpirvBlockAttribute::SpirvBlockAttribute(ProgramID pid, ast::NodeID nid)
|
||||
AddBlockAttribute::BlockAttribute::BlockAttribute(ProgramID pid, ast::NodeID nid)
|
||||
: Base(pid, nid) {}
|
||||
AddSpirvBlockAttribute::SpirvBlockAttribute::~SpirvBlockAttribute() = default;
|
||||
std::string AddSpirvBlockAttribute::SpirvBlockAttribute::InternalName() const {
|
||||
return "spirv_block";
|
||||
AddBlockAttribute::BlockAttribute::~BlockAttribute() = default;
|
||||
std::string AddBlockAttribute::BlockAttribute::InternalName() const {
|
||||
return "block";
|
||||
}
|
||||
|
||||
const AddSpirvBlockAttribute::SpirvBlockAttribute*
|
||||
AddSpirvBlockAttribute::SpirvBlockAttribute::Clone(CloneContext* ctx) const {
|
||||
return ctx->dst->ASTNodes().Create<AddSpirvBlockAttribute::SpirvBlockAttribute>(
|
||||
const AddBlockAttribute::BlockAttribute* AddBlockAttribute::BlockAttribute::Clone(
|
||||
CloneContext* ctx) const {
|
||||
return ctx->dst->ASTNodes().Create<AddBlockAttribute::BlockAttribute>(
|
||||
ctx->dst->ID(), ctx->dst->AllocateNodeID());
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_TRANSFORM_ADD_SPIRV_BLOCK_ATTRIBUTE_H_
|
||||
#define SRC_TINT_TRANSFORM_ADD_SPIRV_BLOCK_ATTRIBUTE_H_
|
||||
#ifndef SRC_TINT_TRANSFORM_ADD_BLOCK_ATTRIBUTE_H_
|
||||
#define SRC_TINT_TRANSFORM_ADD_BLOCK_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -22,23 +22,23 @@
|
||||
|
||||
namespace tint::transform {
|
||||
|
||||
/// AddSpirvBlockAttribute is a transform that adds an
|
||||
/// `@internal(spirv_block)` attribute to any structure that is used as the
|
||||
/// AddBlockAttribute is a transform that adds an
|
||||
/// `@internal(block)` attribute to any structure that is used as the
|
||||
/// store type of a buffer. If that structure is nested inside another structure
|
||||
/// or an array, then it is wrapped inside another structure which gets the
|
||||
/// `@internal(spirv_block)` attribute instead.
|
||||
class AddSpirvBlockAttribute final : public Castable<AddSpirvBlockAttribute, Transform> {
|
||||
/// `@internal(block)` attribute instead.
|
||||
class AddBlockAttribute final : public Castable<AddBlockAttribute, Transform> {
|
||||
public:
|
||||
/// SpirvBlockAttribute is an InternalAttribute that is used to decorate a
|
||||
// structure that needs a SPIR-V block attribute.
|
||||
class SpirvBlockAttribute final : public Castable<SpirvBlockAttribute, ast::InternalAttribute> {
|
||||
/// BlockAttribute is an InternalAttribute that is used to decorate a
|
||||
// structure that is used as a buffer in SPIR-V or GLSL.
|
||||
class BlockAttribute final : public Castable<BlockAttribute, ast::InternalAttribute> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param nid the unique node identifier
|
||||
SpirvBlockAttribute(ProgramID program_id, ast::NodeID nid);
|
||||
BlockAttribute(ProgramID program_id, ast::NodeID nid);
|
||||
/// Destructor
|
||||
~SpirvBlockAttribute() override;
|
||||
~BlockAttribute() override;
|
||||
|
||||
/// @return a short description of the internal attribute which will be
|
||||
/// displayed as `@internal(<name>)`
|
||||
@@ -47,14 +47,14 @@ class AddSpirvBlockAttribute final : public Castable<AddSpirvBlockAttribute, Tra
|
||||
/// Performs a deep clone of this object using the CloneContext `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned object
|
||||
const SpirvBlockAttribute* Clone(CloneContext* ctx) const override;
|
||||
const BlockAttribute* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
/// Constructor
|
||||
AddSpirvBlockAttribute();
|
||||
AddBlockAttribute();
|
||||
|
||||
/// Destructor
|
||||
~AddSpirvBlockAttribute() override;
|
||||
~AddBlockAttribute() override;
|
||||
|
||||
protected:
|
||||
/// Runs the transform using the CloneContext built for transforming a
|
||||
@@ -68,4 +68,4 @@ class AddSpirvBlockAttribute final : public Castable<AddSpirvBlockAttribute, Tra
|
||||
|
||||
} // namespace tint::transform
|
||||
|
||||
#endif // SRC_TINT_TRANSFORM_ADD_SPIRV_BLOCK_ATTRIBUTE_H_
|
||||
#endif // SRC_TINT_TRANSFORM_ADD_BLOCK_ATTRIBUTE_H_
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
@@ -22,18 +22,18 @@
|
||||
namespace tint::transform {
|
||||
namespace {
|
||||
|
||||
using AddSpirvBlockAttributeTest = TransformTest;
|
||||
using AddBlockAttributeTest = TransformTest;
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, EmptyModule) {
|
||||
TEST_F(AddBlockAttributeTest, EmptyModule) {
|
||||
auto* src = "";
|
||||
auto* expect = "";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Noop_UsedForPrivateVar) {
|
||||
TEST_F(AddBlockAttributeTest, Noop_UsedForPrivateVar) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
@@ -48,12 +48,12 @@ fn main() {
|
||||
)";
|
||||
auto* expect = src;
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Noop_UsedForShaderIO) {
|
||||
TEST_F(AddBlockAttributeTest, Noop_UsedForShaderIO) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
@location(0)
|
||||
@@ -67,12 +67,12 @@ fn main() -> S {
|
||||
)";
|
||||
auto* expect = src;
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicScalar) {
|
||||
TEST_F(AddBlockAttributeTest, BasicScalar) {
|
||||
auto* src = R"(
|
||||
@group(0) @binding(0)
|
||||
var<uniform> u : f32;
|
||||
@@ -83,7 +83,7 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : f32,
|
||||
}
|
||||
@@ -96,12 +96,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicArray) {
|
||||
TEST_F(AddBlockAttributeTest, BasicArray) {
|
||||
auto* src = R"(
|
||||
@group(0) @binding(0)
|
||||
var<uniform> u : array<vec4<f32>, 4u>;
|
||||
@@ -112,7 +112,7 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : array<vec4<f32>, 4u>,
|
||||
}
|
||||
@@ -125,12 +125,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicArray_Alias) {
|
||||
TEST_F(AddBlockAttributeTest, BasicArray_Alias) {
|
||||
auto* src = R"(
|
||||
type Numbers = array<vec4<f32>, 4u>;
|
||||
|
||||
@@ -145,7 +145,7 @@ fn main() {
|
||||
auto* expect = R"(
|
||||
type Numbers = array<vec4<f32>, 4u>;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : array<vec4<f32>, 4u>,
|
||||
}
|
||||
@@ -158,12 +158,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicStruct_AccessRoot) {
|
||||
TEST_F(AddBlockAttributeTest, BasicStruct_AccessRoot) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
@@ -178,25 +178,29 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
@internal(spirv_block)
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : S;
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : S,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : u_block;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
let f = u;
|
||||
let f = u.inner;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicStruct_AccessField) {
|
||||
TEST_F(AddBlockAttributeTest, BasicStruct_AccessField) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
@@ -211,7 +215,7 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
@@ -224,12 +228,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicScalar_PushConstant) {
|
||||
TEST_F(AddBlockAttributeTest, BasicScalar_PushConstant) {
|
||||
auto* src = R"(
|
||||
enable chromium_experimental_push_constant;
|
||||
var<push_constant> u : f32;
|
||||
@@ -242,7 +246,7 @@ fn main() {
|
||||
auto* expect = R"(
|
||||
enable chromium_experimental_push_constant;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : f32,
|
||||
}
|
||||
@@ -255,12 +259,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, BasicStruct_PushConstant) {
|
||||
TEST_F(AddBlockAttributeTest, BasicStruct_PushConstant) {
|
||||
auto* src = R"(
|
||||
enable chromium_experimental_push_constant;
|
||||
struct S {
|
||||
@@ -276,7 +280,7 @@ fn main() {
|
||||
auto* expect = R"(
|
||||
enable chromium_experimental_push_constant;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
@@ -289,12 +293,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Nested_OuterBuffer_InnerNotBuffer) {
|
||||
TEST_F(AddBlockAttributeTest, Nested_OuterBuffer_InnerNotBuffer) {
|
||||
auto* src = R"(
|
||||
struct Inner {
|
||||
f : f32,
|
||||
@@ -317,7 +321,7 @@ struct Inner {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct Outer {
|
||||
i : Inner,
|
||||
}
|
||||
@@ -330,12 +334,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Nested_OuterBuffer_InnerBuffer) {
|
||||
TEST_F(AddBlockAttributeTest, Nested_OuterBuffer_InnerBuffer) {
|
||||
auto* src = R"(
|
||||
struct Inner {
|
||||
f : f32,
|
||||
@@ -362,14 +366,14 @@ struct Inner {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct Outer {
|
||||
i : Inner,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u0 : Outer;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u1_block {
|
||||
inner : Inner,
|
||||
}
|
||||
@@ -383,12 +387,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Nested_OuterNotBuffer_InnerBuffer) {
|
||||
TEST_F(AddBlockAttributeTest, Nested_OuterNotBuffer_InnerBuffer) {
|
||||
auto* src = R"(
|
||||
struct Inner {
|
||||
f : f32,
|
||||
@@ -420,7 +424,7 @@ struct Outer {
|
||||
|
||||
var<private> p : Outer;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : Inner,
|
||||
}
|
||||
@@ -434,12 +438,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Nested_InnerUsedForMultipleBuffers) {
|
||||
TEST_F(AddBlockAttributeTest, Nested_InnerUsedForMultipleBuffers) {
|
||||
auto* src = R"(
|
||||
struct Inner {
|
||||
f : f32,
|
||||
@@ -470,14 +474,14 @@ struct Inner {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct S {
|
||||
i : Inner,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u0 : S;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u1_block {
|
||||
inner : Inner,
|
||||
}
|
||||
@@ -494,12 +498,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, StructInArray) {
|
||||
TEST_F(AddBlockAttributeTest, StructInArray) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
@@ -519,7 +523,7 @@ struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : S,
|
||||
}
|
||||
@@ -533,12 +537,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, StructInArray_MultipleBuffers) {
|
||||
TEST_F(AddBlockAttributeTest, StructInArray_MultipleBuffers) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
@@ -562,7 +566,7 @@ struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u0_block {
|
||||
inner : S,
|
||||
}
|
||||
@@ -579,12 +583,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Aliases_Nested_OuterBuffer_InnerBuffer) {
|
||||
TEST_F(AddBlockAttributeTest, Aliases_Nested_OuterBuffer_InnerBuffer) {
|
||||
auto* src = R"(
|
||||
struct Inner {
|
||||
f : f32,
|
||||
@@ -617,7 +621,7 @@ struct Inner {
|
||||
|
||||
type MyInner = Inner;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct Outer {
|
||||
i : MyInner,
|
||||
}
|
||||
@@ -626,7 +630,7 @@ type MyOuter = Outer;
|
||||
|
||||
@group(0) @binding(0) var<uniform> u0 : MyOuter;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u1_block {
|
||||
inner : Inner,
|
||||
}
|
||||
@@ -640,12 +644,12 @@ fn main() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddSpirvBlockAttributeTest, Aliases_Nested_OuterBuffer_InnerBuffer_OutOfOrder) {
|
||||
TEST_F(AddBlockAttributeTest, Aliases_Nested_OuterBuffer_InnerBuffer_OutOfOrder) {
|
||||
auto* src = R"(
|
||||
@fragment
|
||||
fn main() {
|
||||
@@ -678,7 +682,7 @@ fn main() {
|
||||
let f1 = u1.inner.f;
|
||||
}
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct u1_block {
|
||||
inner : Inner,
|
||||
}
|
||||
@@ -691,7 +695,7 @@ type MyInner = Inner;
|
||||
|
||||
type MyOuter = Outer;
|
||||
|
||||
@internal(spirv_block)
|
||||
@internal(block)
|
||||
struct Outer {
|
||||
i : MyInner,
|
||||
}
|
||||
@@ -701,7 +705,147 @@ struct Inner {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddSpirvBlockAttribute>(src);
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddBlockAttributeTest, UniformAndPrivateUsages) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : S;
|
||||
|
||||
var<private> p : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
p = u;
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(block)
|
||||
struct u_block {
|
||||
inner : S,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : u_block;
|
||||
|
||||
var<private> p : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
p = u.inner;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddBlockAttributeTest, StorageAndPrivateUsages) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<storage, read_write> s : S;
|
||||
|
||||
var<private> p : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
p = s;
|
||||
p.f = 1234.0;
|
||||
s = p;
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@internal(block)
|
||||
struct s_block {
|
||||
inner : S,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<storage, read_write> s : s_block;
|
||||
|
||||
var<private> p : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
p = s.inner;
|
||||
p.f = 1234.0;
|
||||
s.inner = p;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddBlockAttributeTest, StorageAndUniformUsages) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : S;
|
||||
|
||||
@group(0) @binding(1) var<storage, read_write> s : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
s = u;
|
||||
}
|
||||
)";
|
||||
auto* expect = R"(
|
||||
@internal(block) @internal(block)
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
@group(0) @binding(0) var<uniform> u : S;
|
||||
|
||||
@group(0) @binding(1) var<storage, read_write> s : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
s = u;
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
TEST_F(AddBlockAttributeTest, PrivateUsageOnly) {
|
||||
auto* src = R"(
|
||||
struct S {
|
||||
f : f32,
|
||||
}
|
||||
|
||||
var<private> p : S;
|
||||
|
||||
@fragment
|
||||
fn main() {
|
||||
p.f = 4321.0f;
|
||||
}
|
||||
)";
|
||||
auto* expect = src;
|
||||
|
||||
auto got = Run<AddBlockAttribute>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
@@ -46,8 +46,8 @@
|
||||
#include "src/tint/sem/type_constructor.h"
|
||||
#include "src/tint/sem/type_conversion.h"
|
||||
#include "src/tint/sem/variable.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
#include "src/tint/transform/add_empty_entry_point.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/binding_remapper.h"
|
||||
#include "src/tint/transform/builtin_polyfill.h"
|
||||
#include "src/tint/transform/canonicalize_entry_point_io.h"
|
||||
@@ -244,7 +244,7 @@ SanitizedResult Sanitize(const Program* in,
|
||||
|
||||
manager.Add<transform::PromoteInitializersToLet>();
|
||||
manager.Add<transform::AddEmptyEntryPoint>();
|
||||
manager.Add<transform::AddSpirvBlockAttribute>();
|
||||
manager.Add<transform::AddBlockAttribute>();
|
||||
data.Add<transform::CanonicalizeEntryPointIO::Config>(
|
||||
transform::CanonicalizeEntryPointIO::ShaderStyle::kGlsl);
|
||||
|
||||
@@ -284,18 +284,15 @@ bool GeneratorImpl::Generate() {
|
||||
return false;
|
||||
}
|
||||
} else if (auto* str = decl->As<ast::Struct>()) {
|
||||
// Skip emission if the struct contains a runtime-sized array, since its
|
||||
// only use will be as the store-type of a buffer and we emit those
|
||||
// elsewhere.
|
||||
// TODO(crbug.com/tint/1339): We could also avoid emitting any other
|
||||
// struct that is only used as a buffer store type.
|
||||
const sem::Struct* sem_str = builder_.Sem().Get(str);
|
||||
const auto& members = sem_str->Members();
|
||||
TINT_ASSERT(Writer, members.size() > 0);
|
||||
auto* last_member = members[members.size() - 1];
|
||||
auto* arr = last_member->Type()->As<sem::Array>();
|
||||
if (!arr || !arr->IsRuntimeSized()) {
|
||||
if (!EmitStructType(current_buffer_, sem_str)) {
|
||||
auto* sem = builder_.Sem().Get(str);
|
||||
bool has_rt_arr = false;
|
||||
if (auto* arr = sem->Members().back()->Type()->As<sem::Array>()) {
|
||||
has_rt_arr = arr->IsRuntimeSized();
|
||||
}
|
||||
bool is_block =
|
||||
ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(str->attributes);
|
||||
if (!has_rt_arr && !is_block) {
|
||||
if (!EmitStructType(current_buffer_, sem)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1915,7 +1912,7 @@ bool GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable
|
||||
if (version_.IsDesktop()) {
|
||||
out << ", std140";
|
||||
}
|
||||
out << ") uniform " << UniqueIdentifier(StructName(str)) << " {";
|
||||
out << ") uniform " << UniqueIdentifier(StructName(str) + "_ubo") << " {";
|
||||
}
|
||||
EmitStructMembers(current_buffer_, str, /* emit_offsets */ true);
|
||||
auto name = builder_.Symbols().NameFor(var->symbol);
|
||||
@@ -1934,10 +1931,12 @@ bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable
|
||||
}
|
||||
auto bp = sem->As<sem::GlobalVariable>()->BindingPoint();
|
||||
line() << "layout(binding = " << bp.binding << ", std430) buffer "
|
||||
<< UniqueIdentifier(StructName(str)) << " {";
|
||||
<< UniqueIdentifier(StructName(str) + "_ssbo") << " {";
|
||||
EmitStructMembers(current_buffer_, str, /* emit_offsets */ true);
|
||||
auto name = builder_.Symbols().NameFor(var->symbol);
|
||||
line() << "} " << name << ";";
|
||||
line();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -384,7 +384,7 @@ struct UBO {
|
||||
vec4 coord;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform UBO_1 {
|
||||
layout(binding = 0) uniform UBO_ubo {
|
||||
vec4 coord;
|
||||
} ubo;
|
||||
|
||||
@@ -425,7 +425,7 @@ struct Uniforms {
|
||||
vec4 coord;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform Uniforms_1 {
|
||||
layout(binding = 0) uniform Uniforms_ubo {
|
||||
vec4 coord;
|
||||
} uniforms;
|
||||
|
||||
@@ -462,15 +462,11 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RW_Storage
|
||||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
int a;
|
||||
float b;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
float v = coord.b;
|
||||
return;
|
||||
@@ -510,15 +506,11 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RO_Storage
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
int a;
|
||||
float b;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
float v = coord.b;
|
||||
return;
|
||||
@@ -555,15 +547,11 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_WO_Storage
|
||||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
int a;
|
||||
float b;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
coord.b = 2.0f;
|
||||
return;
|
||||
@@ -600,15 +588,11 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_StorageBuf
|
||||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
float b;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
int a;
|
||||
float b;
|
||||
} coord;
|
||||
|
||||
void frag_main() {
|
||||
coord.b = 2.0f;
|
||||
return;
|
||||
@@ -651,7 +635,7 @@ struct S {
|
||||
float x;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform S_1 {
|
||||
layout(binding = 0) uniform S_ubo {
|
||||
float x;
|
||||
} coord;
|
||||
|
||||
@@ -694,13 +678,10 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct S {
|
||||
float x;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer S_1 {
|
||||
layout(binding = 0, std430) buffer S_ssbo {
|
||||
float x;
|
||||
} coord;
|
||||
|
||||
float sub_func(float param) {
|
||||
return coord.x;
|
||||
}
|
||||
@@ -930,13 +911,10 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Multiple_EntryPoint_With_Same_Module
|
||||
ASSERT_TRUE(gen.Generate()) << gen.error();
|
||||
EXPECT_EQ(gen.result(), R"(#version 310 es
|
||||
|
||||
struct Data {
|
||||
float d;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
float d;
|
||||
} data;
|
||||
|
||||
void a() {
|
||||
float v = data.d;
|
||||
return;
|
||||
|
||||
@@ -277,15 +277,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Matrix_Empty) {
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
int a;
|
||||
mat2x3 b;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
int a;
|
||||
mat2x3 b;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.b = mat2x3(vec3(0.0f), vec3(0.0f));
|
||||
}
|
||||
@@ -322,15 +318,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_Matrix_Single_El
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
float z;
|
||||
mat4x3 a;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
float z;
|
||||
mat4x3 a;
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.a[2][1];
|
||||
}
|
||||
@@ -367,15 +359,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
float z;
|
||||
int a[5];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
int x = data.a[2];
|
||||
}
|
||||
@@ -415,15 +403,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor,
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
float z;
|
||||
int a[5];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
int a = 2;
|
||||
int b = 4;
|
||||
@@ -462,15 +446,11 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) {
|
||||
R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
struct Data {
|
||||
float z;
|
||||
int a[5];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
float z;
|
||||
int a[5];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.a[2] = 2;
|
||||
}
|
||||
@@ -520,13 +500,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
vec3 x = data.c[2].b;
|
||||
}
|
||||
@@ -578,13 +555,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
vec2 x = data.c[2].b.xy;
|
||||
}
|
||||
@@ -637,13 +611,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.c[2].b.g;
|
||||
}
|
||||
@@ -695,13 +666,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
float x = data.c[2].b[1];
|
||||
}
|
||||
@@ -752,13 +720,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.c[2].b = vec3(1.0f, 2.0f, 3.0f);
|
||||
}
|
||||
@@ -810,13 +775,10 @@ struct Inner {
|
||||
vec3 b;
|
||||
};
|
||||
|
||||
struct Data {
|
||||
Inner c[4];
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Data_1 {
|
||||
layout(binding = 0, std430) buffer Data_ssbo {
|
||||
Inner c[4];
|
||||
} data;
|
||||
|
||||
void tint_symbol() {
|
||||
data.c[2].b.y = 1.0f;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,10 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength) {
|
||||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(binding = 1, std430) buffer my_struct_1 {
|
||||
layout(binding = 1, std430) buffer my_struct_ssbo {
|
||||
float a[];
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint len = uint(b.a.length());
|
||||
}
|
||||
@@ -84,10 +85,11 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) {
|
||||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(binding = 1, std430) buffer my_struct_1 {
|
||||
layout(binding = 1, std430) buffer my_struct_ssbo {
|
||||
float z;
|
||||
float a[];
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint len = uint(b.a.length());
|
||||
}
|
||||
@@ -127,9 +129,10 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) {
|
||||
auto* expect = R"(#version 310 es
|
||||
precision mediump float;
|
||||
|
||||
layout(binding = 1, std430) buffer my_struct_1 {
|
||||
layout(binding = 1, std430) buffer my_struct_ssbo {
|
||||
float a[];
|
||||
} b;
|
||||
|
||||
void a_func() {
|
||||
uint len = uint(b.a.length());
|
||||
}
|
||||
|
||||
@@ -57,11 +57,12 @@ struct Nephews {
|
||||
float louie;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Nephews_1 {
|
||||
layout(binding = 0, std430) buffer Nephews_ssbo {
|
||||
float huey;
|
||||
float dewey;
|
||||
float louie;
|
||||
} nephews;
|
||||
|
||||
)");
|
||||
}
|
||||
|
||||
@@ -79,11 +80,12 @@ struct Nephews {
|
||||
float louie;
|
||||
};
|
||||
|
||||
layout(binding = 0, std430) buffer Nephews_1 {
|
||||
layout(binding = 0, std430) buffer Nephews_ssbo {
|
||||
float huey;
|
||||
layout(offset=256) float dewey;
|
||||
layout(offset=512) float louie;
|
||||
} nephews;
|
||||
|
||||
)");
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ struct Simple {
|
||||
float member;
|
||||
};
|
||||
|
||||
layout(binding = 0) uniform Simple_1 {
|
||||
layout(binding = 0) uniform Simple_ubo {
|
||||
float member;
|
||||
} simple;
|
||||
|
||||
@@ -57,7 +57,7 @@ struct Simple {
|
||||
float member;
|
||||
};
|
||||
|
||||
layout(binding = 0, std140) uniform Simple_1 {
|
||||
layout(binding = 0, std140) uniform Simple_ubo {
|
||||
float member;
|
||||
} simple;
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "src/tint/sem/type_conversion.h"
|
||||
#include "src/tint/sem/variable.h"
|
||||
#include "src/tint/sem/vector.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
#include "src/tint/utils/defer.h"
|
||||
#include "src/tint/utils/map.h"
|
||||
#include "src/tint/writer/append_vector.h"
|
||||
@@ -4059,8 +4059,7 @@ bool Builder::GenerateStructType(const sem::Struct* struct_type, const Operand&
|
||||
ops.push_back(result);
|
||||
|
||||
auto* decl = struct_type->Declaration();
|
||||
if (decl && ast::HasAttribute<transform::AddSpirvBlockAttribute::SpirvBlockAttribute>(
|
||||
decl->attributes)) {
|
||||
if (decl && ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(decl->attributes)) {
|
||||
push_annot(spv::Op::OpDecorate, {Operand(struct_id), U32Operand(SpvDecorationBlock)});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/transform/add_block_attribute.h"
|
||||
#include "src/tint/transform/add_empty_entry_point.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/builtin_polyfill.h"
|
||||
#include "src/tint/transform/canonicalize_entry_point_io.h"
|
||||
#include "src/tint/transform/disable_uniformity_analysis.h"
|
||||
@@ -86,7 +86,7 @@ SanitizedResult Sanitize(const Program* in, const Options& options) {
|
||||
manager.Add<transform::WhileToLoop>(); // ZeroInitWorkgroupMemory
|
||||
manager.Add<transform::CanonicalizeEntryPointIO>();
|
||||
manager.Add<transform::AddEmptyEntryPoint>();
|
||||
manager.Add<transform::AddSpirvBlockAttribute>();
|
||||
manager.Add<transform::AddBlockAttribute>();
|
||||
manager.Add<transform::VarForDynamicIndex>();
|
||||
|
||||
data.Add<transform::CanonicalizeEntryPointIO::Config>(
|
||||
|
||||
Reference in New Issue
Block a user