Fix incorrect ASSERT in vertex validation.
Also adds a test that would have fired the ASSERT. BUG=dawn:80 BUG=dawn:107 Change-Id: I56cdbc91956465c8941b45bb5e9da4c27da301ae Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7840 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Yunchao He <yunchao.he@intel.com> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
0c38e92187
commit
2b82eb2902
|
@ -34,14 +34,22 @@ namespace dawn_native {
|
|||
if (attribute->shaderLocation >= kMaxVertexAttributes) {
|
||||
return DAWN_VALIDATION_ERROR("Setting attribute out of bounds");
|
||||
}
|
||||
|
||||
// No underflow is possible because the max vertex format size is smaller than
|
||||
// kMaxVertexAttributeEnd.
|
||||
ASSERT(kMaxVertexAttributeEnd >= VertexFormatSize(attribute->format));
|
||||
ASSERT(vertexBufferStride == 0 ||
|
||||
vertexBufferStride >= VertexFormatSize(attribute->format));
|
||||
if (attribute->offset > kMaxVertexAttributeEnd - VertexFormatSize(attribute->format) ||
|
||||
(vertexBufferStride > 0 &&
|
||||
attribute->offset + VertexFormatSize(attribute->format) > vertexBufferStride)) {
|
||||
if (attribute->offset > kMaxVertexAttributeEnd - VertexFormatSize(attribute->format)) {
|
||||
return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds");
|
||||
}
|
||||
|
||||
// No overflow is possible because the offset is already validated to be less
|
||||
// than kMaxVertexAttributeEnd.
|
||||
ASSERT(attribute->offset < kMaxVertexAttributeEnd);
|
||||
if (vertexBufferStride > 0 &&
|
||||
attribute->offset + VertexFormatSize(attribute->format) > vertexBufferStride) {
|
||||
return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds");
|
||||
}
|
||||
|
||||
if ((*attributesSetMask)[attribute->shaderLocation]) {
|
||||
return DAWN_VALIDATION_ERROR("Setting already set attribute");
|
||||
}
|
||||
|
|
|
@ -363,3 +363,18 @@ TEST_F(VertexInputTest, SetAttributeOffsetOverflow) {
|
|||
}
|
||||
)");
|
||||
}
|
||||
|
||||
// Check for some potential underflow in the vertex input validation
|
||||
TEST_F(VertexInputTest, VertexFormatLargerThanNonZeroStride) {
|
||||
utils::ComboVertexInputDescriptor state;
|
||||
state.bufferCount = 1;
|
||||
state.cBuffers[0].stride = 4;
|
||||
state.cBuffers[0].attributeCount = 1;
|
||||
state.cAttributes[0].format = dawn::VertexFormat::Float4;
|
||||
CreatePipeline(false, state, R"(
|
||||
#version 450
|
||||
void main() {
|
||||
gl_Position = vec4(0.0);
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue