mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-23 15:03:43 +00:00
[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 <rharrison@chromium.org> Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
parent
45292213bd
commit
5c948e4f8f
6
BUILD.gn
6
BUILD.gn
@ -315,8 +315,6 @@ source_set("libtint_core_src") {
|
|||||||
"src/ast/struct_member_offset_decoration.h",
|
"src/ast/struct_member_offset_decoration.h",
|
||||||
"src/ast/switch_statement.cc",
|
"src/ast/switch_statement.cc",
|
||||||
"src/ast/switch_statement.h",
|
"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.cc",
|
||||||
"src/ast/type/alias_type.h",
|
"src/ast/type/alias_type.h",
|
||||||
"src/ast/type/array_type.cc",
|
"src/ast/type/array_type.cc",
|
||||||
@ -375,6 +373,8 @@ source_set("libtint_core_src") {
|
|||||||
"src/reader/reader.h",
|
"src/reader/reader.h",
|
||||||
"src/scope_stack.h",
|
"src/scope_stack.h",
|
||||||
"src/source.h",
|
"src/source.h",
|
||||||
|
"src/transform/vertex_pulling_transform.cc",
|
||||||
|
"src/transform/vertex_pulling_transform.h",
|
||||||
"src/type_determiner.cc",
|
"src/type_determiner.cc",
|
||||||
"src/type_determiner.h",
|
"src/type_determiner.h",
|
||||||
"src/type_manager.cc",
|
"src/type_manager.cc",
|
||||||
@ -723,7 +723,6 @@ source_set("tint_unittests_core_src") {
|
|||||||
"src/ast/struct_member_test.cc",
|
"src/ast/struct_member_test.cc",
|
||||||
"src/ast/struct_test.cc",
|
"src/ast/struct_test.cc",
|
||||||
"src/ast/switch_statement_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/alias_type_test.cc",
|
||||||
"src/ast/type/array_type_test.cc",
|
"src/ast/type/array_type_test.cc",
|
||||||
"src/ast/type/bool_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/variable_test.cc",
|
||||||
"src/ast/workgroup_decoration_test.cc",
|
"src/ast/workgroup_decoration_test.cc",
|
||||||
"src/scope_stack_test.cc",
|
"src/scope_stack_test.cc",
|
||||||
|
"src/transform/vertex_pulling_transform_test.cc",
|
||||||
"src/type_determiner_test.cc",
|
"src/type_determiner_test.cc",
|
||||||
"src/type_manager_test.cc",
|
"src/type_manager_test.cc",
|
||||||
"src/validator_control_block_test.cc",
|
"src/validator_control_block_test.cc",
|
||||||
|
@ -21,13 +21,12 @@
|
|||||||
#include "src/ast/pipeline_stage.h"
|
#include "src/ast/pipeline_stage.h"
|
||||||
#include "src/context.h"
|
#include "src/context.h"
|
||||||
#include "src/reader/reader.h"
|
#include "src/reader/reader.h"
|
||||||
|
#include "src/transform/vertex_pulling_transform.h"
|
||||||
#include "src/type_determiner.h"
|
#include "src/type_determiner.h"
|
||||||
#include "src/type_manager.h"
|
#include "src/type_manager.h"
|
||||||
#include "src/validator.h"
|
#include "src/validator.h"
|
||||||
#include "src/writer/writer.h"
|
#include "src/writer/writer.h"
|
||||||
|
|
||||||
#include "src/ast/transform/vertex_pulling_transform.h"
|
|
||||||
|
|
||||||
#if TINT_BUILD_SPV_READER
|
#if TINT_BUILD_SPV_READER
|
||||||
#include "src/reader/spirv/parser.h"
|
#include "src/reader/spirv/parser.h"
|
||||||
#endif // TINT_BUILD_SPV_READER
|
#endif // TINT_BUILD_SPV_READER
|
||||||
|
@ -136,8 +136,6 @@ set(TINT_LIB_SRCS
|
|||||||
ast/struct_member_offset_decoration.h
|
ast/struct_member_offset_decoration.h
|
||||||
ast/switch_statement.cc
|
ast/switch_statement.cc
|
||||||
ast/switch_statement.h
|
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.h
|
||||||
ast/type_constructor_expression.cc
|
ast/type_constructor_expression.cc
|
||||||
ast/type/alias_type.cc
|
ast/type/alias_type.cc
|
||||||
@ -196,6 +194,8 @@ set(TINT_LIB_SRCS
|
|||||||
reader/reader.h
|
reader/reader.h
|
||||||
scope_stack.h
|
scope_stack.h
|
||||||
source.h
|
source.h
|
||||||
|
transform/vertex_pulling_transform.cc
|
||||||
|
transform/vertex_pulling_transform.h
|
||||||
type_determiner.cc
|
type_determiner.cc
|
||||||
type_determiner.h
|
type_determiner.h
|
||||||
type_manager.cc
|
type_manager.cc
|
||||||
@ -333,7 +333,6 @@ set(TINT_TEST_SRCS
|
|||||||
ast/struct_member_offset_decoration_test.cc
|
ast/struct_member_offset_decoration_test.cc
|
||||||
ast/struct_test.cc
|
ast/struct_test.cc
|
||||||
ast/switch_statement_test.cc
|
ast/switch_statement_test.cc
|
||||||
ast/transform/vertex_pulling_transform_test.cc
|
|
||||||
ast/type/alias_type_test.cc
|
ast/type/alias_type_test.cc
|
||||||
ast/type/array_type_test.cc
|
ast/type/array_type_test.cc
|
||||||
ast/type/bool_type_test.cc
|
ast/type/bool_type_test.cc
|
||||||
@ -356,6 +355,7 @@ set(TINT_TEST_SRCS
|
|||||||
ast/variable_test.cc
|
ast/variable_test.cc
|
||||||
ast/workgroup_decoration_test.cc
|
ast/workgroup_decoration_test.cc
|
||||||
scope_stack_test.cc
|
scope_stack_test.cc
|
||||||
|
transform/vertex_pulling_transform_test.cc
|
||||||
type_determiner_test.cc
|
type_determiner_test.cc
|
||||||
type_manager_test.cc
|
type_manager_test.cc
|
||||||
validator_control_block_test.cc
|
validator_control_block_test.cc
|
||||||
|
@ -12,16 +12,14 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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/array_accessor_expression.h"
|
||||||
#include "src/ast/assignment_statement.h"
|
#include "src/ast/assignment_statement.h"
|
||||||
#include "src/ast/binary_expression.h"
|
#include "src/ast/binary_expression.h"
|
||||||
#include "src/ast/bitcast_expression.h"
|
#include "src/ast/bitcast_expression.h"
|
||||||
#include "src/ast/decorated_variable.h"
|
#include "src/ast/decorated_variable.h"
|
||||||
#include "src/ast/expression.h"
|
|
||||||
#include "src/ast/member_accessor_expression.h"
|
#include "src/ast/member_accessor_expression.h"
|
||||||
#include "src/ast/module.h"
|
|
||||||
#include "src/ast/scalar_constructor_expression.h"
|
#include "src/ast/scalar_constructor_expression.h"
|
||||||
#include "src/ast/struct.h"
|
#include "src/ast/struct.h"
|
||||||
#include "src/ast/struct_decoration.h"
|
#include "src/ast/struct_decoration.h"
|
||||||
@ -36,22 +34,21 @@
|
|||||||
#include "src/ast/type_constructor_expression.h"
|
#include "src/ast/type_constructor_expression.h"
|
||||||
#include "src/ast/uint_literal.h"
|
#include "src/ast/uint_literal.h"
|
||||||
#include "src/ast/variable_decl_statement.h"
|
#include "src/ast/variable_decl_statement.h"
|
||||||
#include "src/context.h"
|
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
|
||||||
namespace transform {
|
namespace transform {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// TODO(idanr): What to do if these names are already used?
|
|
||||||
static const char kVertexBufferNamePrefix[] = "tint_pulling_vertex_buffer_";
|
static const char kVertexBufferNamePrefix[] = "tint_pulling_vertex_buffer_";
|
||||||
static const char kStructBufferName[] = "data";
|
static const char kStructBufferName[] = "data";
|
||||||
static const char kPullingPosVarName[] = "tint_pulling_pos";
|
static const char kPullingPosVarName[] = "tint_pulling_pos";
|
||||||
static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index";
|
static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index";
|
||||||
static const char kDefaultInstanceIndexName[] = "tint_pulling_instance_index";
|
static const char kDefaultInstanceIndexName[] = "tint_pulling_instance_index";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
VertexPullingTransform::VertexPullingTransform(Context* ctx, Module* mod)
|
VertexPullingTransform::VertexPullingTransform(Context* ctx, ast::Module* mod)
|
||||||
: ctx_(ctx), mod_(mod) {}
|
: ctx_(ctx), mod_(mod) {}
|
||||||
|
|
||||||
VertexPullingTransform::~VertexPullingTransform() = default;
|
VertexPullingTransform::~VertexPullingTransform() = default;
|
||||||
@ -78,7 +75,7 @@ bool VertexPullingTransform::Run() {
|
|||||||
|
|
||||||
// Find entry point
|
// Find entry point
|
||||||
auto* func = mod_->FindFunctionByNameAndStage(entry_point_name_,
|
auto* func = mod_->FindFunctionByNameAndStage(entry_point_name_,
|
||||||
PipelineStage::kVertex);
|
ast::PipelineStage::kVertex);
|
||||||
if (func == nullptr) {
|
if (func == nullptr) {
|
||||||
SetError("Vertex stage entry point not found");
|
SetError("Vertex stage entry point not found");
|
||||||
return false;
|
return false;
|
||||||
@ -125,12 +122,13 @@ void VertexPullingTransform::FindOrInsertVertexIndexIfUsed() {
|
|||||||
|
|
||||||
// Look for an existing vertex index builtin
|
// Look for an existing vertex index builtin
|
||||||
for (auto& v : mod_->global_variables()) {
|
for (auto& v : mod_->global_variables()) {
|
||||||
if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) {
|
if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& d : v->AsDecorated()->decorations()) {
|
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();
|
vertex_index_name_ = v->name();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -140,12 +138,13 @@ void VertexPullingTransform::FindOrInsertVertexIndexIfUsed() {
|
|||||||
// We didn't find a vertex index builtin, so create one
|
// We didn't find a vertex index builtin, so create one
|
||||||
vertex_index_name_ = kDefaultVertexIndexName;
|
vertex_index_name_ = kDefaultVertexIndexName;
|
||||||
|
|
||||||
auto var = std::make_unique<DecoratedVariable>(std::make_unique<Variable>(
|
auto var =
|
||||||
vertex_index_name_, StorageClass::kInput, GetI32Type()));
|
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||||
|
vertex_index_name_, ast::StorageClass::kInput, GetI32Type()));
|
||||||
|
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(
|
decorations.push_back(
|
||||||
std::make_unique<BuiltinDecoration>(Builtin::kVertexIdx));
|
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx));
|
||||||
|
|
||||||
var->set_decorations(std::move(decorations));
|
var->set_decorations(std::move(decorations));
|
||||||
mod_->AddGlobalVariable(std::move(var));
|
mod_->AddGlobalVariable(std::move(var));
|
||||||
@ -166,12 +165,13 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() {
|
|||||||
|
|
||||||
// Look for an existing instance index builtin
|
// Look for an existing instance index builtin
|
||||||
for (auto& v : mod_->global_variables()) {
|
for (auto& v : mod_->global_variables()) {
|
||||||
if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) {
|
if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& d : v->AsDecorated()->decorations()) {
|
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();
|
instance_index_name_ = v->name();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -181,12 +181,13 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() {
|
|||||||
// We didn't find an instance index builtin, so create one
|
// We didn't find an instance index builtin, so create one
|
||||||
instance_index_name_ = kDefaultInstanceIndexName;
|
instance_index_name_ = kDefaultInstanceIndexName;
|
||||||
|
|
||||||
auto var = std::make_unique<DecoratedVariable>(std::make_unique<Variable>(
|
auto var =
|
||||||
instance_index_name_, StorageClass::kInput, GetI32Type()));
|
std::make_unique<ast::DecoratedVariable>(std::make_unique<ast::Variable>(
|
||||||
|
instance_index_name_, ast::StorageClass::kInput, GetI32Type()));
|
||||||
|
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(
|
decorations.push_back(
|
||||||
std::make_unique<BuiltinDecoration>(Builtin::kInstanceIdx));
|
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx));
|
||||||
|
|
||||||
var->set_decorations(std::move(decorations));
|
var->set_decorations(std::move(decorations));
|
||||||
mod_->AddGlobalVariable(std::move(var));
|
mod_->AddGlobalVariable(std::move(var));
|
||||||
@ -194,7 +195,7 @@ void VertexPullingTransform::FindOrInsertInstanceIndexIfUsed() {
|
|||||||
|
|
||||||
void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
|
void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
|
||||||
for (auto& v : mod_->global_variables()) {
|
for (auto& v : mod_->global_variables()) {
|
||||||
if (!v->IsDecorated() || v->storage_class() != StorageClass::kInput) {
|
if (!v->IsDecorated() || v->storage_class() != ast::StorageClass::kInput) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +208,8 @@ void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
|
|||||||
// This is where the replacement happens. Expressions use identifier
|
// This is where the replacement happens. Expressions use identifier
|
||||||
// strings instead of pointers, so we don't need to update any other place
|
// strings instead of pointers, so we don't need to update any other place
|
||||||
// in the AST.
|
// in the AST.
|
||||||
v = std::make_unique<Variable>(v->name(), StorageClass::kPrivate,
|
v = std::make_unique<ast::Variable>(
|
||||||
v->type());
|
v->name(), ast::StorageClass::kPrivate, v->type());
|
||||||
location_to_var_[location] = v.get();
|
location_to_var_[location] = v.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -218,45 +219,51 @@ void VertexPullingTransform::ConvertVertexInputVariablesToPrivate() {
|
|||||||
void VertexPullingTransform::AddVertexStorageBuffers() {
|
void VertexPullingTransform::AddVertexStorageBuffers() {
|
||||||
// TODO(idanr): Make this readonly https://github.com/gpuweb/gpuweb/issues/935
|
// TODO(idanr): Make this readonly https://github.com/gpuweb/gpuweb/issues/935
|
||||||
// The array inside the struct definition
|
// The array inside the struct definition
|
||||||
auto internal_array = std::make_unique<type::ArrayType>(GetU32Type());
|
auto internal_array = std::make_unique<ast::type::ArrayType>(GetU32Type());
|
||||||
internal_array->set_array_stride(4u);
|
internal_array->set_array_stride(4u);
|
||||||
auto* internal_array_type = ctx_->type_mgr().Get(std::move(internal_array));
|
auto* internal_array_type = ctx_->type_mgr().Get(std::move(internal_array));
|
||||||
|
|
||||||
// Creating the struct type
|
// Creating the struct type
|
||||||
StructMemberList members;
|
ast::StructMemberList members;
|
||||||
StructMemberDecorationList member_dec;
|
ast::StructMemberDecorationList member_dec;
|
||||||
member_dec.push_back(std::make_unique<StructMemberOffsetDecoration>(0u));
|
member_dec.push_back(std::make_unique<ast::StructMemberOffsetDecoration>(0u));
|
||||||
members.push_back(std::make_unique<StructMember>(
|
|
||||||
|
members.push_back(std::make_unique<ast::StructMember>(
|
||||||
kStructBufferName, internal_array_type, std::move(member_dec)));
|
kStructBufferName, internal_array_type, std::move(member_dec)));
|
||||||
auto* struct_type = ctx_->type_mgr().Get(std::make_unique<type::StructType>(
|
|
||||||
std::make_unique<Struct>(StructDecoration::kBlock, std::move(members))));
|
auto* struct_type = ctx_->type_mgr().Get(
|
||||||
|
std::make_unique<ast::type::StructType>(std::make_unique<ast::Struct>(
|
||||||
|
ast::StructDecoration::kBlock, std::move(members))));
|
||||||
|
|
||||||
for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) {
|
for (uint32_t i = 0; i < vertex_state_->vertex_buffers.size(); ++i) {
|
||||||
// The decorated variable with struct type
|
// The decorated variable with struct type
|
||||||
auto var = std::make_unique<DecoratedVariable>(std::make_unique<Variable>(
|
auto var = std::make_unique<ast::DecoratedVariable>(
|
||||||
GetVertexBufferName(i), StorageClass::kStorageBuffer, struct_type));
|
std::make_unique<ast::Variable>(GetVertexBufferName(i),
|
||||||
|
ast::StorageClass::kStorageBuffer,
|
||||||
|
struct_type));
|
||||||
|
|
||||||
// Add decorations
|
// Add decorations
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(std::make_unique<BindingDecoration>(i));
|
decorations.push_back(std::make_unique<ast::BindingDecoration>(i));
|
||||||
decorations.push_back(std::make_unique<SetDecoration>(pulling_set_));
|
decorations.push_back(std::make_unique<ast::SetDecoration>(pulling_set_));
|
||||||
var->set_decorations(std::move(decorations));
|
var->set_decorations(std::move(decorations));
|
||||||
|
|
||||||
mod_->AddGlobalVariable(std::move(var));
|
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
|
// Assign by looking at the vertex descriptor to find attributes with matching
|
||||||
// location.
|
// location.
|
||||||
|
|
||||||
// A block statement allowing us to use append instead of insert
|
// A block statement allowing us to use append instead of insert
|
||||||
auto block = std::make_unique<BlockStatement>();
|
auto block = std::make_unique<ast::BlockStatement>();
|
||||||
|
|
||||||
// Declare the |kPullingPosVarName| variable in the shader
|
// Declare the |kPullingPosVarName| variable in the shader
|
||||||
auto pos_declaration =
|
auto pos_declaration = std::make_unique<ast::VariableDeclStatement>(
|
||||||
std::make_unique<VariableDeclStatement>(std::make_unique<Variable>(
|
std::make_unique<ast::Variable>(
|
||||||
kPullingPosVarName, StorageClass::kFunction, GetI32Type()));
|
kPullingPosVarName, ast::StorageClass::kFunction, GetI32Type()));
|
||||||
|
|
||||||
// |kPullingPosVarName| refers to the byte location of the current read. We
|
// |kPullingPosVarName| refers to the byte location of the current read. We
|
||||||
// declare a variable in the shader to avoid having to reuse Expression
|
// 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;
|
auto* v = it->second;
|
||||||
|
|
||||||
// Identifier to index by
|
// Identifier to index by
|
||||||
auto index_identifier = std::make_unique<IdentifierExpression>(
|
auto index_identifier = std::make_unique<ast::IdentifierExpression>(
|
||||||
buffer_layout.step_mode == InputStepMode::kVertex
|
buffer_layout.step_mode == InputStepMode::kVertex
|
||||||
? vertex_index_name_
|
? vertex_index_name_
|
||||||
: instance_index_name_);
|
: instance_index_name_);
|
||||||
|
|
||||||
// An expression for the start of the read in the buffer in bytes
|
// An expression for the start of the read in the buffer in bytes
|
||||||
auto pos_value = std::make_unique<BinaryExpression>(
|
auto pos_value = std::make_unique<ast::BinaryExpression>(
|
||||||
BinaryOp::kAdd,
|
ast::BinaryOp::kAdd,
|
||||||
std::make_unique<BinaryExpression>(
|
std::make_unique<ast::BinaryExpression>(
|
||||||
BinaryOp::kMultiply, std::move(index_identifier),
|
ast::BinaryOp::kMultiply, std::move(index_identifier),
|
||||||
GenUint(static_cast<uint32_t>(buffer_layout.array_stride))),
|
GenUint(static_cast<uint32_t>(buffer_layout.array_stride))),
|
||||||
GenUint(static_cast<uint32_t>(attribute_desc.offset)));
|
GenUint(static_cast<uint32_t>(attribute_desc.offset)));
|
||||||
|
|
||||||
// Update position of the read
|
// Update position of the read
|
||||||
auto set_pos_expr = std::make_unique<AssignmentStatement>(
|
auto set_pos_expr = std::make_unique<ast::AssignmentStatement>(
|
||||||
CreatePullingPositionIdent(), std::move(pos_value));
|
CreatePullingPositionIdent(), std::move(pos_value));
|
||||||
block->append(std::move(set_pos_expr));
|
block->append(std::move(set_pos_expr));
|
||||||
|
|
||||||
block->append(std::make_unique<AssignmentStatement>(
|
block->append(std::make_unique<ast::AssignmentStatement>(
|
||||||
std::make_unique<IdentifierExpression>(v->name()),
|
std::make_unique<ast::IdentifierExpression>(v->name()),
|
||||||
AccessByFormat(i, attribute_desc.format)));
|
AccessByFormat(i, attribute_desc.format)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,17 +310,18 @@ void VertexPullingTransform::AddVertexPullingPreamble(Function* vertex_func) {
|
|||||||
vertex_func->body()->insert(0, std::move(block));
|
vertex_func->body()->insert(0, std::move(block));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::GenUint(uint32_t value) {
|
std::unique_ptr<ast::Expression> VertexPullingTransform::GenUint(
|
||||||
return std::make_unique<ScalarConstructorExpression>(
|
uint32_t value) {
|
||||||
std::make_unique<UintLiteral>(GetU32Type(), value));
|
return std::make_unique<ast::ScalarConstructorExpression>(
|
||||||
|
std::make_unique<ast::UintLiteral>(GetU32Type(), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression>
|
std::unique_ptr<ast::Expression>
|
||||||
VertexPullingTransform::CreatePullingPositionIdent() {
|
VertexPullingTransform::CreatePullingPositionIdent() {
|
||||||
return std::make_unique<IdentifierExpression>(kPullingPosVarName);
|
return std::make_unique<ast::IdentifierExpression>(kPullingPosVarName);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessByFormat(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessByFormat(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
VertexFormat format) {
|
VertexFormat format) {
|
||||||
// TODO(idanr): this doesn't account for the format of the attribute in the
|
// TODO(idanr): this doesn't account for the format of the attribute in the
|
||||||
@ -341,41 +349,42 @@ std::unique_ptr<Expression> VertexPullingTransform::AccessByFormat(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessU32(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessU32(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
std::unique_ptr<Expression> pos) {
|
std::unique_ptr<ast::Expression> pos) {
|
||||||
// Here we divide by 4, since the buffer is uint32 not uint8. The input buffer
|
// 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
|
// 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,
|
// 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
|
// unpacked into an appropriate variable. All reads should end up here as a
|
||||||
// base case.
|
// base case.
|
||||||
return std::make_unique<ArrayAccessorExpression>(
|
return std::make_unique<ast::ArrayAccessorExpression>(
|
||||||
std::make_unique<MemberAccessorExpression>(
|
std::make_unique<ast::MemberAccessorExpression>(
|
||||||
std::make_unique<IdentifierExpression>(GetVertexBufferName(buffer)),
|
std::make_unique<ast::IdentifierExpression>(
|
||||||
std::make_unique<IdentifierExpression>(kStructBufferName)),
|
GetVertexBufferName(buffer)),
|
||||||
std::make_unique<BinaryExpression>(BinaryOp::kDivide, std::move(pos),
|
std::make_unique<ast::IdentifierExpression>(kStructBufferName)),
|
||||||
GenUint(4)));
|
std::make_unique<ast::BinaryExpression>(ast::BinaryOp::kDivide,
|
||||||
|
std::move(pos), GenUint(4)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessI32(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessI32(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
std::unique_ptr<Expression> pos) {
|
std::unique_ptr<ast::Expression> pos) {
|
||||||
// as<T> reinterprets bits
|
// as<T> reinterprets bits
|
||||||
return std::make_unique<BitcastExpression>(GetI32Type(),
|
return std::make_unique<ast::BitcastExpression>(
|
||||||
AccessU32(buffer, std::move(pos)));
|
GetI32Type(), AccessU32(buffer, std::move(pos)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessF32(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessF32(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
std::unique_ptr<Expression> pos) {
|
std::unique_ptr<ast::Expression> pos) {
|
||||||
// as<T> reinterprets bits
|
// as<T> reinterprets bits
|
||||||
return std::make_unique<BitcastExpression>(GetF32Type(),
|
return std::make_unique<ast::BitcastExpression>(
|
||||||
AccessU32(buffer, std::move(pos)));
|
GetF32Type(), AccessU32(buffer, std::move(pos)));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessPrimitive(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessPrimitive(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
std::unique_ptr<Expression> pos,
|
std::unique_ptr<ast::Expression> pos,
|
||||||
VertexFormat format) {
|
VertexFormat format) {
|
||||||
// This function uses a position expression to read, rather than using the
|
// This function uses a position expression to read, rather than using the
|
||||||
// position variable. This allows us to read from offset positions relative to
|
// position variable. This allows us to read from offset positions relative to
|
||||||
@ -393,41 +402,42 @@ std::unique_ptr<Expression> VertexPullingTransform::AccessPrimitive(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Expression> VertexPullingTransform::AccessVec(
|
std::unique_ptr<ast::Expression> VertexPullingTransform::AccessVec(
|
||||||
uint32_t buffer,
|
uint32_t buffer,
|
||||||
uint32_t element_stride,
|
uint32_t element_stride,
|
||||||
type::Type* base_type,
|
ast::type::Type* base_type,
|
||||||
VertexFormat base_format,
|
VertexFormat base_format,
|
||||||
uint32_t count) {
|
uint32_t count) {
|
||||||
ExpressionList expr_list;
|
ast::ExpressionList expr_list;
|
||||||
for (uint32_t i = 0; i < count; ++i) {
|
for (uint32_t i = 0; i < count; ++i) {
|
||||||
// Offset read position by element_stride for each component
|
// Offset read position by element_stride for each component
|
||||||
auto cur_pos = std::make_unique<BinaryExpression>(
|
auto cur_pos = std::make_unique<ast::BinaryExpression>(
|
||||||
BinaryOp::kAdd, CreatePullingPositionIdent(),
|
ast::BinaryOp::kAdd, CreatePullingPositionIdent(),
|
||||||
GenUint(element_stride * i));
|
GenUint(element_stride * i));
|
||||||
expr_list.push_back(
|
expr_list.push_back(
|
||||||
AccessPrimitive(buffer, std::move(cur_pos), base_format));
|
AccessPrimitive(buffer, std::move(cur_pos), base_format));
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_unique<TypeConstructorExpression>(
|
return std::make_unique<ast::TypeConstructorExpression>(
|
||||||
ctx_->type_mgr().Get(
|
ctx_->type_mgr().Get(
|
||||||
std::make_unique<type::VectorType>(base_type, count)),
|
std::make_unique<ast::type::VectorType>(base_type, count)),
|
||||||
std::move(expr_list));
|
std::move(expr_list));
|
||||||
}
|
}
|
||||||
|
|
||||||
type::Type* VertexPullingTransform::GetU32Type() {
|
ast::type::Type* VertexPullingTransform::GetU32Type() {
|
||||||
return ctx_->type_mgr().Get(std::make_unique<type::U32Type>());
|
return ctx_->type_mgr().Get(std::make_unique<ast::type::U32Type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
type::Type* VertexPullingTransform::GetI32Type() {
|
ast::type::Type* VertexPullingTransform::GetI32Type() {
|
||||||
return ctx_->type_mgr().Get(std::make_unique<type::I32Type>());
|
return ctx_->type_mgr().Get(std::make_unique<ast::type::I32Type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
type::Type* VertexPullingTransform::GetF32Type() {
|
ast::type::Type* VertexPullingTransform::GetF32Type() {
|
||||||
return ctx_->type_mgr().Get(std::make_unique<type::F32Type>());
|
return ctx_->type_mgr().Get(std::make_unique<ast::type::F32Type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default;
|
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor() = default;
|
||||||
|
|
||||||
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
|
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
|
||||||
uint64_t in_array_stride,
|
uint64_t in_array_stride,
|
||||||
InputStepMode in_step_mode,
|
InputStepMode in_step_mode,
|
||||||
@ -435,21 +445,25 @@ VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
|
|||||||
: array_stride(std::move(in_array_stride)),
|
: array_stride(std::move(in_array_stride)),
|
||||||
step_mode(std::move(in_step_mode)),
|
step_mode(std::move(in_step_mode)),
|
||||||
attributes(std::move(in_attributes)) {}
|
attributes(std::move(in_attributes)) {}
|
||||||
|
|
||||||
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
|
VertexBufferLayoutDescriptor::VertexBufferLayoutDescriptor(
|
||||||
const VertexBufferLayoutDescriptor& other)
|
const VertexBufferLayoutDescriptor& other)
|
||||||
: array_stride(other.array_stride),
|
: array_stride(other.array_stride),
|
||||||
step_mode(other.step_mode),
|
step_mode(other.step_mode),
|
||||||
attributes(other.attributes) {}
|
attributes(other.attributes) {}
|
||||||
|
|
||||||
VertexBufferLayoutDescriptor::~VertexBufferLayoutDescriptor() = default;
|
VertexBufferLayoutDescriptor::~VertexBufferLayoutDescriptor() = default;
|
||||||
|
|
||||||
VertexStateDescriptor::VertexStateDescriptor() = default;
|
VertexStateDescriptor::VertexStateDescriptor() = default;
|
||||||
|
|
||||||
VertexStateDescriptor::VertexStateDescriptor(
|
VertexStateDescriptor::VertexStateDescriptor(
|
||||||
std::vector<VertexBufferLayoutDescriptor> in_vertex_buffers)
|
std::vector<VertexBufferLayoutDescriptor> in_vertex_buffers)
|
||||||
: vertex_buffers(std::move(in_vertex_buffers)) {}
|
: vertex_buffers(std::move(in_vertex_buffers)) {}
|
||||||
|
|
||||||
VertexStateDescriptor::VertexStateDescriptor(const VertexStateDescriptor& other)
|
VertexStateDescriptor::VertexStateDescriptor(const VertexStateDescriptor& other)
|
||||||
: vertex_buffers(other.vertex_buffers) {}
|
: vertex_buffers(other.vertex_buffers) {}
|
||||||
|
|
||||||
VertexStateDescriptor::~VertexStateDescriptor() = default;
|
VertexStateDescriptor::~VertexStateDescriptor() = default;
|
||||||
|
|
||||||
} // namespace transform
|
} // namespace transform
|
||||||
} // namespace ast
|
|
||||||
} // namespace tint
|
} // namespace tint
|
@ -12,8 +12,15 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SRC_AST_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_
|
#ifndef SRC_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_
|
||||||
#define SRC_AST_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 <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -21,22 +28,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace tint {
|
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 {
|
namespace transform {
|
||||||
|
|
||||||
/// Describes the format of data in a vertex buffer
|
/// Describes the format of data in a vertex buffer
|
||||||
@ -102,6 +93,7 @@ struct VertexBufferLayoutDescriptor {
|
|||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
/// @param other the struct to copy
|
/// @param other the struct to copy
|
||||||
VertexBufferLayoutDescriptor(const VertexBufferLayoutDescriptor& other);
|
VertexBufferLayoutDescriptor(const VertexBufferLayoutDescriptor& other);
|
||||||
|
|
||||||
~VertexBufferLayoutDescriptor();
|
~VertexBufferLayoutDescriptor();
|
||||||
|
|
||||||
/// The array stride used in the in buffer
|
/// The array stride used in the in buffer
|
||||||
@ -124,6 +116,7 @@ struct VertexStateDescriptor {
|
|||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
/// @param other the struct to copy
|
/// @param other the struct to copy
|
||||||
VertexStateDescriptor(const VertexStateDescriptor& other);
|
VertexStateDescriptor(const VertexStateDescriptor& other);
|
||||||
|
|
||||||
~VertexStateDescriptor();
|
~VertexStateDescriptor();
|
||||||
|
|
||||||
/// The vertex buffers
|
/// The vertex buffers
|
||||||
@ -154,7 +147,7 @@ class VertexPullingTransform {
|
|||||||
/// Constructor
|
/// Constructor
|
||||||
/// @param ctx the tint context
|
/// @param ctx the tint context
|
||||||
/// @param mod the module to convert to vertex pulling
|
/// @param mod the module to convert to vertex pulling
|
||||||
VertexPullingTransform(Context* ctx, Module* mod);
|
VertexPullingTransform(Context* ctx, ast::Module* mod);
|
||||||
~VertexPullingTransform();
|
~VertexPullingTransform();
|
||||||
|
|
||||||
/// Sets the vertex state descriptor, containing info about attributes
|
/// Sets the vertex state descriptor, containing info about attributes
|
||||||
@ -196,48 +189,52 @@ class VertexPullingTransform {
|
|||||||
void AddVertexStorageBuffers();
|
void AddVertexStorageBuffers();
|
||||||
|
|
||||||
/// Adds assignment to the variables from the buffers
|
/// 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
|
/// Generates an expression holding a constant uint
|
||||||
/// @param value uint value
|
/// @param value uint value
|
||||||
std::unique_ptr<Expression> GenUint(uint32_t value);
|
std::unique_ptr<ast::Expression> GenUint(uint32_t value);
|
||||||
|
|
||||||
/// Generates an expression to read the shader value |kPullingPosVarName|
|
/// Generates an expression to read the shader value |kPullingPosVarName|
|
||||||
std::unique_ptr<Expression> CreatePullingPositionIdent();
|
std::unique_ptr<ast::Expression> CreatePullingPositionIdent();
|
||||||
|
|
||||||
/// Generates an expression reading from a buffer a specific format.
|
/// Generates an expression reading from a buffer a specific format.
|
||||||
/// This reads the value wherever |kPullingPosVarName| points to at the time
|
/// This reads the value wherever |kPullingPosVarName| points to at the time
|
||||||
/// of the read.
|
/// of the read.
|
||||||
/// @param buffer the index of the vertex buffer
|
/// @param buffer the index of the vertex buffer
|
||||||
/// @param format the format to read
|
/// @param format the format to read
|
||||||
std::unique_ptr<Expression> AccessByFormat(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessByFormat(uint32_t buffer,
|
||||||
VertexFormat format);
|
VertexFormat format);
|
||||||
|
|
||||||
/// Generates an expression reading a uint32 from a vertex buffer
|
/// Generates an expression reading a uint32 from a vertex buffer
|
||||||
/// @param buffer the index of the vertex buffer
|
/// @param buffer the index of the vertex buffer
|
||||||
/// @param pos an expression for the position of the access, in bytes
|
/// @param pos an expression for the position of the access, in bytes
|
||||||
std::unique_ptr<Expression> AccessU32(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessU32(
|
||||||
std::unique_ptr<Expression> pos);
|
uint32_t buffer,
|
||||||
|
std::unique_ptr<ast::Expression> pos);
|
||||||
|
|
||||||
/// Generates an expression reading an int32 from a vertex buffer
|
/// Generates an expression reading an int32 from a vertex buffer
|
||||||
/// @param buffer the index of the vertex buffer
|
/// @param buffer the index of the vertex buffer
|
||||||
/// @param pos an expression for the position of the access, in bytes
|
/// @param pos an expression for the position of the access, in bytes
|
||||||
std::unique_ptr<Expression> AccessI32(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessI32(
|
||||||
std::unique_ptr<Expression> pos);
|
uint32_t buffer,
|
||||||
|
std::unique_ptr<ast::Expression> pos);
|
||||||
|
|
||||||
/// Generates an expression reading a float from a vertex buffer
|
/// Generates an expression reading a float from a vertex buffer
|
||||||
/// @param buffer the index of the vertex buffer
|
/// @param buffer the index of the vertex buffer
|
||||||
/// @param pos an expression for the position of the access, in bytes
|
/// @param pos an expression for the position of the access, in bytes
|
||||||
std::unique_ptr<Expression> AccessF32(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessF32(
|
||||||
std::unique_ptr<Expression> pos);
|
uint32_t buffer,
|
||||||
|
std::unique_ptr<ast::Expression> pos);
|
||||||
|
|
||||||
/// Generates an expression reading a basic type (u32, i32, f32) from a vertex
|
/// Generates an expression reading a basic type (u32, i32, f32) from a vertex
|
||||||
/// buffer
|
/// buffer
|
||||||
/// @param buffer the index of the vertex buffer
|
/// @param buffer the index of the vertex buffer
|
||||||
/// @param pos an expression for the position of the access, in bytes
|
/// @param pos an expression for the position of the access, in bytes
|
||||||
/// @param format the underlying vertex format
|
/// @param format the underlying vertex format
|
||||||
std::unique_ptr<Expression> AccessPrimitive(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessPrimitive(
|
||||||
std::unique_ptr<Expression> pos,
|
uint32_t buffer,
|
||||||
|
std::unique_ptr<ast::Expression> pos,
|
||||||
VertexFormat format);
|
VertexFormat format);
|
||||||
|
|
||||||
/// Generates an expression reading a vec2/3/4 from a vertex buffer.
|
/// Generates an expression reading a vec2/3/4 from a vertex buffer.
|
||||||
@ -248,19 +245,19 @@ class VertexPullingTransform {
|
|||||||
/// @param base_type underlying AST type
|
/// @param base_type underlying AST type
|
||||||
/// @param base_format underlying vertex format
|
/// @param base_format underlying vertex format
|
||||||
/// @param count how many elements the vector has
|
/// @param count how many elements the vector has
|
||||||
std::unique_ptr<Expression> AccessVec(uint32_t buffer,
|
std::unique_ptr<ast::Expression> AccessVec(uint32_t buffer,
|
||||||
uint32_t element_stride,
|
uint32_t element_stride,
|
||||||
type::Type* base_type,
|
ast::type::Type* base_type,
|
||||||
VertexFormat base_format,
|
VertexFormat base_format,
|
||||||
uint32_t count);
|
uint32_t count);
|
||||||
|
|
||||||
// Used to grab corresponding types from the type manager
|
// Used to grab corresponding types from the type manager
|
||||||
type::Type* GetU32Type();
|
ast::type::Type* GetU32Type();
|
||||||
type::Type* GetI32Type();
|
ast::type::Type* GetI32Type();
|
||||||
type::Type* GetF32Type();
|
ast::type::Type* GetF32Type();
|
||||||
|
|
||||||
Context* ctx_ = nullptr;
|
Context* ctx_ = nullptr;
|
||||||
Module* mod_ = nullptr;
|
ast::Module* mod_ = nullptr;
|
||||||
std::string entry_point_name_;
|
std::string entry_point_name_;
|
||||||
std::string error_;
|
std::string error_;
|
||||||
|
|
||||||
@ -270,12 +267,11 @@ class VertexPullingTransform {
|
|||||||
// Default to 4 as it is past the limits of user-accessible sets
|
// Default to 4 as it is past the limits of user-accessible sets
|
||||||
uint32_t pulling_set_ = 4u;
|
uint32_t pulling_set_ = 4u;
|
||||||
|
|
||||||
std::unordered_map<uint32_t, Variable*> location_to_var_;
|
std::unordered_map<uint32_t, ast::Variable*> location_to_var_;
|
||||||
std::unique_ptr<VertexStateDescriptor> vertex_state_;
|
std::unique_ptr<VertexStateDescriptor> vertex_state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace transform
|
} // namespace transform
|
||||||
} // namespace ast
|
|
||||||
} // namespace tint
|
} // namespace tint
|
||||||
|
|
||||||
#endif // SRC_AST_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_
|
#endif // SRC_TRANSFORM_VERTEX_PULLING_TRANSFORM_H_
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "src/ast/transform/vertex_pulling_transform.h"
|
#include "src/transform/vertex_pulling_transform.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include "src/ast/decorated_variable.h"
|
#include "src/ast/decorated_variable.h"
|
||||||
@ -27,7 +27,6 @@
|
|||||||
#include "src/validator.h"
|
#include "src/validator.h"
|
||||||
|
|
||||||
namespace tint {
|
namespace tint {
|
||||||
namespace ast {
|
|
||||||
namespace transform {
|
namespace transform {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -40,9 +39,9 @@ class VertexPullingTransformHelper {
|
|||||||
|
|
||||||
// Create basic module with an entry point and vertex function
|
// Create basic module with an entry point and vertex function
|
||||||
void InitBasicModule() {
|
void InitBasicModule() {
|
||||||
auto func = std::make_unique<Function>(
|
auto func = std::make_unique<ast::Function>(
|
||||||
"main", VariableList{},
|
"main", ast::VariableList{},
|
||||||
ctx_.type_mgr().Get(std::make_unique<type::VoidType>()));
|
ctx_.type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
||||||
func->add_decoration(
|
func->add_decoration(
|
||||||
std::make_unique<ast::StageDecoration>(ast::PipelineStage ::kVertex));
|
std::make_unique<ast::StageDecoration>(ast::PipelineStage ::kVertex));
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
@ -52,7 +51,7 @@ class VertexPullingTransformHelper {
|
|||||||
void InitTransform(VertexStateDescriptor vertex_state) {
|
void InitTransform(VertexStateDescriptor vertex_state) {
|
||||||
EXPECT_TRUE(mod_->IsValid());
|
EXPECT_TRUE(mod_->IsValid());
|
||||||
|
|
||||||
tint::TypeDeterminer td(&ctx_, mod_.get());
|
TypeDeterminer td(&ctx_, mod_.get());
|
||||||
EXPECT_TRUE(td.Determine());
|
EXPECT_TRUE(td.Determine());
|
||||||
|
|
||||||
transform_->SetVertexState(
|
transform_->SetVertexState(
|
||||||
@ -63,12 +62,12 @@ class VertexPullingTransformHelper {
|
|||||||
// Inserts a variable which will be converted to vertex pulling
|
// Inserts a variable which will be converted to vertex pulling
|
||||||
void AddVertexInputVariable(uint32_t location,
|
void AddVertexInputVariable(uint32_t location,
|
||||||
std::string name,
|
std::string name,
|
||||||
type::Type* type) {
|
ast::type::Type* type) {
|
||||||
auto var = std::make_unique<DecoratedVariable>(
|
auto var = std::make_unique<ast::DecoratedVariable>(
|
||||||
std::make_unique<Variable>(name, StorageClass::kInput, type));
|
std::make_unique<ast::Variable>(name, ast::StorageClass::kInput, type));
|
||||||
|
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(std::make_unique<LocationDecoration>(location));
|
decorations.push_back(std::make_unique<ast::LocationDecoration>(location));
|
||||||
|
|
||||||
var->set_decorations(std::move(decorations));
|
var->set_decorations(std::move(decorations));
|
||||||
mod_->AddGlobalVariable(std::move(var));
|
mod_->AddGlobalVariable(std::move(var));
|
||||||
@ -108,9 +107,9 @@ TEST_F(VertexPullingTransformTest, Error_InvalidEntryPoint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
|
TEST_F(VertexPullingTransformTest, Error_EntryPointWrongStage) {
|
||||||
auto func = std::make_unique<Function>(
|
auto func = std::make_unique<ast::Function>(
|
||||||
"main", VariableList{},
|
"main", ast::VariableList{},
|
||||||
ctx()->type_mgr().Get(std::make_unique<type::VoidType>()));
|
ctx()->type_mgr().Get(std::make_unique<ast::type::VoidType>()));
|
||||||
func->add_decoration(
|
func->add_decoration(
|
||||||
std::make_unique<ast::StageDecoration>(ast::PipelineStage::kFragment));
|
std::make_unique<ast::StageDecoration>(ast::PipelineStage::kFragment));
|
||||||
mod()->AddFunction(std::move(func));
|
mod()->AddFunction(std::move(func));
|
||||||
@ -129,7 +128,7 @@ TEST_F(VertexPullingTransformTest, BasicModule) {
|
|||||||
TEST_F(VertexPullingTransformTest, OneAttribute) {
|
TEST_F(VertexPullingTransformTest, OneAttribute) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
AddVertexInputVariable(0, "var_a", &f32);
|
AddVertexInputVariable(0, "var_a", &f32);
|
||||||
|
|
||||||
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
||||||
@ -209,7 +208,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
|
|||||||
TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
|
TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
AddVertexInputVariable(0, "var_a", &f32);
|
AddVertexInputVariable(0, "var_a", &f32);
|
||||||
|
|
||||||
InitTransform(
|
InitTransform(
|
||||||
@ -290,7 +289,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
|
|||||||
TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
|
TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
AddVertexInputVariable(0, "var_a", &f32);
|
AddVertexInputVariable(0, "var_a", &f32);
|
||||||
|
|
||||||
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}});
|
||||||
@ -372,32 +371,32 @@ TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) {
|
|||||||
TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
|
TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
AddVertexInputVariable(0, "var_a", &f32);
|
AddVertexInputVariable(0, "var_a", &f32);
|
||||||
AddVertexInputVariable(1, "var_b", &f32);
|
AddVertexInputVariable(1, "var_b", &f32);
|
||||||
|
|
||||||
type::I32Type i32;
|
ast::type::I32Type i32;
|
||||||
{
|
{
|
||||||
auto vertex_index_var =
|
auto vertex_index_var = std::make_unique<ast::DecoratedVariable>(
|
||||||
std::make_unique<DecoratedVariable>(std::make_unique<Variable>(
|
std::make_unique<ast::Variable>("custom_vertex_index",
|
||||||
"custom_vertex_index", StorageClass::kInput, &i32));
|
ast::StorageClass::kInput, &i32));
|
||||||
|
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(
|
decorations.push_back(
|
||||||
std::make_unique<BuiltinDecoration>(Builtin::kVertexIdx));
|
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kVertexIdx));
|
||||||
|
|
||||||
vertex_index_var->set_decorations(std::move(decorations));
|
vertex_index_var->set_decorations(std::move(decorations));
|
||||||
mod()->AddGlobalVariable(std::move(vertex_index_var));
|
mod()->AddGlobalVariable(std::move(vertex_index_var));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto instance_index_var =
|
auto instance_index_var = std::make_unique<ast::DecoratedVariable>(
|
||||||
std::make_unique<DecoratedVariable>(std::make_unique<Variable>(
|
std::make_unique<ast::Variable>("custom_instance_index",
|
||||||
"custom_instance_index", StorageClass::kInput, &i32));
|
ast::StorageClass::kInput, &i32));
|
||||||
|
|
||||||
VariableDecorationList decorations;
|
ast::VariableDecorationList decorations;
|
||||||
decorations.push_back(
|
decorations.push_back(
|
||||||
std::make_unique<BuiltinDecoration>(Builtin::kInstanceIdx));
|
std::make_unique<ast::BuiltinDecoration>(ast::Builtin::kInstanceIdx));
|
||||||
|
|
||||||
instance_index_var->set_decorations(std::move(decorations));
|
instance_index_var->set_decorations(std::move(decorations));
|
||||||
mod()->AddGlobalVariable(std::move(instance_index_var));
|
mod()->AddGlobalVariable(std::move(instance_index_var));
|
||||||
@ -532,10 +531,10 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
|
|||||||
TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
|
TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
AddVertexInputVariable(0, "var_a", &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);
|
AddVertexInputVariable(1, "var_b", &vec4_f32);
|
||||||
|
|
||||||
InitTransform(
|
InitTransform(
|
||||||
@ -709,14 +708,14 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
|
|||||||
TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
|
TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
|
||||||
InitBasicModule();
|
InitBasicModule();
|
||||||
|
|
||||||
type::F32Type f32;
|
ast::type::F32Type f32;
|
||||||
type::ArrayType vec2_f32{&f32, 2u};
|
ast::type::ArrayType vec2_f32{&f32, 2u};
|
||||||
AddVertexInputVariable(0, "var_a", &vec2_f32);
|
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);
|
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);
|
AddVertexInputVariable(2, "var_c", &vec4_f32);
|
||||||
|
|
||||||
InitTransform(
|
InitTransform(
|
||||||
@ -1005,5 +1004,4 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace transform
|
} // namespace transform
|
||||||
} // namespace ast
|
|
||||||
} // namespace tint
|
} // namespace tint
|
Loading…
x
Reference in New Issue
Block a user