tint/writer/spirv: Create Module class

Move the generic code for building up a SPIR-V module from Builder to
a new Module class. This can then be reused by the new IR-based SPIR-V
writer.

Switches to naming of methods to camel case to bring in line with the
rest of the codebase.

Bug: tint:1906
Change-Id: I7775edff6fe56328c6562559c016a19097b50805
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131340
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-05-03 22:54:15 +00:00 committed by Dawn LUCI CQ
parent 09b02ffc7b
commit f885a90a5f
42 changed files with 1665 additions and 1462 deletions

View File

@ -955,6 +955,8 @@ libtint_source_set("libtint_spv_writer_src") {
"writer/spirv/generator_impl.h",
"writer/spirv/instruction.cc",
"writer/spirv/instruction.h",
"writer/spirv/module.cc",
"writer/spirv/module.h",
"writer/spirv/operand.cc",
"writer/spirv/operand.h",
"writer/spirv/scalar_constant.h",
@ -1828,6 +1830,7 @@ if (tint_build_unittests) {
"writer/spirv/builder_type_test.cc",
"writer/spirv/builder_unary_op_expression_test.cc",
"writer/spirv/instruction_test.cc",
"writer/spirv/module_test.cc",
"writer/spirv/operand_test.cc",
"writer/spirv/scalar_constant_test.cc",
"writer/spirv/spv_dump.cc",

View File

@ -644,6 +644,8 @@ if(${TINT_BUILD_SPV_WRITER})
writer/spirv/generator_impl.h
writer/spirv/instruction.cc
writer/spirv/instruction.h
writer/spirv/module.cc
writer/spirv/module.h
writer/spirv/operand.cc
writer/spirv/operand.h
writer/spirv/scalar_constant.h
@ -1208,6 +1210,7 @@ if(TINT_BUILD_TESTS)
writer/spirv/builder_type_test.cc
writer/spirv/builder_unary_op_expression_test.cc
writer/spirv/instruction_test.cc
writer/spirv/module_test.cc
writer/spirv/operand_test.cc
writer/spirv/scalar_constant_test.cc
writer/spirv/spv_dump.cc

View File

@ -28,9 +28,9 @@ BinaryWriter::BinaryWriter() = default;
BinaryWriter::~BinaryWriter() = default;
void BinaryWriter::WriteBuilder(Builder* builder) {
out_.reserve(builder->total_size());
builder->iterate([this](const Instruction& inst) { this->process_instruction(inst); });
void BinaryWriter::WriteModule(const Module* module) {
out_.reserve(module->TotalSize());
module->Iterate([this](const Instruction& inst) { this->process_instruction(inst); });
}
void BinaryWriter::WriteInstruction(const Instruction& inst) {

View File

@ -17,11 +17,11 @@
#include <vector>
#include "src/tint/writer/spirv/builder.h"
#include "src/tint/writer/spirv/module.h"
namespace tint::writer::spirv {
/// Writer to convert from builder to SPIR-V binary
/// Writer to convert from module to SPIR-V binary.
class BinaryWriter {
public:
/// Constructor
@ -32,11 +32,10 @@ class BinaryWriter {
/// @param bound the bound to output
void WriteHeader(uint32_t bound);
/// Writes the given builder data into a binary. Note, this does not emit
/// the SPIR-V header. You **must** call WriteHeader() before WriteBuilder()
/// if you want the SPIR-V to be emitted.
/// @param builder the builder to assemble from
void WriteBuilder(Builder* builder);
/// Writes the given module data into a binary. Note, this does not emit the SPIR-V header. You
/// **must** call WriteHeader() before WriteModule() if you want the SPIR-V to be emitted.
/// @param module the module to assemble from
void WriteModule(const Module* module);
/// Writes the given instruction into the binary.
/// @param inst the instruction to assemble

View File

@ -33,11 +33,11 @@ TEST_F(BinaryWriterTest, Preamble) {
}
TEST_F(BinaryWriterTest, Float) {
spirv::Builder& b = Build();
Module m;
b.push_annot(spv::Op::OpKill, {Operand(2.4f)});
m.PushAnnot(spv::Op::OpKill, {Operand(2.4f)});
BinaryWriter bw;
bw.WriteBuilder(&b);
bw.WriteModule(&m);
auto res = bw.result();
ASSERT_EQ(res.size(), 2u);
@ -47,11 +47,11 @@ TEST_F(BinaryWriterTest, Float) {
}
TEST_F(BinaryWriterTest, Int) {
spirv::Builder& b = Build();
Module m;
b.push_annot(spv::Op::OpKill, {Operand(2u)});
m.PushAnnot(spv::Op::OpKill, {Operand(2u)});
BinaryWriter bw;
bw.WriteBuilder(&b);
bw.WriteModule(&m);
auto res = bw.result();
ASSERT_EQ(res.size(), 2u);
@ -59,11 +59,11 @@ TEST_F(BinaryWriterTest, Int) {
}
TEST_F(BinaryWriterTest, String) {
spirv::Builder& b = Build();
Module m;
b.push_annot(spv::Op::OpKill, {Operand("my_string")});
m.PushAnnot(spv::Op::OpKill, {Operand("my_string")});
BinaryWriter bw;
bw.WriteBuilder(&b);
bw.WriteModule(&m);
auto res = bw.result();
ASSERT_EQ(res.size(), 4u);
@ -84,11 +84,11 @@ TEST_F(BinaryWriterTest, String) {
}
TEST_F(BinaryWriterTest, String_Multiple4Length) {
spirv::Builder& b = Build();
Module m;
b.push_annot(spv::Op::OpKill, {Operand("mystring")});
m.PushAnnot(spv::Op::OpKill, {Operand("mystring")});
BinaryWriter bw;
bw.WriteBuilder(&b);
bw.WriteModule(&m);
auto res = bw.result();
ASSERT_EQ(res.size(), 4u);

View File

@ -58,15 +58,6 @@ namespace {
const char kGLSLstd450[] = "GLSL.std.450";
uint32_t size_of(const InstructionList& instructions) {
uint32_t size = 0;
for (const auto& inst : instructions) {
size += inst.word_length();
}
return size;
}
uint32_t pipeline_stage_to_execution_model(ast::PipelineStage stage) {
SpvExecutionModel model = SpvExecutionModelVertex;
@ -274,10 +265,10 @@ bool Builder::Build() {
return false;
}
push_capability(SpvCapabilityShader);
module_.PushCapability(SpvCapabilityShader);
push_memory_model(spv::Op::OpMemoryModel,
{U32Operand(SpvAddressingModelLogical), U32Operand(SpvMemoryModelGLSL450)});
module_.PushMemoryModel(spv::Op::OpMemoryModel, {U32Operand(SpvAddressingModelLogical),
U32Operand(SpvMemoryModelGLSL450)});
for (auto ext : builder_.Sem().Module()->Extensions()) {
GenerateExtension(ext);
@ -325,85 +316,21 @@ void Builder::PopScope() {
}
Operand Builder::result_op() {
return Operand(next_id());
}
uint32_t Builder::total_size() const {
// The 5 covers the magic, version, generator, id bound and reserved.
uint32_t size = 5;
size += size_of(capabilities_);
size += size_of(extensions_);
size += size_of(ext_imports_);
size += size_of(memory_model_);
size += size_of(entry_points_);
size += size_of(execution_modes_);
size += size_of(debug_);
size += size_of(annotations_);
size += size_of(types_);
for (const auto& func : functions_) {
size += func.word_length();
}
return size;
}
void Builder::iterate(std::function<void(const Instruction&)> cb) const {
for (const auto& inst : capabilities_) {
cb(inst);
}
for (const auto& inst : extensions_) {
cb(inst);
}
for (const auto& inst : ext_imports_) {
cb(inst);
}
for (const auto& inst : memory_model_) {
cb(inst);
}
for (const auto& inst : entry_points_) {
cb(inst);
}
for (const auto& inst : execution_modes_) {
cb(inst);
}
for (const auto& inst : debug_) {
cb(inst);
}
for (const auto& inst : annotations_) {
cb(inst);
}
for (const auto& inst : types_) {
cb(inst);
}
for (const auto& func : functions_) {
func.iterate(cb);
}
}
void Builder::push_capability(uint32_t cap) {
if (capability_set_.count(cap) == 0) {
capability_set_.insert(cap);
capabilities_.push_back(Instruction{spv::Op::OpCapability, {Operand(cap)}});
}
}
void Builder::push_extension(const char* extension) {
extensions_.push_back(Instruction{spv::Op::OpExtension, {Operand(extension)}});
return Operand(module_.NextId());
}
bool Builder::GenerateExtension(builtin::Extension extension) {
switch (extension) {
case builtin::Extension::kChromiumExperimentalDp4A:
push_extension("SPV_KHR_integer_dot_product");
push_capability(SpvCapabilityDotProductKHR);
push_capability(SpvCapabilityDotProductInput4x8BitPackedKHR);
module_.PushExtension("SPV_KHR_integer_dot_product");
module_.PushCapability(SpvCapabilityDotProductKHR);
module_.PushCapability(SpvCapabilityDotProductInput4x8BitPackedKHR);
break;
case builtin::Extension::kF16:
push_capability(SpvCapabilityFloat16);
push_capability(SpvCapabilityUniformAndStorageBuffer16BitAccess);
push_capability(SpvCapabilityStorageBuffer16BitAccess);
push_capability(SpvCapabilityStorageInputOutput16);
module_.PushCapability(SpvCapabilityFloat16);
module_.PushCapability(SpvCapabilityUniformAndStorageBuffer16BitAccess);
module_.PushCapability(SpvCapabilityStorageBuffer16BitAccess);
module_.PushCapability(SpvCapabilityStorageInputOutput16);
break;
default:
return false;
@ -517,7 +444,7 @@ bool Builder::GenerateEntryPoint(const ast::Function* func, uint32_t id) {
operands.push_back(Operand(var_id));
}
push_entry_point(spv::Op::OpEntryPoint, operands);
module_.PushEntryPoint(spv::Op::OpEntryPoint, operands);
return true;
}
@ -527,7 +454,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
// WGSL fragment shader origin is upper left
if (func->PipelineStage() == ast::PipelineStage::kFragment) {
push_execution_mode(spv::Op::OpExecutionMode,
module_.PushExecutionMode(spv::Op::OpExecutionMode,
{Operand(id), U32Operand(SpvExecutionModeOriginUpperLeft)});
} else if (func->PipelineStage() == ast::PipelineStage::kCompute) {
auto& wgsize = func_sem->WorkgroupSize();
@ -539,7 +466,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
"transform";
return false;
}
push_execution_mode(
module_.PushExecutionMode(
spv::Op::OpExecutionMode,
{Operand(id), U32Operand(SpvExecutionModeLocalSize), //
Operand(wgsize[0].value()), Operand(wgsize[1].value()), Operand(wgsize[2].value())});
@ -548,7 +475,7 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) {
for (auto it : func_sem->TransitivelyReferencedBuiltinVariables()) {
auto builtin = builder_.Sem().Get(it.second)->Value();
if (builtin == builtin::BuiltinValue::kFragDepth) {
push_execution_mode(spv::Op::OpExecutionMode,
module_.PushExecutionMode(spv::Op::OpExecutionMode,
{Operand(id), U32Operand(SpvExecutionModeDepthReplacing)});
}
}
@ -599,7 +526,7 @@ bool Builder::GenerateFunction(const ast::Function* func_ast) {
auto func_op = result_op();
auto func_id = std::get<uint32_t>(func_op);
push_debug(spv::Op::OpName, {Operand(func_id), Operand(func_ast->name->symbol.Name())});
module_.PushDebug(spv::Op::OpName, {Operand(func_id), Operand(func_ast->name->symbol.Name())});
auto ret_id = GenerateTypeIfNeeded(func->ReturnType());
if (ret_id == 0) {
@ -623,7 +550,7 @@ bool Builder::GenerateFunction(const ast::Function* func_ast) {
return false;
}
push_debug(spv::Op::OpName,
module_.PushDebug(spv::Op::OpName,
{Operand(param_id), Operand(param->Declaration()->name->symbol.Name())});
params.push_back(
Instruction{spv::Op::OpFunctionParameter, {Operand(param_type_id), param_op}});
@ -631,7 +558,10 @@ bool Builder::GenerateFunction(const ast::Function* func_ast) {
RegisterVariable(param, param_id);
}
push_function(Function{definition_inst, result_op(), std::move(params)});
// Start a new function.
current_function_ = Function{definition_inst, result_op(), std::move(params)};
current_label_id_ = current_function_.label_id();
TINT_DEFER(current_function_ = Function());
for (auto* stmt : func_ast->body->statements) {
if (!GenerateStatement(stmt)) {
@ -659,6 +589,9 @@ bool Builder::GenerateFunction(const ast::Function* func_ast) {
func_symbol_to_id_[func_ast->name->symbol] = func_id;
// Add the function to the module.
module_.PushFunction(std::move(current_function_));
return true;
}
@ -681,7 +614,7 @@ uint32_t Builder::GenerateFunctionTypeIfNeeded(const sem::Function* func) {
ops.push_back(Operand(param_type_id));
}
push_type(spv::Op::OpTypeFunction, std::move(ops));
module_.PushType(spv::Op::OpTypeFunction, std::move(ops));
return func_type_id;
});
}
@ -721,7 +654,7 @@ bool Builder::GenerateFunctionVariable(const ast::Variable* v) {
return false;
}
push_debug(spv::Op::OpName, {Operand(var_id), Operand(v->name->symbol.Name())});
module_.PushDebug(spv::Op::OpName, {Operand(var_id), Operand(v->name->symbol.Name())});
// TODO(dsinclair) We could detect if the initializer is fully const and emit
// an initializer value for the variable instead of doing the OpLoad.
@ -782,7 +715,7 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
return false;
}
push_debug(spv::Op::OpName, {Operand(var_id), Operand(v->name->symbol.Name())});
module_.PushDebug(spv::Op::OpName, {Operand(var_id), Operand(v->name->symbol.Name())});
OperandList ops = {Operand(type_id), result, U32Operand(ConvertAddressSpace(sc))};
@ -795,11 +728,11 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
auto access = st ? st->access() : sem->Access();
switch (access) {
case builtin::Access::kWrite:
push_annot(spv::Op::OpDecorate,
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationNonReadable)});
break;
case builtin::Access::kRead:
push_annot(spv::Op::OpDecorate,
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationNonWritable)});
break;
case builtin::Access::kUndefined:
@ -826,20 +759,21 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
}
}
push_type(spv::Op::OpVariable, std::move(ops));
module_.PushType(spv::Op::OpVariable, std::move(ops));
for (auto* attr : v->attributes) {
bool ok = Switch(
attr,
[&](const ast::BuiltinAttribute* builtin_attr) {
auto builtin = builder_.Sem().Get(builtin_attr)->Value();
push_annot(spv::Op::OpDecorate,
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationBuiltIn),
U32Operand(ConvertBuiltin(builtin, sem->AddressSpace()))});
return true;
},
[&](const ast::LocationAttribute*) {
push_annot(spv::Op::OpDecorate, {Operand(var_id), U32Operand(SpvDecorationLocation),
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationLocation),
Operand(sem->Location().value())});
return true;
},
@ -860,19 +794,20 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) {
return true;
},
[&](const ast::InvariantAttribute*) {
push_annot(spv::Op::OpDecorate,
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationInvariant)});
return true;
},
[&](const ast::BindingAttribute*) {
auto bp = sem->BindingPoint();
push_annot(spv::Op::OpDecorate, {Operand(var_id), U32Operand(SpvDecorationBinding),
Operand(bp->binding)});
module_.PushAnnot(
spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationBinding), Operand(bp->binding)});
return true;
},
[&](const ast::GroupAttribute*) {
auto bp = sem->BindingPoint();
push_annot(
module_.PushAnnot(
spv::Op::OpDecorate,
{Operand(var_id), U32Operand(SpvDecorationDescriptorSet), Operand(bp->group)});
return true;
@ -1232,7 +1167,7 @@ uint32_t Builder::GetGLSLstd450Import() {
auto result = result_op();
auto id = std::get<uint32_t>(result);
push_ext_import(spv::Op::OpExtInstImport, {result, Operand(kGLSLstd450)});
module_.PushExtImport(spv::Op::OpExtInstImport, {result, Operand(kGLSLstd450)});
// Remember it for later.
import_name_to_id_[kGLSLstd450] = id;
@ -1404,8 +1339,8 @@ uint32_t Builder::GenerateValueConstructorOrConversion(const sem::Call* call,
if (idx_id == 0) {
return 0;
}
push_type(spv::Op::OpSpecConstantOp,
{Operand(value_type_id), extract, U32Operand(SpvOpCompositeExtract),
module_.PushType(spv::Op::OpSpecConstantOp, {Operand(value_type_id), extract,
U32Operand(SpvOpCompositeExtract),
Operand(id), Operand(idx_id)});
result_is_spec_composite = true;
@ -1438,9 +1373,9 @@ uint32_t Builder::GenerateValueConstructorOrConversion(const sem::Call* call,
ops[kOpsResultIdx] = result;
if (result_is_spec_composite) {
push_type(spv::Op::OpSpecConstantComposite, ops);
module_.PushType(spv::Op::OpSpecConstantComposite, ops);
} else if (result_is_constant_composite) {
push_type(spv::Op::OpConstantComposite, ops);
module_.PushType(spv::Op::OpConstantComposite, ops);
} else {
if (!push_function_inst(spv::Op::OpCompositeConstruct, ops)) {
return 0;
@ -1674,11 +1609,11 @@ uint32_t Builder::GenerateConstantIfNeeded(const constant::Value* constant) {
}
auto& global_scope = scope_stack_[0];
return utils::GetOrCreate(global_scope.type_init_to_id_, OperandListKey{ops},
[&]() -> uint32_t {
return utils::GetOrCreate(
global_scope.type_init_to_id_, OperandListKey{ops}, [&]() -> uint32_t {
auto result = result_op();
ops[kOpsResultIdx] = result;
push_type(spv::Op::OpConstantComposite, std::move(ops));
module_.PushType(spv::Op::OpConstantComposite, std::move(ops));
return std::get<uint32_t>(result);
});
};
@ -1762,28 +1697,31 @@ uint32_t Builder::GenerateConstantIfNeeded(const ScalarConstant& constant) {
switch (constant.kind) {
case ScalarConstant::Kind::kU32: {
push_type(spv::Op::OpConstant, {Operand(type_id), result, Operand(constant.value.u32)});
module_.PushType(spv::Op::OpConstant,
{Operand(type_id), result, Operand(constant.value.u32)});
break;
}
case ScalarConstant::Kind::kI32: {
push_type(spv::Op::OpConstant,
module_.PushType(spv::Op::OpConstant,
{Operand(type_id), result, U32Operand(constant.value.i32)});
break;
}
case ScalarConstant::Kind::kF32: {
push_type(spv::Op::OpConstant, {Operand(type_id), result, Operand(constant.value.f32)});
module_.PushType(spv::Op::OpConstant,
{Operand(type_id), result, Operand(constant.value.f32)});
break;
}
case ScalarConstant::Kind::kF16: {
push_type(spv::Op::OpConstant, {Operand(type_id), result,
U32Operand(constant.value.f16.bits_representation)});
module_.PushType(
spv::Op::OpConstant,
{Operand(type_id), result, U32Operand(constant.value.f16.bits_representation)});
break;
}
case ScalarConstant::Kind::kBool: {
if (constant.value.b) {
push_type(spv::Op::OpConstantTrue, {Operand(type_id), result});
module_.PushType(spv::Op::OpConstantTrue, {Operand(type_id), result});
} else {
push_type(spv::Op::OpConstantFalse, {Operand(type_id), result});
module_.PushType(spv::Op::OpConstantFalse, {Operand(type_id), result});
}
break;
}
@ -1802,7 +1740,7 @@ uint32_t Builder::GenerateConstantNullIfNeeded(const type::Type* type) {
return utils::GetOrCreate(const_null_to_id_, type, [&] {
auto result = result_op();
push_type(spv::Op::OpConstantNull, {Operand(type_id), result});
module_.PushType(spv::Op::OpConstantNull, {Operand(type_id), result});
return std::get<uint32_t>(result);
});
@ -1825,7 +1763,7 @@ uint32_t Builder::GenerateConstantVectorSplatIfNeeded(const type::Vector* type,
for (uint32_t i = 0; i < type->Width(); i++) {
ops.push_back(Operand(value_id));
}
push_type(spv::Op::OpConstantComposite, ops);
module_.PushType(spv::Op::OpConstantComposite, ops);
const_splat_to_id_[key] = result_id;
return result_id;
@ -2297,11 +2235,11 @@ uint32_t Builder::GenerateBuiltinCall(const sem::Call* call, const sem::Builtin*
}
if (builtin->IsFineDerivative() || builtin->IsCoarseDerivative()) {
push_capability(SpvCapabilityDerivativeControl);
module_.PushCapability(SpvCapabilityDerivativeControl);
}
if (builtin->IsImageQuery()) {
push_capability(SpvCapabilityImageQuery);
module_.PushCapability(SpvCapabilityImageQuery);
}
if (builtin->IsTexture()) {
@ -3290,7 +3228,8 @@ uint32_t Builder::GenerateSampledImage(const type::Type* texture_type,
// We need to create the sampled image type and cache the result.
auto sampled_image_type = result_op();
auto texture_type_id = GenerateTypeIfNeeded(texture_type);
push_type(spv::Op::OpTypeSampledImage, {sampled_image_type, Operand(texture_type_id)});
module_.PushType(spv::Op::OpTypeSampledImage,
{sampled_image_type, Operand(texture_type_id)});
return std::get<uint32_t>(sampled_image_type);
});
@ -3357,7 +3296,7 @@ bool Builder::GenerateConditionalBlock(const ast::Expression* cond,
// if there are no more else statements we branch on false to the merge
// block otherwise we branch to the false block
auto false_block_id = else_stmt ? next_id() : merge_block_id;
auto false_block_id = else_stmt ? module_.NextId() : merge_block_id;
if (!push_function_inst(spv::Op::OpBranchConditional,
{Operand(cond_id), Operand(true_block_id), Operand(false_block_id)})) {
@ -3677,19 +3616,19 @@ uint32_t Builder::GenerateTypeIfNeeded(const type::Type* type) {
return GenerateArrayType(arr, result);
},
[&](const type::Bool*) {
push_type(spv::Op::OpTypeBool, {result});
module_.PushType(spv::Op::OpTypeBool, {result});
return true;
},
[&](const type::F32*) {
push_type(spv::Op::OpTypeFloat, {result, Operand(32u)});
module_.PushType(spv::Op::OpTypeFloat, {result, Operand(32u)});
return true;
},
[&](const type::F16*) {
push_type(spv::Op::OpTypeFloat, {result, Operand(16u)});
module_.PushType(spv::Op::OpTypeFloat, {result, Operand(16u)});
return true;
},
[&](const type::I32*) {
push_type(spv::Op::OpTypeInt, {result, Operand(32u), Operand(1u)});
module_.PushType(spv::Op::OpTypeInt, {result, Operand(32u), Operand(1u)});
return true;
},
[&](const type::Matrix* mat) { //
@ -3705,14 +3644,14 @@ uint32_t Builder::GenerateTypeIfNeeded(const type::Type* type) {
return GenerateStructType(str, result);
},
[&](const type::U32*) {
push_type(spv::Op::OpTypeInt, {result, Operand(32u), Operand(0u)});
module_.PushType(spv::Op::OpTypeInt, {result, Operand(32u), Operand(0u)});
return true;
},
[&](const type::Vector* vec) { //
return GenerateVectorType(vec, result);
},
[&](const type::Void*) {
push_type(spv::Op::OpTypeVoid, {result});
module_.PushType(spv::Op::OpTypeVoid, {result});
return true;
},
[&](const type::StorageTexture* tex) {
@ -3734,7 +3673,7 @@ uint32_t Builder::GenerateTypeIfNeeded(const type::Type* type) {
},
[&](const type::Texture* tex) { return GenerateTextureType(tex, result); },
[&](const type::Sampler* s) {
push_type(spv::Op::OpTypeSampler, {result});
module_.PushType(spv::Op::OpTypeSampler, {result});
// Register both of the sampler type names. In SPIR-V they're the same
// sampler type, so we need to match that when we do the dedup check.
@ -3776,9 +3715,9 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r
if (dim == type::TextureDimension::k1d) {
dim_literal = SpvDim1D;
if (texture->Is<type::SampledTexture>()) {
push_capability(SpvCapabilitySampled1D);
module_.PushCapability(SpvCapabilitySampled1D);
} else if (texture->Is<type::StorageTexture>()) {
push_capability(SpvCapabilityImage1D);
module_.PushCapability(SpvCapabilityImage1D);
}
}
if (dim == type::TextureDimension::k3d) {
@ -3806,7 +3745,7 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r
if (dim == type::TextureDimension::kCubeArray) {
if (texture->IsAnyOf<type::SampledTexture, type::DepthTexture>()) {
push_capability(SpvCapabilitySampledCubeArray);
module_.PushCapability(SpvCapabilitySampledCubeArray);
}
}
@ -3831,7 +3770,7 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r
format_literal = convert_texel_format_to_spv(t->texel_format());
}
push_type(spv::Op::OpTypeImage,
module_.PushType(spv::Op::OpTypeImage,
{result, Operand(type_id), Operand(dim_literal), Operand(depth_literal),
Operand(array_literal), Operand(ms_literal), Operand(sampled_literal),
Operand(format_literal)});
@ -3847,7 +3786,7 @@ bool Builder::GenerateArrayType(const type::Array* arr, const Operand& result) {
auto result_id = std::get<uint32_t>(result);
if (arr->Count()->Is<type::RuntimeArrayCount>()) {
push_type(spv::Op::OpTypeRuntimeArray, {result, Operand(elem_type)});
module_.PushType(spv::Op::OpTypeRuntimeArray, {result, Operand(elem_type)});
} else {
auto count = arr->ConstantCount();
if (!count) {
@ -3860,10 +3799,11 @@ bool Builder::GenerateArrayType(const type::Array* arr, const Operand& result) {
return false;
}
push_type(spv::Op::OpTypeArray, {result, Operand(elem_type), Operand(len_id)});
module_.PushType(spv::Op::OpTypeArray, {result, Operand(elem_type), Operand(len_id)});
}
push_annot(spv::Op::OpDecorate,
module_.PushAnnot(
spv::Op::OpDecorate,
{Operand(result_id), U32Operand(SpvDecorationArrayStride), Operand(arr->Stride())});
return true;
}
@ -3875,7 +3815,8 @@ bool Builder::GenerateMatrixType(const type::Matrix* mat, const Operand& result)
return false;
}
push_type(spv::Op::OpTypeMatrix, {result, Operand(col_type_id), Operand(mat->columns())});
module_.PushType(spv::Op::OpTypeMatrix,
{result, Operand(col_type_id), Operand(mat->columns())});
return true;
}
@ -3891,7 +3832,7 @@ bool Builder::GeneratePointerType(const type::Pointer* ptr, const Operand& resul
return false;
}
push_type(spv::Op::OpTypePointer, {result, U32Operand(stg_class), Operand(subtype_id)});
module_.PushType(spv::Op::OpTypePointer, {result, U32Operand(stg_class), Operand(subtype_id)});
return true;
}
@ -3908,7 +3849,7 @@ bool Builder::GenerateReferenceType(const type::Reference* ref, const Operand& r
return false;
}
push_type(spv::Op::OpTypePointer, {result, U32Operand(stg_class), Operand(subtype_id)});
module_.PushType(spv::Op::OpTypePointer, {result, U32Operand(stg_class), Operand(subtype_id)});
return true;
}
@ -3917,7 +3858,8 @@ bool Builder::GenerateStructType(const type::Struct* struct_type, const Operand&
auto struct_id = std::get<uint32_t>(result);
if (struct_type->Name().IsValid()) {
push_debug(spv::Op::OpName, {Operand(struct_id), Operand(struct_type->Name().Name())});
module_.PushDebug(spv::Op::OpName,
{Operand(struct_id), Operand(struct_type->Name().Name())});
}
OperandList ops;
@ -3926,7 +3868,8 @@ bool Builder::GenerateStructType(const type::Struct* struct_type, const Operand&
if (auto* sem_str = struct_type->As<sem::Struct>()) {
auto* decl = sem_str->Declaration();
if (ast::HasAttribute<transform::AddBlockAttribute::BlockAttribute>(decl->attributes)) {
push_annot(spv::Op::OpDecorate, {Operand(struct_id), U32Operand(SpvDecorationBlock)});
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(struct_id), U32Operand(SpvDecorationBlock)});
}
}
@ -3939,14 +3882,14 @@ bool Builder::GenerateStructType(const type::Struct* struct_type, const Operand&
ops.push_back(Operand(mem_id));
}
push_type(spv::Op::OpTypeStruct, std::move(ops));
module_.PushType(spv::Op::OpTypeStruct, std::move(ops));
return true;
}
uint32_t Builder::GenerateStructMember(uint32_t struct_id,
uint32_t idx,
const type::StructMember* member) {
push_debug(spv::Op::OpMemberName,
module_.PushDebug(spv::Op::OpMemberName,
{Operand(struct_id), Operand(idx), Operand(member->Name().Name())});
// Note: This will generate layout annotations for *all* structs, whether or
@ -3955,18 +3898,18 @@ uint32_t Builder::GenerateStructMember(uint32_t struct_id,
// to only generate the layout info for structs used for certain storage
// classes.
push_annot(spv::Op::OpMemberDecorate,
module_.PushAnnot(spv::Op::OpMemberDecorate,
{Operand(struct_id), Operand(idx), U32Operand(SpvDecorationOffset),
Operand(member->Offset())});
// Infer and emit matrix layout.
auto* matrix_type = GetNestedMatrixType(member->Type());
if (matrix_type) {
push_annot(spv::Op::OpMemberDecorate,
module_.PushAnnot(spv::Op::OpMemberDecorate,
{Operand(struct_id), Operand(idx), U32Operand(SpvDecorationColMajor)});
const uint32_t scalar_elem_size = matrix_type->type()->Size();
const uint32_t effective_row_count = (matrix_type->rows() == 2) ? 2 : 4;
push_annot(spv::Op::OpMemberDecorate,
module_.PushAnnot(spv::Op::OpMemberDecorate,
{Operand(struct_id), Operand(idx), U32Operand(SpvDecorationMatrixStride),
Operand(effective_row_count * scalar_elem_size)});
}
@ -3980,7 +3923,7 @@ bool Builder::GenerateVectorType(const type::Vector* vec, const Operand& result)
return false;
}
push_type(spv::Op::OpTypeVector, {result, Operand(type_id), Operand(vec->Width())});
module_.PushType(spv::Op::OpTypeVector, {result, Operand(type_id), Operand(vec->Width())});
return true;
}
@ -4042,7 +3985,7 @@ SpvBuiltIn Builder::ConvertBuiltin(builtin::BuiltinValue builtin, builtin::Addre
case builtin::BuiltinValue::kNumWorkgroups:
return SpvBuiltInNumWorkgroups;
case builtin::BuiltinValue::kSampleIndex:
push_capability(SpvCapabilitySampleRateShading);
module_.PushCapability(SpvCapabilitySampleRateShading);
return SpvBuiltInSampleId;
case builtin::BuiltinValue::kSampleMask:
return SpvBuiltInSampleMask;
@ -4057,10 +4000,11 @@ void Builder::AddInterpolationDecorations(uint32_t id,
builtin::InterpolationSampling sampling) {
switch (type) {
case builtin::InterpolationType::kLinear:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationNoPerspective)});
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(id), U32Operand(SpvDecorationNoPerspective)});
break;
case builtin::InterpolationType::kFlat:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationFlat)});
module_.PushAnnot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationFlat)});
break;
case builtin::InterpolationType::kPerspective:
case builtin::InterpolationType::kUndefined:
@ -4068,11 +4012,12 @@ void Builder::AddInterpolationDecorations(uint32_t id,
}
switch (sampling) {
case builtin::InterpolationSampling::kCentroid:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationCentroid)});
module_.PushAnnot(spv::Op::OpDecorate,
{Operand(id), U32Operand(SpvDecorationCentroid)});
break;
case builtin::InterpolationSampling::kSample:
push_capability(SpvCapabilitySampleRateShading);
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationSample)});
module_.PushCapability(SpvCapabilitySampleRateShading);
module_.PushAnnot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationSample)});
break;
case builtin::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kUndefined:
@ -4101,13 +4046,13 @@ SpvImageFormat Builder::convert_texel_format_to_spv(const builtin::TexelFormat f
case builtin::TexelFormat::kRgba8Sint:
return SpvImageFormatRgba8i;
case builtin::TexelFormat::kRg32Uint:
push_capability(SpvCapabilityStorageImageExtendedFormats);
module_.PushCapability(SpvCapabilityStorageImageExtendedFormats);
return SpvImageFormatRg32ui;
case builtin::TexelFormat::kRg32Sint:
push_capability(SpvCapabilityStorageImageExtendedFormats);
module_.PushCapability(SpvCapabilityStorageImageExtendedFormats);
return SpvImageFormatRg32i;
case builtin::TexelFormat::kRg32Float:
push_capability(SpvCapabilityStorageImageExtendedFormats);
module_.PushCapability(SpvCapabilityStorageImageExtendedFormats);
return SpvImageFormatRg32f;
case builtin::TexelFormat::kRgba16Uint:
return SpvImageFormatRgba16ui;
@ -4128,22 +4073,22 @@ SpvImageFormat Builder::convert_texel_format_to_spv(const builtin::TexelFormat f
}
bool Builder::push_function_inst(spv::Op op, const OperandList& operands) {
if (functions_.empty()) {
if (!current_function_) {
utils::StringStream ss;
ss << "Internal error: trying to add SPIR-V instruction " << int(op)
<< " outside a function";
error_ = ss.str();
return false;
}
functions_.back().push_inst(op, operands);
current_function_.push_inst(op, operands);
return true;
}
bool Builder::InsideBasicBlock() const {
if (functions_.empty()) {
if (!current_function_) {
return false;
}
const auto& instructions = functions_.back().instructions();
const auto& instructions = current_function_.instructions();
if (instructions.empty()) {
// The Function object does not explicitly represent its entry block
// label. So return *true* because an empty list means the only

View File

@ -15,6 +15,7 @@
#ifndef SRC_TINT_WRITER_SPIRV_BUILDER_H_
#define SRC_TINT_WRITER_SPIRV_BUILDER_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
@ -39,6 +40,7 @@
#include "src/tint/sem/builtin.h"
#include "src/tint/type/storage_texture.h"
#include "src/tint/writer/spirv/function.h"
#include "src/tint/writer/spirv/module.h"
#include "src/tint/writer/spirv/scalar_constant.h"
// Forward declarations
@ -54,7 +56,7 @@ class Reference;
namespace tint::writer::spirv {
/// Builder class to create SPIR-V instructions from a module.
/// Builder class to create a SPIR-V module from a Tint AST.
class Builder {
public:
/// Contains information for generating accessor chains
@ -92,100 +94,17 @@ class Builder {
/// @returns true if the builder encountered an error
bool has_error() const { return !error_.empty(); }
/// @returns the number of uint32_t's needed to make up the results
uint32_t total_size() const;
/// @returns the module that this builder has produced
spirv::Module& Module() { return module_; }
/// @returns the id bound for this program
uint32_t id_bound() const { return next_id_; }
/// @returns the next id to be used
uint32_t next_id() {
auto id = next_id_;
next_id_ += 1;
return id;
/// Add an empty function to the builder, to be used for testing purposes.
void PushFunctionForTesting() {
current_function_ = Function(Instruction(spv::Op::OpFunction, {}), {}, {});
}
/// Iterates over all the instructions in the correct order and calls the
/// given callback
/// @param cb the callback to execute
void iterate(std::function<void(const Instruction&)> cb) const;
/// @returns the current function
const Function& CurrentFunction() { return current_function_; }
/// Adds an instruction to the list of capabilities, if the capability
/// hasn't already been added.
/// @param cap the capability to set
void push_capability(uint32_t cap);
/// @returns the capabilities
const InstructionList& capabilities() const { return capabilities_; }
/// Adds an instruction to the extensions
/// @param extension the name of the extension
void push_extension(const char* extension);
/// @returns the extensions
const InstructionList& extensions() const { return extensions_; }
/// Adds an instruction to the ext import
/// @param op the op to set
/// @param operands the operands for the instruction
void push_ext_import(spv::Op op, const OperandList& operands) {
ext_imports_.push_back(Instruction{op, operands});
}
/// @returns the ext imports
const InstructionList& ext_imports() const { return ext_imports_; }
/// Adds an instruction to the memory model
/// @param op the op to set
/// @param operands the operands for the instruction
void push_memory_model(spv::Op op, const OperandList& operands) {
memory_model_.push_back(Instruction{op, operands});
}
/// @returns the memory model
const InstructionList& memory_model() const { return memory_model_; }
/// Adds an instruction to the entry points
/// @param op the op to set
/// @param operands the operands for the instruction
void push_entry_point(spv::Op op, const OperandList& operands) {
entry_points_.push_back(Instruction{op, operands});
}
/// @returns the entry points
const InstructionList& entry_points() const { return entry_points_; }
/// Adds an instruction to the execution modes
/// @param op the op to set
/// @param operands the operands for the instruction
void push_execution_mode(spv::Op op, const OperandList& operands) {
execution_modes_.push_back(Instruction{op, operands});
}
/// @returns the execution modes
const InstructionList& execution_modes() const { return execution_modes_; }
/// Adds an instruction to the debug
/// @param op the op to set
/// @param operands the operands for the instruction
void push_debug(spv::Op op, const OperandList& operands) {
debug_.push_back(Instruction{op, operands});
}
/// @returns the debug instructions
const InstructionList& debug() const { return debug_; }
/// Adds an instruction to the types
/// @param op the op to set
/// @param operands the operands for the instruction
void push_type(spv::Op op, const OperandList& operands) {
types_.push_back(Instruction{op, operands});
}
/// @returns the type instructions
const InstructionList& types() const { return types_; }
/// Adds an instruction to the annotations
/// @param op the op to set
/// @param operands the operands for the instruction
void push_annot(spv::Op op, const OperandList& operands) {
annotations_.push_back(Instruction{op, operands});
}
/// @returns the annotations
const InstructionList& annots() const { return annotations_; }
/// Adds a function to the builder
/// @param func the function to add
void push_function(const Function& func) {
functions_.push_back(func);
current_label_id_ = func.label_id();
}
/// @returns the functions
const std::vector<Function>& functions() const { return functions_; }
/// Pushes an instruction to the current function. If we're outside
/// a function then issue an internal error and return false.
/// @param op the operation
@ -195,11 +114,11 @@ class Builder {
/// Pushes a variable to the current function
/// @param operands the variable operands
void push_function_var(const OperandList& operands) {
if (TINT_UNLIKELY(functions_.empty())) {
if (TINT_UNLIKELY(!current_function_)) {
TINT_ICE(Writer, builder_.Diagnostics())
<< "push_function_var() called without a function";
}
functions_.back().push_var(operands);
current_function_.push_var(operands);
}
/// @returns true if the current instruction insertion point is
@ -591,18 +510,9 @@ class Builder {
ProgramBuilder builder_;
std::string error_;
uint32_t next_id_ = 1;
spirv::Module module_;
Function current_function_;
uint32_t current_label_id_ = 0;
InstructionList capabilities_;
InstructionList extensions_;
InstructionList ext_imports_;
InstructionList memory_model_;
InstructionList entry_points_;
InstructionList execution_modes_;
InstructionList debug_;
InstructionList types_;
InstructionList annotations_;
std::vector<Function> functions_;
// Scope holds per-block information
struct Scope {
@ -625,7 +535,6 @@ class Builder {
std::vector<Scope> scope_stack_;
std::vector<uint32_t> merge_stack_;
std::vector<uint32_t> continue_stack_;
std::unordered_set<uint32_t> capability_set_;
bool zero_initialize_workgroup_memory_ = false;
struct ContinuingInfo {

View File

@ -34,7 +34,7 @@ TEST_F(BuilderTest, Let_IndexAccessor_Vector) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%6 = OpTypeInt 32 1
%5 = OpTypeVector %6 3
@ -45,9 +45,10 @@ TEST_F(BuilderTest, Let_IndexAccessor_Vector) {
%13 = OpTypePointer Function %6
%14 = OpConstantNull %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%12 = OpVariable %13 Function %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%12 = OpVariable %13 Function %14
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpCompositeExtract %6 %10 1
OpStore %12 %11
OpReturn
@ -68,16 +69,17 @@ TEST_F(BuilderTest, Const_IndexAccessor_Vector) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%5 = OpTypeInt 32 1
%6 = OpConstant %5 2
%8 = OpTypePointer Function %5
%9 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%7 = OpVariable %8 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%7 = OpVariable %8 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpStore %7 %6
OpReturn
)");
@ -97,7 +99,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Vector) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeInt 32 0
%7 = OpTypeVector %8 3
@ -108,10 +110,12 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Vector) {
%12 = OpTypePointer Function %8
%16 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
%15 = OpVariable %12 Function %16
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%13 = OpAccessChain %12 %5 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%13 = OpAccessChain %12 %5 %11
%14 = OpLoad %8 %13
OpStore %15 %14
OpReturn
@ -134,7 +138,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Vector) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -146,11 +150,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Vector) {
%15 = OpTypePointer Function %8
%19 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
%10 = OpVariable %11 Function %13
%18 = OpVariable %15 Function %19
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%14 = OpLoad %12 %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%14 = OpLoad %12 %10
%16 = OpAccessChain %15 %5 %14
%17 = OpLoad %8 %16
OpStore %18 %17
@ -172,7 +177,7 @@ TEST_F(BuilderTest, Const_IndexAccessor_Vector2) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%6 = OpTypeInt 32 1
%5 = OpTypeVector %6 3
@ -183,9 +188,10 @@ TEST_F(BuilderTest, Const_IndexAccessor_Vector2) {
%13 = OpTypePointer Function %6
%14 = OpConstantNull %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%12 = OpVariable %13 Function %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%12 = OpVariable %13 Function %14
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpCompositeExtract %6 %10 2
OpStore %12 %11
OpReturn
@ -206,7 +212,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Vector2) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -217,10 +223,12 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Vector2) {
%12 = OpTypePointer Function %8
%16 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
%15 = OpVariable %12 Function %16
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%13 = OpAccessChain %12 %5 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%13 = OpAccessChain %12 %5 %11
%14 = OpLoad %8 %13
OpStore %15 %14
OpReturn
@ -243,7 +251,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Vector2) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -257,11 +265,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Vector2) {
%18 = OpTypePointer Function %8
%22 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
%12 = OpVariable %13 Function %14
%21 = OpVariable %18 Function %22
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %12 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpStore %12 %11
%15 = OpLoad %10 %12
%17 = OpIAdd %10 %15 %16
%19 = OpAccessChain %18 %5 %17
@ -286,7 +295,7 @@ TEST_F(BuilderTest, Let_IndexAccessor_Array_MultiLevel) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%7 = OpTypeFloat 32
%6 = OpTypeVector %7 3
@ -308,9 +317,10 @@ TEST_F(BuilderTest, Let_IndexAccessor_Array_MultiLevel) {
%25 = OpTypePointer Function %7
%26 = OpConstantNull %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%24 = OpVariable %25 Function %26
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%24 = OpVariable %25 Function %26
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%21 = OpCompositeExtract %6 %18 1
%23 = OpCompositeExtract %7 %21 2
OpStore %24 %23
@ -333,16 +343,17 @@ TEST_F(BuilderTest, Const_IndexAccessor_Array_MultiLevel) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%5 = OpTypeFloat 32
%6 = OpConstant %5 6
%8 = OpTypePointer Function %5
%9 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%7 = OpVariable %8 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%7 = OpVariable %8 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpStore %7 %6
OpReturn
)");
@ -362,7 +373,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_MultiLevel) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -377,10 +388,11 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_MultiLevel) {
%16 = OpTypePointer Function %9
%20 = OpConstantNull %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %12
%19 = OpVariable %16 Function %20
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%17 = OpAccessChain %16 %5 %14 %15
%18 = OpLoad %9 %17
OpStore %19 %18
@ -404,7 +416,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Array_MultiLevel) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -421,11 +433,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Array_MultiLevel) {
%20 = OpTypePointer Function %9
%24 = OpConstantNull %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %12
%15 = OpVariable %16 Function %17
%23 = OpVariable %20 Function %24
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %15 %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpStore %15 %14
%18 = OpLoad %13 %15
%21 = OpAccessChain %20 %5 %18 %19
%22 = OpLoad %9 %21
@ -449,7 +462,7 @@ TEST_F(BuilderTest, Const_IndexAccessor_Array_ArrayWithSwizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%7 = OpTypeFloat 32
%6 = OpTypeVector %7 3
@ -471,9 +484,10 @@ TEST_F(BuilderTest, Const_IndexAccessor_Array_ArrayWithSwizzle) {
%25 = OpTypePointer Function %22
%26 = OpConstantNull %22
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%24 = OpVariable %25 Function %26
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%24 = OpVariable %25 Function %26
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%21 = OpCompositeExtract %6 %18 1
%23 = OpVectorShuffle %22 %21 %21 0 1
OpStore %24 %23
@ -495,7 +509,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_ArrayWithSwizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -511,10 +525,12 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_ArrayWithSwizzle) {
%21 = OpTypePointer Function %17
%22 = OpConstantNull %17
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %12
%20 = OpVariable %21 Function %22
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%16 = OpAccessChain %15 %5 %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%16 = OpAccessChain %15 %5 %14
%18 = OpLoad %8 %16
%19 = OpVectorShuffle %17 %18 %18 0 1
OpStore %20 %19
@ -538,7 +554,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Array_ArrayWithSwizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -556,11 +572,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Array_ArrayWithSwizzle) {
%25 = OpTypePointer Function %21
%26 = OpConstantNull %21
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %12
%15 = OpVariable %16 Function %17
%24 = OpVariable %25 Function %26
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %15 %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpStore %15 %14
%18 = OpLoad %13 %15
%20 = OpAccessChain %19 %5 %18
%22 = OpLoad %8 %20
@ -589,7 +606,7 @@ TEST_F(BuilderTest, Let_IndexAccessor_Nested_Array_f32) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%7 = OpTypeFloat 32
%6 = OpTypeVector %7 2
@ -607,9 +624,10 @@ TEST_F(BuilderTest, Let_IndexAccessor_Nested_Array_f32) {
%19 = OpConstantNull %8
%22 = OpTypePointer Function %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%21 = OpVariable %22 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%21 = OpVariable %22 Function %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%18 = OpCompositeExtract %6 %16 1
%20 = OpCompositeExtract %7 %18 0
OpStore %21 %20
@ -636,16 +654,17 @@ TEST_F(BuilderTest, Const_IndexAccessor_Nested_Array_f32) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%5 = OpTypeFloat 32
%6 = OpConstant %5 -0.5
%8 = OpTypePointer Function %5
%9 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%7 = OpVariable %8 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%7 = OpVariable %8 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpStore %7 %6
OpReturn
)");
@ -665,7 +684,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_Vec3_f32) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 3
@ -679,10 +698,11 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Array_Vec3_f32) {
%15 = OpTypePointer Function %9
%19 = OpConstantNull %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %12
%18 = OpVariable %15 Function %19
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%16 = OpAccessChain %15 %5 %13 %14
%17 = OpLoad %9 %16
OpStore %18 %17
@ -706,7 +726,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Nested_Array_f32) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%10 = OpTypeInt 32 0
@ -722,11 +742,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Nested_Array_f32) {
%19 = OpTypePointer Function %9
%23 = OpConstantNull %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %13
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %13
%15 = OpVariable %16 Function %17
%22 = OpVariable %19 Function %23
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %15 %14
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpStore %15 %14
%18 = OpLoad %10 %15
%20 = OpAccessChain %19 %5 %18 %14
%21 = OpLoad %9 %20
@ -751,7 +772,7 @@ TEST_F(BuilderTest, Let_IndexAccessor_Matrix) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%7 = OpTypeFloat 32
%6 = OpTypeVector %7 2
@ -768,9 +789,10 @@ TEST_F(BuilderTest, Let_IndexAccessor_Matrix) {
%19 = OpTypePointer Function %6
%20 = OpConstantNull %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%18 = OpVariable %19 Function %20
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%18 = OpVariable %19 Function %20
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%17 = OpCompositeExtract %6 %14 1
OpStore %18 %17
OpReturn
@ -793,7 +815,7 @@ TEST_F(BuilderTest, Const_IndexAccessor_Matrix) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%6 = OpTypeFloat 32
%5 = OpTypeVector %6 2
@ -803,9 +825,10 @@ TEST_F(BuilderTest, Const_IndexAccessor_Matrix) {
%11 = OpTypePointer Function %5
%12 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%10 = OpVariable %11 Function %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%10 = OpVariable %11 Function %12
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpStore %10 %9
OpReturn
)");
@ -825,7 +848,7 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Matrix) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 2
@ -837,10 +860,12 @@ TEST_F(BuilderTest, Runtime_IndexAccessor_Matrix) {
%13 = OpTypePointer Function %8
%17 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
%16 = OpVariable %13 Function %17
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%14 = OpAccessChain %13 %5 %12
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%14 = OpAccessChain %13 %5 %12
%15 = OpLoad %8 %14
OpStore %16 %15
OpReturn
@ -863,7 +888,7 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Matrix) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeVector %9 2
@ -876,11 +901,12 @@ TEST_F(BuilderTest, Dynamic_IndexAccessor_Matrix) {
%16 = OpTypePointer Function %8
%20 = OpConstantNull %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
%11 = OpVariable %12 Function %14
%19 = OpVariable %16 Function %20
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%15 = OpLoad %13 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%15 = OpLoad %13 %11
%17 = OpAccessChain %16 %5 %15
%18 = OpLoad %8 %17
OpStore %19 %18
@ -912,7 +938,7 @@ TEST_F(BuilderTest, MemberAccessor) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeStruct %8 %8
@ -922,9 +948,11 @@ TEST_F(BuilderTest, MemberAccessor) {
%11 = OpConstant %10 1
%12 = OpTypePointer Function %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%13 = OpAccessChain %12 %5 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%13 = OpAccessChain %12 %5 %11
%14 = OpLoad %8 %13
OpReturn
)");
@ -958,7 +986,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeStruct %9 %9
@ -970,9 +998,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested) {
%13 = OpConstant %11 1
%14 = OpTypePointer Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%15 = OpAccessChain %14 %5 %12 %13
%16 = OpLoad %9 %15
OpReturn
@ -1003,14 +1032,15 @@ TEST_F(BuilderTest, MemberAccessor_NonPointer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%6 = OpTypeFloat 32
%5 = OpTypeStruct %6 %6
%7 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%8 = OpCompositeExtract %6 %7 1
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%8 = OpCompositeExtract %6 %7 1
OpReturn
)");
@ -1044,15 +1074,15 @@ TEST_F(BuilderTest, MemberAccessor_Nested_NonPointer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%7 = OpTypeFloat 32
%6 = OpTypeStruct %7 %7
%5 = OpTypeStruct %6
%8 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%9 = OpCompositeExtract %6 %8 0
%10 = OpCompositeExtract %7 %9 1
OpReturn
@ -1089,7 +1119,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeStruct %9 %9
@ -1100,9 +1130,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) {
%12 = OpConstant %11 0
%13 = OpTypePointer Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%14 = OpAccessChain %13 %5 %12 %12
%15 = OpLoad %9 %14
OpReturn
@ -1136,7 +1167,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeStruct %9 %9
@ -1148,9 +1179,10 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_LHS) {
%13 = OpTypePointer Function %9
%15 = OpConstant %9 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%14 = OpAccessChain %13 %5 %12 %12
OpStore %14 %15
OpReturn
@ -1188,7 +1220,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeFloat 32
%8 = OpTypeStruct %9 %9
@ -1200,10 +1232,11 @@ TEST_F(BuilderTest, MemberAccessor_Nested_Assignment_RHS) {
%14 = OpTypeInt 32 0
%15 = OpConstant %14 0
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %10
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %10
%11 = OpVariable %12 Function %13
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%16 = OpAccessChain %12 %5 %15 %15
%17 = OpLoad %9 %16
OpStore %11 %17
@ -1225,7 +1258,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -1235,9 +1268,11 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_Single) {
%11 = OpConstant %10 1
%12 = OpTypePointer Function %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%13 = OpAccessChain %12 %5 %11
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%13 = OpAccessChain %12 %5 %11
%14 = OpLoad %8 %13
OpReturn
)");
@ -1257,7 +1292,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -1265,9 +1300,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_MultipleNames) {
%9 = OpConstantNull %7
%11 = OpTypeVector %8 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%10 = OpLoad %7 %5
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%10 = OpLoad %7 %5
%12 = OpVectorShuffle %11 %10 %10 1 0
OpReturn
)");
@ -1287,7 +1323,7 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -1295,9 +1331,10 @@ TEST_F(BuilderTest, MemberAccessor_Swizzle_of_Swizzle) {
%9 = OpConstantNull %7
%12 = OpTypeVector %8 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%10 = OpLoad %7 %5
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%10 = OpLoad %7 %5
%11 = OpVectorShuffle %7 %10 %10 1 0 2
%13 = OpVectorShuffle %12 %11 %11 0 2
OpReturn
@ -1318,16 +1355,17 @@ TEST_F(BuilderTest, MemberAccessor_Member_of_Swizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
%6 = OpTypePointer Function %7
%9 = OpConstantNull %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%10 = OpLoad %7 %5
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%10 = OpLoad %7 %5
%11 = OpVectorShuffle %7 %10 %10 1 0 2
%12 = OpCompositeExtract %8 %11 0
OpReturn
@ -1348,7 +1386,7 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%8 = OpTypeFloat 32
%7 = OpTypeVector %8 3
@ -1357,9 +1395,10 @@ TEST_F(BuilderTest, MemberAccessor_Array_of_Swizzle) {
%12 = OpTypeInt 32 1
%13 = OpConstant %12 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %9
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(%10 = OpLoad %7 %5
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(%10 = OpLoad %7 %5
%11 = OpVectorShuffle %7 %10 %10 1 0 2
%14 = OpCompositeExtract %8 %11 1
OpReturn
@ -1401,7 +1440,7 @@ TEST_F(BuilderTest, IndexAccessor_Mixed_ArrayAndMember) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%13 = OpTypeFloat 32
%12 = OpTypeVector %13 3
@ -1422,9 +1461,10 @@ TEST_F(BuilderTest, IndexAccessor_Mixed_ArrayAndMember) {
%22 = OpTypePointer Function %12
%24 = OpTypeVector %13 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"(%5 = OpVariable %6 Function %17
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()),
R"(%5 = OpVariable %6 Function %17
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%23 = OpAccessChain %22 %5 %19 %20 %21 %20 %20
%25 = OpLoad %12 %23
%26 = OpVectorShuffle %24 %25 %25 1 0

View File

@ -31,21 +31,21 @@ TEST_F(BuilderTest, Assign_Var) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
%5 = OpConstant %3 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %5
)");
}
@ -79,21 +79,21 @@ TEST_F(BuilderTest, Assign_Var_ZeroInitializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
%1 = OpVariable %2 Private %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %5
)");
}
@ -109,14 +109,14 @@ TEST_F(BuilderTest, Assign_Var_Complex_InitializerNestedVector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -126,7 +126,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_InitializerNestedVector) {
%8 = OpConstant %4 3
%9 = OpConstantComposite %3 %6 %7 %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %9
)");
}
@ -142,14 +142,14 @@ TEST_F(BuilderTest, Assign_Var_Complex_Initializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -159,7 +159,7 @@ TEST_F(BuilderTest, Assign_Var_Complex_Initializer) {
%8 = OpConstant %4 3
%9 = OpConstantComposite %3 %6 %7 %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %9
)");
}
@ -185,14 +185,14 @@ TEST_F(BuilderTest, Assign_StructMember) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeStruct %4 %4
%2 = OpTypePointer Function %3
%5 = OpConstantNull %3
@ -202,7 +202,7 @@ TEST_F(BuilderTest, Assign_StructMember) {
%10 = OpConstant %4 4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpAccessChain %8 %1 %7
OpStore %9 %10
)");
@ -218,14 +218,14 @@ TEST_F(BuilderTest, Assign_Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -235,7 +235,7 @@ TEST_F(BuilderTest, Assign_Vector) {
%8 = OpConstantComposite %3 %6 %6 %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %8
)");
}
@ -251,14 +251,14 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -269,7 +269,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByName) {
%10 = OpConstant %4 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpAccessChain %8 %1 %7
OpStore %9 %10
)");
@ -286,14 +286,14 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateAssignStatement(assign)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -304,7 +304,7 @@ TEST_F(BuilderTest, Assign_Vector_MemberByIndex) {
%10 = OpConstant %4 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpAccessChain %8 %1 %7
OpStore %9 %10
)");

View File

@ -46,14 +46,14 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 3
%3 = OpConstant %1 4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %1 %2 %3\n");
}
@ -75,15 +75,15 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %1 %4 %4\n");
}
TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
@ -96,19 +96,19 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar_Loads) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 7u) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Function %3
%4 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%1 = OpVariable %2 Function %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%5 = OpLoad %3 %1
%6 = OpLoad %3 %1
%7 = )" + param.name +
@ -140,14 +140,14 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 0
%2 = OpConstant %1 3
%3 = OpConstant %1 4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %1 %2 %3\n");
}
TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
@ -168,15 +168,15 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %1 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(
@ -206,14 +206,14 @@ TEST_P(BinaryArithF32Test, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 3.20000005
%3 = OpConstant %1 4.5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %1 %2 %3\n");
}
@ -229,15 +229,15 @@ TEST_P(BinaryArithF32Test, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %1 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(BuilderTest,
@ -263,14 +263,14 @@ TEST_P(BinaryArithF16Test, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 16
%2 = OpConstant %1 0x1.998p+1
%3 = OpConstant %1 0x1.2p+2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %1 %2 %3\n");
}
@ -288,15 +288,15 @@ TEST_P(BinaryArithF16Test, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 16
%1 = OpTypeVector %2 3
%3 = OpConstant %2 0x1p+0
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %1 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(BuilderTest,
@ -320,14 +320,14 @@ TEST_P(BinaryOperatorBoolTest, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
%3 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %1 %2 %3\n");
}
@ -343,17 +343,17 @@ TEST_P(BinaryOperatorBoolTest, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 7u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%1 = OpTypeVector %2 3
%3 = OpConstantNull %2
%4 = OpConstantTrue %2
%5 = OpConstantComposite %1 %3 %4 %3
%6 = OpConstantComposite %1 %4 %3 %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%7 = " + param.name + " %1 %5 %6\n");
}
INSTANTIATE_TEST_SUITE_P(BuilderTest,
@ -376,15 +376,15 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 0
%2 = OpConstant %1 3
%3 = OpConstant %1 4
%5 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %5 %2 %3\n");
}
@ -400,17 +400,17 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
%7 = OpTypeBool
%6 = OpTypeVector %7 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %6 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(
@ -436,15 +436,15 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 3
%3 = OpConstant %1 4
%5 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %5 %2 %3\n");
}
@ -460,17 +460,17 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
%7 = OpTypeBool
%6 = OpTypeVector %7 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %6 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(
@ -496,15 +496,15 @@ TEST_P(BinaryCompareF32Test, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 3.20000005
%3 = OpConstant %1 4.5
%5 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %5 %2 %3\n");
}
@ -520,17 +520,17 @@ TEST_P(BinaryCompareF32Test, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
%7 = OpTypeBool
%6 = OpTypeVector %7 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %6 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(
@ -558,15 +558,15 @@ TEST_P(BinaryCompareF16Test, Scalar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 4u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 16
%2 = OpConstant %1 0x1.998p+1
%3 = OpConstant %1 0x1.2p+2
%5 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%4 = " + param.name + " %5 %2 %3\n");
}
@ -584,17 +584,17 @@ TEST_P(BinaryCompareF16Test, Vector) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 16
%1 = OpTypeVector %2 3
%3 = OpConstant %2 0x1p+0
%4 = OpConstantComposite %1 %3 %3 %3
%7 = OpTypeBool
%6 = OpTypeVector %7 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = " + param.name + " %6 %4 %4\n");
}
INSTANTIATE_TEST_SUITE_P(
@ -617,16 +617,16 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = OpVectorTimesScalar %1 %4 %3\n");
}
@ -642,16 +642,16 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 16
%1 = OpTypeVector %2 3
%3 = OpConstant %2 0x1p+0
%4 = OpConstantComposite %1 %3 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = OpVectorTimesScalar %1 %4 %3\n");
}
@ -665,16 +665,16 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1
%3 = OpTypeVector %1 3
%4 = OpConstantComposite %3 %2 %2 %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = OpVectorTimesScalar %3 %4 %2\n");
}
@ -690,16 +690,16 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 5u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%1 = OpTypeFloat 16
%2 = OpConstant %1 0x1p+0
%3 = OpTypeVector %1 3
%4 = OpConstantComposite %3 %2 %2 %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
"%5 = OpVectorTimesScalar %3 %4 %2\n");
}
@ -711,11 +711,11 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -723,7 +723,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F32) {
%6 = OpConstantNull %3
%8 = OpConstant %5 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%9 = OpMatrixTimesScalar %3 %7 %8
)");
@ -739,11 +739,11 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 16
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -751,7 +751,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar_F16) {
%6 = OpConstantNull %3
%8 = OpConstant %5 0x1p+0
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%9 = OpMatrixTimesScalar %3 %7 %8
)");
@ -765,11 +765,11 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -777,7 +777,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F32) {
%6 = OpConstantNull %3
%7 = OpConstant %5 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%8 = OpLoad %3 %1
%9 = OpMatrixTimesScalar %3 %8 %7
)");
@ -793,11 +793,11 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 16
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -805,7 +805,7 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix_F16) {
%6 = OpConstantNull %3
%7 = OpConstant %5 0x1p+0
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%8 = OpLoad %3 %1
%9 = OpMatrixTimesScalar %3 %8 %7
)");
@ -820,11 +820,11 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -833,7 +833,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F32) {
%8 = OpConstant %5 1
%9 = OpConstantComposite %4 %8 %8 %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%10 = OpMatrixTimesVector %4 %7 %9
)");
@ -850,11 +850,11 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 16
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -863,7 +863,7 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector_F16) {
%8 = OpConstant %5 0x1p+0
%9 = OpConstantComposite %4 %8 %8 %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%10 = OpMatrixTimesVector %4 %7 %9
)");
@ -878,11 +878,11 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -891,7 +891,7 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F32) {
%7 = OpConstant %5 1
%8 = OpConstantComposite %4 %7 %7 %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpLoad %3 %1
%10 = OpVectorTimesMatrix %4 %8 %9
)");
@ -909,11 +909,11 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 16
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
@ -922,7 +922,7 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix_F16) {
%7 = OpConstant %5 0x1p+0
%8 = OpConstantComposite %4 %7 %7 %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpLoad %3 %1
%10 = OpVectorTimesMatrix %4 %8 %9
)");
@ -936,18 +936,18 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F32) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
%2 = OpTypePointer Function %3
%6 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%8 = OpLoad %3 %1
%9 = OpMatrixTimesMatrix %3 %7 %8
@ -964,18 +964,18 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix_F16) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 9u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%5 = OpTypeFloat 16
%4 = OpTypeVector %5 3
%3 = OpTypeMatrix %4 3
%2 = OpTypePointer Function %3
%6 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%8 = OpLoad %3 %1
%9 = OpMatrixTimesMatrix %3 %7 %8
@ -993,15 +993,15 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.GenerateLabel(b.next_id());
b.PushFunctionForTesting();
b.GenerateLabel(b.Module().NextId());
ASSERT_TRUE(b.GenerateFunctionVariable(v0)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v1)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v3)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 22u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeInt 32 1
%3 = OpConstant %2 1
%5 = OpTypePointer Function %2
@ -1011,7 +1011,7 @@ TEST_F(BuilderTest, Binary_LogicalAnd) {
%11 = OpConstant %2 4
%16 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpLabel
OpStore %4 %3
OpStore %8 %7
@ -1041,21 +1041,21 @@ TEST_F(BuilderTest, Binary_LogicalAnd_WithLoads) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.GenerateLabel(b.next_id());
b.PushFunctionForTesting();
b.GenerateLabel(b.Module().NextId());
ASSERT_TRUE(b.GenerateGlobalVariable(a_var)) << b.error();
ASSERT_TRUE(b.GenerateGlobalVariable(b_var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%3 = OpConstantTrue %2
%5 = OpTypePointer Private %2
%4 = OpVariable %5 Private %3
%6 = OpConstantNull %2
%7 = OpVariable %5 Private %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpLabel
%8 = OpLoad %2 %4
OpSelectionMerge %9 None
@ -1086,17 +1086,17 @@ TEST_F(BuilderTest, Binary_logicalOr_Nested_LogicalAnd) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(t)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(f)) << b.error();
b.GenerateLabel(b.next_id());
b.GenerateLabel(b.Module().NextId());
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
%3 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%4 = OpLabel
OpSelectionMerge %5 None
OpBranchConditional %2 %5 %6
@ -1131,17 +1131,17 @@ TEST_F(BuilderTest, Binary_logicalAnd_Nested_LogicalOr) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(t)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(f)) << b.error();
b.GenerateLabel(b.next_id());
b.GenerateLabel(b.Module().NextId());
EXPECT_EQ(b.GenerateBinaryExpression(expr), 10u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
%3 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%4 = OpLabel
OpSelectionMerge %5 None
OpBranchConditional %2 %6 %5
@ -1169,15 +1169,15 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.GenerateLabel(b.next_id());
b.PushFunctionForTesting();
b.GenerateLabel(b.Module().NextId());
ASSERT_TRUE(b.GenerateFunctionVariable(v0)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v1)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_TRUE(b.GenerateFunctionVariable(v3)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 22u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeInt 32 1
%3 = OpConstant %2 1
%5 = OpTypePointer Function %2
@ -1187,7 +1187,7 @@ TEST_F(BuilderTest, Binary_LogicalOr) {
%11 = OpConstant %2 4
%16 = OpTypeBool
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpLabel
OpStore %4 %3
OpStore %8 %7
@ -1218,21 +1218,21 @@ TEST_F(BuilderTest, Binary_LogicalOr_WithLoads) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.GenerateLabel(b.next_id());
b.PushFunctionForTesting();
b.GenerateLabel(b.Module().NextId());
ASSERT_TRUE(b.GenerateGlobalVariable(a_var)) << b.error();
ASSERT_TRUE(b.GenerateGlobalVariable(b_var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr), 12u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%3 = OpConstantTrue %2
%5 = OpTypePointer Private %2
%4 = OpVariable %5 Private %3
%6 = OpConstantNull %2
%7 = OpVariable %5 Private %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpLabel
%8 = OpLoad %2 %4
OpSelectionMerge %9 None

View File

@ -29,14 +29,14 @@ TEST_F(BuilderTest, Bitcast) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBitcastExpression(bitcast), 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 0
%3 = OpTypeFloat 32
%4 = OpConstant %3 2.4000001
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpBitcast %2 %4
)");
}
@ -48,13 +48,13 @@ TEST_F(BuilderTest, Bitcast_DuplicateType) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateBitcastExpression(bitcast), 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%3 = OpConstant %2 2.4000001
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpCopyObject %2 %3
)");
}

View File

@ -32,13 +32,13 @@ TEST_F(BuilderTest, Block) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_TRUE(b.GenerateStatement(outer)) << b.error();
EXPECT_FALSE(b.has_error());
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3
%4 = OpConstantNull %3
%5 = OpConstant %3 1
@ -46,12 +46,12 @@ TEST_F(BuilderTest, Block) {
%8 = OpConstant %3 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%1 = OpVariable %2 Function %4
%6 = OpVariable %2 Function %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %1 %5
OpStore %6 %7
OpStore %1 %8

View File

@ -63,7 +63,7 @@ TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(tex)) << b.error();
ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error();
@ -71,7 +71,7 @@ TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) {
EXPECT_EQ(b.GenerateExpression(expr1), 8u) << b.error();
EXPECT_EQ(b.GenerateExpression(expr2), 17u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeImage %4 2D 0 0 0 1 Unknown
%2 = OpTypePointer UniformConstant %3
%1 = OpVariable %2 UniformConstant
@ -85,7 +85,7 @@ TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) {
%16 = OpConstantComposite %13 %14 %15
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%9 = OpLoad %7 %5
%10 = OpLoad %3 %1
%12 = OpSampledImage %11 %10 %9
@ -185,7 +185,7 @@ TEST_P(BuiltinBoolTest, Call_Bool_Scalar) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeBool
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -194,7 +194,8 @@ TEST_P(BuiltinBoolTest, Call_Bool_Scalar) {
)");
// both any and all are 'passthrough' for scalar booleans
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), "%10 = OpLoad %3 %1\nOpReturn\n");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
"%10 = OpLoad %3 %1\nOpReturn\n");
}
TEST_P(BuiltinBoolTest, Call_Bool_Vector) {
@ -211,7 +212,7 @@ TEST_P(BuiltinBoolTest, Call_Bool_Vector) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeBool
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -225,7 +226,7 @@ TEST_P(BuiltinBoolTest, Call_Bool_Vector) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
INSTANTIATE_TEST_SUITE_P(BuiltinBuilderTest,
BuiltinBoolTest,
@ -247,7 +248,7 @@ TEST_F(BuiltinBuilderTest, Call_Select) {
ASSERT_TRUE(b.GenerateGlobalVariable(bool_v3)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -260,7 +261,7 @@ TEST_F(BuiltinBuilderTest, Call_Select) {
%12 = OpTypeVoid
%11 = OpTypeFunction %12
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%16 = OpLoad %8 %6
%17 = OpLoad %3 %1
%18 = OpLoad %3 %1
@ -294,7 +295,7 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeFloat 32
%4 = OpTypeRuntimeArray %5
@ -305,13 +306,13 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength) {
%6 = OpTypeFunction %7
%11 = OpTypeInt 32 0
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%10 = OpArrayLength %11 %1 0
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -338,7 +339,7 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%4 = OpTypeFloat 32
%5 = OpTypeRuntimeArray %4
@ -349,13 +350,13 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_OtherMembersInStruct) {
%6 = OpTypeFunction %7
%11 = OpTypeInt 32 0
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%10 = OpArrayLength %11 %1 1
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -386,7 +387,7 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeFloat 32
%4 = OpTypeRuntimeArray %5
@ -397,13 +398,13 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets) {
%6 = OpTypeFunction %7
%11 = OpTypeInt 32 0
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%10 = OpArrayLength %11 %1 0
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -447,7 +448,7 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets_WithPtrNoise) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeFloat 32
%4 = OpTypeRuntimeArray %5
@ -458,13 +459,13 @@ TEST_F(BuiltinBuilderTest, Call_ArrayLength_ViaLets_WithPtrNoise) {
%6 = OpTypeFunction %7
%11 = OpTypeInt 32 0
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%10 = OpArrayLength %11 %1 0
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -2166,7 +2167,7 @@ TEST_P(BuiltinIntTest, Call_SInt_Scalar) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -2179,7 +2180,7 @@ TEST_P(BuiltinIntTest, Call_SInt_Scalar) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
TEST_P(BuiltinIntTest, Call_SInt_Vector) {
@ -2196,7 +2197,7 @@ TEST_P(BuiltinIntTest, Call_SInt_Vector) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -2210,7 +2211,7 @@ TEST_P(BuiltinIntTest, Call_SInt_Vector) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
TEST_P(BuiltinIntTest, Call_UInt_Scalar) {
@ -2227,7 +2228,7 @@ TEST_P(BuiltinIntTest, Call_UInt_Scalar) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 0
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -2240,7 +2241,7 @@ TEST_P(BuiltinIntTest, Call_UInt_Scalar) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
TEST_P(BuiltinIntTest, Call_UInt_Vector) {
@ -2257,7 +2258,7 @@ TEST_P(BuiltinIntTest, Call_UInt_Vector) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeInt 32 0
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -2271,7 +2272,7 @@ TEST_P(BuiltinIntTest, Call_UInt_Vector) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
INSTANTIATE_TEST_SUITE_P(BuiltinBuilderTest,
BuiltinIntTest,
@ -3279,7 +3280,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_F32) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -3287,7 +3288,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_F32) {
%7 = OpTypeVoid
%6 = OpTypeFunction %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpLoad %3 %1
%12 = OpLoad %3 %1
%10 = OpDot %4 %11 %12
@ -3310,7 +3311,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_F16) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 16
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -3318,7 +3319,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_F16) {
%7 = OpTypeVoid
%6 = OpTypeFunction %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpLoad %3 %1
%12 = OpLoad %3 %1
%10 = OpDot %4 %11 %12
@ -3339,7 +3340,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_U32) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeInt 32 0
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -3347,7 +3348,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_U32) {
%7 = OpTypeVoid
%6 = OpTypeFunction %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpLoad %3 %1
%12 = OpLoad %3 %1
%13 = OpCompositeExtract %4 %11 0
@ -3378,7 +3379,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_I32) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeInt 32 1
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -3386,7 +3387,7 @@ TEST_F(BuiltinBuilderTest, Call_Dot_I32) {
%7 = OpTypeVoid
%6 = OpTypeFunction %7
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%11 = OpLoad %3 %1
%12 = OpLoad %3 %1
%13 = OpCompositeExtract %4 %11 0
@ -3427,7 +3428,7 @@ TEST_P(BuiltinDeriveTest, Call_Derivative_Scalar) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -3440,7 +3441,7 @@ TEST_P(BuiltinDeriveTest, Call_Derivative_Scalar) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
TEST_P(BuiltinDeriveTest, Call_Derivative_Vector) {
@ -3461,12 +3462,12 @@ TEST_P(BuiltinDeriveTest, Call_Derivative_Vector) {
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
if (param.name != "dpdx" && param.name != "dpdy" && param.name != "fwidth") {
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability DerivativeControl
)");
}
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Private %3
%5 = OpConstantNull %3
@ -3480,7 +3481,7 @@ TEST_P(BuiltinDeriveTest, Call_Derivative_Vector) {
OpReturn
)",
"${op}", param.op);
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), expected);
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), expected);
}
INSTANTIATE_TEST_SUITE_P(BuiltinBuilderTest,
BuiltinDeriveTest,
@ -3531,7 +3532,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeInt 32 0
%6 = OpTypeInt 32 1
@ -3546,7 +3547,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) {
%15 = OpTypePointer StorageBuffer %5
%19 = OpTypePointer StorageBuffer %6
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%16 = OpAccessChain %15 %1 %13 %13
@ -3555,7 +3556,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicLoad) {
%17 = OpAtomicLoad %6 %20 %12 %13
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -3597,7 +3598,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicStore) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeInt 32 0
%6 = OpTypeInt 32 1
@ -3617,7 +3618,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicStore) {
%22 = OpTypePointer StorageBuffer %5
%27 = OpTypePointer StorageBuffer %6
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(OpStore %12 %11
@ -3630,7 +3631,7 @@ OpAtomicStore %23 %11 %20 %24
OpAtomicStore %28 %11 %20 %29
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -3668,7 +3669,7 @@ TEST_P(Builtin_Builder_AtomicRMW_i32, Test) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
std::string expected_types = R"(%5 = OpTypeInt 32 1
%4 = OpTypeStruct %5
@ -3685,7 +3686,7 @@ TEST_P(Builtin_Builder_AtomicRMW_i32, Test) {
%17 = OpConstant %15 0
%19 = OpTypePointer StorageBuffer %5
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
std::string expected_instructions = R"(OpStore %11 %10
@ -3695,7 +3696,7 @@ TEST_P(Builtin_Builder_AtomicRMW_i32, Test) {
expected_instructions += "%14 = " + GetParam().op + " %5 %20 %16 %17 %21\n";
expected_instructions += "OpReturn\n";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -3741,7 +3742,7 @@ TEST_P(Builtin_Builder_AtomicRMW_u32, Test) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
std::string expected_types = R"(%5 = OpTypeInt 32 0
%4 = OpTypeStruct %5
@ -3757,7 +3758,7 @@ TEST_P(Builtin_Builder_AtomicRMW_u32, Test) {
%16 = OpConstant %5 0
%18 = OpTypePointer StorageBuffer %5
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
std::string expected_instructions = R"(OpStore %11 %10
@ -3767,7 +3768,7 @@ TEST_P(Builtin_Builder_AtomicRMW_u32, Test) {
expected_instructions += "%14 = " + GetParam().op + " %5 %19 %15 %16 %20\n";
expected_instructions += "OpReturn\n";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -3819,7 +3820,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicExchange) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeInt 32 0
%6 = OpTypeInt 32 1
@ -3840,7 +3841,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicExchange) {
%23 = OpTypePointer StorageBuffer %5
%28 = OpTypePointer StorageBuffer %6
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(OpStore %12 %11
@ -3853,7 +3854,7 @@ OpStore %16 %15
%26 = OpAtomicExchange %6 %29 %20 %21 %30
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -3893,7 +3894,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%5 = OpTypeInt 32 0
%6 = OpTypeInt 32 1
@ -3915,7 +3916,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) {
%28 = OpConstant %6 20
%29 = OpConstant %6 10
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(%18 = OpAccessChain %17 %1 %15 %15
@ -3928,7 +3929,7 @@ TEST_F(BuiltinBuilderTest, Call_AtomicCompareExchangeWeak) {
%23 = OpCompositeConstruct %24 %30 %31
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -4094,7 +4095,7 @@ TEST_F(BuiltinBuilderTest, Call_WorkgroupBarrier) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
@ -4102,13 +4103,13 @@ TEST_F(BuiltinBuilderTest, Call_WorkgroupBarrier) {
%7 = OpConstant %6 2
%8 = OpConstant %6 264
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(OpControlBarrier %7 %7 %8
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);
@ -4128,7 +4129,7 @@ TEST_F(BuiltinBuilderTest, Call_StorageBarrier) {
ASSERT_TRUE(b.Build()) << b.error();
ASSERT_EQ(b.functions().size(), 1_u);
ASSERT_EQ(b.Module().Functions().size(), 1_u);
auto* expected_types = R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
@ -4136,13 +4137,13 @@ TEST_F(BuiltinBuilderTest, Call_StorageBarrier) {
%7 = OpConstant %6 2
%8 = OpConstant %6 72
)";
auto got_types = DumpInstructions(b.types());
auto got_types = DumpInstructions(b.Module().Types());
EXPECT_EQ(expected_types, got_types);
auto* expected_instructions = R"(OpControlBarrier %7 %7 %8
OpReturn
)";
auto got_instructions = DumpInstructions(b.functions()[0].instructions());
auto got_instructions = DumpInstructions(b.Module().Functions()[0].instructions());
EXPECT_EQ(expected_instructions, got_instructions);
Validate(b);

View File

@ -3726,16 +3726,16 @@ TEST_P(BuiltinTextureTest, Call) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(texture)) << b.error();
ASSERT_TRUE(b.GenerateGlobalVariable(sampler)) << b.error();
EXPECT_EQ(b.GenerateExpression(call), 8u) << b.error();
auto expected = expected_texture_overload(param.overload);
EXPECT_EQ(expected.types, "\n" + DumpInstructions(b.types()));
EXPECT_EQ(expected.instructions, "\n" + DumpInstructions(b.functions()[0].instructions()));
EXPECT_EQ(expected.capabilities, "\n" + DumpInstructions(b.capabilities()));
EXPECT_EQ(expected.types, "\n" + DumpInstructions(b.Module().Types()));
EXPECT_EQ(expected.instructions, "\n" + DumpInstructions(b.CurrentFunction().instructions()));
EXPECT_EQ(expected.capabilities, "\n" + DumpInstructions(b.Module().Capabilities()));
}
// Check the SPIRV generated passes validation

View File

@ -30,8 +30,8 @@ TEST_F(BuilderTest, GlobalConstAssert) {
ASSERT_TRUE(b.Build()) << b.error();
// const asserts are not emitted
EXPECT_EQ(DumpInstructions(b.types()), "");
EXPECT_EQ(b.functions().size(), 0u);
EXPECT_EQ(DumpInstructions(b.Module().Types()), "");
EXPECT_EQ(b.Module().Functions().size(), 0u);
}
TEST_F(BuilderTest, FunctionConstAssert) {
@ -42,10 +42,10 @@ TEST_F(BuilderTest, FunctionConstAssert) {
ASSERT_TRUE(b.Build()) << b.error();
// const asserts are not emitted
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
}

File diff suppressed because it is too large Load Diff

View File

@ -28,9 +28,9 @@ TEST_F(BuilderTest, Discard) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateStatement(stmt)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpKill
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()), R"(OpKill
)");
}

View File

@ -333,11 +333,11 @@ TEST_F(BuilderTest, SampleIndex_SampleRateShadingCapability) {
ASSERT_TRUE(b.Build()) << b.error();
// Make sure we generate the SampleRateShading capability.
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability Shader
OpCapability SampleRateShading
)");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 BuiltIn SampleId
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %1 BuiltIn SampleId
OpDecorate %1 Flat
)");
}

View File

@ -39,11 +39,11 @@ TEST_P(ImageFormatConversionTest, ImageFormatConversion) {
EXPECT_EQ(b.convert_texel_format_to_spv(param.ast_format), param.spv_format);
if (param.extended_format) {
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability StorageImageExtendedFormats
)");
} else {
EXPECT_EQ(DumpInstructions(b.capabilities()), "");
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()), "");
}
}

View File

@ -33,7 +33,7 @@ TEST_F(BuilderTest, Attribute_Stage) {
spirv::Builder& b = Build();
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
EXPECT_EQ(DumpInstructions(b.entry_points()),
EXPECT_EQ(DumpInstructions(b.Module().EntryPoints()),
R"(OpEntryPoint Fragment %3 "main"
)");
}
@ -76,7 +76,7 @@ TEST_P(Attribute_StageTest, Emit) {
}
ASSERT_TRUE(b.GenerateFunction(func)) << b.error();
auto preamble = b.entry_points();
auto preamble = b.Module().EntryPoints();
ASSERT_GE(preamble.size(), 1u);
EXPECT_EQ(preamble[0].opcode(), spv::Op::OpEntryPoint);
@ -99,7 +99,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_Fragment_OriginUpperLeft) {
spirv::Builder& b = Build();
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()),
EXPECT_EQ(DumpInstructions(b.Module().ExecutionModes()),
R"(OpExecutionMode %3 OriginUpperLeft
)");
}
@ -111,7 +111,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Default) {
spirv::Builder& b = Build();
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()),
EXPECT_EQ(DumpInstructions(b.Module().ExecutionModes()),
R"(OpExecutionMode %3 LocalSize 1 1 1
)");
}
@ -126,7 +126,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Literals) {
spirv::Builder& b = Build();
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()),
EXPECT_EQ(DumpInstructions(b.Module().ExecutionModes()),
R"(OpExecutionMode %3 LocalSize 2 4 6
)");
}
@ -144,7 +144,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_WorkgroupSize_Const) {
spirv::Builder& b = Build();
ASSERT_TRUE(b.GenerateExecutionModes(func, 3)) << b.error();
EXPECT_EQ(DumpInstructions(b.execution_modes()),
EXPECT_EQ(DumpInstructions(b.Module().ExecutionModes()),
R"(OpExecutionMode %3 LocalSize 2 3 4
)");
}
@ -235,7 +235,7 @@ TEST_F(BuilderTest, Decoration_ExecutionMode_FragDepth) {
ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpInstructions(b.execution_modes()),
EXPECT_EQ(DumpInstructions(b.Module().ExecutionModes()),
R"(OpExecutionMode %11 OriginUpperLeft
OpExecutionMode %11 DepthReplacing
)");

View File

@ -161,7 +161,7 @@ TEST_F(BuilderTest, FunctionType) {
auto* func = program->AST().Functions()[0];
ASSERT_TRUE(b.GenerateFunction(func));
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
)");
}
@ -174,7 +174,7 @@ TEST_F(BuilderTest, FunctionType_DeDuplicate) {
ASSERT_TRUE(b.GenerateFunction(func1));
ASSERT_TRUE(b.GenerateFunction(func2));
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
)");
}

View File

@ -28,16 +28,16 @@ TEST_F(BuilderTest, FunctionVar_NoAddressSpace) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3
%4 = OpConstantNull %3
)");
const auto& func = b.functions()[0];
const auto& func = b.CurrentFunction();
EXPECT_EQ(DumpInstructions(func.variables()),
R"(%1 = OpVariable %2 Function %4
)");
@ -50,13 +50,13 @@ TEST_F(BuilderTest, FunctionVar_WithConstantInitializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %6 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 3
@ -64,10 +64,10 @@ TEST_F(BuilderTest, FunctionVar_WithConstantInitializer) {
%7 = OpTypePointer Function %1
%8 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%6 = OpVariable %7 Function %8
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %6 %5
)");
}
@ -81,24 +81,24 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantInitializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(a)) << b.error();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %7 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %7 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 3
%3 = OpTypeVector %1 2
%4 = OpConstant %1 1
%8 = OpTypePointer Function %3
%9 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%7 = OpVariable %8 Function %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%5 = OpFAdd %1 %2 %2
%6 = OpCompositeConstruct %3 %4 %5
OpStore %7 %6
@ -116,24 +116,24 @@ TEST_F(BuilderTest, FunctionVar_WithNonConstantInitializerLoadedFromVar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "v"
OpName %7 "v2"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1
%4 = OpTypePointer Function %1
%5 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%3 = OpVariable %4 Function %5
%7 = OpVariable %4 Function %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %3 %2
%6 = OpLoad %1 %3
OpStore %7 %6
@ -151,24 +151,24 @@ TEST_F(BuilderTest, FunctionVar_LetWithVarInitializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "v"
OpName %7 "v2"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1
%4 = OpTypePointer Function %1
%5 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%3 = OpVariable %4 Function %5
%7 = OpVariable %4 Function %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %3 %2
%6 = OpLoad %1 %3
OpStore %7 %6
@ -186,22 +186,22 @@ TEST_F(BuilderTest, FunctionVar_ConstWithVarInitializer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_TRUE(b.GenerateFunctionVariable(v2)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "v2"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "v2"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 1
%4 = OpTypePointer Function %1
%5 = OpConstantNull %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%3 = OpVariable %4 Function %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpStore %3 %2
)");
}
@ -218,7 +218,7 @@ TEST_F(BuilderTest, FunctionVar_Let) {
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 3
@ -238,7 +238,7 @@ TEST_F(BuilderTest, FunctionVar_Const) {
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), ""); // Not a mistake - 'const' is inlined
EXPECT_EQ(DumpInstructions(b.Module().Types()), ""); // Not a mistake - 'const' is inlined
}
} // namespace

View File

@ -31,9 +31,9 @@ TEST_F(BuilderTest, GlobalVar_WithAddressSpace) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -50,9 +50,9 @@ TEST_F(BuilderTest, GlobalVar_WithInitializer) {
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %6 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %6 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 3
@ -73,15 +73,15 @@ TEST_F(BuilderTest, GlobalConst) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 42
%4 = OpTypePointer Private %1
%3 = OpVariable %4 Private %2
%6 = OpTypeVoid
%5 = OpTypeFunction %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -98,7 +98,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_Initializer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 2
@ -109,8 +109,8 @@ TEST_F(BuilderTest, GlobalConst_Vec_Initializer) {
%10 = OpTypeVoid
%9 = OpTypeFunction %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -128,7 +128,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_F16_Initializer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 16
%1 = OpTypeVector %2 3
%3 = OpConstant %2 0x1p+0
%4 = OpConstant %2 0x1p+1
@ -139,8 +139,8 @@ TEST_F(BuilderTest, GlobalConst_Vec_F16_Initializer) {
%10 = OpTypeVoid
%9 = OpTypeFunction %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -157,7 +157,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_AInt_Initializer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 2
@ -168,8 +168,8 @@ TEST_F(BuilderTest, GlobalConst_Vec_AInt_Initializer) {
%10 = OpTypeVoid
%9 = OpTypeFunction %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -186,7 +186,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_AFloat_Initializer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 2
@ -197,8 +197,8 @@ TEST_F(BuilderTest, GlobalConst_Vec_AFloat_Initializer) {
%10 = OpTypeVoid
%9 = OpTypeFunction %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -215,7 +215,7 @@ TEST_F(BuilderTest, GlobalConst_Nested_Vec_Initializer) {
ASSERT_TRUE(b.Build()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 2
@ -226,8 +226,8 @@ TEST_F(BuilderTest, GlobalConst_Nested_Vec_Initializer) {
%10 = OpTypeVoid
%9 = OpTypeFunction %10
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].variables()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()), R"(OpReturn
)");
Validate(b);
@ -239,12 +239,12 @@ TEST_F(BuilderTest, GlobalVar_WithBindingAndGroup) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "var"
)");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 Binding 2
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %1 Binding 2
OpDecorate %1 DescriptorSet 3
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeSampler
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeSampler
%2 = OpTypePointer UniformConstant %3
%1 = OpVariable %2 UniformConstant
)");
@ -324,7 +324,7 @@ TEST_F(BuilderTest, GlobalVar_DeclReadOnly) {
ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %3 Block
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0
OpMemberDecorate %4 0 Offset 0
OpMemberDecorate %4 1 Offset 4
@ -332,7 +332,7 @@ OpDecorate %1 NonWritable
OpDecorate %1 Binding 0
OpDecorate %1 DescriptorSet 0
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "b_block"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "b_block"
OpMemberName %3 0 "inner"
OpName %4 "A"
OpMemberName %4 0 "a"
@ -340,7 +340,7 @@ OpMemberName %4 1 "b"
OpName %1 "b"
OpName %8 "unused_entry_point"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeInt 32 1
%4 = OpTypeStruct %5 %5
%3 = OpTypeStruct %4
%2 = OpTypePointer StorageBuffer %3
@ -366,21 +366,21 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) {
ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %3 Block
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0
OpMemberDecorate %4 0 Offset 0
OpDecorate %1 NonWritable
OpDecorate %1 Binding 0
OpDecorate %1 DescriptorSet 0
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "b_block"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "b_block"
OpMemberName %3 0 "inner"
OpName %4 "A"
OpMemberName %4 0 "a"
OpName %1 "b"
OpName %8 "unused_entry_point"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeInt 32 1
%4 = OpTypeStruct %5
%3 = OpTypeStruct %4
%2 = OpTypePointer StorageBuffer %3
@ -406,21 +406,21 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) {
ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %3 Block
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0
OpMemberDecorate %4 0 Offset 0
OpDecorate %1 NonWritable
OpDecorate %1 Binding 0
OpDecorate %1 DescriptorSet 0
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "b_block"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "b_block"
OpMemberName %3 0 "inner"
OpName %4 "A"
OpMemberName %4 0 "a"
OpName %1 "b"
OpName %8 "unused_entry_point"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeInt 32 1
%4 = OpTypeStruct %5
%3 = OpTypeStruct %4
%2 = OpTypePointer StorageBuffer %3
@ -447,7 +447,7 @@ TEST_F(BuilderTest, GlobalVar_TwoVarDeclReadOnly) {
ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpInstructions(b.annots()),
EXPECT_EQ(DumpInstructions(b.Module().Annots()),
R"(OpDecorate %3 Block
OpMemberDecorate %3 0 Offset 0
OpMemberDecorate %4 0 Offset 0
@ -457,7 +457,7 @@ OpDecorate %1 Binding 0
OpDecorate %6 DescriptorSet 1
OpDecorate %6 Binding 0
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %3 "b_block"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %3 "b_block"
OpMemberName %3 0 "inner"
OpName %4 "A"
OpMemberName %4 0 "a"
@ -465,7 +465,7 @@ OpName %1 "b"
OpName %6 "c"
OpName %9 "unused_entry_point"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeInt 32 1
%4 = OpTypeStruct %5
%3 = OpTypeStruct %4
%2 = OpTypePointer StorageBuffer %3
@ -488,11 +488,11 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) {
EXPECT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error();
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 NonReadable
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %1 NonReadable
OpDecorate %1 Binding 0
OpDecorate %1 DescriptorSet 0
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeInt 32 0
%3 = OpTypeImage %4 2D 0 0 0 2 R32ui
%2 = OpTypePointer UniformConstant %3
%1 = OpVariable %2 UniformConstant
@ -523,7 +523,7 @@ TEST_F(BuilderTest, GlobalVar_WorkgroupWithZeroInit) {
EXPECT_TRUE(b->GenerateGlobalVariable(var_struct)) << b->error();
ASSERT_FALSE(b->has_error()) << b->error();
EXPECT_EQ(DumpInstructions(b->types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b->Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Workgroup %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Workgroup %4

View File

@ -35,7 +35,7 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalConst) {
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"()");
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"()");
EXPECT_EQ(b.GenerateIdentifierExpression(expr), 0u);
}
@ -48,11 +48,11 @@ TEST_F(BuilderTest, IdentifierExpression_GlobalVar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateGlobalVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -74,7 +74,7 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionConst) {
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 3
@ -91,16 +91,16 @@ TEST_F(BuilderTest, IdentifierExpression_FunctionVar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(v)) << b.error();
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "var"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "var"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3
%4 = OpConstantNull %3
)");
const auto& func = b.functions()[0];
const auto& func = b.CurrentFunction();
EXPECT_EQ(DumpInstructions(func.variables()),
R"(%1 = OpVariable %2 Function %4
)");
@ -115,16 +115,16 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr->As<ast::BinaryExpression>()), 7u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%5 = OpLoad %3 %1
%6 = OpLoad %3 %1
%7 = OpIAdd %3 %5 %6
@ -138,14 +138,14 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateFunctionVariable(let)) << b.error();
EXPECT_EQ(b.GenerateBinaryExpression(expr->As<ast::BinaryExpression>()), 3u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%3 = OpIAdd %1 %2 %2
)");
}

View File

@ -30,13 +30,13 @@ TEST_F(BuilderTest, If_Empty) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %3 None
OpBranchConditional %2 %4 %3
%4 = OpLabel
@ -75,11 +75,11 @@ TEST_F(BuilderTest, If_WithStatements) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -87,7 +87,7 @@ TEST_F(BuilderTest, If_WithStatements) {
%6 = OpConstantTrue %5
%9 = OpConstant %3 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %7
%8 = OpLabel
@ -113,11 +113,11 @@ TEST_F(BuilderTest, If_WithElse) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -126,7 +126,7 @@ TEST_F(BuilderTest, If_WithElse) {
%10 = OpConstant %3 2
%11 = OpConstant %3 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %9
%8 = OpLabel
@ -155,11 +155,11 @@ TEST_F(BuilderTest, If_WithElseIf) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -168,7 +168,7 @@ TEST_F(BuilderTest, If_WithElseIf) {
%10 = OpConstant %3 2
%13 = OpConstant %3 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %9
%8 = OpLabel
@ -211,11 +211,11 @@ TEST_F(BuilderTest, If_WithMultiple) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateIfStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
@ -227,7 +227,7 @@ TEST_F(BuilderTest, If_WithMultiple) {
%19 = OpConstant %3 4
%20 = OpConstant %3 5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %9
%8 = OpLabel
@ -274,13 +274,13 @@ TEST_F(BuilderTest, If_WithBreak) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -316,13 +316,13 @@ TEST_F(BuilderTest, If_WithElseBreak) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -358,13 +358,13 @@ TEST_F(BuilderTest, If_WithContinueAndBreak) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -403,13 +403,13 @@ TEST_F(BuilderTest, If_WithElseContinue) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -442,12 +442,12 @@ TEST_F(BuilderTest, If_WithReturn) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %7
%8 = OpLabel
@ -472,12 +472,12 @@ TEST_F(BuilderTest, If_WithReturnValue) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%1 = OpTypeFunction %2
%5 = OpConstantTrue %2
%8 = OpConstantNull %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpSelectionMerge %6 None
OpBranchConditional %5 %7 %6
%7 = OpLabel
@ -504,12 +504,12 @@ TEST_F(BuilderTest, IfElse_BothReturn) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%1 = OpTypeFunction %2
%5 = OpConstantTrue %2
%9 = OpConstantNull %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpSelectionMerge %6 None
OpBranchConditional %5 %7 %8
%7 = OpLabel
@ -542,12 +542,12 @@ TEST_F(BuilderTest, If_WithNestedBlockReturnValue) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%1 = OpTypeFunction %2
%5 = OpConstantTrue %2
%8 = OpConstantNull %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpSelectionMerge %6 None
OpBranchConditional %5 %7 %6
%7 = OpLabel
@ -572,14 +572,14 @@ TEST_F(BuilderTest, If_WithLoad_Bug327) {
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeBool
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
%6 = OpTypeVoid
%5 = OpTypeFunction %6
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(%9 = OpLoad %3 %1
OpSelectionMerge %10 None
OpBranchConditional %9 %11 %10
@ -603,13 +603,13 @@ TEST_F(BuilderTest, If_ElseIf_WithReturn) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%5 = OpTypeBool
%6 = OpConstantNull %5
%10 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpSelectionMerge %7 None
OpBranchConditional %6 %8 %9
%8 = OpLabel
@ -644,13 +644,13 @@ TEST_F(BuilderTest, Loop_If_ElseIf_WithBreak) {
spirv::Builder& b = Build();
EXPECT_TRUE(b.GenerateFunction(fn)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeVoid
%1 = OpTypeFunction %2
%9 = OpTypeBool
%10 = OpConstantNull %9
%14 = OpConstantTrue %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.Module().Functions()[0].instructions()),
R"(OpBranch %5
%5 = OpLabel
OpLoopMerge %6 %7 None

View File

@ -31,7 +31,7 @@ TEST_F(BuilderTest, Literal_Bool_True) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
)");
}
@ -46,7 +46,7 @@ TEST_F(BuilderTest, Literal_Bool_False) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantFalse %1
)");
}
@ -65,7 +65,7 @@ TEST_F(BuilderTest, Literal_Bool_Dedup) {
ASSERT_NE(b.GenerateLiteralIfNeeded(b_true), 0u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeBool
%2 = OpConstantTrue %1
%3 = OpConstantFalse %1
)");
@ -80,7 +80,7 @@ TEST_F(BuilderTest, Literal_I32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 -23
)");
}
@ -96,7 +96,7 @@ TEST_F(BuilderTest, Literal_I32_Dedup) {
ASSERT_NE(b.GenerateLiteralIfNeeded(i2), 0u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 1
%2 = OpConstant %1 -23
)");
}
@ -111,7 +111,7 @@ TEST_F(BuilderTest, Literal_U32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 0
%2 = OpConstant %1 23
)");
}
@ -127,7 +127,7 @@ TEST_F(BuilderTest, Literal_U32_Dedup) {
ASSERT_NE(b.GenerateLiteralIfNeeded(i2), 0u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeInt 32 0
%2 = OpConstant %1 23
)");
}
@ -142,7 +142,7 @@ TEST_F(BuilderTest, Literal_F32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 23.2450008
)");
}
@ -158,7 +158,7 @@ TEST_F(BuilderTest, Literal_F32_Dedup) {
ASSERT_NE(b.GenerateLiteralIfNeeded(i2), 0u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 32
%2 = OpConstant %1 23.2450008
)");
}
@ -175,7 +175,7 @@ TEST_F(BuilderTest, Literal_F16) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(2u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 16
%2 = OpConstant %1 0x1.73cp+4
)");
}
@ -193,7 +193,7 @@ TEST_F(BuilderTest, Literal_F16_Dedup) {
ASSERT_NE(b.GenerateLiteralIfNeeded(i2), 0u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeFloat 16
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%1 = OpTypeFloat 16
%2 = OpConstant %1 0x1.73cp+4
)");
}

View File

@ -32,10 +32,10 @@ TEST_F(BuilderTest, Loop_Empty) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -63,17 +63,17 @@ TEST_F(BuilderTest, Loop_WithoutContinuing) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
%9 = OpConstant %3 2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %5
%5 = OpLabel
OpLoopMerge %6 %7 None
@ -106,18 +106,18 @@ TEST_F(BuilderTest, Loop_WithContinuing) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
ASSERT_TRUE(b.GenerateGlobalVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeInt 32 1
%2 = OpTypePointer Private %3
%4 = OpConstantNull %3
%1 = OpVariable %2 Private %4
%9 = OpConstant %3 2
%10 = OpConstant %3 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %5
%5 = OpLabel
OpLoopMerge %6 %7 None
@ -150,15 +150,15 @@ TEST_F(BuilderTest, Loop_WithBodyVariableAccessInContinuing) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%7 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%7 = OpTypeInt 32 1
%6 = OpTypePointer Function %7
%8 = OpConstantNull %7
%9 = OpConstant %7 3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -184,10 +184,10 @@ TEST_F(BuilderTest, Loop_WithContinue) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -215,10 +215,10 @@ TEST_F(BuilderTest, Loop_WithBreak) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -244,13 +244,13 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakIf) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -275,13 +275,13 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakUnless) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -309,15 +309,15 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakIf_ConditionIsVar) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeBool
%6 = OpConstantTrue %5
%8 = OpTypePointer Function %5
%9 = OpConstantNull %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None
@ -355,13 +355,13 @@ TEST_F(BuilderTest, Loop_WithContinuing_BreakIf_Nested) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateLoopStatement(outer_loop)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%9 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%9 = OpTypeBool
%10 = OpConstantTrue %9
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpBranch %1
%1 = OpLabel
OpLoopMerge %2 %3 None

View File

@ -28,11 +28,11 @@ TEST_F(BuilderTest, Return) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateReturnStatement(ret));
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpReturn
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()), R"(OpReturn
)");
}
@ -44,17 +44,17 @@ TEST_F(BuilderTest, Return_WithValue) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateReturnStatement(ret));
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
%3 = OpConstant %2 1
%4 = OpConstant %2 3
%5 = OpConstantComposite %1 %3 %3 %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpReturnValue %5
)");
}
@ -67,19 +67,19 @@ TEST_F(BuilderTest, Return_WithValue_GeneratesLoad) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_TRUE(b.GenerateReturnStatement(ret)) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypePointer Function %3
%4 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%1 = OpVariable %2 Function %4
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%5 = OpLoad %3 %1
OpReturnValue %5
)");

View File

@ -32,13 +32,13 @@ TEST_F(BuilderTest, Switch_Empty) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateSwitchStatement(expr)) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpConstant %2 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(OpSelectionMerge %1 None
OpSwitch %3 %4
%4 = OpLabel

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/writer/spirv/spv_dump.h"
#include "src/tint/writer/spirv/test_helper.h"
namespace tint::writer::spirv {
@ -38,33 +37,5 @@ TEST_F(BuilderTest, UnsupportedExtension) {
R"(12:34 error: SPIR-V backend does not support extension 'undefined')");
}
TEST_F(BuilderTest, TracksIdBounds) {
spirv::Builder& b = Build();
for (size_t i = 0; i < 5; i++) {
EXPECT_EQ(b.next_id(), i + 1);
}
EXPECT_EQ(6u, b.id_bound());
}
TEST_F(BuilderTest, Capabilities_Dedup) {
spirv::Builder& b = Build();
b.push_capability(SpvCapabilityShader);
b.push_capability(SpvCapabilityShader);
b.push_capability(SpvCapabilityShader);
EXPECT_EQ(DumpInstructions(b.capabilities()), "OpCapability Shader\n");
}
TEST_F(BuilderTest, DeclareExtension) {
spirv::Builder& b = Build();
b.push_extension("SPV_KHR_integer_dot_product");
EXPECT_EQ(DumpInstructions(b.extensions()), "OpExtension \"SPV_KHR_integer_dot_product\"\n");
}
} // namespace
} // namespace tint::writer::spirv

View File

@ -39,7 +39,7 @@ TEST_F(BuilderTest_Type, GenerateRuntimeArray) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeRuntimeArray %2
)");
}
@ -57,7 +57,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(type)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeRuntimeArray %2
)");
}
@ -72,7 +72,7 @@ TEST_F(BuilderTest_Type, GenerateArray) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpTypeInt 32 0
%4 = OpConstant %3 4
%1 = OpTypeArray %2 %4
@ -89,10 +89,10 @@ TEST_F(BuilderTest_Type, GenerateArray_WithStride) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id);
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 ArrayStride 16
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpDecorate %1 ArrayStride 16
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpTypeInt 32 0
%4 = OpConstant %3 4
%1 = OpTypeArray %2 %4
@ -109,7 +109,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedArray) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpTypeInt 32 0
%4 = OpConstant %3 4
%1 = OpTypeArray %2 %4
@ -125,8 +125,8 @@ TEST_F(BuilderTest_Type, GenerateBool) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeBool
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeBool
)");
}
@ -153,8 +153,8 @@ TEST_F(BuilderTest_Type, GenerateF32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeFloat 32
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeFloat 32
)");
}
@ -181,8 +181,8 @@ TEST_F(BuilderTest_Type, GenerateF16) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeFloat 16
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeFloat 16
)");
}
@ -209,8 +209,8 @@ TEST_F(BuilderTest_Type, GenerateI32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeInt 32 1
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeInt 32 1
)");
}
@ -239,8 +239,8 @@ TEST_F(BuilderTest_Type, GenerateMatrix) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 3u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32
EXPECT_EQ(b.Module().Types().size(), 3u);
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 32
%2 = OpTypeVector %3 3
%1 = OpTypeMatrix %2 2
)");
@ -272,8 +272,8 @@ TEST_F(BuilderTest_Type, GenerateF16Matrix) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 3u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 16
EXPECT_EQ(b.Module().Types().size(), 3u);
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%3 = OpTypeFloat 16
%2 = OpTypeVector %3 3
%1 = OpTypeMatrix %2 2
)");
@ -305,7 +305,7 @@ TEST_F(BuilderTest_Type, GeneratePtr) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypePointer Output %2
)");
}
@ -332,11 +332,11 @@ TEST_F(BuilderTest_Type, GenerateStruct) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%3 = OpTypeFloat 16
%1 = OpTypeStruct %2 %3
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "my_struct"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "my_struct"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b"
)");
@ -358,17 +358,17 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%3 = OpTypeFloat 16
%1 = OpTypeStruct %2 %2 %3 %3
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "S"
OpMemberName %1 0 "a"
OpMemberName %1 1 "b"
OpMemberName %1 2 "c"
OpMemberName %1 3 "d"
)");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 1 Offset 8
OpMemberDecorate %1 2 Offset 16
OpMemberDecorate %1 3 Offset 18
@ -394,7 +394,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_Matrix) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 2
%2 = OpTypeMatrix %3 2
%6 = OpTypeVector %4 3
@ -410,7 +410,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_Matrix) {
%14 = OpTypeMatrix %15 4
%1 = OpTypeStruct %2 %5 %7 %9 %12 %14
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "S"
OpMemberName %1 0 "mat2x2_f32"
OpMemberName %1 1 "mat2x3_f32"
OpMemberName %1 2 "mat4x4_f32"
@ -418,7 +418,7 @@ OpMemberName %1 3 "mat2x2_f16"
OpMemberName %1 4 "mat2x3_f16"
OpMemberName %1 5 "mat4x4_f16"
)");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor
OpMemberDecorate %1 0 MatrixStride 8
OpMemberDecorate %1 1 Offset 64
@ -465,7 +465,7 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_ArraysOfMatrix) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%5 = OpTypeFloat 32
%4 = OpTypeVector %5 2
%3 = OpTypeMatrix %4 2
%6 = OpTypeInt 32 0
@ -489,14 +489,14 @@ TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_ArraysOfMatrix) {
%21 = OpTypeRuntimeArray %22
%1 = OpTypeStruct %2 %8 %12 %17 %21
)");
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
EXPECT_EQ(DumpInstructions(b.Module().Debug()), R"(OpName %1 "S"
OpMemberName %1 0 "arr_mat2x2_f32"
OpMemberName %1 1 "arr_mat2x2_f16"
OpMemberName %1 2 "arr_arr_mat2x3_f32"
OpMemberName %1 3 "arr_arr_mat2x3_f16"
OpMemberName %1 4 "rtarr_mat4x4"
)");
EXPECT_EQ(DumpInstructions(b.annots()), R"(OpMemberDecorate %1 0 Offset 0
EXPECT_EQ(DumpInstructions(b.Module().Annots()), R"(OpMemberDecorate %1 0 Offset 0
OpMemberDecorate %1 0 ColMajor
OpMemberDecorate %1 0 MatrixStride 8
OpDecorate %2 ArrayStride 16
@ -530,8 +530,8 @@ TEST_F(BuilderTest_Type, GenerateU32) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeInt 32 0
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeInt 32 0
)");
}
@ -558,8 +558,8 @@ TEST_F(BuilderTest_Type, GenerateVector) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 2u);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(b.Module().Types().size(), 2u);
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeVector %2 3
)");
}
@ -587,8 +587,8 @@ TEST_F(BuilderTest_Type, GenerateVoid) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
ASSERT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.types()[0]), R"(%1 = OpTypeVoid
ASSERT_EQ(b.Module().Types().size(), 1u);
EXPECT_EQ(DumpInstruction(b.Module().Types()[0]), R"(%1 = OpTypeVoid
)");
}
@ -646,7 +646,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2d) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id_two_d);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 1 Unknown
)");
}
@ -660,7 +660,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2dArray) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id_two_d_array);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 1 Unknown
)");
}
@ -674,10 +674,10 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_Cube) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id_cube);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 Cube 0 0 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()), "");
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()), "");
}
TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) {
@ -689,10 +689,10 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) {
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(1u, id_cube_array);
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 Cube 0 1 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability SampledCubeArray
)");
}
@ -705,7 +705,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_i32) {
EXPECT_EQ(1u, b.GenerateTypeIfNeeded(ms));
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 2D 0 0 1 1 Unknown
)");
}
@ -718,7 +718,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_u32) {
EXPECT_EQ(b.GenerateTypeIfNeeded(ms), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 2D 0 0 1 1 Unknown
)");
@ -732,7 +732,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) {
EXPECT_EQ(b.GenerateTypeIfNeeded(ms), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 1 1 Unknown
)");
@ -745,12 +745,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 1D 0 0 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability Sampled1D
)");
}
@ -763,12 +763,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 1D 0 0 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability Sampled1D
)");
}
@ -781,12 +781,12 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability Sampled1D
)");
}
@ -799,7 +799,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 1 Unknown
)");
@ -813,7 +813,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 1 Unknown
)");
@ -827,7 +827,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 3D 0 0 0 1 Unknown
)");
@ -841,11 +841,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 Cube 0 0 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()), "");
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()), "");
}
TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
@ -856,11 +856,11 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) {
EXPECT_EQ(b.GenerateTypeIfNeeded(s), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()),
EXPECT_EQ(DumpInstructions(b.Module().Types()),
R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 Cube 0 1 0 1 Unknown
)");
EXPECT_EQ(DumpInstructions(b.capabilities()),
EXPECT_EQ(DumpInstructions(b.Module().Capabilities()),
R"(OpCapability SampledCubeArray
)");
}
@ -875,7 +875,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 1D 0 0 0 2 R32f
)");
}
@ -890,7 +890,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
)");
}
@ -905,7 +905,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 1 0 2 R32f
)");
}
@ -920,7 +920,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) {
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 3D 0 0 0 2 R32f
)");
}
@ -935,7 +935,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32floa
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%1 = OpTypeImage %2 2D 0 0 0 2 R32f
)");
}
@ -950,7 +950,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint)
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%1 = OpTypeImage %2 2D 0 0 0 2 R32i
)");
}
@ -965,7 +965,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint)
EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 0
%1 = OpTypeImage %2 2D 0 0 0 2 R32ui
)");
}
@ -977,7 +977,7 @@ TEST_F(BuilderTest_Type, Sampler) {
EXPECT_EQ(b.GenerateTypeIfNeeded(sampler), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n");
EXPECT_EQ(DumpInstructions(b.Module().Types()), "%1 = OpTypeSampler\n");
}
TEST_F(BuilderTest_Type, ComparisonSampler) {
@ -987,7 +987,7 @@ TEST_F(BuilderTest_Type, ComparisonSampler) {
EXPECT_EQ(b.GenerateTypeIfNeeded(sampler), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n");
EXPECT_EQ(DumpInstructions(b.Module().Types()), "%1 = OpTypeSampler\n");
}
TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) {
@ -1001,7 +1001,7 @@ TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) {
EXPECT_EQ(b.GenerateTypeIfNeeded(sampler), 1u);
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n");
EXPECT_EQ(DumpInstructions(b.Module().Types()), "%1 = OpTypeSampler\n");
}
} // namespace

View File

@ -28,12 +28,12 @@ TEST_F(BuilderTest, UnaryOp_Negation_Integer) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpConstant %2 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpSNegate %2 %3
)");
}
@ -44,12 +44,12 @@ TEST_F(BuilderTest, UnaryOp_Negation_Float) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeFloat 32
%3 = OpConstant %2 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpFNegate %2 %3
)");
}
@ -60,12 +60,12 @@ TEST_F(BuilderTest, UnaryOp_Complement) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeInt 32 1
%3 = OpConstant %2 1
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpNot %2 %3
)");
}
@ -76,12 +76,12 @@ TEST_F(BuilderTest, UnaryOp_Not) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 1u) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeBool
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%2 = OpTypeBool
%3 = OpConstantNull %2
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%1 = OpLogicalNot %2 %3
)");
}
@ -94,20 +94,20 @@ TEST_F(BuilderTest, UnaryOp_LoadRequired) {
spirv::Builder& b = Build();
b.push_function(Function{});
b.PushFunctionForTesting();
EXPECT_TRUE(b.GenerateFunctionVariable(var)) << b.error();
EXPECT_EQ(b.GenerateUnaryOpExpression(expr), 6u) << b.error();
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32
EXPECT_EQ(DumpInstructions(b.Module().Types()), R"(%4 = OpTypeFloat 32
%3 = OpTypeVector %4 3
%2 = OpTypePointer Function %3
%5 = OpConstantNull %3
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].variables()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().variables()),
R"(%1 = OpVariable %2 Function %5
)");
EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()),
EXPECT_EQ(DumpInstructions(b.CurrentFunction().instructions()),
R"(%7 = OpLoad %3 %1
%6 = OpFNegate %3 %7
)");

View File

@ -25,6 +25,8 @@ Function::Function(const Instruction& declaration,
Function::Function(const Function& other) = default;
Function& Function::operator=(const Function& other) = default;
Function::~Function() = default;
void Function::iterate(std::function<void(const Instruction&)> cb) const {

View File

@ -38,6 +38,11 @@ class Function {
/// Copy constructor
/// @param other the function to copy
Function(const Function& other);
/// Copy assignment operator
/// @param other the function to copy
/// @returns the new Function
Function& operator=(const Function& other);
/// Destructor
~Function();
/// Iterates over the function call the cb on each instruction
@ -84,6 +89,9 @@ class Function {
return size;
}
/// @returns true if the function has a valid declaration
explicit operator bool() const { return declaration_.opcode() == spv::Op::OpFunction; }
private:
Instruction declaration_;
Operand label_op_;

View File

@ -175,8 +175,9 @@ GeneratorImpl::GeneratorImpl(const Program* program, bool zero_initialize_workgr
bool GeneratorImpl::Generate() {
if (builder_.Build()) {
writer_.WriteHeader(builder_.id_bound());
writer_.WriteBuilder(&builder_);
auto& module = builder_.Module();
writer_.WriteHeader(module.IdBound());
writer_.WriteModule(&module);
return true;
}
return false;

View File

@ -23,6 +23,8 @@ Instruction::Instruction(spv::Op op, OperandList operands)
Instruction::Instruction(const Instruction&) = default;
Instruction& Instruction::operator=(const Instruction&) = default;
Instruction::~Instruction() = default;
uint32_t Instruction::word_length() const {

View File

@ -31,6 +31,11 @@ class Instruction {
Instruction(spv::Op op, OperandList operands);
/// Copy Constructor
Instruction(const Instruction&);
/// Copy assignment operator
/// @param other the instruction to copy
/// @returns the new Instruction
Instruction& operator=(const Instruction& other);
/// Destructor
~Instruction();
/// @returns the instructions op

View File

@ -0,0 +1,101 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/writer/spirv/module.h"
namespace tint::writer::spirv {
namespace {
/// Helper to return the size in words of an instruction list when serialized.
/// @param instructions the instruction list
/// @returns the number of words needed to serialize the list
uint32_t SizeOf(const InstructionList& instructions) {
uint32_t size = 0;
for (const auto& inst : instructions) {
size += inst.word_length();
}
return size;
}
} // namespace
Module::Module() {}
Module::~Module() = default;
uint32_t Module::TotalSize() const {
// The 5 covers the magic, version, generator, id bound and reserved.
uint32_t size = 5;
size += SizeOf(capabilities_);
size += SizeOf(extensions_);
size += SizeOf(ext_imports_);
size += SizeOf(memory_model_);
size += SizeOf(entry_points_);
size += SizeOf(execution_modes_);
size += SizeOf(debug_);
size += SizeOf(annotations_);
size += SizeOf(types_);
for (const auto& func : functions_) {
size += func.word_length();
}
return size;
}
void Module::Iterate(std::function<void(const Instruction&)> cb) const {
for (const auto& inst : capabilities_) {
cb(inst);
}
for (const auto& inst : extensions_) {
cb(inst);
}
for (const auto& inst : ext_imports_) {
cb(inst);
}
for (const auto& inst : memory_model_) {
cb(inst);
}
for (const auto& inst : entry_points_) {
cb(inst);
}
for (const auto& inst : execution_modes_) {
cb(inst);
}
for (const auto& inst : debug_) {
cb(inst);
}
for (const auto& inst : annotations_) {
cb(inst);
}
for (const auto& inst : types_) {
cb(inst);
}
for (const auto& func : functions_) {
func.iterate(cb);
}
}
void Module::PushCapability(uint32_t cap) {
if (capability_set_.count(cap) == 0) {
capability_set_.insert(cap);
capabilities_.push_back(Instruction{spv::Op::OpCapability, {Operand(cap)}});
}
}
void Module::PushExtension(const char* extension) {
extensions_.push_back(Instruction{spv::Op::OpExtension, {Operand(extension)}});
}
} // namespace tint::writer::spirv

View File

@ -0,0 +1,161 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_WRITER_SPIRV_MODULE_H_
#define SRC_TINT_WRITER_SPIRV_MODULE_H_
#include <cstdint>
#include <functional>
#include <unordered_set>
#include <vector>
#include "src/tint/writer/spirv/function.h"
#include "src/tint/writer/spirv/instruction.h"
namespace tint::writer::spirv {
/// A SPIR-V module.
class Module {
public:
/// Constructor
Module();
/// Destructor
~Module();
/// @returns the number of uint32_t's needed to make up the results
uint32_t TotalSize() const;
/// @returns the id bound for this program
uint32_t IdBound() const { return next_id_; }
/// @returns the next id to be used
uint32_t NextId() {
auto id = next_id_;
next_id_ += 1;
return id;
}
/// Iterates over all the instructions in the correct order and calls the given callback.
/// @param cb the callback to execute
void Iterate(std::function<void(const Instruction&)> cb) const;
/// Add an instruction to the list of capabilities, if the capability hasn't already been added.
/// @param cap the capability to set
void PushCapability(uint32_t cap);
/// @returns the capabilities
const InstructionList& Capabilities() const { return capabilities_; }
/// Add an instruction to the list of extensions.
/// @param extension the name of the extension
void PushExtension(const char* extension);
/// @returns the extensions
const InstructionList& Extensions() const { return extensions_; }
/// Add an instruction to the list of imported extension instructions.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushExtImport(spv::Op op, const OperandList& operands) {
ext_imports_.push_back(Instruction{op, operands});
}
/// @returns the ext imports
const InstructionList& ExtImports() const { return ext_imports_; }
/// Add an instruction to the memory model.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushMemoryModel(spv::Op op, const OperandList& operands) {
memory_model_.push_back(Instruction{op, operands});
}
/// @returns the memory model
const InstructionList& MemoryModel() const { return memory_model_; }
/// Add an instruction to the list pf entry points.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushEntryPoint(spv::Op op, const OperandList& operands) {
entry_points_.push_back(Instruction{op, operands});
}
/// @returns the entry points
const InstructionList& EntryPoints() const { return entry_points_; }
/// Add an instruction to the execution mode declarations.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushExecutionMode(spv::Op op, const OperandList& operands) {
execution_modes_.push_back(Instruction{op, operands});
}
/// @returns the execution modes
const InstructionList& ExecutionModes() const { return execution_modes_; }
/// Add an instruction to the debug declarations.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushDebug(spv::Op op, const OperandList& operands) {
debug_.push_back(Instruction{op, operands});
}
/// @returns the debug instructions
const InstructionList& Debug() const { return debug_; }
/// Add an instruction to the type declarations.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushType(spv::Op op, const OperandList& operands) {
types_.push_back(Instruction{op, operands});
}
/// @returns the type instructions
const InstructionList& Types() const { return types_; }
/// Add an instruction to the annotations.
/// @param op the op to set
/// @param operands the operands for the instruction
void PushAnnot(spv::Op op, const OperandList& operands) {
annotations_.push_back(Instruction{op, operands});
}
/// @returns the annotations
const InstructionList& Annots() const { return annotations_; }
/// Add a function to the module.
/// @param func the function to add
void PushFunction(const Function& func) { functions_.push_back(func); }
/// @returns the functions
const std::vector<Function>& Functions() const { return functions_; }
private:
uint32_t next_id_ = 1;
InstructionList capabilities_;
InstructionList extensions_;
InstructionList ext_imports_;
InstructionList memory_model_;
InstructionList entry_points_;
InstructionList execution_modes_;
InstructionList debug_;
InstructionList types_;
InstructionList annotations_;
std::vector<Function> functions_;
std::unordered_set<uint32_t> capability_set_;
};
} // namespace tint::writer::spirv
#endif // SRC_TINT_WRITER_SPIRV_MODULE_H_

View File

@ -0,0 +1,52 @@
// Copyright 2023 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/writer/spirv/spv_dump.h"
#include "src/tint/writer/spirv/test_helper.h"
namespace tint::writer::spirv {
namespace {
using SpvModuleTest = TestHelper;
TEST_F(SpvModuleTest, TracksIdBounds) {
spirv::Module m;
for (size_t i = 0; i < 5; i++) {
EXPECT_EQ(m.NextId(), i + 1);
}
EXPECT_EQ(6u, m.IdBound());
}
TEST_F(SpvModuleTest, Capabilities_Dedup) {
spirv::Module m;
m.PushCapability(SpvCapabilityShader);
m.PushCapability(SpvCapabilityShader);
m.PushCapability(SpvCapabilityShader);
EXPECT_EQ(DumpInstructions(m.Capabilities()), "OpCapability Shader\n");
}
TEST_F(SpvModuleTest, DeclareExtension) {
spirv::Module m;
m.PushExtension("SPV_KHR_integer_dot_product");
EXPECT_EQ(DumpInstructions(m.Extensions()), "OpExtension \"SPV_KHR_integer_dot_product\"\n");
}
} // namespace
} // namespace tint::writer::spirv

View File

@ -60,8 +60,8 @@ std::string Disassemble(const std::vector<uint32_t>& data) {
std::string DumpBuilder(Builder& builder) {
BinaryWriter writer;
writer.WriteHeader(builder.id_bound());
writer.WriteBuilder(&builder);
writer.WriteHeader(builder.Module().IdBound());
writer.WriteModule(&builder.Module());
return Disassemble(writer.result());
}

View File

@ -94,8 +94,8 @@ class TestHelperBase : public ProgramBuilder, public BASE {
/// @param b the spirv::Builder containing the built SPIR-V module
void Validate(spirv::Builder& b) {
BinaryWriter writer;
writer.WriteHeader(b.id_bound());
writer.WriteBuilder(&b);
writer.WriteHeader(b.Module().IdBound());
writer.WriteModule(&b.Module());
auto binary = writer.result();
std::string spv_errors;