only update offset if we call setVertexBuffer previously (#4049)

Co-authored-by: Wei Chen <wei.chen@grabtaxi.com>
This commit is contained in:
Wei Chen
2026-01-14 20:57:34 +08:00
committed by GitHub
parent 0592e4f0ad
commit 68e219c39b
2 changed files with 5 additions and 1 deletions

View File

@@ -87,6 +87,8 @@ protected:
std::uint16_t version = 0; std::uint16_t version = 0;
bool isIndexBuffer; bool isIndexBuffer;
bool persistent; bool persistent;
mutable bool usingVertexBuffer = false;
}; };
} // namespace mtl } // namespace mtl

View File

@@ -165,9 +165,11 @@ void BufferResource::bindVertex(const MTLRenderCommandEncoderPtr& encoder,
assert(offset + size_ <= size); assert(offset + size_ <= size);
if (const auto* mtlBuf = buffer.get()) { if (const auto* mtlBuf = buffer.get()) {
encoder->setVertexBuffer(mtlBuf, static_cast<NS::UInteger>(offset), static_cast<NS::UInteger>(index)); encoder->setVertexBuffer(mtlBuf, static_cast<NS::UInteger>(offset), static_cast<NS::UInteger>(index));
usingVertexBuffer = true;
} else if (!raw.empty()) { } else if (!raw.empty()) {
size_ = size_ ? std::min(size_, size - offset) : size - offset; size_ = size_ ? std::min(size_, size - offset) : size - offset;
encoder->setVertexBytes(raw.data() + offset, size_, index); encoder->setVertexBytes(raw.data() + offset, size_, index);
usingVertexBuffer = false;
} }
} }
@@ -192,7 +194,7 @@ void BufferResource::updateVertexBindOffset(const MTLRenderCommandEncoderPtr& en
// The documentation for `setVertexBufferOffset` indicates that it should work for buffers // The documentation for `setVertexBufferOffset` indicates that it should work for buffers
// assigned using `setVertexBytes` but, in practice, it produces a validation failure: // assigned using `setVertexBytes` but, in practice, it produces a validation failure:
// `Set Vertex Buffer Offset Validation index(1) must have an existing buffer.` // `Set Vertex Buffer Offset Validation index(1) must have an existing buffer.`
if (buffer.get()) { if (buffer.get() && usingVertexBuffer) {
encoder->setVertexBufferOffset(offset, index); encoder->setVertexBufferOffset(offset, index);
} else { } else {
bindVertex(encoder, offset, index, size_); bindVertex(encoder, offset, index, size_);