mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-21 02:39:11 +00:00
Factor out code to flatten bindings for msl
And use it in the fuzzers to fix ICE that occurs when bindings are not flattened when processing MSL. Bug: chromium:1314938 Change-Id: Ic35503e53395fad232487226c324067975291fbf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/88461 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Antonio Maiorano <amaiorano@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
870b5a665f
commit
4e98fb0bd8
@@ -32,6 +32,7 @@
|
||||
#include "src/tint/utils/io/command.h"
|
||||
#include "src/tint/utils/string.h"
|
||||
#include "src/tint/val/val.h"
|
||||
#include "src/tint/writer/flatten_bindings.h"
|
||||
#include "tint/tint.h"
|
||||
|
||||
namespace {
|
||||
@@ -640,58 +641,12 @@ bool GenerateWgsl(const tint::Program* program, const Options& options) {
|
||||
/// @returns true on success
|
||||
bool GenerateMsl(const tint::Program* program, const Options& options) {
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
const tint::Program* input_program = program;
|
||||
|
||||
// Remap resource numbers to a flat namespace.
|
||||
// TODO(crbug.com/tint/1101): Make this more robust for multiple entry points.
|
||||
using BindingPoint = tint::transform::BindingPoint;
|
||||
tint::transform::BindingRemapper::BindingPoints binding_points;
|
||||
uint32_t next_buffer_idx = 0;
|
||||
uint32_t next_sampler_idx = 0;
|
||||
uint32_t next_texture_idx = 0;
|
||||
|
||||
tint::inspector::Inspector inspector(program);
|
||||
auto entry_points = inspector.GetEntryPoints();
|
||||
for (auto& entry_point : entry_points) {
|
||||
auto bindings = inspector.GetResourceBindings(entry_point.name);
|
||||
for (auto& binding : bindings) {
|
||||
BindingPoint src = {binding.bind_group, binding.binding};
|
||||
if (binding_points.count(src)) {
|
||||
continue;
|
||||
}
|
||||
switch (binding.resource_type) {
|
||||
case tint::inspector::ResourceBinding::ResourceType::kUniformBuffer:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kStorageBuffer:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kReadOnlyStorageBuffer:
|
||||
binding_points.emplace(src, BindingPoint{0, next_buffer_idx++});
|
||||
break;
|
||||
case tint::inspector::ResourceBinding::ResourceType::kSampler:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kComparisonSampler:
|
||||
binding_points.emplace(src, BindingPoint{0, next_sampler_idx++});
|
||||
break;
|
||||
case tint::inspector::ResourceBinding::ResourceType::kSampledTexture:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kMultisampledTexture:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kWriteOnlyStorageTexture:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kDepthTexture:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kDepthMultisampledTexture:
|
||||
case tint::inspector::ResourceBinding::ResourceType::kExternalTexture:
|
||||
binding_points.emplace(src, BindingPoint{0, next_texture_idx++});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the binding remapper transform.
|
||||
tint::transform::Output transform_output;
|
||||
if (!binding_points.empty()) {
|
||||
tint::transform::Manager manager;
|
||||
tint::transform::DataMap inputs;
|
||||
inputs.Add<tint::transform::BindingRemapper::Remappings>(
|
||||
std::move(binding_points), tint::transform::BindingRemapper::AccessControls{},
|
||||
/* mayCollide */ true);
|
||||
manager.Add<tint::transform::BindingRemapper>();
|
||||
transform_output = manager.Run(program, inputs);
|
||||
input_program = &transform_output.program;
|
||||
// TODO(crbug.com/tint/1501): Do this via Options::BindingMap.
|
||||
const tint::Program* input_program = program;
|
||||
auto flattened = tint::writer::FlattenBindings(program);
|
||||
if (flattened) {
|
||||
input_program = &*flattened;
|
||||
}
|
||||
|
||||
// TODO(jrprice): Provide a way for the user to set non-default options.
|
||||
|
||||
Reference in New Issue
Block a user