From e0bee791cbac4e7ef97ff4f126bc23eb8eb479a1 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Mon, 11 Apr 2022 15:21:41 +0000 Subject: [PATCH] Add ifdefs for Tint API usage that may not be available Fixed Kokoro failures when building Tint with all readers and writers disabled. Change-Id: I9bd041339236488dd563bbe687da883035f2a4b7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86181 Reviewed-by: Corentin Wallez Commit-Queue: Antonio Maiorano --- src/dawn/native/ShaderModule.cpp | 15 +++++++++++++++ src/dawn/native/vulkan/ShaderModuleVk.cpp | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/dawn/native/ShaderModule.cpp b/src/dawn/native/ShaderModule.cpp index 779e6ae499..136158b443 100644 --- a/src/dawn/native/ShaderModule.cpp +++ b/src/dawn/native/ShaderModule.cpp @@ -380,6 +380,7 @@ namespace dawn::native { ResultOrError ParseWGSL(const tint::Source::File* file, OwnedCompilationMessages* outMessages) { +#if TINT_BUILD_WGSL_READER tint::Program program = tint::reader::wgsl::Parse(file); if (outMessages != nullptr) { outMessages->AddMessages(program.Diagnostics()); @@ -391,10 +392,14 @@ namespace dawn::native { } return std::move(program); +#else + return DAWN_FORMAT_VALIDATION_ERROR("TINT_BUILD_WGSL_READER is not defined."); +#endif } ResultOrError ParseSPIRV(const std::vector& spirv, OwnedCompilationMessages* outMessages) { +#if TINT_BUILD_SPV_READER tint::Program program = tint::reader::spirv::Parse(spirv); if (outMessages != nullptr) { outMessages->AddMessages(program.Diagnostics()); @@ -405,6 +410,10 @@ namespace dawn::native { } return std::move(program); +#else + return DAWN_FORMAT_VALIDATION_ERROR("TINT_BUILD_SPV_READER is not defined."); + +#endif } std::vector GetBindGroupMinBufferSizes(const BindingGroupInfoMap& shaderBindings, @@ -997,6 +1006,7 @@ namespace dawn::native { ShaderModuleWGSLDescriptor newWgslDesc; std::string newWgslCode; if (spirvDesc && device->IsToggleEnabled(Toggle::ForceWGSLStep)) { +#if TINT_BUILD_WGSL_WRITER std::vector spirv(spirvDesc->code, spirvDesc->code + spirvDesc->codeSize); tint::Program program; DAWN_TRY_ASSIGN(program, ParseSPIRV(spirv, outMessages)); @@ -1010,6 +1020,11 @@ namespace dawn::native { spirvDesc = nullptr; wgslDesc = &newWgslDesc; +#else + device->EmitLog( + WGPULoggingType_Info, + "Toggle::ForceWGSLStep skipped because TINT_BUILD_WGSL_WRITER is not defined\n"); +#endif } if (spirvDesc) { diff --git a/src/dawn/native/vulkan/ShaderModuleVk.cpp b/src/dawn/native/vulkan/ShaderModuleVk.cpp index d56e599c11..da9ca3db7a 100644 --- a/src/dawn/native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn/native/vulkan/ShaderModuleVk.cpp @@ -203,6 +203,7 @@ namespace dawn::native::vulkan { transformInputs, nullptr, nullptr)); } +#if TINT_BUILD_SPV_WRITER tint::writer::spirv::Options options; options.emit_vertex_point_size = true; options.disable_workgroup_init = GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit); @@ -249,6 +250,9 @@ namespace dawn::native::vulkan { GetLabel()); return std::move(moduleAndSpirv); +#else + return DAWN_INTERNAL_ERROR("TINT_BUILD_SPV_WRITER is not defined."); +#endif } } // namespace dawn::native::vulkan