Skip to content

Commit

Permalink
Clarify stride validation errors
Browse files Browse the repository at this point in the history
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 <[email protected]>
Auto-Submit: Brandon Jones <[email protected]>
Reviewed-by: Loko Kung <[email protected]>
Commit-Queue: Loko Kung <[email protected]>
  • Loading branch information
toji authored and Dawn LUCI CQ committed Aug 22, 2024
1 parent 01ce8fb commit 5d8a49e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/dawn/native/RenderPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5d8a49e

Please sign in to comment.