Skip to content

Commit

Permalink
Metal: avoid crashing for invalid programs (#8321)
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado authored Dec 19, 2024
1 parent 32abd9e commit 1f1389e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions filament/backend/src/metal/MetalContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ struct MetalContext {

RenderPassFlags currentRenderPassFlags;
MetalRenderTarget* currentRenderTarget = nullptr;
bool validPipelineBound = false;

// State trackers.
PipelineStateTracker pipelineState;
Expand Down
7 changes: 7 additions & 0 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,7 @@
// during the draw call when the program is invalid. The shader compile error has already been
// dumped to the console at this point, so it's fine to simply return early.
if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!functions)) {
mContext->validPipelineBound = false;
return;
}

Expand Down Expand Up @@ -1789,6 +1790,8 @@
clamp:0.0];
mContext->currentPolygonOffset = ps.polygonOffset;
}

mContext->validPipelineBound = true;
}

void MetalDriver::bindRenderPrimitive(Handle<HwRenderPrimitive> rph) {
Expand Down Expand Up @@ -1886,6 +1889,10 @@
<< "draw() without a valid command encoder.";
DEBUG_LOG("draw2(...)\n");

if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!mContext->validPipelineBound)) {
return;
}

// Bind the offset data.
if (mContext->dynamicOffsets.isDirty()) {
const auto [size, data] = mContext->dynamicOffsets.getOffsets();
Expand Down

0 comments on commit 1f1389e

Please sign in to comment.