Skip to content

Commit 1f1389e

Browse files
authored
Metal: avoid crashing for invalid programs (#8321)
1 parent 32abd9e commit 1f1389e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

filament/backend/src/metal/MetalContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct MetalContext {
155155

156156
RenderPassFlags currentRenderPassFlags;
157157
MetalRenderTarget* currentRenderTarget = nullptr;
158+
bool validPipelineBound = false;
158159

159160
// State trackers.
160161
PipelineStateTracker pipelineState;

filament/backend/src/metal/MetalDriver.mm

+7
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@
16571657
// during the draw call when the program is invalid. The shader compile error has already been
16581658
// dumped to the console at this point, so it's fine to simply return early.
16591659
if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!functions)) {
1660+
mContext->validPipelineBound = false;
16601661
return;
16611662
}
16621663

@@ -1789,6 +1790,8 @@
17891790
clamp:0.0];
17901791
mContext->currentPolygonOffset = ps.polygonOffset;
17911792
}
1793+
1794+
mContext->validPipelineBound = true;
17921795
}
17931796

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

1892+
if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!mContext->validPipelineBound)) {
1893+
return;
1894+
}
1895+
18891896
// Bind the offset data.
18901897
if (mContext->dynamicOffsets.isDirty()) {
18911898
const auto [size, data] = mContext->dynamicOffsets.getOffsets();

0 commit comments

Comments
 (0)