Port RenderPipelineValidationTests to WGSL

Bug: dawn:572
Change-Id: I0306c51c1e141f9e1452d2c1e8d688c014af2d78
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/33929
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-11-26 13:28:45 +00:00 committed by Commit Bot service account
parent de56b07e61
commit 419f102f4d
1 changed files with 43 additions and 46 deletions

View File

@ -26,18 +26,17 @@ class RenderPipelineValidationTest : public ValidationTest {
void SetUp() override { void SetUp() override {
ValidationTest::SetUp(); ValidationTest::SetUp();
vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
#version 450 [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[stage(vertex)]] fn main() -> void {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
})"); })");
fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
#version 450 [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() { fragColor = vec4<f32>(0.0, 1.0, 0.0, 1.0);
fragColor = vec4(0.0, 1.0, 0.0, 1.0); })");
})");
} }
wgpu::ShaderModule vsModule; wgpu::ShaderModule vsModule;
@ -165,7 +164,7 @@ TEST_F(RenderPipelineValidationTest, NonRenderableFormat) {
// Tests that the format of the color state descriptor must match the output of the fragment shader. // Tests that the format of the color state descriptor must match the output of the fragment shader.
TEST_F(RenderPipelineValidationTest, FragmentOutputFormatCompatibility) { TEST_F(RenderPipelineValidationTest, FragmentOutputFormatCompatibility) {
constexpr uint32_t kNumTextureFormatBaseType = 3u; constexpr uint32_t kNumTextureFormatBaseType = 3u;
std::array<const char*, kNumTextureFormatBaseType> kVecPreFix = {{"", "i", "u"}}; std::array<const char*, kNumTextureFormatBaseType> kScalarTypes = {{"f32", "i32", "u32"}};
std::array<wgpu::TextureFormat, kNumTextureFormatBaseType> kColorFormats = { std::array<wgpu::TextureFormat, kNumTextureFormatBaseType> kColorFormats = {
{wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureFormat::RGBA8Sint, {wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureFormat::RGBA8Sint,
wgpu::TextureFormat::RGBA8Uint}}; wgpu::TextureFormat::RGBA8Uint}};
@ -178,13 +177,12 @@ TEST_F(RenderPipelineValidationTest, FragmentOutputFormatCompatibility) {
std::ostringstream stream; std::ostringstream stream;
stream << R"( stream << R"(
#version 450 [[location(0)]] var<out> fragColor : vec4<)"
layout(location = 0) out )" << kScalarTypes[i] << R"(>;
<< kVecPreFix[i] << R"(vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() {
})"; })";
descriptor.cFragmentStage.module = utils::CreateShaderModule( descriptor.cFragmentStage.module =
device, utils::SingleShaderStage::Fragment, stream.str().c_str()); utils::CreateShaderModuleFromWGSL(device, stream.str().c_str());
if (i == j) { if (i == j) {
device.CreateRenderPipeline(&descriptor); device.CreateRenderPipeline(&descriptor);
@ -394,7 +392,7 @@ TEST_F(RenderPipelineValidationTest, AlphaToCoverageAndSampleCount) {
// Tests that the texture component type in shader must match the bind group layout. // Tests that the texture component type in shader must match the bind group layout.
TEST_F(RenderPipelineValidationTest, TextureComponentTypeCompatibility) { TEST_F(RenderPipelineValidationTest, TextureComponentTypeCompatibility) {
constexpr uint32_t kNumTextureComponentType = 3u; constexpr uint32_t kNumTextureComponentType = 3u;
std::array<const char*, kNumTextureComponentType> kTexturePrefix = {{"", "i", "u"}}; std::array<const char*, kNumTextureComponentType> kScalarTypes = {{"f32", "i32", "u32"}};
std::array<wgpu::TextureComponentType, kNumTextureComponentType> kTextureComponentTypes = {{ std::array<wgpu::TextureComponentType, kNumTextureComponentType> kTextureComponentTypes = {{
wgpu::TextureComponentType::Float, wgpu::TextureComponentType::Float,
wgpu::TextureComponentType::Sint, wgpu::TextureComponentType::Sint,
@ -408,13 +406,13 @@ TEST_F(RenderPipelineValidationTest, TextureComponentTypeCompatibility) {
std::ostringstream stream; std::ostringstream stream;
stream << R"( stream << R"(
#version 450 [[set(0), binding(0)]] var<uniform_constant> myTexture : texture_sampled_2d<)"
layout(set = 0, binding = 0) uniform )" << kScalarTypes[i] << R"(>;
<< kTexturePrefix[i] << R"(texture2D tex;
void main() { [[stage(fragment)]] fn main() -> void {
})"; })";
descriptor.cFragmentStage.module = utils::CreateShaderModule( descriptor.cFragmentStage.module =
device, utils::SingleShaderStage::Fragment, stream.str().c_str()); utils::CreateShaderModuleFromWGSL(device, stream.str().c_str());
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
@ -434,12 +432,12 @@ TEST_F(RenderPipelineValidationTest, TextureComponentTypeCompatibility) {
TEST_F(RenderPipelineValidationTest, TextureViewDimensionCompatibility) { TEST_F(RenderPipelineValidationTest, TextureViewDimensionCompatibility) {
constexpr uint32_t kNumTextureViewDimensions = 6u; constexpr uint32_t kNumTextureViewDimensions = 6u;
std::array<const char*, kNumTextureViewDimensions> kTextureKeywords = {{ std::array<const char*, kNumTextureViewDimensions> kTextureKeywords = {{
"texture1D", "texture_sampled_1d",
"texture2D", "texture_sampled_2d",
"texture2DArray", "texture_sampled_2d_array",
"textureCube", "texture_sampled_cube",
"textureCubeArray", "texture_sampled_cube_array",
"texture3D", "texture_sampled_3d",
}}; }};
std::array<wgpu::TextureViewDimension, kNumTextureViewDimensions> kTextureViewDimensions = {{ std::array<wgpu::TextureViewDimension, kNumTextureViewDimensions> kTextureViewDimensions = {{
@ -458,13 +456,12 @@ TEST_F(RenderPipelineValidationTest, TextureViewDimensionCompatibility) {
std::ostringstream stream; std::ostringstream stream;
stream << R"( stream << R"(
#version 450 [[set(0), binding(0)]] var<uniform_constant> myTexture : )"
layout(set = 0, binding = 0) uniform )" << kTextureKeywords[i] << R"(<f32>;
<< kTextureKeywords[i] << R"( tex; [[stage(fragment)]] fn main() -> void {
void main() {
})"; })";
descriptor.cFragmentStage.module = utils::CreateShaderModule( descriptor.cFragmentStage.module =
device, utils::SingleShaderStage::Fragment, stream.str().c_str()); utils::CreateShaderModuleFromWGSL(device, stream.str().c_str());
wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout( wgpu::BindGroupLayout bgl = utils::MakeBindGroupLayout(
device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false, device, {{0, wgpu::ShaderStage::Fragment, wgpu::BindingType::SampledTexture, false,
@ -483,15 +480,14 @@ TEST_F(RenderPipelineValidationTest, TextureViewDimensionCompatibility) {
// Test that declaring a storage buffer in the vertex shader without setting pipeline layout won't // Test that declaring a storage buffer in the vertex shader without setting pipeline layout won't
// cause crash. // cause crash.
TEST_F(RenderPipelineValidationTest, StorageBufferInVertexShaderNoLayout) { TEST_F(RenderPipelineValidationTest, StorageBufferInVertexShaderNoLayout) {
wgpu::ShaderModule vsModuleWithStorageBuffer = wgpu::ShaderModule vsModuleWithStorageBuffer = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[block]] struct Dst {
#version 450 [[offset(0)]] data : [[stride(4)]] array<u32, 100>;
#define kNumValues 100 };
layout(std430, set = 0, binding = 0) buffer Dst { uint dst[kNumValues]; }; [[set(0), binding(0)]] var<storage_buffer> dst : [[access(read_write)]] Dst;
void main() { [[builtin(vertex_idx)]] var<in> VertexIndex : u32;
uint index = gl_VertexIndex; [[stage(vertex)]] fn main() -> void {
dst[index] = 0x1234; dst.data[VertexIndex] = 0x1234u;
gl_Position = vec4(1.f, 0.f, 0.f, 1.f);
})"); })");
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
@ -503,6 +499,7 @@ TEST_F(RenderPipelineValidationTest, StorageBufferInVertexShaderNoLayout) {
// Test that a pipeline with defaulted layout may not have multisampled array textures // Test that a pipeline with defaulted layout may not have multisampled array textures
// TODO(enga): Also test multisampled cube, cube array, and 3D. These have no GLSL keywords. // TODO(enga): Also test multisampled cube, cube array, and 3D. These have no GLSL keywords.
// TODO(cwallez@chromium.org): Convert them to SPIRV ASM to remove the dependency on glslang.
TEST_F(RenderPipelineValidationTest, MultisampledTexture) { TEST_F(RenderPipelineValidationTest, MultisampledTexture) {
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.layout = nullptr; descriptor.layout = nullptr;