|
597 | 597 | MDRenderPass const &pass = *render.pass; |
598 | 598 | MDSubpass const &subpass = render.get_subpass(); |
599 | 599 |
|
600 | | - // First determine attachments that should be cleared. |
601 | | - LocalVector<RDD::AttachmentClear> clears; |
602 | | - clears.reserve(subpass.color_references.size() + /* possible depth stencil clear */ 1); |
| 600 | + uint32_t ds_index = subpass.depth_stencil_reference.attachment; |
| 601 | + bool clear_depth = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, false)); |
| 602 | + bool clear_stencil = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, true)); |
603 | 603 |
|
604 | | - for (uint32_t i = 0; i < subpass.color_references.size(); i++) { |
| 604 | + 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) { |
| 607 | + return; |
| 608 | + } |
| 609 | + |
| 610 | + RDD::AttachmentClear *clears = ALLOCA_ARRAY(RDD::AttachmentClear, clear_count); |
| 611 | + uint32_t clears_idx = 0; |
| 612 | + |
| 613 | + for (uint32_t i = 0; i < color_count; i++) { |
605 | 614 | uint32_t idx = subpass.color_references[i].attachment; |
606 | 615 | if (idx != RDD::AttachmentReference::UNUSED && pass.attachments[idx].shouldClear(subpass, false)) { |
607 | | - clears.push_back({ .aspect = RDD::TEXTURE_ASPECT_COLOR_BIT, .color_attachment = idx, .value = render.clear_values[idx] }); |
| 616 | + clears[clears_idx++] = { .aspect = RDD::TEXTURE_ASPECT_COLOR_BIT, .color_attachment = idx, .value = render.clear_values[idx] }; |
608 | 617 | } |
609 | 618 | } |
610 | | - uint32_t ds_index = subpass.depth_stencil_reference.attachment; |
611 | | - bool shouldClearDepth = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, false)); |
612 | | - bool shouldClearStencil = (ds_index != RDD::AttachmentReference::UNUSED && pass.attachments[ds_index].shouldClear(subpass, true)); |
613 | | - if (shouldClearDepth || shouldClearStencil) { |
| 619 | + |
| 620 | + if (clear_depth || clear_stencil) { |
614 | 621 | MDAttachment const &attachment = pass.attachments[ds_index]; |
615 | 622 | BitField<RDD::TextureAspectBits> bits = {}; |
616 | | - if (shouldClearDepth && attachment.type & MDAttachmentType::Depth) { |
| 623 | + if (clear_depth && attachment.type & MDAttachmentType::Depth) { |
617 | 624 | bits.set_flag(RDD::TEXTURE_ASPECT_DEPTH_BIT); |
618 | 625 | } |
619 | | - if (shouldClearStencil && attachment.type & MDAttachmentType::Stencil) { |
| 626 | + if (clear_stencil && attachment.type & MDAttachmentType::Stencil) { |
620 | 627 | bits.set_flag(RDD::TEXTURE_ASPECT_STENCIL_BIT); |
621 | 628 | } |
622 | 629 |
|
623 | | - clears.push_back({ .aspect = bits, .color_attachment = ds_index, .value = render.clear_values[ds_index] }); |
624 | | - } |
625 | | - |
626 | | - if (clears.is_empty()) { |
627 | | - return; |
| 630 | + clears[clears_idx++] = { .aspect = bits, .color_attachment = ds_index, .value = render.clear_values[ds_index] }; |
628 | 631 | } |
629 | 632 |
|
630 | | - render_clear_attachments(clears, { render.render_area }); |
| 633 | + render_clear_attachments(VectorView(clears, clear_count), { render.render_area }); |
631 | 634 | } |
632 | 635 |
|
633 | 636 | void MDCommandBuffer::render_next_subpass() { |
|
1448 | 1451 |
|
1449 | 1452 | for (uint32_t i = 0; i < uniforms.size(); i++) { |
1450 | 1453 | RDD::BoundUniform const &uniform = uniforms[i]; |
1451 | | - UniformInfo ui = set.uniforms[i]; |
| 1454 | + const UniformInfo &ui = set.uniforms[i]; |
1452 | 1455 |
|
1453 | | - BindingInfo *bi = ui.bindings.getptr(stage); |
| 1456 | + const BindingInfo *bi = ui.bindings.getptr(stage); |
1454 | 1457 | if (bi == nullptr) { |
1455 | 1458 | // No binding for this stage. |
1456 | 1459 | continue; |
|
1481 | 1484 | textures[j] = texture; |
1482 | 1485 | add_usage(texture, stage, bi->usage); |
1483 | 1486 | } |
1484 | | - BindingInfo *sbi = ui.bindings_secondary.getptr(stage); |
| 1487 | + const BindingInfo *sbi = ui.bindings_secondary.getptr(stage); |
1485 | 1488 | if (sbi) { |
1486 | 1489 | [enc setSamplerStates:samplers withRange:NSMakeRange(sbi->index, count)]; |
1487 | 1490 | } |
|
1510 | 1513 | id<MTLTexture> obj = rid::get(uniform.ids[0]); |
1511 | 1514 | [enc setTexture:obj atIndex:bi->index]; |
1512 | 1515 | add_usage(obj, stage, bi->usage); |
1513 | | - BindingInfo *sbi = ui.bindings_secondary.getptr(stage); |
| 1516 | + const BindingInfo *sbi = ui.bindings_secondary.getptr(stage); |
1514 | 1517 | if (sbi) { |
1515 | 1518 | id<MTLTexture> tex = obj.parentTexture ? obj.parentTexture : obj; |
1516 | 1519 | id<MTLBuffer> buf = tex.buffer; |
@@ -1976,7 +1979,7 @@ + (instancetype)newLibraryWithCacheEntry:(ShaderCacheEntry *)entry |
1976 | 1979 | options:(MTLCompileOptions *)options |
1977 | 1980 | strategy:(ShaderLoadStrategy)strategy { |
1978 | 1981 | switch (strategy) { |
1979 | | - case ShaderLoadStrategy::DEFAULT: |
| 1982 | + case ShaderLoadStrategy::IMMEDIATE: |
1980 | 1983 | [[fallthrough]]; |
1981 | 1984 | default: |
1982 | 1985 | return [[MDImmediateLibrary alloc] initWithCacheEntry:entry device:device source:source options:options]; |
|
0 commit comments