Update more Dawn tests to use WGSL

Bug: dawn:572
Change-Id: I0f567da883005d909d498a7a88e9b73137201919
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/41820
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-02-17 15:49:07 +00:00 committed by Commit Bot service account
parent a5ba2827f5
commit 0b17eb8e19
4 changed files with 197 additions and 202 deletions

View File

@ -162,14 +162,13 @@ class BufferZeroInitTest : public DawnTest {
expectedValues.size()));
}
void TestBufferZeroInitInBindGroup(const char* computeShader,
void TestBufferZeroInitInBindGroup(wgpu::ShaderModule module,
uint64_t bufferOffset,
uint64_t boundBufferSize,
const std::vector<uint32_t>& expectedBufferData) {
wgpu::ComputePipelineDescriptor pipelineDescriptor;
pipelineDescriptor.layout = nullptr;
pipelineDescriptor.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, computeShader);
pipelineDescriptor.computeStage.module = module;
pipelineDescriptor.computeStage.entryPoint = "main";
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDescriptor);
@ -201,6 +200,15 @@ class BufferZeroInitTest : public DawnTest {
EXPECT_PIXEL_RGBA8_EQ(kExpectedColor, outputTexture, 0u, 0u);
}
void TestBufferZeroInitInBindGroup(const char* glslComputeShader,
uint64_t bufferOffset,
uint64_t boundBufferSize,
const std::vector<uint32_t>& expectedBufferData) {
return TestBufferZeroInitInBindGroup(
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, glslComputeShader),
bufferOffset, boundBufferSize, expectedBufferData);
}
wgpu::RenderPipeline CreateRenderPipelineForTest(const char* vertexShader,
uint32_t vertexBufferCount = 1u) {
constexpr wgpu::TextureFormat kColorAttachmentFormat = wgpu::TextureFormat::RGBA8Unorm;
@ -417,16 +425,16 @@ class BufferZeroInitTest : public DawnTest {
// As long as the comptue shader is executed once, the pixel color of outImage will be set
// to red.
const char* computeShader = R"(
#version 450
layout(set = 0, binding = 0, rgba8) uniform writeonly image2D outImage;
void main() {
imageStore(outImage, ivec2(0, 0), vec4(1.f, 0.f, 0.f, 1.f));
[[group(0), binding(0)]] var outImage : [[access(write)]] texture_storage_2d<rgba8unorm>;
[[stage(compute)]] fn main() -> void {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
})";
wgpu::ComputePipelineDescriptor pipelineDescriptor;
pipelineDescriptor.layout = nullptr;
pipelineDescriptor.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, computeShader);
utils::CreateShaderModuleFromWGSL(device, computeShader);
pipelineDescriptor.computeStage.entryPoint = "main";
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&pipelineDescriptor);
@ -984,26 +992,29 @@ TEST_P(BufferZeroInitTest, BoundAsUniformBuffer) {
DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled());
const char* computeShader = R"(
#version 450
layout(set = 0, binding = 0, std140) uniform UBO {
uvec4 value;
} ubo;
layout(set = 0, binding = 1, rgba8) uniform writeonly image2D outImage;
void main() {
if (ubo.value == uvec4(0, 0, 0, 0)) {
imageStore(outImage, ivec2(0, 0), vec4(0.f, 1.f, 0.f, 1.f));
[[block]] struct UBO {
[[offset(0)]] value : vec4<u32>;
};
[[group(0), binding(0)]] var<uniform> ubo : UBO;
[[group(0), binding(1)]] var outImage : [[access(write)]] texture_storage_2d<rgba8unorm>;
[[stage(compute)]] fn main() -> void {
if (all(ubo.value == vec4<u32>(0, 0, 0, 0))) {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(0.0, 1.0, 0.0, 1.0));
} else {
imageStore(outImage, ivec2(0, 0), vec4(1.f, 0.f, 0.f, 1.f));
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
}
}
)";
constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, computeShader);
// Bind the whole buffer
{
const std::vector<uint32_t> expected(kBoundBufferSize / sizeof(uint32_t), 0u);
TestBufferZeroInitInBindGroup(computeShader, 0, kBoundBufferSize, expected);
TestBufferZeroInitInBindGroup(module, 0, kBoundBufferSize, expected);
}
// Bind a range of a buffer
@ -1012,7 +1023,7 @@ TEST_P(BufferZeroInitTest, BoundAsUniformBuffer) {
constexpr uint32_t kExtraBytes = 16u;
const std::vector<uint32_t> expected(
(kBoundBufferSize + kOffset + kExtraBytes) / sizeof(uint32_t), 0u);
TestBufferZeroInitInBindGroup(computeShader, kOffset, kBoundBufferSize, expected);
TestBufferZeroInitInBindGroup(module, kOffset, kBoundBufferSize, expected);
}
}
@ -1023,26 +1034,28 @@ TEST_P(BufferZeroInitTest, BoundAsReadonlyStorageBuffer) {
DAWN_SKIP_TEST_IF(IsOpenGLES() && IsBackendValidationEnabled());
const char* computeShader = R"(
#version 450
layout(set = 0, binding = 0, std140) readonly buffer SSBO {
uvec4 value;
} ssbo;
layout(set = 0, binding = 1, rgba8) uniform writeonly image2D outImage;
void main() {
if (ssbo.value == uvec4(0, 0, 0, 0)) {
imageStore(outImage, ivec2(0, 0), vec4(0.f, 1.f, 0.f, 1.f));
[[block]] struct SSBO {
[[offset(0)]] value : vec4<u32>;
};
[[group(0), binding(0)]] var<storage> ssbo : SSBO;
[[group(0), binding(1)]] var outImage : [[access(write)]] texture_storage_2d<rgba8unorm>;
[[stage(compute)]] fn main() -> void {
if (all(ssbo.value == vec4<u32>(0, 0, 0, 0))) {
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(0.0, 1.0, 0.0, 1.0));
} else {
imageStore(outImage, ivec2(0, 0), vec4(1.f, 0.f, 0.f, 1.f));
textureStore(outImage, vec2<i32>(0, 0), vec4<f32>(1.0, 0.0, 0.0, 1.0));
}
}
)";
constexpr uint32_t kBoundBufferSize = 16u;
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, computeShader);
// Bind the whole buffer
{
const std::vector<uint32_t> expected(kBoundBufferSize / sizeof(uint32_t), 0u);
TestBufferZeroInitInBindGroup(computeShader, 0, kBoundBufferSize, expected);
TestBufferZeroInitInBindGroup(module, 0, kBoundBufferSize, expected);
}
// Bind a range of a buffer
@ -1051,7 +1064,7 @@ TEST_P(BufferZeroInitTest, BoundAsReadonlyStorageBuffer) {
constexpr uint32_t kExtraBytes = 16u;
const std::vector<uint32_t> expected(
(kBoundBufferSize + kOffset + kExtraBytes) / sizeof(uint32_t), 0u);
TestBufferZeroInitInBindGroup(computeShader, kOffset, kBoundBufferSize, expected);
TestBufferZeroInitInBindGroup(module, kOffset, kBoundBufferSize, expected);
}
}

View File

@ -68,14 +68,13 @@ class TextureZeroInitTest : public DawnTest {
wgpu::RenderPipeline CreatePipelineForTest(float depth = 0.f) {
utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
pipelineDescriptor.vertexStage.module = CreateBasicVertexShaderForTest(depth);
const char* fs =
R"(#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
})";
pipelineDescriptor.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fs);
const char* fs = R"(
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
)";
pipelineDescriptor.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, fs);
pipelineDescriptor.cDepthStencilState.depthCompare = wgpu::CompareFunction::Equal;
pipelineDescriptor.cDepthStencilState.stencilFront.compare = wgpu::CompareFunction::Equal;
@ -84,30 +83,34 @@ class TextureZeroInitTest : public DawnTest {
return device.CreateRenderPipeline(&pipelineDescriptor);
}
wgpu::ShaderModule CreateBasicVertexShaderForTest(float depth = 0.f) {
std::string source = R"(#version 450
const vec2 pos[6] = vec2[6](vec2(-1.0f, -1.0f),
vec2(-1.0f, 1.0f),
vec2( 1.0f, -1.0f),
vec2( 1.0f, 1.0f),
vec2(-1.0f, 1.0f),
vec2( 1.0f, -1.0f)
);
std::string source = R"(
const pos : array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2<f32>(-1.0, -1.0),
vec2<f32>(-1.0, 1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, 1.0),
vec2<f32>( 1.0, -1.0)
);
void main() {
gl_Position = vec4(pos[gl_VertexIndex], )" +
[[builtin(vertex_index)]] var<in> VertexIndex : u32;
[[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
Position = vec4<f32>(pos[VertexIndex], )" +
std::to_string(depth) + R"(, 1.0);
})";
return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, source.c_str());
return utils::CreateShaderModuleFromWGSL(device, source.c_str());
}
wgpu::ShaderModule CreateSampledTextureFragmentShaderForTest() {
return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
R"(#version 450
layout(set = 0, binding = 0) uniform sampler sampler0;
layout(set = 0, binding = 1) uniform texture2D texture0;
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = texelFetch(sampler2D(texture0, sampler0), ivec2(gl_FragCoord), 0);
})");
return utils::CreateShaderModuleFromWGSL(device, R"(
[[group(0), binding(0)]] var texture0 : texture_2d<f32>;
[[builtin(frag_coord)]] var<in> FragCoord : vec4<f32>;
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = textureLoad(texture0, vec2<i32>(FragCoord.xy), 0);
}
)");
}
constexpr static uint32_t kSize = 128;
@ -853,8 +856,6 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
wgpu::Sampler sampler = device.CreateSampler();
// Create render pipeline
utils::ComboRenderPipelineDescriptor renderPipelineDescriptor(device);
renderPipelineDescriptor.cColorStates[0].format = kColorFormat;
@ -864,7 +865,7 @@ TEST_P(TextureZeroInitTest, RenderPassSampledTextureClear) {
// Create bindgroup
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, texture.CreateView()}});
{{0, texture.CreateView()}});
// Encode pass and submit
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -921,11 +922,8 @@ TEST_P(TextureZeroInitTest, TextureBothSampledAndAttachmentClear) {
renderPipelineDescriptor.cFragmentStage.module = CreateSampledTextureFragmentShaderForTest();
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup
wgpu::Sampler sampler = device.CreateSampler();
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, sampleView}});
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0), {{0, sampleView}});
// Encode pass and submit
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -975,27 +973,25 @@ TEST_P(TextureZeroInitTest, ComputePassSampledTextureClear) {
// Create compute pipeline
wgpu::ComputePipelineDescriptor computePipelineDescriptor;
wgpu::ProgrammableStageDescriptor computeStage;
const char* cs =
R"(#version 450
layout(binding = 0) uniform texture2D sampleTex;
layout(std430, binding = 1) buffer BufferTex {
vec4 result;
} bufferTex;
layout(binding = 2) uniform sampler sampler0;
void main() {
bufferTex.result =
texelFetch(sampler2D(sampleTex, sampler0), ivec2(0,0), 0);
})";
computePipelineDescriptor.computeStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Compute, cs);
const char* cs = R"(
[[group(0), binding(0)]] var tex : texture_2d<f32>;
[[block]] struct Result {
[[offset(0)]] value : vec4<f32>;
};
[[group(0), binding(1)]] var<storage> result : Result;
[[stage(compute)]] fn main() -> void {
result.value = textureLoad(tex, vec2<i32>(0,0), 0);
}
)";
computePipelineDescriptor.computeStage.module = utils::CreateShaderModuleFromWGSL(device, cs);
computePipelineDescriptor.computeStage.entryPoint = "main";
wgpu::ComputePipeline computePipeline =
device.CreateComputePipeline(&computePipelineDescriptor);
// Create bindgroup
wgpu::BindGroup bindGroup = utils::MakeBindGroup(
device, computePipeline.GetBindGroupLayout(0),
{{0, texture.CreateView()}, {1, bufferTex, 0, bufferSize}, {2, sampler}});
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, computePipeline.GetBindGroupLayout(0),
{{0, texture.CreateView()}, {1, bufferTex, 0, bufferSize}});
// Encode the pass and submit
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
@ -1131,8 +1127,6 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
wgpu::Sampler sampler = device.CreateSampler();
// Fill the sample texture with data
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize, 1);
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
@ -1156,7 +1150,7 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) {
// Create bindgroup
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, texture.CreateView()}});
{{0, texture.CreateView()}});
// Encode pass and submit
encoder = device.CreateCommandEncoder();
@ -1273,8 +1267,6 @@ TEST_P(TextureZeroInitTest, PreservesInitializedMip) {
kColorFormat);
wgpu::Texture sampleTexture = device.CreateTexture(&sampleTextureDescriptor);
wgpu::Sampler sampler = device.CreateSampler();
wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
@ -1303,9 +1295,8 @@ TEST_P(TextureZeroInitTest, PreservesInitializedMip) {
wgpu::RenderPipeline renderPipeline = device.CreateRenderPipeline(&renderPipelineDescriptor);
// Create bindgroup
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, sampleTexture.CreateView()}});
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampleTexture.CreateView()}});
// Encode pass and submit
encoder = device.CreateCommandEncoder();
@ -1354,8 +1345,6 @@ TEST_P(TextureZeroInitTest, PreservesInitializedArrayLayer) {
kColorFormat);
wgpu::Texture sampleTexture = device.CreateTexture(&sampleTextureDescriptor);
wgpu::Sampler sampler = device.CreateSampler();
wgpu::TextureDescriptor renderTextureDescriptor = CreateTextureDescriptor(
1, 1, wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::RenderAttachment, kColorFormat);
wgpu::Texture renderTexture = device.CreateTexture(&renderTextureDescriptor);
@ -1390,7 +1379,7 @@ TEST_P(TextureZeroInitTest, PreservesInitializedArrayLayer) {
// Create bindgroup
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, sampleTexture.CreateView(&textureViewDescriptor)}});
{{0, sampleTexture.CreateView(&textureViewDescriptor)}});
// Encode pass and submit
encoder = device.CreateCommandEncoder();
@ -1808,13 +1797,11 @@ class CompressedTextureZeroInitTest : public TextureZeroInitTest {
device.CreateRenderPipeline(&renderPipelineDescriptor);
pass.SetPipeline(renderPipeline);
wgpu::Sampler sampler = device.CreateSampler();
wgpu::TextureViewDescriptor textureViewDescriptor = CreateTextureViewDescriptor(
viewMipmapLevel, baseArrayLayer, textureDescriptor.format);
wgpu::BindGroup bindGroup = utils::MakeBindGroup(
device, renderPipeline.GetBindGroupLayout(0),
{{0, sampler}, {1, bcTexture.CreateView(&textureViewDescriptor)}});
wgpu::BindGroup bindGroup =
utils::MakeBindGroup(device, renderPipeline.GetBindGroupLayout(0),
{{0, bcTexture.CreateView(&textureViewDescriptor)}});
pass.SetBindGroup(0, bindGroup);
pass.Draw(6);
pass.EndPass();

View File

@ -70,41 +70,45 @@ class VertexStateTest : public DawnTest {
int multiplier,
const std::vector<ShaderTestSpec>& testSpec) {
std::ostringstream vs;
vs << "#version 450\n";
// TODO(cwallez@chromium.org): this only handles float attributes, we should extend it to
// other types Adds line of the form
// layout(location=1) in vec4 input1;
// [[location(1) var<in> input1 : vec4<f32>;
for (const auto& input : testSpec) {
vs << "layout(location=" << input.location << ") in vec4 input" << input.location
<< ";\n";
vs << "[[location(" << input.location << ")]] var<in> input" << input.location
<< " : vec4<f32>;\n";
}
vs << "layout(location = 0) out vec4 color;\n";
vs << "void main() {\n";
vs << "[[builtin(vertex_index)]] var<in> VertexIndex : u32;\n";
vs << "[[builtin(instance_index)]] var<in> InstanceIndex : u32;\n";
vs << "[[location(0)]] var<out> color : vec4<f32>;\n";
vs << "[[builtin(position)]] var<out> Position : vec4<f32>;\n";
vs << "[[stage(vertex)]] fn main() -> void {\n";
// Hard code the triangle in the shader so that we don't have to add a vertex input for it.
// Also this places the triangle in the grid based on its VertexID and InstanceID
vs << " const vec2 pos[3] = vec2[3](vec2(0.5f, 1.0f), vec2(0.0f, 0.0f), vec2(1.0f, "
"0.0f));\n";
vs << " vec2 offset = vec2(float(gl_VertexIndex / 3), float(gl_InstanceIndex));\n";
vs << " vec2 worldPos = pos[gl_VertexIndex % 3] + offset;\n";
vs << " vec4 position = vec4(worldPos / 2 - vec2(1.0f), 0.0f, 1.0f);\n";
vs << " gl_Position = vec4(position.x, -position.y, position.z, position.w);\n";
vs << " const pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(\n"
" vec2<f32>(0.5, 1.0), vec2<f32>(0.0, 0.0), vec2<f32>(1.0, 0.0));\n";
vs << " var offset : vec2<f32> = vec2<f32>(f32(VertexIndex / 3u), "
"f32(InstanceIndex));\n";
vs << " var worldPos : vec2<f32> = pos[VertexIndex % 3u] + offset;\n";
vs << " var position : vec4<f32> = vec4<f32>(0.5 * worldPos - vec2<f32>(1.0, 1.0), 0.0, "
"1.0);\n";
vs << " Position = vec4<f32>(position.x, -position.y, position.z, position.w);\n";
// Perform the checks by successively ANDing a boolean
vs << " bool success = true;\n";
vs << " var success : bool = true;\n";
for (const auto& input : testSpec) {
for (int component = 0; component < 4; ++component) {
vs << " success = success && (input" << input.location << "[" << component
<< "] == ";
if (ShouldComponentBeDefault(input.format, component)) {
vs << (component == 3 ? "1.0f" : "0.0f");
vs << (component == 3 ? "1.0" : "0.0");
} else {
if (input.step == InputStepMode::Vertex) {
vs << multiplier << " * gl_VertexIndex + " << component << ".0f";
vs << "f32(" << multiplier << " * VertexIndex) + " << component << ".0";
} else {
vs << multiplier << " * gl_InstanceIndex + " << component << ".0f";
vs << "f32(" << multiplier << " * InstanceIndex) + " << component << ".0";
}
}
vs << ");\n";
@ -113,22 +117,20 @@ class VertexStateTest : public DawnTest {
// Choose the color
vs << " if (success) {\n";
vs << " color = vec4(0.0f, 1.0f, 0.0f, 1.0f);\n";
vs << " color = vec4<f32>(0.0, 1.0, 0.0, 1.0);\n";
vs << " } else {\n";
vs << " color = vec4(1.0f, 0.0f, 0.0f, 1.0f);\n";
vs << " }\n;";
vs << " color = vec4<f32>(1.0, 0.0, 0.0, 1.0);\n";
vs << " }\n";
vs << "}\n";
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vs.str().c_str());
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) in vec4 color;
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = color;
})");
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, vs.str().c_str());
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<in> color : vec4<f32>;
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = color;
}
)");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;
@ -534,9 +536,6 @@ TEST_P(VertexStateTest, LastAllowedVertexBuffer) {
// Test that overlapping vertex attributes are permitted and load data correctly
TEST_P(VertexStateTest, OverlappingVertexAttributes) {
// TODO(crbug.com/tint/114): Tint needs to support 1.4 version of OpSelect
DAWN_SKIP_TEST_IF(HasToggleEnabled("use_tint_generator"));
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3);
utils::ComboVertexStateDescriptor vertexState;
@ -563,38 +562,38 @@ TEST_P(VertexStateTest, OverlappingVertexAttributes) {
utils::CreateBufferFromData(device, &data, sizeof(data), wgpu::BufferUsage::Vertex);
utils::ComboRenderPipelineDescriptor pipelineDesc(device);
pipelineDesc.vertexStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 attr0;
layout(location = 1) in uvec2 attr1;
layout(location = 2) in vec4 attr2;
layout(location = 3) in float attr3;
pipelineDesc.vertexStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<in> attr0 : vec4<f32>;
[[location(1)]] var<in> attr1 : vec2<u32>;
[[location(2)]] var<in> attr2 : vec4<f32>;
[[location(3)]] var<in> attr3 : f32;
layout(location = 0) out vec4 color;
[[location(0)]] var<out> color : vec4<f32>;
[[builtin(position)]] var<out> Position : vec4<f32>;
void main() {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 1.0;
[[stage(vertex)]] fn main() -> void {
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
bool success = (
attr0.x == 1.0f &&
attr1.x == 2u &&
attr1.y == 3u &&
attr2.z == 4.0f &&
attr2.w == 5.0f &&
attr3 == 1.0f
);
color = success ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);
})");
pipelineDesc.cFragmentStage.module =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) in vec4 color;
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = color;
})");
var success : bool = (
attr0.x == 1.0 &&
attr1.x == 2u &&
attr1.y == 3u &&
attr2.z == 4.0 &&
attr2.w == 5.0 &&
attr3 == 1.0
);
if (success) {
color = vec4<f32>(0.0, 1.0, 0.0, 1.0);
} else {
color = vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
})");
pipelineDesc.cFragmentStage.module = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<in> color : vec4<f32>;
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = color;
})");
pipelineDesc.vertexState = &vertexState;
pipelineDesc.cColorStates[0].format = renderPass.colorFormat;
pipelineDesc.primitiveTopology = wgpu::PrimitiveTopology::PointList;
@ -634,21 +633,17 @@ class OptionalVertexStateTest : public DawnTest {};
TEST_P(OptionalVertexStateTest, Basic) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, 3, 3);
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);
gl_PointSize = 1.0;
})");
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
Position = vec4<f32>(0.0, 0.0, 0.0, 1.0);
})");
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0f, 1.0f, 0.0f, 1.0f);
})");
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, R"(
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = vec4<f32>(0.0, 1.0, 0.0, 1.0);
})");
utils::ComboRenderPipelineDescriptor descriptor(device);
descriptor.vertexStage.module = vsModule;

View File

@ -33,34 +33,37 @@ namespace {
};
constexpr char kVertexShader[] = R"(
#version 450
layout(location = 0) in vec4 pos;
void main() {
gl_Position = pos;
})";
[[location(0)]] var<in> pos : vec4<f32>;
[[builtin(position)]] var<out> Position : vec4<f32>;
[[stage(vertex)]] fn main() -> void {
Position = pos;
})";
constexpr char kFragmentShaderA[] = R"(
#version 450
layout (std140, set = 0, binding = 0) uniform Uniforms {
vec3 color;
};
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(color / 5000., 1.0);
})";
[[block]] struct Uniforms {
[[offset(0)]] color : vec3<f32>;
};
[[group(0), binding(0)]] var<uniform> uniforms : Uniforms;
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = vec4<f32>(uniforms.color * (1.0 / 5000.0), 1.0);
})";
constexpr char kFragmentShaderB[] = R"(
#version 450
layout (std140, set = 0, binding = 0) uniform Constants {
vec3 colorA;
};
layout (std140, set = 1, binding = 0) uniform Uniforms {
vec3 colorB;
};
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4((colorA + colorB) / 5000., 1.0);
})";
[[block]] struct Constants {
[[offset(0)]] color : vec3<f32>;
};
[[block]] struct Uniforms {
[[offset(0)]] color : vec3<f32>;
};
[[group(0), binding(0)]] var<uniform> constants : Constants;
[[group(1), binding(0)]] var<uniform> uniforms : Uniforms;
[[location(0)]] var<out> fragColor : vec4<f32>;
[[stage(fragment)]] fn main() -> void {
fragColor = vec4<f32>((constants.color + uniforms.color) * (1.0 / 5000.0), 1.0);
})";
enum class Pipeline {
Static, // Keep the same pipeline for all draws.
@ -364,10 +367,8 @@ void DrawCallPerf::SetUp() {
wgpu::PipelineLayout pipelineLayout = device.CreatePipelineLayout(&pipelineLayoutDesc);
// Create the shaders for the first pipeline.
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, kVertexShader);
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, kFragmentShaderA);
wgpu::ShaderModule vsModule = utils::CreateShaderModuleFromWGSL(device, kVertexShader);
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, kFragmentShaderA);
// Create the first pipeline.
renderPipelineDesc.layout = pipelineLayout;
@ -395,8 +396,7 @@ void DrawCallPerf::SetUp() {
// Create the fragment shader module. This shader matches the pipeline layout described
// above.
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, kFragmentShaderB);
wgpu::ShaderModule fsModule = utils::CreateShaderModuleFromWGSL(device, kFragmentShaderB);
// Create the pipeline.
renderPipelineDesc.layout = pipelineLayout;