mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 16:16:08 +00:00
Migrate from using ast::Module to Program
Enforce all places where Dawn passes in or returns a ast::Module, now takes a `const Program* ` or returns a `Program`. As the end goal of all this is to have immutable Programs, all Program inputs take a pointer instead of moving the actual object. As consumers of a Program are now all const, we have to const_cast to work around all the places we've been incorrectly mutating a ast::Module. These const_casts are temporary, and will be fixed in the next set of changes. Depends on https://dawn-review.googlesource.com/c/dawn/+/38522 Bug: tint:390 Change-Id: Ie05b112b16134937d1b601e9b713ea4ec4e1c677 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38541 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
@@ -43,29 +43,27 @@
|
||||
namespace tint {
|
||||
namespace inspector {
|
||||
|
||||
Inspector::Inspector(const ast::Module& module) : module_(module) {}
|
||||
|
||||
Inspector::Inspector(const Program* program) : Inspector(program->module) {}
|
||||
Inspector::Inspector(const Program* program) : program_(*program) {}
|
||||
|
||||
Inspector::~Inspector() = default;
|
||||
|
||||
std::vector<EntryPoint> Inspector::GetEntryPoints() {
|
||||
std::vector<EntryPoint> result;
|
||||
|
||||
for (auto* func : module_.Functions()) {
|
||||
for (auto* func : program_.Functions()) {
|
||||
if (!func->IsEntryPoint()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
EntryPoint entry_point;
|
||||
entry_point.name = module_.SymbolToName(func->symbol());
|
||||
entry_point.remapped_name = module_.SymbolToName(func->symbol());
|
||||
entry_point.name = program_.SymbolToName(func->symbol());
|
||||
entry_point.remapped_name = program_.SymbolToName(func->symbol());
|
||||
entry_point.stage = func->pipeline_stage();
|
||||
std::tie(entry_point.workgroup_size_x, entry_point.workgroup_size_y,
|
||||
entry_point.workgroup_size_z) = func->workgroup_size();
|
||||
|
||||
for (auto* var : func->referenced_module_variables()) {
|
||||
auto name = module_.SymbolToName(var->symbol());
|
||||
auto name = program_.SymbolToName(var->symbol());
|
||||
if (var->HasBuiltinDecoration()) {
|
||||
continue;
|
||||
}
|
||||
@@ -108,7 +106,7 @@ std::string Inspector::GetRemappedNameForEntryPoint(
|
||||
|
||||
std::map<uint32_t, Scalar> Inspector::GetConstantIDs() {
|
||||
std::map<uint32_t, Scalar> result;
|
||||
for (auto* var : module_.global_variables()) {
|
||||
for (auto* var : program_.global_variables()) {
|
||||
if (!var->HasConstantIdDecoration()) {
|
||||
continue;
|
||||
}
|
||||
@@ -285,7 +283,7 @@ std::vector<ResourceBinding> Inspector::GetMultisampledTextureResourceBindings(
|
||||
}
|
||||
|
||||
ast::Function* Inspector::FindEntryPointByName(const std::string& name) {
|
||||
auto* func = module_.Functions().Find(module_.GetSymbol(name));
|
||||
auto* func = program_.Functions().Find(program_.GetSymbol(name));
|
||||
if (!func) {
|
||||
error_ += name + " was not found!";
|
||||
return nullptr;
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "src/ast/module.h"
|
||||
#include "src/ast/pipeline_stage.h"
|
||||
#include "src/inspector/entry_point.h"
|
||||
#include "src/inspector/scalar.h"
|
||||
@@ -68,13 +67,9 @@ struct ResourceBinding {
|
||||
SampledKind sampled_kind;
|
||||
};
|
||||
|
||||
/// Extracts information from a module
|
||||
/// Extracts information from a program
|
||||
class Inspector {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param module Shader module to extract information from.
|
||||
explicit Inspector(const ast::Module& module);
|
||||
|
||||
/// Constructor
|
||||
/// @param program Shader program to extract information from.
|
||||
explicit Inspector(const Program* program);
|
||||
@@ -134,7 +129,7 @@ class Inspector {
|
||||
const std::string& entry_point);
|
||||
|
||||
private:
|
||||
const ast::Module& module_;
|
||||
const Program& program_;
|
||||
std::string error_;
|
||||
|
||||
/// @param name name of the entry point to find
|
||||
|
||||
@@ -67,11 +67,11 @@ namespace tint {
|
||||
namespace inspector {
|
||||
namespace {
|
||||
|
||||
class InspectorHelper : public ast::BuilderWithModule {
|
||||
class InspectorHelper : public ast::BuilderWithProgram {
|
||||
public:
|
||||
InspectorHelper()
|
||||
: td_(std::make_unique<TypeDeterminer>(mod)),
|
||||
inspector_(std::make_unique<Inspector>(*mod)),
|
||||
inspector_(std::make_unique<Inspector>(mod)),
|
||||
sampler_type_(type::SamplerKind::kSampler),
|
||||
comparison_sampler_type_(type::SamplerKind::kComparisonSampler) {}
|
||||
|
||||
@@ -317,7 +317,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
return {struct_type, std::move(access_type)};
|
||||
}
|
||||
|
||||
/// Adds a binding variable with a struct type to the module
|
||||
/// Adds a binding variable with a struct type to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
/// @param storage_class the storage class to use
|
||||
@@ -337,7 +337,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
mod->AddGlobalVariable(var);
|
||||
}
|
||||
|
||||
/// Adds an uniform buffer variable to the module
|
||||
/// Adds an uniform buffer variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
/// @param group the binding/group/ to use for the uniform buffer
|
||||
@@ -349,7 +349,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
AddBinding(name, type, ast::StorageClass::kUniform, group, binding);
|
||||
}
|
||||
|
||||
/// Adds a storage buffer variable to the module
|
||||
/// Adds a storage buffer variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
/// @param group the binding/group to use for the storage buffer
|
||||
@@ -398,7 +398,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
ast::FunctionDecorationList{});
|
||||
}
|
||||
|
||||
/// Adds a regular sampler variable to the module
|
||||
/// Adds a regular sampler variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param group the binding/group to use for the storage buffer
|
||||
/// @param binding the binding number to use for the storage buffer
|
||||
@@ -407,7 +407,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
binding);
|
||||
}
|
||||
|
||||
/// Adds a comparison sampler variable to the module
|
||||
/// Adds a comparison sampler variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param group the binding/group to use for the storage buffer
|
||||
/// @param binding the binding number to use for the storage buffer
|
||||
@@ -444,7 +444,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
return create<type::MultisampledTexture>(dim, type);
|
||||
}
|
||||
|
||||
/// Adds a sampled texture variable to the module
|
||||
/// Adds a sampled texture variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
/// @param group the binding/group to use for the sampled texture
|
||||
@@ -456,7 +456,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
AddBinding(name, type, ast::StorageClass::kUniformConstant, group, binding);
|
||||
}
|
||||
|
||||
/// Adds a multi-sampled texture variable to the module
|
||||
/// Adds a multi-sampled texture variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
/// @param group the binding/group to use for the multi-sampled texture
|
||||
@@ -473,7 +473,7 @@ class InspectorHelper : public ast::BuilderWithModule {
|
||||
Var(name, ast::StorageClass::kUniformConstant, type));
|
||||
}
|
||||
|
||||
/// Adds a depth texture variable to the module
|
||||
/// Adds a depth texture variable to the program
|
||||
/// @param name the name of the variable
|
||||
/// @param type the type to use
|
||||
void AddDepthTexture(const std::string& name, type::Type* type) {
|
||||
|
||||
Reference in New Issue
Block a user