Fix issue where M1 GPU does not support reusing Metal visibility buffer
offsets across separate render encoders within a single Vulkan command buffer.
Monotonically increase the offset into the temporary visibility buffer
after each query in a MVKCommandEncoder (ie- Vulkan command buffer).
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm b/MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm
index 96ea826..60a34fb 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandEncoderState.mm
@@ -1099,20 +1099,18 @@
MVKQuerySpec querySpec;
querySpec.set(pQueryPool, query);
- NSUInteger offset = _mtlRenderPassQueries.empty() ? 0 : _mtlVisibilityResultOffset + kMVKQuerySlotSizeInBytes;
- NSUInteger maxOffset = _cmdEncoder->_pDeviceMetalFeatures->maxQueryBufferSize - kMVKQuerySlotSizeInBytes;
- offset = min(offset, maxOffset);
- _mtlRenderPassQueries.push_back(make_pair(querySpec, offset));
+ _mtlRenderPassQueries.push_back(make_pair(querySpec, _mtlVisibilityResultOffset));
bool shouldCount = _cmdEncoder->_pDeviceFeatures->occlusionQueryPrecise && mvkAreAllFlagsEnabled(flags, VK_QUERY_CONTROL_PRECISE_BIT);
_mtlVisibilityResultMode = shouldCount ? MTLVisibilityResultModeCounting : MTLVisibilityResultModeBoolean;
- _mtlVisibilityResultOffset = offset;
markDirty();
}
void MVKOcclusionQueryCommandEncoderState::endOcclusionQuery(MVKOcclusionQueryPool* pQueryPool, uint32_t query) {
_mtlVisibilityResultMode = MTLVisibilityResultModeDisabled;
+ _mtlVisibilityResultOffset = min<NSUInteger>(_mtlVisibilityResultOffset + kMVKQuerySlotSizeInBytes,
+ _cmdEncoder->_pDeviceMetalFeatures->maxQueryBufferSize - kMVKQuerySlotSizeInBytes);
markDirty();
}