diff --git a/src/dawn_native/RenderEncoderBase.cpp b/src/dawn_native/RenderEncoderBase.cpp index 993bc66abe..240fc29436 100644 --- a/src/dawn_native/RenderEncoderBase.cpp +++ b/src/dawn_native/RenderEncoderBase.cpp @@ -244,6 +244,8 @@ namespace dawn_native { DAWN_TRY(GetDevice()->ValidateObject(buffer)); DAWN_TRY(ValidateCanUseAs(buffer, wgpu::BufferUsage::Index)); + DAWN_TRY(ValidateIndexFormat(format)); + DAWN_INVALID_IF(format == wgpu::IndexFormat::Undefined, "Index format must be specified"); diff --git a/src/tests/unittests/validation/IndexBufferValidationTests.cpp b/src/tests/unittests/validation/IndexBufferValidationTests.cpp index d13bf33ee1..d1d62b31ce 100644 --- a/src/tests/unittests/validation/IndexBufferValidationTests.cpp +++ b/src/tests/unittests/validation/IndexBufferValidationTests.cpp @@ -58,6 +58,21 @@ TEST_F(IndexBufferValidationTest, UndefinedIndexFormat) { ASSERT_DEVICE_ERROR(encoder.Finish()); } +// Test that an invalid index format is disallowed. +TEST_F(IndexBufferValidationTest, InvalidIndexFormat) { + wgpu::BufferDescriptor bufferDesc; + bufferDesc.usage = wgpu::BufferUsage::Index; + bufferDesc.size = 256; + wgpu::Buffer buffer = device.CreateBuffer(&bufferDesc); + + DummyRenderPass renderPass(device); + wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); + wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass); + pass.SetIndexBuffer(buffer, static_cast(404)); + pass.EndPass(); + ASSERT_DEVICE_ERROR(encoder.Finish()); +} + // Test that for OOB validation of index buffer offset and size. TEST_F(IndexBufferValidationTest, IndexBufferOffsetOOBValidation) { wgpu::BufferDescriptor bufferDesc;