tint: Refactor sem::Constant to be less memory-hungry
Change sem::Constant to be an interface to the constant data. Implement
this so that zero-initialized data doesn't need to allocate the full
size of the type.
This also makes usage a lot cleaner (no more flattened-list of
elements!), and gives us a clear path for supporting constant
structures if/when we want to support them.
Bug: chromium:1339558
Bug: chromium:1339561
Bug: chromium:1339580
Bug: chromium:1339597
Change-Id: Ifcd456f69aee18d5b84befa896d7b0189d68c2dd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94942
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 5bccb5f..e9b0a80 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -88,6 +88,7 @@
#include "src/tint/program_id.h"
#include "src/tint/sem/array.h"
#include "src/tint/sem/bool.h"
+#include "src/tint/sem/constant.h"
#include "src/tint/sem/depth_texture.h"
#include "src/tint/sem/external_texture.h"
#include "src/tint/sem/f16.h"
@@ -163,6 +164,9 @@
/// SemNodeAllocator is an alias to BlockAllocator<sem::Node>
using SemNodeAllocator = utils::BlockAllocator<sem::Node>;
+ /// ConstantAllocator is an alias to BlockAllocator<sem::Constant>
+ using ConstantAllocator = utils::BlockAllocator<sem::Constant>;
+
/// Constructor
ProgramBuilder();
@@ -229,6 +233,12 @@
return sem_nodes_;
}
+ /// @returns a reference to the program's semantic constant storage
+ ConstantAllocator& ConstantNodes() {
+ AssertNotMoved();
+ return constant_nodes_;
+ }
+
/// @returns a reference to the program's AST root Module
ast::Module& AST() {
AssertNotMoved();
@@ -332,9 +342,8 @@
}
/// Creates a new sem::Node owned by the ProgramBuilder.
- /// When the ProgramBuilder is destructed, the sem::Node will also be
- /// destructed.
- /// @param args the arguments to pass to the type constructor
+ /// When the ProgramBuilder is destructed, the sem::Node will also be destructed.
+ /// @param args the arguments to pass to the constructor
/// @returns the node pointer
template <typename T, typename... ARGS>
traits::EnableIf<traits::IsTypeOrDerived<T, sem::Node> &&
@@ -345,6 +354,16 @@
return sem_nodes_.Create<T>(std::forward<ARGS>(args)...);
}
+ /// Creates a new sem::Constant owned by the ProgramBuilder.
+ /// When the ProgramBuilder is destructed, the sem::Node will also be destructed.
+ /// @param args the arguments to pass to the constructor
+ /// @returns the node pointer
+ template <typename T, typename... ARGS>
+ traits::EnableIf<traits::IsTypeOrDerived<T, sem::Constant>, T>* create(ARGS&&... args) {
+ AssertNotMoved();
+ return constant_nodes_.Create<T>(std::forward<ARGS>(args)...);
+ }
+
/// Creates a new sem::Type owned by the ProgramBuilder.
/// When the ProgramBuilder is destructed, owned ProgramBuilder and the
/// returned`Type` will also be destructed.
@@ -2747,6 +2766,7 @@
sem::Manager types_;
ASTNodeAllocator ast_nodes_;
SemNodeAllocator sem_nodes_;
+ ConstantAllocator constant_nodes_;
ast::Module* ast_;
sem::Info sem_;
SymbolTable symbols_{id_};