mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 10:25:28 +00:00
tint: Make GLSL backend consistent with the others
Remove transform::Glsl and replace with a Sanitize function. Cleans up the code, reduces allocations and copies, and makes it consistent with the other backends. Also add a copy of src/tint/.clang-format to include/tint/ to keep files in there formatted as per the tint standard. Bug: tint:1495 Change-Id: I8a44ffecc6b3d244517bceb374ed93063e96f218 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86205 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro-Run: Antonio Maiorano <amaiorano@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
b5c46c30ec
commit
f625a6d57e
@@ -1,145 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "src/tint/transform/glsl.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/transform/add_empty_entry_point.h"
|
||||
#include "src/tint/transform/add_spirv_block_attribute.h"
|
||||
#include "src/tint/transform/binding_remapper.h"
|
||||
#include "src/tint/transform/builtin_polyfill.h"
|
||||
#include "src/tint/transform/canonicalize_entry_point_io.h"
|
||||
#include "src/tint/transform/combine_samplers.h"
|
||||
#include "src/tint/transform/decompose_memory_access.h"
|
||||
#include "src/tint/transform/expand_compound_assignment.h"
|
||||
#include "src/tint/transform/fold_trivial_single_use_lets.h"
|
||||
#include "src/tint/transform/loop_to_for_loop.h"
|
||||
#include "src/tint/transform/manager.h"
|
||||
#include "src/tint/transform/promote_initializers_to_const_var.h"
|
||||
#include "src/tint/transform/promote_side_effects_to_decl.h"
|
||||
#include "src/tint/transform/remove_phonies.h"
|
||||
#include "src/tint/transform/renamer.h"
|
||||
#include "src/tint/transform/simplify_pointers.h"
|
||||
#include "src/tint/transform/single_entry_point.h"
|
||||
#include "src/tint/transform/unshadow.h"
|
||||
#include "src/tint/transform/unwind_discard_functions.h"
|
||||
#include "src/tint/transform/zero_init_workgroup_memory.h"
|
||||
#include "src/tint/writer/generate_external_texture_bindings.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::Glsl);
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::transform::Glsl::Config);
|
||||
|
||||
namespace tint::transform {
|
||||
|
||||
Glsl::Glsl() = default;
|
||||
Glsl::~Glsl() = default;
|
||||
|
||||
Output Glsl::Run(const Program* in, const DataMap& inputs) const {
|
||||
Manager manager;
|
||||
DataMap data;
|
||||
|
||||
auto* cfg = inputs.Get<Config>();
|
||||
|
||||
{ // Builtin polyfills
|
||||
BuiltinPolyfill::Builtins polyfills;
|
||||
polyfills.count_leading_zeros = true;
|
||||
polyfills.count_trailing_zeros = true;
|
||||
polyfills.extract_bits = BuiltinPolyfill::Level::kClampParameters;
|
||||
polyfills.first_leading_bit = true;
|
||||
polyfills.first_trailing_bit = true;
|
||||
polyfills.insert_bits = BuiltinPolyfill::Level::kClampParameters;
|
||||
data.Add<BuiltinPolyfill::Config>(polyfills);
|
||||
manager.Add<BuiltinPolyfill>();
|
||||
}
|
||||
|
||||
if (cfg && !cfg->entry_point.empty()) {
|
||||
manager.Add<SingleEntryPoint>();
|
||||
data.Add<SingleEntryPoint::Config>(cfg->entry_point);
|
||||
}
|
||||
manager.Add<Renamer>();
|
||||
data.Add<Renamer::Config>(Renamer::Target::kGlslKeywords,
|
||||
/* preserve_unicode */ false);
|
||||
manager.Add<Unshadow>();
|
||||
|
||||
// Attempt to convert `loop`s into for-loops. This is to try and massage the
|
||||
// output into something that will not cause FXC to choke or misbehave.
|
||||
manager.Add<FoldTrivialSingleUseLets>();
|
||||
manager.Add<LoopToForLoop>();
|
||||
|
||||
if (!cfg || !cfg->disable_workgroup_init) {
|
||||
// ZeroInitWorkgroupMemory must come before CanonicalizeEntryPointIO as
|
||||
// ZeroInitWorkgroupMemory may inject new builtin parameters.
|
||||
manager.Add<ZeroInitWorkgroupMemory>();
|
||||
}
|
||||
manager.Add<CanonicalizeEntryPointIO>();
|
||||
manager.Add<ExpandCompoundAssignment>();
|
||||
manager.Add<PromoteSideEffectsToDecl>();
|
||||
manager.Add<UnwindDiscardFunctions>();
|
||||
manager.Add<SimplifyPointers>();
|
||||
|
||||
manager.Add<RemovePhonies>();
|
||||
|
||||
if (cfg && cfg->generate_external_texture_bindings) {
|
||||
auto new_bindings_map = writer::GenerateExternalTextureBindings(in);
|
||||
data.Add<MultiplanarExternalTexture::NewBindingPoints>(new_bindings_map);
|
||||
}
|
||||
manager.Add<MultiplanarExternalTexture>();
|
||||
|
||||
manager.Add<CombineSamplers>();
|
||||
if (auto* binding_info = inputs.Get<CombineSamplers::BindingInfo>()) {
|
||||
data.Add<CombineSamplers::BindingInfo>(*binding_info);
|
||||
} else {
|
||||
data.Add<CombineSamplers::BindingInfo>(CombineSamplers::BindingMap(),
|
||||
sem::BindingPoint());
|
||||
}
|
||||
manager.Add<BindingRemapper>();
|
||||
if (auto* remappings = inputs.Get<BindingRemapper::Remappings>()) {
|
||||
data.Add<BindingRemapper::Remappings>(*remappings);
|
||||
} else {
|
||||
BindingRemapper::BindingPoints bp;
|
||||
BindingRemapper::AccessControls ac;
|
||||
data.Add<BindingRemapper::Remappings>(bp, ac, /* mayCollide */ true);
|
||||
}
|
||||
|
||||
manager.Add<PromoteInitializersToConstVar>();
|
||||
|
||||
manager.Add<AddEmptyEntryPoint>();
|
||||
manager.Add<AddSpirvBlockAttribute>();
|
||||
|
||||
data.Add<CanonicalizeEntryPointIO::Config>(
|
||||
CanonicalizeEntryPointIO::ShaderStyle::kGlsl);
|
||||
auto out = manager.Run(in, data);
|
||||
if (!out.program.IsValid()) {
|
||||
return out;
|
||||
}
|
||||
|
||||
ProgramBuilder builder;
|
||||
CloneContext ctx(&builder, &out.program);
|
||||
ctx.Clone();
|
||||
return Output{Program(std::move(builder))};
|
||||
}
|
||||
|
||||
Glsl::Config::Config(const std::string& entry_point_in,
|
||||
bool disable_workgroup_init_in,
|
||||
bool generate_external_texture_bindings_in)
|
||||
: entry_point(entry_point_in),
|
||||
disable_workgroup_init(disable_workgroup_init_in),
|
||||
generate_external_texture_bindings(
|
||||
generate_external_texture_bindings_in) {}
|
||||
Glsl::Config::Config(const Config&) = default;
|
||||
Glsl::Config::~Config() = default;
|
||||
|
||||
} // namespace tint::transform
|
||||
@@ -1,75 +0,0 @@
|
||||
// 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_TINT_TRANSFORM_GLSL_H_
|
||||
#define SRC_TINT_TRANSFORM_GLSL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/transform/transform.h"
|
||||
|
||||
// Forward declarations
|
||||
namespace tint {
|
||||
class CloneContext;
|
||||
} // namespace tint
|
||||
|
||||
namespace tint::transform {
|
||||
|
||||
/// Glsl is a transform used to sanitize a Program for use with the Glsl writer.
|
||||
/// Passing a non-sanitized Program to the Glsl writer will result in undefined
|
||||
/// behavior.
|
||||
class Glsl final : public Castable<Glsl, Transform> {
|
||||
public:
|
||||
/// Configuration options for the Glsl sanitizer transform.
|
||||
struct Config final : public Castable<Data, transform::Data> {
|
||||
/// Constructor
|
||||
/// @param entry_point the root entry point function to generate
|
||||
/// @param disable_workgroup_init `true` to disable workgroup memory zero
|
||||
/// initialization
|
||||
/// @param generate_external_texture_bindings 'true' to generates binding
|
||||
/// mappings for external textures
|
||||
explicit Config(const std::string& entry_point,
|
||||
bool disable_workgroup_init,
|
||||
bool generate_external_texture_bindings);
|
||||
|
||||
/// Copy constructor
|
||||
Config(const Config&);
|
||||
|
||||
/// Destructor
|
||||
~Config() override;
|
||||
|
||||
/// GLSL generator wraps a single entry point in a main() function.
|
||||
std::string entry_point;
|
||||
|
||||
/// Set to `true` to disable workgroup memory zero initialization
|
||||
bool disable_workgroup_init = false;
|
||||
|
||||
/// Set to 'true' to generates binding mappings for external textures
|
||||
bool generate_external_texture_bindings = false;
|
||||
};
|
||||
|
||||
/// Constructor
|
||||
Glsl();
|
||||
~Glsl() override;
|
||||
|
||||
/// Runs the transform on `program`, returning the transformation result.
|
||||
/// @param program the source program to transform
|
||||
/// @param data optional extra transform-specific data
|
||||
/// @returns the transformation result
|
||||
Output Run(const Program* program, const DataMap& data = {}) const override;
|
||||
};
|
||||
|
||||
} // namespace tint::transform
|
||||
|
||||
#endif // SRC_TINT_TRANSFORM_GLSL_H_
|
||||
@@ -1,39 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "src/tint/transform/glsl.h"
|
||||
|
||||
#include "src/tint/transform/test_helper.h"
|
||||
|
||||
namespace tint::transform {
|
||||
namespace {
|
||||
|
||||
using GlslTest = TransformTest;
|
||||
|
||||
TEST_F(GlslTest, AddEmptyEntryPoint) {
|
||||
auto* src = R"()";
|
||||
|
||||
auto* expect = R"(
|
||||
@stage(compute) @workgroup_size(1)
|
||||
fn unused_entry_point() {
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<Glsl>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace tint::transform
|
||||
Reference in New Issue
Block a user