Skip to content

Commit 2473ce6

Browse files
authored
Merge pull request KhronosGroup#2417 from squidbus/arg-buf-binding
Reduce number of unused pipeline bindings reserved for argument buffers.
2 parents 3803cc9 + 29def23 commit 2473ce6

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
8282
/** Returns a text description of this layout. */
8383
std::string getLogDescription(std::string indent = "");
8484

85+
/** Overridden because pipeline descriptor sets may be marked as discrete and not use an argument buffer. */
86+
bool isUsingMetalArgumentBuffers() override;
87+
8588
/** Constructs an instance for the specified device. */
8689
MVKPipelineLayout(MVKDevice* device, const VkPipelineLayoutCreateInfo* pCreateInfo);
8790

@@ -98,6 +101,7 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject {
98101
MVKSmallVector<VkPushConstantRange> _pushConstants;
99102
MVKShaderResourceBinding _mtlResourceCounts;
100103
MVKShaderResourceBinding _pushConstantsMTLResourceIndexes;
104+
bool _canUseMetalArgumentBuffers;
101105
};
102106

103107

MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,34 @@
141141
return descStr.str();
142142
}
143143

144+
bool MVKPipelineLayout::isUsingMetalArgumentBuffers() {
145+
return MVKDeviceTrackingMixin::isUsingMetalArgumentBuffers() && _canUseMetalArgumentBuffers;
146+
}
147+
144148
MVKPipelineLayout::MVKPipelineLayout(MVKDevice* device,
145149
const VkPipelineLayoutCreateInfo* pCreateInfo) : MVKVulkanAPIDeviceObject(device) {
146150

151+
_canUseMetalArgumentBuffers = false;
152+
uint32_t dslCnt = pCreateInfo->setLayoutCount;
153+
_descriptorSetLayouts.reserve(dslCnt);
154+
for (uint32_t i = 0; i < dslCnt; i++) {
155+
MVKDescriptorSetLayout* pDescSetLayout = (MVKDescriptorSetLayout*)pCreateInfo->pSetLayouts[i];
156+
pDescSetLayout->retain();
157+
_descriptorSetLayouts.push_back(pDescSetLayout);
158+
_canUseMetalArgumentBuffers = _canUseMetalArgumentBuffers || pDescSetLayout->isUsingMetalArgumentBuffers();
159+
}
160+
147161
// For pipeline layout compatibility (“compatible for set N”),
148162
// consume the Metal resource indexes in this order:
149-
// - Fixed count of argument buffers for descriptor sets (if using Metal argument buffers).
163+
// - An argument buffer for each descriptor set (if using Metal argument buffers).
150164
// - Push constants
151165
// - Descriptor set content
152166

153-
// If we are using Metal argument buffers, consume a fixed number
154-
// of buffer indexes for the Metal argument buffers themselves.
167+
// If we are using Metal argument buffers, consume a number of
168+
// buffer indexes covering all descriptor sets for the Metal
169+
// argument buffers themselves.
155170
if (isUsingMetalArgumentBuffers()) {
156-
_mtlResourceCounts.addArgumentBuffers(kMVKMaxDescriptorSetCount);
171+
_mtlResourceCounts.addArgumentBuffers(dslCnt);
157172
}
158173

159174
// Add push constants from config
@@ -172,13 +187,8 @@
172187

173188
// Add descriptor set layouts, accumulating the resource index offsets used by the corresponding DSL,
174189
// and associating the current accumulated resource index offsets with each DSL as it is added.
175-
uint32_t dslCnt = pCreateInfo->setLayoutCount;
176-
_descriptorSetLayouts.reserve(dslCnt);
177190
for (uint32_t i = 0; i < dslCnt; i++) {
178-
MVKDescriptorSetLayout* pDescSetLayout = (MVKDescriptorSetLayout*)pCreateInfo->pSetLayouts[i];
179-
pDescSetLayout->retain();
180-
_descriptorSetLayouts.push_back(pDescSetLayout);
181-
191+
MVKDescriptorSetLayout* pDescSetLayout = _descriptorSetLayouts[i];
182192
MVKShaderResourceBinding adjstdDSLRezOfsts = _mtlResourceCounts;
183193
MVKShaderResourceBinding adjstdDSLRezCnts = pDescSetLayout->_mtlResourceCounts;
184194
if (pDescSetLayout->isUsingMetalArgumentBuffers()) {

0 commit comments

Comments
 (0)