Skip to content

Commit

Permalink
Fix a couple depthClamp issues on metal
Browse files Browse the repository at this point in the history
- depthClamp is only supported from iOS 11.0
- reset the depthClamp state at the beginning of the renderpass


BUGS=[379729888]
  • Loading branch information
pixelflinger committed Dec 5, 2024
1 parent 8088db6 commit b48a155
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 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 @@ -135,6 +135,7 @@ struct MetalContext {
bool supportsTextureSwizzling = false;
bool supportsAutoDepthResolve = false;
bool supportsMemorylessRenderTargets = false;
bool supportsDepthClamp = false;
uint8_t maxColorRenderTargets = 4;
struct {
uint8_t common;
Expand Down
18 changes: 13 additions & 5 deletions filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
mContext->highestSupportedGpuFamily.mac >= 2; // newer macOS GPUs
}

mContext->supportsDepthClamp = false;
if (@available(macOS 10.11, iOS 11.0, *)) {
mContext->supportsDepthClamp = true;
}

// In order to support resolve store action on depth attachment, the GPU needs to support it.
// Note that support for depth resolve implies support for stencil resolve using .sample0 resolve filter.
// (Other resolve filters are supported starting .apple5 and .mac2 families).
Expand Down Expand Up @@ -1063,7 +1068,7 @@
}

bool MetalDriver::isDepthClampSupported() {
return true;
return mContext->supportsDepthClamp;
}

bool MetalDriver::isWorkaroundNeeded(Workaround workaround) {
Expand Down Expand Up @@ -1258,6 +1263,7 @@
mContext->cullModeState.invalidate();
mContext->windingState.invalidate();
mContext->scissorRectState.invalidate();
mContext->depthClampState.invalidate();
mContext->currentPolygonOffset = {0.0f, 0.0f};

mContext->finalizedDescriptorSets.clear();
Expand Down Expand Up @@ -1729,10 +1735,12 @@
}

// depth clip mode
MTLDepthClipMode depthClipMode = rs.depthClamp ? MTLDepthClipModeClamp : MTLDepthClipModeClip;
mContext->depthClampState.updateState(depthClipMode);
if (mContext->depthClampState.stateChanged()) {
[mContext->currentRenderPassEncoder setDepthClipMode:depthClipMode];
if (mContext->supportsDepthClamp) {
MTLDepthClipMode depthClipMode = rs.depthClamp ? MTLDepthClipModeClamp : MTLDepthClipModeClip;
mContext->depthClampState.updateState(depthClipMode);
if (mContext->depthClampState.stateChanged()) {
[mContext->currentRenderPassEncoder setDepthClipMode:depthClipMode];
}
}

// Set the depth-stencil state, if a state change is needed.
Expand Down

0 comments on commit b48a155

Please sign in to comment.