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:
Corentin Wallez 2019-06-07 11:05:37 +00:00 committed by Commit Bot service account
parent 0c38e92187
commit 2b82eb2902
2 changed files with 28 additions and 5 deletions

View File

@ -34,14 +34,22 @@ namespace dawn_native {
if (attribute->shaderLocation >= kMaxVertexAttributes) { if (attribute->shaderLocation >= kMaxVertexAttributes) {
return DAWN_VALIDATION_ERROR("Setting attribute out of bounds"); 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(kMaxVertexAttributeEnd >= VertexFormatSize(attribute->format));
ASSERT(vertexBufferStride == 0 || if (attribute->offset > kMaxVertexAttributeEnd - VertexFormatSize(attribute->format)) {
vertexBufferStride >= VertexFormatSize(attribute->format));
if (attribute->offset > kMaxVertexAttributeEnd - VertexFormatSize(attribute->format) ||
(vertexBufferStride > 0 &&
attribute->offset + VertexFormatSize(attribute->format) > vertexBufferStride)) {
return DAWN_VALIDATION_ERROR("Setting attribute offset out of bounds"); 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]) { if ((*attributesSetMask)[attribute->shaderLocation]) {
return DAWN_VALIDATION_ERROR("Setting already set attribute"); return DAWN_VALIDATION_ERROR("Setting already set attribute");
} }

View File

@ -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);
}
)");
}