Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 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/transform/msl.h" |
| 16 | |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 17 | #include <memory> |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 18 | #include <unordered_map> |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 19 | #include <utility> |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 20 | #include <vector> |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 21 | |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 22 | #include "src/ast/disable_validation_decoration.h" |
| 23 | #include "src/program_builder.h" |
| 24 | #include "src/sem/call.h" |
| 25 | #include "src/sem/function.h" |
| 26 | #include "src/sem/statement.h" |
| 27 | #include "src/sem/variable.h" |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 28 | #include "src/transform/array_length_from_uniform.h" |
James Price | f8f31a4 | 2021-04-09 13:50:38 +0000 | [diff] [blame] | 29 | #include "src/transform/canonicalize_entry_point_io.h" |
Brandon Jones | c705b6c | 2021-05-10 16:15:31 +0000 | [diff] [blame] | 30 | #include "src/transform/external_texture_transform.h" |
James Price | 567f2e4 | 2021-06-18 09:47:23 +0000 | [diff] [blame] | 31 | #include "src/transform/inline_pointer_lets.h" |
James Price | f8f31a4 | 2021-04-09 13:50:38 +0000 | [diff] [blame] | 32 | #include "src/transform/manager.h" |
Ben Clayton | 31936f3 | 2021-06-16 09:50:11 +0000 | [diff] [blame] | 33 | #include "src/transform/pad_array_elements.h" |
James Price | 42220ba | 2021-06-01 12:08:20 +0000 | [diff] [blame] | 34 | #include "src/transform/promote_initializers_to_const_var.h" |
James Price | 567f2e4 | 2021-06-18 09:47:23 +0000 | [diff] [blame] | 35 | #include "src/transform/simplify.h" |
Ben Clayton | 0597a2b | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 36 | #include "src/transform/wrap_arrays_in_structs.h" |
Ben Clayton | 75db82c | 2021-06-18 22:44:31 +0000 | [diff] [blame] | 37 | #include "src/transform/zero_init_workgroup_memory.h" |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 38 | |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 39 | TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 40 | TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl::Config); |
| 41 | TINT_INSTANTIATE_TYPEINFO(tint::transform::Msl::Result); |
| 42 | |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 43 | namespace tint { |
| 44 | namespace transform { |
| 45 | |
| 46 | Msl::Msl() = default; |
| 47 | Msl::~Msl() = default; |
| 48 | |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 49 | Output Msl::Run(const Program* in, const DataMap& inputs) { |
James Price | f8f31a4 | 2021-04-09 13:50:38 +0000 | [diff] [blame] | 50 | Manager manager; |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 51 | DataMap internal_inputs; |
| 52 | |
| 53 | auto* cfg = inputs.Get<Config>(); |
| 54 | |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 55 | // Build the configs for the internal transforms. |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 56 | uint32_t buffer_size_ubo_index = kDefaultBufferSizeUniformIndex; |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 57 | uint32_t fixed_sample_mask = 0xFFFFFFFF; |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 58 | if (cfg) { |
| 59 | buffer_size_ubo_index = cfg->buffer_size_ubo_index; |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 60 | fixed_sample_mask = cfg->fixed_sample_mask; |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 61 | } |
| 62 | auto array_length_from_uniform_cfg = ArrayLengthFromUniform::Config( |
| 63 | sem::BindingPoint{0, buffer_size_ubo_index}); |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 64 | auto entry_point_io_cfg = CanonicalizeEntryPointIO::Config( |
| 65 | CanonicalizeEntryPointIO::BuiltinStyle::kParameter, fixed_sample_mask); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 66 | |
| 67 | // Use the SSBO binding numbers as the indices for the buffer size lookups. |
| 68 | for (auto* var : in->AST().GlobalVariables()) { |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 69 | auto* global = in->Sem().Get<sem::GlobalVariable>(var); |
| 70 | if (global && global->StorageClass() == ast::StorageClass::kStorage) { |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 71 | array_length_from_uniform_cfg.bindpoint_to_size_index.emplace( |
Ben Clayton | 0f2d95d | 2021-07-22 13:24:59 +0000 | [diff] [blame] | 72 | global->BindingPoint(), global->BindingPoint().binding); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
Ben Clayton | 701820b | 2021-07-20 18:23:06 +0000 | [diff] [blame] | 76 | if (!cfg || !cfg->disable_workgroup_init) { |
| 77 | // ZeroInitWorkgroupMemory must come before CanonicalizeEntryPointIO as |
| 78 | // ZeroInitWorkgroupMemory may inject new builtin parameters. |
| 79 | manager.Add<ZeroInitWorkgroupMemory>(); |
| 80 | } |
James Price | f8f31a4 | 2021-04-09 13:50:38 +0000 | [diff] [blame] | 81 | manager.Add<CanonicalizeEntryPointIO>(); |
Brandon Jones | c705b6c | 2021-05-10 16:15:31 +0000 | [diff] [blame] | 82 | manager.Add<ExternalTextureTransform>(); |
James Price | 42220ba | 2021-06-01 12:08:20 +0000 | [diff] [blame] | 83 | manager.Add<PromoteInitializersToConstVar>(); |
Ben Clayton | 0597a2b | 2021-06-16 09:19:36 +0000 | [diff] [blame] | 84 | manager.Add<WrapArraysInStructs>(); |
Ben Clayton | 31936f3 | 2021-06-16 09:50:11 +0000 | [diff] [blame] | 85 | manager.Add<PadArrayElements>(); |
James Price | 567f2e4 | 2021-06-18 09:47:23 +0000 | [diff] [blame] | 86 | manager.Add<InlinePointerLets>(); |
| 87 | manager.Add<Simplify>(); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 88 | // ArrayLengthFromUniform must come after InlinePointerLets and Simplify, as |
| 89 | // it assumes that the form of the array length argument is &var.array. |
| 90 | manager.Add<ArrayLengthFromUniform>(); |
| 91 | internal_inputs.Add<ArrayLengthFromUniform::Config>( |
| 92 | std::move(array_length_from_uniform_cfg)); |
| 93 | internal_inputs.Add<CanonicalizeEntryPointIO::Config>( |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 94 | std::move(entry_point_io_cfg)); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 95 | auto out = manager.Run(in, internal_inputs); |
James Price | f8f31a4 | 2021-04-09 13:50:38 +0000 | [diff] [blame] | 96 | if (!out.program.IsValid()) { |
| 97 | return out; |
| 98 | } |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 99 | |
| 100 | ProgramBuilder builder; |
| 101 | CloneContext ctx(&builder, &out.program); |
| 102 | // TODO(jrprice): Consider making this a standalone transform, with target |
| 103 | // storage class(es) as transform options. |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 104 | HandleModuleScopeVariables(ctx); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 105 | ctx.Clone(); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 106 | |
| 107 | auto result = std::make_unique<Result>( |
| 108 | out.data.Get<ArrayLengthFromUniform::Result>()->needs_buffer_sizes); |
Ben Clayton | b5cd10c | 2021-06-25 10:26:26 +0000 | [diff] [blame] | 109 | |
| 110 | builder.SetTransformApplied(this); |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 111 | return Output{Program(std::move(builder)), std::move(result)}; |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 112 | } |
| 113 | |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 114 | void Msl::HandleModuleScopeVariables(CloneContext& ctx) const { |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 115 | // MSL does not allow private and workgroup variables at module-scope, so we |
| 116 | // push these declarations into the entry point function and then pass them as |
| 117 | // pointer parameters to any function that references them. |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 118 | // Similarly, texture and sampler types are converted to entry point |
| 119 | // parameters and passed by value to functions that need them. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 120 | // |
| 121 | // Since WGSL does not allow function-scope variables to have these storage |
| 122 | // classes, we annotate the new variable declarations with an attribute that |
| 123 | // bypasses that validation rule. |
| 124 | // |
| 125 | // Before: |
| 126 | // ``` |
| 127 | // var<private> v : f32 = 2.0; |
| 128 | // |
| 129 | // fn foo() { |
| 130 | // v = v + 1.0; |
| 131 | // } |
| 132 | // |
Sarah | e6cb51e | 2021-06-29 18:39:44 +0000 | [diff] [blame] | 133 | // [[stage(compute), workgroup_size(1)]] |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 134 | // fn main() { |
| 135 | // foo(); |
| 136 | // } |
| 137 | // ``` |
| 138 | // |
| 139 | // After: |
| 140 | // ``` |
| 141 | // fn foo(v : ptr<private, f32>) { |
| 142 | // *v = *v + 1.0; |
| 143 | // } |
| 144 | // |
Sarah | e6cb51e | 2021-06-29 18:39:44 +0000 | [diff] [blame] | 145 | // [[stage(compute), workgroup_size(1)]] |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 146 | // fn main() { |
| 147 | // var<private> v : f32 = 2.0; |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 148 | // foo(&v); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 149 | // } |
| 150 | // ``` |
| 151 | |
| 152 | // Predetermine the list of function calls that need to be replaced. |
| 153 | using CallList = std::vector<const ast::CallExpression*>; |
| 154 | std::unordered_map<const ast::Function*, CallList> calls_to_replace; |
| 155 | |
| 156 | std::vector<ast::Function*> functions_to_process; |
| 157 | |
| 158 | // Build a list of functions that transitively reference any private or |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 159 | // workgroup variables, or texture/sampler variables. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 160 | for (auto* func_ast : ctx.src->AST().Functions()) { |
| 161 | auto* func_sem = ctx.src->Sem().Get(func_ast); |
| 162 | |
| 163 | bool needs_processing = false; |
| 164 | for (auto* var : func_sem->ReferencedModuleVariables()) { |
| 165 | if (var->StorageClass() == ast::StorageClass::kPrivate || |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 166 | var->StorageClass() == ast::StorageClass::kWorkgroup || |
| 167 | var->StorageClass() == ast::StorageClass::kUniformConstant) { |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 168 | needs_processing = true; |
| 169 | break; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (needs_processing) { |
| 174 | functions_to_process.push_back(func_ast); |
| 175 | |
| 176 | // Find all of the calls to this function that will need to be replaced. |
| 177 | for (auto* call : func_sem->CallSites()) { |
| 178 | auto* call_sem = ctx.src->Sem().Get(call); |
| 179 | calls_to_replace[call_sem->Stmt()->Function()].push_back(call); |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
James Price | 5c61d6d | 2021-08-04 19:18:38 +0000 | [diff] [blame] | 184 | // Build a list of `&ident` expressions. We'll use this later to avoid |
| 185 | // generating expressions of the form `&*ident`, which break WGSL validation |
| 186 | // rules when this expression is passed to a function. |
| 187 | // TODO(jrprice): We should add support for bidirectional SEM tree traversal |
| 188 | // so that we can do this on the fly instead. |
| 189 | std::unordered_map<ast::IdentifierExpression*, ast::UnaryOpExpression*> |
| 190 | ident_to_address_of; |
| 191 | for (auto* node : ctx.src->ASTNodes().Objects()) { |
| 192 | auto* address_of = node->As<ast::UnaryOpExpression>(); |
| 193 | if (!address_of || address_of->op() != ast::UnaryOp::kAddressOf) { |
| 194 | continue; |
| 195 | } |
| 196 | if (auto* ident = address_of->expr()->As<ast::IdentifierExpression>()) { |
| 197 | ident_to_address_of[ident] = address_of; |
| 198 | } |
| 199 | } |
| 200 | |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 201 | for (auto* func_ast : functions_to_process) { |
| 202 | auto* func_sem = ctx.src->Sem().Get(func_ast); |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 203 | bool is_entry_point = func_ast->IsEntryPoint(); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 204 | |
| 205 | // Map module-scope variables onto their function-scope replacement. |
| 206 | std::unordered_map<const sem::Variable*, Symbol> var_to_symbol; |
| 207 | |
| 208 | for (auto* var : func_sem->ReferencedModuleVariables()) { |
| 209 | if (var->StorageClass() != ast::StorageClass::kPrivate && |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 210 | var->StorageClass() != ast::StorageClass::kWorkgroup && |
| 211 | var->StorageClass() != ast::StorageClass::kUniformConstant) { |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 212 | continue; |
| 213 | } |
| 214 | |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 215 | // This is the symbol for the variable that replaces the module-scope var. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 216 | auto new_var_symbol = ctx.dst->Sym(); |
| 217 | |
Ben Clayton | 96a6e7e | 2021-07-15 22:20:29 +0000 | [diff] [blame] | 218 | auto* store_type = CreateASTTypeFor(ctx, var->Type()->UnwrapRef()); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 219 | |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 220 | if (is_entry_point) { |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 221 | if (store_type->is_handle()) { |
| 222 | // For a texture or sampler variable, redeclare it as an entry point |
| 223 | // parameter. Disable entry point parameter validation. |
| 224 | auto* disable_validation = |
| 225 | ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( |
| 226 | ctx.dst->ID(), ast::DisabledValidation::kEntryPointParameter); |
| 227 | auto decos = ctx.Clone(var->Declaration()->decorations()); |
| 228 | decos.push_back(disable_validation); |
| 229 | auto* param = ctx.dst->Param(new_var_symbol, store_type, decos); |
| 230 | ctx.InsertFront(func_ast->params(), param); |
| 231 | } else { |
| 232 | // For a private or workgroup variable, redeclare it at function |
| 233 | // scope. Disable storage class validation on this variable. |
| 234 | auto* disable_validation = |
| 235 | ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( |
James Price | 14c0b8a | 2021-06-24 15:53:26 +0000 | [diff] [blame] | 236 | ctx.dst->ID(), ast::DisabledValidation::kIgnoreStorageClass); |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 237 | auto* constructor = ctx.Clone(var->Declaration()->constructor()); |
Ben Clayton | 75db82c | 2021-06-18 22:44:31 +0000 | [diff] [blame] | 238 | auto* local_var = ctx.dst->Var( |
| 239 | new_var_symbol, store_type, var->StorageClass(), constructor, |
| 240 | ast::DecorationList{disable_validation}); |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 241 | ctx.InsertFront(func_ast->body()->statements(), |
| 242 | ctx.dst->Decl(local_var)); |
| 243 | } |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 244 | } else { |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 245 | // For a regular function, redeclare the variable as a parameter. |
| 246 | // Use a pointer for non-handle types. |
| 247 | auto* param_type = store_type; |
| 248 | if (!store_type->is_handle()) { |
| 249 | param_type = ctx.dst->ty.pointer(param_type, var->StorageClass()); |
| 250 | } |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 251 | ctx.InsertBack(func_ast->params(), |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 252 | ctx.dst->Param(new_var_symbol, param_type)); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 253 | } |
| 254 | |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 255 | // Replace all uses of the module-scope variable. |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 256 | // For non-entry points, dereference non-handle pointer parameters. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 257 | for (auto* user : var->Users()) { |
| 258 | if (user->Stmt()->Function() == func_ast) { |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 259 | ast::Expression* expr = ctx.dst->Expr(new_var_symbol); |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 260 | if (!is_entry_point && !store_type->is_handle()) { |
James Price | 5c61d6d | 2021-08-04 19:18:38 +0000 | [diff] [blame] | 261 | // If this identifier is used by an address-of operator, just remove |
| 262 | // the address-of instead of adding a deref, since we already have a |
| 263 | // pointer. |
| 264 | auto* ident = user->Declaration()->As<ast::IdentifierExpression>(); |
| 265 | if (ident_to_address_of.count(ident)) { |
| 266 | ctx.Replace(ident_to_address_of[ident], expr); |
| 267 | continue; |
| 268 | } |
| 269 | |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 270 | expr = ctx.dst->Deref(expr); |
| 271 | } |
| 272 | ctx.Replace(user->Declaration(), expr); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | var_to_symbol[var] = new_var_symbol; |
| 277 | } |
| 278 | |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 279 | // Pass the variables as pointers to any functions that need them. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 280 | for (auto* call : calls_to_replace[func_ast]) { |
| 281 | auto* target = ctx.src->AST().Functions().Find(call->func()->symbol()); |
| 282 | auto* target_sem = ctx.src->Sem().Get(target); |
| 283 | |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 284 | // Add new arguments for any variables that are needed by the callee. |
| 285 | // For entry points, pass non-handle types as pointers. |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 286 | for (auto* target_var : target_sem->ReferencedModuleVariables()) { |
| 287 | if (target_var->StorageClass() == ast::StorageClass::kPrivate || |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 288 | target_var->StorageClass() == ast::StorageClass::kWorkgroup || |
| 289 | target_var->StorageClass() == ast::StorageClass::kUniformConstant) { |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 290 | ast::Expression* arg = ctx.dst->Expr(var_to_symbol[target_var]); |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 291 | if (is_entry_point && !target_var->Type()->UnwrapRef()->is_handle()) { |
James Price | 2940c70 | 2021-06-11 12:29:56 +0000 | [diff] [blame] | 292 | arg = ctx.dst->AddressOf(arg); |
| 293 | } |
| 294 | ctx.InsertBack(call->params(), arg); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
James Price | 830b97f | 2021-06-11 12:34:26 +0000 | [diff] [blame] | 300 | // Now remove all module-scope variables with these storage classes. |
| 301 | for (auto* var_ast : ctx.src->AST().GlobalVariables()) { |
| 302 | auto* var_sem = ctx.src->Sem().Get(var_ast); |
| 303 | if (var_sem->StorageClass() == ast::StorageClass::kPrivate || |
| 304 | var_sem->StorageClass() == ast::StorageClass::kWorkgroup || |
| 305 | var_sem->StorageClass() == ast::StorageClass::kUniformConstant) { |
| 306 | ctx.Remove(ctx.src->AST().GlobalDeclarations(), var_ast); |
James Price | 7a47fa8 | 2021-05-26 15:41:02 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Ben Clayton | 701820b | 2021-07-20 18:23:06 +0000 | [diff] [blame] | 311 | Msl::Config::Config(uint32_t buffer_size_ubo_idx, |
| 312 | uint32_t sample_mask, |
| 313 | bool disable_wi) |
James Price | c32e8f6 | 2021-06-22 20:08:29 +0000 | [diff] [blame] | 314 | : buffer_size_ubo_index(buffer_size_ubo_idx), |
Ben Clayton | 701820b | 2021-07-20 18:23:06 +0000 | [diff] [blame] | 315 | fixed_sample_mask(sample_mask), |
| 316 | disable_workgroup_init(disable_wi) {} |
James Price | 960aa2e | 2021-06-19 00:33:35 +0000 | [diff] [blame] | 317 | Msl::Config::Config(const Config&) = default; |
| 318 | Msl::Config::~Config() = default; |
| 319 | |
| 320 | Msl::Result::Result(bool needs_buffer_sizes) |
| 321 | : needs_storage_buffer_sizes(needs_buffer_sizes) {} |
| 322 | Msl::Result::Result(const Result&) = default; |
| 323 | Msl::Result::~Result() = default; |
| 324 | |
Ben Clayton | 2101c35 | 2021-02-10 21:22:03 +0000 | [diff] [blame] | 325 | } // namespace transform |
| 326 | } // namespace tint |