Skip to content

Commit 32043fc

Browse files
committed
Metal: Fix crash when clearing render buffers
1 parent 4a44078 commit 32043fc

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

drivers/metal/metal_objects.mm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,18 @@
602602
bool clear_stencil = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, true));
603603

604604
uint32_t color_count = subpass.color_references.size();
605-
uint32_t clear_count = color_count + (clear_depth || clear_stencil ? 1 : 0);
606-
if (clear_count == 0) {
605+
uint32_t clears_size = color_count + (clear_depth || clear_stencil ? 1 : 0);
606+
if (clears_size == 0) {
607607
return;
608608
}
609609

610-
RDD::AttachmentClear *clears = ALLOCA_ARRAY(RDD::AttachmentClear, clear_count);
611-
uint32_t clears_idx = 0;
610+
RDD::AttachmentClear *clears = ALLOCA_ARRAY(RDD::AttachmentClear, clears_size);
611+
uint32_t clears_count = 0;
612612

613613
for (uint32_t i = 0; i < color_count; i++) {
614614
uint32_t idx = subpass.color_references[i].attachment;
615615
if (idx != RDD::AttachmentReference::UNUSED && pass.attachments[idx].shouldClear(subpass, false)) {
616-
clears[clears_idx++] = { .aspect = RDD::TEXTURE_ASPECT_COLOR_BIT, .color_attachment = idx, .value = render.clear_values[idx] };
616+
clears[clears_count++] = { .aspect = RDD::TEXTURE_ASPECT_COLOR_BIT, .color_attachment = idx, .value = render.clear_values[idx] };
617617
}
618618
}
619619

@@ -627,10 +627,14 @@
627627
bits.set_flag(RDD::TEXTURE_ASPECT_STENCIL_BIT);
628628
}
629629

630-
clears[clears_idx++] = { .aspect = bits, .color_attachment = ds_index, .value = render.clear_values[ds_index] };
630+
clears[clears_count++] = { .aspect = bits, .color_attachment = ds_index, .value = render.clear_values[ds_index] };
631631
}
632632

633-
render_clear_attachments(VectorView(clears, clear_count), { render.render_area });
633+
if (clears_count == 0) {
634+
return;
635+
}
636+
637+
render_clear_attachments(VectorView(clears, clears_count), { render.render_area });
634638
}
635639

636640
void MDCommandBuffer::render_next_subpass() {

0 commit comments

Comments
 (0)