| 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
5 #include "impeller/renderer/backend/metal/shader_function_mtl.h"
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
type
GLenum type
Definition: blit_command_gles.cc:151
impeller::ShaderFunctionMTL::CompileCallback
std::function< void(id< MTLFunction >)> CompileCallback
Definition: shader_function_mtl.h:24
value
int32_t value
Definition: dl_golden_unittests.cc:459
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
std
Definition: comparable.h:95
shader_function_mtl.h