Skip to content

Commit

Permalink
Throw an exception when failing to build a Metal render pipeline stat…
Browse files Browse the repository at this point in the history
…e. (#7878)

Currently, if this fails we log the error message to stderr (which
doesn't get captured by most crash reporting systems) and then crash in
a postcondition assert. By including the error message in an exception
reason and throwing an ObjC exception, we get better discoverability of
error causes.

(Building a render pipeline state from shaders is usually when a shader
actually gets JITted from LLVM IR to GPU-specific code, so if we
accidentally used a feature that's not available on the local GPU, we'll
find out about it here.)
  • Loading branch information
ullerrm authored and bejado committed May 24, 2024
1 parent 11ecaa2 commit 17f32d1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions filament/backend/src/metal/MetalState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@
NSError* error = nullptr;
id<MTLRenderPipelineState> pipeline = [device newRenderPipelineStateWithDescriptor:descriptor
error:&error];
if (error) {
auto description = [error.localizedDescription cStringUsingEncoding:NSUTF8StringEncoding];
if (UTILS_UNLIKELY(pipeline == nil)) {
NSString *errorMessage =
[NSString stringWithFormat:@"Could not create Metal pipeline state: %@",
error ? error.localizedDescription : @"unknown error"];
auto description = [errorMessage cStringUsingEncoding:NSUTF8StringEncoding];
utils::slog.e << description << utils::io::endl;
[[NSException exceptionWithName:@"MetalRenderPipelineFailure"
reason:errorMessage
userInfo:nil] raise];
}
ASSERT_POSTCONDITION(error == nil, "Could not create Metal pipeline state.");

Expand Down

0 comments on commit 17f32d1

Please sign in to comment.