mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-08 07:33:33 +00:00
tint: Add Initialize() / Shutdown() public APIs
Have Initialize() bind the Program printer - which is helpful for debugging. Call these from dawn/node. This allows dawn/node to print programs when things go wrong. Change-Id: I32d8805381d2939e82dc6ea383b9860fbb5fb69e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107684 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
02f04d914d
commit
8fa6c25b78
@ -15,6 +15,9 @@
|
|||||||
#ifndef INCLUDE_TINT_TINT_H_
|
#ifndef INCLUDE_TINT_TINT_H_
|
||||||
#define INCLUDE_TINT_TINT_H_
|
#define INCLUDE_TINT_TINT_H_
|
||||||
|
|
||||||
|
// Guard for accidental includes to private headers
|
||||||
|
#define CURRENTLY_IN_TINT_PUBLIC_HEADER
|
||||||
|
|
||||||
// TODO(tint:88): When implementing support for an install target, all of these
|
// TODO(tint:88): When implementing support for an install target, all of these
|
||||||
// headers will need to be moved to include/tint/.
|
// headers will need to be moved to include/tint/.
|
||||||
|
|
||||||
@ -64,4 +67,16 @@
|
|||||||
#include "src/tint/writer/glsl/generator.h"
|
#include "src/tint/writer/glsl/generator.h"
|
||||||
#endif // TINT_BUILD_GLSL_WRITER
|
#endif // TINT_BUILD_GLSL_WRITER
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
|
||||||
|
/// Initialize initializes the Tint library. Call before using the Tint API.
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
|
/// Shutdown uninitializes the Tint library. Call after using the Tint API.
|
||||||
|
void Shutdown();
|
||||||
|
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#undef CURRENTLY_IN_TINT_PUBLIC_HEADER
|
||||||
|
|
||||||
#endif // INCLUDE_TINT_TINT_H_
|
#endif // INCLUDE_TINT_TINT_H_
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "dawn/dawn_proc.h"
|
#include "dawn/dawn_proc.h"
|
||||||
#include "src/dawn/node/binding/Flags.h"
|
#include "src/dawn/node/binding/Flags.h"
|
||||||
#include "src/dawn/node/binding/GPU.h"
|
#include "src/dawn/node/binding/GPU.h"
|
||||||
|
#include "tint/tint.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Napi::Value CreateGPU(const Napi::CallbackInfo& info) {
|
Napi::Value CreateGPU(const Napi::CallbackInfo& info) {
|
||||||
@ -55,7 +56,10 @@ Napi::Value CreateGPU(const Napi::CallbackInfo& info) {
|
|||||||
// types into the global object, and adding the 'create' function on the exported
|
// types into the global object, and adding the 'create' function on the exported
|
||||||
// object.
|
// object.
|
||||||
Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
|
Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
|
||||||
// Begin by setting the Dawn procedure function pointers.
|
// Initialize Tint
|
||||||
|
tint::Initialize();
|
||||||
|
|
||||||
|
// Set all the Dawn procedure function pointers.
|
||||||
dawnProcSetProcs(&dawn::native::GetProcs());
|
dawnProcSetProcs(&dawn::native::GetProcs());
|
||||||
|
|
||||||
// Register all the interop types
|
// Register all the interop types
|
||||||
|
@ -474,6 +474,7 @@ libtint_source_set("libtint_core_all_src") {
|
|||||||
"symbol_table.h",
|
"symbol_table.h",
|
||||||
"text/unicode.cc",
|
"text/unicode.cc",
|
||||||
"text/unicode.h",
|
"text/unicode.h",
|
||||||
|
"tint.cc",
|
||||||
"traits.h",
|
"traits.h",
|
||||||
"transform/add_block_attribute.cc",
|
"transform/add_block_attribute.cc",
|
||||||
"transform/add_block_attribute.h",
|
"transform/add_block_attribute.h",
|
||||||
|
@ -385,6 +385,7 @@ set(TINT_LIB_SRCS
|
|||||||
symbol_table.h
|
symbol_table.h
|
||||||
symbol.cc
|
symbol.cc
|
||||||
symbol.h
|
symbol.h
|
||||||
|
tint.cc
|
||||||
text/unicode.cc
|
text/unicode.cc
|
||||||
text/unicode.h
|
text/unicode.h
|
||||||
traits.h
|
traits.h
|
||||||
|
@ -109,7 +109,7 @@
|
|||||||
#include "src/tint/sem/vector.h"
|
#include "src/tint/sem/vector.h"
|
||||||
#include "src/tint/sem/void.h"
|
#include "src/tint/sem/void.h"
|
||||||
|
|
||||||
#ifdef INCLUDE_TINT_TINT_H_
|
#ifdef CURRENTLY_IN_TINT_PUBLIC_HEADER
|
||||||
#error "internal tint header being #included from tint.h"
|
#error "internal tint header being #included from tint.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,15 +14,12 @@
|
|||||||
|
|
||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include "src/tint/program.h"
|
#include "src/tint/program.h"
|
||||||
|
#include "tint/tint.h"
|
||||||
|
|
||||||
#if TINT_BUILD_SPV_READER
|
#if TINT_BUILD_SPV_READER
|
||||||
#include "src/tint/reader/spirv/parser_impl_test_helper.h"
|
#include "src/tint/reader/spirv/parser_impl_test_helper.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TINT_BUILD_WGSL_WRITER
|
|
||||||
#include "src/tint/writer/wgsl/generator.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
|
void TintInternalCompilerErrorReporter(const tint::diag::List& diagnostics) {
|
||||||
@ -54,15 +51,7 @@ struct Flags {
|
|||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
testing::InitGoogleMock(&argc, argv);
|
testing::InitGoogleMock(&argc, argv);
|
||||||
|
|
||||||
#if TINT_BUILD_WGSL_WRITER
|
tint::Initialize();
|
||||||
tint::Program::printer = [](const tint::Program* program) {
|
|
||||||
auto result = tint::writer::wgsl::Generate(program, {});
|
|
||||||
if (!result.error.empty()) {
|
|
||||||
return "error: " + result.error;
|
|
||||||
}
|
|
||||||
return result.wgsl;
|
|
||||||
};
|
|
||||||
#endif // TINT_BUILD_WGSL_WRITER
|
|
||||||
|
|
||||||
Flags flags;
|
Flags flags;
|
||||||
if (!flags.parse(argc, argv)) {
|
if (!flags.parse(argc, argv)) {
|
||||||
@ -79,5 +68,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
auto res = RUN_ALL_TESTS();
|
auto res = RUN_ALL_TESTS();
|
||||||
|
|
||||||
|
tint::Shutdown();
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
36
src/tint/tint.cc
Normal file
36
src/tint/tint.cc
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Copyright 2022 The Tint Authors.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include "tint/tint.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
|
||||||
|
void Initialize() {
|
||||||
|
#if TINT_BUILD_WGSL_WRITER
|
||||||
|
// Register the Program printer. This is used for debugging purposes.
|
||||||
|
tint::Program::printer = [](const tint::Program* program) {
|
||||||
|
auto result = writer::wgsl::Generate(program, {});
|
||||||
|
if (!result.error.empty()) {
|
||||||
|
return "error: " + result.error;
|
||||||
|
}
|
||||||
|
return result.wgsl;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shutdown() {
|
||||||
|
// Currently no-op, but may release tint resources in the future.
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace tint
|
Loading…
x
Reference in New Issue
Block a user