From 5d8a49e88a933514ee09d165ac5a7955d9869a52 Mon Sep 17 00:00:00 2001 From: Brandon Jones Date: Thu, 22 Aug 2024 20:26:52 +0000 Subject: [PATCH] Clarify stride validation errors It was pointed out that these messages, validating that a vertex attribute offset/size fits within the buffer stride, were confusing and easy to misunderstand. Updating in hopes of making the intent clearer for the reader. Bug: 361461530 Change-Id: Ibf8f7e7f2004ffad3a5a6636876cdce079d1489f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203614 Reviewed-by: Gregg Tavares Auto-Submit: Brandon Jones Reviewed-by: Loko Kung Commit-Queue: Loko Kung --- src/dawn/native/RenderPipeline.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp index e93a627b800..64d8f4123e2 100644 --- a/src/dawn/native/RenderPipeline.cpp +++ b/src/dawn/native/RenderPipeline.cpp @@ -116,20 +116,23 @@ MaybeError ValidateVertexAttribute(DeviceBase* device, // No underflow is possible because the max vertex format size is smaller than // kMaxVertexBufferArrayStride. DAWN_ASSERT(kMaxVertexBufferArrayStride >= formatInfo.byteSize); - DAWN_INVALID_IF( - attribute->offset > kMaxVertexBufferArrayStride - formatInfo.byteSize, - "Attribute offset (%u) with format %s (size: %u) doesn't fit in the maximum vertex " - "buffer stride (%u).", - attribute->offset, attribute->format, formatInfo.byteSize, kMaxVertexBufferArrayStride); + DAWN_INVALID_IF(attribute->offset > kMaxVertexBufferArrayStride - formatInfo.byteSize, + "Attribute offset (%u) + format size (%u for %s) must be <= the maximum vertex " + "buffer stride (%u). Offsets larger than the maximum vertex buffer stride are " + "accomodated by setting buffer offsets when calling setVertexBuffer, which the " + "attribute offset is added to.", + attribute->offset, formatInfo.byteSize, attribute->format, + kMaxVertexBufferArrayStride); // No overflow is possible because the offset is already validated to be less // than kMaxVertexBufferArrayStride. DAWN_ASSERT(attribute->offset < kMaxVertexBufferArrayStride); DAWN_INVALID_IF( vertexBufferStride > 0 && attribute->offset + formatInfo.byteSize > vertexBufferStride, - "Attribute offset (%u) with format %s (size: %u) doesn't fit in the vertex buffer " - "stride (%u).", - attribute->offset, attribute->format, formatInfo.byteSize, vertexBufferStride); + "Attribute offset (%u) + format size (%u for %s) must be <= the vertex buffer stride (%u). " + "Offsets larger than the vertex buffer stride are accomodated by setting buffer offsets " + "when calling setVertexBuffer, which the attribute offset is added to.", + attribute->offset, formatInfo.byteSize, attribute->format, vertexBufferStride); DAWN_INVALID_IF(attribute->offset % std::min(4u, formatInfo.byteSize) != 0, "Attribute offset (%u) in not a multiple of %u.", attribute->offset,