From 214c71769bbb7271bd6ab14f7d1b8346a09d186b Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Thu, 21 May 2020 10:38:36 +0000 Subject: [PATCH] Disallow using combined textures and samplers in shaders This patch adds a validation to disallow declaraing combined textures and samplers in shaders. SPVC doesn't provide a way to extract the information of combined textures and samplers from shaders, so currently we cannot add the related validation when we use SPVC. BUG=dawn:423 TEST=dawn_unittests Change-Id: I81f05dc6adb57fbc981ee1a651e160c096315551 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22000 Reviewed-by: Austin Eng Reviewed-by: Corentin Wallez Commit-Queue: Jiawei Shao --- src/dawn_native/ShaderModule.cpp | 4 ++++ .../validation/ShaderModuleValidationTests.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 68da595728..7641053031 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -572,6 +572,10 @@ namespace dawn_native { return DAWN_VALIDATION_ERROR("Push constants aren't supported."); } + if (resources.sampled_images.size() > 0) { + return DAWN_VALIDATION_ERROR("Combined images and samplers aren't supported."); + } + // Fill in bindingInfo with the SPIRV bindings auto ExtractResourcesBinding = [this](const spirv_cross::SmallVector& resources, diff --git a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp index 6a037e9c88..bb08ecc702 100644 --- a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp +++ b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp @@ -115,3 +115,16 @@ TEST_F(ShaderModuleValidationTest, NoChainedDescriptor) { wgpu::ShaderModuleDescriptor desc = {}; ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc)); } + +// Test that it is not allowed to use combined texture and sampler. +// TODO(jiawei.shao@intel.com): support extracting combined texture and sampler in spvc. +TEST_F(ShaderModuleValidationTest, CombinedTextureAndSampler) { + const char* shader = R"( + #version 450 + layout (set = 0, binding = 0) uniform sampler2D texture; + void main() { + })"; + + ASSERT_DEVICE_ERROR( + utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, shader)); +}