From 5c948e4f8fb803d23c8e67a36f7aa46a250e74d4 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 24 Sep 2020 14:30:34 +0000 Subject: [PATCH] [transform] Move the transform folder This CL moves the transform folder from src/ast to src/. The transforms operate on the AST, but they aren't part of the AST so I think the top level folder makes more sense. This will possibly cause issues when rolling if the transform is being used. Change-Id: Ibd7c94474168a7a4bdf38321f4e12ad111c80323 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28941 Commit-Queue: Ryan Harrison Reviewed-by: Ryan Harrison --- BUILD.gn | 6 +- include/tint/tint.h | 3 +- src/CMakeLists.txt | 6 +- .../transform/vertex_pulling_transform.cc | 186 ++++++++++-------- .../transform/vertex_pulling_transform.h | 86 ++++---- .../vertex_pulling_transform_test.cc | 70 ++++--- 6 files changed, 182 insertions(+), 175 deletions(-) rename src/{ast => }/transform/vertex_pulling_transform.cc (68%) rename src/{ast => }/transform/vertex_pulling_transform.h (81%) rename src/{ast => }/transform/vertex_pulling_transform_test.cc (92%) diff --git a/BUILD.gn b/BUILD.gn index 1110d6ce8c..a1ed133638 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -315,8 +315,6 @@ source_set("libtint_core_src") { "src/ast/struct_member_offset_decoration.h", "src/ast/switch_statement.cc", "src/ast/switch_statement.h", - "src/ast/transform/vertex_pulling_transform.cc", - "src/ast/transform/vertex_pulling_transform.h", "src/ast/type/alias_type.cc", "src/ast/type/alias_type.h", "src/ast/type/array_type.cc", @@ -375,6 +373,8 @@ source_set("libtint_core_src") { "src/reader/reader.h", "src/scope_stack.h", "src/source.h", + "src/transform/vertex_pulling_transform.cc", + "src/transform/vertex_pulling_transform.h", "src/type_determiner.cc", "src/type_determiner.h", "src/type_manager.cc", @@ -723,7 +723,6 @@ source_set("tint_unittests_core_src") { "src/ast/struct_member_test.cc", "src/ast/struct_test.cc", "src/ast/switch_statement_test.cc", - "src/ast/transform/vertex_pulling_transform_test.cc", "src/ast/type/alias_type_test.cc", "src/ast/type/array_type_test.cc", "src/ast/type/bool_type_test.cc", @@ -746,6 +745,7 @@ source_set("tint_unittests_core_src") { "src/ast/variable_test.cc", "src/ast/workgroup_decoration_test.cc", "src/scope_stack_test.cc", + "src/transform/vertex_pulling_transform_test.cc", "src/type_determiner_test.cc", "src/type_manager_test.cc", "src/validator_control_block_test.cc", diff --git a/include/tint/tint.h b/include/tint/tint.h index cba95f005a..9a23ab2156 100644 --- a/include/tint/tint.h +++ b/include/tint/tint.h @@ -21,13 +21,12 @@ #include "src/ast/pipeline_stage.h" #include "src/context.h" #include "src/reader/reader.h" +#include "src/transform/vertex_pulling_transform.h" #include "src/type_determiner.h" #include "src/type_manager.h" #include "src/validator.h" #include "src/writer/writer.h" -#include "src/ast/transform/vertex_pulling_transform.h" - #if TINT_BUILD_SPV_READER #include "src/reader/spirv/parser.h" #endif // TINT_BUILD_SPV_READER diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16409aabc1..7c16a03ca9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -136,8 +136,6 @@ set(TINT_LIB_SRCS ast/struct_member_offset_decoration.h ast/switch_statement.cc ast/switch_statement.h - ast/transform/vertex_pulling_transform.cc - ast/transform/vertex_pulling_transform.h ast/type_constructor_expression.h ast/type_constructor_expression.cc ast/type/alias_type.cc @@ -196,6 +194,8 @@ set(TINT_LIB_SRCS reader/reader.h scope_stack.h source.h + transform/vertex_pulling_transform.cc + transform/vertex_pulling_transform.h type_determiner.cc type_determiner.h type_manager.cc @@ -333,7 +333,6 @@ set(TINT_TEST_SRCS ast/struct_member_offset_decoration_test.cc ast/struct_test.cc ast/switch_statement_test.cc - ast/transform/vertex_pulling_transform_test.cc ast/type/alias_type_test.cc ast/type/array_type_test.cc ast/type/bool_type_test.cc @@ -356,6 +355,7 @@ set(TINT_TEST_SRCS ast/variable_test.cc ast/workgroup_decoration_test.cc scope_stack_test.cc + transform/vertex_pulling_transform_test.cc type_determiner_test.cc type_manager_test.cc validator_control_block_test.cc diff --git a/src/ast/transform/vertex_pulling_transform.cc b/src/transform/vertex_pulling_transform.cc similarity index 68% rename from src/ast/transform/vertex_pulling_transform.cc rename to src/transform/vertex_pulling_transform.cc index 23fd90b614..be060a9c5e 100644 --- a/src/ast/transform/vertex_pulling_transform.cc +++ b/src/transform/vertex_pulling_transform.cc @@ -12,16 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/transform/vertex_pulling_transform.h" +#include "src/transform/vertex_pulling_transform.h" #include "src/ast/array_accessor_expression.h" #include "src/ast/assignment_statement.h" #include "src/ast/binary_expression.h" #include "src/ast/bitcast_expression.h" #include "src/ast/decorated_variable.h" -#include "src/ast/expression.h" #include "src/ast/member_accessor_expression.h" -#include "src/ast/module.h" #include "src/ast/scalar_constructor_expression.h" #include "src/ast/struct.h" #include "src/ast/struct_decoration.h" @@ -36,22 +34,21 @@ #include "src/ast/type_constructor_expression.h" #include "src/ast/uint_literal.h" #include "src/ast/variable_decl_statement.h" -#include "src/context.h" namespace tint { -namespace ast { namespace transform { namespace { -// TODO(idanr): What to do if these names are already used? + static const char kVertexBufferNamePrefix[] = "tint_pulling_vertex_buffer_"; static const char kStructBufferName[] = "data"; static const char kPullingPosVarName[] = "tint_pulling_pos"; static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index"; static const char kDefaultInstanceIndexName[] = "tint_pulling_instance_index"; + } // namespace -VertexPullingTransform::VertexPullingTransform(Context* ctx, Module* mod) +VertexPullingTransform::VertexPullingTransform(Context* ctx, ast::Module* mod) : ctx_(ctx), mod_(mod) {} VertexPullingTransform::~VertexPullingTransform() = default; @@ -78,7 +75,7 @@ bool VertexPullingTransform::Run() { // Find entry point auto* func = mod_->FindFunctionByNameAndStage(entry_point_name_, - PipelineStage::kVertex); + ast::PipelineStage::kVertex); if (func == nullptr) { SetError("Vertex stage entry point not found"); return false; @@ -125,12 +122,13 @@ void VertexPullingTransform::FindOrInsertVertexIndexIfUsed() { // Look for an existing vertex index builtin for (auto& v : mod_->global_variables()) { - if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) { + if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) { continue; } for (auto& d : v->AsDecorated()->decorations()) { - if (d->IsBuiltin() && d->AsBuiltin()->value() == Builtin::kVertexIdx) { + if (d->IsBuiltin() && + d->AsBuiltin()->value() == ast::Builtin::kVertexIdx) { vertex_index_name_ = v->name(); return; } @@ -140,12 +138,13 @@ void VertexPullingTransform::FindOrInsertVertexIndexIfUsed() { // We didn't find a vertex index builtin, so create one vertex_index_name_ = kDefaultVertexIndexName; - auto var = std::make_unique(std::make_unique( - vertex_index_name_, StorageClass::kInput, GetI32Type())); + auto var = + std::make_unique(std::make_unique( + vertex_index_name_, ast::StorageClass::kInput, GetI32Type())); - VariableDecorationList decorations; + ast::VariableDecorationList decorations; decorations.push_back( - std::make_unique(Builtin::kVertexIdx)); + std::make_unique(ast::Builtin::kVertexIdx)); var->set_decorations(std::move(decorations)); mod_->AddGlobalVariable(std::move(var)); @@ -166,12 +165,13 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() { // Look for an existing instance index builtin for (auto& v : mod_->global_variables()) { - if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) { + if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) { continue; } for (auto& d : v->AsDecorated()->decorations()) { - if (d->IsBuiltin() && d->AsBuiltin()->value() == Builtin::kInstanceIdx) { + if (d->IsBuiltin() && + d->AsBuiltin()->value() == ast::Builtin::kInstanceIdx) { instance_index_name_ = v->name(); return; } @@ -181,12 +181,13 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() { // We didn't find an instance index builtin, so create one instance_index_name_ = kDefaultInstanceIndexName; - auto var = std::make_unique(std::make_unique( - instance_index_name_, StorageClass::kInput, GetI32Type())); + auto var = + std::make_unique(std::make_unique( + instance_index_name_, ast::StorageClass::kInput, GetI32Type())); - VariableDecorationList decorations; + ast::VariableDecorationList decorations; decorations.push_back( - std::make_unique(Builtin::kInstanceIdx)); + std::make_unique(ast::Builtin::kInstanceIdx)); var->set_decorations(std::move(decorations)); mod_->AddGlobalVariable(std::move(var)); @@ -194,7 +195,7 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() { void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() { for (auto& v : mod_->global_variables()) { - if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) { + if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) { continue; } @@ -207,8 +208,8 @@ void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() { // This is where the replacement happens. Expressions use identifier // strings instead of pointers, so we don't need to update any other place // in the AST. - v = std::make_unique(v->name(), StorageClass::kPrivate, - v->type()); + v = std::make_unique( + v->name(), ast::StorageClass::kPrivate, v->type()); location_to_var_[location] = v.get(); break; } @@ -218,45 +219,51 @@ void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() { void VertexPullingTransform::AddVertexStorageBuffers() { // TODO(idanr): Make this readonly https://github.com/gpuweb/gpuweb/issues/935 // The array inside the struct definition - auto internal_array = std::make_unique(GetU32Type()); + auto internal_array = std::make_unique(GetU32Type()); internal_array->set_array_stride(4u); auto* internal_array_type = ctx_->type_mgr().Get(std::move(internal_array)); // Creating the struct type - StructMemberList members; - StructMemberDecorationList member_dec; - member_dec.push_back(std::make_unique(0u)); - members.push_back(std::make_unique( + ast::StructMemberList members; + ast::StructMemberDecorationList member_dec; + member_dec.push_back(std::make_unique(0u)); + + members.push_back(std::make_unique( kStructBufferName, internal_array_type, std::move(member_dec))); - auto* struct_type = ctx_->type_mgr().Get(std::make_unique( - std::make_unique(StructDecoration::kBlock, std::move(members)))); + + auto* struct_type = ctx_->type_mgr().Get( + std::make_unique(std::make_unique( + ast::StructDecoration::kBlock, std::move(members)))); for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) { // The decorated variable with struct type - auto var = std::make_unique(std::make_unique( - GetVertexBufferName(i), StorageClass::kStorageBuffer, struct_type)); + auto var = std::make_unique( + std::make_unique(GetVertexBufferName(i), + ast::StorageClass::kStorageBuffer, + struct_type)); // Add decorations - VariableDecorationList decorations; - decorations.push_back(std::make_unique(i)); - decorations.push_back(std::make_unique(pulling_set_)); + ast::VariableDecorationList decorations; + decorations.push_back(std::make_unique(i)); + decorations.push_back(std::make_unique(pulling_set_)); var->set_decorations(std::move(decorations)); mod_->AddGlobalVariable(std::move(var)); } } -void VertexPullingTransform::AddVertexPullingPreamble(Function* vertex_func) { +void VertexPullingTransform::AddVertexPullingPreamble( + ast::Function* vertex_func) { // Assign by looking at the vertex descriptor to find attributes with matching // location. // A block statement allowing us to use append instead of insert - auto block = std::make_unique(); + auto block = std::make_unique(); // Declare the |kPullingPosVarName| variable in the shader - auto pos_declaration = - std::make_unique(std::make_unique( - kPullingPosVarName, StorageClass::kFunction, GetI32Type())); + auto pos_declaration = std::make_unique( + std::make_unique( + kPullingPosVarName, ast::StorageClass::kFunction, GetI32Type())); // |kPullingPosVarName| refers to the byte location of the current read. We // declare a variable in the shader to avoid having to reuse Expression @@ -276,26 +283,26 @@ void VertexPullingTransform::AddVertexPullingPreamble(Function* vertex_func) { auto* v = it->second; // Identifier to index by - auto index_identifier = std::make_unique( + auto index_identifier = std::make_unique( buffer_layout.step_mode == InputStepMode::kVertex ? vertex_index_name_ : instance_index_name_); // An expression for the start of the read in the buffer in bytes - auto pos_value = std::make_unique( - BinaryOp::kAdd, - std::make_unique( - BinaryOp::kMultiply, std::move(index_identifier), + auto pos_value = std::make_unique( + ast::BinaryOp::kAdd, + std::make_unique( + ast::BinaryOp::kMultiply, std::move(index_identifier), GenUint(static_cast(buffer_layout.array_stride))), GenUint(static_cast(attribute_desc.offset))); // Update position of the read - auto set_pos_expr = std::make_unique( + auto set_pos_expr = std::make_unique( CreatePullingPositionIdent(), std::move(pos_value)); block->append(std::move(set_pos_expr)); - block->append(std::make_unique( - std::make_unique(v->name()), + block->append(std::make_unique( + std::make_unique(v->name()), AccessByFormat(i, attribute_desc.format))); } } @@ -303,17 +310,18 @@ void VertexPullingTransform::AddVertexPullingPreamble(Function* vertex_func) { vertex_func->body()->insert(0, std::move(block)); } -std::unique_ptr VertexPullingTransform::GenUint(uint32_t value) { - return std::make_unique( - std::make_unique(GetU32Type(), value)); +std::unique_ptr VertexPullingTransform::GenUint( + uint32_t value) { + return std::make_unique( + std::make_unique(GetU32Type(), value)); } -std::unique_ptr +std::unique_ptr VertexPullingTransform::CreatePullingPositionIdent() { - return std::make_unique(kPullingPosVarName); + return std::make_unique(kPullingPosVarName); } -std::unique_ptr VertexPullingTransform::AccessByFormat( +std::unique_ptr VertexPullingTransform::AccessByFormat( uint32_t buffer, VertexFormat format) { // TODO(idanr): this doesn't account for the format of the attribute in the @@ -341,41 +349,42 @@ std::unique_ptr VertexPullingTransform::AccessByFormat( } } -std::unique_ptr VertexPullingTransform::AccessU32( +std::unique_ptr VertexPullingTransform::AccessU32( uint32_t buffer, - std::unique_ptr pos) { + std::unique_ptr pos) { // Here we divide by 4, since the buffer is uint32 not uint8. The input buffer // has byte offsets for each attribute, and we will convert it to u32 indexes // by dividing. Then, that element is going to be read, and if needed, // unpacked into an appropriate variable. All reads should end up here as a // base case. - return std::make_unique( - std::make_unique( - std::make_unique(GetVertexBufferName(buffer)), - std::make_unique(kStructBufferName)), - std::make_unique(BinaryOp::kDivide, std::move(pos), - GenUint(4))); + return std::make_unique( + std::make_unique( + std::make_unique( + GetVertexBufferName(buffer)), + std::make_unique(kStructBufferName)), + std::make_unique(ast::BinaryOp::kDivide, + std::move(pos), GenUint(4))); } -std::unique_ptr VertexPullingTransform::AccessI32( +std::unique_ptr VertexPullingTransform::AccessI32( uint32_t buffer, - std::unique_ptr pos) { + std::unique_ptr pos) { // as reinterprets bits - return std::make_unique(GetI32Type(), - AccessU32(buffer, std::move(pos))); + return std::make_unique( + GetI32Type(), AccessU32(buffer, std::move(pos))); } -std::unique_ptr VertexPullingTransform::AccessF32( +std::unique_ptr VertexPullingTransform::AccessF32( uint32_t buffer, - std::unique_ptr pos) { + std::unique_ptr pos) { // as reinterprets bits - return std::make_unique(GetF32Type(), - AccessU32(buffer, std::move(pos))); + return std::make_unique( + GetF32Type(), AccessU32(buffer, std::move(pos))); } -std::unique_ptr VertexPullingTransform::AccessPrimitive( +std::unique_ptr VertexPullingTransform::AccessPrimitive( uint32_t buffer, - std::unique_ptr pos, + std::unique_ptr pos, VertexFormat format) { // This function uses a position expression to read, rather than using the // position variable. This allows us to read from offset positions relative to @@ -393,41 +402,42 @@ std::unique_ptr VertexPullingTransform::AccessPrimitive( } } -std::unique_ptr VertexPullingTransform::AccessVec( +std::unique_ptr VertexPullingTransform::AccessVec( uint32_t buffer, uint32_t element_stride, - type::Type* base_type, + ast::type::Type* base_type, VertexFormat base_format, uint32_t count) { - ExpressionList expr_list; + ast::ExpressionList expr_list; for (uint32_t i = 0; i < count; ++i) { // Offset read position by element_stride for each component - auto cur_pos = std::make_unique( - BinaryOp::kAdd, CreatePullingPositionIdent(), + auto cur_pos = std::make_unique( + ast::BinaryOp::kAdd, CreatePullingPositionIdent(), GenUint(element_stride * i)); expr_list.push_back( AccessPrimitive(buffer, std::move(cur_pos), base_format)); } - return std::make_unique( + return std::make_unique( ctx_->type_mgr().Get( - std::make_unique(base_type, count)), + std::make_unique(base_type, count)), std::move(expr_list)); } -type::Type* VertexPullingTransform::GetU32Type() { - return ctx_->type_mgr().Get(std::make_unique()); +ast::type::Type* VertexPullingTransform::GetU32Type() { + return ctx_->type_mgr().Get(std::make_unique()); } -type::Type* VertexPullingTransform::GetI32Type() { - return ctx_->type_mgr().Get(std::make_unique()); +ast::type::Type* VertexPullingTransform::GetI32Type() { + return ctx_->type_mgr().Get(std::make_unique()); } -type::Type* VertexPullingTransform::GetF32Type() { - return ctx_->type_mgr().Get(std::make_unique()); +ast::type::Type* VertexPullingTransform::GetF32Type() { + return ctx_->type_mgr().Get(std::make_unique()); } VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default; + VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor( uint64_t in_array_stride, InputStepMode in_step_mode, @@ -435,21 +445,25 @@ VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor( : array_stride(std::move(in_array_stride)), step_mode(std::move(in_step_mode)), attributes(std::move(in_attributes)) {} + VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor( const VertexBufferLayoutDescriptor& other) : array_stride(other.array_stride), step_mode(other.step_mode), attributes(other.attributes) {} + VertexBufferLayoutDescriptor::~VertexBufferLayoutDescriptor() = default; VertexStateDescriptor::VertexStateDescriptor() = default; + VertexStateDescriptor::VertexStateDescriptor( std::vector in_vertex_buffers) : vertex_buffers(std::move(in_vertex_buffers)) {} + VertexStateDescriptor::VertexStateDescriptor(const VertexStateDescriptor& other) : vertex_buffers(other.vertex_buffers) {} + VertexStateDescriptor::~VertexStateDescriptor() = default; } // namespace transform -} // namespace ast } // namespace tint diff --git a/src/ast/transform/vertex_pulling_transform.h b/src/transform/vertex_pulling_transform.h similarity index 81% rename from src/ast/transform/vertex_pulling_transform.h rename to src/transform/vertex_pulling_transform.h index 030c517820..c1d9195fbf 100644 --- a/src/ast/transform/vertex_pulling_transform.h +++ b/src/transform/vertex_pulling_transform.h @@ -12,8 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_AST_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ -#define SRC_AST_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ +#ifndef SRC_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ +#define SRC_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ + +#include "src/ast/expression.h" +#include "src/ast/function.h" +#include "src/ast/module.h" +#include "src/ast/statement.h" +#include "src/ast/variable.h" +#include "src/context.h" #include #include @@ -21,22 +28,6 @@ #include namespace tint { - -class Context; - -namespace ast { - -class EntryPoint; -class Expression; -class Function; -class Module; -class Statement; -class Variable; - -namespace type { -class Type; -} // namespace type - namespace transform { /// Describes the format of data in a vertex buffer @@ -102,6 +93,7 @@ struct VertexBufferLayoutDescriptor { /// Copy constructor /// @param other the struct to copy VertexBufferLayoutDescriptor(const VertexBufferLayoutDescriptor& other); + ~VertexBufferLayoutDescriptor(); /// The array stride used in the in buffer @@ -124,6 +116,7 @@ struct VertexStateDescriptor { /// Copy constructor /// @param other the struct to copy VertexStateDescriptor(const VertexStateDescriptor& other); + ~VertexStateDescriptor(); /// The vertex buffers @@ -154,7 +147,7 @@ class VertexPullingTransform { /// Constructor /// @param ctx the tint context /// @param mod the module to convert to vertex pulling - VertexPullingTransform(Context* ctx, Module* mod); + VertexPullingTransform(Context* ctx, ast::Module* mod); ~VertexPullingTransform(); /// Sets the vertex state descriptor, containing info about attributes @@ -196,49 +189,53 @@ class VertexPullingTransform { void AddVertexStorageBuffers(); /// Adds assignment to the variables from the buffers - void AddVertexPullingPreamble(Function* vertex_func); + void AddVertexPullingPreamble(ast::Function* vertex_func); /// Generates an expression holding a constant uint /// @param value uint value - std::unique_ptr GenUint(uint32_t value); + std::unique_ptr GenUint(uint32_t value); /// Generates an expression to read the shader value |kPullingPosVarName| - std::unique_ptr CreatePullingPositionIdent(); + std::unique_ptr CreatePullingPositionIdent(); /// Generates an expression reading from a buffer a specific format. /// This reads the value wherever |kPullingPosVarName| points to at the time /// of the read. /// @param buffer the index of the vertex buffer /// @param format the format to read - std::unique_ptr AccessByFormat(uint32_t buffer, - VertexFormat format); + std::unique_ptr AccessByFormat(uint32_t buffer, + VertexFormat format); /// Generates an expression reading a uint32 from a vertex buffer /// @param buffer the index of the vertex buffer /// @param pos an expression for the position of the access, in bytes - std::unique_ptr AccessU32(uint32_t buffer, - std::unique_ptr pos); + std::unique_ptr AccessU32( + uint32_t buffer, + std::unique_ptr pos); /// Generates an expression reading an int32 from a vertex buffer /// @param buffer the index of the vertex buffer /// @param pos an expression for the position of the access, in bytes - std::unique_ptr AccessI32(uint32_t buffer, - std::unique_ptr pos); + std::unique_ptr AccessI32( + uint32_t buffer, + std::unique_ptr pos); /// Generates an expression reading a float from a vertex buffer /// @param buffer the index of the vertex buffer /// @param pos an expression for the position of the access, in bytes - std::unique_ptr AccessF32(uint32_t buffer, - std::unique_ptr pos); + std::unique_ptr AccessF32( + uint32_t buffer, + std::unique_ptr pos); /// Generates an expression reading a basic type (u32, i32, f32) from a vertex /// buffer /// @param buffer the index of the vertex buffer /// @param pos an expression for the position of the access, in bytes /// @param format the underlying vertex format - std::unique_ptr AccessPrimitive(uint32_t buffer, - std::unique_ptr pos, - VertexFormat format); + std::unique_ptr AccessPrimitive( + uint32_t buffer, + std::unique_ptr pos, + VertexFormat format); /// Generates an expression reading a vec2/3/4 from a vertex buffer. /// This reads the value wherever |kPullingPosVarName| points to at the time @@ -248,19 +245,19 @@ class VertexPullingTransform { /// @param base_type underlying AST type /// @param base_format underlying vertex format /// @param count how many elements the vector has - std::unique_ptr AccessVec(uint32_t buffer, - uint32_t element_stride, - type::Type* base_type, - VertexFormat base_format, - uint32_t count); + std::unique_ptr AccessVec(uint32_t buffer, + uint32_t element_stride, + ast::type::Type* base_type, + VertexFormat base_format, + uint32_t count); // Used to grab corresponding types from the type manager - type::Type* GetU32Type(); - type::Type* GetI32Type(); - type::Type* GetF32Type(); + ast::type::Type* GetU32Type(); + ast::type::Type* GetI32Type(); + ast::type::Type* GetF32Type(); Context* ctx_ = nullptr; - Module* mod_ = nullptr; + ast::Module* mod_ = nullptr; std::string entry_point_name_; std::string error_; @@ -270,12 +267,11 @@ class VertexPullingTransform { // Default to 4 as it is past the limits of user-accessible sets uint32_t pulling_set_ = 4u; - std::unordered_map location_to_var_; + std::unordered_map location_to_var_; std::unique_ptr vertex_state_; }; } // namespace transform -} // namespace ast } // namespace tint -#endif // SRC_AST_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ +#endif // SRC_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_ diff --git a/src/ast/transform/vertex_pulling_transform_test.cc b/src/transform/vertex_pulling_transform_test.cc similarity index 92% rename from src/ast/transform/vertex_pulling_transform_test.cc rename to src/transform/vertex_pulling_transform_test.cc index e2569b22f5..59599ed9e7 100644 --- a/src/ast/transform/vertex_pulling_transform_test.cc +++ b/src/transform/vertex_pulling_transform_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/ast/transform/vertex_pulling_transform.h" +#include "src/transform/vertex_pulling_transform.h" #include "gtest/gtest.h" #include "src/ast/decorated_variable.h" @@ -27,7 +27,6 @@ #include "src/validator.h" namespace tint { -namespace ast { namespace transform { namespace { @@ -40,9 +39,9 @@ class VertexPullingTransformHelper { // Create basic module with an entry point and vertex function void InitBasicModule() { - auto func = std::make_unique( - "main", VariableList{}, - ctx_.type_mgr().Get(std::make_unique())); + auto func = std::make_unique( + "main", ast::VariableList{}, + ctx_.type_mgr().Get(std::make_unique())); func->add_decoration( std::make_unique(ast::PipelineStage ::kVertex)); mod()->AddFunction(std::move(func)); @@ -52,7 +51,7 @@ class VertexPullingTransformHelper { void InitTransform(VertexStateDescriptor vertex_state) { EXPECT_TRUE(mod_->IsValid()); - tint::TypeDeterminer td(&ctx_, mod_.get()); + TypeDeterminer td(&ctx_, mod_.get()); EXPECT_TRUE(td.Determine()); transform_->SetVertexState( @@ -63,12 +62,12 @@ class VertexPullingTransformHelper { // Inserts a variable which will be converted to vertex pulling void AddVertexInputVariable(uint32_t location, std::string name, - type::Type* type) { - auto var = std::make_unique( - std::make_unique(name, StorageClass::kInput, type)); + ast::type::Type* type) { + auto var = std::make_unique( + std::make_unique(name, ast::StorageClass::kInput, type)); - VariableDecorationList decorations; - decorations.push_back(std::make_unique(location)); + ast::VariableDecorationList decorations; + decorations.push_back(std::make_unique(location)); var->set_decorations(std::move(decorations)); mod_->AddGlobalVariable(std::move(var)); @@ -108,9 +107,9 @@ TEST_F(VertexPullingTransformTest, Error_InvalidEntryPoint) { } TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) { - auto func = std::make_unique( - "main", VariableList{}, - ctx()->type_mgr().Get(std::make_unique())); + auto func = std::make_unique( + "main", ast::VariableList{}, + ctx()->type_mgr().Get(std::make_unique())); func->add_decoration( std::make_unique(ast::PipelineStage::kFragment)); mod()->AddFunction(std::move(func)); @@ -129,7 +128,7 @@ TEST_F(VertexPullingTransformTest, BasicModule) { TEST_F(VertexPullingTransformTest, OneAttribute) { InitBasicModule(); - type::F32Type f32; + ast::type::F32Type f32; AddVertexInputVariable(0, "var_a", &f32); InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}}); @@ -209,7 +208,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { InitBasicModule(); - type::F32Type f32; + ast::type::F32Type f32; AddVertexInputVariable(0, "var_a", &f32); InitTransform( @@ -290,7 +289,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { InitBasicModule(); - type::F32Type f32; + ast::type::F32Type f32; AddVertexInputVariable(0, "var_a", &f32); InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}}); @@ -372,32 +371,32 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { InitBasicModule(); - type::F32Type f32; + ast::type::F32Type f32; AddVertexInputVariable(0, "var_a", &f32); AddVertexInputVariable(1, "var_b", &f32); - type::I32Type i32; + ast::type::I32Type i32; { - auto vertex_index_var = - std::make_unique(std::make_unique( - "custom_vertex_index", StorageClass::kInput, &i32)); + auto vertex_index_var = std::make_unique( + std::make_unique("custom_vertex_index", + ast::StorageClass::kInput, &i32)); - VariableDecorationList decorations; + ast::VariableDecorationList decorations; decorations.push_back( - std::make_unique(Builtin::kVertexIdx)); + std::make_unique(ast::Builtin::kVertexIdx)); vertex_index_var->set_decorations(std::move(decorations)); mod()->AddGlobalVariable(std::move(vertex_index_var)); } { - auto instance_index_var = - std::make_unique(std::make_unique( - "custom_instance_index", StorageClass::kInput, &i32)); + auto instance_index_var = std::make_unique( + std::make_unique("custom_instance_index", + ast::StorageClass::kInput, &i32)); - VariableDecorationList decorations; + ast::VariableDecorationList decorations; decorations.push_back( - std::make_unique(Builtin::kInstanceIdx)); + std::make_unique(ast::Builtin::kInstanceIdx)); instance_index_var->set_decorations(std::move(decorations)); mod()->AddGlobalVariable(std::move(instance_index_var)); @@ -532,10 +531,10 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { InitBasicModule(); - type::F32Type f32; + ast::type::F32Type f32; AddVertexInputVariable(0, "var_a", &f32); - type::ArrayType vec4_f32{&f32, 4u}; + ast::type::ArrayType vec4_f32{&f32, 4u}; AddVertexInputVariable(1, "var_b", &vec4_f32); InitTransform( @@ -709,14 +708,14 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { InitBasicModule(); - type::F32Type f32; - type::ArrayType vec2_f32{&f32, 2u}; + ast::type::F32Type f32; + ast::type::ArrayType vec2_f32{&f32, 2u}; AddVertexInputVariable(0, "var_a", &vec2_f32); - type::ArrayType vec3_f32{&f32, 3u}; + ast::type::ArrayType vec3_f32{&f32, 3u}; AddVertexInputVariable(1, "var_b", &vec3_f32); - type::ArrayType vec4_f32{&f32, 4u}; + ast::type::ArrayType vec4_f32{&f32, 4u}; AddVertexInputVariable(2, "var_c", &vec4_f32); InitTransform( @@ -1005,5 +1004,4 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { } // namespace } // namespace transform -} // namespace ast } // namespace tint