| 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
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::ShaderFunctionMTL::GetMTLFunctionSpecialized
void GetMTLFunctionSpecialized(const std::vector< Scalar > &constants, const CompileCallback &callback) const
Definition: shader_function_mtl.mm:20
shader_function_mtl.h
impeller::ShaderFunctionMTL::~ShaderFunctionMTL
~ShaderFunctionMTL() override
impeller::ShaderFunctionMTL::GetMTLFunction
id< MTLFunction > GetMTLFunction() const
Definition: shader_function_mtl.mm:42
impeller::ShaderFunctionMTL::CompileCallback
std::function< void(id< MTLFunction >)> CompileCallback
Definition: shader_function_mtl.h:25
impeller::ShaderFunction::GetName
const std::string & GetName() const
Definition: shader_function.cc:22
std
Definition: comparable.h:95
impeller
Definition: aiks_blur_unittests.cc:20