dawn-cmake/src/writer/spirv/generator.cc
Ben Clayton d59cedb5a5 Add tint::Program as a wrapper of tint::ast::Module.
`tint::Program` will become the new public API object for a parsed shader program.
For now, have Program be a simple wrapper around ast::Module so we can migrate Dawn's use of the public tint API.

Add new Program variants of public APIs for places that returned or took a Module.

Remove Reset() methods from Generators, they aren't used, and make the migration harder.

Change-Id: Ic5bee46ceb109ea591ba7fec33685220b244a1ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/38540
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
2021-01-25 18:14:08 +00:00

52 lines
1.4 KiB
C++

// 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/writer/spirv/generator.h"
#include <utility>
namespace tint {
namespace writer {
namespace spirv {
Generator::Generator(ast::Module module)
: module_(std::move(module)),
builder_(std::make_unique<Builder>(&module_)),
writer_(std::make_unique<BinaryWriter>()) {}
Generator::Generator(Program* program)
: builder_(std::make_unique<Builder>(&program->module)),
writer_(std::make_unique<BinaryWriter>()) {}
Generator::~Generator() = default;
bool Generator::Generate() {
if (!builder_->Build()) {
set_error(builder_->error());
return false;
}
writer_->WriteHeader(builder_->id_bound());
writer_->WriteBuilder(builder_.get());
return true;
}
bool Generator::GenerateEntryPoint(ast::PipelineStage, const std::string&) {
return false;
}
} // namespace spirv
} // namespace writer
} // namespace tint