diff --git a/drivers/metal/metal_objects.mm b/drivers/metal/metal_objects.mm index abdcccf00c6..d3c3d2b2327 100644 --- a/drivers/metal/metal_objects.mm +++ b/drivers/metal/metal_objects.mm @@ -560,10 +560,10 @@ void MDCommandBuffer::_render_clear_render_area() { } } uint32_t ds_index = subpass.depth_stencil_reference.attachment; - MDAttachment const &attachment = pass.attachments[ds_index]; - bool shouldClearDepth = (ds_index != RDD::AttachmentReference::UNUSED && attachment.shouldClear(subpass, false)); - bool shouldClearStencil = (ds_index != RDD::AttachmentReference::UNUSED && attachment.shouldClear(subpass, true)); + bool shouldClearDepth = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, false)); + bool shouldClearStencil = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, true)); if (shouldClearDepth || shouldClearStencil) { + MDAttachment const &attachment = pass.attachments[ds_index]; BitField bits; if (shouldClearDepth && attachment.type & MDAttachmentType::Depth) { bits.set_flag(RDD::TEXTURE_ASPECT_DEPTH_BIT);