Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce number of unused pipeline bindings reserved for argument buffers. #2417

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

squidbus
Copy link
Contributor

@squidbus squidbus commented Jan 6, 2025

  • Checks if any descriptor set layouts bound to a pipeline layout are actually using argument buffers before reserving any indices to bind them.
  • Reduces the number of reserved indices for argument buffers to only the number of descriptor sets.

I was hitting limits on number of bind indices available because a fixed 8 are always reserved for argument buffers, even with only a single descriptor set using push descriptors (which do not use argument buffers). Mainly when tessellation is involved, it was unable to reserve indices for the output buffer.

Please let me know if there's anything I'm missing with this approach, I tested it in my application both as-is and with push descriptors disabled, and it seems to work fine.

Side note: It may be worth modifying the maxPushDescriptors property based on the number of potential reserved bindings needed, as it's what I use to determine whether to use push descriptors or not for a pipeline descriptor set layout. Advertising with the max possible number when in reality some may be taken away for argument buffers and other internal bindings can cause problems that could be avoided if the application knew to avoid using as many push descriptors. But I didn't delve into that in this PR.

Copy link
Contributor

@billhollings billhollings left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! Makes a lot of sense.

And I'm an impressed at how simple the change was (ie. not triggering side-effects elsewhere).

I've made some inline recommendations about simplifying the change even more.

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm Outdated Show resolved Hide resolved
_descriptorSetLayouts.push_back(pDescSetLayout);
_canUseMetalArgumentBuffers = _canUseMetalArgumentBuffers || pDescSetLayout->isUsingMetalArgumentBuffers();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than setting dslCnt for use in place of kMVKMaxDescriptorSetCount, is there a reason all this code was moved from where it was?

The only change in the loop itself seems to be setting _canUseMetalArgumentBuffers, but I don't see _canUseMetalArgumentBuffers used anywhere before the location of the original code.

And we seem to have ended up with two loops iterating the same data.

My preference would be to leave this code where it was, add the setting of _canUseMetalArgumentBuffers there, and either set dslCnt up here, or simply use pCreateInfo->setLayoutCount in place of kMVKMaxDescriptorSetCount below, and leave dslCnt where it was just being used to clarify the loop test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it calls isUsingMetalArgumentBuffers() right below this, it takes into account the value of _canUseMetalArgumentBuffers, so it needs to be known to reserve the right number of buffers. And then the push constants part and second loop below that needs to know how many buffers were reserved for descriptor sets, so we can't just move those down either.

Do you have any particular alternate preference for how to organize the code based on these constraints?

pDescSetLayout->retain();
_descriptorSetLayouts.push_back(pDescSetLayout);

MVKDescriptorSetLayout* pDescSetLayout = _descriptorSetLayouts[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my suggestion about this code above. This line (and the second looping) won't be needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants