mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
tests: Use ProgramBuilder helpers where we can
A general code cleanup Change-Id: Ib251ca2d4b71f75736bdba8b4255965593a76c31 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48680 Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Reviewed-by: James Price <jrprice@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Commit Bot service account
parent
261642e4e3
commit
43073d8aa3
@@ -182,10 +182,9 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
||||
|
||||
// Construct the variable that'll hold the result of
|
||||
// RWByteAddressBuffer.GetDimensions()
|
||||
auto* buffer_size_result =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Var(
|
||||
ctx.dst->Symbols().New(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
|
||||
auto* buffer_size_result = ctx.dst->Decl(ctx.dst->Var(
|
||||
ctx.dst->Symbols().New(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction, ctx.dst->Expr(0u)));
|
||||
|
||||
// Call storage_buffer.GetDimensions(buffer_size_result)
|
||||
auto* call_get_dims =
|
||||
@@ -203,14 +202,12 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
|
||||
auto name = ctx.dst->Symbols().New();
|
||||
uint32_t array_offset = array_member_sem->Offset();
|
||||
uint32_t array_stride = array_member_sem->Size();
|
||||
auto* array_length_var =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(ctx.dst->Const(
|
||||
name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Div(
|
||||
ctx.dst->Sub(
|
||||
buffer_size_result->variable()->symbol(),
|
||||
array_offset),
|
||||
array_stride)));
|
||||
auto* array_length_var = ctx.dst->Decl(ctx.dst->Const(
|
||||
name, ctx.dst->ty.u32(),
|
||||
ctx.dst->Div(
|
||||
ctx.dst->Sub(buffer_size_result->variable()->symbol(),
|
||||
array_offset),
|
||||
array_stride)));
|
||||
|
||||
// Insert the array length calculations at the top of the block
|
||||
ctx.InsertBefore(block->statements(), *block->begin(),
|
||||
|
||||
@@ -257,8 +257,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
|
||||
ret_values.push_back(new_ret_value());
|
||||
}
|
||||
|
||||
auto* new_ret = ctx.dst->create<ast::ReturnStatement>(
|
||||
ctx.dst->Construct(new_ret_type, ret_values));
|
||||
auto* new_ret =
|
||||
ctx.dst->Return(ctx.dst->Construct(new_ret_type, ret_values));
|
||||
ctx.Replace(ret, new_ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,10 +356,10 @@ sem::Type* UnwrapPtrAndAlias(sem::Type* ty) {
|
||||
|
||||
/// StorageBufferAccess describes a single storage buffer access
|
||||
struct StorageBufferAccess {
|
||||
sem::Expression const* var = nullptr; // Storage buffer variable
|
||||
std::unique_ptr<Offset> offset; // The byte offset on var
|
||||
sem::Type* type = nullptr; // The type of the access
|
||||
operator bool() const { return var; } // Returns true if valid
|
||||
sem::Expression const* var = nullptr; // Storage buffer variable
|
||||
std::unique_ptr<Offset> offset; // The byte offset on var
|
||||
sem::Type* type = nullptr; // The type of the access
|
||||
operator bool() const { return var; } // Returns true if valid
|
||||
};
|
||||
|
||||
/// Store describes a single storage buffer write
|
||||
@@ -459,8 +459,8 @@ struct State {
|
||||
}
|
||||
func = ctx.dst->create<ast::Function>(
|
||||
ctx.dst->Symbols().New(), params, ctx.Clone(el_ty),
|
||||
ctx.dst->Block(ctx.dst->create<ast::ReturnStatement>(
|
||||
ctx.dst->create<ast::TypeConstructorExpression>(
|
||||
ctx.dst->Block(
|
||||
ctx.dst->Return(ctx.dst->create<ast::TypeConstructorExpression>(
|
||||
ctx.Clone(el_ty), values))),
|
||||
ast::DecorationList{}, ast::DecorationList{});
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ Output EmitVertexPointSize::Run(const Program* in, const DataMap&) {
|
||||
// Declare the pointsize builtin output variable.
|
||||
out.Global(pointsize, out.ty.f32(), ast::StorageClass::kOutput, nullptr,
|
||||
ast::DecorationList{
|
||||
out.create<ast::BuiltinDecoration>(ast::Builtin::kPointSize),
|
||||
out.Builtin(ast::Builtin::kPointSize),
|
||||
});
|
||||
|
||||
// Add the pointsize assignment statement to the front of all vertex stages.
|
||||
|
||||
@@ -106,8 +106,7 @@ void Hlsl::PromoteInitializersToConstVar(CloneContext& ctx) const {
|
||||
// Construct the constant that holds the hoisted initializer
|
||||
auto* dst_var = ctx.dst->Const(dst_symbol, dst_ty, dst_init);
|
||||
// Construct the variable declaration statement
|
||||
auto* dst_var_decl =
|
||||
ctx.dst->create<ast::VariableDeclStatement>(dst_var);
|
||||
auto* dst_var_decl = ctx.dst->Decl(dst_var);
|
||||
// Construct the identifier for referencing the constant
|
||||
auto* dst_ident = ctx.dst->Expr(dst_symbol);
|
||||
|
||||
@@ -127,10 +126,9 @@ void Hlsl::AddEmptyEntryPoint(CloneContext& ctx) const {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx.dst->Func(
|
||||
ctx.dst->Symbols().New("tint_unused_entry_point"), {},
|
||||
ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
ctx.dst->Func(ctx.dst->Symbols().New("tint_unused_entry_point"), {},
|
||||
ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->Stage(ast::PipelineStage::kCompute)});
|
||||
}
|
||||
|
||||
} // namespace transform
|
||||
|
||||
@@ -176,7 +176,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
|
||||
auto* call = ctx.dst->Call(return_func_symbol, ctx.Clone(ret->value()));
|
||||
ctx.InsertBefore(ret_sem->Block()->statements(), ret,
|
||||
ctx.dst->create<ast::CallStatement>(call));
|
||||
ctx.Replace(ret, ctx.dst->create<ast::ReturnStatement>());
|
||||
ctx.Replace(ret, ctx.dst->Return());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,9 +245,8 @@ void Spirv::AddEmptyEntryPoint(CloneContext& ctx) const {
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx.dst->Func(
|
||||
"_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->create<ast::StageDecoration>(ast::PipelineStage::kCompute)});
|
||||
ctx.dst->Func("_tint_unused_entry_point", {}, ctx.dst->ty.void_(), {},
|
||||
{ctx.dst->Stage(ast::PipelineStage::kCompute)});
|
||||
}
|
||||
|
||||
Symbol Spirv::HoistToInputVariables(
|
||||
|
||||
@@ -117,12 +117,11 @@ struct State {
|
||||
static const char kDefaultVertexIndexName[] = "tint_pulling_vertex_index";
|
||||
vertex_index_name = ctx.dst->Symbols().New(kDefaultVertexIndexName);
|
||||
|
||||
ctx.dst->Global(
|
||||
vertex_index_name, ctx.dst->ty.u32(), ast::StorageClass::kInput,
|
||||
nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(ast::Builtin::kVertexIndex),
|
||||
});
|
||||
ctx.dst->Global(vertex_index_name, ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->Builtin(ast::Builtin::kVertexIndex),
|
||||
});
|
||||
}
|
||||
|
||||
/// Inserts instance_index binding, or finds the existing one
|
||||
@@ -163,8 +162,7 @@ struct State {
|
||||
ctx.dst->Global(instance_index_name, ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kInput, nullptr,
|
||||
ast::DecorationList{
|
||||
ctx.dst->create<ast::BuiltinDecoration>(
|
||||
ast::Builtin::kInstanceIndex),
|
||||
ctx.dst->Builtin(ast::Builtin::kInstanceIndex),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -230,9 +228,9 @@ struct State {
|
||||
ast::StatementList stmts;
|
||||
|
||||
// Declare the pulling position variable in the shader
|
||||
stmts.emplace_back(ctx.dst->create<ast::VariableDeclStatement>(
|
||||
ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction)));
|
||||
stmts.emplace_back(
|
||||
ctx.dst->Decl(ctx.dst->Var(GetPullingPositionName(), ctx.dst->ty.u32(),
|
||||
ast::StorageClass::kFunction)));
|
||||
|
||||
for (uint32_t i = 0; i < cfg.vertex_state.size(); ++i) {
|
||||
const VertexBufferLayoutDescriptor& buffer_layout = cfg.vertex_state[i];
|
||||
|
||||
Reference in New Issue
Block a user