Skip to content

Commit

Permalink
Allow vertex buffer binding when they are used disregarding implicit …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
aitor-lunarg committed May 1, 2024
1 parent 0d62a42 commit bd24db8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ class MVKGraphicsPipeline : public MVKPipeline {
uint32_t _tessCtlPatchOutputBufferIndex = 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 _hasRasterInfo = false;
bool _needsVertexSwizzleBuffer = false;
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3

maxBinding = max(pVKVB->binding, maxBinding);
uint32_t vbIdx = getMetalBufferIndexForVertexAttributeBinding(pVKVB->binding);
_isVertexInputBindingUsed[vbIdx] = true;
auto vbDesc = inputDesc.layouts[vbIdx];
if (isVtxStrideStatic && pVKVB->stride == 0) {
// Stride can't be 0, it will be set later to attributes' maximum offset + size
Expand Down Expand Up @@ -1840,7 +1841,7 @@ static MTLVertexFormat mvkAdjustFormatVectorToSize(MTLVertexFormat format, uint3
}

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.
Expand Down

0 comments on commit bd24db8

Please sign in to comment.