From 1f1389e668e83e1041096d4acc493428d462375b Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Thu, 19 Dec 2024 10:00:51 -0800 Subject: [PATCH] Metal: avoid crashing for invalid programs (#8321) --- filament/backend/src/metal/MetalContext.h | 1 + filament/backend/src/metal/MetalDriver.mm | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/filament/backend/src/metal/MetalContext.h b/filament/backend/src/metal/MetalContext.h index 15843515082..f85e08545bf 100644 --- a/filament/backend/src/metal/MetalContext.h +++ b/filament/backend/src/metal/MetalContext.h @@ -155,6 +155,7 @@ struct MetalContext { RenderPassFlags currentRenderPassFlags; MetalRenderTarget* currentRenderTarget = nullptr; + bool validPipelineBound = false; // State trackers. PipelineStateTracker pipelineState; diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index d787c0cdb26..5bc2002ec7e 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -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; } @@ -1789,6 +1790,8 @@ clamp:0.0]; mContext->currentPolygonOffset = ps.polygonOffset; } + + mContext->validPipelineBound = true; } void MetalDriver::bindRenderPrimitive(Handle rph) { @@ -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();