Partially port StorageTextureValidationTests to WGSL

The rest of the port is blocked on support for the textureStore
intrinsic to write to storage textures.

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

View File

@ -23,17 +23,16 @@ class StorageTextureValidationTests : public ValidationTest {
void SetUp() override { void SetUp() override {
ValidationTest::SetUp(); ValidationTest::SetUp();
mDefaultVSModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( mDefaultVSModule = utils::CreateShaderModuleFromWGSL(device, R"(
#version 450 [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[stage(vertex)]] fn main() -> void {
gl_Position = vec4(0.f, 0.f, 0.f, 1.f); Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
})"); })");
mDefaultFSModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( mDefaultFSModule = 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>(1.0, 0.0, 0.0, 1.0);
fragColor = vec4(1.f, 0.f, 0.f, 1.f); })");
})");
} }
static const char* GetGLSLFloatImageTypeDeclaration(wgpu::TextureViewDimension dimension) { static const char* GetGLSLFloatImageTypeDeclaration(wgpu::TextureViewDimension dimension) {
@ -125,12 +124,12 @@ class StorageTextureValidationTests : public ValidationTest {
TEST_F(StorageTextureValidationTests, RenderPipeline) { TEST_F(StorageTextureValidationTests, RenderPipeline) {
// Readonly storage texture can be declared in a vertex shader. // Readonly storage texture can be declared in a vertex shader.
{ {
wgpu::ShaderModule vsModule = wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( [[set(0), binding(0)]] var<uniform_constant> image0 : texture_storage_ro_2d<rgba8unorm>;
#version 450 [[builtin(vertex_idx)]] var<in> VertexIndex : u32;
layout(set = 0, binding = 0, rgba8) uniform readonly image2D image0; [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[stage(vertex)]] fn main() -> void {
gl_Position = imageLoad(image0, ivec2(gl_VertexIndex, 0)); Position = textureLoad(image0, vec2<i32>(i32(VertexIndex), 0));
})"); })");
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
@ -142,13 +141,12 @@ TEST_F(StorageTextureValidationTests, RenderPipeline) {
// Read-only storage textures can be declared in a fragment shader. // Read-only storage textures can be declared in a fragment shader.
{ {
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"( [[set(0), binding(0)]] var<uniform_constant> image0 : texture_storage_ro_2d<rgba8unorm>;
#version 450 [[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;
layout(set = 0, binding = 0, rgba8) uniform readonly image2D image0; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor; [[stage(fragment)]] fn main() -> void {
void main() { fragColor = textureLoad(image0, vec2<i32>(FragCoord.xy));
fragColor = imageLoad(image0, ivec2(gl_FragCoord.xy));
})"); })");
utils::ComboRenderPipelineDescriptor descriptor(device); utils::ComboRenderPipelineDescriptor descriptor(device);
@ -198,14 +196,17 @@ TEST_F(StorageTextureValidationTests, RenderPipeline) {
TEST_F(StorageTextureValidationTests, ComputePipeline) { TEST_F(StorageTextureValidationTests, ComputePipeline) {
// Read-only storage textures can be declared in a compute shader. // Read-only storage textures can be declared in a compute shader.
{ {
wgpu::ShaderModule csModule = wgpu::ShaderModule csModule = utils::CreateShaderModuleFromWGSL(device, R"(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, R"( [[set(0), binding(0)]] var<uniform_constant> image0 : texture_storage_ro_2d<rgba8unorm>;
#version 450 [[builtin(local_invocation_id)]] var<in> LocalInvocationID : vec3<u32>;
layout(set = 0, binding = 0, rgba8) uniform readonly image2D image0;
layout(std430, set = 0, binding = 1) buffer Buf { uint buf; }; [[block]] struct Buf {
void main() { [[offset(0)]] data : f32;
vec4 pixel = imageLoad(image0, ivec2(gl_LocalInvocationID.xy)); };
buf = uint(pixel.x); [[set(0), binding(1)]] var<storage_buffer> buf : [[access(read_write)]] Buf;
[[stage(compute)]] fn main() -> void {
buf.data = textureLoad(image0, vec2<i32>(LocalInvocationID.xy)).x;
})"); })");
wgpu::ComputePipelineDescriptor descriptor; wgpu::ComputePipelineDescriptor descriptor;
@ -236,6 +237,7 @@ TEST_F(StorageTextureValidationTests, ComputePipeline) {
} }
// Validate read-write storage textures have not been supported yet. // Validate read-write storage textures have not been supported yet.
// TODO(cwallez@chromium.org): Convert them to SPIRV ASM to remove the dependency on glslang.
TEST_F(StorageTextureValidationTests, ReadWriteStorageTexture) { TEST_F(StorageTextureValidationTests, ReadWriteStorageTexture) {
// Read-write storage textures cannot be declared in a vertex shader by default. // Read-write storage textures cannot be declared in a vertex shader by default.
{ {