Port TextureViewTests to WGSL

tint: 639 has been fixed

Bug: dawn:572
Change-Id: I3c6bcb4e6c04109f633694a8813ae5f0edb21da8
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/45603
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Ben Clayton 2021-03-24 09:12:53 +00:00 committed by Commit Bot service account
parent d020de4501
commit fcafc6e347
1 changed files with 69 additions and 77 deletions

View File

@ -60,24 +60,27 @@ namespace {
} }
wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) { wgpu::ShaderModule CreateDefaultVertexShaderModule(wgpu::Device device) {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( return utils::CreateShaderModuleFromWGSL(device, R"(
#version 450 [[builtin(vertex_index)]] var<in> VertexIndex : u32;
layout (location = 0) out vec2 o_texCoord; [[builtin(position)]] var<out> Position : vec4<f32>;
void main() { [[location(0)]] var<out> TexCoord : vec2<f32>;
const vec2 pos[6] = vec2[6](vec2(-2.f, -2.f), [[stage(vertex)]] fn main() -> void {
vec2(-2.f, 2.f), const pos : array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2( 2.f, -2.f), vec2<f32>(-2., -2.),
vec2(-2.f, 2.f), vec2<f32>(-2., 2.),
vec2( 2.f, -2.f), vec2<f32>( 2., -2.),
vec2( 2.f, 2.f)); vec2<f32>(-2., 2.),
const vec2 texCoord[6] = vec2[6](vec2(0.f, 0.f), vec2<f32>( 2., -2.),
vec2(0.f, 1.f), vec2<f32>( 2., 2.));
vec2(1.f, 0.f), const texCoord : array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2(0.f, 1.f), vec2<f32>(0., 0.),
vec2(1.f, 0.f), vec2<f32>(0., 1.),
vec2(1.f, 1.f)); vec2<f32>(1., 0.),
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f); vec2<f32>(0., 1.),
o_texCoord = texCoord[gl_VertexIndex]; vec2<f32>(1., 0.),
vec2<f32>(1., 1.));
Position = vec4<f32>(pos[VertexIndex], 0., 1.);
TexCoord = texCoord[VertexIndex];
} }
)"); )");
} }
@ -160,8 +163,7 @@ class TextureViewSamplingTest : public DawnTest {
} }
void Verify(const wgpu::TextureView& textureView, const char* fragmentShader, int expected) { void Verify(const wgpu::TextureView& textureView, const char* fragmentShader, int expected) {
wgpu::ShaderModule fsModule = wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, fragmentShader);
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fragmentShader);
utils::ComboRenderPipelineDescriptor2 textureDescriptor; utils::ComboRenderPipelineDescriptor2 textureDescriptor;
textureDescriptor.vertex.module = mVSModule; textureDescriptor.vertex.module = mVSModule;
@ -212,15 +214,13 @@ class TextureViewSamplingTest : public DawnTest {
wgpu::TextureView textureView = mTexture.CreateView(&descriptor); wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 [[group(0), binding(0)]] var sampler0 : sampler;
layout(set = 0, binding = 0) uniform sampler sampler0; [[group(0), binding(1)]] var texture0 : texture_2d<f32>;
layout(set = 0, binding = 1) uniform texture2D texture0; [[location(0)]] var<in> texCoord : vec2<f32>;
layout(location = 0) in vec2 texCoord; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = fragColor = textureSample(texture0, sampler0, texCoord);
texture(sampler2D(texture0, sampler0), texCoord);
} }
)"; )";
@ -253,17 +253,15 @@ class TextureViewSamplingTest : public DawnTest {
wgpu::TextureView textureView = mTexture.CreateView(&descriptor); wgpu::TextureView textureView = mTexture.CreateView(&descriptor);
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 [[group(0), binding(0)]] var sampler0 : sampler;
layout(set = 0, binding = 0) uniform sampler sampler0; [[group(0), binding(1)]] var texture0 : texture_2d_array<f32>;
layout(set = 0, binding = 1) uniform texture2DArray texture0; [[location(0)]] var<in> texCoord : vec2<f32>;
layout(location = 0) in vec2 texCoord; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = fragColor = textureSample(texture0, sampler0, texCoord, 0) +
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 0)) + textureSample(texture0, sampler0, texCoord, 1) +
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 1)) + textureSample(texture0, sampler0, texCoord, 2);
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 2));
} }
)"; )";
@ -277,40 +275,37 @@ class TextureViewSamplingTest : public DawnTest {
std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) { std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) {
// Reference: https://en.wikipedia.org/wiki/Cube_mapping // Reference: https://en.wikipedia.org/wiki/Cube_mapping
const std::array<std::string, 6> kCoordsToCubeMapFace = {{ const std::array<std::string, 6> kCoordsToCubeMapFace = {{
" 1.f, tc, -sc", // Positive X " 1., tc, -sc", // Positive X
"-1.f, tc, sc", // Negative X "-1., tc, sc", // Negative X
" sc, 1.f, -tc", // Positive Y " sc, 1., -tc", // Positive Y
" sc, -1.f, tc", // Negative Y " sc, -1., tc", // Negative Y
" sc, tc, 1.f", // Positive Z " sc, tc, 1.", // Positive Z
" -sc, tc, -1.f", // Negative Z "-sc, tc, -1.", // Negative Z
}}; }};
const std::string textureType = isCubeMapArray ? "textureCubeArray" : "textureCube"; const std::string textureType = isCubeMapArray ? "texture_cube_array" : "texture_cube";
const std::string samplerType = isCubeMapArray ? "samplerCubeArray" : "samplerCube";
const uint32_t cubeMapArrayIndex = layer / 6; const uint32_t cubeMapArrayIndex = layer / 6;
const std::string coordToCubeMapFace = kCoordsToCubeMapFace[layer % 6]; const std::string coordToCubeMapFace = kCoordsToCubeMapFace[layer % 6];
std::ostringstream stream; std::ostringstream stream;
stream << R"( stream << R"(
#version 450 [[group(0), binding(0)]] var sampler0 : sampler;
layout(set = 0, binding = 0) uniform sampler sampler0; [[group(0), binding(1)]] var texture0 : )"
layout(set = 0, binding = 1) uniform )" << textureType << R"(<f32>;
<< textureType << R"( texture0; [[location(0)]] var<in> texCoord : vec2<f32>;
layout(location = 0) in vec2 texCoord; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor;
void main() { [[stage(fragment)]] fn main() -> void {
float sc = 2.f * texCoord.x - 1.f; var sc : f32 = 2.0 * texCoord.x - 1.0;
float tc = 2.f * texCoord.y - 1.f; var tc : f32 = 2.0 * texCoord.y - 1.0;
fragColor = texture()" fragColor = textureSample(texture0, sampler0, vec3<f32>()"
<< samplerType << "(texture0, sampler0), "; << coordToCubeMapFace << ")";
if (isCubeMapArray) { if (isCubeMapArray) {
stream << "vec4(" << coordToCubeMapFace << ", " << cubeMapArrayIndex; stream << ", " << cubeMapArrayIndex;
} else {
stream << "vec3(" << coordToCubeMapFace;
} }
stream << R"()); stream << R"();
})"; })";
return stream.str(); return stream.str();
@ -368,17 +363,15 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) {
wgpu::TextureView textureView = mTexture.CreateView(); wgpu::TextureView textureView = mTexture.CreateView();
const char* fragmentShader = R"( const char* fragmentShader = R"(
#version 450 [[group(0), binding(0)]] var sampler0 : sampler;
layout(set = 0, binding = 0) uniform sampler sampler0; [[group(0), binding(1)]] var texture0 : texture_2d_array<f32>;
layout(set = 0, binding = 1) uniform texture2DArray texture0; [[location(0)]] var<in> texCoord : vec2<f32>;
layout(location = 0) in vec2 texCoord; [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = fragColor = textureSample(texture0, sampler0, texCoord, 0) +
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 0)) + textureSample(texture0, sampler0, texCoord, 1) +
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 1)) + textureSample(texture0, sampler0, texCoord, 2);
texture(sampler2DArray(texture0, sampler0), vec3(texCoord, 2));
} }
)"; )";
@ -503,15 +496,14 @@ class TextureViewRenderingTest : public DawnTest {
renderPassInfo.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f}; renderPassInfo.cColorAttachments[0].clearColor = {1.0f, 0.0f, 0.0f, 1.0f};
const char* oneColorFragmentShader = R"( const char* oneColorFragmentShader = R"(
#version 450 [[location(0)]] var<out> fragColor : vec4<f32>;
layout(location = 0) out vec4 fragColor;
void main() { [[stage(fragment)]] fn main() -> void {
fragColor = vec4(0.0, 1.0, 0.0, 1.0); fragColor = vec4<f32>(0.0, 1.0, 0.0, 1.0);
} }
)"; )";
wgpu::ShaderModule oneColorFsModule = utils::CreateShaderModule( wgpu::ShaderModule oneColorFsModule =
device, utils::SingleShaderStage::Fragment, oneColorFragmentShader); utils::CreateShaderModuleFromWGSL(device, oneColorFragmentShader);
utils::ComboRenderPipelineDescriptor2 pipelineDescriptor; utils::ComboRenderPipelineDescriptor2 pipelineDescriptor;
pipelineDescriptor.vertex.module = vsModule; pipelineDescriptor.vertex.module = vsModule;