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 <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2020-05-08 18:05:19 +00:00 committed by Commit Bot service account
parent 70ffa0c285
commit 818c6b7082
2 changed files with 13 additions and 2 deletions

View File

@ -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) {

View File

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