A couple optimizations to Metal Shader Pipeline
- Don't create an empty options object just to destroy it. - Don't copy the shader source into the NSString. - Allow UTF-8 shader source, not just ASCII. Change-Id: Ic15ba5d315e42875e6db43af086c23a905c1dac4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/312837 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
0baaa23722
commit
595f7b4172
@ -89,26 +89,27 @@ id<MTLLibrary> GrGenerateMtlShaderLibrary(const GrMtlGpu* gpu,
|
||||
|
||||
id<MTLLibrary> GrCompileMtlShaderLibrary(const GrMtlGpu* gpu,
|
||||
const SkSL::String& shaderString) {
|
||||
NSString* mtlCode = [[NSString alloc] initWithCString: shaderString.c_str()
|
||||
encoding: NSASCIIStringEncoding];
|
||||
auto nsSource = [[NSString alloc] initWithBytesNoCopy:const_cast<char*>(shaderString.c_str())
|
||||
length:shaderString.size()
|
||||
encoding:NSUTF8StringEncoding
|
||||
freeWhenDone:NO];
|
||||
#if PRINT_MSL
|
||||
print_msl([mtlCode cStringUsingEncoding: NSASCIIStringEncoding]);
|
||||
print_msl(nsSource.UTF8String);
|
||||
#endif
|
||||
|
||||
MTLCompileOptions* defaultOptions = [[MTLCompileOptions alloc] init];
|
||||
NSError* error = nil;
|
||||
#if defined(SK_BUILD_FOR_MAC)
|
||||
id<MTLLibrary> compiledLibrary = GrMtlNewLibraryWithSource(gpu->device(), mtlCode,
|
||||
defaultOptions, &error);
|
||||
id<MTLLibrary> compiledLibrary = GrMtlNewLibraryWithSource(gpu->device(), nsSource,
|
||||
nil, &error);
|
||||
#else
|
||||
id<MTLLibrary> compiledLibrary = [gpu->device() newLibraryWithSource: mtlCode
|
||||
options: defaultOptions
|
||||
error: &error];
|
||||
id<MTLLibrary> compiledLibrary = [gpu->device() newLibraryWithSource:nsSource
|
||||
options:nil
|
||||
error:&error];
|
||||
#endif
|
||||
if (!compiledLibrary) {
|
||||
SkDebugf("Error compiling MSL shader: %s\n%s\n",
|
||||
shaderString.c_str(),
|
||||
[[error localizedDescription] cStringUsingEncoding: NSASCIIStringEncoding]);
|
||||
error.debugDescription.UTF8String);
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user