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

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
/** Returns a text description of this layout. */
std::string getLogDescription(std::string indent = "");

/** Overridden because pipeline descriptor sets may be marked as discrete and not use an argument buffer. */
bool isUsingMetalArgumentBuffers() override;

/** Constructs an instance for the specified device. */
MVKPipelineLayout(MVKDevice* device, const VkPipelineLayoutCreateInfo* pCreateInfo);

Expand All @@ -98,6 +101,7 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
MVKSmallVector<VkPushConstantRange> _pushConstants;
MVKShaderResourceBinding _mtlResourceCounts;
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
bool _canUseMetalArgumentBuffers;
};


Expand Down
30 changes: 20 additions & 10 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,34 @@
return descStr.str();
}

bool MVKPipelineLayout::isUsingMetalArgumentBuffers() {
return MVKDeviceTrackingMixin::isUsingMetalArgumentBuffers() && _canUseMetalArgumentBuffers;
}

MVKPipelineLayout::MVKPipelineLayout(MVKDevice* device,
const VkPipelineLayoutCreateInfo* pCreateInfo) : MVKVulkanAPIDeviceObject(device) {

_canUseMetalArgumentBuffers = false;
uint32_t dslCnt = pCreateInfo->setLayoutCount;
_descriptorSetLayouts.reserve(dslCnt);
for (uint32_t i = 0; i < dslCnt; i++) {
MVKDescriptorSetLayout* pDescSetLayout = (MVKDescriptorSetLayout*)pCreateInfo->pSetLayouts[i];
pDescSetLayout->retain();
_descriptorSetLayouts.push_back(pDescSetLayout);
_canUseMetalArgumentBuffers = _canUseMetalArgumentBuffers || pDescSetLayout->isUsingMetalArgumentBuffers();
}

billhollings marked this conversation as resolved.
Show resolved Hide resolved
// For pipeline layout compatibility (“compatible for set N”),
// consume the Metal resource indexes in this order:
// - Fixed count of argument buffers for descriptor sets (if using Metal argument buffers).
// - An argument buffer for each descriptor set (if using Metal argument buffers).
// - Push constants
// - Descriptor set content

// If we are using Metal argument buffers, consume a fixed number
// of buffer indexes for the Metal argument buffers themselves.
// If we are using Metal argument buffers, consume a number of
// buffer indexes covering all descriptor sets for the Metal
// argument buffers themselves.
if (isUsingMetalArgumentBuffers()) {
_mtlResourceCounts.addArgumentBuffers(kMVKMaxDescriptorSetCount);
_mtlResourceCounts.addArgumentBuffers(dslCnt);
}

// Add push constants from config
Expand All @@ -172,13 +187,8 @@

// Add descriptor set layouts, accumulating the resource index offsets used by the corresponding DSL,
// and associating the current accumulated resource index offsets with each DSL as it is added.
uint32_t dslCnt = pCreateInfo->setLayoutCount;
_descriptorSetLayouts.reserve(dslCnt);
for (uint32_t i = 0; i < dslCnt; i++) {
MVKDescriptorSetLayout* pDescSetLayout = (MVKDescriptorSetLayout*)pCreateInfo->pSetLayouts[i];
pDescSetLayout->retain();
_descriptorSetLayouts.push_back(pDescSetLayout);

MVKDescriptorSetLayout* pDescSetLayout = _descriptorSetLayouts[i];
billhollings marked this conversation as resolved.
Show resolved Hide resolved
MVKShaderResourceBinding adjstdDSLRezOfsts = _mtlResourceCounts;
MVKShaderResourceBinding adjstdDSLRezCnts = pDescSetLayout->_mtlResourceCounts;
if (pDescSetLayout->isUsingMetalArgumentBuffers()) {
Expand Down