diff --git a/src/tint/lang/spirv/writer/BUILD.bazel b/src/tint/lang/spirv/writer/BUILD.bazel index 9cc1e251cdf..dbd9c587ccd 100644 --- a/src/tint/lang/spirv/writer/BUILD.bazel +++ b/src/tint/lang/spirv/writer/BUILD.bazel @@ -136,10 +136,9 @@ cc_library( "//conditions:default": [], }) + select({ ":tint_build_spv_writer": [ + "//src/tint/lang/spirv/writer", "//src/tint/lang/spirv/writer/common", "//src/tint/lang/spirv/writer/common:test", - "//src/tint/lang/spirv/writer/printer", - "//src/tint/lang/spirv/writer/raise", ], "//conditions:default": [], }), diff --git a/src/tint/lang/spirv/writer/BUILD.cmake b/src/tint/lang/spirv/writer/BUILD.cmake index fcddb03731c..7d31e90d7ce 100644 --- a/src/tint/lang/spirv/writer/BUILD.cmake +++ b/src/tint/lang/spirv/writer/BUILD.cmake @@ -153,10 +153,9 @@ endif(TINT_BUILD_SPV_READER OR TINT_BUILD_SPV_WRITER) if(TINT_BUILD_SPV_WRITER) tint_target_add_dependencies(tint_lang_spirv_writer_test test + tint_lang_spirv_writer tint_lang_spirv_writer_common tint_lang_spirv_writer_common_test - tint_lang_spirv_writer_printer - tint_lang_spirv_writer_raise ) endif(TINT_BUILD_SPV_WRITER) diff --git a/src/tint/lang/spirv/writer/BUILD.gn b/src/tint/lang/spirv/writer/BUILD.gn index d727487dde2..49a8ec99770 100644 --- a/src/tint/lang/spirv/writer/BUILD.gn +++ b/src/tint/lang/spirv/writer/BUILD.gn @@ -142,10 +142,9 @@ if (tint_build_unittests) { if (tint_build_spv_writer) { deps += [ + "${tint_src_dir}/lang/spirv/writer", "${tint_src_dir}/lang/spirv/writer/common", "${tint_src_dir}/lang/spirv/writer/common:unittests", - "${tint_src_dir}/lang/spirv/writer/printer", - "${tint_src_dir}/lang/spirv/writer/raise", ] } } diff --git a/src/tint/lang/spirv/writer/common/BUILD.bazel b/src/tint/lang/spirv/writer/common/BUILD.bazel index a317f7ed15c..3f79228c63a 100644 --- a/src/tint/lang/spirv/writer/common/BUILD.bazel +++ b/src/tint/lang/spirv/writer/common/BUILD.bazel @@ -120,9 +120,8 @@ cc_library( "//conditions:default": [], }) + select({ ":tint_build_spv_writer": [ + "//src/tint/lang/spirv/writer", "//src/tint/lang/spirv/writer/common", - "//src/tint/lang/spirv/writer/printer", - "//src/tint/lang/spirv/writer/raise", ], "//conditions:default": [], }), diff --git a/src/tint/lang/spirv/writer/common/BUILD.cmake b/src/tint/lang/spirv/writer/common/BUILD.cmake index 94860e3c4d7..c461889034a 100644 --- a/src/tint/lang/spirv/writer/common/BUILD.cmake +++ b/src/tint/lang/spirv/writer/common/BUILD.cmake @@ -131,9 +131,8 @@ endif(TINT_BUILD_SPV_READER OR TINT_BUILD_SPV_WRITER) if(TINT_BUILD_SPV_WRITER) tint_target_add_dependencies(tint_lang_spirv_writer_common_test test + tint_lang_spirv_writer tint_lang_spirv_writer_common - tint_lang_spirv_writer_printer - tint_lang_spirv_writer_raise ) endif(TINT_BUILD_SPV_WRITER) diff --git a/src/tint/lang/spirv/writer/common/BUILD.gn b/src/tint/lang/spirv/writer/common/BUILD.gn index 23470d41891..bef8cf11c8c 100644 --- a/src/tint/lang/spirv/writer/common/BUILD.gn +++ b/src/tint/lang/spirv/writer/common/BUILD.gn @@ -125,9 +125,8 @@ if (tint_build_unittests) { if (tint_build_spv_writer) { deps += [ + "${tint_src_dir}/lang/spirv/writer", "${tint_src_dir}/lang/spirv/writer/common", - "${tint_src_dir}/lang/spirv/writer/printer", - "${tint_src_dir}/lang/spirv/writer/raise", ] } } diff --git a/src/tint/lang/spirv/writer/common/helper_test.h b/src/tint/lang/spirv/writer/common/helper_test.h index 3e1cbbc5b41..d12c05843db 100644 --- a/src/tint/lang/spirv/writer/common/helper_test.h +++ b/src/tint/lang/spirv/writer/common/helper_test.h @@ -45,8 +45,7 @@ #include "src/tint/lang/core/type/sampled_texture.h" #include "src/tint/lang/core/type/storage_texture.h" #include "src/tint/lang/spirv/writer/common/spv_dump_test.h" -#include "src/tint/lang/spirv/writer/printer/printer.h" -#include "src/tint/lang/spirv/writer/raise/raise.h" +#include "src/tint/lang/spirv/writer/writer.h" namespace tint::spirv::writer { @@ -104,44 +103,27 @@ class SpirvWriterTestHelperBase : public BASE { /// SPIR-V output. std::string output_; - /// The generated SPIR-V - writer::Module spirv_; - /// @returns the error string from the validation std::string Error() const { return err_; } /// Run the printer on the IR module and validate the result. /// @param options the optional writer options to use when raising the IR - /// @param zero_init_workgroup_memory `true` to initialize all the variables in the Workgroup /// storage class with OpConstantNull /// @returns true if generation and validation succeeded - bool Generate(Options options = {}, bool zero_init_workgroup_memory = false) { - auto raised = Raise(mod, options); - if (raised != Success) { - err_ = raised.Failure().reason.Str(); - return false; - } - - if (zero_init_workgroup_memory) { - options.disable_workgroup_init = false; - options.use_zero_initialize_workgroup_memory_extension = true; - } - - auto spirv = PrintModule(mod, options); - if (spirv != Success) { - err_ = spirv.Failure().reason.Str(); + bool Generate(Options options = {}) { + auto result = writer::Generate(mod, options); + if (result != Success) { + err_ = result.Failure().reason.Str(); return false; } - output_ = Disassemble(spirv->Code(), SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | + output_ = Disassemble(result->spirv, SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES | SPV_BINARY_TO_TEXT_OPTION_INDENT | SPV_BINARY_TO_TEXT_OPTION_COMMENT); - if (!Validate(spirv->Code())) { + if (!Validate(result->spirv)) { return false; } - - spirv_ = std::move(spirv.Get()); return true; } @@ -180,9 +162,6 @@ class SpirvWriterTestHelperBase : public BASE { return result; } - /// @returns the disassembled types from the generated module. - std::string DumpTypes() { return DumpInstructions(spirv_.Types()); } - /// Helper to make a scalar type corresponding to the element type `type`. /// @param type the element type /// @returns the scalar type diff --git a/src/tint/lang/spirv/writer/type_test.cc b/src/tint/lang/spirv/writer/type_test.cc index febac195e5d..d2298a57f4e 100644 --- a/src/tint/lang/spirv/writer/type_test.cc +++ b/src/tint/lang/spirv/writer/type_test.cc @@ -414,14 +414,14 @@ TEST_F(SpirvWriterTest, Type_DepthTexture_DedupWithSampledTexture) { }); ASSERT_TRUE(Generate()) << Error() << output_; - EXPECT_EQ(DumpTypes(), R"(%4 = OpTypeFloat 32 -%3 = OpTypeImage %4 2D 0 0 0 1 Unknown -%2 = OpTypePointer UniformConstant %3 -%1 = OpVariable %2 UniformConstant -%6 = OpTypePointer UniformConstant %3 -%5 = OpVariable %6 UniformConstant -%8 = OpTypeVoid -%9 = OpTypeFunction %8 + EXPECT_INST(R"( %float = OpTypeFloat 32 + %3 = OpTypeImage %float 2D 0 0 0 1 Unknown +%_ptr_UniformConstant_3 = OpTypePointer UniformConstant %3 + %v1 = OpVariable %_ptr_UniformConstant_3 UniformConstant ; DescriptorSet 0, Binding 1, Coherent +%_ptr_UniformConstant_3_0 = OpTypePointer UniformConstant %3 + %v2 = OpVariable %_ptr_UniformConstant_3_0 UniformConstant ; DescriptorSet 0, Binding 2, Coherent + %void = OpTypeVoid + %9 = OpTypeFunction %void )"); } @@ -447,14 +447,14 @@ TEST_F(SpirvWriterTest, Type_DepthMultisampledTexture_DedupWithMultisampledTextu }); ASSERT_TRUE(Generate()) << Error() << output_; - EXPECT_EQ(DumpTypes(), R"(%4 = OpTypeFloat 32 -%3 = OpTypeImage %4 2D 0 0 1 1 Unknown -%2 = OpTypePointer UniformConstant %3 -%1 = OpVariable %2 UniformConstant -%6 = OpTypePointer UniformConstant %3 -%5 = OpVariable %6 UniformConstant -%8 = OpTypeVoid -%9 = OpTypeFunction %8 + EXPECT_INST(R"( %float = OpTypeFloat 32 + %3 = OpTypeImage %float 2D 0 0 1 1 Unknown +%_ptr_UniformConstant_3 = OpTypePointer UniformConstant %3 + %v1 = OpVariable %_ptr_UniformConstant_3 UniformConstant ; DescriptorSet 0, Binding 1, Coherent +%_ptr_UniformConstant_3_0 = OpTypePointer UniformConstant %3 + %v2 = OpVariable %_ptr_UniformConstant_3_0 UniformConstant ; DescriptorSet 0, Binding 2, Coherent + %void = OpTypeVoid + %9 = OpTypeFunction %void )"); } diff --git a/src/tint/lang/spirv/writer/var_test.cc b/src/tint/lang/spirv/writer/var_test.cc index 24b269aa4bc..c753a128b0b 100644 --- a/src/tint/lang/spirv/writer/var_test.cc +++ b/src/tint/lang/spirv/writer/var_test.cc @@ -181,8 +181,12 @@ TEST_F(SpirvWriterTest, WorkgroupVar_LoadAndStore) { TEST_F(SpirvWriterTest, WorkgroupVar_ZeroInitializeWithExtension) { mod.root_block->Append(b.Var("v", ty.ptr())); + Options opts{}; + opts.disable_workgroup_init = false; + opts.use_zero_initialize_workgroup_memory_extension = true; + // Create a writer with the zero_init_workgroup_memory flag set to `true`. - ASSERT_TRUE(Generate({}, /* zero_init_workgroup_memory */ true)) << Error() << output_; + ASSERT_TRUE(Generate(opts)) << Error() << output_; EXPECT_INST("%4 = OpConstantNull %int"); EXPECT_INST("%v = OpVariable %_ptr_Workgroup_int Workgroup %4"); }