Allow vertex buffer binding when they are used disregarding implicit index

Due to how MoltenVK decides when a buffer can be bound based on
its requirements for the implicit buffer, if the application uses
all bindings, implicit buffer index will be uint max. This lead
to used buffers not being bound.
This commit is contained in:
Aitor Camacho 2024-05-01 15:57:16 +02:00
parent 0d62a427d4
commit bd24db8553
2 changed files with 4 additions and 1 deletions

View File

@ -430,6 +430,8 @@ protected:
uint32_t _tessCtlPatchOutputBufferIndex = 0; uint32_t _tessCtlPatchOutputBufferIndex = 0;
uint32_t _tessCtlLevelBufferIndex = 0; uint32_t _tessCtlLevelBufferIndex = 0;
static constexpr uint32_t _maxVertexInputBindingBufferCount = 31u; // Taken from Metal Feature Set Table. Highest value out of all present GPUs
bool _isVertexInputBindingUsed[_maxVertexInputBindingBufferCount] = { false };
bool _primitiveRestartEnable = true; bool _primitiveRestartEnable = true;
bool _hasRasterInfo = false; bool _hasRasterInfo = false;
bool _needsVertexSwizzleBuffer = false; bool _needsVertexSwizzleBuffer = false;

View File

@ -1414,6 +1414,7 @@ bool MVKGraphicsPipeline::addVertexInputToPipeline(T* inputDesc,
maxBinding = max(pVKVB->binding, maxBinding); maxBinding = max(pVKVB->binding, maxBinding);
uint32_t vbIdx = getMetalBufferIndexForVertexAttributeBinding(pVKVB->binding); uint32_t vbIdx = getMetalBufferIndexForVertexAttributeBinding(pVKVB->binding);
_isVertexInputBindingUsed[vbIdx] = true;
auto vbDesc = inputDesc.layouts[vbIdx]; auto vbDesc = inputDesc.layouts[vbIdx];
if (isVtxStrideStatic && pVKVB->stride == 0) { if (isVtxStrideStatic && pVKVB->stride == 0) {
// Stride can't be 0, it will be set later to attributes' maximum offset + size // Stride can't be 0, it will be set later to attributes' maximum offset + size
@ -1840,7 +1841,7 @@ void MVKGraphicsPipeline::initReservedVertexAttributeBufferCount(const VkGraphic
} }
bool MVKGraphicsPipeline::isValidVertexBufferIndex(MVKShaderStage stage, uint32_t mtlBufferIndex) { bool MVKGraphicsPipeline::isValidVertexBufferIndex(MVKShaderStage stage, uint32_t mtlBufferIndex) {
return mtlBufferIndex < _descriptorBufferCounts.stages[stage] || mtlBufferIndex > getImplicitBufferIndex(stage, 0); return _isVertexInputBindingUsed[mtlBufferIndex] || mtlBufferIndex < _descriptorBufferCounts.stages[stage] || mtlBufferIndex > getImplicitBufferIndex(stage, 0);
} }
// Initializes the vertex attributes in a shader conversion configuration. // Initializes the vertex attributes in a shader conversion configuration.