Flutter Impeller
shader_function_mtl.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 namespace impeller {
8 
9 ShaderFunctionMTL::ShaderFunctionMTL(UniqueID parent_library_id,
10  id<MTLFunction> function,
11  id<MTLLibrary> library,
12  std::string name,
13  ShaderStage stage)
14  : ShaderFunction(parent_library_id, std::move(name), stage),
15  function_(function),
16  library_(library) {}
17 
18 ShaderFunctionMTL::~ShaderFunctionMTL() = default;
19 
20 void ShaderFunctionMTL::GetMTLFunctionSpecialized(
21  const std::vector<Scalar>& constants,
22  const CompileCallback& callback) const {
23  MTLFunctionConstantValues* constantValues =
24  [[MTLFunctionConstantValues alloc] init];
25  size_t index = 0;
26  for (const auto value : constants) {
27  Scalar copied_value = value;
28  [constantValues setConstantValue:&copied_value
29  type:MTLDataTypeFloat
30  atIndex:index];
31  index++;
32  }
33  CompileCallback callback_value = callback;
34  [library_ newFunctionWithName:@(GetName().data())
35  constantValues:constantValues
36  completionHandler:^(id<MTLFunction> _Nullable function,
37  NSError* _Nullable error) {
38  callback_value(function);
39  }];
40 }
41 
42 id<MTLFunction> ShaderFunctionMTL::GetMTLFunction() const {
43  return function_;
44 }
45 
46 } // namespace impeller
GLenum type
std::function< void(id< MTLFunction >)> CompileCallback
int32_t value
float Scalar
Definition: scalar.h:19
Definition: comparable.h:95