mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-14 03:11:29 +00:00
Stub sanitizer transforms for the hlsl, msl & spirv writers
These transforms will perform work to massage the Program into something consumable by the given writer. Change-Id: I8989e8d4bc1a9cae7ce1f8764c8f3811db3bd04d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41483 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
c2118b0dcb
commit
2101c35f3b
6
BUILD.gn
6
BUILD.gn
@ -539,6 +539,8 @@ source_set("libtint_spv_reader_src") {
|
|||||||
|
|
||||||
source_set("libtint_spv_writer_src") {
|
source_set("libtint_spv_writer_src") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"src/transform/spirv.cc",
|
||||||
|
"src/transform/spirv.h",
|
||||||
"src/writer/spirv/binary_writer.cc",
|
"src/writer/spirv/binary_writer.cc",
|
||||||
"src/writer/spirv/binary_writer.h",
|
"src/writer/spirv/binary_writer.h",
|
||||||
"src/writer/spirv/builder.cc",
|
"src/writer/spirv/builder.cc",
|
||||||
@ -609,6 +611,8 @@ source_set("libtint_wgsl_writer_src") {
|
|||||||
|
|
||||||
source_set("libtint_msl_writer_src") {
|
source_set("libtint_msl_writer_src") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"src/transform/msl.cc",
|
||||||
|
"src/transform/msl.h",
|
||||||
"src/writer/msl/generator.cc",
|
"src/writer/msl/generator.cc",
|
||||||
"src/writer/msl/generator.h",
|
"src/writer/msl/generator.h",
|
||||||
"src/writer/msl/generator_impl.cc",
|
"src/writer/msl/generator_impl.cc",
|
||||||
@ -630,6 +634,8 @@ source_set("libtint_msl_writer_src") {
|
|||||||
|
|
||||||
source_set("libtint_hlsl_writer_src") {
|
source_set("libtint_hlsl_writer_src") {
|
||||||
sources = [
|
sources = [
|
||||||
|
"src/transform/hlsl.cc",
|
||||||
|
"src/transform/hlsl.h",
|
||||||
"src/writer/hlsl/generator.cc",
|
"src/writer/hlsl/generator.cc",
|
||||||
"src/writer/hlsl/generator.h",
|
"src/writer/hlsl/generator.h",
|
||||||
"src/writer/hlsl/generator_impl.cc",
|
"src/writer/hlsl/generator_impl.cc",
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
|
|
||||||
#if TINT_BUILD_SPV_WRITER
|
#if TINT_BUILD_SPV_WRITER
|
||||||
#include "spirv-tools/libspirv.hpp"
|
#include "spirv-tools/libspirv.hpp"
|
||||||
|
#include "src/transform/spirv.h"
|
||||||
#include "src/writer/spirv/generator.h"
|
#include "src/writer/spirv/generator.h"
|
||||||
#endif // TINT_BUILD_SPV_WRITER
|
#endif // TINT_BUILD_SPV_WRITER
|
||||||
|
|
||||||
@ -52,10 +53,12 @@
|
|||||||
#endif // TINT_BUILD_WGSL_WRITER
|
#endif // TINT_BUILD_WGSL_WRITER
|
||||||
|
|
||||||
#if TINT_BUILD_MSL_WRITER
|
#if TINT_BUILD_MSL_WRITER
|
||||||
|
#include "src/transform/msl.h"
|
||||||
#include "src/writer/msl/generator.h"
|
#include "src/writer/msl/generator.h"
|
||||||
#endif // TINT_BUILD_MSL_WRITER
|
#endif // TINT_BUILD_MSL_WRITER
|
||||||
|
|
||||||
#if TINT_BUILD_HLSL_WRITER
|
#if TINT_BUILD_HLSL_WRITER
|
||||||
|
#include "src/transform/hlsl.h"
|
||||||
#include "src/writer/hlsl/generator.h"
|
#include "src/writer/hlsl/generator.h"
|
||||||
#endif // TINT_BUILD_HLSL_WRITER
|
#endif // TINT_BUILD_HLSL_WRITER
|
||||||
|
|
||||||
|
@ -538,6 +538,27 @@ int main(int argc, const char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (options.format) {
|
||||||
|
#if TINT_BUILD_SPV_WRITER
|
||||||
|
case Format::kSpirv:
|
||||||
|
case Format::kSpvAsm:
|
||||||
|
transform_manager.append(std::make_unique<tint::transform::Spirv>());
|
||||||
|
break;
|
||||||
|
#endif // TINT_BUILD_SPV_WRITER
|
||||||
|
#if TINT_BUILD_MSL_WRITER
|
||||||
|
case Format::kMsl:
|
||||||
|
transform_manager.append(std::make_unique<tint::transform::Msl>());
|
||||||
|
break;
|
||||||
|
#endif // TINT_BUILD_MSL_WRITER
|
||||||
|
#if TINT_BUILD_HLSL_WRITER
|
||||||
|
case Format::kHlsl:
|
||||||
|
transform_manager.append(std::make_unique<tint::transform::Hlsl>());
|
||||||
|
break;
|
||||||
|
#endif // TINT_BUILD_HLSL_WRITER
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
auto out = transform_manager.Run(program.get());
|
auto out = transform_manager.Run(program.get());
|
||||||
if (out.diagnostics.contains_errors()) {
|
if (out.diagnostics.contains_errors()) {
|
||||||
diag_formatter.format(out.diagnostics, diag_printer.get());
|
diag_formatter.format(out.diagnostics, diag_printer.get());
|
||||||
|
@ -329,6 +329,8 @@ endif()
|
|||||||
|
|
||||||
if(${TINT_BUILD_SPV_WRITER})
|
if(${TINT_BUILD_SPV_WRITER})
|
||||||
list(APPEND TINT_LIB_SRCS
|
list(APPEND TINT_LIB_SRCS
|
||||||
|
transform/spirv.cc
|
||||||
|
transform/spirv.h
|
||||||
writer/spirv/binary_writer.cc
|
writer/spirv/binary_writer.cc
|
||||||
writer/spirv/binary_writer.h
|
writer/spirv/binary_writer.h
|
||||||
writer/spirv/builder.cc
|
writer/spirv/builder.cc
|
||||||
@ -355,6 +357,8 @@ endif()
|
|||||||
|
|
||||||
if(${TINT_BUILD_MSL_WRITER})
|
if(${TINT_BUILD_MSL_WRITER})
|
||||||
list(APPEND TINT_LIB_SRCS
|
list(APPEND TINT_LIB_SRCS
|
||||||
|
transform/msl.cc
|
||||||
|
transform/msl.h
|
||||||
writer/msl/generator.cc
|
writer/msl/generator.cc
|
||||||
writer/msl/generator.h
|
writer/msl/generator.h
|
||||||
writer/msl/generator_impl.cc
|
writer/msl/generator_impl.cc
|
||||||
@ -366,6 +370,8 @@ endif()
|
|||||||
|
|
||||||
if(${TINT_BUILD_HLSL_WRITER})
|
if(${TINT_BUILD_HLSL_WRITER})
|
||||||
list(APPEND TINT_LIB_SRCS
|
list(APPEND TINT_LIB_SRCS
|
||||||
|
transform/hlsl.cc
|
||||||
|
transform/hlsl.h
|
||||||
writer/hlsl/generator.cc
|
writer/hlsl/generator.cc
|
||||||
writer/hlsl/generator.h
|
writer/hlsl/generator.h
|
||||||
writer/hlsl/generator_impl.cc
|
writer/hlsl/generator_impl.cc
|
||||||
|
34
src/transform/hlsl.cc
Normal file
34
src/transform/hlsl.cc
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2020 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 "src/transform/hlsl.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "src/program_builder.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
Hlsl::Hlsl() = default;
|
||||||
|
Hlsl::~Hlsl() = default;
|
||||||
|
|
||||||
|
Transform::Output Hlsl::Run(const Program* in) {
|
||||||
|
ProgramBuilder out;
|
||||||
|
CloneContext(&out, in).Clone();
|
||||||
|
return Output{Program(std::move(out))};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
44
src/transform/hlsl.h
Normal file
44
src/transform/hlsl.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2021 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.
|
||||||
|
|
||||||
|
#ifndef SRC_TRANSFORM_HLSL_H_
|
||||||
|
#define SRC_TRANSFORM_HLSL_H_
|
||||||
|
|
||||||
|
#include "src/transform/transform.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
/// Hlsl is a transform used to sanitize a Program for use with the Hlsl writer.
|
||||||
|
/// Passing a non-sanitized Program to the Hlsl writer will result in undefined
|
||||||
|
/// behavior.
|
||||||
|
class Hlsl : public Transform {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
Hlsl();
|
||||||
|
~Hlsl() override;
|
||||||
|
|
||||||
|
/// Runs the transform on `program`, returning the transformation result.
|
||||||
|
/// @note Users of Tint should register the transform with transform manager
|
||||||
|
/// and invoke its Run(), instead of directly calling the transform's Run().
|
||||||
|
/// Calling Run() directly does not perform program state cleanup operations.
|
||||||
|
/// @param program the source program to transform
|
||||||
|
/// @returns the transformation result
|
||||||
|
Output Run(const Program* program) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_TRANSFORM_HLSL_H_
|
34
src/transform/msl.cc
Normal file
34
src/transform/msl.cc
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2020 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 "src/transform/msl.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "src/program_builder.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
Msl::Msl() = default;
|
||||||
|
Msl::~Msl() = default;
|
||||||
|
|
||||||
|
Transform::Output Msl::Run(const Program* in) {
|
||||||
|
ProgramBuilder out;
|
||||||
|
CloneContext(&out, in).Clone();
|
||||||
|
return Output{Program(std::move(out))};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
44
src/transform/msl.h
Normal file
44
src/transform/msl.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2021 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.
|
||||||
|
|
||||||
|
#ifndef SRC_TRANSFORM_MSL_H_
|
||||||
|
#define SRC_TRANSFORM_MSL_H_
|
||||||
|
|
||||||
|
#include "src/transform/transform.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
/// Msl is a transform used to sanitize a Program for use with the Msl writer.
|
||||||
|
/// Passing a non-sanitized Program to the Msl writer will result in undefined
|
||||||
|
/// behavior.
|
||||||
|
class Msl : public Transform {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
Msl();
|
||||||
|
~Msl() override;
|
||||||
|
|
||||||
|
/// Runs the transform on `program`, returning the transformation result.
|
||||||
|
/// @note Users of Tint should register the transform with transform manager
|
||||||
|
/// and invoke its Run(), instead of directly calling the transform's Run().
|
||||||
|
/// Calling Run() directly does not perform program state cleanup operations.
|
||||||
|
/// @param program the source program to transform
|
||||||
|
/// @returns the transformation result
|
||||||
|
Output Run(const Program* program) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_TRANSFORM_MSL_H_
|
34
src/transform/spirv.cc
Normal file
34
src/transform/spirv.cc
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Copyright 2020 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 "src/transform/spirv.h"
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#include "src/program_builder.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
Spirv::Spirv() = default;
|
||||||
|
Spirv::~Spirv() = default;
|
||||||
|
|
||||||
|
Transform::Output Spirv::Run(const Program* in) {
|
||||||
|
ProgramBuilder out;
|
||||||
|
CloneContext(&out, in).Clone();
|
||||||
|
return Output{Program(std::move(out))};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
44
src/transform/spirv.h
Normal file
44
src/transform/spirv.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2021 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.
|
||||||
|
|
||||||
|
#ifndef SRC_TRANSFORM_SPIRV_H_
|
||||||
|
#define SRC_TRANSFORM_SPIRV_H_
|
||||||
|
|
||||||
|
#include "src/transform/transform.h"
|
||||||
|
|
||||||
|
namespace tint {
|
||||||
|
namespace transform {
|
||||||
|
|
||||||
|
/// Spirv is a transform used to sanitize a Program for use with the Spirv
|
||||||
|
/// writer. Passing a non-sanitized Program to the Spirv writer will result in
|
||||||
|
/// undefined behavior.
|
||||||
|
class Spirv : public Transform {
|
||||||
|
public:
|
||||||
|
/// Constructor
|
||||||
|
Spirv();
|
||||||
|
~Spirv() override;
|
||||||
|
|
||||||
|
/// Runs the transform on `program`, returning the transformation result.
|
||||||
|
/// @note Users of Tint should register the transform with transform manager
|
||||||
|
/// and invoke its Run(), instead of directly calling the transform's Run().
|
||||||
|
/// Calling Run() directly does not perform program state cleanup operations.
|
||||||
|
/// @param program the source program to transform
|
||||||
|
/// @returns the transformation result
|
||||||
|
Output Run(const Program* program) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace transform
|
||||||
|
} // namespace tint
|
||||||
|
|
||||||
|
#endif // SRC_TRANSFORM_SPIRV_H_
|
Loading…
x
Reference in New Issue
Block a user