Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2023 The Dawn & Tint Authors |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 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 Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 27 | |
| 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 sinclair | e93ae12 | 2024-06-11 23:29:52 +0000 | [diff] [blame] | 34 | // IWYU pragma: begin_keep |
Ben Clayton | c1942cf | 2023-08-16 19:15:21 +0000 | [diff] [blame] | 35 | #include "src/tint/api/common/override_id.h" |
Ben Clayton | c1942cf | 2023-08-16 19:15:21 +0000 | [diff] [blame] | 36 | |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 37 | #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 sinclair | e93ae12 | 2024-06-11 23:29:52 +0000 | [diff] [blame] | 65 | // IWYU pragma: end_keep |
| 66 | |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 67 | namespace tint { |
| 68 | |
| 69 | /// Initialize initializes the Tint library. Call before using the Tint API. |
| 70 | void Initialize() { |
| 71 | #if TINT_BUILD_WGSL_WRITER |
| 72 | // Register the Program printer. This is used for debugging purposes. |
Ben Clayton | 5ed5cc4 | 2023-09-22 10:31:04 +0000 | [diff] [blame] | 73 | tint::Program::printer = [](const tint::Program& program) { |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 74 | auto result = wgsl::writer::Generate(program, {}); |
Ben Clayton | 89274f7 | 2024-01-03 10:53:42 +0000 | [diff] [blame] | 75 | if (result != Success) { |
Ben Clayton | 1e1f488 | 2024-02-05 17:35:59 +0000 | [diff] [blame] | 76 | return result.Failure().reason.Str(); |
Ben Clayton | b1cd47d | 2023-08-14 19:44:15 +0000 | [diff] [blame] | 77 | } |
| 78 | return result->wgsl; |
| 79 | }; |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | /// Shutdown uninitializes the Tint library. Call after using the Tint API. |
| 84 | void Shutdown() { |
| 85 | // Currently no-op, but may release tint resources in the future. |
| 86 | } |
| 87 | |
| 88 | } // namespace tint |