Fix runtime shader loading.
This commit is contained in:
@@ -19,10 +19,12 @@ executable("host") {
|
||||
sources = [
|
||||
"ShaderTypes.h",
|
||||
"impeller_host_view_controller.h",
|
||||
"impeller_host_view_controller.m",
|
||||
"impeller_host_view_controller.mm",
|
||||
"impeller_renderer.h",
|
||||
"impeller_renderer.m",
|
||||
"main.m",
|
||||
"impeller_renderer.mm",
|
||||
"main.mm",
|
||||
"shaders_location.cc",
|
||||
"shaders_location.h",
|
||||
]
|
||||
|
||||
libs = [
|
||||
@@ -34,6 +36,7 @@ executable("host") {
|
||||
|
||||
deps = [
|
||||
":impeller_host_shaders",
|
||||
"//flutter/fml",
|
||||
"//flutter/impeller/impeller",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#import <ModelIO/ModelIO.h>
|
||||
#import <simd/simd.h>
|
||||
|
||||
#include "flutter/fml/logging.h"
|
||||
#import "impeller_renderer.h"
|
||||
#import "shaders_location.h"
|
||||
|
||||
// Include header shared between C code here, which executes Metal API commands,
|
||||
// and .metal files
|
||||
@@ -82,7 +84,16 @@ static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100;
|
||||
_mtlVertexDescriptor.layouts[BufferIndexMeshGenerics].stepFunction =
|
||||
MTLVertexStepFunctionPerVertex;
|
||||
|
||||
id<MTLLibrary> defaultLibrary = [_device newDefaultLibrary];
|
||||
auto shader_library_path =
|
||||
impeller::ImpellerShadersLocation("impeller_host.metallib");
|
||||
|
||||
FML_CHECK(shader_library_path.has_value());
|
||||
|
||||
NSError* shader_library_error = nil;
|
||||
|
||||
id<MTLLibrary> defaultLibrary =
|
||||
[_device newLibraryWithFile:@(shader_library_path.value().c_str())
|
||||
error:&shader_library_error];
|
||||
|
||||
id<MTLFunction> vertexFunction =
|
||||
[defaultLibrary newFunctionWithName:@"vertexShader"];
|
||||
31
engine/src/flutter/impeller/host/shaders_location.cc
Normal file
31
engine/src/flutter/impeller/host/shaders_location.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "shaders_location.h"
|
||||
|
||||
#include "flutter/fml/file.h"
|
||||
#include "flutter/fml/paths.h"
|
||||
|
||||
namespace impeller {
|
||||
|
||||
std::optional<std::string> ImpellerShadersLocation(std::string library_name) {
|
||||
auto executable_directory = fml::paths::GetExecutableDirectoryPath();
|
||||
|
||||
if (!executable_directory.first) {
|
||||
FML_LOG(ERROR) << "Shaders directory could not be found.";
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto path = fml::paths::JoinPaths(
|
||||
{executable_directory.second, "shaders", library_name});
|
||||
|
||||
if (!fml::IsFile(path)) {
|
||||
FML_LOG(ERROR) << "The shader library does not exist: " << path;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
12
engine/src/flutter/impeller/host/shaders_location.h
Normal file
12
engine/src/flutter/impeller/host/shaders_location.h
Normal file
@@ -0,0 +1,12 @@
|
||||
// Copyright 2013 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace impeller {
|
||||
|
||||
std::optional<std::string> ImpellerShadersLocation(std::string library_name);
|
||||
|
||||
} // namespace impeller
|
||||
@@ -11,7 +11,7 @@ template("metal_library") {
|
||||
action("$target_name") {
|
||||
inputs = invoker.sources
|
||||
|
||||
metal_library_path = "$target_out_dir/shaders/$metal_library_name.metallib"
|
||||
metal_library_path = "$root_out_dir/shaders/$metal_library_name.metallib"
|
||||
|
||||
outputs = [ metal_library_path ]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user