Validate texture component type in BGL against its shader module declaration

We have already been validating the component type of a texture matches
the bind group layout. Here is another constraint introduced by
https://github.com/gpuweb/gpuweb/pull/384. For better code reuse,
conversion from wgpu::TextureComponentType to dawn_native::Format::Type
is factored out as a helper function.

Bug: dawn:202
Change-Id: I394497722b4043dc109eca60116224b7a617e02e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12860
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Jiajie Hu
2019-10-31 09:51:11 +00:00
committed by Commit Bot service account
parent 64a3bb93dc
commit 9ec47a0bca
5 changed files with 66 additions and 11 deletions

View File

@@ -321,3 +321,42 @@ TEST_F(RenderPipelineValidationTest, SampleCountCompatibilityWithRenderPass) {
}
}
}
// Tests that the texture component type in shader must match the bind group layout.
TEST_F(RenderPipelineValidationTest, TextureComponentTypeCompatibility) {
constexpr uint32_t kNumTextureComponentType = 3u;
std::array<const char*, kNumTextureComponentType> kTexturePrefix = {{"", "i", "u"}};
std::array<wgpu::TextureComponentType, kNumTextureComponentType> kTextureComponentTypes = {{
wgpu::TextureComponentType::Float,
wgpu::TextureComponentType::Sint,
wgpu::TextureComponentType::Uint,
}};
for (size_t i = 0; i < kNumTextureComponentType; ++i) {
for (size_t j = 0; j < kNumTextureComponentType; ++j) {
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
std::ostringstream stream;
stream << R"(
#version 450
layout(set = 0, binding = 0) uniform )"
<< kTexturePrefix[i] << R"(texture2D tex;
void main() {
})";
descriptor.cFragmentStage.module = utils::CreateShaderModule(
device, utils::SingleShaderStage::Fragment, stream.str().c_str());
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
false, wgpu::TextureViewDimension::e2D, kTextureComponentTypes[j]}});
descriptor.layout = utils::MakeBasicPipelineLayout(device, &bgl);
if (i == j) {
device.CreateRenderPipeline(&descriptor);
} else {
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}
}
}
}