1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/writer/msl/generator.h"
16 
17 #include <utility>
18 
19 #include "src/writer/msl/generator_impl.h"
20 
21 namespace tint {
22 namespace writer {
23 namespace msl {
24 
25 Options::Options() = default;
26 Options::~Options() = default;
27 Options::Options(const Options&) = default;
28 Options& Options::operator=(const Options&) = default;
29 
30 Result::Result() = default;
31 Result::~Result() = default;
32 Result::Result(const Result&) = default;
33 
Generate(const Program* program, const Options& options)34 Result Generate(const Program* program, const Options& options) {
35   Result result;
36 
37   // Sanitize the program.
38   auto sanitized_result = Sanitize(
39       program, options.buffer_size_ubo_index, options.fixed_sample_mask,
40       options.emit_vertex_point_size, options.disable_workgroup_init,
41       options.array_length_from_uniform);
42   if (!sanitized_result.program.IsValid()) {
43     result.success = false;
44     result.error = sanitized_result.program.Diagnostics().str();
45     return result;
46   }
47   result.needs_storage_buffer_sizes =
48       sanitized_result.needs_storage_buffer_sizes;
49   result.used_array_length_from_uniform_indices =
50       std::move(sanitized_result.used_array_length_from_uniform_indices);
51 
52   // Generate the MSL code.
53   auto impl = std::make_unique<GeneratorImpl>(&sanitized_result.program);
54   result.success = impl->Generate();
55   result.error = impl->error();
56   result.msl = impl->result();
57   result.has_invariant_attribute = impl->HasInvariant();
58   result.workgroup_allocations = impl->DynamicWorkgroupAllocations();
59 
60   return result;
61 }
62 
63 }  // namespace msl
64 }  // namespace writer
65 }  // namespace tint
66