Check bindingType with shader stage when creating default pipeline layout

This patch intends to fix a crash issue when creating a rendering
pipeline with storage buffer declared in vertex shader and pipeline
layout is not set.

Without this patch, in PipelineLayoutBase::CreateDefault() the
bindingSlot.visibility is always set to Fragment and Compute when it is
a storage buffer, therefore a crash happens at the failure of the
assertion modules->IsCompatibleWithPipelineLayout() when the storage
buffer is actually declared in the vertex shader.

BUG=dawn:276
TEST=dawn_unittests

Change-Id: I56876a97d53ead5ed226dc1b9bbed1a77156b2b2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/16564
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao
2020-03-09 00:45:18 +00:00
committed by Commit Bot service account
parent 7d20b44501
commit 532be50b76
4 changed files with 42 additions and 5 deletions

View File

@@ -456,3 +456,24 @@ TEST_F(RenderPipelineValidationTest, TextureViewDimensionCompatibility) {
}
}
}
// Test that declaring a storage buffer in the vertex shader without setting pipeline layout won't
// cause crash.
TEST_F(RenderPipelineValidationTest, StorageBufferInVertexShaderNoLayout) {
wgpu::ShaderModule vsModuleWithStorageBuffer =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
#define kNumValues 100
layout(std430, set = 0, binding = 0) buffer Dst { uint dst[kNumValues]; };
void main() {
uint index = gl_VertexIndex;
dst[index] = 0x1234;
gl_Position = vec4(1.f, 0.f, 0.f, 1.f);
})");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = nullptr;
descriptor.vertexStage.module = vsModuleWithStorageBuffer;
descriptor.cFragmentStage.module = fsModule;
ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor));
}