blob: 12e47e6561949c8b75fa125e6068811eece5f31c [file] [log] [blame]
Austin Engcc2516a2023-10-17 20:57:54 +00001// Copyright 2023 The Dawn & Tint Authors
Ben Claytonb1cd47d2023-08-14 19:44:15 +00002//
Austin Engcc2516a2023-10-17 20:57:54 +00003// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are met:
Ben Claytonb1cd47d2023-08-14 19:44:15 +00005//
Austin Engcc2516a2023-10-17 20:57:54 +00006// 1. Redistributions of source code must retain the above copyright notice, this
7// list of conditions and the following disclaimer.
Ben Claytonb1cd47d2023-08-14 19:44:15 +00008//
Austin Engcc2516a2023-10-17 20:57:54 +00009// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12//
13// 3. Neither the name of the copyright holder nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Ben Claytonb1cd47d2023-08-14 19:44:15 +000027
28#include "src/tint/api/tint.h"
29
30////////////////////////////////////////////////////////////////////////////////
31// The following includes are used by './tools/run gen' to add an implicit
32// dependency from 'tint/api' to the libraries used to make up the Tint API.
33////////////////////////////////////////////////////////////////////////////////
dan sinclaire93ae122024-06-11 23:29:52 +000034// IWYU pragma: begin_keep
Ben Claytonc1942cf2023-08-16 19:15:21 +000035#include "src/tint/api/common/override_id.h"
Ben Claytonc1942cf2023-08-16 19:15:21 +000036
Ben Claytonb1cd47d2023-08-14 19:44:15 +000037#if TINT_BUILD_GLSL_WRITER
38#include "src/tint/lang/glsl/writer/writer.h" // nogncheck
39#endif
40
41#if TINT_BUILD_HLSL_WRITER
42#include "src/tint/lang/hlsl/writer/writer.h" // nogncheck
43#endif
44
45#if TINT_BUILD_MSL_WRITER
46#include "src/tint/lang/msl/writer/writer.h" // nogncheck
47#endif
48
49#if TINT_BUILD_SPV_READER
50#include "src/tint/lang/spirv/reader/reader.h" // nogncheck
51#endif
52
53#if TINT_BUILD_SPV_WRITER
54#include "src/tint/lang/spirv/writer/writer.h" // nogncheck
55#endif
56
57#if TINT_BUILD_WGSL_READER
58#include "src/tint/lang/wgsl/reader/reader.h" // nogncheck
59#endif
60
61#if TINT_BUILD_WGSL_WRITER
62#include "src/tint/lang/wgsl/writer/writer.h" // nogncheck
63#endif
64
dan sinclaire93ae122024-06-11 23:29:52 +000065// IWYU pragma: end_keep
66
Ben Claytonb1cd47d2023-08-14 19:44:15 +000067namespace tint {
68
69/// Initialize initializes the Tint library. Call before using the Tint API.
70void Initialize() {
71#if TINT_BUILD_WGSL_WRITER
72 // Register the Program printer. This is used for debugging purposes.
Ben Clayton5ed5cc42023-09-22 10:31:04 +000073 tint::Program::printer = [](const tint::Program& program) {
Ben Claytonb1cd47d2023-08-14 19:44:15 +000074 auto result = wgsl::writer::Generate(program, {});
Ben Clayton89274f72024-01-03 10:53:42 +000075 if (result != Success) {
Ben Clayton1e1f4882024-02-05 17:35:59 +000076 return result.Failure().reason.Str();
Ben Claytonb1cd47d2023-08-14 19:44:15 +000077 }
78 return result->wgsl;
79 };
80#endif
81}
82
83/// Shutdown uninitializes the Tint library. Call after using the Tint API.
84void Shutdown() {
85 // Currently no-op, but may release tint resources in the future.
86}
87
88} // namespace tint