Skip to content

Commit

Permalink
Merge pull request #1918 from billhollings/accumulate-render-stages
Browse files Browse the repository at this point in the history
Accumulate render stages when a resource is used by multiple descriptor bindings.
  • Loading branch information
billhollings authored May 23, 2023
2 parents a832e38 + b863ece commit 3d7f996
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Released 2023/05/23
large for `MTLCounterSampleBuffer`, and fall back to emulation via CPU timestamps.
- Ensure shaders that use `PhysicalStorageBufferAddresses` encode the use of the associated `MTLBuffer`.
- Disable pipeline cache compression prior to macOS 10.15 and iOS/tvOS 13.0.
- Accumulate render stages when a resource is used by multiple descriptor bindings.
- Respect the bind point supplied to `vkCmdBindDescriptorSets()` / `vkCmdPushDescriptorSets()`.
- Check if shader compiled before adding it to a pipeline, to avoid Metal validation error.
- Identify each unsupported device feature flag that the app attempts to enable.
Expand Down
3 changes: 3 additions & 0 deletions MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.h
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ class MVKGraphicsResourcesCommandEncoderState : public MVKResourcesCommandEncode
/** Marks any overridden buffer indexes as dirty. */
void markOverriddenBufferIndexesDirty();

void endMetalRenderPass() override;

void markDirty() override;

#pragma mark Construction
Expand All @@ -577,6 +579,7 @@ class MVKGraphicsResourcesCommandEncoderState : public MVKResourcesCommandEncode
void bindMetalArgumentBuffer(MVKShaderStage stage, MVKMTLBufferBinding& buffBind) override;

ResourceBindings<8> _shaderStageResourceBindings[kMVKShaderStageFragment + 1];
std::unordered_map<id<MTLResource>, MTLRenderStages> _renderUsageStages;
};


Expand Down
12 changes: 11 additions & 1 deletion MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@
}
}

void MVKGraphicsResourcesCommandEncoderState::endMetalRenderPass() {
MVKResourcesCommandEncoderState::endMetalRenderPass();
_renderUsageStages.clear();
}

// Mark everything as dirty
void MVKGraphicsResourcesCommandEncoderState::markDirty() {
MVKResourcesCommandEncoderState::markDirty();
Expand Down Expand Up @@ -976,7 +981,12 @@
} else {
auto* mtlRendEnc = _cmdEncoder->_mtlRenderEncoder;
if ([mtlRendEnc respondsToSelector: @selector(useResource:usage:stages:)]) {
[mtlRendEnc useResource: mtlResource usage: mtlUsage stages: mtlStages];
// Within a renderpass, a resource may be used by multiple descriptor bindings,
// each of which may assign a different usage stage. Dynamically accumulate
// usage stages across all descriptor bindings using the resource.
auto& accumStages = _renderUsageStages[mtlResource];
accumStages |= mtlStages;
[mtlRendEnc useResource: mtlResource usage: mtlUsage stages: accumStages];
} else {
[mtlRendEnc useResource: mtlResource usage: mtlUsage];
}
Expand Down

0 comments on commit 3d7f996

Please sign in to comment.