blob: 5a3ff9d11513b5a8a7286f071ee835aedf23e6b5 [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
James Price773271b02024-09-10 20:15:47 +000058#include "src/tint/lang/wgsl/inspector/inspector.h" // nogncheck
59#include "src/tint/lang/wgsl/reader/reader.h" // nogncheck
Ben Claytonb1cd47d2023-08-14 19:44:15 +000060#endif
61
62#if TINT_BUILD_WGSL_WRITER
63#include "src/tint/lang/wgsl/writer/writer.h" // nogncheck
64#endif
65
dan sinclaire93ae122024-06-11 23:29:52 +000066// IWYU pragma: end_keep
67
Ben Claytonb1cd47d2023-08-14 19:44:15 +000068namespace tint {
69
70/// Initialize initializes the Tint library. Call before using the Tint API.
71void Initialize() {
72#if TINT_BUILD_WGSL_WRITER
73 // Register the Program printer. This is used for debugging purposes.
Ben Clayton5ed5cc42023-09-22 10:31:04 +000074 tint::Program::printer = [](const tint::Program& program) {
Ben Claytonb1cd47d2023-08-14 19:44:15 +000075 auto result = wgsl::writer::Generate(program, {});
Ben Clayton89274f72024-01-03 10:53:42 +000076 if (result != Success) {
Ben Clayton1e1f4882024-02-05 17:35:59 +000077 return result.Failure().reason.Str();
Ben Claytonb1cd47d2023-08-14 19:44:15 +000078 }
79 return result->wgsl;
80 };
81#endif
82}
83
84/// Shutdown uninitializes the Tint library. Call after using the Tint API.
85void Shutdown() {
86 // Currently no-op, but may release tint resources in the future.
87}
88
89} // namespace tint