msl: Remove the sanitizer transform

Invoke the required transforms directly in the MSL backend.

Change-Id: Id8026b1a64415fbe363f8f8a5790e8216cd12c68
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/63620
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price
2021-09-08 19:57:47 +00:00
committed by Tint LUCI CQ
parent 5910ec1e8a
commit 733addc20f
11 changed files with 94 additions and 301 deletions

View File

@@ -1,134 +0,0 @@
// 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 <memory>
#include <unordered_map>
#include <utility>
#include <vector>
#include "src/ast/disable_validation_decoration.h"
#include "src/program_builder.h"
#include "src/sem/call.h"
#include "src/sem/function.h"
#include "src/sem/statement.h"
#include "src/sem/variable.h"
#include "src/transform/array_length_from_uniform.h"
#include "src/transform/canonicalize_entry_point_io.h"
#include "src/transform/external_texture_transform.h"
#include "src/transform/inline_pointer_lets.h"
#include "src/transform/manager.h"
#include "src/transform/module_scope_var_to_entry_point_param.h"
#include "src/transform/pad_array_elements.h"
#include "src/transform/promote_initializers_to_const_var.h"
#include "src/transform/simplify.h"
#include "src/transform/wrap_arrays_in_structs.h"
#include "src/transform/zero_init_workgroup_memory.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl);
TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl::Config);
TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl::Result);
namespace tint {
namespace transform {
Msl::Msl() = default;
Msl::~Msl() = default;
Output Msl::Run(const Program* in, const DataMap& inputs) {
Manager manager;
DataMap internal_inputs;
auto* cfg = inputs.Get<Config>();
// Build the configs for the internal transforms.
uint32_t buffer_size_ubo_index = kDefaultBufferSizeUniformIndex;
uint32_t fixed_sample_mask = 0xFFFFFFFF;
bool emit_point_size = false;
if (cfg) {
buffer_size_ubo_index = cfg->buffer_size_ubo_index;
fixed_sample_mask = cfg->fixed_sample_mask;
emit_point_size = cfg->emit_vertex_point_size;
}
auto array_length_from_uniform_cfg = ArrayLengthFromUniform::Config(
sem::BindingPoint{0, buffer_size_ubo_index});
auto entry_point_io_cfg = CanonicalizeEntryPointIO::Config(
CanonicalizeEntryPointIO::ShaderStyle::kMsl, fixed_sample_mask,
emit_point_size);
// Use the SSBO binding numbers as the indices for the buffer size lookups.
for (auto* var : in->AST().GlobalVariables()) {
auto* global = in->Sem().Get<sem::GlobalVariable>(var);
if (global && global->StorageClass() == ast::StorageClass::kStorage) {
array_length_from_uniform_cfg.bindpoint_to_size_index.emplace(
global->BindingPoint(), global->BindingPoint().binding);
}
}
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<ExternalTextureTransform>();
manager.Add<PromoteInitializersToConstVar>();
manager.Add<WrapArraysInStructs>();
manager.Add<PadArrayElements>();
manager.Add<ModuleScopeVarToEntryPointParam>();
manager.Add<InlinePointerLets>();
manager.Add<Simplify>();
// ArrayLengthFromUniform must come after InlinePointerLets and Simplify, as
// it assumes that the form of the array length argument is &var.array.
manager.Add<ArrayLengthFromUniform>();
internal_inputs.Add<ArrayLengthFromUniform::Config>(
std::move(array_length_from_uniform_cfg));
internal_inputs.Add<CanonicalizeEntryPointIO::Config>(
std::move(entry_point_io_cfg));
auto out = manager.Run(in, internal_inputs);
if (!out.program.IsValid()) {
return out;
}
ProgramBuilder builder;
CloneContext ctx(&builder, &out.program);
// TODO(jrprice): Move the sanitizer into the backend.
ctx.Clone();
auto result = std::make_unique<Result>(
out.data.Get<ArrayLengthFromUniform::Result>()->needs_buffer_sizes);
builder.SetTransformApplied(this);
return Output{Program(std::move(builder)), std::move(result)};
}
Msl::Config::Config(uint32_t buffer_size_ubo_idx,
uint32_t sample_mask,
bool emit_point_size,
bool disable_wi)
: buffer_size_ubo_index(buffer_size_ubo_idx),
fixed_sample_mask(sample_mask),
emit_vertex_point_size(emit_point_size),
disable_workgroup_init(disable_wi) {}
Msl::Config::Config(const Config&) = default;
Msl::Config::~Config() = default;
Msl::Result::Result(bool needs_buffer_sizes)
: needs_storage_buffer_sizes(needs_buffer_sizes) {}
Msl::Result::Result(const Result&) = default;
Msl::Result::~Result() = default;
} // namespace transform
} // namespace tint

View File

@@ -1,94 +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_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 Castable<Msl, Transform> {
public:
/// The default buffer slot to use for the storage buffer size buffer.
const uint32_t kDefaultBufferSizeUniformIndex = 30;
/// Configuration options for the Msl sanitizer transform.
struct Config : public Castable<Data, transform::Data> {
/// Constructor
/// @param buffer_size_ubo_idx the index to use for the buffer size UBO
/// @param sample_mask the fixed sample mask to use for fragment shaders
/// @param emit_point_size `true` to emit a vertex point size builtin
/// @param disable_workgroup_init `true` to disable workgroup memory zero
/// initialization
Config(uint32_t buffer_size_ubo_idx,
uint32_t sample_mask = 0xFFFFFFFF,
bool emit_point_size = false,
bool disable_workgroup_init = false);
/// Copy constructor
Config(const Config&);
/// Destructor
~Config() override;
/// The index to use when generating a UBO to receive storage buffer sizes.
uint32_t buffer_size_ubo_index = 0;
/// The fixed sample mask to combine with fragment shader outputs.
uint32_t fixed_sample_mask = 0xFFFFFFFF;
/// Set to `true` to generate a [[point_size]] attribute which is set to 1.0
/// for all vertex shaders in the module.
bool emit_vertex_point_size = false;
/// Set to `true` to disable workgroup memory zero initialization
bool disable_workgroup_init = false;
};
/// Information produced by the sanitizer that users may need to act on.
struct Result : public Castable<Result, transform::Data> {
/// Constructor
/// @param needs_buffer_sizes True if the shader needs a UBO of buffer sizes
explicit Result(bool needs_buffer_sizes);
/// Copy constructor
Result(const Result&);
/// Destructor
~Result() override;
/// True if the shader needs a UBO of buffer sizes.
bool const needs_storage_buffer_sizes;
};
/// Constructor
Msl();
~Msl() override;
/// Runs the transform on `program`, returning the transformation result.
/// @param program the source program to transform
/// @param data optional extra transform-specific input data
/// @returns the transformation result
Output Run(const Program* program, const DataMap& data = {}) override;
};
} // namespace transform
} // namespace tint
#endif // SRC_TRANSFORM_MSL_H_

View File

@@ -1,29 +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/transform/msl.h"
#include "src/transform/test_helper.h"
namespace tint {
namespace transform {
namespace {
using MslTest = TransformTest;
// TODO(jrprice): Remove this file when we remove the sanitizers.
} // namespace
} // namespace transform
} // namespace tint