From 818c6b7082186c4b98872f7d8dc1a586fd7a2ee1 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Fri, 8 May 2020 18:05:19 +0000 Subject: [PATCH] Validate that ShaderModuleDescriptor has chained descriptor Bug: chromium:1074575 Change-Id: Ibb124ca8c4771d9b8f2846d3a5f79dca6de8743d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21360 Reviewed-by: Corentin Wallez Reviewed-by: Stephen White Commit-Queue: Austin Eng --- src/dawn_native/ShaderModule.cpp | 8 ++++++-- .../unittests/validation/ShaderModuleValidationTests.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index b72ce35f13..de3a692c8c 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -329,10 +329,14 @@ namespace dawn_native { return ValidateSpirv(device, descriptor->code, descriptor->codeSize); } - // For now only a single SPIRV or WGSL subdescriptor is allowed. const ChainedStruct* chainedDescriptor = descriptor->nextInChain; + if (chainedDescriptor == nullptr) { + return DAWN_VALIDATION_ERROR("Shader module descriptor missing chained descriptor"); + } + // For now only a single SPIRV or WGSL subdescriptor is allowed. if (chainedDescriptor->nextInChain != nullptr) { - return DAWN_VALIDATION_ERROR("chained nextInChain must be nullptr"); + return DAWN_VALIDATION_ERROR( + "Shader module descriptor chained nextInChain must be nullptr"); } switch (chainedDescriptor->sType) { diff --git a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp index 828124f495..6a037e9c88 100644 --- a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp +++ b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp @@ -108,3 +108,10 @@ TEST_F(ShaderModuleValidationTest, FragmentOutputLocationExceedsMaxColorAttachme ASSERT_DEVICE_ERROR(utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, stream.str().c_str())); } + +// Test that it is invalid to create a shader module with no chained descriptor. (It must be +// WGSL or SPIRV, not empty) +TEST_F(ShaderModuleValidationTest, NoChainedDescriptor) { + wgpu::ShaderModuleDescriptor desc = {}; + ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc)); +}