Autoformat all tests and examples
Bug: none
Change-Id: I69904944db1d4c2fbcca74bb8b66b5a7524e76bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24642
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp
index dfd041c..5c197c4 100644
--- a/examples/Animometer.cpp
+++ b/examples/Animometer.cpp
@@ -18,8 +18,8 @@
#include "utils/SystemUtils.h"
#include "utils/WGPUHelpers.h"
-#include <cstdlib>
#include <cstdio>
+#include <cstdlib>
#include <vector>
wgpu::Device device;
@@ -138,8 +138,7 @@
bufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform;
ubo = device.CreateBuffer(&bufferDesc);
- bindGroup =
- utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}});
+ bindGroup = utils::MakeBindGroup(device, bgl, {{0, ubo, 0, sizeof(ShaderData)}});
}
void frame() {
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index 39ef9c5..96ae72f 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -49,9 +49,7 @@
# Template for samples to avoid listing dawn_sample_utils as a dep every time
template("dawn_sample") {
executable(target_name) {
- deps = [
- ":dawn_sample_utils",
- ]
+ deps = [ ":dawn_sample_utils" ]
forward_variables_from(invoker, "*", [ "deps" ])
if (defined(invoker.deps)) {
@@ -61,43 +59,27 @@
}
dawn_sample("CppHelloTriangle") {
- sources = [
- "CppHelloTriangle.cpp",
- ]
+ sources = [ "CppHelloTriangle.cpp" ]
}
dawn_sample("CHelloTriangle") {
- sources = [
- "CHelloTriangle.cpp",
- ]
+ sources = [ "CHelloTriangle.cpp" ]
}
dawn_sample("ComputeBoids") {
- sources = [
- "ComputeBoids.cpp",
- ]
- deps = [
- "${dawn_root}/third_party/gn/glm",
- ]
+ sources = [ "ComputeBoids.cpp" ]
+ deps = [ "${dawn_root}/third_party/gn/glm" ]
}
dawn_sample("Animometer") {
- sources = [
- "Animometer.cpp",
- ]
+ sources = [ "Animometer.cpp" ]
}
dawn_sample("CubeReflection") {
- sources = [
- "CubeReflection.cpp",
- ]
- deps = [
- "${dawn_root}/third_party/gn/glm",
- ]
+ sources = [ "CubeReflection.cpp" ]
+ deps = [ "${dawn_root}/third_party/gn/glm" ]
}
dawn_sample("ManualSwapChainTest") {
- sources = [
- "ManualSwapChainTest.cpp",
- ]
+ sources = [ "ManualSwapChainTest.cpp" ]
}
diff --git a/examples/CHelloTriangle.cpp b/examples/CHelloTriangle.cpp
index 048fba1..22d8202 100644
--- a/examples/CHelloTriangle.cpp
+++ b/examples/CHelloTriangle.cpp
@@ -120,7 +120,7 @@
{
colorAttachment.attachment = backbufferView;
colorAttachment.resolveTarget = nullptr;
- colorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
+ colorAttachment.clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
colorAttachment.loadOp = WGPULoadOp_Clear;
colorAttachment.storeOp = WGPUStoreOp_Store;
renderpassInfo.colorAttachmentCount = 1;
diff --git a/examples/ComputeBoids.cpp b/examples/ComputeBoids.cpp
index 59538df..f958ab4 100644
--- a/examples/ComputeBoids.cpp
+++ b/examples/ComputeBoids.cpp
@@ -67,7 +67,7 @@
modelBuffer =
utils::CreateBufferFromData(device, model, sizeof(model), wgpu::BufferUsage::Vertex);
- SimParams params = { 0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles };
+ SimParams params = {0.04f, 0.1f, 0.025f, 0.025f, 0.02f, 0.05f, 0.005f, kNumParticles};
updateParams =
utils::CreateBufferFromData(device, ¶ms, sizeof(params), wgpu::BufferUsage::Uniform);
@@ -75,8 +75,7 @@
{
std::mt19937 generator;
std::uniform_real_distribution<float> dist(-1.0f, 1.0f);
- for (auto& p : initialParticles)
- {
+ for (auto& p : initialParticles) {
p.pos = glm::vec2(dist(generator), dist(generator));
p.vel = glm::vec2(dist(generator), dist(generator)) * 0.1f;
}
@@ -253,11 +252,13 @@
updatePipeline = device.CreateComputePipeline(&csDesc);
for (uint32_t i = 0; i < 2; ++i) {
- updateBGs[i] = utils::MakeBindGroup(device, bgl, {
- {0, updateParams, 0, sizeof(SimParams)},
- {1, particleBuffers[i], 0, kNumParticles * sizeof(Particle)},
- {2, particleBuffers[(i + 1) % 2], 0, kNumParticles * sizeof(Particle)},
- });
+ updateBGs[i] = utils::MakeBindGroup(
+ device, bgl,
+ {
+ {0, updateParams, 0, sizeof(SimParams)},
+ {1, particleBuffers[i], 0, kNumParticles * sizeof(Particle)},
+ {2, particleBuffers[(i + 1) % 2], 0, kNumParticles * sizeof(Particle)},
+ });
}
}
diff --git a/examples/CppHelloTriangle.cpp b/examples/CppHelloTriangle.cpp
index fbc598d..378afa8 100644
--- a/examples/CppHelloTriangle.cpp
+++ b/examples/CppHelloTriangle.cpp
@@ -36,15 +36,15 @@
void initBuffers() {
static const uint32_t indexData[3] = {
- 0, 1, 2,
+ 0,
+ 1,
+ 2,
};
indexBuffer =
utils::CreateBufferFromData(device, indexData, sizeof(indexData), wgpu::BufferUsage::Index);
static const float vertexData[12] = {
- 0.0f, 0.5f, 0.0f, 1.0f,
- -0.5f, -0.5f, 0.0f, 1.0f,
- 0.5f, -0.5f, 0.0f, 1.0f,
+ 0.0f, 0.5f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f, 1.0f, 0.5f, -0.5f, 0.0f, 1.0f,
};
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData),
wgpu::BufferUsage::Vertex);
@@ -141,17 +141,19 @@
wgpu::TextureView view = texture.CreateView();
- bindGroup = utils::MakeBindGroup(device, bgl, {
- {0, sampler},
- {1, view}
- });
+ bindGroup = utils::MakeBindGroup(device, bgl, {{0, sampler}, {1, view}});
}
-struct {uint32_t a; float b;} s;
+struct {
+ uint32_t a;
+ float b;
+} s;
void frame() {
s.a = (s.a + 1) % 256;
s.b += 0.02f;
- if (s.b >= 1.0f) {s.b = 0.0f;}
+ if (s.b >= 1.0f) {
+ s.b = 0.0f;
+ }
wgpu::TextureView backbufferView = swapchain.GetCurrentTextureView();
utils::ComboRenderPassDescriptor renderPass({backbufferView}, depthStencilView);
diff --git a/examples/CubeReflection.cpp b/examples/CubeReflection.cpp
index becec87..4ff18e0 100644
--- a/examples/CubeReflection.cpp
+++ b/examples/CubeReflection.cpp
@@ -18,10 +18,10 @@
#include "utils/SystemUtils.h"
#include "utils/WGPUHelpers.h"
-#include <vector>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
+#include <vector>
wgpu::Device device;
@@ -43,67 +43,44 @@
wgpu::RenderPipeline reflectionPipeline;
void initBuffers() {
- static const uint32_t indexData[6*6] = {
- 0, 1, 2,
- 0, 2, 3,
+ static const uint32_t indexData[6 * 6] = {0, 1, 2, 0, 2, 3,
- 4, 5, 6,
- 4, 6, 7,
+ 4, 5, 6, 4, 6, 7,
- 8, 9, 10,
- 8, 10, 11,
+ 8, 9, 10, 8, 10, 11,
- 12, 13, 14,
- 12, 14, 15,
+ 12, 13, 14, 12, 14, 15,
- 16, 17, 18,
- 16, 18, 19,
+ 16, 17, 18, 16, 18, 19,
- 20, 21, 22,
- 20, 22, 23
- };
+ 20, 21, 22, 20, 22, 23};
indexBuffer =
utils::CreateBufferFromData(device, indexData, sizeof(indexData), wgpu::BufferUsage::Index);
static const float vertexData[6 * 4 * 6] = {
- -1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
- 1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
- 1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
- -1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
+ -1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0,
+ 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, -1.0, 1.0, 1.0, 1.0, 0.0, 0.0,
- -1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
- -1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
- 1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
- 1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
+ -1.0, -1.0, -1.0, 1.0, 1.0, 0.0, -1.0, 1.0, -1.0, 1.0, 1.0, 0.0,
+ 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 1.0, -1.0, -1.0, 1.0, 1.0, 0.0,
- -1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
- -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
- 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
- 1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
+ -1.0, 1.0, -1.0, 1.0, 0.0, 1.0, -1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0,
- -1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
- 1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
- 1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
- -1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
+ -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 1.0, -1.0, -1.0, 0.0, 1.0, 0.0,
+ 1.0, -1.0, 1.0, 0.0, 1.0, 0.0, -1.0, -1.0, 1.0, 0.0, 1.0, 0.0,
- 1.0, -1.0, -1.0, 0.0, 1.0, 1.0,
- 1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
- 1.0, 1.0, 1.0, 0.0, 1.0, 1.0,
- 1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
+ 1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0, 1.0,
- -1.0, -1.0, -1.0, 1.0, 1.0, 1.0,
- -1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
- -1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- -1.0, 1.0, -1.0, 1.0, 1.0, 1.0
- };
+ -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0,
+ -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, 1.0};
vertexBuffer = utils::CreateBufferFromData(device, vertexData, sizeof(vertexData),
wgpu::BufferUsage::Vertex);
static const float planeData[6 * 4] = {
- -2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
- 2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
- 2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
- -2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
+ -2.0, -1.0, -2.0, 0.5, 0.5, 0.5, 2.0, -1.0, -2.0, 0.5, 0.5, 0.5,
+ 2.0, -1.0, 2.0, 0.5, 0.5, 0.5, -2.0, -1.0, 2.0, 0.5, 0.5, 0.5,
};
planeBuffer = utils::CreateBufferFromData(device, planeData, sizeof(planeData),
wgpu::BufferUsage::Vertex);
@@ -191,15 +168,13 @@
transformBuffer[1] = utils::CreateBufferFromData(device, &transform, sizeof(glm::mat4),
wgpu::BufferUsage::Uniform);
- bindGroup[0] = utils::MakeBindGroup(device, bgl, {
- {0, cameraBuffer, 0, sizeof(CameraData)},
- {1, transformBuffer[0], 0, sizeof(glm::mat4)}
- });
+ bindGroup[0] = utils::MakeBindGroup(
+ device, bgl,
+ {{0, cameraBuffer, 0, sizeof(CameraData)}, {1, transformBuffer[0], 0, sizeof(glm::mat4)}});
- bindGroup[1] = utils::MakeBindGroup(device, bgl, {
- {0, cameraBuffer, 0, sizeof(CameraData)},
- {1, transformBuffer[1], 0, sizeof(glm::mat4)}
- });
+ bindGroup[1] = utils::MakeBindGroup(
+ device, bgl,
+ {{0, cameraBuffer, 0, sizeof(CameraData)}, {1, transformBuffer[1], 0, sizeof(glm::mat4)}});
depthStencilView = CreateDefaultDepthStencilView(device);
@@ -250,17 +225,20 @@
cameraData.proj = glm::perspective(glm::radians(45.0f), 1.f, 1.0f, 100.0f);
}
-struct {uint32_t a; float b;} s;
+struct {
+ uint32_t a;
+ float b;
+} s;
void frame() {
s.a = (s.a + 1) % 256;
s.b += 0.01f;
- if (s.b >= 1.0f) {s.b = 0.0f;}
+ if (s.b >= 1.0f) {
+ s.b = 0.0f;
+ }
- cameraData.view = glm::lookAt(
- glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f, 8.f * std::cos(glm::radians(s.b * 360.f))),
- glm::vec3(0.0f, 0.0f, 0.0f),
- glm::vec3(0.0f, 1.0f, 0.0f)
- );
+ cameraData.view = glm::lookAt(glm::vec3(8.f * std::sin(glm::radians(s.b * 360.f)), 2.f,
+ 8.f * std::cos(glm::radians(s.b * 360.f))),
+ glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
queue.WriteBuffer(cameraBuffer, 0, &cameraData, sizeof(CameraData));
diff --git a/examples/ManualSwapChainTest.cpp b/examples/ManualSwapChainTest.cpp
index ee924d3..9e3990d 100644
--- a/examples/ManualSwapChainTest.cpp
+++ b/examples/ManualSwapChainTest.cpp
@@ -150,7 +150,8 @@
utils::ComboRenderPassDescriptor desc({view});
desc.cColorAttachments[0].loadOp = wgpu::LoadOp::Clear;
- desc.cColorAttachments[0].clearColor = {data->clearCycle, 1.0f - data->clearCycle, 0.0f, 1.0f};
+ desc.cColorAttachments[0].clearColor = {data->clearCycle, 1.0f - data->clearCycle, 0.0f,
+ 1.0f};
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&desc);
pass.EndPass();
diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp
index 17b7c9e..ee7e006 100644
--- a/examples/SampleUtils.cpp
+++ b/examples/SampleUtils.cpp
@@ -60,7 +60,7 @@
enum class CmdBufType {
None,
Terrible,
- //TODO(cwallez@chromium.org) double terrible cmdbuf
+ // TODO(cwallez@chromium.org): double terrible cmdbuf
};
// Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on
@@ -74,7 +74,7 @@
#elif defined(DAWN_ENABLE_BACKEND_OPENGL)
static wgpu::BackendType backendType = wgpu::BackendType::OpenGL;
#else
- #error
+# error
#endif
static CmdBufType cmdBufType = CmdBufType::Terrible;
@@ -136,31 +136,29 @@
cDevice = backendDevice;
break;
- case CmdBufType::Terrible:
- {
- c2sBuf = new utils::TerribleCommandBuffer();
- s2cBuf = new utils::TerribleCommandBuffer();
+ case CmdBufType::Terrible: {
+ c2sBuf = new utils::TerribleCommandBuffer();
+ s2cBuf = new utils::TerribleCommandBuffer();
- dawn_wire::WireServerDescriptor serverDesc = {};
- serverDesc.device = backendDevice;
- serverDesc.procs = &backendProcs;
- serverDesc.serializer = s2cBuf;
+ dawn_wire::WireServerDescriptor serverDesc = {};
+ serverDesc.device = backendDevice;
+ serverDesc.procs = &backendProcs;
+ serverDesc.serializer = s2cBuf;
- wireServer = new dawn_wire::WireServer(serverDesc);
- c2sBuf->SetHandler(wireServer);
+ wireServer = new dawn_wire::WireServer(serverDesc);
+ c2sBuf->SetHandler(wireServer);
- dawn_wire::WireClientDescriptor clientDesc = {};
- clientDesc.serializer = c2sBuf;
+ dawn_wire::WireClientDescriptor clientDesc = {};
+ clientDesc.serializer = c2sBuf;
- wireClient = new dawn_wire::WireClient(clientDesc);
- WGPUDevice clientDevice = wireClient->GetDevice();
- DawnProcTable clientProcs = dawn_wire::WireClient::GetProcs();
- s2cBuf->SetHandler(wireClient);
+ wireClient = new dawn_wire::WireClient(clientDesc);
+ WGPUDevice clientDevice = wireClient->GetDevice();
+ DawnProcTable clientProcs = dawn_wire::WireClient::GetProcs();
+ s2cBuf->SetHandler(wireClient);
- procs = clientProcs;
- cDevice = clientDevice;
- }
- break;
+ procs = clientProcs;
+ cDevice = clientDevice;
+ } break;
}
dawnProcSetProcs(&procs);
@@ -221,7 +219,8 @@
backendType = wgpu::BackendType::Vulkan;
continue;
}
- fprintf(stderr, "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n");
+ fprintf(stderr,
+ "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n");
return false;
}
if (std::string("-c") == argv[i] || std::string("--command-buffer") == argv[i]) {
diff --git a/src/tests/end2end/BasicTests.cpp b/src/tests/end2end/BasicTests.cpp
index 98ecb2e..4a0409f 100644
--- a/src/tests/end2end/BasicTests.cpp
+++ b/src/tests/end2end/BasicTests.cpp
@@ -16,8 +16,7 @@
#include "utils/WGPUHelpers.h"
-class BasicTests : public DawnTest {
-};
+class BasicTests : public DawnTest {};
// Test adapter filter by vendor id.
TEST_P(BasicTests, VendorIdFilter) {
diff --git a/src/tests/end2end/BindGroupTests.cpp b/src/tests/end2end/BindGroupTests.cpp
index 118a4ee..780f482 100644
--- a/src/tests/end2end/BindGroupTests.cpp
+++ b/src/tests/end2end/BindGroupTests.cpp
@@ -22,102 +22,102 @@
constexpr static uint32_t kRTSize = 8;
class BindGroupTests : public DawnTest {
-protected:
- wgpu::CommandBuffer CreateSimpleComputeCommandBuffer(const wgpu::ComputePipeline& pipeline,
- const wgpu::BindGroup& bindGroup) {
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
- pass.SetPipeline(pipeline);
- pass.SetBindGroup(0, bindGroup);
- pass.Dispatch(1);
- pass.EndPass();
- return encoder.Finish();
- }
+ protected:
+ wgpu::CommandBuffer CreateSimpleComputeCommandBuffer(const wgpu::ComputePipeline& pipeline,
+ const wgpu::BindGroup& bindGroup) {
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
+ pass.SetPipeline(pipeline);
+ pass.SetBindGroup(0, bindGroup);
+ pass.Dispatch(1);
+ pass.EndPass();
+ return encoder.Finish();
+ }
- wgpu::PipelineLayout MakeBasicPipelineLayout(
- std::vector<wgpu::BindGroupLayout> bindingInitializer) const {
- wgpu::PipelineLayoutDescriptor descriptor;
+ wgpu::PipelineLayout MakeBasicPipelineLayout(
+ std::vector<wgpu::BindGroupLayout> bindingInitializer) const {
+ wgpu::PipelineLayoutDescriptor descriptor;
- descriptor.bindGroupLayoutCount = bindingInitializer.size();
- descriptor.bindGroupLayouts = bindingInitializer.data();
+ descriptor.bindGroupLayoutCount = bindingInitializer.size();
+ descriptor.bindGroupLayouts = bindingInitializer.data();
- return device.CreatePipelineLayout(&descriptor);
- }
+ return device.CreatePipelineLayout(&descriptor);
+ }
- wgpu::ShaderModule MakeSimpleVSModule() const {
- return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ wgpu::ShaderModule MakeSimpleVSModule() const {
+ return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
const vec2 pos[3] = vec2[3](vec2(-1.f, 1.f), vec2(1.f, 1.f), vec2(-1.f, -1.f));
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
})");
- }
+ }
- wgpu::ShaderModule MakeFSModule(std::vector<wgpu::BindingType> bindingTypes) const {
- ASSERT(bindingTypes.size() <= kMaxBindGroups);
+ wgpu::ShaderModule MakeFSModule(std::vector<wgpu::BindingType> bindingTypes) const {
+ ASSERT(bindingTypes.size() <= kMaxBindGroups);
- std::ostringstream fs;
- fs << R"(
+ std::ostringstream fs;
+ fs << R"(
#version 450
layout(location = 0) out vec4 fragColor;
)";
- for (size_t i = 0; i < bindingTypes.size(); ++i) {
- switch (bindingTypes[i]) {
- case wgpu::BindingType::UniformBuffer:
- fs << "layout (std140, set = " << i << ", binding = 0) uniform UniformBuffer" << i
- << R"( {
+ for (size_t i = 0; i < bindingTypes.size(); ++i) {
+ switch (bindingTypes[i]) {
+ case wgpu::BindingType::UniformBuffer:
+ fs << "layout (std140, set = " << i << ", binding = 0) uniform UniformBuffer"
+ << i << R"( {
vec4 color;
} buffer)"
- << i << ";\n";
- break;
- case wgpu::BindingType::StorageBuffer:
- fs << "layout (std430, set = " << i << ", binding = 0) buffer StorageBuffer" << i
- << R"( {
+ << i << ";\n";
+ break;
+ case wgpu::BindingType::StorageBuffer:
+ fs << "layout (std430, set = " << i << ", binding = 0) buffer StorageBuffer"
+ << i << R"( {
vec4 color;
} buffer)"
- << i << ";\n";
- break;
- default:
- UNREACHABLE();
- }
- }
+ << i << ";\n";
+ break;
+ default:
+ UNREACHABLE();
+ }
+ }
- fs << R"(
+ fs << R"(
void main() {
fragColor = vec4(0.0);
)";
- for (size_t i = 0; i < bindingTypes.size(); ++i) {
- fs << "fragColor += buffer" << i << ".color;\n";
- }
- fs << "}\n";
+ for (size_t i = 0; i < bindingTypes.size(); ++i) {
+ fs << "fragColor += buffer" << i << ".color;\n";
+ }
+ fs << "}\n";
- return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
- fs.str().c_str());
- }
+ return utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment,
+ fs.str().c_str());
+ }
- wgpu::RenderPipeline MakeTestPipeline(const utils::BasicRenderPass& renderPass,
- std::vector<wgpu::BindingType> bindingTypes,
- std::vector<wgpu::BindGroupLayout> bindGroupLayouts) {
- wgpu::ShaderModule vsModule = MakeSimpleVSModule();
- wgpu::ShaderModule fsModule = MakeFSModule(bindingTypes);
+ wgpu::RenderPipeline MakeTestPipeline(const utils::BasicRenderPass& renderPass,
+ std::vector<wgpu::BindingType> bindingTypes,
+ std::vector<wgpu::BindGroupLayout> bindGroupLayouts) {
+ wgpu::ShaderModule vsModule = MakeSimpleVSModule();
+ wgpu::ShaderModule fsModule = MakeFSModule(bindingTypes);
- wgpu::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(bindGroupLayouts);
+ wgpu::PipelineLayout pipelineLayout = MakeBasicPipelineLayout(bindGroupLayouts);
- utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
- pipelineDescriptor.layout = pipelineLayout;
- pipelineDescriptor.vertexStage.module = vsModule;
- pipelineDescriptor.cFragmentStage.module = fsModule;
- pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
- pipelineDescriptor.cColorStates[0].colorBlend.operation = wgpu::BlendOperation::Add;
- pipelineDescriptor.cColorStates[0].colorBlend.srcFactor = wgpu::BlendFactor::One;
- pipelineDescriptor.cColorStates[0].colorBlend.dstFactor = wgpu::BlendFactor::One;
- pipelineDescriptor.cColorStates[0].alphaBlend.operation = wgpu::BlendOperation::Add;
- pipelineDescriptor.cColorStates[0].alphaBlend.srcFactor = wgpu::BlendFactor::One;
- pipelineDescriptor.cColorStates[0].alphaBlend.dstFactor = wgpu::BlendFactor::One;
+ utils::ComboRenderPipelineDescriptor pipelineDescriptor(device);
+ pipelineDescriptor.layout = pipelineLayout;
+ pipelineDescriptor.vertexStage.module = vsModule;
+ pipelineDescriptor.cFragmentStage.module = fsModule;
+ pipelineDescriptor.cColorStates[0].format = renderPass.colorFormat;
+ pipelineDescriptor.cColorStates[0].colorBlend.operation = wgpu::BlendOperation::Add;
+ pipelineDescriptor.cColorStates[0].colorBlend.srcFactor = wgpu::BlendFactor::One;
+ pipelineDescriptor.cColorStates[0].colorBlend.dstFactor = wgpu::BlendFactor::One;
+ pipelineDescriptor.cColorStates[0].alphaBlend.operation = wgpu::BlendOperation::Add;
+ pipelineDescriptor.cColorStates[0].alphaBlend.srcFactor = wgpu::BlendFactor::One;
+ pipelineDescriptor.cColorStates[0].alphaBlend.dstFactor = wgpu::BlendFactor::One;
- return device.CreateRenderPipeline(&pipelineDescriptor);
- }
+ return device.CreateRenderPipeline(&pipelineDescriptor);
+ }
};
// Test a bindgroup reused in two command buffers in the same call to queue.Submit().
@@ -195,10 +195,10 @@
};
ASSERT(offsetof(Data, color) == 256);
constexpr float dummy = 0.0f;
- Data data {
- { 1.f, 0.f, dummy, dummy, 0.f, 1.0f, dummy, dummy },
- { 0 },
- { 0.f, 1.f, 0.f, 1.f },
+ Data data{
+ {1.f, 0.f, dummy, dummy, 0.f, 1.0f, dummy, dummy},
+ {0},
+ {0.f, 1.f, 0.f, 1.f},
};
wgpu::Buffer buffer =
utils::CreateBufferFromData(device, &data, sizeof(data), wgpu::BufferUsage::Uniform);
@@ -219,15 +219,15 @@
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(notFilled, renderPass.color, max, max);
}
-// Test a bindgroup containing a UBO in the vertex shader and a sampler and texture in the fragment shader.
-// In D3D12 for example, these different types of bindings end up in different namespaces, but the register
-// offsets used must match between the shader module and descriptor range.
+// Test a bindgroup containing a UBO in the vertex shader and a sampler and texture in the fragment
+// shader. In D3D12 for example, these different types of bindings end up in different namespaces,
+// but the register offsets used must match between the shader module and descriptor range.
TEST_P(BindGroupTests, UBOSamplerAndTexture) {
utils::BasicRenderPass renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
@@ -260,7 +260,7 @@
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDescriptor);
constexpr float dummy = 0.0f;
- constexpr float transform[] = { 1.f, 0.f, dummy, dummy, 0.f, 1.f, dummy, dummy };
+ constexpr float transform[] = {1.f, 0.f, dummy, dummy, 0.f, 1.f, dummy, dummy};
wgpu::Buffer buffer = utils::CreateBufferFromData(device, &transform, sizeof(transform),
wgpu::BufferUsage::Uniform);
@@ -320,9 +320,9 @@
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
uint32_t min = 1, max = kRTSize - 3;
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
- EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min);
+ EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max);
EXPECT_PIXEL_RGBA8_EQ(notFilled, renderPass.color, max, max);
}
@@ -1091,4 +1091,8 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 0, 0);
}
-DAWN_INSTANTIATE_TEST(BindGroupTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(BindGroupTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp
index f010be6..4b626ee 100644
--- a/src/tests/end2end/BufferTests.cpp
+++ b/src/tests/end2end/BufferTests.cpp
@@ -17,34 +17,34 @@
#include <cstring>
class BufferMapReadTests : public DawnTest {
- protected:
- static void MapReadCallback(WGPUBufferMapAsyncStatus status,
- const void* data,
- uint64_t,
- void* userdata) {
- ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
- ASSERT_NE(nullptr, data);
+ protected:
+ static void MapReadCallback(WGPUBufferMapAsyncStatus status,
+ const void* data,
+ uint64_t,
+ void* userdata) {
+ ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
+ ASSERT_NE(nullptr, data);
- static_cast<BufferMapReadTests*>(userdata)->mappedData = data;
- }
+ static_cast<BufferMapReadTests*>(userdata)->mappedData = data;
+ }
- const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
- buffer.MapReadAsync(MapReadCallback, this);
+ const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
+ buffer.MapReadAsync(MapReadCallback, this);
- while (mappedData == nullptr) {
- WaitABit();
- }
+ while (mappedData == nullptr) {
+ WaitABit();
+ }
- return mappedData;
- }
+ return mappedData;
+ }
- void UnmapBuffer(const wgpu::Buffer& buffer) {
- buffer.Unmap();
- mappedData = nullptr;
- }
+ void UnmapBuffer(const wgpu::Buffer& buffer) {
+ buffer.Unmap();
+ mappedData = nullptr;
+ }
- private:
- const void* mappedData = nullptr;
+ private:
+ const void* mappedData = nullptr;
};
// Test that the simplest map read works.
@@ -145,41 +145,45 @@
UnmapBuffer(buffer);
}
-DAWN_INSTANTIATE_TEST(BufferMapReadTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(BufferMapReadTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
class BufferMapWriteTests : public DawnTest {
- protected:
- static void MapWriteCallback(WGPUBufferMapAsyncStatus status,
- void* data,
- uint64_t,
- void* userdata) {
- ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
- ASSERT_NE(nullptr, data);
+ protected:
+ static void MapWriteCallback(WGPUBufferMapAsyncStatus status,
+ void* data,
+ uint64_t,
+ void* userdata) {
+ ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
+ ASSERT_NE(nullptr, data);
- static_cast<BufferMapWriteTests*>(userdata)->mappedData = data;
- }
+ static_cast<BufferMapWriteTests*>(userdata)->mappedData = data;
+ }
- void* MapWriteAsyncAndWait(const wgpu::Buffer& buffer) {
- buffer.MapWriteAsync(MapWriteCallback, this);
+ void* MapWriteAsyncAndWait(const wgpu::Buffer& buffer) {
+ buffer.MapWriteAsync(MapWriteCallback, this);
- while (mappedData == nullptr) {
- WaitABit();
- }
+ while (mappedData == nullptr) {
+ WaitABit();
+ }
- // Ensure the prior write's status is updated.
- void* resultPointer = mappedData;
- mappedData = nullptr;
+ // Ensure the prior write's status is updated.
+ void* resultPointer = mappedData;
+ mappedData = nullptr;
- return resultPointer;
- }
+ return resultPointer;
+ }
- void UnmapBuffer(const wgpu::Buffer& buffer) {
- buffer.Unmap();
- mappedData = nullptr;
- }
+ void UnmapBuffer(const wgpu::Buffer& buffer) {
+ buffer.Unmap();
+ mappedData = nullptr;
+ }
- private:
- void* mappedData = nullptr;
+ private:
+ void* mappedData = nullptr;
};
// Test that the simplest map write works.
@@ -307,64 +311,68 @@
UnmapBuffer(buffer);
}
-DAWN_INSTANTIATE_TEST(BufferMapWriteTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(BufferMapWriteTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
class CreateBufferMappedTests : public DawnTest {
- protected:
- static void MapReadCallback(WGPUBufferMapAsyncStatus status,
- const void* data,
- uint64_t,
- void* userdata) {
- ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
- ASSERT_NE(nullptr, data);
+ protected:
+ static void MapReadCallback(WGPUBufferMapAsyncStatus status,
+ const void* data,
+ uint64_t,
+ void* userdata) {
+ ASSERT_EQ(WGPUBufferMapAsyncStatus_Success, status);
+ ASSERT_NE(nullptr, data);
- static_cast<CreateBufferMappedTests*>(userdata)->mappedData = data;
- }
+ static_cast<CreateBufferMappedTests*>(userdata)->mappedData = data;
+ }
- const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
- buffer.MapReadAsync(MapReadCallback, this);
+ const void* MapReadAsyncAndWait(const wgpu::Buffer& buffer) {
+ buffer.MapReadAsync(MapReadCallback, this);
- while (mappedData == nullptr) {
- WaitABit();
- }
+ while (mappedData == nullptr) {
+ WaitABit();
+ }
- return mappedData;
- }
+ return mappedData;
+ }
- void UnmapBuffer(const wgpu::Buffer& buffer) {
- buffer.Unmap();
- mappedData = nullptr;
- }
+ void UnmapBuffer(const wgpu::Buffer& buffer) {
+ buffer.Unmap();
+ mappedData = nullptr;
+ }
- void CheckResultStartsZeroed(const wgpu::CreateBufferMappedResult& result, uint64_t size) {
- ASSERT_EQ(result.dataLength, size);
- for (uint64_t i = 0; i < result.dataLength; ++i) {
- uint8_t value = *(reinterpret_cast<uint8_t*>(result.data) + i);
- ASSERT_EQ(value, 0u);
- }
- }
+ void CheckResultStartsZeroed(const wgpu::CreateBufferMappedResult& result, uint64_t size) {
+ ASSERT_EQ(result.dataLength, size);
+ for (uint64_t i = 0; i < result.dataLength; ++i) {
+ uint8_t value = *(reinterpret_cast<uint8_t*>(result.data) + i);
+ ASSERT_EQ(value, 0u);
+ }
+ }
- wgpu::CreateBufferMappedResult CreateBufferMapped(wgpu::BufferUsage usage, uint64_t size) {
- wgpu::BufferDescriptor descriptor = {};
- descriptor.size = size;
- descriptor.usage = usage;
+ wgpu::CreateBufferMappedResult CreateBufferMapped(wgpu::BufferUsage usage, uint64_t size) {
+ wgpu::BufferDescriptor descriptor = {};
+ descriptor.size = size;
+ descriptor.usage = usage;
- wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
- CheckResultStartsZeroed(result, size);
- return result;
- }
+ wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
+ CheckResultStartsZeroed(result, size);
+ return result;
+ }
- wgpu::CreateBufferMappedResult CreateBufferMappedWithData(wgpu::BufferUsage usage,
- const std::vector<uint32_t>& data) {
- size_t byteLength = data.size() * sizeof(uint32_t);
- wgpu::CreateBufferMappedResult result = CreateBufferMapped(usage, byteLength);
- memcpy(result.data, data.data(), byteLength);
+ wgpu::CreateBufferMappedResult CreateBufferMappedWithData(wgpu::BufferUsage usage,
+ const std::vector<uint32_t>& data) {
+ size_t byteLength = data.size() * sizeof(uint32_t);
+ wgpu::CreateBufferMappedResult result = CreateBufferMapped(usage, byteLength);
+ memcpy(result.data, data.data(), byteLength);
- return result;
- }
+ return result;
+ }
- private:
- const void* mappedData = nullptr;
+ private:
+ const void* mappedData = nullptr;
};
// Test that the simplest CreateBufferMapped works for MapWrite buffers.
diff --git a/src/tests/end2end/ClipSpaceTests.cpp b/src/tests/end2end/ClipSpaceTests.cpp
index be97ced..33c78e9 100644
--- a/src/tests/end2end/ClipSpaceTests.cpp
+++ b/src/tests/end2end/ClipSpaceTests.cpp
@@ -97,4 +97,8 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, colorTexture, 0, 0);
}
-DAWN_INSTANTIATE_TEST(ClipSpaceTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ClipSpaceTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/ColorStateTests.cpp b/src/tests/end2end/ColorStateTests.cpp
index f0fa1e5..b4f935d 100644
--- a/src/tests/end2end/ColorStateTests.cpp
+++ b/src/tests/end2end/ColorStateTests.cpp
@@ -758,8 +758,8 @@
renderTargetViews[i] = renderTargets[i].CreateView();
}
- utils::ComboRenderPassDescriptor renderPass({renderTargetViews[0], renderTargetViews[1],
- renderTargetViews[2], renderTargetViews[3]});
+ utils::ComboRenderPassDescriptor renderPass(
+ {renderTargetViews[0], renderTargetViews[1], renderTargetViews[2], renderTargetViews[3]});
wgpu::ShaderModule fsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
@@ -1047,4 +1047,8 @@
EXPECT_PIXEL_RGBA8_EQ(expected, renderPass.color, kRTSize / 2, kRTSize / 2);
}
-DAWN_INSTANTIATE_TEST(ColorStateTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ColorStateTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
index dcb762e..f127acd 100644
--- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
+++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
@@ -173,7 +173,7 @@
}
DAWN_INSTANTIATE_TEST(ComputeCopyStorageBufferTests,
- D3D12Backend(),
- MetalBackend(),
- OpenGLBackend(),
- VulkanBackend());
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/ComputeSharedMemoryTests.cpp b/src/tests/end2end/ComputeSharedMemoryTests.cpp
index bb33856..a11c01a 100644
--- a/src/tests/end2end/ComputeSharedMemoryTests.cpp
+++ b/src/tests/end2end/ComputeSharedMemoryTests.cpp
@@ -98,7 +98,7 @@
}
DAWN_INSTANTIATE_TEST(ComputeSharedMemoryTests,
- D3D12Backend(),
- MetalBackend(),
- OpenGLBackend(),
- VulkanBackend());
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp
index 5d592a1..75de2f6 100644
--- a/src/tests/end2end/CopyTests.cpp
+++ b/src/tests/end2end/CopyTests.cpp
@@ -21,164 +21,164 @@
#include "utils/WGPUHelpers.h"
class CopyTests : public DawnTest {
- protected:
- static constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
+ protected:
+ static constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
- struct TextureSpec {
- wgpu::Origin3D copyOrigin;
- wgpu::Extent3D textureSize;
- uint32_t level;
- };
+ struct TextureSpec {
+ wgpu::Origin3D copyOrigin;
+ wgpu::Extent3D textureSize;
+ uint32_t level;
+ };
- struct BufferSpec {
- uint64_t size;
- uint64_t offset;
- uint32_t bytesPerRow;
- uint32_t rowsPerImage;
- };
+ struct BufferSpec {
+ uint64_t size;
+ uint64_t offset;
+ uint32_t bytesPerRow;
+ uint32_t rowsPerImage;
+ };
- static std::vector<RGBA8> GetExpectedTextureData(
- const utils::BufferTextureCopyLayout& layout) {
- std::vector<RGBA8> textureData(layout.texelBlockCount);
- for (uint32_t layer = 0; layer < layout.mipSize.depth; ++layer) {
- const uint32_t texelIndexOffsetPerSlice = layout.texelBlocksPerImage * layer;
- for (uint32_t y = 0; y < layout.mipSize.height; ++y) {
- for (uint32_t x = 0; x < layout.mipSize.width; ++x) {
- uint32_t i = x + y * layout.texelBlocksPerRow;
- textureData[texelIndexOffsetPerSlice + i] =
- RGBA8(static_cast<uint8_t>((x + layer * x) % 256),
- static_cast<uint8_t>((y + layer * y) % 256),
- static_cast<uint8_t>(x / 256), static_cast<uint8_t>(y / 256));
- }
- }
- }
-
- return textureData;
- }
-
- static BufferSpec MinimumBufferSpec(uint32_t width,
- uint32_t rowsPerImage,
- uint32_t arrayLayer = 1,
- bool testZeroRowsPerImage = true) {
- const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kTextureFormat, width);
- const uint32_t totalBufferSize = utils::GetBytesInBufferTextureCopy(
- kTextureFormat, width, bytesPerRow, rowsPerImage, arrayLayer);
- uint32_t appliedRowsPerImage = testZeroRowsPerImage ? 0 : rowsPerImage;
- return {totalBufferSize, 0, bytesPerRow, appliedRowsPerImage};
- }
-
- static void PackTextureData(const RGBA8* srcData, uint32_t width, uint32_t height, uint32_t srcTexelsPerRow, RGBA8* dstData, uint32_t dstTexelsPerRow) {
- for (unsigned int y = 0; y < height; ++y) {
- for (unsigned int x = 0; x < width; ++x) {
- unsigned int src = x + y * srcTexelsPerRow;
- unsigned int dst = x + y * dstTexelsPerRow;
- dstData[dst] = srcData[src];
+ static std::vector<RGBA8> GetExpectedTextureData(const utils::BufferTextureCopyLayout& layout) {
+ std::vector<RGBA8> textureData(layout.texelBlockCount);
+ for (uint32_t layer = 0; layer < layout.mipSize.depth; ++layer) {
+ const uint32_t texelIndexOffsetPerSlice = layout.texelBlocksPerImage * layer;
+ for (uint32_t y = 0; y < layout.mipSize.height; ++y) {
+ for (uint32_t x = 0; x < layout.mipSize.width; ++x) {
+ uint32_t i = x + y * layout.texelBlocksPerRow;
+ textureData[texelIndexOffsetPerSlice + i] =
+ RGBA8(static_cast<uint8_t>((x + layer * x) % 256),
+ static_cast<uint8_t>((y + layer * y) % 256),
+ static_cast<uint8_t>(x / 256), static_cast<uint8_t>(y / 256));
}
}
}
+
+ return textureData;
+ }
+
+ static BufferSpec MinimumBufferSpec(uint32_t width,
+ uint32_t rowsPerImage,
+ uint32_t arrayLayer = 1,
+ bool testZeroRowsPerImage = true) {
+ const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kTextureFormat, width);
+ const uint32_t totalBufferSize = utils::GetBytesInBufferTextureCopy(
+ kTextureFormat, width, bytesPerRow, rowsPerImage, arrayLayer);
+ uint32_t appliedRowsPerImage = testZeroRowsPerImage ? 0 : rowsPerImage;
+ return {totalBufferSize, 0, bytesPerRow, appliedRowsPerImage};
+ }
+
+ static void PackTextureData(const RGBA8* srcData,
+ uint32_t width,
+ uint32_t height,
+ uint32_t srcTexelsPerRow,
+ RGBA8* dstData,
+ uint32_t dstTexelsPerRow) {
+ for (unsigned int y = 0; y < height; ++y) {
+ for (unsigned int x = 0; x < width; ++x) {
+ unsigned int src = x + y * srcTexelsPerRow;
+ unsigned int dst = x + y * dstTexelsPerRow;
+ dstData[dst] = srcData[src];
+ }
+ }
+ }
};
class CopyTests_T2B : public CopyTests {
- protected:
- void DoTest(const TextureSpec& textureSpec,
- const BufferSpec& bufferSpec,
- const wgpu::Extent3D& copySize) {
- // Create a texture that is `width` x `height` with (`level` + 1) mip levels.
- wgpu::TextureDescriptor descriptor;
- descriptor.dimension = wgpu::TextureDimension::e2D;
- descriptor.size = textureSpec.textureSize;
- descriptor.sampleCount = 1;
- descriptor.format = kTextureFormat;
- descriptor.mipLevelCount = textureSpec.level + 1;
- descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
- wgpu::Texture texture = device.CreateTexture(&descriptor);
+ protected:
+ void DoTest(const TextureSpec& textureSpec,
+ const BufferSpec& bufferSpec,
+ const wgpu::Extent3D& copySize) {
+ // Create a texture that is `width` x `height` with (`level` + 1) mip levels.
+ wgpu::TextureDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.size = textureSpec.textureSize;
+ descriptor.sampleCount = 1;
+ descriptor.format = kTextureFormat;
+ descriptor.mipLevelCount = textureSpec.level + 1;
+ descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
- const utils::BufferTextureCopyLayout copyLayout =
- utils::GetBufferTextureCopyLayoutForTexture2DAtLevel(
- kTextureFormat, textureSpec.textureSize, textureSpec.level,
- bufferSpec.rowsPerImage);
+ const utils::BufferTextureCopyLayout copyLayout =
+ utils::GetBufferTextureCopyLayoutForTexture2DAtLevel(
+ kTextureFormat, textureSpec.textureSize, textureSpec.level,
+ bufferSpec.rowsPerImage);
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- // Initialize the source texture
- std::vector<RGBA8> textureArrayData = GetExpectedTextureData(copyLayout);
- {
- wgpu::Buffer uploadBuffer =
- utils::CreateBufferFromData(device, textureArrayData.data(),
- copyLayout.byteLength, wgpu::BufferUsage::CopySrc);
- wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
- uploadBuffer, 0, copyLayout.bytesPerRow, bufferSpec.rowsPerImage);
- wgpu::TextureCopyView textureCopyView =
- utils::CreateTextureCopyView(texture, textureSpec.level, {0, 0, 0});
- encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Layout.mipSize);
- }
+ // Initialize the source texture
+ std::vector<RGBA8> textureArrayData = GetExpectedTextureData(copyLayout);
+ {
+ wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
+ device, textureArrayData.data(), copyLayout.byteLength, wgpu::BufferUsage::CopySrc);
+ wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
+ uploadBuffer, 0, copyLayout.bytesPerRow, bufferSpec.rowsPerImage);
+ wgpu::TextureCopyView textureCopyView =
+ utils::CreateTextureCopyView(texture, textureSpec.level, {0, 0, 0});
+ encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Layout.mipSize);
+ }
- // Create a buffer of `size` and populate it with empty data (0,0,0,0) Note:
- // Prepopulating the buffer with empty data ensures that there is not random data in the
- // expectation and helps ensure that the padding due to the bytes per row is not modified
- // by the copy.
- // TODO(jiawei.shao@intel.com): remove the initialization of the buffer after we support
- // buffer lazy-initialization.
- const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(kTextureFormat);
- const std::vector<RGBA8> emptyData(bufferSpec.size / bytesPerTexel, RGBA8());
- wgpu::Buffer buffer =
- utils::CreateBufferFromData(device, emptyData.data(), bufferSpec.size,
- wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst);
+ // Create a buffer of `size` and populate it with empty data (0,0,0,0) Note:
+ // Prepopulating the buffer with empty data ensures that there is not random data in the
+ // expectation and helps ensure that the padding due to the bytes per row is not modified
+ // by the copy.
+ // TODO(jiawei.shao@intel.com): remove the initialization of the buffer after we support
+ // buffer lazy-initialization.
+ const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(kTextureFormat);
+ const std::vector<RGBA8> emptyData(bufferSpec.size / bytesPerTexel, RGBA8());
+ wgpu::Buffer buffer =
+ utils::CreateBufferFromData(device, emptyData.data(), bufferSpec.size,
+ wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst);
- {
- wgpu::TextureCopyView textureCopyView =
- utils::CreateTextureCopyView(texture, textureSpec.level, textureSpec.copyOrigin);
- wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
- buffer, bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
- encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size);
- }
+ {
+ wgpu::TextureCopyView textureCopyView =
+ utils::CreateTextureCopyView(texture, textureSpec.level, textureSpec.copyOrigin);
+ wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
+ buffer, bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
+ encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size);
+ }
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
- uint64_t bufferOffset = bufferSpec.offset;
- const uint32_t texelCountInCopyRegion =
- bufferSpec.bytesPerRow / bytesPerTexel * (copySize.height - 1) + copySize.width;
- const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copySize.depth;
- std::vector<RGBA8> expected(texelCountInCopyRegion);
- for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
- // Pack the data used to create the upload buffer in the specified copy region to have
- // the same format as the expected buffer data.
- std::fill(expected.begin(), expected.end(), RGBA8());
- const uint32_t texelIndexOffset = copyLayout.texelBlocksPerImage * slice;
- const uint32_t expectedTexelArrayDataStartIndex =
- texelIndexOffset + (textureSpec.copyOrigin.x +
- textureSpec.copyOrigin.y * copyLayout.texelBlocksPerRow);
+ uint64_t bufferOffset = bufferSpec.offset;
+ const uint32_t texelCountInCopyRegion =
+ bufferSpec.bytesPerRow / bytesPerTexel * (copySize.height - 1) + copySize.width;
+ const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copySize.depth;
+ std::vector<RGBA8> expected(texelCountInCopyRegion);
+ for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
+ // Pack the data used to create the upload buffer in the specified copy region to have
+ // the same format as the expected buffer data.
+ std::fill(expected.begin(), expected.end(), RGBA8());
+ const uint32_t texelIndexOffset = copyLayout.texelBlocksPerImage * slice;
+ const uint32_t expectedTexelArrayDataStartIndex =
+ texelIndexOffset + (textureSpec.copyOrigin.x +
+ textureSpec.copyOrigin.y * copyLayout.texelBlocksPerRow);
- PackTextureData(&textureArrayData[expectedTexelArrayDataStartIndex], copySize.width,
- copySize.height, copyLayout.texelBlocksPerRow, expected.data(),
- bufferSpec.bytesPerRow / bytesPerTexel);
+ PackTextureData(&textureArrayData[expectedTexelArrayDataStartIndex], copySize.width,
+ copySize.height, copyLayout.texelBlocksPerRow, expected.data(),
+ bufferSpec.bytesPerRow / bytesPerTexel);
- EXPECT_BUFFER_U32_RANGE_EQ(reinterpret_cast<const uint32_t*>(expected.data()), buffer,
- bufferOffset, static_cast<uint32_t>(expected.size()))
- << "Texture to Buffer copy failed copying region [(" << textureSpec.copyOrigin.x
- << ", " << textureSpec.copyOrigin.y << "), ("
- << textureSpec.copyOrigin.x + copySize.width << ", "
- << textureSpec.copyOrigin.y + copySize.height << ")) from "
- << textureSpec.textureSize.width << " x " << textureSpec.textureSize.height
- << " texture at mip level " << textureSpec.level << " layer " << slice << " to "
- << bufferSpec.size << "-byte buffer with offset " << bufferOffset
- << " and bytes per row " << bufferSpec.bytesPerRow << std::endl;
+ EXPECT_BUFFER_U32_RANGE_EQ(reinterpret_cast<const uint32_t*>(expected.data()), buffer,
+ bufferOffset, static_cast<uint32_t>(expected.size()))
+ << "Texture to Buffer copy failed copying region [(" << textureSpec.copyOrigin.x
+ << ", " << textureSpec.copyOrigin.y << "), ("
+ << textureSpec.copyOrigin.x + copySize.width << ", "
+ << textureSpec.copyOrigin.y + copySize.height << ")) from "
+ << textureSpec.textureSize.width << " x " << textureSpec.textureSize.height
+ << " texture at mip level " << textureSpec.level << " layer " << slice << " to "
+ << bufferSpec.size << "-byte buffer with offset " << bufferOffset
+ << " and bytes per row " << bufferSpec.bytesPerRow << std::endl;
- bufferOffset += copyLayout.bytesPerImage;
- }
- }
+ bufferOffset += copyLayout.bytesPerImage;
+ }
+ }
};
class CopyTests_B2T : public CopyTests {
-protected:
+ protected:
static void FillBufferData(RGBA8* data, size_t count) {
for (size_t i = 0; i < count; ++i) {
- data[i] = RGBA8(
- static_cast<uint8_t>(i % 256),
- static_cast<uint8_t>((i / 256) % 256),
- static_cast<uint8_t>((i / 256 / 256) % 256),
- 255);
+ data[i] = RGBA8(static_cast<uint8_t>(i % 256), static_cast<uint8_t>((i / 256) % 256),
+ static_cast<uint8_t>((i / 256 / 256) % 256), 255);
}
}
@@ -510,7 +510,7 @@
constexpr uint32_t kWidth = 256;
constexpr uint32_t kHeight = 128;
for (unsigned int w : {64, 128, 256}) {
- for (unsigned int h : { 16, 32, 48 }) {
+ for (unsigned int h : {16, 32, 48}) {
TextureSpec textureSpec;
textureSpec.copyOrigin = {0, 0, 0};
textureSpec.level = 0;
@@ -531,7 +531,7 @@
defaultTextureSpec.textureSize = {kWidth, kHeight, 1};
for (unsigned int w : {13, 63, 65}) {
- for (unsigned int h : { 17, 19, 63 }) {
+ for (unsigned int h : {17, 19, 63}) {
TextureSpec textureSpec = defaultTextureSpec;
DoTest(textureSpec, MinimumBufferSpec(w, h), {w, h, 1});
}
@@ -746,7 +746,11 @@
DoTest(textureSpec, bufferSpec, {kWidth, kHeight, kCopyLayers});
}
-DAWN_INSTANTIATE_TEST(CopyTests_T2B, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(CopyTests_T2B,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
// Test that copying an entire texture with 256-byte aligned dimensions works
TEST_P(CopyTests_B2T, FullTextureAligned) {
@@ -877,7 +881,7 @@
constexpr uint32_t kWidth = 256;
constexpr uint32_t kHeight = 128;
for (unsigned int w : {64, 128, 256}) {
- for (unsigned int h : { 16, 32, 48 }) {
+ for (unsigned int h : {16, 32, 48}) {
TextureSpec textureSpec;
textureSpec.copyOrigin = {0, 0, 0};
textureSpec.level = 0;
@@ -1090,7 +1094,11 @@
DoTest(textureSpec, bufferSpec, {kWidth, kHeight, kCopyLayers});
}
-DAWN_INSTANTIATE_TEST(CopyTests_B2T, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(CopyTests_B2T,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
TEST_P(CopyTests_T2T, Texture) {
constexpr uint32_t kWidth = 256;
@@ -1310,7 +1318,11 @@
}
}
-DAWN_INSTANTIATE_TEST(CopyTests_T2T, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(CopyTests_T2T,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
static constexpr uint64_t kSmallBufferSize = 4;
static constexpr uint64_t kLargeBufferSize = 1 << 16;
diff --git a/src/tests/end2end/CullingTests.cpp b/src/tests/end2end/CullingTests.cpp
index 79a2303..726df13 100644
--- a/src/tests/end2end/CullingTests.cpp
+++ b/src/tests/end2end/CullingTests.cpp
@@ -127,4 +127,8 @@
DoTest(wgpu::FrontFace::CW, wgpu::CullMode::Back, true, false);
}
-DAWN_INSTANTIATE_TEST(CullingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(CullingTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/D3D12ResourceWrappingTests.cpp b/src/tests/end2end/D3D12ResourceWrappingTests.cpp
index 2907a87..364f48f 100644
--- a/src/tests/end2end/D3D12ResourceWrappingTests.cpp
+++ b/src/tests/end2end/D3D12ResourceWrappingTests.cpp
@@ -130,8 +130,7 @@
// A small fixture used to initialize default data for the D3D12Resource validation tests.
// These tests are skipped if the harness is using the wire.
-class D3D12SharedHandleValidation : public D3D12ResourceTestBase {
-};
+class D3D12SharedHandleValidation : public D3D12ResourceTestBase {};
// Test a successful wrapping of an D3D12Resource in a texture
TEST_P(D3D12SharedHandleValidation, Success) {
diff --git a/src/tests/end2end/DebugMarkerTests.cpp b/src/tests/end2end/DebugMarkerTests.cpp
index f9fab77..d368a17 100644
--- a/src/tests/end2end/DebugMarkerTests.cpp
+++ b/src/tests/end2end/DebugMarkerTests.cpp
@@ -42,4 +42,8 @@
queue.Submit(1, &commands);
}
-DAWN_INSTANTIATE_TEST(DebugMarkerTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(DebugMarkerTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/DepthSamplingTests.cpp b/src/tests/end2end/DepthSamplingTests.cpp
index 7c24a69..06dcce6e 100644
--- a/src/tests/end2end/DepthSamplingTests.cpp
+++ b/src/tests/end2end/DepthSamplingTests.cpp
@@ -20,14 +20,10 @@
namespace {
constexpr wgpu::CompareFunction kCompareFunctions[] = {
- wgpu::CompareFunction::Never,
- wgpu::CompareFunction::Less,
- wgpu::CompareFunction::LessEqual,
- wgpu::CompareFunction::Greater,
- wgpu::CompareFunction::GreaterEqual,
- wgpu::CompareFunction::Equal,
- wgpu::CompareFunction::NotEqual,
- wgpu::CompareFunction::Always,
+ wgpu::CompareFunction::Never, wgpu::CompareFunction::Less,
+ wgpu::CompareFunction::LessEqual, wgpu::CompareFunction::Greater,
+ wgpu::CompareFunction::GreaterEqual, wgpu::CompareFunction::Equal,
+ wgpu::CompareFunction::NotEqual, wgpu::CompareFunction::Always,
};
// Test a "normal" ref value between 0 and 1; as well as negative and > 1 refs.
@@ -225,12 +221,11 @@
wgpu::SamplerDescriptor samplerDesc;
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
- wgpu::BindGroup bindGroup =
- utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
- {
- {0, sampler},
- {1, mInputTexture.CreateView()},
- });
+ wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
+ {
+ {0, sampler},
+ {1, mInputTexture.CreateView()},
+ });
for (float textureValue : textureValues) {
// Set the input depth texture to the provided texture value
@@ -258,12 +253,9 @@
wgpu::SamplerDescriptor samplerDesc;
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
- wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
- {
- {0, sampler},
- {1, mInputTexture.CreateView()},
- {2, mOutputBuffer}
- });
+ wgpu::BindGroup bindGroup = utils::MakeBindGroup(
+ device, pipeline.GetBindGroupLayout(0),
+ {{0, sampler}, {1, mInputTexture.CreateView()}, {2, mOutputBuffer}});
for (float textureValue : textureValues) {
// Set the input depth texture to the provided texture value
@@ -321,13 +313,12 @@
samplerDesc.compare = compare;
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
- wgpu::BindGroup bindGroup =
- utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
- {
- {0, sampler},
- {1, mInputTexture.CreateView()},
- {2, mUniformBuffer},
- });
+ wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
+ {
+ {0, sampler},
+ {1, mInputTexture.CreateView()},
+ {2, mUniformBuffer},
+ });
for (float textureValue : textureValues) {
// Set the input depth texture to the provided texture value
@@ -364,12 +355,10 @@
wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
- {
- {0, sampler},
- {1, mInputTexture.CreateView()},
- {2, mUniformBuffer},
- {3, mOutputBuffer}
- });
+ {{0, sampler},
+ {1, mInputTexture.CreateView()},
+ {2, mUniformBuffer},
+ {3, mOutputBuffer}});
for (float textureValue : textureValues) {
// Set the input depth texture to the provided texture value
diff --git a/src/tests/end2end/DepthStencilStateTests.cpp b/src/tests/end2end/DepthStencilStateTests.cpp
index 4881437..4788094 100644
--- a/src/tests/end2end/DepthStencilStateTests.cpp
+++ b/src/tests/end2end/DepthStencilStateTests.cpp
@@ -21,38 +21,38 @@
constexpr static unsigned int kRTSize = 64;
class DepthStencilStateTest : public DawnTest {
- protected:
- void SetUp() override {
- DawnTest::SetUp();
+ protected:
+ void SetUp() override {
+ DawnTest::SetUp();
- wgpu::TextureDescriptor renderTargetDescriptor;
- renderTargetDescriptor.dimension = wgpu::TextureDimension::e2D;
- renderTargetDescriptor.size.width = kRTSize;
- renderTargetDescriptor.size.height = kRTSize;
- renderTargetDescriptor.size.depth = 1;
- renderTargetDescriptor.sampleCount = 1;
- renderTargetDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- renderTargetDescriptor.mipLevelCount = 1;
- renderTargetDescriptor.usage =
- wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
- renderTarget = device.CreateTexture(&renderTargetDescriptor);
+ wgpu::TextureDescriptor renderTargetDescriptor;
+ renderTargetDescriptor.dimension = wgpu::TextureDimension::e2D;
+ renderTargetDescriptor.size.width = kRTSize;
+ renderTargetDescriptor.size.height = kRTSize;
+ renderTargetDescriptor.size.depth = 1;
+ renderTargetDescriptor.sampleCount = 1;
+ renderTargetDescriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ renderTargetDescriptor.mipLevelCount = 1;
+ renderTargetDescriptor.usage =
+ wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
+ renderTarget = device.CreateTexture(&renderTargetDescriptor);
- renderTargetView = renderTarget.CreateView();
+ renderTargetView = renderTarget.CreateView();
- wgpu::TextureDescriptor depthDescriptor;
- depthDescriptor.dimension = wgpu::TextureDimension::e2D;
- depthDescriptor.size.width = kRTSize;
- depthDescriptor.size.height = kRTSize;
- depthDescriptor.size.depth = 1;
- depthDescriptor.sampleCount = 1;
- depthDescriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
- depthDescriptor.mipLevelCount = 1;
- depthDescriptor.usage = wgpu::TextureUsage::OutputAttachment;
- depthTexture = device.CreateTexture(&depthDescriptor);
+ wgpu::TextureDescriptor depthDescriptor;
+ depthDescriptor.dimension = wgpu::TextureDimension::e2D;
+ depthDescriptor.size.width = kRTSize;
+ depthDescriptor.size.height = kRTSize;
+ depthDescriptor.size.depth = 1;
+ depthDescriptor.sampleCount = 1;
+ depthDescriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
+ depthDescriptor.mipLevelCount = 1;
+ depthDescriptor.usage = wgpu::TextureUsage::OutputAttachment;
+ depthTexture = device.CreateTexture(&depthDescriptor);
- depthTextureView = depthTexture.CreateView();
+ depthTextureView = depthTexture.CreateView();
- vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
vec3 color;
@@ -67,7 +67,7 @@
}
)");
- fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(set = 0, binding = 0) uniform myBlock {
vec3 color;
@@ -78,235 +78,251 @@
fragColor = vec4(myUbo.color, 1.f);
}
)");
- }
+ }
- struct TestSpec {
- const wgpu::DepthStencilStateDescriptor& depthStencilState;
- RGBA8 color;
- float depth;
- uint32_t stencil;
- };
+ struct TestSpec {
+ const wgpu::DepthStencilStateDescriptor& depthStencilState;
+ RGBA8 color;
+ float depth;
+ uint32_t stencil;
+ };
- // Check whether a depth comparison function works as expected
- // The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function
- void CheckDepthCompareFunction(wgpu::CompareFunction compareFunction,
- bool less,
- bool equal,
- bool greater) {
- wgpu::StencilStateFaceDescriptor stencilFace;
- stencilFace.compare = wgpu::CompareFunction::Always;
- stencilFace.failOp = wgpu::StencilOperation::Keep;
- stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
- stencilFace.passOp = wgpu::StencilOperation::Keep;
+ // Check whether a depth comparison function works as expected
+ // The less, equal, greater booleans denote wether the respective triangle should be visible
+ // based on the comparison function
+ void CheckDepthCompareFunction(wgpu::CompareFunction compareFunction,
+ bool less,
+ bool equal,
+ bool greater) {
+ wgpu::StencilStateFaceDescriptor stencilFace;
+ stencilFace.compare = wgpu::CompareFunction::Always;
+ stencilFace.failOp = wgpu::StencilOperation::Keep;
+ stencilFace.depthFailOp = wgpu::StencilOperation::Keep;
+ stencilFace.passOp = wgpu::StencilOperation::Keep;
- wgpu::DepthStencilStateDescriptor baseState;
- baseState.depthWriteEnabled = true;
- baseState.depthCompare = wgpu::CompareFunction::Always;
- baseState.stencilBack = stencilFace;
- baseState.stencilFront = stencilFace;
- baseState.stencilReadMask = 0xff;
- baseState.stencilWriteMask = 0xff;
+ wgpu::DepthStencilStateDescriptor baseState;
+ baseState.depthWriteEnabled = true;
+ baseState.depthCompare = wgpu::CompareFunction::Always;
+ baseState.stencilBack = stencilFace;
+ baseState.stencilFront = stencilFace;
+ baseState.stencilReadMask = 0xff;
+ baseState.stencilWriteMask = 0xff;
- wgpu::DepthStencilStateDescriptor state;
- state.depthWriteEnabled = true;
- state.depthCompare = compareFunction;
- state.stencilBack = stencilFace;
- state.stencilFront = stencilFace;
- state.stencilReadMask = 0xff;
- state.stencilWriteMask = 0xff;
+ wgpu::DepthStencilStateDescriptor state;
+ state.depthWriteEnabled = true;
+ state.depthCompare = compareFunction;
+ state.stencilBack = stencilFace;
+ state.stencilFront = stencilFace;
+ state.stencilReadMask = 0xff;
+ state.stencilWriteMask = 0xff;
- RGBA8 baseColor = RGBA8(255, 255, 255, 255);
- RGBA8 lessColor = RGBA8(255, 0, 0, 255);
- RGBA8 equalColor = RGBA8(0, 255, 0, 255);
- RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
+ RGBA8 baseColor = RGBA8(255, 255, 255, 255);
+ RGBA8 lessColor = RGBA8(255, 0, 0, 255);
+ RGBA8 equalColor = RGBA8(0, 255, 0, 255);
+ RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
- // Base triangle at depth 0.5, depth always, depth write enabled
- TestSpec base = { baseState, baseColor, 0.5f, 0u };
+ // Base triangle at depth 0.5, depth always, depth write enabled
+ TestSpec base = {baseState, baseColor, 0.5f, 0u};
- // Draw the base triangle, then a triangle in stencilFront of the base triangle with the
- // given depth comparison function
- DoTest({ base, { state, lessColor, 0.f, 0u } }, less ? lessColor : baseColor);
+ // Draw the base triangle, then a triangle in stencilFront of the base triangle with the
+ // given depth comparison function
+ DoTest({base, {state, lessColor, 0.f, 0u}}, less ? lessColor : baseColor);
- // Draw the base triangle, then a triangle in at the same depth as the base triangle with the given depth comparison function
- DoTest({ base, { state, equalColor, 0.5f, 0u } }, equal ? equalColor : baseColor);
+ // Draw the base triangle, then a triangle in at the same depth as the base triangle with
+ // the given depth comparison function
+ DoTest({base, {state, equalColor, 0.5f, 0u}}, equal ? equalColor : baseColor);
- // Draw the base triangle, then a triangle behind the base triangle with the given depth comparison function
- DoTest({ base, { state, greaterColor, 1.0f, 0u } }, greater ? greaterColor : baseColor);
- }
+ // Draw the base triangle, then a triangle behind the base triangle with the given depth
+ // comparison function
+ DoTest({base, {state, greaterColor, 1.0f, 0u}}, greater ? greaterColor : baseColor);
+ }
- // Check whether a stencil comparison function works as expected
- // The less, equal, greater booleans denote wether the respective triangle should be visible based on the comparison function
- void CheckStencilCompareFunction(wgpu::CompareFunction compareFunction,
- bool less,
- bool equal,
- bool greater) {
- wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
- baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
- baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
- baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
- baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
- wgpu::DepthStencilStateDescriptor baseState;
- baseState.depthWriteEnabled = false;
- baseState.depthCompare = wgpu::CompareFunction::Always;
- baseState.stencilBack = baseStencilFaceDescriptor;
- baseState.stencilFront = baseStencilFaceDescriptor;
- baseState.stencilReadMask = 0xff;
- baseState.stencilWriteMask = 0xff;
+ // Check whether a stencil comparison function works as expected
+ // The less, equal, greater booleans denote wether the respective triangle should be visible
+ // based on the comparison function
+ void CheckStencilCompareFunction(wgpu::CompareFunction compareFunction,
+ bool less,
+ bool equal,
+ bool greater) {
+ wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
+ baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
+ baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
+ baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
+ baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
+ wgpu::DepthStencilStateDescriptor baseState;
+ baseState.depthWriteEnabled = false;
+ baseState.depthCompare = wgpu::CompareFunction::Always;
+ baseState.stencilBack = baseStencilFaceDescriptor;
+ baseState.stencilFront = baseStencilFaceDescriptor;
+ baseState.stencilReadMask = 0xff;
+ baseState.stencilWriteMask = 0xff;
- wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
- stencilFaceDescriptor.compare = compareFunction;
- stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
- wgpu::DepthStencilStateDescriptor state;
- state.depthWriteEnabled = false;
- state.depthCompare = wgpu::CompareFunction::Always;
- state.stencilBack = stencilFaceDescriptor;
- state.stencilFront = stencilFaceDescriptor;
- state.stencilReadMask = 0xff;
- state.stencilWriteMask = 0xff;
+ wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
+ stencilFaceDescriptor.compare = compareFunction;
+ stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
+ wgpu::DepthStencilStateDescriptor state;
+ state.depthWriteEnabled = false;
+ state.depthCompare = wgpu::CompareFunction::Always;
+ state.stencilBack = stencilFaceDescriptor;
+ state.stencilFront = stencilFaceDescriptor;
+ state.stencilReadMask = 0xff;
+ state.stencilWriteMask = 0xff;
- RGBA8 baseColor = RGBA8(255, 255, 255, 255);
- RGBA8 lessColor = RGBA8(255, 0, 0, 255);
- RGBA8 equalColor = RGBA8(0, 255, 0, 255);
- RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
+ RGBA8 baseColor = RGBA8(255, 255, 255, 255);
+ RGBA8 lessColor = RGBA8(255, 0, 0, 255);
+ RGBA8 equalColor = RGBA8(0, 255, 0, 255);
+ RGBA8 greaterColor = RGBA8(0, 0, 255, 255);
- // Base triangle with stencil reference 1
- TestSpec base = { baseState, baseColor, 0.0f, 1u };
+ // Base triangle with stencil reference 1
+ TestSpec base = {baseState, baseColor, 0.0f, 1u};
- // Draw the base triangle, then a triangle with stencil reference 0 with the given stencil comparison function
- DoTest({ base, { state, lessColor, 0.f, 0u } }, less ? lessColor : baseColor);
+ // Draw the base triangle, then a triangle with stencil reference 0 with the given stencil
+ // comparison function
+ DoTest({base, {state, lessColor, 0.f, 0u}}, less ? lessColor : baseColor);
- // Draw the base triangle, then a triangle with stencil reference 1 with the given stencil comparison function
- DoTest({ base, { state, equalColor, 0.f, 1u } }, equal ? equalColor : baseColor);
+ // Draw the base triangle, then a triangle with stencil reference 1 with the given stencil
+ // comparison function
+ DoTest({base, {state, equalColor, 0.f, 1u}}, equal ? equalColor : baseColor);
- // Draw the base triangle, then a triangle with stencil reference 2 with the given stencil comparison function
- DoTest({ base, { state, greaterColor, 0.f, 2u } }, greater ? greaterColor : baseColor);
- }
+ // Draw the base triangle, then a triangle with stencil reference 2 with the given stencil
+ // comparison function
+ DoTest({base, {state, greaterColor, 0.f, 2u}}, greater ? greaterColor : baseColor);
+ }
- // Given the provided `initialStencil` and `reference`, check that applying the `stencilOperation` produces the `expectedStencil`
- void CheckStencilOperation(wgpu::StencilOperation stencilOperation,
- uint32_t initialStencil,
- uint32_t reference,
- uint32_t expectedStencil) {
- wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
- baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
- baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
- baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
- baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
- wgpu::DepthStencilStateDescriptor baseState;
- baseState.depthWriteEnabled = false;
- baseState.depthCompare = wgpu::CompareFunction::Always;
- baseState.stencilBack = baseStencilFaceDescriptor;
- baseState.stencilFront = baseStencilFaceDescriptor;
- baseState.stencilReadMask = 0xff;
- baseState.stencilWriteMask = 0xff;
+ // Given the provided `initialStencil` and `reference`, check that applying the
+ // `stencilOperation` produces the `expectedStencil`
+ void CheckStencilOperation(wgpu::StencilOperation stencilOperation,
+ uint32_t initialStencil,
+ uint32_t reference,
+ uint32_t expectedStencil) {
+ wgpu::StencilStateFaceDescriptor baseStencilFaceDescriptor;
+ baseStencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
+ baseStencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
+ baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
+ baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace;
+ wgpu::DepthStencilStateDescriptor baseState;
+ baseState.depthWriteEnabled = false;
+ baseState.depthCompare = wgpu::CompareFunction::Always;
+ baseState.stencilBack = baseStencilFaceDescriptor;
+ baseState.stencilFront = baseStencilFaceDescriptor;
+ baseState.stencilReadMask = 0xff;
+ baseState.stencilWriteMask = 0xff;
- wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
- stencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
- stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.passOp = stencilOperation;
- wgpu::DepthStencilStateDescriptor state;
- state.depthWriteEnabled = false;
- state.depthCompare = wgpu::CompareFunction::Always;
- state.stencilBack = stencilFaceDescriptor;
- state.stencilFront = stencilFaceDescriptor;
- state.stencilReadMask = 0xff;
- state.stencilWriteMask = 0xff;
+ wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
+ stencilFaceDescriptor.compare = wgpu::CompareFunction::Always;
+ stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.passOp = stencilOperation;
+ wgpu::DepthStencilStateDescriptor state;
+ state.depthWriteEnabled = false;
+ state.depthCompare = wgpu::CompareFunction::Always;
+ state.stencilBack = stencilFaceDescriptor;
+ state.stencilFront = stencilFaceDescriptor;
+ state.stencilReadMask = 0xff;
+ state.stencilWriteMask = 0xff;
- CheckStencil({
+ CheckStencil(
+ {
// Wipe the stencil buffer with the initialStencil value
- { baseState, RGBA8(255, 255, 255, 255), 0.f, initialStencil },
+ {baseState, RGBA8(255, 255, 255, 255), 0.f, initialStencil},
// Draw a triangle with the provided stencil operation and reference
- { state, RGBA8(255, 0, 0, 255), 0.f, reference },
- }, expectedStencil);
- }
+ {state, RGBA8(255, 0, 0, 255), 0.f, reference},
+ },
+ expectedStencil);
+ }
- // Draw a list of test specs, and check if the stencil value is equal to the expected value
- void CheckStencil(std::vector<TestSpec> testParams, uint32_t expectedStencil) {
- wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
- stencilFaceDescriptor.compare = wgpu::CompareFunction::Equal;
- stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
- stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
- wgpu::DepthStencilStateDescriptor state;
- state.depthWriteEnabled = false;
- state.depthCompare = wgpu::CompareFunction::Always;
- state.stencilBack = stencilFaceDescriptor;
- state.stencilFront = stencilFaceDescriptor;
- state.stencilReadMask = 0xff;
- state.stencilWriteMask = 0xff;
+ // Draw a list of test specs, and check if the stencil value is equal to the expected value
+ void CheckStencil(std::vector<TestSpec> testParams, uint32_t expectedStencil) {
+ wgpu::StencilStateFaceDescriptor stencilFaceDescriptor;
+ stencilFaceDescriptor.compare = wgpu::CompareFunction::Equal;
+ stencilFaceDescriptor.failOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep;
+ stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep;
+ wgpu::DepthStencilStateDescriptor state;
+ state.depthWriteEnabled = false;
+ state.depthCompare = wgpu::CompareFunction::Always;
+ state.stencilBack = stencilFaceDescriptor;
+ state.stencilFront = stencilFaceDescriptor;
+ state.stencilReadMask = 0xff;
+ state.stencilWriteMask = 0xff;
- testParams.push_back({ state, RGBA8(0, 255, 0, 255), 0, expectedStencil });
- DoTest(testParams, RGBA8(0, 255, 0, 255));
- }
+ testParams.push_back({state, RGBA8(0, 255, 0, 255), 0, expectedStencil});
+ DoTest(testParams, RGBA8(0, 255, 0, 255));
+ }
- // Each test param represents a pair of triangles with a color, depth, stencil value, and depthStencil state, one frontfacing, one backfacing
- // Draw the triangles in order and check the expected colors for the frontfaces and backfaces
- void DoTest(const std::vector<TestSpec> &testParams, const RGBA8& expectedFront, const RGBA8& expectedBack) {
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ // Each test param represents a pair of triangles with a color, depth, stencil value, and
+ // depthStencil state, one frontfacing, one backfacing Draw the triangles in order and check the
+ // expected colors for the frontfaces and backfaces
+ void DoTest(const std::vector<TestSpec>& testParams,
+ const RGBA8& expectedFront,
+ const RGBA8& expectedBack) {
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- struct TriangleData {
- float color[3];
- float depth;
+ struct TriangleData {
+ float color[3];
+ float depth;
+ };
+
+ utils::ComboRenderPassDescriptor renderPass({renderTargetView}, depthTextureView);
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
+
+ for (size_t i = 0; i < testParams.size(); ++i) {
+ const TestSpec& test = testParams[i];
+
+ TriangleData data = {
+ {static_cast<float>(test.color.r) / 255.f, static_cast<float>(test.color.g) / 255.f,
+ static_cast<float>(test.color.b) / 255.f},
+ test.depth,
};
+ // Upload a buffer for each triangle's depth and color data
+ wgpu::Buffer buffer = utils::CreateBufferFromData(device, &data, sizeof(TriangleData),
+ wgpu::BufferUsage::Uniform);
- utils::ComboRenderPassDescriptor renderPass({renderTargetView}, depthTextureView);
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
+ // Create a pipeline for the triangles with the test spec's depth stencil state
- for (size_t i = 0; i < testParams.size(); ++i) {
- const TestSpec& test = testParams[i];
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
+ descriptor.cDepthStencilState = test.depthStencilState;
+ descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
+ descriptor.depthStencilState = &descriptor.cDepthStencilState;
- TriangleData data = {
- { static_cast<float>(test.color.r) / 255.f, static_cast<float>(test.color.g) / 255.f, static_cast<float>(test.color.b) / 255.f },
- test.depth,
- };
- // Upload a buffer for each triangle's depth and color data
- wgpu::Buffer buffer = utils::CreateBufferFromData(
- device, &data, sizeof(TriangleData), wgpu::BufferUsage::Uniform);
+ wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
- // Create a pipeline for the triangles with the test spec's depth stencil state
+ // Create a bind group for the data
+ wgpu::BindGroup bindGroup = utils::MakeBindGroup(
+ device, pipeline.GetBindGroupLayout(0), {{0, buffer, 0, sizeof(TriangleData)}});
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
- descriptor.cDepthStencilState = test.depthStencilState;
- descriptor.cDepthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8;
- descriptor.depthStencilState = &descriptor.cDepthStencilState;
-
- wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
-
- // Create a bind group for the data
- wgpu::BindGroup bindGroup = utils::MakeBindGroup(
- device, pipeline.GetBindGroupLayout(0), {{0, buffer, 0, sizeof(TriangleData)}});
-
- pass.SetPipeline(pipeline);
- pass.SetStencilReference(test.stencil); // Set the stencil reference
- pass.SetBindGroup(
- 0, bindGroup); // Set the bind group which contains color and depth data
- pass.Draw(6);
- }
- pass.EndPass();
-
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
-
- EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2) << "Front face check failed";
- EXPECT_PIXEL_RGBA8_EQ(expectedBack, renderTarget, 3 * kRTSize / 4, kRTSize / 2) << "Back face check failed";
+ pass.SetPipeline(pipeline);
+ pass.SetStencilReference(test.stencil); // Set the stencil reference
+ pass.SetBindGroup(0,
+ bindGroup); // Set the bind group which contains color and depth data
+ pass.Draw(6);
}
+ pass.EndPass();
- void DoTest(const std::vector<TestSpec> &testParams, const RGBA8& expected) {
- DoTest(testParams, expected, expected);
- }
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
- wgpu::Texture renderTarget;
- wgpu::Texture depthTexture;
- wgpu::TextureView renderTargetView;
- wgpu::TextureView depthTextureView;
- wgpu::ShaderModule vsModule;
- wgpu::ShaderModule fsModule;
+ EXPECT_PIXEL_RGBA8_EQ(expectedFront, renderTarget, kRTSize / 4, kRTSize / 2)
+ << "Front face check failed";
+ EXPECT_PIXEL_RGBA8_EQ(expectedBack, renderTarget, 3 * kRTSize / 4, kRTSize / 2)
+ << "Back face check failed";
+ }
+
+ void DoTest(const std::vector<TestSpec>& testParams, const RGBA8& expected) {
+ DoTest(testParams, expected, expected);
+ }
+
+ wgpu::Texture renderTarget;
+ wgpu::Texture depthTexture;
+ wgpu::TextureView renderTargetView;
+ wgpu::TextureView depthTextureView;
+ wgpu::ShaderModule vsModule;
+ wgpu::ShaderModule fsModule;
};
// Test compilation and usage of the fixture
@@ -325,9 +341,11 @@
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
- DoTest({
- { state, RGBA8(0, 255, 0, 255), 0.5f, 0u },
- }, RGBA8(0, 255, 0, 255));
+ DoTest(
+ {
+ {state, RGBA8(0, 255, 0, 255), 0.5f, 0u},
+ },
+ RGBA8(0, 255, 0, 255));
}
// Test defaults: depth and stencil tests disabled
@@ -347,9 +365,9 @@
state.stencilWriteMask = 0xff;
TestSpec specs[3] = {
- { state, RGBA8(255, 0, 0, 255), 0.0f, 0u },
- { state, RGBA8(0, 255, 0, 255), 0.5f, 0u },
- { state, RGBA8(0, 0, 255, 255), 1.0f, 0u },
+ {state, RGBA8(255, 0, 0, 255), 0.0f, 0u},
+ {state, RGBA8(0, 255, 0, 255), 0.5f, 0u},
+ {state, RGBA8(0, 0, 255, 255), 1.0f, 0u},
};
// Test that for all combinations, the last triangle drawn is the one visible
@@ -357,8 +375,8 @@
for (uint32_t last = 0; last < 3; ++last) {
uint32_t i = (last + 1) % 3;
uint32_t j = (last + 2) % 3;
- DoTest({ specs[i], specs[j], specs[last] }, specs[last].color);
- DoTest({ specs[j], specs[i], specs[last] }, specs[last].color);
+ DoTest({specs[i], specs[j], specs[last]}, specs[last].color);
+ DoTest({specs[j], specs[i], specs[last]}, specs[last].color);
}
}
@@ -427,11 +445,17 @@
checkState.stencilReadMask = 0xff;
checkState.stencilWriteMask = 0xff;
- DoTest({
- { baseState, RGBA8(255, 255, 255, 255), 1.f, 0u }, // Draw a base triangle with depth enabled
- { noDepthWrite, RGBA8(0, 0, 0, 255), 0.f, 0u }, // Draw a second triangle without depth enabled
- { checkState, RGBA8(0, 255, 0, 255), 1.f, 0u }, // Draw a third triangle which should occlude the second even though it is behind it
- }, RGBA8(0, 255, 0, 255));
+ DoTest(
+ {
+ {baseState, RGBA8(255, 255, 255, 255), 1.f,
+ 0u}, // Draw a base triangle with depth enabled
+ {noDepthWrite, RGBA8(0, 0, 0, 255), 0.f,
+ 0u}, // Draw a second triangle without depth enabled
+ {checkState, RGBA8(0, 255, 0, 255), 1.f,
+ 0u}, // Draw a third triangle which should occlude the second even though it is behind
+ // it
+ },
+ RGBA8(0, 255, 0, 255));
}
// The following tests check that each stencil comparison function works
@@ -536,9 +560,11 @@
RGBA8 red = RGBA8(255, 0, 0, 255);
RGBA8 green = RGBA8(0, 255, 0, 255);
- TestSpec base = { baseState, baseColor, 0.5f, 3u }; // Base triangle to set the stencil to 3
- DoTest({ base, { state, red, 0.f, 1u } }, baseColor); // Triangle with stencil reference 1 and read mask 2 does not draw because (3 & 2 != 1)
- DoTest({ base, { state, green, 0.f, 2u } }, green); // Triangle with stencil reference 2 and read mask 2 draws because (3 & 2 == 2)
+ TestSpec base = {baseState, baseColor, 0.5f, 3u}; // Base triangle to set the stencil to 3
+ DoTest({base, {state, red, 0.f, 1u}}, baseColor); // Triangle with stencil reference 1 and read
+ // mask 2 does not draw because (3 & 2 != 1)
+ DoTest({base, {state, green, 0.f, 2u}},
+ green); // Triangle with stencil reference 2 and read mask 2 draws because (3 & 2 == 2)
}
// Check that setting a stencil write mask works
@@ -572,9 +598,12 @@
RGBA8 baseColor = RGBA8(255, 255, 255, 255);
RGBA8 green = RGBA8(0, 255, 0, 255);
- TestSpec base = { baseState, baseColor, 0.5f, 3u }; // Base triangle with stencil reference 3 and mask 1 to set the stencil 1
- DoTest({ base, { state, green, 0.f, 2u } }, baseColor); // Triangle with stencil reference 2 does not draw because 2 != (3 & 1)
- DoTest({ base, { state, green, 0.f, 1u } }, green); // Triangle with stencil reference 1 draws because 1 == (3 & 1)
+ TestSpec base = {baseState, baseColor, 0.5f,
+ 3u}; // Base triangle with stencil reference 3 and mask 1 to set the stencil 1
+ DoTest({base, {state, green, 0.f, 2u}},
+ baseColor); // Triangle with stencil reference 2 does not draw because 2 != (3 & 1)
+ DoTest({base, {state, green, 0.f, 1u}},
+ green); // Triangle with stencil reference 1 draws because 1 == (3 & 1)
}
// Test that the stencil operation is executed on stencil fail
@@ -605,10 +634,13 @@
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
- CheckStencil({
- { baseState, RGBA8(255, 255, 255, 255), 1.f, 1 }, // Triangle to set stencil value to 1
- { state, RGBA8(0, 0, 0, 255), 0.f, 2 } // Triangle with stencil reference 2 fails the Less comparison function
- }, 2); // Replace the stencil on failure, so it should be 2
+ CheckStencil(
+ {
+ {baseState, RGBA8(255, 255, 255, 255), 1.f, 1}, // Triangle to set stencil value to 1
+ {state, RGBA8(0, 0, 0, 255), 0.f,
+ 2} // Triangle with stencil reference 2 fails the Less comparison function
+ },
+ 2); // Replace the stencil on failure, so it should be 2
}
// Test that the stencil operation is executed on stencil pass, depth fail
@@ -639,10 +671,12 @@
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
- CheckStencil({
- { baseState, RGBA8(255, 255, 255, 255), 0.f, 1 }, // Triangle to set stencil value to 1. Depth is 0
- { state, RGBA8(0, 0, 0, 255), 1.f, 2 } }, // Triangle with stencil reference 2 passes the Greater comparison function. At depth 1, it fails the Less depth test
- 2); // Replace the stencil on stencil pass, depth failure, so it should be 2
+ CheckStencil({{baseState, RGBA8(255, 255, 255, 255), 0.f,
+ 1}, // Triangle to set stencil value to 1. Depth is 0
+ {state, RGBA8(0, 0, 0, 255), 1.f,
+ 2}}, // Triangle with stencil reference 2 passes the Greater comparison
+ // function. At depth 1, it fails the Less depth test
+ 2); // Replace the stencil on stencil pass, depth failure, so it should be 2
}
// Test that the stencil operation is executed on stencil pass, depth pass
@@ -673,10 +707,12 @@
state.stencilReadMask = 0xff;
state.stencilWriteMask = 0xff;
- CheckStencil({
- { baseState, RGBA8(255, 255, 255, 255), 1.f, 1 }, // Triangle to set stencil value to 1. Depth is 0
- { state, RGBA8(0, 0, 0, 255), 0.f, 2 } }, // Triangle with stencil reference 2 passes the Greater comparison function. At depth 0, it pass the Less depth test
-2); // Replace the stencil on stencil pass, depth pass, so it should be 2
+ CheckStencil({{baseState, RGBA8(255, 255, 255, 255), 1.f,
+ 1}, // Triangle to set stencil value to 1. Depth is 0
+ {state, RGBA8(0, 0, 0, 255), 0.f,
+ 2}}, // Triangle with stencil reference 2 passes the Greater comparison
+ // function. At depth 0, it pass the Less depth test
+ 2); // Replace the stencil on stencil pass, depth pass, so it should be 2
}
// Test that creating a render pipeline works with for all depth and combined formats
diff --git a/src/tests/end2end/DestroyTests.cpp b/src/tests/end2end/DestroyTests.cpp
index 82c43a6..4122001 100644
--- a/src/tests/end2end/DestroyTests.cpp
+++ b/src/tests/end2end/DestroyTests.cpp
@@ -157,4 +157,8 @@
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
}
-DAWN_INSTANTIATE_TEST(DestroyTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(DestroyTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/DrawIndexedTests.cpp b/src/tests/end2end/DrawIndexedTests.cpp
index 48abdad..f980af3 100644
--- a/src/tests/end2end/DrawIndexedTests.cpp
+++ b/src/tests/end2end/DrawIndexedTests.cpp
@@ -20,90 +20,89 @@
constexpr uint32_t kRTSize = 4;
class DrawIndexedTest : public DawnTest {
- protected:
- void SetUp() override {
- DawnTest::SetUp();
+ protected:
+ void SetUp() override {
+ DawnTest::SetUp();
- renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
+ renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
- wgpu::ShaderModule vsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ wgpu::ShaderModule vsModule =
+ utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
void main() {
gl_Position = pos;
})");
- wgpu::ShaderModule fsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ wgpu::ShaderModule fsModule =
+ utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
- descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexState.vertexBufferCount = 1;
- descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
- descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
- descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
- descriptor.cColorStates[0].format = renderPass.colorFormat;
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
+ descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cColorStates[0].format = renderPass.colorFormat;
- pipeline = device.CreateRenderPipeline(&descriptor);
+ pipeline = device.CreateRenderPipeline(&descriptor);
- vertexBuffer = utils::CreateBufferFromData<float>(
- device, wgpu::BufferUsage::Vertex,
- {// First quad: the first 3 vertices represent the bottom left triangle
- -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f,
- 1.0f, 0.0f, 1.0f,
+ vertexBuffer = utils::CreateBufferFromData<float>(
+ device, wgpu::BufferUsage::Vertex,
+ {// First quad: the first 3 vertices represent the bottom left triangle
+ -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
+ 0.0f, 1.0f,
- // Second quad: the first 3 vertices represent the top right triangle
- -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f,
- -1.0f, 0.0f, 1.0f});
- indexBuffer = utils::CreateBufferFromData<uint32_t>(
- device, wgpu::BufferUsage::Index,
- {0, 1, 2, 0, 3, 1,
- // The indices below are added to test negatve baseVertex
- 0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
+ // Second quad: the first 3 vertices represent the top right triangle
+ -1.0f, 1.0f, 0.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, -1.0f,
+ 0.0f, 1.0f});
+ indexBuffer = utils::CreateBufferFromData<uint32_t>(
+ device, wgpu::BufferUsage::Index,
+ {0, 1, 2, 0, 3, 1,
+ // The indices below are added to test negatve baseVertex
+ 0 + 4, 1 + 4, 2 + 4, 0 + 4, 3 + 4, 1 + 4});
+ }
+
+ utils::BasicRenderPass renderPass;
+ wgpu::RenderPipeline pipeline;
+ wgpu::Buffer vertexBuffer;
+ wgpu::Buffer indexBuffer;
+
+ void Test(uint32_t indexCount,
+ uint32_t instanceCount,
+ uint32_t firstIndex,
+ int32_t baseVertex,
+ uint32_t firstInstance,
+ uint64_t bufferOffset,
+ RGBA8 bottomLeftExpected,
+ RGBA8 topRightExpected) {
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ {
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
+ pass.SetPipeline(pipeline);
+ pass.SetVertexBuffer(0, vertexBuffer);
+ pass.SetIndexBuffer(indexBuffer, bufferOffset);
+ pass.DrawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance);
+ pass.EndPass();
}
- utils::BasicRenderPass renderPass;
- wgpu::RenderPipeline pipeline;
- wgpu::Buffer vertexBuffer;
- wgpu::Buffer indexBuffer;
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
- void Test(uint32_t indexCount,
- uint32_t instanceCount,
- uint32_t firstIndex,
- int32_t baseVertex,
- uint32_t firstInstance,
- uint64_t bufferOffset,
- RGBA8 bottomLeftExpected,
- RGBA8 topRightExpected) {
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- {
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
- pass.SetPipeline(pipeline);
- pass.SetVertexBuffer(0, vertexBuffer);
- pass.SetIndexBuffer(indexBuffer, bufferOffset);
- pass.DrawIndexed(indexCount, instanceCount, firstIndex, baseVertex, firstInstance);
- pass.EndPass();
- }
-
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
-
- EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);
- EXPECT_PIXEL_RGBA8_EQ(topRightExpected, renderPass.color, 3, 1);
- }
+ EXPECT_PIXEL_RGBA8_EQ(bottomLeftExpected, renderPass.color, 1, 3);
+ EXPECT_PIXEL_RGBA8_EQ(topRightExpected, renderPass.color, 3, 1);
+ }
};
// The most basic DrawIndexed triangle draw.
TEST_P(DrawIndexedTest, Uint32) {
-
RGBA8 filled(0, 255, 0, 255);
RGBA8 notFilled(0, 0, 0, 0);
@@ -134,4 +133,8 @@
Test(3, 1, 3, -4, 0, 6 * sizeof(uint32_t), notFilled, filled);
}
-DAWN_INSTANTIATE_TEST(DrawIndexedTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(DrawIndexedTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/DrawIndirectTests.cpp b/src/tests/end2end/DrawIndirectTests.cpp
index 3f14375..56b55ec 100644
--- a/src/tests/end2end/DrawIndirectTests.cpp
+++ b/src/tests/end2end/DrawIndirectTests.cpp
@@ -124,4 +124,8 @@
Test({3, 1, 0, 0, 3, 1, 3, 0}, 4 * sizeof(uint32_t), notFilled, filled);
}
-DAWN_INSTANTIATE_TEST(DrawIndirectTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(DrawIndirectTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/GpuMemorySynchronizationTests.cpp b/src/tests/end2end/GpuMemorySynchronizationTests.cpp
index 3b4dcd1..4cf64d0 100644
--- a/src/tests/end2end/GpuMemorySynchronizationTests.cpp
+++ b/src/tests/end2end/GpuMemorySynchronizationTests.cpp
@@ -231,7 +231,11 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8(2, 0, 0, 255), renderPass.color, 0, 0);
}
-DAWN_INSTANTIATE_TEST(GpuMemorySyncTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(GpuMemorySyncTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
class StorageToUniformSyncTests : public DawnTest {
protected:
diff --git a/src/tests/end2end/IOSurfaceWrappingTests.cpp b/src/tests/end2end/IOSurfaceWrappingTests.cpp
index af40c1b..9e44cb7 100644
--- a/src/tests/end2end/IOSurfaceWrappingTests.cpp
+++ b/src/tests/end2end/IOSurfaceWrappingTests.cpp
@@ -369,7 +369,8 @@
// Test sampling from a R8 IOSurface
TEST_P(IOSurfaceUsageTests, SampleFromR8IOSurface) {
DAWN_SKIP_TEST_IF(UsesWire());
- ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_OneComponent8, 1);
+ ScopedIOSurfaceRef ioSurface =
+ CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_OneComponent8, 1);
uint8_t data = 0x01;
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::R8Unorm, &data, sizeof(data),
@@ -379,7 +380,8 @@
// Test clearing a R8 IOSurface
TEST_P(IOSurfaceUsageTests, ClearR8IOSurface) {
DAWN_SKIP_TEST_IF(UsesWire());
- ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_OneComponent8, 1);
+ ScopedIOSurfaceRef ioSurface =
+ CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_OneComponent8, 1);
uint8_t data = 0x01;
DoClearTest(ioSurface.get(), wgpu::TextureFormat::R8Unorm, &data, sizeof(data));
@@ -388,7 +390,8 @@
// Test sampling from a RG8 IOSurface
TEST_P(IOSurfaceUsageTests, SampleFromRG8IOSurface) {
DAWN_SKIP_TEST_IF(UsesWire());
- ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_TwoComponent8, 2);
+ ScopedIOSurfaceRef ioSurface =
+ CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_TwoComponent8, 2);
uint16_t data = 0x0102; // Stored as (G, R)
DoSampleTest(ioSurface.get(), wgpu::TextureFormat::RG8Unorm, &data, sizeof(data),
@@ -398,7 +401,8 @@
// Test clearing a RG8 IOSurface
TEST_P(IOSurfaceUsageTests, ClearRG8IOSurface) {
DAWN_SKIP_TEST_IF(UsesWire());
- ScopedIOSurfaceRef ioSurface = CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_TwoComponent8, 2);
+ ScopedIOSurfaceRef ioSurface =
+ CreateSinglePlaneIOSurface(1, 1, kCVPixelFormatType_TwoComponent8, 2);
uint16_t data = 0x0201;
DoClearTest(ioSurface.get(), wgpu::TextureFormat::RG8Unorm, &data, sizeof(data));
diff --git a/src/tests/end2end/IndexFormatTests.cpp b/src/tests/end2end/IndexFormatTests.cpp
index ea83e91..554c674 100644
--- a/src/tests/end2end/IndexFormatTests.cpp
+++ b/src/tests/end2end/IndexFormatTests.cpp
@@ -21,45 +21,45 @@
constexpr uint32_t kRTSize = 400;
class IndexFormatTest : public DawnTest {
- protected:
- void SetUp() override {
- DawnTest::SetUp();
+ protected:
+ void SetUp() override {
+ DawnTest::SetUp();
- renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
- }
+ renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
+ }
- utils::BasicRenderPass renderPass;
+ utils::BasicRenderPass renderPass;
- wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format) {
- wgpu::ShaderModule vsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ wgpu::RenderPipeline MakeTestPipeline(wgpu::IndexFormat format) {
+ wgpu::ShaderModule vsModule =
+ utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
void main() {
gl_Position = pos;
})");
- wgpu::ShaderModule fsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ wgpu::ShaderModule fsModule =
+ utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
- descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
- descriptor.cVertexState.indexFormat = format;
- descriptor.cVertexState.vertexBufferCount = 1;
- descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
- descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
- descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
- descriptor.cColorStates[0].format = renderPass.colorFormat;
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
+ descriptor.primitiveTopology = wgpu::PrimitiveTopology::TriangleStrip;
+ descriptor.cVertexState.indexFormat = format;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cColorStates[0].format = renderPass.colorFormat;
- return device.CreateRenderPipeline(&descriptor);
- }
+ return device.CreateRenderPipeline(&descriptor);
+ }
};
// Test that the Uint32 index format is correctly interpreted
@@ -275,4 +275,8 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8(0, 255, 0, 255), renderPass.color, 100, 300);
}
-DAWN_INSTANTIATE_TEST(IndexFormatTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(IndexFormatTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/MultisampledRenderingTests.cpp b/src/tests/end2end/MultisampledRenderingTests.cpp
index ef03bf2..0605594 100644
--- a/src/tests/end2end/MultisampledRenderingTests.cpp
+++ b/src/tests/end2end/MultisampledRenderingTests.cpp
@@ -61,7 +61,6 @@
const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth;
-
return CreateRenderPipelineForTest(fs, 1, testDepth);
}
@@ -285,8 +284,8 @@
utils::ComboRenderPassDescriptor renderPass =
CreateComboRenderPassDescriptorForTest({mMultisampledColorView}, {mResolveView},
wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, true);
- std::array<float, 5> kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color
- 0.2f}; // depth
+ std::array<float, 5> kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color
+ 0.2f}; // depth
constexpr uint32_t kSize = sizeof(kUniformData);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
@@ -299,8 +298,8 @@
{mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load,
kTestDepth);
- std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color
- 0.5f}; // depth
+ std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color
+ 0.5f}; // depth
constexpr uint32_t kSize = sizeof(kUniformData);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
@@ -369,8 +368,8 @@
{mMultisampledColorView, multisampledColorView2}, {mResolveView, resolveView2},
wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth);
- std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
- kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
+ std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
+ kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
constexpr uint32_t kSize = sizeof(kUniformData);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
@@ -503,8 +502,8 @@
{mMultisampledColorView, multisampledColorView2}, {resolveView1, resolveView2},
wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth);
- std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
- kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
+ std::array<float, 8> kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1
+ kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2
constexpr uint32_t kSize = sizeof(kUniformData);
EncodeRenderPassForTest(commandEncoder, renderPass, pipeline, kUniformData.data(), kSize);
}
diff --git a/src/tests/end2end/NonzeroTextureCreationTests.cpp b/src/tests/end2end/NonzeroTextureCreationTests.cpp
index 9ee9e80..97759af 100644
--- a/src/tests/end2end/NonzeroTextureCreationTests.cpp
+++ b/src/tests/end2end/NonzeroTextureCreationTests.cpp
@@ -292,6 +292,6 @@
MetalBackend({"nonzero_clear_resources_on_creation_for_testing"},
{"lazy_clear_resource_on_first_use"}),
OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"},
- {"lazy_clear_resource_on_first_use"}),
+ {"lazy_clear_resource_on_first_use"}),
VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"},
- {"lazy_clear_resource_on_first_use"}));
+ {"lazy_clear_resource_on_first_use"}));
diff --git a/src/tests/end2end/ObjectCachingTests.cpp b/src/tests/end2end/ObjectCachingTests.cpp
index d27a3f5..20705a9 100644
--- a/src/tests/end2end/ObjectCachingTests.cpp
+++ b/src/tests/end2end/ObjectCachingTests.cpp
@@ -400,4 +400,8 @@
EXPECT_EQ(sampler.Get() == sameSampler.Get(), !UsesWire());
}
-DAWN_INSTANTIATE_TEST(ObjectCachingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ObjectCachingTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/OpArrayLengthTests.cpp b/src/tests/end2end/OpArrayLengthTests.cpp
index 3e6a043..2d8e465 100644
--- a/src/tests/end2end/OpArrayLengthTests.cpp
+++ b/src/tests/end2end/OpArrayLengthTests.cpp
@@ -262,4 +262,8 @@
EXPECT_PIXEL_RGBA8_EQ(expectedColor, renderPass.color, 0, 0);
}
-DAWN_INSTANTIATE_TEST(OpArrayLengthTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(OpArrayLengthTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/PipelineLayoutTests.cpp b/src/tests/end2end/PipelineLayoutTests.cpp
index 6e71234..a4a02e9 100644
--- a/src/tests/end2end/PipelineLayoutTests.cpp
+++ b/src/tests/end2end/PipelineLayoutTests.cpp
@@ -62,4 +62,4 @@
D3D12Backend(),
MetalBackend(),
OpenGLBackend(),
- VulkanBackend());
\ No newline at end of file
+ VulkanBackend());
diff --git a/src/tests/end2end/PrimitiveTopologyTests.cpp b/src/tests/end2end/PrimitiveTopologyTests.cpp
index 822bfee..0c0c285 100644
--- a/src/tests/end2end/PrimitiveTopologyTests.cpp
+++ b/src/tests/end2end/PrimitiveTopologyTests.cpp
@@ -18,7 +18,8 @@
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/WGPUHelpers.h"
-// Primitive topology tests work by drawing the following vertices with all the different primitive topology states:
+// Primitive topology tests work by drawing the following vertices with all the different primitive
+// topology states:
// -------------------------------------
// | |
// | 1 2 5 |
@@ -81,8 +82,8 @@
// -------------------------------------
//
// Each of these different states is a superset of some of the previous states,
-// so for every state, we check any new added test locations that are not contained in previous states
-// We also check that the test locations of subsequent states are untouched
+// so for every state, we check any new added test locations that are not contained in previous
+// states We also check that the test locations of subsequent states are untouched
constexpr static unsigned int kRTSize = 32;
@@ -91,11 +92,13 @@
};
constexpr TestLocation GetMidpoint(const TestLocation& a, const TestLocation& b) noexcept {
- return { (a.x + b.x) / 2, (a.y + b.y) / 2 };
+ return {(a.x + b.x) / 2, (a.y + b.y) / 2};
}
-constexpr TestLocation GetCentroid(const TestLocation& a, const TestLocation& b, const TestLocation& c) noexcept {
- return { (a.x + b.x + c.x) / 3, (a.y + b.y + c.y) / 3 };
+constexpr TestLocation GetCentroid(const TestLocation& a,
+ const TestLocation& b,
+ const TestLocation& c) noexcept {
+ return {(a.x + b.x + c.x) / 3, (a.y + b.y + c.y) / 3};
}
// clang-format off
@@ -144,13 +147,13 @@
// clang-format on
class PrimitiveTopologyTest : public DawnTest {
- protected:
- void SetUp() override {
- DawnTest::SetUp();
+ protected:
+ void SetUp() override {
+ DawnTest::SetUp();
- renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
+ renderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
- vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
layout(location = 0) in vec4 pos;
void main() {
@@ -158,69 +161,73 @@
gl_PointSize = 1.0;
})");
- fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
- vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
- wgpu::BufferUsage::Vertex);
+ vertexBuffer = utils::CreateBufferFromData(device, kVertices, sizeof(kVertices),
+ wgpu::BufferUsage::Vertex);
+ }
+
+ struct LocationSpec {
+ const TestLocation* locations;
+ size_t count;
+ bool include;
+ };
+
+ template <std::size_t N>
+ constexpr LocationSpec TestPoints(TestLocation const (&points)[N], bool include) noexcept {
+ return {points, N, include};
+ }
+
+ // Draw the vertices with the given primitive topology and check the pixel values of the test
+ // locations
+ void DoTest(wgpu::PrimitiveTopology primitiveTopology,
+ const std::vector<LocationSpec>& locationSpecs) {
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
+ descriptor.primitiveTopology = primitiveTopology;
+ descriptor.cVertexState.vertexBufferCount = 1;
+ descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
+ descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
+ descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
+ descriptor.cColorStates[0].format = renderPass.colorFormat;
+
+ wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
+
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ {
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
+ pass.SetPipeline(pipeline);
+ pass.SetVertexBuffer(0, vertexBuffer);
+ pass.Draw(6);
+ pass.EndPass();
}
- struct LocationSpec {
- const TestLocation* locations;
- size_t count;
- bool include;
- };
+ wgpu::CommandBuffer commands = encoder.Finish();
+ queue.Submit(1, &commands);
- template <std::size_t N>
- constexpr LocationSpec TestPoints(TestLocation const (&points)[N], bool include) noexcept {
- return { points, N, include };
- }
-
- // Draw the vertices with the given primitive topology and check the pixel values of the test locations
- void DoTest(wgpu::PrimitiveTopology primitiveTopology,
- const std::vector<LocationSpec>& locationSpecs) {
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
- descriptor.primitiveTopology = primitiveTopology;
- descriptor.cVertexState.vertexBufferCount = 1;
- descriptor.cVertexState.cVertexBuffers[0].arrayStride = 4 * sizeof(float);
- descriptor.cVertexState.cVertexBuffers[0].attributeCount = 1;
- descriptor.cVertexState.cAttributes[0].format = wgpu::VertexFormat::Float4;
- descriptor.cColorStates[0].format = renderPass.colorFormat;
-
- wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor);
-
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- {
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass.renderPassInfo);
- pass.SetPipeline(pipeline);
- pass.SetVertexBuffer(0, vertexBuffer);
- pass.Draw(6);
- pass.EndPass();
- }
-
- wgpu::CommandBuffer commands = encoder.Finish();
- queue.Submit(1, &commands);
-
- for (auto& locationSpec : locationSpecs) {
- for (size_t i = 0; i < locationSpec.count; ++i) {
- // If this pixel is included, check that it is green. Otherwise, check that it is black
- RGBA8 color = locationSpec.include ? RGBA8::kGreen : RGBA8::kZero;
- EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color, locationSpec.locations[i].x, locationSpec.locations[i].y)
- << "Expected (" << locationSpec.locations[i].x << ", " << locationSpec.locations[i].y << ") to be " << color;
- }
+ for (auto& locationSpec : locationSpecs) {
+ for (size_t i = 0; i < locationSpec.count; ++i) {
+ // If this pixel is included, check that it is green. Otherwise, check that it is
+ // black
+ RGBA8 color = locationSpec.include ? RGBA8::kGreen : RGBA8::kZero;
+ EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color, locationSpec.locations[i].x,
+ locationSpec.locations[i].y)
+ << "Expected (" << locationSpec.locations[i].x << ", "
+ << locationSpec.locations[i].y << ") to be " << color;
}
}
+ }
- utils::BasicRenderPass renderPass;
- wgpu::ShaderModule vsModule;
- wgpu::ShaderModule fsModule;
- wgpu::Buffer vertexBuffer;
+ utils::BasicRenderPass renderPass;
+ wgpu::ShaderModule vsModule;
+ wgpu::ShaderModule fsModule;
+ wgpu::Buffer vertexBuffer;
};
// Test Point primitive topology
@@ -286,4 +293,8 @@
});
}
-DAWN_INSTANTIATE_TEST(PrimitiveTopologyTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(PrimitiveTopologyTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/RenderBundleTests.cpp b/src/tests/end2end/RenderBundleTests.cpp
index 0df87c3..c58eb8c 100644
--- a/src/tests/end2end/RenderBundleTests.cpp
+++ b/src/tests/end2end/RenderBundleTests.cpp
@@ -196,4 +196,8 @@
EXPECT_PIXEL_RGBA8_EQ(kColors[1], renderPass.color, 3, 1);
}
-DAWN_INSTANTIATE_TEST(RenderBundleTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(RenderBundleTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/RenderPassLoadOpTests.cpp b/src/tests/end2end/RenderPassLoadOpTests.cpp
index db7b6a9..011c6e0 100644
--- a/src/tests/end2end/RenderPassLoadOpTests.cpp
+++ b/src/tests/end2end/RenderPassLoadOpTests.cpp
@@ -22,62 +22,61 @@
constexpr static unsigned int kRTSize = 16;
class DrawQuad {
- public:
- DrawQuad() {}
- DrawQuad(wgpu::Device device, const char* vsSource, const char* fsSource) : device(device) {
- vsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsSource);
- fsModule =
- utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fsSource);
+ public:
+ DrawQuad() {
+ }
+ DrawQuad(wgpu::Device device, const char* vsSource, const char* fsSource) : device(device) {
+ vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, vsSource);
+ fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fsSource);
- pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
- }
+ pipelineLayout = utils::MakeBasicPipelineLayout(device, nullptr);
+ }
- void Draw(wgpu::RenderPassEncoder* pass) {
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.layout = pipelineLayout;
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
+ void Draw(wgpu::RenderPassEncoder* pass) {
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.layout = pipelineLayout;
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
- auto renderPipeline = device.CreateRenderPipeline(&descriptor);
+ auto renderPipeline = device.CreateRenderPipeline(&descriptor);
- pass->SetPipeline(renderPipeline);
- pass->Draw(6, 1, 0, 0);
- }
+ pass->SetPipeline(renderPipeline);
+ pass->Draw(6, 1, 0, 0);
+ }
- private:
- wgpu::Device device;
- wgpu::ShaderModule vsModule = {};
- wgpu::ShaderModule fsModule = {};
- wgpu::PipelineLayout pipelineLayout = {};
+ private:
+ wgpu::Device device;
+ wgpu::ShaderModule vsModule = {};
+ wgpu::ShaderModule fsModule = {};
+ wgpu::PipelineLayout pipelineLayout = {};
};
class RenderPassLoadOpTests : public DawnTest {
- protected:
- void SetUp() override {
- DawnTest::SetUp();
+ protected:
+ void SetUp() override {
+ DawnTest::SetUp();
- wgpu::TextureDescriptor descriptor;
- descriptor.dimension = wgpu::TextureDimension::e2D;
- descriptor.size.width = kRTSize;
- descriptor.size.height = kRTSize;
- descriptor.size.depth = 1;
- descriptor.sampleCount = 1;
- descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- descriptor.mipLevelCount = 1;
- descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
- renderTarget = device.CreateTexture(&descriptor);
+ wgpu::TextureDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.size.width = kRTSize;
+ descriptor.size.height = kRTSize;
+ descriptor.size.depth = 1;
+ descriptor.sampleCount = 1;
+ descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ descriptor.mipLevelCount = 1;
+ descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc;
+ renderTarget = device.CreateTexture(&descriptor);
- renderTargetView = renderTarget.CreateView();
+ renderTargetView = renderTarget.CreateView();
- std::fill(expectZero.begin(), expectZero.end(), RGBA8::kZero);
+ std::fill(expectZero.begin(), expectZero.end(), RGBA8::kZero);
- std::fill(expectGreen.begin(), expectGreen.end(), RGBA8::kGreen);
+ std::fill(expectGreen.begin(), expectGreen.end(), RGBA8::kGreen);
- std::fill(expectBlue.begin(), expectBlue.end(), RGBA8::kBlue);
+ std::fill(expectBlue.begin(), expectBlue.end(), RGBA8::kBlue);
- // draws a blue quad on the right half of the screen
- const char* vsSource = R"(
+ // draws a blue quad on the right half of the screen
+ const char* vsSource = R"(
#version 450
void main() {
const vec2 pos[6] = vec2[6](
@@ -86,24 +85,24 @@
gl_Position = vec4(pos[gl_VertexIndex], 0.f, 1.f);
}
)";
- const char* fsSource = R"(
+ const char* fsSource = R"(
#version 450
layout(location = 0) out vec4 color;
void main() {
color = vec4(0.f, 0.f, 1.f, 1.f);
}
)";
- blueQuad = DrawQuad(device, vsSource, fsSource);
- }
+ blueQuad = DrawQuad(device, vsSource, fsSource);
+ }
- wgpu::Texture renderTarget;
- wgpu::TextureView renderTargetView;
+ wgpu::Texture renderTarget;
+ wgpu::TextureView renderTargetView;
- std::array<RGBA8, kRTSize * kRTSize> expectZero;
- std::array<RGBA8, kRTSize * kRTSize> expectGreen;
- std::array<RGBA8, kRTSize * kRTSize> expectBlue;
+ std::array<RGBA8, kRTSize * kRTSize> expectZero;
+ std::array<RGBA8, kRTSize * kRTSize> expectGreen;
+ std::array<RGBA8, kRTSize * kRTSize> expectBlue;
- DrawQuad blueQuad = {};
+ DrawQuad blueQuad = {};
};
// Tests clearing, loading, and drawing into color attachments
@@ -144,7 +143,12 @@
// Left half should still be green
EXPECT_TEXTURE_RGBA8_EQ(expectGreen.data(), renderTarget, 0, 0, kRTSize / 2, kRTSize, 0, 0);
// Right half should now be blue
- EXPECT_TEXTURE_RGBA8_EQ(expectBlue.data(), renderTarget, kRTSize / 2, 0, kRTSize / 2, kRTSize, 0, 0);
+ EXPECT_TEXTURE_RGBA8_EQ(expectBlue.data(), renderTarget, kRTSize / 2, 0, kRTSize / 2, kRTSize,
+ 0, 0);
}
-DAWN_INSTANTIATE_TEST(RenderPassLoadOpTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(RenderPassLoadOpTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/RenderPassTests.cpp b/src/tests/end2end/RenderPassTests.cpp
index ead9bee..74069ff 100644
--- a/src/tests/end2end/RenderPassTests.cpp
+++ b/src/tests/end2end/RenderPassTests.cpp
@@ -21,7 +21,7 @@
constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::RGBA8Unorm;
class RenderPassTest : public DawnTest {
-protected:
+ protected:
void SetUp() override {
DawnTest::SetUp();
@@ -71,9 +71,9 @@
// Test using two different render passes in one commandBuffer works correctly.
TEST_P(RenderPassTest, TwoRenderPassesInOneCommandBuffer) {
if (IsOpenGL() || IsMetal()) {
- // crbug.com/950768
- // This test is consistently failing on OpenGL and flaky on Metal.
- return;
+ // crbug.com/950768
+ // This test is consistently failing on OpenGL and flaky on Metal.
+ return;
}
wgpu::Texture renderTarget1 = CreateDefault2DTexture();
diff --git a/src/tests/end2end/SamplerTests.cpp b/src/tests/end2end/SamplerTests.cpp
index d40f099..ad5ed92 100644
--- a/src/tests/end2end/SamplerTests.cpp
+++ b/src/tests/end2end/SamplerTests.cpp
@@ -46,10 +46,10 @@
255,
},
};
-}
+} // namespace
class SamplerTest : public DawnTest {
-protected:
+ protected:
void SetUp() override {
DawnTest::SetUp();
mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize);
@@ -177,4 +177,8 @@
}
}
-DAWN_INSTANTIATE_TEST(SamplerTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(SamplerTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/ScissorTests.cpp b/src/tests/end2end/ScissorTests.cpp
index f674303..98722d0 100644
--- a/src/tests/end2end/ScissorTests.cpp
+++ b/src/tests/end2end/ScissorTests.cpp
@@ -17,7 +17,7 @@
#include "utils/ComboRenderPipelineDescriptor.h"
#include "utils/WGPUHelpers.h"
-class ScissorTest: public DawnTest {
+class ScissorTest : public DawnTest {
protected:
wgpu::RenderPipeline CreateQuadPipeline(wgpu::TextureFormat format) {
wgpu::ShaderModule vsModule =
@@ -152,4 +152,8 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 99, 99);
}
-DAWN_INSTANTIATE_TEST(ScissorTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ScissorTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/TextureFormatTests.cpp b/src/tests/end2end/TextureFormatTests.cpp
index 06f70a5..cad7b31 100644
--- a/src/tests/end2end/TextureFormatTests.cpp
+++ b/src/tests/end2end/TextureFormatTests.cpp
@@ -404,7 +404,7 @@
ASSERT(sizeof(float) * formatInfo.componentCount == formatInfo.texelByteSize);
ASSERT(formatInfo.type == wgpu::TextureComponentType::Float);
- std::vector<float> textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f,
+ std::vector<float> textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f,
1.0e29f, NAN, INFINITY, -INFINITY};
DoFloatFormatSamplingTest(formatInfo, textureData, textureData);
@@ -733,4 +733,8 @@
// TODO(cwallez@chromium.org): Add tests for depth-stencil formats when we know if they are copyable
// in WebGPU.
-DAWN_INSTANTIATE_TEST(TextureFormatTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(TextureFormatTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/TextureViewTests.cpp b/src/tests/end2end/TextureViewTests.cpp
index acab158..4697169 100644
--- a/src/tests/end2end/TextureViewTests.cpp
+++ b/src/tests/end2end/TextureViewTests.cpp
@@ -70,7 +70,7 @@
} // anonymous namespace
class TextureViewSamplingTest : public DawnTest {
-protected:
+ protected:
// Generates an arbitrary pixel value per-layer-per-level, used for the "actual" uploaded
// textures and the "expected" results.
static int GenerateTestPixelValue(uint32_t layer, uint32_t level) {
@@ -104,8 +104,8 @@
const uint32_t textureHeightLevel0 = 1 << mipLevelCount;
constexpr wgpu::TextureUsage kUsage =
wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
- mTexture = Create2DTexture(
- device, textureWidthLevel0, textureHeightLevel0, arrayLayerCount, mipLevelCount, kUsage);
+ mTexture = Create2DTexture(device, textureWidthLevel0, textureHeightLevel0, arrayLayerCount,
+ mipLevelCount, kUsage);
mDefaultTextureViewDescriptor.dimension = wgpu::TextureViewDimension::e2DArray;
mDefaultTextureViewDescriptor.format = kDefaultFormat;
@@ -145,10 +145,7 @@
queue.Submit(1, ©);
}
- 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 =
utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, fragmentShader);
@@ -176,8 +173,8 @@
RGBA8 expectedPixel(0, 0, 0, expected);
EXPECT_PIXEL_RGBA8_EQ(expectedPixel, mRenderPass.color, 0, 0);
- EXPECT_PIXEL_RGBA8_EQ(
- expectedPixel, mRenderPass.color, mRenderPass.width - 1, mRenderPass.height - 1);
+ EXPECT_PIXEL_RGBA8_EQ(expectedPixel, mRenderPass.color, mRenderPass.width - 1,
+ mRenderPass.height - 1);
// TODO(jiawei.shao@intel.com): add tests for 3D textures once Dawn supports 3D textures
}
@@ -262,13 +259,13 @@
std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) {
// Reference: https://en.wikipedia.org/wiki/Cube_mapping
const std::array<std::string, 6> kCoordsToCubeMapFace = {{
- " 1.f, tc, -sc", // Positive X
- "-1.f, tc, sc", // Negative X
- " sc, 1.f, -tc", // Positive Y
- " sc, -1.f, tc", // Negative Y
- " sc, tc, 1.f", // Positive Z
- " -sc, tc, -1.f", // Negative Z
- }};
+ " 1.f, tc, -sc", // Positive X
+ "-1.f, tc, sc", // Negative X
+ " sc, 1.f, -tc", // Positive Y
+ " sc, -1.f, tc", // Negative Y
+ " sc, tc, 1.f", // Positive Z
+ " -sc, tc, -1.f", // Negative Z
+ }};
const std::string textureType = isCubeMapArray ? "textureCubeArray" : "textureCube";
const std::string samplerType = isCubeMapArray ? "samplerCubeArray" : "samplerCube";
@@ -279,13 +276,15 @@
stream << R"(
#version 450
layout(set = 0, binding = 0) uniform sampler sampler0;
- layout(set = 0, binding = 1) uniform )" << textureType << R"( texture0;
+ layout(set = 0, binding = 1) uniform )"
+ << textureType << R"( texture0;
layout(location = 0) in vec2 texCoord;
layout(location = 0) out vec4 fragColor;
void main() {
float sc = 2.f * texCoord.x - 1.f;
float tc = 2.f * texCoord.y - 1.f;
- fragColor = texture()" << samplerType << "(texture0, sampler0), ";
+ fragColor = texture()"
+ << samplerType << "(texture0, sampler0), ";
if (isCubeMapArray) {
stream << "vec4(" << coordToCubeMapFace << ", " << cubeMapArrayIndex;
@@ -321,7 +320,7 @@
// Check the data in the every face of the cube map (array) texture view.
for (uint32_t layer = 0; layer < textureViewLayerCount; ++layer) {
- const std::string &fragmentShader =
+ const std::string& fragmentShader =
CreateFragmentShaderForCubeMapFace(layer, isCubeMapArray);
int expected = GenerateTestPixelValue(textureViewBaseLayer + layer, 0);
@@ -362,8 +361,8 @@
}
)";
- const int expected = GenerateTestPixelValue(0, 0) + GenerateTestPixelValue(1, 0) +
- GenerateTestPixelValue(2, 0);
+ const int expected =
+ GenerateTestPixelValue(0, 0) + GenerateTestPixelValue(1, 0) + GenerateTestPixelValue(2, 0);
Verify(textureView, fragmentShader, expected);
}
@@ -427,7 +426,8 @@
TextureCubeMapTest(20, 3, 12, true);
}
-// Test sampling from a cube map texture array view that covers the last layer of a 2D array texture.
+// Test sampling from a cube map texture array view that covers the last layer of a 2D array
+// texture.
TEST_P(TextureViewSamplingTest, TextureCubeMapArrayViewCoveringLastLayer) {
// Test failing on the GPU FYI Mac Pro (AMD), see
// https://bugs.chromium.org/p/dawn/issues/detail?id=58
@@ -519,9 +519,8 @@
bytesPerRow / kBytesPerTexel * (textureWidthLevel0 - 1) + textureHeightLevel0;
constexpr RGBA8 kExpectedPixel(0, 255, 0, 255);
std::vector<RGBA8> expected(expectedDataSize, kExpectedPixel);
- EXPECT_TEXTURE_RGBA8_EQ(
- expected.data(), texture, 0, 0, textureViewWidth, textureViewHeight,
- textureViewBaseLevel, textureViewBaseLayer);
+ EXPECT_TEXTURE_RGBA8_EQ(expected.data(), texture, 0, 0, textureViewWidth, textureViewHeight,
+ textureViewBaseLevel, textureViewBaseLayer);
}
};
@@ -565,7 +564,6 @@
TextureLayerAsColorAttachmentTest(wgpu::TextureViewDimension::e2D, kLayers, kMipLevels,
kBaseLayer, kBaseLevel);
}
-
}
// Test rendering into a 1-layer 2D array texture view created on a mipmap level of a 2D texture.
@@ -610,9 +608,17 @@
}
}
-DAWN_INSTANTIATE_TEST(TextureViewSamplingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(TextureViewSamplingTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
-DAWN_INSTANTIATE_TEST(TextureViewRenderingTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(TextureViewRenderingTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
class TextureViewTest : public DawnTest {};
diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp
index 3333007..dbd2e76 100644
--- a/src/tests/end2end/TextureZeroInitTests.cpp
+++ b/src/tests/end2end/TextureZeroInitTests.cpp
@@ -1144,11 +1144,10 @@
EXPECT_EQ(true, dawn_native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, 1));
}
-DAWN_INSTANTIATE_TEST(
- TextureZeroInitTest,
- D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
- D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
- {"use_d3d12_render_pass"}),
- OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}),
- VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
+DAWN_INSTANTIATE_TEST(TextureZeroInitTest,
+ D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"}),
+ D3D12Backend({"nonzero_clear_resources_on_creation_for_testing"},
+ {"use_d3d12_render_pass"}),
+ OpenGLBackend({"nonzero_clear_resources_on_creation_for_testing"}),
+ MetalBackend({"nonzero_clear_resources_on_creation_for_testing"}),
+ VulkanBackend({"nonzero_clear_resources_on_creation_for_testing"}));
diff --git a/src/tests/end2end/VertexFormatTests.cpp b/src/tests/end2end/VertexFormatTests.cpp
index 6030adc..a4e773a 100644
--- a/src/tests/end2end/VertexFormatTests.cpp
+++ b/src/tests/end2end/VertexFormatTests.cpp
@@ -915,4 +915,8 @@
DoVertexFormatTest(wgpu::VertexFormat::Int4, vertexData, vertexData);
}
-DAWN_INSTANTIATE_TEST(VertexFormatTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(VertexFormatTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/VertexStateTests.cpp b/src/tests/end2end/VertexStateTests.cpp
index e65fefa..1c92f34 100644
--- a/src/tests/end2end/VertexStateTests.cpp
+++ b/src/tests/end2end/VertexStateTests.cpp
@@ -543,7 +543,7 @@
uint16_t halfs[2];
};
static_assert(sizeof(Data) == 16, "");
- Data data {1.f, {2u, 3u}, {Float32ToFloat16(4.f), Float32ToFloat16(5.f)}};
+ Data data{1.f, {2u, 3u}, {Float32ToFloat16(4.f), Float32ToFloat16(5.f)}};
wgpu::Buffer vertexBuffer =
utils::CreateBufferFromData(device, &data, sizeof(data), wgpu::BufferUsage::Vertex);
@@ -599,7 +599,11 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kGreen, renderPass.color, 1, 1);
}
-DAWN_INSTANTIATE_TEST(VertexStateTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(VertexStateTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
// TODO for the input state:
// - Add more vertex formats
diff --git a/src/tests/end2end/ViewportOrientationTests.cpp b/src/tests/end2end/ViewportOrientationTests.cpp
index b592c21..7c2a04a 100644
--- a/src/tests/end2end/ViewportOrientationTests.cpp
+++ b/src/tests/end2end/ViewportOrientationTests.cpp
@@ -64,4 +64,8 @@
EXPECT_PIXEL_RGBA8_EQ(RGBA8::kZero, renderPass.color, 1, 1);
}
-DAWN_INSTANTIATE_TEST(ViewportOrientationTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ViewportOrientationTests,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/end2end/ViewportTests.cpp b/src/tests/end2end/ViewportTests.cpp
index 56dac87..2145ab4 100644
--- a/src/tests/end2end/ViewportTests.cpp
+++ b/src/tests/end2end/ViewportTests.cpp
@@ -404,4 +404,8 @@
DoTest(info);
}
-DAWN_INSTANTIATE_TEST(ViewportTest, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
+DAWN_INSTANTIATE_TEST(ViewportTest,
+ D3D12Backend(),
+ MetalBackend(),
+ OpenGLBackend(),
+ VulkanBackend());
diff --git a/src/tests/unittests/BitSetIteratorTests.cpp b/src/tests/unittests/BitSetIteratorTests.cpp
index 34cfb6c..7bed713 100644
--- a/src/tests/unittests/BitSetIteratorTests.cpp
+++ b/src/tests/unittests/BitSetIteratorTests.cpp
@@ -20,8 +20,8 @@
// This is ANGLE's BitSetIterator_unittests.cpp file.
class BitSetIteratorTest : public testing::Test {
- protected:
- std::bitset<40> mStateBits;
+ protected:
+ std::bitset<40> mStateBits;
};
// Simple iterator test.
diff --git a/src/tests/unittests/BuddyAllocatorTests.cpp b/src/tests/unittests/BuddyAllocatorTests.cpp
index cdb8908..5d46630 100644
--- a/src/tests/unittests/BuddyAllocatorTests.cpp
+++ b/src/tests/unittests/BuddyAllocatorTests.cpp
@@ -324,4 +324,4 @@
ASSERT_EQ(allocator.Allocate(16, alignment), 16ull);
ASSERT_EQ(allocator.ComputeTotalNumOfFreeBlocksForTesting(), 0u);
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/BuddyMemoryAllocatorTests.cpp b/src/tests/unittests/BuddyMemoryAllocatorTests.cpp
index a2d60ea..55da401 100644
--- a/src/tests/unittests/BuddyMemoryAllocatorTests.cpp
+++ b/src/tests/unittests/BuddyMemoryAllocatorTests.cpp
@@ -355,4 +355,4 @@
constexpr uint64_t largeBlock = (1ull << 63) + 1;
ResourceMemoryAllocation invalidAllocation = allocator.Allocate(largeBlock);
ASSERT_EQ(invalidAllocation.GetInfo().mMethod, AllocationMethod::kInvalid);
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/CommandAllocatorTests.cpp b/src/tests/unittests/CommandAllocatorTests.cpp
index 206261f..bc1d736 100644
--- a/src/tests/unittests/CommandAllocatorTests.cpp
+++ b/src/tests/unittests/CommandAllocatorTests.cpp
@@ -121,7 +121,8 @@
uint32_t myValues[5] = {6, 42, 0xFFFFFFFF, 0, 54};
{
- CommandPushConstants* pushConstants = allocator.Allocate<CommandPushConstants>(CommandType::PushConstants);
+ CommandPushConstants* pushConstants =
+ allocator.Allocate<CommandPushConstants>(CommandType::PushConstants);
pushConstants->size = mySize;
pushConstants->offset = myOffset;
@@ -209,7 +210,7 @@
for (int i = 0; i < kCommandCount; i++) {
CommandBig* big = allocator.Allocate<CommandBig>(CommandType::Big);
for (int j = 0; j < kBigBufferSize; j++) {
- big->buffer[j] = count ++;
+ big->buffer[j] = count++;
}
}
@@ -223,9 +224,9 @@
CommandBig* big = iterator.NextCommand<CommandBig>();
for (int i = 0; i < kBigBufferSize; i++) {
ASSERT_EQ(big->buffer[i], count);
- count ++;
+ count++;
}
- numCommands ++;
+ numCommands++;
}
ASSERT_EQ(numCommands, kCommandCount);
@@ -242,7 +243,7 @@
uint16_t count = 0;
for (int i = 0; i < kCommandCount; i++) {
CommandSmall* small = allocator.Allocate<CommandSmall>(CommandType::Small);
- small->data = count ++;
+ small->data = count++;
}
CommandIterator iterator(std::move(allocator));
@@ -254,8 +255,8 @@
CommandSmall* small = iterator.NextCommand<CommandSmall>();
ASSERT_EQ(small->data, count);
- count ++;
- numCommands ++;
+ count++;
+ numCommands++;
}
ASSERT_EQ(numCommands, kCommandCount);
diff --git a/src/tests/unittests/EnumClassBitmasksTests.cpp b/src/tests/unittests/EnumClassBitmasksTests.cpp
index b706e49..c87f09f 100644
--- a/src/tests/unittests/EnumClassBitmasksTests.cpp
+++ b/src/tests/unittests/EnumClassBitmasksTests.cpp
@@ -25,7 +25,7 @@
A = 8,
};
- template<>
+ template <>
struct IsDawnBitmask<Color> {
static constexpr bool enable = true;
};
diff --git a/src/tests/unittests/ErrorTests.cpp b/src/tests/unittests/ErrorTests.cpp
index 514c740..042784d 100644
--- a/src/tests/unittests/ErrorTests.cpp
+++ b/src/tests/unittests/ErrorTests.cpp
@@ -21,278 +21,260 @@
namespace {
-int dummySuccess = 0xbeef;
-const char* dummyErrorMessage = "I am an error message :3";
+ int dummySuccess = 0xbeef;
+ const char* dummyErrorMessage = "I am an error message :3";
-// Check returning a success MaybeError with {};
-TEST(ErrorTests, Error_Success) {
- auto ReturnSuccess = []() -> MaybeError {
- return {};
- };
+ // Check returning a success MaybeError with {};
+ TEST(ErrorTests, Error_Success) {
+ auto ReturnSuccess = []() -> MaybeError { return {}; };
- MaybeError result = ReturnSuccess();
- ASSERT_TRUE(result.IsSuccess());
-}
+ MaybeError result = ReturnSuccess();
+ ASSERT_TRUE(result.IsSuccess());
+ }
-// Check returning an error MaybeError with "return DAWN_VALIDATION_ERROR"
-TEST(ErrorTests, Error_Error) {
- auto ReturnError = []() -> MaybeError {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check returning an error MaybeError with "return DAWN_VALIDATION_ERROR"
+ TEST(ErrorTests, Error_Error) {
+ auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); };
- MaybeError result = ReturnError();
- ASSERT_TRUE(result.IsError());
+ MaybeError result = ReturnError();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check returning a success ResultOrError with an implicit conversion
-TEST(ErrorTests, ResultOrError_Success) {
- auto ReturnSuccess = []() -> ResultOrError<int*> {
- return &dummySuccess;
- };
+ // Check returning a success ResultOrError with an implicit conversion
+ TEST(ErrorTests, ResultOrError_Success) {
+ auto ReturnSuccess = []() -> ResultOrError<int*> { return &dummySuccess; };
- ResultOrError<int*> result = ReturnSuccess();
- ASSERT_TRUE(result.IsSuccess());
- ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
-}
+ ResultOrError<int*> result = ReturnSuccess();
+ ASSERT_TRUE(result.IsSuccess());
+ ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
+ }
-// Check returning an error ResultOrError with "return DAWN_VALIDATION_ERROR"
-TEST(ErrorTests, ResultOrError_Error) {
- auto ReturnError = []() -> ResultOrError<int*> {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check returning an error ResultOrError with "return DAWN_VALIDATION_ERROR"
+ TEST(ErrorTests, ResultOrError_Error) {
+ auto ReturnError = []() -> ResultOrError<int*> {
+ return DAWN_VALIDATION_ERROR(dummyErrorMessage);
+ };
- ResultOrError<int*> result = ReturnError();
- ASSERT_TRUE(result.IsError());
+ ResultOrError<int*> result = ReturnError();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check DAWN_TRY handles successes correctly.
-TEST(ErrorTests, TRY_Success) {
- auto ReturnSuccess = []() -> MaybeError {
- return {};
- };
+ // Check DAWN_TRY handles successes correctly.
+ TEST(ErrorTests, TRY_Success) {
+ auto ReturnSuccess = []() -> MaybeError { return {}; };
- // We need to check that DAWN_TRY doesn't return on successes
- bool tryReturned = true;
+ // We need to check that DAWN_TRY doesn't return on successes
+ bool tryReturned = true;
- auto Try = [ReturnSuccess, &tryReturned]() -> MaybeError {
- DAWN_TRY(ReturnSuccess());
- tryReturned = false;
- return {};
- };
+ auto Try = [ReturnSuccess, &tryReturned]() -> MaybeError {
+ DAWN_TRY(ReturnSuccess());
+ tryReturned = false;
+ return {};
+ };
- MaybeError result = Try();
- ASSERT_TRUE(result.IsSuccess());
- ASSERT_FALSE(tryReturned);
-}
+ MaybeError result = Try();
+ ASSERT_TRUE(result.IsSuccess());
+ ASSERT_FALSE(tryReturned);
+ }
-// Check DAWN_TRY handles errors correctly.
-TEST(ErrorTests, TRY_Error) {
- auto ReturnError = []() -> MaybeError {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check DAWN_TRY handles errors correctly.
+ TEST(ErrorTests, TRY_Error) {
+ auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); };
- auto Try = [ReturnError]() -> MaybeError {
- DAWN_TRY(ReturnError());
- // DAWN_TRY should return before this point
- EXPECT_FALSE(true);
- return {};
- };
+ auto Try = [ReturnError]() -> MaybeError {
+ DAWN_TRY(ReturnError());
+ // DAWN_TRY should return before this point
+ EXPECT_FALSE(true);
+ return {};
+ };
- MaybeError result = Try();
- ASSERT_TRUE(result.IsError());
+ MaybeError result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check DAWN_TRY adds to the backtrace.
-TEST(ErrorTests, TRY_AddsToBacktrace) {
- auto ReturnError = []() -> MaybeError {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check DAWN_TRY adds to the backtrace.
+ TEST(ErrorTests, TRY_AddsToBacktrace) {
+ auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); };
- auto SingleTry = [ReturnError]() -> MaybeError {
- DAWN_TRY(ReturnError());
- return {};
- };
+ auto SingleTry = [ReturnError]() -> MaybeError {
+ DAWN_TRY(ReturnError());
+ return {};
+ };
- auto DoubleTry = [SingleTry]() -> MaybeError {
- DAWN_TRY(SingleTry());
- return {};
- };
+ auto DoubleTry = [SingleTry]() -> MaybeError {
+ DAWN_TRY(SingleTry());
+ return {};
+ };
- MaybeError singleResult = SingleTry();
- ASSERT_TRUE(singleResult.IsError());
+ MaybeError singleResult = SingleTry();
+ ASSERT_TRUE(singleResult.IsError());
- MaybeError doubleResult = DoubleTry();
- ASSERT_TRUE(doubleResult.IsError());
+ MaybeError doubleResult = DoubleTry();
+ ASSERT_TRUE(doubleResult.IsError());
- std::unique_ptr<ErrorData> singleData = singleResult.AcquireError();
- std::unique_ptr<ErrorData> doubleData = doubleResult.AcquireError();
+ std::unique_ptr<ErrorData> singleData = singleResult.AcquireError();
+ std::unique_ptr<ErrorData> doubleData = doubleResult.AcquireError();
- ASSERT_EQ(singleData->GetBacktrace().size() + 1, doubleData->GetBacktrace().size());
-}
+ ASSERT_EQ(singleData->GetBacktrace().size() + 1, doubleData->GetBacktrace().size());
+ }
-// Check DAWN_TRY_ASSIGN handles successes correctly.
-TEST(ErrorTests, TRY_RESULT_Success) {
- auto ReturnSuccess = []() -> ResultOrError<int*> {
- return &dummySuccess;
- };
+ // Check DAWN_TRY_ASSIGN handles successes correctly.
+ TEST(ErrorTests, TRY_RESULT_Success) {
+ auto ReturnSuccess = []() -> ResultOrError<int*> { return &dummySuccess; };
- // We need to check that DAWN_TRY doesn't return on successes
- bool tryReturned = true;
+ // We need to check that DAWN_TRY doesn't return on successes
+ bool tryReturned = true;
- auto Try = [ReturnSuccess, &tryReturned]() -> ResultOrError<int*> {
- int* result = nullptr;
- DAWN_TRY_ASSIGN(result, ReturnSuccess());
- tryReturned = false;
+ auto Try = [ReturnSuccess, &tryReturned]() -> ResultOrError<int*> {
+ int* result = nullptr;
+ DAWN_TRY_ASSIGN(result, ReturnSuccess());
+ tryReturned = false;
- EXPECT_EQ(result, &dummySuccess);
- return result;
- };
+ EXPECT_EQ(result, &dummySuccess);
+ return result;
+ };
- ResultOrError<int*> result = Try();
- ASSERT_TRUE(result.IsSuccess());
- ASSERT_FALSE(tryReturned);
- ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
-}
+ ResultOrError<int*> result = Try();
+ ASSERT_TRUE(result.IsSuccess());
+ ASSERT_FALSE(tryReturned);
+ ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
+ }
-// Check DAWN_TRY_ASSIGN handles errors correctly.
-TEST(ErrorTests, TRY_RESULT_Error) {
- auto ReturnError = []() -> ResultOrError<int*> {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check DAWN_TRY_ASSIGN handles errors correctly.
+ TEST(ErrorTests, TRY_RESULT_Error) {
+ auto ReturnError = []() -> ResultOrError<int*> {
+ return DAWN_VALIDATION_ERROR(dummyErrorMessage);
+ };
- auto Try = [ReturnError]() -> ResultOrError<int*> {
- int* result = nullptr;
- DAWN_TRY_ASSIGN(result, ReturnError());
- DAWN_UNUSED(result);
+ auto Try = [ReturnError]() -> ResultOrError<int*> {
+ int* result = nullptr;
+ DAWN_TRY_ASSIGN(result, ReturnError());
+ DAWN_UNUSED(result);
- // DAWN_TRY should return before this point
- EXPECT_FALSE(true);
- return &dummySuccess;
- };
+ // DAWN_TRY should return before this point
+ EXPECT_FALSE(true);
+ return &dummySuccess;
+ };
- ResultOrError<int*> result = Try();
- ASSERT_TRUE(result.IsError());
+ ResultOrError<int*> result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check DAWN_TRY_ASSIGN adds to the backtrace.
-TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) {
- auto ReturnError = []() -> ResultOrError<int*> {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check DAWN_TRY_ASSIGN adds to the backtrace.
+ TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) {
+ auto ReturnError = []() -> ResultOrError<int*> {
+ return DAWN_VALIDATION_ERROR(dummyErrorMessage);
+ };
- auto SingleTry = [ReturnError]() -> ResultOrError<int*> {
- DAWN_TRY(ReturnError());
- return &dummySuccess;
- };
+ auto SingleTry = [ReturnError]() -> ResultOrError<int*> {
+ DAWN_TRY(ReturnError());
+ return &dummySuccess;
+ };
- auto DoubleTry = [SingleTry]() -> ResultOrError<int*> {
- DAWN_TRY(SingleTry());
- return &dummySuccess;
- };
+ auto DoubleTry = [SingleTry]() -> ResultOrError<int*> {
+ DAWN_TRY(SingleTry());
+ return &dummySuccess;
+ };
- ResultOrError<int*> singleResult = SingleTry();
- ASSERT_TRUE(singleResult.IsError());
+ ResultOrError<int*> singleResult = SingleTry();
+ ASSERT_TRUE(singleResult.IsError());
- ResultOrError<int*> doubleResult = DoubleTry();
- ASSERT_TRUE(doubleResult.IsError());
+ ResultOrError<int*> doubleResult = DoubleTry();
+ ASSERT_TRUE(doubleResult.IsError());
- std::unique_ptr<ErrorData> singleData = singleResult.AcquireError();
- std::unique_ptr<ErrorData> doubleData = doubleResult.AcquireError();
+ std::unique_ptr<ErrorData> singleData = singleResult.AcquireError();
+ std::unique_ptr<ErrorData> doubleData = doubleResult.AcquireError();
- ASSERT_EQ(singleData->GetBacktrace().size() + 1, doubleData->GetBacktrace().size());
-}
+ ASSERT_EQ(singleData->GetBacktrace().size() + 1, doubleData->GetBacktrace().size());
+ }
-// Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error
-TEST(ErrorTests, TRY_RESULT_ConversionToError) {
- auto ReturnError = []() -> ResultOrError<int*> {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error
+ TEST(ErrorTests, TRY_RESULT_ConversionToError) {
+ auto ReturnError = []() -> ResultOrError<int*> {
+ return DAWN_VALIDATION_ERROR(dummyErrorMessage);
+ };
- auto Try = [ReturnError]() -> MaybeError {
- int* result = nullptr;
- DAWN_TRY_ASSIGN(result, ReturnError());
- DAWN_UNUSED(result);
+ auto Try = [ReturnError]() -> MaybeError {
+ int* result = nullptr;
+ DAWN_TRY_ASSIGN(result, ReturnError());
+ DAWN_UNUSED(result);
- return {};
- };
+ return {};
+ };
- MaybeError result = Try();
- ASSERT_TRUE(result.IsError());
+ MaybeError result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error
-// Version without Result<E*, T*>
-TEST(ErrorTests, TRY_RESULT_ConversionToErrorNonPointer) {
- auto ReturnError = []() -> ResultOrError<int> {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error
+ // Version without Result<E*, T*>
+ TEST(ErrorTests, TRY_RESULT_ConversionToErrorNonPointer) {
+ auto ReturnError = []() -> ResultOrError<int> {
+ return DAWN_VALIDATION_ERROR(dummyErrorMessage);
+ };
- auto Try = [ReturnError]() -> MaybeError {
- int result = 0;
- DAWN_TRY_ASSIGN(result, ReturnError());
- DAWN_UNUSED(result);
+ auto Try = [ReturnError]() -> MaybeError {
+ int result = 0;
+ DAWN_TRY_ASSIGN(result, ReturnError());
+ DAWN_UNUSED(result);
- return {};
- };
+ return {};
+ };
- MaybeError result = Try();
- ASSERT_TRUE(result.IsError());
+ MaybeError result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check a MaybeError can be DAWN_TRIED in a function that returns an ResultOrError
-// Check DAWN_TRY handles errors correctly.
-TEST(ErrorTests, TRY_ConversionToErrorOrResult) {
- auto ReturnError = []() -> MaybeError {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check a MaybeError can be DAWN_TRIED in a function that returns an ResultOrError
+ // Check DAWN_TRY handles errors correctly.
+ TEST(ErrorTests, TRY_ConversionToErrorOrResult) {
+ auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); };
- auto Try = [ReturnError]() -> ResultOrError<int*>{
- DAWN_TRY(ReturnError());
- return &dummySuccess;
- };
+ auto Try = [ReturnError]() -> ResultOrError<int*> {
+ DAWN_TRY(ReturnError());
+ return &dummySuccess;
+ };
- ResultOrError<int*> result = Try();
- ASSERT_TRUE(result.IsError());
+ ResultOrError<int*> result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
-// Check a MaybeError can be DAWN_TRIED in a function that returns an ResultOrError
-// Check DAWN_TRY handles errors correctly. Version without Result<E*, T*>
-TEST(ErrorTests, TRY_ConversionToErrorOrResultNonPointer) {
- auto ReturnError = []() -> MaybeError {
- return DAWN_VALIDATION_ERROR(dummyErrorMessage);
- };
+ // Check a MaybeError can be DAWN_TRIED in a function that returns an ResultOrError
+ // Check DAWN_TRY handles errors correctly. Version without Result<E*, T*>
+ TEST(ErrorTests, TRY_ConversionToErrorOrResultNonPointer) {
+ auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); };
- auto Try = [ReturnError]() -> ResultOrError<int>{
- DAWN_TRY(ReturnError());
- return 42;
- };
+ auto Try = [ReturnError]() -> ResultOrError<int> {
+ DAWN_TRY(ReturnError());
+ return 42;
+ };
- ResultOrError<int> result = Try();
- ASSERT_TRUE(result.IsError());
+ ResultOrError<int> result = Try();
+ ASSERT_TRUE(result.IsError());
- std::unique_ptr<ErrorData> errorData = result.AcquireError();
- ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
-}
+ std::unique_ptr<ErrorData> errorData = result.AcquireError();
+ ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage);
+ }
} // anonymous namespace
diff --git a/src/tests/unittests/LinkedListTests.cpp b/src/tests/unittests/LinkedListTests.cpp
index 94f2ecd..7dcb37f 100644
--- a/src/tests/unittests/LinkedListTests.cpp
+++ b/src/tests/unittests/LinkedListTests.cpp
@@ -362,4 +362,4 @@
EXPECT_TRUE(n.IsInList());
n.RemoveFromList();
EXPECT_FALSE(n.IsInList());
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/ObjectBaseTests.cpp b/src/tests/unittests/ObjectBaseTests.cpp
index 6c3f2d7..ab141d3 100644
--- a/src/tests/unittests/ObjectBaseTests.cpp
+++ b/src/tests/unittests/ObjectBaseTests.cpp
@@ -194,4 +194,3 @@
obj = nullptr;
ASSERT_EQ(refcount, 1);
}
-
diff --git a/src/tests/unittests/PerStageTests.cpp b/src/tests/unittests/PerStageTests.cpp
index a8c4cf4..dcecd83 100644
--- a/src/tests/unittests/PerStageTests.cpp
+++ b/src/tests/unittests/PerStageTests.cpp
@@ -48,7 +48,7 @@
counts[SingleShaderStage::Compute] = 0;
for (auto stage : IterateStages(kAllStages)) {
- counts[stage] ++;
+ counts[stage]++;
}
ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 1);
@@ -64,7 +64,7 @@
counts[SingleShaderStage::Compute] = 0;
for (auto stage : IterateStages(wgpu::ShaderStage::Fragment)) {
- counts[stage] ++;
+ counts[stage]++;
}
ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 0);
@@ -80,7 +80,7 @@
counts[SingleShaderStage::Compute] = 0;
for (auto stage : IterateStages(wgpu::ShaderStage::Fragment & wgpu::ShaderStage::Vertex)) {
- counts[stage] ++;
+ counts[stage]++;
}
ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 0);
diff --git a/src/tests/unittests/RefCountedTests.cpp b/src/tests/unittests/RefCountedTests.cpp
index 5981dc9..7e5c959 100644
--- a/src/tests/unittests/RefCountedTests.cpp
+++ b/src/tests/unittests/RefCountedTests.cpp
@@ -410,4 +410,4 @@
destination = nullptr;
EXPECT_TRUE(deleted);
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/ResultTests.cpp b/src/tests/unittests/ResultTests.cpp
index 7b21d2e..bd48217 100644
--- a/src/tests/unittests/ResultTests.cpp
+++ b/src/tests/unittests/ResultTests.cpp
@@ -19,363 +19,367 @@
namespace {
-template<typename T, typename E>
-void TestError(Result<T, E>* result, E expectedError) {
- EXPECT_TRUE(result->IsError());
- EXPECT_FALSE(result->IsSuccess());
+ template <typename T, typename E>
+ void TestError(Result<T, E>* result, E expectedError) {
+ EXPECT_TRUE(result->IsError());
+ EXPECT_FALSE(result->IsSuccess());
- std::unique_ptr<E> storedError = result->AcquireError();
- EXPECT_EQ(*storedError, expectedError);
-}
-
-template<typename T, typename E>
-void TestSuccess(Result<T, E>* result, T expectedSuccess) {
- EXPECT_FALSE(result->IsError());
- EXPECT_TRUE(result->IsSuccess());
-
- const T storedSuccess = result->AcquireSuccess();
- EXPECT_EQ(storedSuccess, expectedSuccess);
-
- // Once the success is acquired, result has an empty
- // payload and is neither in the success nor error state.
- EXPECT_FALSE(result->IsError());
- EXPECT_FALSE(result->IsSuccess());
-}
-
-static int dummyError = 0xbeef;
-static float dummySuccess = 42.0f;
-static const float dummyConstSuccess = 42.0f;
-
-class AClass : public RefCounted {
- public:
- int a = 0;
-};
-
-// Tests using the following overload of TestSuccess make
-// local Ref instances to dummySuccessObj. Tests should
-// ensure any local Ref objects made along the way continue
-// to point to dummySuccessObj.
-template <typename T, typename E>
-void TestSuccess(Result<Ref<T>, E>* result, T* expectedSuccess) {
- EXPECT_FALSE(result->IsError());
- EXPECT_TRUE(result->IsSuccess());
-
- // AClass starts with a reference count of 1 and stored
- // on the stack in the caller. The result parameter should
- // hold the only other reference to the object.
- EXPECT_EQ(expectedSuccess->GetRefCountForTesting(), 2u);
-
- const Ref<T> storedSuccess = result->AcquireSuccess();
- EXPECT_EQ(storedSuccess.Get(), expectedSuccess);
-
- // Once the success is acquired, result has an empty
- // payload and is neither in the success nor error state.
- EXPECT_FALSE(result->IsError());
- EXPECT_FALSE(result->IsSuccess());
-
- // Once we call AcquireSuccess, result no longer stores
- // the object. storedSuccess should contain the only other
- // reference to the object.
- EXPECT_EQ(storedSuccess->GetRefCountForTesting(), 2u);
-}
-
-// Result<void, E*>
-
-// Test constructing an error Result<void, E>
-TEST(ResultOnlyPointerError, ConstructingError) {
- Result<void, int> result(std::make_unique<int>(dummyError));
- TestError(&result, dummyError);
-}
-
-// Test moving an error Result<void, E>
-TEST(ResultOnlyPointerError, MovingError) {
- Result<void, int> result(std::make_unique<int>(dummyError));
- Result<void, int> movedResult(std::move(result));
- TestError(&movedResult, dummyError);
-}
-
-// Test returning an error Result<void, E>
-TEST(ResultOnlyPointerError, ReturningError) {
- auto CreateError = []() -> Result<void, int> { return {std::make_unique<int>(dummyError)}; };
-
- Result<void, int> result = CreateError();
- TestError(&result, dummyError);
-}
-
-// Test constructing a success Result<void, E>
-TEST(ResultOnlyPointerError, ConstructingSuccess) {
- Result<void, int> result;
- EXPECT_TRUE(result.IsSuccess());
- EXPECT_FALSE(result.IsError());
-}
-
-// Test moving a success Result<void, E>
-TEST(ResultOnlyPointerError, MovingSuccess) {
- Result<void, int> result;
- Result<void, int> movedResult(std::move(result));
- EXPECT_TRUE(movedResult.IsSuccess());
- EXPECT_FALSE(movedResult.IsError());
-}
-
-// Test returning a success Result<void, E>
-TEST(ResultOnlyPointerError, ReturningSuccess) {
- auto CreateError = []() -> Result<void, int> { return {}; };
-
- Result<void, int> result = CreateError();
- EXPECT_TRUE(result.IsSuccess());
- EXPECT_FALSE(result.IsError());
-}
-
-// Result<T*, E*>
-
-// Test constructing an error Result<T*, E>
-TEST(ResultBothPointer, ConstructingError) {
- Result<float*, int> result(std::make_unique<int>(dummyError));
- TestError(&result, dummyError);
-}
-
-// Test moving an error Result<T*, E>
-TEST(ResultBothPointer, MovingError) {
- Result<float*, int> result(std::make_unique<int>(dummyError));
- Result<float*, int> movedResult(std::move(result));
- TestError(&movedResult, dummyError);
-}
-
-// Test returning an error Result<T*, E>
-TEST(ResultBothPointer, ReturningError) {
- auto CreateError = []() -> Result<float*, int> { return {std::make_unique<int>(dummyError)}; };
-
- Result<float*, int> result = CreateError();
- TestError(&result, dummyError);
-}
-
-// Test constructing a success Result<T*, E>
-TEST(ResultBothPointer, ConstructingSuccess) {
- Result<float*, int> result(&dummySuccess);
- TestSuccess(&result, &dummySuccess);
-}
-
-// Test moving a success Result<T*, E>
-TEST(ResultBothPointer, MovingSuccess) {
- Result<float*, int> result(&dummySuccess);
- Result<float*, int> movedResult(std::move(result));
- TestSuccess(&movedResult, &dummySuccess);
-}
-
-// Test returning a success Result<T*, E>
-TEST(ResultBothPointer, ReturningSuccess) {
- auto CreateSuccess = []() -> Result<float*, int*> {
- return {&dummySuccess};
- };
-
- Result<float*, int*> result = CreateSuccess();
- TestSuccess(&result, &dummySuccess);
-}
-
-// Tests converting from a Result<TChild*, E>
-TEST(ResultBothPointer, ConversionFromChildClass) {
- struct T {
- int a;
- };
- struct TChild : T {};
-
- TChild child;
- T* childAsT = &child;
- {
- Result<T*, int> result(&child);
- TestSuccess(&result, childAsT);
+ std::unique_ptr<E> storedError = result->AcquireError();
+ EXPECT_EQ(*storedError, expectedError);
}
- {
- Result<TChild*, int> resultChild(&child);
- Result<T*, int> result(std::move(resultChild));
- TestSuccess(&result, childAsT);
+
+ template <typename T, typename E>
+ void TestSuccess(Result<T, E>* result, T expectedSuccess) {
+ EXPECT_FALSE(result->IsError());
+ EXPECT_TRUE(result->IsSuccess());
+
+ const T storedSuccess = result->AcquireSuccess();
+ EXPECT_EQ(storedSuccess, expectedSuccess);
+
+ // Once the success is acquired, result has an empty
+ // payload and is neither in the success nor error state.
+ EXPECT_FALSE(result->IsError());
+ EXPECT_FALSE(result->IsSuccess());
}
- {
- Result<TChild*, int> resultChild(&child);
- Result<T*, int> result = std::move(resultChild);
- TestSuccess(&result, childAsT);
+
+ static int dummyError = 0xbeef;
+ static float dummySuccess = 42.0f;
+ static const float dummyConstSuccess = 42.0f;
+
+ class AClass : public RefCounted {
+ public:
+ int a = 0;
+ };
+
+ // Tests using the following overload of TestSuccess make
+ // local Ref instances to dummySuccessObj. Tests should
+ // ensure any local Ref objects made along the way continue
+ // to point to dummySuccessObj.
+ template <typename T, typename E>
+ void TestSuccess(Result<Ref<T>, E>* result, T* expectedSuccess) {
+ EXPECT_FALSE(result->IsError());
+ EXPECT_TRUE(result->IsSuccess());
+
+ // AClass starts with a reference count of 1 and stored
+ // on the stack in the caller. The result parameter should
+ // hold the only other reference to the object.
+ EXPECT_EQ(expectedSuccess->GetRefCountForTesting(), 2u);
+
+ const Ref<T> storedSuccess = result->AcquireSuccess();
+ EXPECT_EQ(storedSuccess.Get(), expectedSuccess);
+
+ // Once the success is acquired, result has an empty
+ // payload and is neither in the success nor error state.
+ EXPECT_FALSE(result->IsError());
+ EXPECT_FALSE(result->IsSuccess());
+
+ // Once we call AcquireSuccess, result no longer stores
+ // the object. storedSuccess should contain the only other
+ // reference to the object.
+ EXPECT_EQ(storedSuccess->GetRefCountForTesting(), 2u);
}
-}
-// Result<const T*, E>
+ // Result<void, E*>
-// Test constructing an error Result<const T*, E>
-TEST(ResultBothPointerWithConstResult, ConstructingError) {
- Result<const float*, int> result(std::make_unique<int>(dummyError));
- TestError(&result, dummyError);
-}
+ // Test constructing an error Result<void, E>
+ TEST(ResultOnlyPointerError, ConstructingError) {
+ Result<void, int> result(std::make_unique<int>(dummyError));
+ TestError(&result, dummyError);
+ }
-// Test moving an error Result<const T*, E>
-TEST(ResultBothPointerWithConstResult, MovingError) {
- Result<const float*, int> result(std::make_unique<int>(dummyError));
- Result<const float*, int> movedResult(std::move(result));
- TestError(&movedResult, dummyError);
-}
+ // Test moving an error Result<void, E>
+ TEST(ResultOnlyPointerError, MovingError) {
+ Result<void, int> result(std::make_unique<int>(dummyError));
+ Result<void, int> movedResult(std::move(result));
+ TestError(&movedResult, dummyError);
+ }
-// Test returning an error Result<const T*, E*>
-TEST(ResultBothPointerWithConstResult, ReturningError) {
- auto CreateError = []() -> Result<const float*, int> {
- return {std::make_unique<int>(dummyError)};
+ // Test returning an error Result<void, E>
+ TEST(ResultOnlyPointerError, ReturningError) {
+ auto CreateError = []() -> Result<void, int> {
+ return {std::make_unique<int>(dummyError)};
+ };
+
+ Result<void, int> result = CreateError();
+ TestError(&result, dummyError);
+ }
+
+ // Test constructing a success Result<void, E>
+ TEST(ResultOnlyPointerError, ConstructingSuccess) {
+ Result<void, int> result;
+ EXPECT_TRUE(result.IsSuccess());
+ EXPECT_FALSE(result.IsError());
+ }
+
+ // Test moving a success Result<void, E>
+ TEST(ResultOnlyPointerError, MovingSuccess) {
+ Result<void, int> result;
+ Result<void, int> movedResult(std::move(result));
+ EXPECT_TRUE(movedResult.IsSuccess());
+ EXPECT_FALSE(movedResult.IsError());
+ }
+
+ // Test returning a success Result<void, E>
+ TEST(ResultOnlyPointerError, ReturningSuccess) {
+ auto CreateError = []() -> Result<void, int> { return {}; };
+
+ Result<void, int> result = CreateError();
+ EXPECT_TRUE(result.IsSuccess());
+ EXPECT_FALSE(result.IsError());
+ }
+
+ // Result<T*, E*>
+
+ // Test constructing an error Result<T*, E>
+ TEST(ResultBothPointer, ConstructingError) {
+ Result<float*, int> result(std::make_unique<int>(dummyError));
+ TestError(&result, dummyError);
+ }
+
+ // Test moving an error Result<T*, E>
+ TEST(ResultBothPointer, MovingError) {
+ Result<float*, int> result(std::make_unique<int>(dummyError));
+ Result<float*, int> movedResult(std::move(result));
+ TestError(&movedResult, dummyError);
+ }
+
+ // Test returning an error Result<T*, E>
+ TEST(ResultBothPointer, ReturningError) {
+ auto CreateError = []() -> Result<float*, int> {
+ return {std::make_unique<int>(dummyError)};
+ };
+
+ Result<float*, int> result = CreateError();
+ TestError(&result, dummyError);
+ }
+
+ // Test constructing a success Result<T*, E>
+ TEST(ResultBothPointer, ConstructingSuccess) {
+ Result<float*, int> result(&dummySuccess);
+ TestSuccess(&result, &dummySuccess);
+ }
+
+ // Test moving a success Result<T*, E>
+ TEST(ResultBothPointer, MovingSuccess) {
+ Result<float*, int> result(&dummySuccess);
+ Result<float*, int> movedResult(std::move(result));
+ TestSuccess(&movedResult, &dummySuccess);
+ }
+
+ // Test returning a success Result<T*, E>
+ TEST(ResultBothPointer, ReturningSuccess) {
+ auto CreateSuccess = []() -> Result<float*, int*> { return {&dummySuccess}; };
+
+ Result<float*, int*> result = CreateSuccess();
+ TestSuccess(&result, &dummySuccess);
+ }
+
+ // Tests converting from a Result<TChild*, E>
+ TEST(ResultBothPointer, ConversionFromChildClass) {
+ struct T {
+ int a;
+ };
+ struct TChild : T {};
+
+ TChild child;
+ T* childAsT = &child;
+ {
+ Result<T*, int> result(&child);
+ TestSuccess(&result, childAsT);
+ }
+ {
+ Result<TChild*, int> resultChild(&child);
+ Result<T*, int> result(std::move(resultChild));
+ TestSuccess(&result, childAsT);
+ }
+ {
+ Result<TChild*, int> resultChild(&child);
+ Result<T*, int> result = std::move(resultChild);
+ TestSuccess(&result, childAsT);
+ }
+ }
+
+ // Result<const T*, E>
+
+ // Test constructing an error Result<const T*, E>
+ TEST(ResultBothPointerWithConstResult, ConstructingError) {
+ Result<const float*, int> result(std::make_unique<int>(dummyError));
+ TestError(&result, dummyError);
+ }
+
+ // Test moving an error Result<const T*, E>
+ TEST(ResultBothPointerWithConstResult, MovingError) {
+ Result<const float*, int> result(std::make_unique<int>(dummyError));
+ Result<const float*, int> movedResult(std::move(result));
+ TestError(&movedResult, dummyError);
+ }
+
+ // Test returning an error Result<const T*, E*>
+ TEST(ResultBothPointerWithConstResult, ReturningError) {
+ auto CreateError = []() -> Result<const float*, int> {
+ return {std::make_unique<int>(dummyError)};
+ };
+
+ Result<const float*, int> result = CreateError();
+ TestError(&result, dummyError);
+ }
+
+ // Test constructing a success Result<const T*, E*>
+ TEST(ResultBothPointerWithConstResult, ConstructingSuccess) {
+ Result<const float*, int> result(&dummyConstSuccess);
+ TestSuccess(&result, &dummyConstSuccess);
+ }
+
+ // Test moving a success Result<const T*, E*>
+ TEST(ResultBothPointerWithConstResult, MovingSuccess) {
+ Result<const float*, int> result(&dummyConstSuccess);
+ Result<const float*, int> movedResult(std::move(result));
+ TestSuccess(&movedResult, &dummyConstSuccess);
+ }
+
+ // Test returning a success Result<const T*, E*>
+ TEST(ResultBothPointerWithConstResult, ReturningSuccess) {
+ auto CreateSuccess = []() -> Result<const float*, int> { return {&dummyConstSuccess}; };
+
+ Result<const float*, int> result = CreateSuccess();
+ TestSuccess(&result, &dummyConstSuccess);
+ }
+
+ // Result<Ref<T>, E>
+
+ // Test constructing an error Result<Ref<T>, E>
+ TEST(ResultRefT, ConstructingError) {
+ Result<Ref<AClass>, int> result(std::make_unique<int>(dummyError));
+ TestError(&result, dummyError);
+ }
+
+ // Test moving an error Result<Ref<T>, E>
+ TEST(ResultRefT, MovingError) {
+ Result<Ref<AClass>, int> result(std::make_unique<int>(dummyError));
+ Result<Ref<AClass>, int> movedResult(std::move(result));
+ TestError(&movedResult, dummyError);
+ }
+
+ // Test returning an error Result<Ref<T>, E>
+ TEST(ResultRefT, ReturningError) {
+ auto CreateError = []() -> Result<Ref<AClass>, int> {
+ return {std::make_unique<int>(dummyError)};
+ };
+
+ Result<Ref<AClass>, int> result = CreateError();
+ TestError(&result, dummyError);
+ }
+
+ // Test constructing a success Result<Ref<T>, E>
+ TEST(ResultRefT, ConstructingSuccess) {
+ AClass success;
+
+ Ref<AClass> refObj(&success);
+ Result<Ref<AClass>, int> result(std::move(refObj));
+ TestSuccess(&result, &success);
+ }
+
+ // Test moving a success Result<Ref<T>, E>
+ TEST(ResultRefT, MovingSuccess) {
+ AClass success;
+
+ Ref<AClass> refObj(&success);
+ Result<Ref<AClass>, int> result(std::move(refObj));
+ Result<Ref<AClass>, int> movedResult(std::move(result));
+ TestSuccess(&movedResult, &success);
+ }
+
+ // Test returning a success Result<Ref<T>, E>
+ TEST(ResultRefT, ReturningSuccess) {
+ AClass success;
+ auto CreateSuccess = [&success]() -> Result<Ref<AClass>, int> {
+ return Ref<AClass>(&success);
+ };
+
+ Result<Ref<AClass>, int> result = CreateSuccess();
+ TestSuccess(&result, &success);
+ }
+
+ class OtherClass {
+ public:
+ int a = 0;
};
+ class Base : public RefCounted {};
+ class Child : public OtherClass, public Base {};
- Result<const float*, int> result = CreateError();
- TestError(&result, dummyError);
-}
+ // Test constructing a Result<Ref<TChild>, E>
+ TEST(ResultRefT, ConversionFromChildConstructor) {
+ Child child;
+ Ref<Child> refChild(&child);
-// Test constructing a success Result<const T*, E*>
-TEST(ResultBothPointerWithConstResult, ConstructingSuccess) {
- Result<const float*, int> result(&dummyConstSuccess);
- TestSuccess(&result, &dummyConstSuccess);
-}
+ Result<Ref<Base>, int> result(std::move(refChild));
+ TestSuccess<Base>(&result, &child);
+ }
-// Test moving a success Result<const T*, E*>
-TEST(ResultBothPointerWithConstResult, MovingSuccess) {
- Result<const float*, int> result(&dummyConstSuccess);
- Result<const float*, int> movedResult(std::move(result));
- TestSuccess(&movedResult, &dummyConstSuccess);
-}
+ // Test copy constructing Result<Ref<TChild>, E>
+ TEST(ResultRefT, ConversionFromChildCopyConstructor) {
+ Child child;
+ Ref<Child> refChild(&child);
-// Test returning a success Result<const T*, E*>
-TEST(ResultBothPointerWithConstResult, ReturningSuccess) {
- auto CreateSuccess = []() -> Result<const float*, int> { return {&dummyConstSuccess}; };
+ Result<Ref<Child>, int> resultChild(std::move(refChild));
+ Result<Ref<Base>, int> result(std::move(resultChild));
+ TestSuccess<Base>(&result, &child);
+ }
- Result<const float*, int> result = CreateSuccess();
- TestSuccess(&result, &dummyConstSuccess);
-}
+ // Test assignment operator for Result<Ref<TChild>, E>
+ TEST(ResultRefT, ConversionFromChildAssignmentOperator) {
+ Child child;
+ Ref<Child> refChild(&child);
-// Result<Ref<T>, E>
+ Result<Ref<Child>, int> resultChild(std::move(refChild));
+ Result<Ref<Base>, int> result = std::move(resultChild);
+ TestSuccess<Base>(&result, &child);
+ }
-// Test constructing an error Result<Ref<T>, E>
-TEST(ResultRefT, ConstructingError) {
- Result<Ref<AClass>, int> result(std::make_unique<int>(dummyError));
- TestError(&result, dummyError);
-}
+ // Result<T, E>
-// Test moving an error Result<Ref<T>, E>
-TEST(ResultRefT, MovingError) {
- Result<Ref<AClass>, int> result(std::make_unique<int>(dummyError));
- Result<Ref<AClass>, int> movedResult(std::move(result));
- TestError(&movedResult, dummyError);
-}
+ // Test constructing an error Result<T, E>
+ TEST(ResultGeneric, ConstructingError) {
+ Result<std::vector<float>, int> result(std::make_unique<int>(dummyError));
+ TestError(&result, dummyError);
+ }
-// Test returning an error Result<Ref<T>, E>
-TEST(ResultRefT, ReturningError) {
- auto CreateError = []() -> Result<Ref<AClass>, int> {
- return {std::make_unique<int>(dummyError)};
- };
+ // Test moving an error Result<T, E>
+ TEST(ResultGeneric, MovingError) {
+ Result<std::vector<float>, int> result(std::make_unique<int>(dummyError));
+ Result<std::vector<float>, int> movedResult(std::move(result));
+ TestError(&movedResult, dummyError);
+ }
- Result<Ref<AClass>, int> result = CreateError();
- TestError(&result, dummyError);
-}
+ // Test returning an error Result<T, E>
+ TEST(ResultGeneric, ReturningError) {
+ auto CreateError = []() -> Result<std::vector<float>, int> {
+ return {std::make_unique<int>(dummyError)};
+ };
-// Test constructing a success Result<Ref<T>, E>
-TEST(ResultRefT, ConstructingSuccess) {
- AClass success;
+ Result<std::vector<float>, int> result = CreateError();
+ TestError(&result, dummyError);
+ }
- Ref<AClass> refObj(&success);
- Result<Ref<AClass>, int> result(std::move(refObj));
- TestSuccess(&result, &success);
-}
+ // Test constructing a success Result<T, E>
+ TEST(ResultGeneric, ConstructingSuccess) {
+ Result<std::vector<float>, int> result({1.0f});
+ TestSuccess(&result, {1.0f});
+ }
-// Test moving a success Result<Ref<T>, E>
-TEST(ResultRefT, MovingSuccess) {
- AClass success;
+ // Test moving a success Result<T, E>
+ TEST(ResultGeneric, MovingSuccess) {
+ Result<std::vector<float>, int> result({1.0f});
+ Result<std::vector<float>, int> movedResult(std::move(result));
+ TestSuccess(&movedResult, {1.0f});
+ }
- Ref<AClass> refObj(&success);
- Result<Ref<AClass>, int> result(std::move(refObj));
- Result<Ref<AClass>, int> movedResult(std::move(result));
- TestSuccess(&movedResult, &success);
-}
+ // Test returning a success Result<T, E>
+ TEST(ResultGeneric, ReturningSuccess) {
+ auto CreateSuccess = []() -> Result<std::vector<float>, int> { return {{1.0f}}; };
-// Test returning a success Result<Ref<T>, E>
-TEST(ResultRefT, ReturningSuccess) {
- AClass success;
- auto CreateSuccess = [&success]() -> Result<Ref<AClass>, int> { return Ref<AClass>(&success); };
-
- Result<Ref<AClass>, int> result = CreateSuccess();
- TestSuccess(&result, &success);
-}
-
-class OtherClass {
- public:
- int a = 0;
-};
-class Base : public RefCounted {};
-class Child : public OtherClass, public Base {};
-
-// Test constructing a Result<Ref<TChild>, E>
-TEST(ResultRefT, ConversionFromChildConstructor) {
- Child child;
- Ref<Child> refChild(&child);
-
- Result<Ref<Base>, int> result(std::move(refChild));
- TestSuccess<Base>(&result, &child);
-}
-
-// Test copy constructing Result<Ref<TChild>, E>
-TEST(ResultRefT, ConversionFromChildCopyConstructor) {
- Child child;
- Ref<Child> refChild(&child);
-
- Result<Ref<Child>, int> resultChild(std::move(refChild));
- Result<Ref<Base>, int> result(std::move(resultChild));
- TestSuccess<Base>(&result, &child);
-}
-
-// Test assignment operator for Result<Ref<TChild>, E>
-TEST(ResultRefT, ConversionFromChildAssignmentOperator) {
- Child child;
- Ref<Child> refChild(&child);
-
- Result<Ref<Child>, int> resultChild(std::move(refChild));
- Result<Ref<Base>, int> result = std::move(resultChild);
- TestSuccess<Base>(&result, &child);
-}
-
-// Result<T, E>
-
-// Test constructing an error Result<T, E>
-TEST(ResultGeneric, ConstructingError) {
- Result<std::vector<float>, int> result(std::make_unique<int>(dummyError));
- TestError(&result, dummyError);
-}
-
-// Test moving an error Result<T, E>
-TEST(ResultGeneric, MovingError) {
- Result<std::vector<float>, int> result(std::make_unique<int>(dummyError));
- Result<std::vector<float>, int> movedResult(std::move(result));
- TestError(&movedResult, dummyError);
-}
-
-// Test returning an error Result<T, E>
-TEST(ResultGeneric, ReturningError) {
- auto CreateError = []() -> Result<std::vector<float>, int> {
- return {std::make_unique<int>(dummyError)};
- };
-
- Result<std::vector<float>, int> result = CreateError();
- TestError(&result, dummyError);
-}
-
-// Test constructing a success Result<T, E>
-TEST(ResultGeneric, ConstructingSuccess) {
- Result<std::vector<float>, int> result({1.0f});
- TestSuccess(&result, {1.0f});
-}
-
-// Test moving a success Result<T, E>
-TEST(ResultGeneric, MovingSuccess) {
- Result<std::vector<float>, int> result({1.0f});
- Result<std::vector<float>, int> movedResult(std::move(result));
- TestSuccess(&movedResult, {1.0f});
-}
-
-// Test returning a success Result<T, E>
-TEST(ResultGeneric, ReturningSuccess) {
- auto CreateSuccess = []() -> Result<std::vector<float>, int> { return {{1.0f}}; };
-
- Result<std::vector<float>, int> result = CreateSuccess();
- TestSuccess(&result, {1.0f});
-}
+ Result<std::vector<float>, int> result = CreateSuccess();
+ TestSuccess(&result, {1.0f});
+ }
} // anonymous namespace
diff --git a/src/tests/unittests/RingBufferAllocatorTests.cpp b/src/tests/unittests/RingBufferAllocatorTests.cpp
index a3e5a62..f0c256b 100644
--- a/src/tests/unittests/RingBufferAllocatorTests.cpp
+++ b/src/tests/unittests/RingBufferAllocatorTests.cpp
@@ -174,4 +174,4 @@
ASSERT_EQ(allocator.Allocate(1, serial), 0u);
ASSERT_EQ(allocator.Allocate(std::numeric_limits<uint64_t>::max(), serial + 1),
RingBufferAllocator::kInvalidOffset);
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/SerialQueueTests.cpp b/src/tests/unittests/SerialQueueTests.cpp
index 6f75eb7..2545c51 100644
--- a/src/tests/unittests/SerialQueueTests.cpp
+++ b/src/tests/unittests/SerialQueueTests.cpp
@@ -153,4 +153,4 @@
queue.Enqueue({2}, 1);
EXPECT_EQ(queue.LastSerial(), 1u);
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/ToBackendTests.cpp b/src/tests/unittests/ToBackendTests.cpp
index c537a8e..5234e40 100644
--- a/src/tests/unittests/ToBackendTests.cpp
+++ b/src/tests/unittests/ToBackendTests.cpp
@@ -21,21 +21,19 @@
// Make our own Base - Backend object pair, reusing the CommandBuffer name
namespace dawn_native {
- class CommandBufferBase : public RefCounted {
- };
-}
+ class CommandBufferBase : public RefCounted {};
+} // namespace dawn_native
using namespace dawn_native;
-class MyCommandBuffer : public CommandBufferBase {
-};
+class MyCommandBuffer : public CommandBufferBase {};
struct MyBackendTraits {
using CommandBufferType = MyCommandBuffer;
};
// Instanciate ToBackend for our "backend"
-template<typename T>
+template <typename T>
auto ToBackend(T&& common) -> decltype(ToBackendBase<MyBackendTraits>(common)) {
return ToBackendBase<MyBackendTraits>(common);
}
@@ -71,7 +69,8 @@
const Ref<CommandBufferBase> base(cmdBuf);
const auto& backendCmdBuf = ToBackend(base);
- static_assert(std::is_same<decltype(ToBackend(base)), const Ref<MyCommandBuffer>&>::value, "");
+ static_assert(std::is_same<decltype(ToBackend(base)), const Ref<MyCommandBuffer>&>::value,
+ "");
ASSERT_EQ(cmdBuf, backendCmdBuf.Get());
cmdBuf->Release();
diff --git a/src/tests/unittests/d3d12/CopySplitTests.cpp b/src/tests/unittests/d3d12/CopySplitTests.cpp
index 46f7047..f867fef 100644
--- a/src/tests/unittests/d3d12/CopySplitTests.cpp
+++ b/src/tests/unittests/d3d12/CopySplitTests.cpp
@@ -55,7 +55,8 @@
// Check that the offset is aligned
void ValidateOffset(const TextureCopySplit& copySplit) {
- ASSERT_TRUE(Align(copySplit.offset, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT) == copySplit.offset);
+ ASSERT_TRUE(Align(copySplit.offset, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT) ==
+ copySplit.offset);
}
bool RangesOverlap(uint32_t minA, uint32_t maxA, uint32_t minB, uint32_t maxB) {
@@ -68,9 +69,15 @@
const auto& a = copySplit.copies[i];
for (uint32_t j = i + 1; j < copySplit.count; ++j) {
const auto& b = copySplit.copies[j];
- bool overlapX = RangesOverlap(a.textureOffset.x, a.textureOffset.x + a.copySize.width, b.textureOffset.x, b.textureOffset.x + b.copySize.width);
- bool overlapY = RangesOverlap(a.textureOffset.y, a.textureOffset.y + a.copySize.height, b.textureOffset.y, b.textureOffset.y + b.copySize.height);
- bool overlapZ = RangesOverlap(a.textureOffset.z, a.textureOffset.z + a.copySize.depth, b.textureOffset.z, b.textureOffset.z + b.copySize.depth);
+ bool overlapX =
+ RangesOverlap(a.textureOffset.x, a.textureOffset.x + a.copySize.width,
+ b.textureOffset.x, b.textureOffset.x + b.copySize.width);
+ bool overlapY =
+ RangesOverlap(a.textureOffset.y, a.textureOffset.y + a.copySize.height,
+ b.textureOffset.y, b.textureOffset.y + b.copySize.height);
+ bool overlapZ =
+ RangesOverlap(a.textureOffset.z, a.textureOffset.z + a.copySize.depth,
+ b.textureOffset.z, b.textureOffset.z + b.copySize.depth);
ASSERT_TRUE(!overlapX || !overlapY || !overlapZ);
}
}
@@ -105,7 +112,8 @@
ASSERT_EQ(maxZ, textureSpec.z + textureSpec.depth);
}
- // Validate that the number of pixels copied is exactly equal to the number of pixels in the texture region
+ // Validate that the number of pixels copied is exactly equal to the number of pixels in the
+ // texture region
void ValidatePixelCount(const TextureSpec& textureSpec, const TextureCopySplit& copySplit) {
uint32_t count = 0;
for (uint32_t i = 0; i < copySplit.count; ++i) {
@@ -116,7 +124,9 @@
}
// Check that every buffer offset is at the correct pixel location
- void ValidateBufferOffset(const TextureSpec& textureSpec, const BufferSpec& bufferSpec, const TextureCopySplit& copySplit) {
+ void ValidateBufferOffset(const TextureSpec& textureSpec,
+ const BufferSpec& bufferSpec,
+ const TextureCopySplit& copySplit) {
ASSERT_TRUE(copySplit.count > 0);
uint32_t texelsPerBlock = textureSpec.blockWidth * textureSpec.blockHeight;
@@ -149,7 +159,9 @@
}
}
- void ValidateCopySplit(const TextureSpec& textureSpec, const BufferSpec& bufferSpec, const TextureCopySplit& copySplit) {
+ void ValidateCopySplit(const TextureSpec& textureSpec,
+ const BufferSpec& bufferSpec,
+ const TextureCopySplit& copySplit) {
ValidateFootprints(copySplit);
ValidateOffset(copySplit);
ValidateDisjoint(copySplit);
@@ -176,8 +188,13 @@
os << "CopySplit" << std::endl;
for (uint32_t i = 0; i < copySplit.count; ++i) {
const auto& copy = copySplit.copies[i];
- os << " " << i << ": Texture at (" << copy.textureOffset.x << ", " << copy.textureOffset.y << ", " << copy.textureOffset.z << "), size (" << copy.copySize.width << ", " << copy.copySize.height << ", " << copy.copySize.depth << ")" << std::endl;
- os << " " << i << ": Buffer at (" << copy.bufferOffset.x << ", " << copy.bufferOffset.y << ", " << copy.bufferOffset.z << "), footprint (" << copy.bufferSize.width << ", " << copy.bufferSize.height << ", " << copy.bufferSize.depth << ")" << std::endl;
+ os << " " << i << ": Texture at (" << copy.textureOffset.x << ", "
+ << copy.textureOffset.y << ", " << copy.textureOffset.z << "), size ("
+ << copy.copySize.width << ", " << copy.copySize.height << ", " << copy.copySize.depth
+ << ")" << std::endl;
+ os << " " << i << ": Buffer at (" << copy.bufferOffset.x << ", " << copy.bufferOffset.y
+ << ", " << copy.bufferOffset.z << "), footprint (" << copy.bufferSize.width << ", "
+ << copy.bufferSize.height << ", " << copy.bufferSize.depth << ")" << std::endl;
}
return os;
}
@@ -260,42 +277,40 @@
}
// Define a list of values to set properties in the spec structs
- constexpr uint32_t kCheckValues[] = {
- 1, 2, 3, 4, 5, 6, 7, 8, // small values
- 16, 32, 64, 128, 256, 512, 1024, 2048, // powers of 2
- 15, 31, 63, 127, 257, 511, 1023, 2047, // misalignments
- 17, 33, 65, 129, 257, 513, 1025, 2049
- };
+ constexpr uint32_t kCheckValues[] = {1, 2, 3, 4, 5, 6, 7, 8, // small values
+ 16, 32, 64, 128, 256, 512, 1024, 2048, // powers of 2
+ 15, 31, 63, 127, 257, 511, 1023, 2047, // misalignments
+ 17, 33, 65, 129, 257, 513, 1025, 2049};
-}
+} // namespace
class CopySplitTest : public testing::Test {
- protected:
- TextureCopySplit DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
- ASSERT(textureSpec.width % textureSpec.blockWidth == 0 &&
- textureSpec.height % textureSpec.blockHeight == 0);
- dawn_native::Format fakeFormat = {};
- fakeFormat.blockWidth = textureSpec.blockWidth;
- fakeFormat.blockHeight = textureSpec.blockHeight;
- fakeFormat.blockByteSize = textureSpec.texelBlockSizeInBytes;
- TextureCopySplit copySplit = ComputeTextureCopySplit(
- {textureSpec.x, textureSpec.y, textureSpec.z},
- {textureSpec.width, textureSpec.height, textureSpec.depth}, fakeFormat,
- bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
- ValidateCopySplit(textureSpec, bufferSpec, copySplit);
- return copySplit;
- }
+ protected:
+ TextureCopySplit DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
+ ASSERT(textureSpec.width % textureSpec.blockWidth == 0 &&
+ textureSpec.height % textureSpec.blockHeight == 0);
+ dawn_native::Format fakeFormat = {};
+ fakeFormat.blockWidth = textureSpec.blockWidth;
+ fakeFormat.blockHeight = textureSpec.blockHeight;
+ fakeFormat.blockByteSize = textureSpec.texelBlockSizeInBytes;
+ TextureCopySplit copySplit = ComputeTextureCopySplit(
+ {textureSpec.x, textureSpec.y, textureSpec.z},
+ {textureSpec.width, textureSpec.height, textureSpec.depth}, fakeFormat,
+ bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
+ ValidateCopySplit(textureSpec, bufferSpec, copySplit);
+ return copySplit;
+ }
};
TEST_F(CopySplitTest, General) {
for (TextureSpec textureSpec : kBaseTextureSpecs) {
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -310,12 +325,12 @@
}
textureSpec.width = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -331,12 +346,12 @@
}
textureSpec.height = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -349,12 +364,12 @@
for (uint32_t val : kCheckValues) {
textureSpec.x = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -367,12 +382,12 @@
for (uint32_t val : kCheckValues) {
textureSpec.y = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -385,12 +400,12 @@
for (uint32_t texelSize : {4, 8, 16, 32, 64}) {
textureSpec.texelBlockSizeInBytes = texelSize;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
-
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -407,8 +422,9 @@
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
@@ -426,8 +442,9 @@
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
- message << "Failed generating splits: " << textureSpec << ", " << bufferSpec << std::endl
- << copySplit << std::endl;
+ message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
+ << std::endl
+ << copySplit << std::endl;
FAIL() << message.str();
}
}
diff --git a/src/tests/unittests/validation/BindGroupValidationTests.cpp b/src/tests/unittests/validation/BindGroupValidationTests.cpp
index 6dec976..9b3aeb5 100644
--- a/src/tests/unittests/validation/BindGroupValidationTests.cpp
+++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp
@@ -121,16 +121,10 @@
{1, wgpu::ShaderStage::Fragment, wgpu::BindingType::Sampler}});
// Control case: check that different bindings work
- utils::MakeBindGroup(device, layout, {
- {0, mSampler},
- {1, mSampler}
- });
+ utils::MakeBindGroup(device, layout, {{0, mSampler}, {1, mSampler}});
// Check that setting the same binding twice is invalid
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {
- {0, mSampler},
- {0, mSampler}
- }));
+ ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, mSampler}, {0, mSampler}}));
}
// Check that a sampler binding must contain exactly one sampler
@@ -406,7 +400,7 @@
utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256}});
// Success case, touching the end of the buffer works
- utils::MakeBindGroup(device, layout, {{0, buffer, 3*256, 256}});
+ utils::MakeBindGroup(device, layout, {{0, buffer, 3 * 256, 256}});
// Error case, zero size is invalid.
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 0}}));
@@ -419,16 +413,17 @@
utils::MakeBindGroup(device, layout, {{0, buffer, 256, wgpu::kWholeSize}});
// Error case, offset is OOB
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256*5, 0}}));
+ ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256 * 5, 0}}));
// Error case, size is OOB
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256*5}}));
+ ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 0, 256 * 5}}));
// Error case, offset+size is OOB
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 1024, 256}}));
// Error case, offset+size overflows to be 0
- ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));
+ ASSERT_DEVICE_ERROR(
+ utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));
}
// Tests constraints to be sure the uniform buffer binding isn't too large
@@ -1191,8 +1186,8 @@
// Create buffers which are 3x, 2x, and 1x the size of the minimum buffer offset, plus 4 bytes
// to spare (to avoid zero-sized bindings). We will offset the bindings so they reach the very
- // end of the buffer. Any mismatch applying too-large of an offset to a smaller buffer will hit the
- // out-of-bounds condition during validation.
+ // end of the buffer. Any mismatch applying too-large of an offset to a smaller buffer will hit
+ // the out-of-bounds condition during validation.
wgpu::Buffer buffer3x =
CreateBuffer(3 * kMinDynamicBufferOffsetAlignment + 4, wgpu::BufferUsage::Storage);
wgpu::Buffer buffer2x =
@@ -1487,7 +1482,6 @@
wgpu::RenderPipeline CreateFSRenderPipeline(
const char* fsShader,
std::vector<wgpu::BindGroupLayout> bindGroupLayout) {
-
wgpu::ShaderModule vsModule =
utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
@@ -1520,7 +1514,7 @@
layout(location = 0) out vec4 fragColor;
void main() {
})",
- std::move(bindGroupLayout));
+ std::move(bindGroupLayout));
}
wgpu::ComputePipeline CreateComputePipeline(
@@ -1558,7 +1552,7 @@
} rdst;
void main() {
})",
- std::move(bindGroupLayout));
+ std::move(bindGroupLayout));
}
};
diff --git a/src/tests/unittests/validation/BufferValidationTests.cpp b/src/tests/unittests/validation/BufferValidationTests.cpp
index f807b52..a724057 100644
--- a/src/tests/unittests/validation/BufferValidationTests.cpp
+++ b/src/tests/unittests/validation/BufferValidationTests.cpp
@@ -21,13 +21,13 @@
using namespace testing;
class MockBufferMapReadCallback {
- public:
- MOCK_METHOD(void,
- Call,
- (WGPUBufferMapAsyncStatus status,
- const uint32_t* ptr,
- uint64_t dataLength,
- void* userdata));
+ public:
+ MOCK_METHOD(void,
+ Call,
+ (WGPUBufferMapAsyncStatus status,
+ const uint32_t* ptr,
+ uint64_t dataLength,
+ void* userdata));
};
static std::unique_ptr<MockBufferMapReadCallback> mockBufferMapReadCallback;
@@ -41,11 +41,11 @@
}
class MockBufferMapWriteCallback {
- public:
- MOCK_METHOD(
- void,
- Call,
- (WGPUBufferMapAsyncStatus status, uint32_t* ptr, uint64_t dataLength, void* userdata));
+ public:
+ MOCK_METHOD(
+ void,
+ Call,
+ (WGPUBufferMapAsyncStatus status, uint32_t* ptr, uint64_t dataLength, void* userdata));
};
static std::unique_ptr<MockBufferMapWriteCallback> mockBufferMapWriteCallback;
@@ -59,57 +59,57 @@
}
class BufferValidationTest : public ValidationTest {
- protected:
- wgpu::Buffer CreateMapReadBuffer(uint64_t size) {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = size;
- descriptor.usage = wgpu::BufferUsage::MapRead;
+ protected:
+ wgpu::Buffer CreateMapReadBuffer(uint64_t size) {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = size;
+ descriptor.usage = wgpu::BufferUsage::MapRead;
- return device.CreateBuffer(&descriptor);
- }
- wgpu::Buffer CreateMapWriteBuffer(uint64_t size) {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = size;
- descriptor.usage = wgpu::BufferUsage::MapWrite;
+ return device.CreateBuffer(&descriptor);
+ }
+ wgpu::Buffer CreateMapWriteBuffer(uint64_t size) {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = size;
+ descriptor.usage = wgpu::BufferUsage::MapWrite;
- return device.CreateBuffer(&descriptor);
- }
+ return device.CreateBuffer(&descriptor);
+ }
- wgpu::CreateBufferMappedResult CreateBufferMapped(uint64_t size, wgpu::BufferUsage usage) {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = size;
- descriptor.usage = usage;
+ wgpu::CreateBufferMappedResult CreateBufferMapped(uint64_t size, wgpu::BufferUsage usage) {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = size;
+ descriptor.usage = usage;
- return device.CreateBufferMapped(&descriptor);
- }
+ return device.CreateBufferMapped(&descriptor);
+ }
- wgpu::Buffer BufferMappedAtCreation(uint64_t size, wgpu::BufferUsage usage) {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = size;
- descriptor.usage = usage;
- descriptor.mappedAtCreation = true;
+ wgpu::Buffer BufferMappedAtCreation(uint64_t size, wgpu::BufferUsage usage) {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = size;
+ descriptor.usage = usage;
+ descriptor.mappedAtCreation = true;
- return device.CreateBuffer(&descriptor);
- }
+ return device.CreateBuffer(&descriptor);
+ }
- wgpu::Queue queue;
+ wgpu::Queue queue;
- private:
- void SetUp() override {
- ValidationTest::SetUp();
+ private:
+ void SetUp() override {
+ ValidationTest::SetUp();
- mockBufferMapReadCallback = std::make_unique<MockBufferMapReadCallback>();
- mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>();
- queue = device.GetDefaultQueue();
- }
+ mockBufferMapReadCallback = std::make_unique<MockBufferMapReadCallback>();
+ mockBufferMapWriteCallback = std::make_unique<MockBufferMapWriteCallback>();
+ queue = device.GetDefaultQueue();
+ }
- void TearDown() override {
- // Delete mocks so that expectations are checked
- mockBufferMapReadCallback = nullptr;
- mockBufferMapWriteCallback = nullptr;
+ void TearDown() override {
+ // Delete mocks so that expectations are checked
+ mockBufferMapReadCallback = nullptr;
+ mockBufferMapWriteCallback = nullptr;
- ValidationTest::TearDown();
- }
+ ValidationTest::TearDown();
+ }
};
// Test case where creation should succeed
@@ -416,7 +416,8 @@
WaitForAllOperations(device);
}
-// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the callback
+// Test that the MapReadCallback isn't fired twice the buffer external refcount reaches 0 in the
+// callback
TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) {
wgpu::Buffer buf = CreateMapReadBuffer(4);
@@ -429,7 +430,8 @@
WaitForAllOperations(device);
}
-// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the callback
+// Test that the MapWriteCallback isn't fired twice the buffer external refcount reaches 0 in the
+// callback
TEST_F(BufferValidationTest, DestroyInsideMapWriteCallback) {
wgpu::Buffer buf = CreateMapWriteBuffer(4);
diff --git a/src/tests/unittests/validation/CommandBufferValidationTests.cpp b/src/tests/unittests/validation/CommandBufferValidationTests.cpp
index e8909ac..e31879b 100644
--- a/src/tests/unittests/validation/CommandBufferValidationTests.cpp
+++ b/src/tests/unittests/validation/CommandBufferValidationTests.cpp
@@ -16,8 +16,7 @@
#include "utils/WGPUHelpers.h"
-class CommandBufferValidationTest : public ValidationTest {
-};
+class CommandBufferValidationTest : public ValidationTest {};
// Test for an empty command buffer
TEST_F(CommandBufferValidationTest, Empty) {
diff --git a/src/tests/unittests/validation/ComputeValidationTests.cpp b/src/tests/unittests/validation/ComputeValidationTests.cpp
index fded925..8135997 100644
--- a/src/tests/unittests/validation/ComputeValidationTests.cpp
+++ b/src/tests/unittests/validation/ComputeValidationTests.cpp
@@ -14,7 +14,7 @@
#include "tests/unittests/validation/ValidationTest.h"
-class ComputeValidationTest : public ValidationTest {
-};
+class ComputeValidationTest : public ValidationTest {};
-//TODO(cwallez@chromium.org): Add a regression test for Disptach validation trying to acces the input state.
+// TODO(cwallez@chromium.org): Add a regression test for Disptach validation trying to acces the
+// input state.
diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp
index 1cd9e28..e5877af 100644
--- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp
+++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp
@@ -1168,8 +1168,8 @@
TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) {
{
- wgpu::Texture source = Create2DTexture(16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8,
- wgpu::TextureUsage::CopySrc);
+ wgpu::Texture source = Create2DTexture(
+ 16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1179,8 +1179,8 @@
}
{
- wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8,
- wgpu::TextureUsage::CopySrc);
+ wgpu::Texture source = Create2DTexture(
+ 16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1190,8 +1190,8 @@
}
{
- wgpu::Texture source = Create2DTexture(16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8,
- wgpu::TextureUsage::CopySrc);
+ wgpu::Texture source = Create2DTexture(
+ 16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
wgpu::Texture destination = Create2DTexture(
16, 16, 1, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
@@ -1659,4 +1659,4 @@
{0, 0, 0});
}
}
-}
\ No newline at end of file
+}
diff --git a/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp b/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp
index 62e9ca9..cc16640 100644
--- a/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp
+++ b/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp
@@ -223,8 +223,7 @@
}
}
-class SetScissorRectTest : public ValidationTest {
-};
+class SetScissorRectTest : public ValidationTest {};
// Test to check basic use of SetScissor
TEST_F(SetScissorRectTest, Success) {
@@ -284,8 +283,7 @@
encoder.Finish();
}
-class SetBlendColorTest : public ValidationTest {
-};
+class SetBlendColorTest : public ValidationTest {};
// Test to check basic use of SetBlendColor
TEST_F(SetBlendColorTest, Success) {
@@ -315,8 +313,7 @@
encoder.Finish();
}
-class SetStencilReferenceTest : public ValidationTest {
-};
+class SetStencilReferenceTest : public ValidationTest {};
// Test to check basic use of SetStencilReferenceTest
TEST_F(SetStencilReferenceTest, Success) {
diff --git a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
index 566c746..8779ce3 100644
--- a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
+++ b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
@@ -18,181 +18,180 @@
namespace {
-class QueueSubmitValidationTest : public ValidationTest {
-};
+ class QueueSubmitValidationTest : public ValidationTest {};
-// Test submitting with a mapped buffer is disallowed
-TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
- // Create a map-write buffer.
- wgpu::BufferDescriptor descriptor;
- descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
- descriptor.size = 4;
- wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
- // Create a fake copy destination buffer
- descriptor.usage = wgpu::BufferUsage::CopyDst;
- wgpu::Buffer targetBuffer = device.CreateBuffer(&descriptor);
-
- // Create a command buffer that reads from the mappable buffer.
- wgpu::CommandBuffer commands;
- {
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- encoder.CopyBufferToBuffer(buffer, 0, targetBuffer, 0, 4);
- commands = encoder.Finish();
- }
-
- wgpu::Queue queue = device.GetDefaultQueue();
-
- // Submitting when the buffer has never been mapped should succeed
- queue.Submit(1, &commands);
-
- // Map the buffer, submitting when the buffer is mapped should fail
- buffer.MapWriteAsync(nullptr, nullptr);
-
- // Try submitting before the callback is fired.
- ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
-
- WaitForAllOperations(device);
-
- // Try submitting after the callback is fired.
- ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
-
- // Unmap the buffer, queue submit should succeed
- buffer.Unmap();
- queue.Submit(1, &commands);
-}
-
-class QueueWriteBufferValidationTest : public ValidationTest {
- private:
- void SetUp() override {
- ValidationTest::SetUp();
- queue = device.GetDefaultQueue();
- }
-
- protected:
- wgpu::Buffer CreateBuffer(uint64_t size) {
+ // Test submitting with a mapped buffer is disallowed
+ TEST_F(QueueSubmitValidationTest, SubmitWithMappedBuffer) {
+ // Create a map-write buffer.
wgpu::BufferDescriptor descriptor;
- descriptor.size = size;
- descriptor.usage = wgpu::BufferUsage::CopyDst;
- return device.CreateBuffer(&descriptor);
- }
-
- wgpu::Queue queue;
-};
-
-// Test the success case for WriteBuffer
-TEST_F(QueueWriteBufferValidationTest, Success) {
- wgpu::Buffer buf = CreateBuffer(4);
-
- uint32_t foo = 0x01020304;
- queue.WriteBuffer(buf, 0, &foo, sizeof(foo));
-}
-
-// Test error case for WriteBuffer out of bounds
-TEST_F(QueueWriteBufferValidationTest, OutOfBounds) {
- wgpu::Buffer buf = CreateBuffer(4);
-
- uint32_t foo[2] = {0, 0};
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, foo, 8));
-}
-
-// Test error case for WriteBuffer out of bounds with an overflow
-TEST_F(QueueWriteBufferValidationTest, OutOfBoundsOverflow) {
- wgpu::Buffer buf = CreateBuffer(1024);
-
- uint32_t foo[2] = {0, 0};
-
- // An offset that when added to "4" would overflow to be zero and pass validation without
- // overflow checks.
- uint64_t offset = uint64_t(int64_t(0) - int64_t(4));
-
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, offset, foo, 4));
-}
-
-// Test error case for WriteBuffer with the wrong usage
-TEST_F(QueueWriteBufferValidationTest, WrongUsage) {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = 4;
- descriptor.usage = wgpu::BufferUsage::Vertex;
- wgpu::Buffer buf = device.CreateBuffer(&descriptor);
-
- uint32_t foo = 0;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &foo, sizeof(foo)));
-}
-
-// Test WriteBuffer with unaligned size
-TEST_F(QueueWriteBufferValidationTest, UnalignedSize) {
- wgpu::Buffer buf = CreateBuffer(4);
-
- uint16_t value = 123;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
-}
-
-// Test WriteBuffer with unaligned offset
-TEST_F(QueueWriteBufferValidationTest, UnalignedOffset) {
- wgpu::Buffer buf = CreateBuffer(8);
-
- uint32_t value = 0x01020304;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 2, &value, sizeof(value)));
-}
-
-// Test WriteBuffer with destroyed buffer
-TEST_F(QueueWriteBufferValidationTest, DestroyedBuffer) {
- wgpu::Buffer buf = CreateBuffer(4);
- buf.Destroy();
-
- uint32_t value = 0;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
-}
-
-// Test WriteBuffer with mapped buffer
-TEST_F(QueueWriteBufferValidationTest, MappedBuffer) {
- // CreateBufferMapped
- {
- wgpu::BufferDescriptor descriptor;
+ descriptor.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc;
descriptor.size = 4;
- descriptor.usage = wgpu::BufferUsage::CopyDst;
- wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
-
- uint32_t value = 0;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(result.buffer, 0, &value, sizeof(value)));
- }
-
- // mappedAtCreation
- {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = 4;
- descriptor.usage = wgpu::BufferUsage::CopyDst;
- descriptor.mappedAtCreation = true;
wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
- uint32_t value = 0;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 0, &value, sizeof(value)));
+ // Create a fake copy destination buffer
+ descriptor.usage = wgpu::BufferUsage::CopyDst;
+ wgpu::Buffer targetBuffer = device.CreateBuffer(&descriptor);
+
+ // Create a command buffer that reads from the mappable buffer.
+ wgpu::CommandBuffer commands;
+ {
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
+ encoder.CopyBufferToBuffer(buffer, 0, targetBuffer, 0, 4);
+ commands = encoder.Finish();
+ }
+
+ wgpu::Queue queue = device.GetDefaultQueue();
+
+ // Submitting when the buffer has never been mapped should succeed
+ queue.Submit(1, &commands);
+
+ // Map the buffer, submitting when the buffer is mapped should fail
+ buffer.MapWriteAsync(nullptr, nullptr);
+
+ // Try submitting before the callback is fired.
+ ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
+
+ WaitForAllOperations(device);
+
+ // Try submitting after the callback is fired.
+ ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
+
+ // Unmap the buffer, queue submit should succeed
+ buffer.Unmap();
+ queue.Submit(1, &commands);
}
- // MapReadAsync
- {
+ class QueueWriteBufferValidationTest : public ValidationTest {
+ private:
+ void SetUp() override {
+ ValidationTest::SetUp();
+ queue = device.GetDefaultQueue();
+ }
+
+ protected:
+ wgpu::Buffer CreateBuffer(uint64_t size) {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = size;
+ descriptor.usage = wgpu::BufferUsage::CopyDst;
+ return device.CreateBuffer(&descriptor);
+ }
+
+ wgpu::Queue queue;
+ };
+
+ // Test the success case for WriteBuffer
+ TEST_F(QueueWriteBufferValidationTest, Success) {
+ wgpu::Buffer buf = CreateBuffer(4);
+
+ uint32_t foo = 0x01020304;
+ queue.WriteBuffer(buf, 0, &foo, sizeof(foo));
+ }
+
+ // Test error case for WriteBuffer out of bounds
+ TEST_F(QueueWriteBufferValidationTest, OutOfBounds) {
+ wgpu::Buffer buf = CreateBuffer(4);
+
+ uint32_t foo[2] = {0, 0};
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, foo, 8));
+ }
+
+ // Test error case for WriteBuffer out of bounds with an overflow
+ TEST_F(QueueWriteBufferValidationTest, OutOfBoundsOverflow) {
+ wgpu::Buffer buf = CreateBuffer(1024);
+
+ uint32_t foo[2] = {0, 0};
+
+ // An offset that when added to "4" would overflow to be zero and pass validation without
+ // overflow checks.
+ uint64_t offset = uint64_t(int64_t(0) - int64_t(4));
+
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, offset, foo, 4));
+ }
+
+ // Test error case for WriteBuffer with the wrong usage
+ TEST_F(QueueWriteBufferValidationTest, WrongUsage) {
wgpu::BufferDescriptor descriptor;
descriptor.size = 4;
- descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
+ descriptor.usage = wgpu::BufferUsage::Vertex;
wgpu::Buffer buf = device.CreateBuffer(&descriptor);
- buf.MapReadAsync(nullptr, nullptr);
+ uint32_t foo = 0;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &foo, sizeof(foo)));
+ }
+
+ // Test WriteBuffer with unaligned size
+ TEST_F(QueueWriteBufferValidationTest, UnalignedSize) {
+ wgpu::Buffer buf = CreateBuffer(4);
+
+ uint16_t value = 123;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+ }
+
+ // Test WriteBuffer with unaligned offset
+ TEST_F(QueueWriteBufferValidationTest, UnalignedOffset) {
+ wgpu::Buffer buf = CreateBuffer(8);
+
+ uint32_t value = 0x01020304;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 2, &value, sizeof(value)));
+ }
+
+ // Test WriteBuffer with destroyed buffer
+ TEST_F(QueueWriteBufferValidationTest, DestroyedBuffer) {
+ wgpu::Buffer buf = CreateBuffer(4);
+ buf.Destroy();
+
uint32_t value = 0;
ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
}
- // MapWriteAsync
- {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = 4;
- descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
- wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+ // Test WriteBuffer with mapped buffer
+ TEST_F(QueueWriteBufferValidationTest, MappedBuffer) {
+ // CreateBufferMapped
+ {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = 4;
+ descriptor.usage = wgpu::BufferUsage::CopyDst;
+ wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
- buf.MapWriteAsync(nullptr, nullptr);
- uint32_t value = 0;
- ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+ uint32_t value = 0;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(result.buffer, 0, &value, sizeof(value)));
+ }
+
+ // mappedAtCreation
+ {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = 4;
+ descriptor.usage = wgpu::BufferUsage::CopyDst;
+ descriptor.mappedAtCreation = true;
+ wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+ uint32_t value = 0;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 0, &value, sizeof(value)));
+ }
+
+ // MapReadAsync
+ {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = 4;
+ descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
+ wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
+ buf.MapReadAsync(nullptr, nullptr);
+ uint32_t value = 0;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+ }
+
+ // MapWriteAsync
+ {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = 4;
+ descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::MapWrite;
+ wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
+ buf.MapWriteAsync(nullptr, nullptr);
+ uint32_t value = 0;
+ ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+ }
}
-}
} // anonymous namespace
diff --git a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp
index 039da11..c238acf 100644
--- a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp
+++ b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp
@@ -636,4 +636,4 @@
}
}
-} // anonymous namespace
\ No newline at end of file
+} // anonymous namespace
diff --git a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
index 7c9b11b..5b99a1f 100644
--- a/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
+++ b/src/tests/unittests/validation/RenderPassDescriptorValidationTests.cpp
@@ -22,720 +22,746 @@
namespace {
-class RenderPassDescriptorValidationTest : public ValidationTest {
- public:
- void AssertBeginRenderPassSuccess(const wgpu::RenderPassDescriptor* descriptor) {
- wgpu::CommandEncoder commandEncoder = TestBeginRenderPass(descriptor);
- commandEncoder.Finish();
- }
- void AssertBeginRenderPassError(const wgpu::RenderPassDescriptor* descriptor) {
- wgpu::CommandEncoder commandEncoder = TestBeginRenderPass(descriptor);
- ASSERT_DEVICE_ERROR(commandEncoder.Finish());
+ class RenderPassDescriptorValidationTest : public ValidationTest {
+ public:
+ void AssertBeginRenderPassSuccess(const wgpu::RenderPassDescriptor* descriptor) {
+ wgpu::CommandEncoder commandEncoder = TestBeginRenderPass(descriptor);
+ commandEncoder.Finish();
+ }
+ void AssertBeginRenderPassError(const wgpu::RenderPassDescriptor* descriptor) {
+ wgpu::CommandEncoder commandEncoder = TestBeginRenderPass(descriptor);
+ ASSERT_DEVICE_ERROR(commandEncoder.Finish());
+ }
+
+ private:
+ wgpu::CommandEncoder TestBeginRenderPass(const wgpu::RenderPassDescriptor* descriptor) {
+ wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
+ wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(descriptor);
+ renderPassEncoder.EndPass();
+ return commandEncoder;
+ }
+ };
+
+ wgpu::Texture CreateTexture(wgpu::Device& device,
+ wgpu::TextureDimension dimension,
+ wgpu::TextureFormat format,
+ uint32_t width,
+ uint32_t height,
+ uint32_t arrayLayerCount,
+ uint32_t mipLevelCount,
+ uint32_t sampleCount = 1,
+ wgpu::TextureUsage usage = wgpu::TextureUsage::OutputAttachment) {
+ wgpu::TextureDescriptor descriptor;
+ descriptor.dimension = dimension;
+ descriptor.size.width = width;
+ descriptor.size.height = height;
+ descriptor.size.depth = arrayLayerCount;
+ descriptor.sampleCount = sampleCount;
+ descriptor.format = format;
+ descriptor.mipLevelCount = mipLevelCount;
+ descriptor.usage = usage;
+
+ return device.CreateTexture(&descriptor);
}
- private:
- wgpu::CommandEncoder TestBeginRenderPass(const wgpu::RenderPassDescriptor* descriptor) {
- wgpu::CommandEncoder commandEncoder = device.CreateCommandEncoder();
- wgpu::RenderPassEncoder renderPassEncoder = commandEncoder.BeginRenderPass(descriptor);
- renderPassEncoder.EndPass();
- return commandEncoder;
+ wgpu::TextureView Create2DAttachment(wgpu::Device& device,
+ uint32_t width,
+ uint32_t height,
+ wgpu::TextureFormat format) {
+ wgpu::Texture texture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, format, width, height, 1, 1);
+ return texture.CreateView();
}
-};
-wgpu::Texture CreateTexture(wgpu::Device& device,
- wgpu::TextureDimension dimension,
- wgpu::TextureFormat format,
- uint32_t width,
- uint32_t height,
- uint32_t arrayLayerCount,
- uint32_t mipLevelCount,
- uint32_t sampleCount = 1,
- wgpu::TextureUsage usage = wgpu::TextureUsage::OutputAttachment) {
- wgpu::TextureDescriptor descriptor;
- descriptor.dimension = dimension;
- descriptor.size.width = width;
- descriptor.size.height = height;
- descriptor.size.depth = arrayLayerCount;
- descriptor.sampleCount = sampleCount;
- descriptor.format = format;
- descriptor.mipLevelCount = mipLevelCount;
- descriptor.usage = usage;
+ // Using BeginRenderPass with no attachments isn't valid
+ TEST_F(RenderPassDescriptorValidationTest, Empty) {
+ utils::ComboRenderPassDescriptor renderPass({}, nullptr);
+ AssertBeginRenderPassError(&renderPass);
+ }
- return device.CreateTexture(&descriptor);
-}
+ // A render pass with only one color or one depth attachment is ok
+ TEST_F(RenderPassDescriptorValidationTest, OneAttachment) {
+ // One color attachment
+ {
+ wgpu::TextureView color =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ utils::ComboRenderPassDescriptor renderPass({color});
-wgpu::TextureView Create2DAttachment(wgpu::Device& device,
- uint32_t width,
- uint32_t height,
- wgpu::TextureFormat format) {
- wgpu::Texture texture =
- CreateTexture(device, wgpu::TextureDimension::e2D, format, width, height, 1, 1);
- return texture.CreateView();
-}
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ // One depth-stencil attachment
+ {
+ wgpu::TextureView depthStencil =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencil);
-// Using BeginRenderPass with no attachments isn't valid
-TEST_F(RenderPassDescriptorValidationTest, Empty) {
- utils::ComboRenderPassDescriptor renderPass({}, nullptr);
- AssertBeginRenderPassError(&renderPass);
-}
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
-// A render pass with only one color or one depth attachment is ok
-TEST_F(RenderPassDescriptorValidationTest, OneAttachment) {
- // One color attachment
- {
+ // Test OOB color attachment indices are handled
+ TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentOutOfBounds) {
+ wgpu::TextureView color0 =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ wgpu::TextureView color1 =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ wgpu::TextureView color2 =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ wgpu::TextureView color3 =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ // For setting the color attachment, control case
+ {
+ utils::ComboRenderPassDescriptor renderPass({color0, color1, color2, color3});
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ // For setting the color attachment, OOB
+ {
+ // We cannot use utils::ComboRenderPassDescriptor here because it only supports at most
+ // kMaxColorAttachments(4) color attachments.
+ std::array<wgpu::RenderPassColorAttachmentDescriptor, 5> colorAttachments;
+ colorAttachments[0].attachment = color0;
+ colorAttachments[0].resolveTarget = nullptr;
+ colorAttachments[0].clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
+ colorAttachments[0].loadOp = wgpu::LoadOp::Clear;
+ colorAttachments[0].storeOp = wgpu::StoreOp::Store;
+
+ colorAttachments[1] = colorAttachments[0];
+ colorAttachments[1].attachment = color1;
+
+ colorAttachments[2] = colorAttachments[0];
+ colorAttachments[2].attachment = color2;
+
+ colorAttachments[3] = colorAttachments[0];
+ colorAttachments[3].attachment = color3;
+
+ colorAttachments[4] = colorAttachments[0];
+ colorAttachments[4].attachment =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+
+ wgpu::RenderPassDescriptor renderPass;
+ renderPass.colorAttachmentCount = 5;
+ renderPass.colorAttachments = colorAttachments.data();
+ renderPass.depthStencilAttachment = nullptr;
+ AssertBeginRenderPassError(&renderPass);
+ }
+ }
+
+ // Attachments must have the same size
+ TEST_F(RenderPassDescriptorValidationTest, SizeMustMatch) {
+ wgpu::TextureView color1x1A =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ wgpu::TextureView color1x1B =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+ wgpu::TextureView color2x2 =
+ Create2DAttachment(device, 2, 2, wgpu::TextureFormat::RGBA8Unorm);
+
+ wgpu::TextureView depthStencil1x1 =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8);
+ wgpu::TextureView depthStencil2x2 =
+ Create2DAttachment(device, 2, 2, wgpu::TextureFormat::Depth24PlusStencil8);
+
+ // Control case: all the same size (1x1)
+ {
+ utils::ComboRenderPassDescriptor renderPass({color1x1A, color1x1B}, depthStencil1x1);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // One of the color attachments has a different size
+ {
+ utils::ComboRenderPassDescriptor renderPass({color1x1A, color2x2});
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // The depth stencil attachment has a different size
+ {
+ utils::ComboRenderPassDescriptor renderPass({color1x1A, color1x1B}, depthStencil2x2);
+ AssertBeginRenderPassError(&renderPass);
+ }
+ }
+
+ // Attachments formats must match whether they are used for color or depth-stencil
+ TEST_F(RenderPassDescriptorValidationTest, FormatMismatch) {
wgpu::TextureView color = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- utils::ComboRenderPassDescriptor renderPass({color});
-
- AssertBeginRenderPassSuccess(&renderPass);
- }
- // One depth-stencil attachment
- {
wgpu::TextureView depthStencil =
Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencil);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
+ // Using depth-stencil for color
+ {
+ utils::ComboRenderPassDescriptor renderPass({depthStencil});
+ AssertBeginRenderPassError(&renderPass);
+ }
-// Test OOB color attachment indices are handled
-TEST_F(RenderPassDescriptorValidationTest, ColorAttachmentOutOfBounds) {
- wgpu::TextureView color0 = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView color1 = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView color2 = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView color3 = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- // For setting the color attachment, control case
- {
- utils::ComboRenderPassDescriptor renderPass({color0, color1, color2, color3});
- AssertBeginRenderPassSuccess(&renderPass);
- }
- // For setting the color attachment, OOB
- {
- // We cannot use utils::ComboRenderPassDescriptor here because it only supports at most
- // kMaxColorAttachments(4) color attachments.
- std::array<wgpu::RenderPassColorAttachmentDescriptor, 5> colorAttachments;
- colorAttachments[0].attachment = color0;
- colorAttachments[0].resolveTarget = nullptr;
- colorAttachments[0].clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
- colorAttachments[0].loadOp = wgpu::LoadOp::Clear;
- colorAttachments[0].storeOp = wgpu::StoreOp::Store;
-
- colorAttachments[1] = colorAttachments[0];
- colorAttachments[1].attachment = color1;
-
- colorAttachments[2] = colorAttachments[0];
- colorAttachments[2].attachment = color2;
-
- colorAttachments[3] = colorAttachments[0];
- colorAttachments[3].attachment = color3;
-
- colorAttachments[4] = colorAttachments[0];
- colorAttachments[4].attachment =
- Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
-
- wgpu::RenderPassDescriptor renderPass;
- renderPass.colorAttachmentCount = 5;
- renderPass.colorAttachments = colorAttachments.data();
- renderPass.depthStencilAttachment = nullptr;
- AssertBeginRenderPassError(&renderPass);
- }
-}
-
-// Attachments must have the same size
-TEST_F(RenderPassDescriptorValidationTest, SizeMustMatch) {
- wgpu::TextureView color1x1A = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView color1x1B = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView color2x2 = Create2DAttachment(device, 2, 2, wgpu::TextureFormat::RGBA8Unorm);
-
- wgpu::TextureView depthStencil1x1 =
- Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8);
- wgpu::TextureView depthStencil2x2 =
- Create2DAttachment(device, 2, 2, wgpu::TextureFormat::Depth24PlusStencil8);
-
- // Control case: all the same size (1x1)
- {
- utils::ComboRenderPassDescriptor renderPass({color1x1A, color1x1B}, depthStencil1x1);
- AssertBeginRenderPassSuccess(&renderPass);
+ // Using color for depth-stencil
+ {
+ utils::ComboRenderPassDescriptor renderPass({}, color);
+ AssertBeginRenderPassError(&renderPass);
+ }
}
- // One of the color attachments has a different size
- {
- utils::ComboRenderPassDescriptor renderPass({color1x1A, color2x2});
- AssertBeginRenderPassError(&renderPass);
- }
+ // Depth and stencil storeOps must match
+ TEST_F(RenderPassDescriptorValidationTest, DepthStencilStoreOpMismatch) {
+ constexpr uint32_t kArrayLayers = 1;
+ constexpr uint32_t kLevelCount = 1;
+ constexpr uint32_t kSize = 32;
+ constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
+ constexpr wgpu::TextureFormat kDepthStencilFormat =
+ wgpu::TextureFormat::Depth24PlusStencil8;
- // The depth stencil attachment has a different size
- {
- utils::ComboRenderPassDescriptor renderPass({color1x1A, color1x1B}, depthStencil2x2);
- AssertBeginRenderPassError(&renderPass);
- }
-}
-
-// Attachments formats must match whether they are used for color or depth-stencil
-TEST_F(RenderPassDescriptorValidationTest, FormatMismatch) {
- wgpu::TextureView color = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
- wgpu::TextureView depthStencil =
- Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8);
-
- // Using depth-stencil for color
- {
- utils::ComboRenderPassDescriptor renderPass({depthStencil});
- AssertBeginRenderPassError(&renderPass);
- }
-
- // Using color for depth-stencil
- {
- utils::ComboRenderPassDescriptor renderPass({}, color);
- AssertBeginRenderPassError(&renderPass);
- }
-}
-
-// Depth and stencil storeOps must match
-TEST_F(RenderPassDescriptorValidationTest, DepthStencilStoreOpMismatch) {
- constexpr uint32_t kArrayLayers = 1;
- constexpr uint32_t kLevelCount = 1;
- constexpr uint32_t kSize = 32;
- constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
- constexpr wgpu::TextureFormat kDepthStencilFormat = wgpu::TextureFormat::Depth24PlusStencil8;
-
- wgpu::Texture colorTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers, kLevelCount);
- wgpu::Texture depthStencilTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
- kArrayLayers, kLevelCount);
-
- wgpu::TextureViewDescriptor descriptor;
- descriptor.dimension = wgpu::TextureViewDimension::e2D;
- descriptor.baseArrayLayer = 0;
- descriptor.arrayLayerCount = kArrayLayers;
- descriptor.baseMipLevel = 0;
- descriptor.mipLevelCount = kLevelCount;
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
-
- // StoreOps mismatch causing the render pass to error
- {
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
- renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
- AssertBeginRenderPassError(&renderPass);
- }
-
- // StoreOps match so render pass is a success
- {
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
- renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // StoreOps match so render pass is a success
- {
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Clear;
- renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
-
-// Currently only texture views with arrayLayerCount == 1 are allowed to be color and depth stencil
-// attachments
-TEST_F(RenderPassDescriptorValidationTest, TextureViewLayerCountForColorAndDepthStencil) {
- constexpr uint32_t kLevelCount = 1;
- constexpr uint32_t kSize = 32;
- constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
- constexpr wgpu::TextureFormat kDepthStencilFormat = wgpu::TextureFormat::Depth24PlusStencil8;
-
- constexpr uint32_t kArrayLayers = 10;
-
- wgpu::Texture colorTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers, kLevelCount);
- wgpu::Texture depthStencilTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
- kArrayLayers, kLevelCount);
-
- wgpu::TextureViewDescriptor baseDescriptor;
- baseDescriptor.dimension = wgpu::TextureViewDimension::e2DArray;
- baseDescriptor.baseArrayLayer = 0;
- baseDescriptor.arrayLayerCount = kArrayLayers;
- baseDescriptor.baseMipLevel = 0;
- baseDescriptor.mipLevelCount = kLevelCount;
-
- // Using 2D array texture view with arrayLayerCount > 1 is not allowed for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.arrayLayerCount = 5;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassError(&renderPass);
- }
-
- // Using 2D array texture view with arrayLayerCount > 1 is not allowed for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.arrayLayerCount = 5;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassError(&renderPass);
- }
-
- // Using 2D array texture view that covers the first layer of the texture is OK for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.baseArrayLayer = 0;
- descriptor.arrayLayerCount = 1;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D array texture view that covers the first layer is OK for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.baseArrayLayer = 0;
- descriptor.arrayLayerCount = 1;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D array texture view that covers the last layer is OK for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.baseArrayLayer = kArrayLayers - 1;
- descriptor.arrayLayerCount = 1;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D array texture view that covers the last layer is OK for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.baseArrayLayer = kArrayLayers - 1;
- descriptor.arrayLayerCount = 1;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
-
-// Only 2D texture views with mipLevelCount == 1 are allowed to be color attachments
-TEST_F(RenderPassDescriptorValidationTest, TextureViewLevelCountForColorAndDepthStencil) {
- constexpr uint32_t kArrayLayers = 1;
- constexpr uint32_t kSize = 32;
- constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
- constexpr wgpu::TextureFormat kDepthStencilFormat = wgpu::TextureFormat::Depth24PlusStencil8;
-
- constexpr uint32_t kLevelCount = 4;
-
- wgpu::Texture colorTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers, kLevelCount);
- wgpu::Texture depthStencilTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
- kArrayLayers, kLevelCount);
-
- wgpu::TextureViewDescriptor baseDescriptor;
- baseDescriptor.dimension = wgpu::TextureViewDimension::e2D;
- baseDescriptor.baseArrayLayer = 0;
- baseDescriptor.arrayLayerCount = kArrayLayers;
- baseDescriptor.baseMipLevel = 0;
- baseDescriptor.mipLevelCount = kLevelCount;
-
- // Using 2D texture view with mipLevelCount > 1 is not allowed for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.mipLevelCount = 2;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassError(&renderPass);
- }
-
- // Using 2D texture view with mipLevelCount > 1 is not allowed for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.mipLevelCount = 2;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassError(&renderPass);
- }
-
- // Using 2D texture view that covers the first level of the texture is OK for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.baseMipLevel = 0;
- descriptor.mipLevelCount = 1;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D texture view that covers the first level is OK for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.baseMipLevel = 0;
- descriptor.mipLevelCount = 1;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D texture view that covers the last level is OK for color
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kColorFormat;
- descriptor.baseMipLevel = kLevelCount - 1;
- descriptor.mipLevelCount = 1;
-
- wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Using 2D texture view that covers the last level is OK for depth stencil
- {
- wgpu::TextureViewDescriptor descriptor = baseDescriptor;
- descriptor.format = kDepthStencilFormat;
- descriptor.baseMipLevel = kLevelCount - 1;
- descriptor.mipLevelCount = 1;
-
- wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
- utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
-
-// It is not allowed to set resolve target when the color attachment is non-multisampled.
-TEST_F(RenderPassDescriptorValidationTest, NonMultisampledColorWithResolveTarget) {
- static constexpr uint32_t kArrayLayers = 1;
- static constexpr uint32_t kLevelCount = 1;
- static constexpr uint32_t kSize = 32;
- static constexpr uint32_t kSampleCount = 1;
- static constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
-
- wgpu::Texture colorTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize, kArrayLayers,
- kLevelCount, kSampleCount);
- wgpu::Texture resolveTargetTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize, kArrayLayers,
- kLevelCount, kSampleCount);
- wgpu::TextureView colorTextureView = colorTexture.CreateView();
- wgpu::TextureView resolveTargetTextureView = resolveTargetTexture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass({colorTextureView});
- renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-class MultisampledRenderPassDescriptorValidationTest : public RenderPassDescriptorValidationTest {
- public:
- utils::ComboRenderPassDescriptor CreateMultisampledRenderPass() {
- return utils::ComboRenderPassDescriptor({CreateMultisampledColorTextureView()});
- }
-
- wgpu::TextureView CreateMultisampledColorTextureView() {
- return CreateColorTextureView(kSampleCount);
- }
-
- wgpu::TextureView CreateNonMultisampledColorTextureView() {
- return CreateColorTextureView(1);
- }
-
- static constexpr uint32_t kArrayLayers = 1;
- static constexpr uint32_t kLevelCount = 1;
- static constexpr uint32_t kSize = 32;
- static constexpr uint32_t kSampleCount = 4;
- static constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
-
- private:
- wgpu::TextureView CreateColorTextureView(uint32_t sampleCount) {
wgpu::Texture colorTexture =
CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
- kArrayLayers, kLevelCount, sampleCount);
-
- return colorTexture.CreateView();
- }
-};
-
-// Tests on the use of multisampled textures as color attachments
-TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorAttachments) {
- wgpu::TextureView colorTextureView = CreateNonMultisampledColorTextureView();
- wgpu::TextureView resolveTargetTextureView = CreateNonMultisampledColorTextureView();
- wgpu::TextureView multisampledColorTextureView = CreateMultisampledColorTextureView();
-
- // It is allowed to use a multisampled color attachment without setting resolve target.
- {
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // It is not allowed to use multiple color attachments with different sample counts.
- {
- utils::ComboRenderPassDescriptor renderPass(
- {multisampledColorTextureView, colorTextureView});
- AssertBeginRenderPassError(&renderPass);
- }
-}
-
-// It is not allowed to use a multisampled resolve target.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledResolveTarget) {
- wgpu::TextureView multisampledResolveTargetView = CreateMultisampledColorTextureView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = multisampledResolveTargetView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// It is not allowed to use a resolve target with array layer count > 1.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetArrayLayerMoreThanOne) {
- constexpr uint32_t kArrayLayers2 = 2;
- wgpu::Texture resolveTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers2, kLevelCount);
- wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// It is not allowed to use a resolve target with mipmap level count > 1.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetMipmapLevelMoreThanOne) {
- constexpr uint32_t kLevelCount2 = 2;
- wgpu::Texture resolveTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers, kLevelCount2);
- wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// It is not allowed to use a resolve target which is created from a texture whose usage does not
-// include wgpu::TextureUsage::OutputAttachment.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetUsageNoOutputAttachment) {
- constexpr wgpu::TextureUsage kUsage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
- wgpu::Texture nonColorUsageResolveTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize, kArrayLayers,
- kLevelCount, 1, kUsage);
- wgpu::TextureView nonColorUsageResolveTextureView = nonColorUsageResolveTexture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = nonColorUsageResolveTextureView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// It is not allowed to use a resolve target which is in error state.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetInErrorState) {
- wgpu::Texture resolveTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize, kSize, kArrayLayers, kLevelCount);
- wgpu::TextureViewDescriptor errorTextureView;
- errorTextureView.dimension = wgpu::TextureViewDimension::e2D;
- errorTextureView.format = kColorFormat;
- errorTextureView.baseArrayLayer = kArrayLayers + 1;
- ASSERT_DEVICE_ERROR(wgpu::TextureView errorResolveTarget =
- resolveTexture.CreateView(&errorTextureView));
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = errorResolveTarget;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// It is allowed to use a multisampled color attachment and a non-multisampled resolve target.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorWithResolveTarget) {
- wgpu::TextureView resolveTargetTextureView = CreateNonMultisampledColorTextureView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView;
- AssertBeginRenderPassSuccess(&renderPass);
-}
-
-// It is not allowed to use a resolve target in a format different from the color attachment.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetDifferentFormat) {
- constexpr wgpu::TextureFormat kColorFormat2 = wgpu::TextureFormat::BGRA8Unorm;
- wgpu::Texture resolveTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat2,
- kSize, kSize, kArrayLayers, kLevelCount);
- wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
- AssertBeginRenderPassError(&renderPass);
-}
-
-// Tests on the size of the resolve target.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, ColorAttachmentResolveTargetCompatibility) {
- constexpr uint32_t kSize2 = kSize * 2;
- wgpu::Texture resolveTexture = CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat,
- kSize2, kSize2, kArrayLayers, kLevelCount + 1);
-
- wgpu::TextureViewDescriptor textureViewDescriptor;
- textureViewDescriptor.nextInChain = nullptr;
- textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
- textureViewDescriptor.format = kColorFormat;
- textureViewDescriptor.mipLevelCount = 1;
- textureViewDescriptor.baseArrayLayer = 0;
- textureViewDescriptor.arrayLayerCount = 1;
-
- {
- wgpu::TextureViewDescriptor firstMipLevelDescriptor = textureViewDescriptor;
- firstMipLevelDescriptor.baseMipLevel = 0;
-
- wgpu::TextureView resolveTextureView = resolveTexture.CreateView(&firstMipLevelDescriptor);
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
- AssertBeginRenderPassError(&renderPass);
- }
-
- {
- wgpu::TextureViewDescriptor secondMipLevelDescriptor = textureViewDescriptor;
- secondMipLevelDescriptor.baseMipLevel = 1;
-
- wgpu::TextureView resolveTextureView = resolveTexture.CreateView(&secondMipLevelDescriptor);
-
- utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
- renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
-
-// Tests on the sample count of depth stencil attachment.
-TEST_F(MultisampledRenderPassDescriptorValidationTest, DepthStencilAttachmentSampleCount) {
- constexpr wgpu::TextureFormat kDepthStencilFormat = wgpu::TextureFormat::Depth24PlusStencil8;
- wgpu::Texture multisampledDepthStencilTexture =
- CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
- kArrayLayers, kLevelCount, kSampleCount);
- wgpu::TextureView multisampledDepthStencilTextureView =
- multisampledDepthStencilTexture.CreateView();
-
- // It is not allowed to use a depth stencil attachment whose sample count is different from the
- // one of the color attachment.
- {
+ kArrayLayers, kLevelCount);
wgpu::Texture depthStencilTexture =
CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
kArrayLayers, kLevelCount);
- wgpu::TextureView depthStencilTextureView = depthStencilTexture.CreateView();
- utils::ComboRenderPassDescriptor renderPass(
- {CreateMultisampledColorTextureView()}, depthStencilTextureView);
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::e2D;
+ descriptor.baseArrayLayer = 0;
+ descriptor.arrayLayerCount = kArrayLayers;
+ descriptor.baseMipLevel = 0;
+ descriptor.mipLevelCount = kLevelCount;
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+
+ // StoreOps mismatch causing the render pass to error
+ {
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
+ renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // StoreOps match so render pass is a success
+ {
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Store;
+ renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Store;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // StoreOps match so render pass is a success
+ {
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ renderPass.cDepthStencilAttachmentInfo.stencilStoreOp = wgpu::StoreOp::Clear;
+ renderPass.cDepthStencilAttachmentInfo.depthStoreOp = wgpu::StoreOp::Clear;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
+
+ // Currently only texture views with arrayLayerCount == 1 are allowed to be color and depth
+ // stencil attachments
+ TEST_F(RenderPassDescriptorValidationTest, TextureViewLayerCountForColorAndDepthStencil) {
+ constexpr uint32_t kLevelCount = 1;
+ constexpr uint32_t kSize = 32;
+ constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
+ constexpr wgpu::TextureFormat kDepthStencilFormat =
+ wgpu::TextureFormat::Depth24PlusStencil8;
+
+ constexpr uint32_t kArrayLayers = 10;
+
+ wgpu::Texture colorTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount);
+ wgpu::Texture depthStencilTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
+ kArrayLayers, kLevelCount);
+
+ wgpu::TextureViewDescriptor baseDescriptor;
+ baseDescriptor.dimension = wgpu::TextureViewDimension::e2DArray;
+ baseDescriptor.baseArrayLayer = 0;
+ baseDescriptor.arrayLayerCount = kArrayLayers;
+ baseDescriptor.baseMipLevel = 0;
+ baseDescriptor.mipLevelCount = kLevelCount;
+
+ // Using 2D array texture view with arrayLayerCount > 1 is not allowed for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.arrayLayerCount = 5;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Using 2D array texture view with arrayLayerCount > 1 is not allowed for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.arrayLayerCount = 5;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Using 2D array texture view that covers the first layer of the texture is OK for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.baseArrayLayer = 0;
+ descriptor.arrayLayerCount = 1;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D array texture view that covers the first layer is OK for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.baseArrayLayer = 0;
+ descriptor.arrayLayerCount = 1;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D array texture view that covers the last layer is OK for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.baseArrayLayer = kArrayLayers - 1;
+ descriptor.arrayLayerCount = 1;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D array texture view that covers the last layer is OK for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.baseArrayLayer = kArrayLayers - 1;
+ descriptor.arrayLayerCount = 1;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
+
+ // Only 2D texture views with mipLevelCount == 1 are allowed to be color attachments
+ TEST_F(RenderPassDescriptorValidationTest, TextureViewLevelCountForColorAndDepthStencil) {
+ constexpr uint32_t kArrayLayers = 1;
+ constexpr uint32_t kSize = 32;
+ constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
+ constexpr wgpu::TextureFormat kDepthStencilFormat =
+ wgpu::TextureFormat::Depth24PlusStencil8;
+
+ constexpr uint32_t kLevelCount = 4;
+
+ wgpu::Texture colorTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount);
+ wgpu::Texture depthStencilTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
+ kArrayLayers, kLevelCount);
+
+ wgpu::TextureViewDescriptor baseDescriptor;
+ baseDescriptor.dimension = wgpu::TextureViewDimension::e2D;
+ baseDescriptor.baseArrayLayer = 0;
+ baseDescriptor.arrayLayerCount = kArrayLayers;
+ baseDescriptor.baseMipLevel = 0;
+ baseDescriptor.mipLevelCount = kLevelCount;
+
+ // Using 2D texture view with mipLevelCount > 1 is not allowed for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.mipLevelCount = 2;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Using 2D texture view with mipLevelCount > 1 is not allowed for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.mipLevelCount = 2;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Using 2D texture view that covers the first level of the texture is OK for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.baseMipLevel = 0;
+ descriptor.mipLevelCount = 1;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D texture view that covers the first level is OK for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.baseMipLevel = 0;
+ descriptor.mipLevelCount = 1;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D texture view that covers the last level is OK for color
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kColorFormat;
+ descriptor.baseMipLevel = kLevelCount - 1;
+ descriptor.mipLevelCount = 1;
+
+ wgpu::TextureView colorTextureView = colorTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Using 2D texture view that covers the last level is OK for depth stencil
+ {
+ wgpu::TextureViewDescriptor descriptor = baseDescriptor;
+ descriptor.format = kDepthStencilFormat;
+ descriptor.baseMipLevel = kLevelCount - 1;
+ descriptor.mipLevelCount = 1;
+
+ wgpu::TextureView depthStencilView = depthStencilTexture.CreateView(&descriptor);
+ utils::ComboRenderPassDescriptor renderPass({}, depthStencilView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
+
+ // It is not allowed to set resolve target when the color attachment is non-multisampled.
+ TEST_F(RenderPassDescriptorValidationTest, NonMultisampledColorWithResolveTarget) {
+ static constexpr uint32_t kArrayLayers = 1;
+ static constexpr uint32_t kLevelCount = 1;
+ static constexpr uint32_t kSize = 32;
+ static constexpr uint32_t kSampleCount = 1;
+ static constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
+
+ wgpu::Texture colorTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount, kSampleCount);
+ wgpu::Texture resolveTargetTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount, kSampleCount);
+ wgpu::TextureView colorTextureView = colorTexture.CreateView();
+ wgpu::TextureView resolveTargetTextureView = resolveTargetTexture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass({colorTextureView});
+ renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView;
AssertBeginRenderPassError(&renderPass);
}
- {
- utils::ComboRenderPassDescriptor renderPass(
- {CreateNonMultisampledColorTextureView()}, multisampledDepthStencilTextureView);
+ class MultisampledRenderPassDescriptorValidationTest
+ : public RenderPassDescriptorValidationTest {
+ public:
+ utils::ComboRenderPassDescriptor CreateMultisampledRenderPass() {
+ return utils::ComboRenderPassDescriptor({CreateMultisampledColorTextureView()});
+ }
+
+ wgpu::TextureView CreateMultisampledColorTextureView() {
+ return CreateColorTextureView(kSampleCount);
+ }
+
+ wgpu::TextureView CreateNonMultisampledColorTextureView() {
+ return CreateColorTextureView(1);
+ }
+
+ static constexpr uint32_t kArrayLayers = 1;
+ static constexpr uint32_t kLevelCount = 1;
+ static constexpr uint32_t kSize = 32;
+ static constexpr uint32_t kSampleCount = 4;
+ static constexpr wgpu::TextureFormat kColorFormat = wgpu::TextureFormat::RGBA8Unorm;
+
+ private:
+ wgpu::TextureView CreateColorTextureView(uint32_t sampleCount) {
+ wgpu::Texture colorTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount, sampleCount);
+
+ return colorTexture.CreateView();
+ }
+ };
+
+ // Tests on the use of multisampled textures as color attachments
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorAttachments) {
+ wgpu::TextureView colorTextureView = CreateNonMultisampledColorTextureView();
+ wgpu::TextureView resolveTargetTextureView = CreateNonMultisampledColorTextureView();
+ wgpu::TextureView multisampledColorTextureView = CreateMultisampledColorTextureView();
+
+ // It is allowed to use a multisampled color attachment without setting resolve target.
+ {
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // It is not allowed to use multiple color attachments with different sample counts.
+ {
+ utils::ComboRenderPassDescriptor renderPass(
+ {multisampledColorTextureView, colorTextureView});
+ AssertBeginRenderPassError(&renderPass);
+ }
+ }
+
+ // It is not allowed to use a multisampled resolve target.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledResolveTarget) {
+ wgpu::TextureView multisampledResolveTargetView = CreateMultisampledColorTextureView();
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = multisampledResolveTargetView;
AssertBeginRenderPassError(&renderPass);
}
- // It is allowed to use a multisampled depth stencil attachment whose sample count is equal to
- // the one of the color attachment.
- {
- utils::ComboRenderPassDescriptor renderPass(
- {CreateMultisampledColorTextureView()}, multisampledDepthStencilTextureView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
+ // It is not allowed to use a resolve target with array layer count > 1.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetArrayLayerMoreThanOne) {
+ constexpr uint32_t kArrayLayers2 = 2;
+ wgpu::Texture resolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers2, kLevelCount);
+ wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
- // It is allowed to use a multisampled depth stencil attachment while there is no color
- // attachment.
- {
- utils::ComboRenderPassDescriptor renderPass({}, multisampledDepthStencilTextureView);
- AssertBeginRenderPassSuccess(&renderPass);
- }
-}
-
-// Tests that NaN cannot be accepted as a valid color or depth clear value and INFINITY is valid in
-// both color and depth clear values.
-TEST_F(RenderPassDescriptorValidationTest, UseNaNOrINFINITYAsColorOrDepthClearValue) {
- wgpu::TextureView color = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
-
- // Tests that NaN cannot be used in clearColor.
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.r = NAN;
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
AssertBeginRenderPassError(&renderPass);
}
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.g = NAN;
+ // It is not allowed to use a resolve target with mipmap level count > 1.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetMipmapLevelMoreThanOne) {
+ constexpr uint32_t kLevelCount2 = 2;
+ wgpu::Texture resolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount2);
+ wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
AssertBeginRenderPassError(&renderPass);
}
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.b = NAN;
+ // It is not allowed to use a resolve target which is created from a texture whose usage does
+ // not include wgpu::TextureUsage::OutputAttachment.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetUsageNoOutputAttachment) {
+ constexpr wgpu::TextureUsage kUsage =
+ wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
+ wgpu::Texture nonColorUsageResolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount, 1, kUsage);
+ wgpu::TextureView nonColorUsageResolveTextureView =
+ nonColorUsageResolveTexture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = nonColorUsageResolveTextureView;
AssertBeginRenderPassError(&renderPass);
}
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.a = NAN;
+ // It is not allowed to use a resolve target which is in error state.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetInErrorState) {
+ wgpu::Texture resolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize, kSize,
+ kArrayLayers, kLevelCount);
+ wgpu::TextureViewDescriptor errorTextureView;
+ errorTextureView.dimension = wgpu::TextureViewDimension::e2D;
+ errorTextureView.format = kColorFormat;
+ errorTextureView.baseArrayLayer = kArrayLayers + 1;
+ ASSERT_DEVICE_ERROR(wgpu::TextureView errorResolveTarget =
+ resolveTexture.CreateView(&errorTextureView));
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = errorResolveTarget;
AssertBeginRenderPassError(&renderPass);
}
- // Tests that INFINITY can be used in clearColor.
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.r = INFINITY;
+ // It is allowed to use a multisampled color attachment and a non-multisampled resolve target.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, MultisampledColorWithResolveTarget) {
+ wgpu::TextureView resolveTargetTextureView = CreateNonMultisampledColorTextureView();
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTargetTextureView;
AssertBeginRenderPassSuccess(&renderPass);
}
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.g = INFINITY;
- AssertBeginRenderPassSuccess(&renderPass);
- }
+ // It is not allowed to use a resolve target in a format different from the color attachment.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, ResolveTargetDifferentFormat) {
+ constexpr wgpu::TextureFormat kColorFormat2 = wgpu::TextureFormat::BGRA8Unorm;
+ wgpu::Texture resolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat2, kSize, kSize,
+ kArrayLayers, kLevelCount);
+ wgpu::TextureView resolveTextureView = resolveTexture.CreateView();
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.b = INFINITY;
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- {
- utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
- renderPass.cColorAttachments[0].clearColor.a = INFINITY;
- AssertBeginRenderPassSuccess(&renderPass);
- }
-
- // Tests that NaN cannot be used in clearDepth.
- {
- wgpu::TextureView depth =
- Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24Plus);
- utils::ComboRenderPassDescriptor renderPass({color}, depth);
- renderPass.cDepthStencilAttachmentInfo.clearDepth = NAN;
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
AssertBeginRenderPassError(&renderPass);
}
- // Tests that INFINITY can be used in clearDepth.
- {
- wgpu::TextureView depth =
- Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24Plus);
- utils::ComboRenderPassDescriptor renderPass({color}, depth);
- renderPass.cDepthStencilAttachmentInfo.clearDepth = INFINITY;
- AssertBeginRenderPassSuccess(&renderPass);
+ // Tests on the size of the resolve target.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest,
+ ColorAttachmentResolveTargetCompatibility) {
+ constexpr uint32_t kSize2 = kSize * 2;
+ wgpu::Texture resolveTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kColorFormat, kSize2, kSize2,
+ kArrayLayers, kLevelCount + 1);
+
+ wgpu::TextureViewDescriptor textureViewDescriptor;
+ textureViewDescriptor.nextInChain = nullptr;
+ textureViewDescriptor.dimension = wgpu::TextureViewDimension::e2D;
+ textureViewDescriptor.format = kColorFormat;
+ textureViewDescriptor.mipLevelCount = 1;
+ textureViewDescriptor.baseArrayLayer = 0;
+ textureViewDescriptor.arrayLayerCount = 1;
+
+ {
+ wgpu::TextureViewDescriptor firstMipLevelDescriptor = textureViewDescriptor;
+ firstMipLevelDescriptor.baseMipLevel = 0;
+
+ wgpu::TextureView resolveTextureView =
+ resolveTexture.CreateView(&firstMipLevelDescriptor);
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ {
+ wgpu::TextureViewDescriptor secondMipLevelDescriptor = textureViewDescriptor;
+ secondMipLevelDescriptor.baseMipLevel = 1;
+
+ wgpu::TextureView resolveTextureView =
+ resolveTexture.CreateView(&secondMipLevelDescriptor);
+
+ utils::ComboRenderPassDescriptor renderPass = CreateMultisampledRenderPass();
+ renderPass.cColorAttachments[0].resolveTarget = resolveTextureView;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
}
-}
-// TODO(cwallez@chromium.org): Constraints on attachment aliasing?
+ // Tests on the sample count of depth stencil attachment.
+ TEST_F(MultisampledRenderPassDescriptorValidationTest, DepthStencilAttachmentSampleCount) {
+ constexpr wgpu::TextureFormat kDepthStencilFormat =
+ wgpu::TextureFormat::Depth24PlusStencil8;
+ wgpu::Texture multisampledDepthStencilTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize, kSize,
+ kArrayLayers, kLevelCount, kSampleCount);
+ wgpu::TextureView multisampledDepthStencilTextureView =
+ multisampledDepthStencilTexture.CreateView();
-} // anonymous namespace
+ // It is not allowed to use a depth stencil attachment whose sample count is different from
+ // the one of the color attachment.
+ {
+ wgpu::Texture depthStencilTexture =
+ CreateTexture(device, wgpu::TextureDimension::e2D, kDepthStencilFormat, kSize,
+ kSize, kArrayLayers, kLevelCount);
+ wgpu::TextureView depthStencilTextureView = depthStencilTexture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass({CreateMultisampledColorTextureView()},
+ depthStencilTextureView);
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({CreateNonMultisampledColorTextureView()},
+ multisampledDepthStencilTextureView);
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // It is allowed to use a multisampled depth stencil attachment whose sample count is equal
+ // to the one of the color attachment.
+ {
+ utils::ComboRenderPassDescriptor renderPass({CreateMultisampledColorTextureView()},
+ multisampledDepthStencilTextureView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // It is allowed to use a multisampled depth stencil attachment while there is no color
+ // attachment.
+ {
+ utils::ComboRenderPassDescriptor renderPass({}, multisampledDepthStencilTextureView);
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
+
+ // Tests that NaN cannot be accepted as a valid color or depth clear value and INFINITY is valid
+ // in both color and depth clear values.
+ TEST_F(RenderPassDescriptorValidationTest, UseNaNOrINFINITYAsColorOrDepthClearValue) {
+ wgpu::TextureView color = Create2DAttachment(device, 1, 1, wgpu::TextureFormat::RGBA8Unorm);
+
+ // Tests that NaN cannot be used in clearColor.
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.r = NAN;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.g = NAN;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.b = NAN;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.a = NAN;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Tests that INFINITY can be used in clearColor.
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.r = INFINITY;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.g = INFINITY;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.b = INFINITY;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ {
+ utils::ComboRenderPassDescriptor renderPass({color}, nullptr);
+ renderPass.cColorAttachments[0].clearColor.a = INFINITY;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+
+ // Tests that NaN cannot be used in clearDepth.
+ {
+ wgpu::TextureView depth =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24Plus);
+ utils::ComboRenderPassDescriptor renderPass({color}, depth);
+ renderPass.cDepthStencilAttachmentInfo.clearDepth = NAN;
+ AssertBeginRenderPassError(&renderPass);
+ }
+
+ // Tests that INFINITY can be used in clearDepth.
+ {
+ wgpu::TextureView depth =
+ Create2DAttachment(device, 1, 1, wgpu::TextureFormat::Depth24Plus);
+ utils::ComboRenderPassDescriptor renderPass({color}, depth);
+ renderPass.cDepthStencilAttachmentInfo.clearDepth = INFINITY;
+ AssertBeginRenderPassSuccess(&renderPass);
+ }
+ }
+
+ // TODO(cwallez@chromium.org): Constraints on attachment aliasing?
+
+} // anonymous namespace
diff --git a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
index 867cd11..19cc817 100644
--- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
+++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp
@@ -22,26 +22,26 @@
#include <sstream>
class RenderPipelineValidationTest : public ValidationTest {
- protected:
- void SetUp() override {
- ValidationTest::SetUp();
+ protected:
+ void SetUp() override {
+ ValidationTest::SetUp();
- vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
+ vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"(
#version 450
void main() {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
})");
- fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
- }
+ }
- wgpu::ShaderModule vsModule;
- wgpu::ShaderModule fsModule;
+ wgpu::ShaderModule vsModule;
+ wgpu::ShaderModule fsModule;
};
// Test cases where creation should succeed
diff --git a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp
index bb08ecc..1e570eb 100644
--- a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp
+++ b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp
@@ -20,8 +20,7 @@
#include <sstream>
-class ShaderModuleValidationTest : public ValidationTest {
-};
+class ShaderModuleValidationTest : public ValidationTest {};
// Test case with a simpler shader that should successfully be created
TEST_F(ShaderModuleValidationTest, CreationSuccess) {
@@ -112,8 +111,8 @@
// Test that it is invalid to create a shader module with no chained descriptor. (It must be
// WGSL or SPIRV, not empty)
TEST_F(ShaderModuleValidationTest, NoChainedDescriptor) {
- wgpu::ShaderModuleDescriptor desc = {};
- ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc));
+ wgpu::ShaderModuleDescriptor desc = {};
+ ASSERT_DEVICE_ERROR(device.CreateShaderModule(&desc));
}
// Test that it is not allowed to use combined texture and sampler.
diff --git a/src/tests/unittests/validation/TextureValidationTests.cpp b/src/tests/unittests/validation/TextureValidationTests.cpp
index c3d9612..52dc159 100644
--- a/src/tests/unittests/validation/TextureValidationTests.cpp
+++ b/src/tests/unittests/validation/TextureValidationTests.cpp
@@ -21,474 +21,476 @@
namespace {
-class TextureValidationTest : public ValidationTest {
- protected:
- void SetUp() override {
- queue = device.GetDefaultQueue();
- }
+ class TextureValidationTest : public ValidationTest {
+ protected:
+ void SetUp() override {
+ queue = device.GetDefaultQueue();
+ }
- wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
- wgpu::TextureDescriptor descriptor;
- descriptor.size.width = kWidth;
- descriptor.size.height = kHeight;
- descriptor.size.depth = kDefaultDepth;
- descriptor.mipLevelCount = kDefaultMipLevels;
- descriptor.sampleCount = kDefaultSampleCount;
- descriptor.dimension = wgpu::TextureDimension::e2D;
- descriptor.format = kDefaultTextureFormat;
- descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::Sampled;
- return descriptor;
- }
+ wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
+ wgpu::TextureDescriptor descriptor;
+ descriptor.size.width = kWidth;
+ descriptor.size.height = kHeight;
+ descriptor.size.depth = kDefaultDepth;
+ descriptor.mipLevelCount = kDefaultMipLevels;
+ descriptor.sampleCount = kDefaultSampleCount;
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.format = kDefaultTextureFormat;
+ descriptor.usage = wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::Sampled;
+ return descriptor;
+ }
- wgpu::Queue queue;
+ wgpu::Queue queue;
- private:
- static constexpr uint32_t kWidth = 32;
- static constexpr uint32_t kHeight = 32;
- static constexpr uint32_t kDefaultDepth = 1;
- static constexpr uint32_t kDefaultMipLevels = 1;
- static constexpr uint32_t kDefaultSampleCount = 1;
+ private:
+ static constexpr uint32_t kWidth = 32;
+ static constexpr uint32_t kHeight = 32;
+ static constexpr uint32_t kDefaultDepth = 1;
+ static constexpr uint32_t kDefaultMipLevels = 1;
+ static constexpr uint32_t kDefaultSampleCount = 1;
- static constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
-};
-
-// Test the validation of sample count
-TEST_F(TextureValidationTest, SampleCount) {
- wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
-
- // sampleCount == 1 is allowed.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 1;
-
- device.CreateTexture(&descriptor);
- }
-
- // sampleCount == 4 is allowed.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 4;
-
- device.CreateTexture(&descriptor);
- }
-
- // It is an error to create a texture with an invalid sampleCount.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 3;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // It is an error to create a multisampled texture with mipLevelCount > 1.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 4;
- descriptor.mipLevelCount = 2;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Currently we do not support multisampled 2D array textures.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 4;
- descriptor.size.depth = 2;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // It is an error to set TextureUsage::Storage when sampleCount > 1.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.sampleCount = 4;
- descriptor.usage |= wgpu::TextureUsage::Storage;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-}
-
-// Test the validation of the mip level count
-TEST_F(TextureValidationTest, MipLevelCount) {
- wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
-
- // mipLevelCount == 1 is allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 32;
- descriptor.mipLevelCount = 1;
-
- device.CreateTexture(&descriptor);
- }
-
- // mipLevelCount == 0 is an error
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 32;
- descriptor.mipLevelCount = 0;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Full mip chains are allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 32;
- // Mip level sizes: 32, 16, 8, 4, 2, 1
- descriptor.mipLevelCount = 6;
-
- device.CreateTexture(&descriptor);
- }
-
- // Too big mip chains on width are disallowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 31;
- descriptor.size.height = 32;
- // Mip level width: 31, 15, 7, 3, 1, 1
- descriptor.mipLevelCount = 7;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Too big mip chains on height are disallowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 31;
- // Mip level height: 31, 15, 7, 3, 1, 1
- descriptor.mipLevelCount = 7;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Undefined shift check if miplevel is bigger than the integer bit width.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 32;
- descriptor.mipLevelCount = 100;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Non square mip map halves the resolution until a 1x1 dimension.
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 32;
- descriptor.size.height = 8;
- // Mip maps: 32 * 8, 16 * 4, 8 * 2, 4 * 1, 2 * 1, 1 * 1
- descriptor.mipLevelCount = 6;
-
- device.CreateTexture(&descriptor);
- }
-
- // Mip level exceeding kMaxTexture2DMipLevels not allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = 1 >> kMaxTexture2DMipLevels;
- descriptor.size.height = 1 >> kMaxTexture2DMipLevels;
- descriptor.mipLevelCount = kMaxTexture2DMipLevels + 1u;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-}
-// Test the validation of array layer count
-TEST_F(TextureValidationTest, ArrayLayerCount) {
- wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
-
- // Array layer count exceeding kMaxTexture2DArrayLayers is not allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.depth = kMaxTexture2DArrayLayers + 1u;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Array layer count less than kMaxTexture2DArrayLayers is allowed;
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.depth = kMaxTexture2DArrayLayers >> 1;
-
- device.CreateTexture(&descriptor);
- }
-
- // Array layer count equal to kMaxTexture2DArrayLayers is allowed;
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.depth = kMaxTexture2DArrayLayers;
-
- device.CreateTexture(&descriptor);
- }
-}
-
-// Test the validation of texture size
-TEST_F(TextureValidationTest, TextureSize) {
- wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
-
- // Texture size exceeding kMaxTextureSize is not allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = kMaxTextureSize + 1u;
- descriptor.size.height = kMaxTextureSize + 1u;
-
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-
- // Texture size less than kMaxTextureSize is allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = kMaxTextureSize >> 1;
- descriptor.size.height = kMaxTextureSize >> 1;
-
- device.CreateTexture(&descriptor);
- }
-
- // Texture equal to kMaxTextureSize is allowed
- {
- wgpu::TextureDescriptor descriptor = defaultDescriptor;
- descriptor.size.width = kMaxTextureSize;
- descriptor.size.height = kMaxTextureSize;
-
- device.CreateTexture(&descriptor);
- }
-}
-
-// Test that it is valid to destroy a texture
-TEST_F(TextureValidationTest, DestroyTexture) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- wgpu::Texture texture = device.CreateTexture(&descriptor);
- texture.Destroy();
-}
-
-// Test that it's valid to destroy a destroyed texture
-TEST_F(TextureValidationTest, DestroyDestroyedTexture) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- wgpu::Texture texture = device.CreateTexture(&descriptor);
- texture.Destroy();
- texture.Destroy();
-}
-
-// Test that it's invalid to submit a destroyed texture in a queue
-// in the case of destroy, encode, submit
-TEST_F(TextureValidationTest, DestroyEncodeSubmit) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- wgpu::Texture texture = device.CreateTexture(&descriptor);
- wgpu::TextureView textureView = texture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass({textureView});
-
- // Destroy the texture
- texture.Destroy();
-
- wgpu::CommandEncoder encoder_post_destroy = device.CreateCommandEncoder();
- {
- wgpu::RenderPassEncoder pass = encoder_post_destroy.BeginRenderPass(&renderPass);
- pass.EndPass();
- }
- wgpu::CommandBuffer commands = encoder_post_destroy.Finish();
-
- // Submit should fail due to destroyed texture
- ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
-}
-
-// Test that it's invalid to submit a destroyed texture in a queue
-// in the case of encode, destroy, submit
-TEST_F(TextureValidationTest, EncodeDestroySubmit) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- wgpu::Texture texture = device.CreateTexture(&descriptor);
- wgpu::TextureView textureView = texture.CreateView();
-
- utils::ComboRenderPassDescriptor renderPass({textureView});
-
- wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
- {
- wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
- pass.EndPass();
- }
- wgpu::CommandBuffer commands = encoder.Finish();
-
- // Destroy the texture
- texture.Destroy();
-
- // Submit should fail due to destroyed texture
- ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
-}
-
-// Test it is an error to create an OutputAttachment texture with a non-renderable format.
-TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
- wgpu::TextureDescriptor descriptor;
- descriptor.size = {1, 1, 1};
- descriptor.usage = wgpu::TextureUsage::OutputAttachment;
-
- // Succeeds because RGBA8Unorm is renderable
- descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- device.CreateTexture(&descriptor);
-
- wgpu::TextureFormat nonRenderableFormats[] = {
- wgpu::TextureFormat::RG11B10Float,
- wgpu::TextureFormat::R8Snorm,
- wgpu::TextureFormat::RG8Snorm,
- wgpu::TextureFormat::RGBA8Snorm,
+ static constexpr wgpu::TextureFormat kDefaultTextureFormat =
+ wgpu::TextureFormat::RGBA8Unorm;
};
- for (wgpu::TextureFormat format : nonRenderableFormats) {
- // Fails because `format` is non-renderable
- descriptor.format = format;
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
-}
+ // Test the validation of sample count
+ TEST_F(TextureValidationTest, SampleCount) {
+ wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
-// Test it is an error to create a Storage texture with any format that doesn't support
-// TextureUsage::Storage texture usages.
-TEST_F(TextureValidationTest, TextureFormatNotSupportTextureUsageStorage) {
- wgpu::TextureDescriptor descriptor;
- descriptor.size = {1, 1, 1};
- descriptor.usage = wgpu::TextureUsage::Storage;
-
- for (wgpu::TextureFormat format : utils::kAllTextureFormats) {
- descriptor.format = format;
- if (utils::TextureFormatSupportsStorageTexture(format)) {
- device.CreateTexture(&descriptor);
- } else {
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
- }
- }
-}
-
-// Test it is an error to create a texture with format "Undefined".
-TEST_F(TextureValidationTest, TextureFormatUndefined) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = wgpu::TextureFormat::Undefined;
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
-}
-
-// TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
-// compressed texture formats.
-class CompressedTextureFormatsValidationTests : public TextureValidationTest {
- public:
- CompressedTextureFormatsValidationTests() : TextureValidationTest() {
- device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
- }
-
- protected:
- wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
- wgpu::TextureDescriptor descriptor =
- TextureValidationTest::CreateDefaultTextureDescriptor();
- descriptor.usage =
- wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::Sampled;
- return descriptor;
- }
-
- const std::array<wgpu::TextureFormat, 14> kBCFormats = {
- wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
- wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
- wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
- wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm,
- wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm,
- wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat,
- wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
-};
-
-// Test the validation of texture size when creating textures in compressed texture formats.
-TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
- // Test that it is invalid to use a number that is not a multiple of 4 (the compressed block
- // width and height of all BC formats) as the width or height of textures in BC formats.
- for (wgpu::TextureFormat format : kBCFormats) {
+ // sampleCount == 1 is allowed.
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- ASSERT_TRUE(descriptor.size.width % 4 == 0 && descriptor.size.height % 4 == 0);
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 1;
+
device.CreateTexture(&descriptor);
}
+ // sampleCount == 4 is allowed.
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.size.width = 31;
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 4;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // It is an error to create a texture with an invalid sampleCount.
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 3;
+
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
+ // It is an error to create a multisampled texture with mipLevelCount > 1.
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.size.height = 31;
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 4;
+ descriptor.mipLevelCount = 2;
+
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
+ // Currently we do not support multisampled 2D array textures.
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.size.width = 12;
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 4;
+ descriptor.size.depth = 2;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // It is an error to set TextureUsage::Storage when sampleCount > 1.
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.sampleCount = 4;
+ descriptor.usage |= wgpu::TextureUsage::Storage;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+ }
+
+ // Test the validation of the mip level count
+ TEST_F(TextureValidationTest, MipLevelCount) {
+ wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
+
+ // mipLevelCount == 1 is allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
descriptor.size.height = 32;
+ descriptor.mipLevelCount = 1;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // mipLevelCount == 0 is an error
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
+ descriptor.size.height = 32;
+ descriptor.mipLevelCount = 0;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Full mip chains are allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
+ descriptor.size.height = 32;
+ // Mip level sizes: 32, 16, 8, 4, 2, 1
+ descriptor.mipLevelCount = 6;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // Too big mip chains on width are disallowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 31;
+ descriptor.size.height = 32;
+ // Mip level width: 31, 15, 7, 3, 1, 1
+ descriptor.mipLevelCount = 7;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Too big mip chains on height are disallowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
+ descriptor.size.height = 31;
+ // Mip level height: 31, 15, 7, 3, 1, 1
+ descriptor.mipLevelCount = 7;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Undefined shift check if miplevel is bigger than the integer bit width.
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
+ descriptor.size.height = 32;
+ descriptor.mipLevelCount = 100;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Non square mip map halves the resolution until a 1x1 dimension.
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 32;
+ descriptor.size.height = 8;
+ // Mip maps: 32 * 8, 16 * 4, 8 * 2, 4 * 1, 2 * 1, 1 * 1
+ descriptor.mipLevelCount = 6;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // Mip level exceeding kMaxTexture2DMipLevels not allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = 1 >> kMaxTexture2DMipLevels;
+ descriptor.size.height = 1 >> kMaxTexture2DMipLevels;
+ descriptor.mipLevelCount = kMaxTexture2DMipLevels + 1u;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+ }
+ // Test the validation of array layer count
+ TEST_F(TextureValidationTest, ArrayLayerCount) {
+ wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
+
+ // Array layer count exceeding kMaxTexture2DArrayLayers is not allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.depth = kMaxTexture2DArrayLayers + 1u;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Array layer count less than kMaxTexture2DArrayLayers is allowed;
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.depth = kMaxTexture2DArrayLayers >> 1;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // Array layer count equal to kMaxTexture2DArrayLayers is allowed;
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.depth = kMaxTexture2DArrayLayers;
+
device.CreateTexture(&descriptor);
}
}
-}
-// Test the creation of a texture with BC format will fail when the extension textureCompressionBC
-// is not enabled.
-TEST_F(CompressedTextureFormatsValidationTests, UseBCFormatWithoutEnablingExtension) {
- const std::vector<const char*> kEmptyVector;
- wgpu::Device deviceWithoutExtension = CreateDeviceFromAdapter(adapter, kEmptyVector);
- for (wgpu::TextureFormat format : kBCFormats) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- ASSERT_DEVICE_ERROR(deviceWithoutExtension.CreateTexture(&descriptor));
+ // Test the validation of texture size
+ TEST_F(TextureValidationTest, TextureSize) {
+ wgpu::TextureDescriptor defaultDescriptor = CreateDefaultTextureDescriptor();
+
+ // Texture size exceeding kMaxTextureSize is not allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = kMaxTextureSize + 1u;
+ descriptor.size.height = kMaxTextureSize + 1u;
+
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ // Texture size less than kMaxTextureSize is allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = kMaxTextureSize >> 1;
+ descriptor.size.height = kMaxTextureSize >> 1;
+
+ device.CreateTexture(&descriptor);
+ }
+
+ // Texture equal to kMaxTextureSize is allowed
+ {
+ wgpu::TextureDescriptor descriptor = defaultDescriptor;
+ descriptor.size.width = kMaxTextureSize;
+ descriptor.size.height = kMaxTextureSize;
+
+ device.CreateTexture(&descriptor);
+ }
}
-}
-// Test the validation of texture usages when creating textures in compressed texture formats.
-TEST_F(CompressedTextureFormatsValidationTests, TextureUsage) {
- // Test that only CopySrc, CopyDst and Sampled are accepted as the texture usage of the
- // textures in BC formats.
- for (wgpu::TextureFormat format : kBCFormats) {
+ // Test that it is valid to destroy a texture
+ TEST_F(TextureValidationTest, DestroyTexture) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
+ texture.Destroy();
+ }
+
+ // Test that it's valid to destroy a destroyed texture
+ TEST_F(TextureValidationTest, DestroyDestroyedTexture) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
+ texture.Destroy();
+ texture.Destroy();
+ }
+
+ // Test that it's invalid to submit a destroyed texture in a queue
+ // in the case of destroy, encode, submit
+ TEST_F(TextureValidationTest, DestroyEncodeSubmit) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
+ wgpu::TextureView textureView = texture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass({textureView});
+
+ // Destroy the texture
+ texture.Destroy();
+
+ wgpu::CommandEncoder encoder_post_destroy = device.CreateCommandEncoder();
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.usage = wgpu::TextureUsage::OutputAttachment;
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ wgpu::RenderPassEncoder pass = encoder_post_destroy.BeginRenderPass(&renderPass);
+ pass.EndPass();
}
+ wgpu::CommandBuffer commands = encoder_post_destroy.Finish();
+ // Submit should fail due to destroyed texture
+ ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
+ }
+
+ // Test that it's invalid to submit a destroyed texture in a queue
+ // in the case of encode, destroy, submit
+ TEST_F(TextureValidationTest, EncodeDestroySubmit) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
+ wgpu::TextureView textureView = texture.CreateView();
+
+ utils::ComboRenderPassDescriptor renderPass({textureView});
+
+ wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
{
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.usage = wgpu::TextureUsage::Storage;
- ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
+ pass.EndPass();
}
+ wgpu::CommandBuffer commands = encoder.Finish();
- {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ // Destroy the texture
+ texture.Destroy();
+
+ // Submit should fail due to destroyed texture
+ ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
+ }
+
+ // Test it is an error to create an OutputAttachment texture with a non-renderable format.
+ TEST_F(TextureValidationTest, NonRenderableAndOutputAttachment) {
+ wgpu::TextureDescriptor descriptor;
+ descriptor.size = {1, 1, 1};
+ descriptor.usage = wgpu::TextureUsage::OutputAttachment;
+
+ // Succeeds because RGBA8Unorm is renderable
+ descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ device.CreateTexture(&descriptor);
+
+ wgpu::TextureFormat nonRenderableFormats[] = {
+ wgpu::TextureFormat::RG11B10Float,
+ wgpu::TextureFormat::R8Snorm,
+ wgpu::TextureFormat::RG8Snorm,
+ wgpu::TextureFormat::RGBA8Snorm,
+ };
+
+ for (wgpu::TextureFormat format : nonRenderableFormats) {
+ // Fails because `format` is non-renderable
descriptor.format = format;
- descriptor.usage = wgpu::TextureUsage::Present;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
}
-}
-// Test the validation of sample count when creating textures in compressed texture formats.
-TEST_F(CompressedTextureFormatsValidationTests, SampleCount) {
- // Test that it is invalid to specify SampleCount > 1 when we create a texture in BC formats.
- for (wgpu::TextureFormat format : kBCFormats) {
+ // Test it is an error to create a Storage texture with any format that doesn't support
+ // TextureUsage::Storage texture usages.
+ TEST_F(TextureValidationTest, TextureFormatNotSupportTextureUsageStorage) {
+ wgpu::TextureDescriptor descriptor;
+ descriptor.size = {1, 1, 1};
+ descriptor.usage = wgpu::TextureUsage::Storage;
+
+ for (wgpu::TextureFormat format : utils::kAllTextureFormats) {
+ descriptor.format = format;
+ if (utils::TextureFormatSupportsStorageTexture(format)) {
+ device.CreateTexture(&descriptor);
+ } else {
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+ }
+ }
+
+ // Test it is an error to create a texture with format "Undefined".
+ TEST_F(TextureValidationTest, TextureFormatUndefined) {
wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.sampleCount = 4;
+ descriptor.format = wgpu::TextureFormat::Undefined;
ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
}
-}
-// Test the validation of creating 2D array textures in compressed texture formats.
-TEST_F(CompressedTextureFormatsValidationTests, 2DArrayTexture) {
- // Test that it is allowed to create a 2D array texture in BC formats.
- for (wgpu::TextureFormat format : kBCFormats) {
- wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
- descriptor.format = format;
- descriptor.size.depth = 6;
- device.CreateTexture(&descriptor);
+ // TODO(jiawei.shao@intel.com): add tests to verify we cannot create 1D or 3D textures with
+ // compressed texture formats.
+ class CompressedTextureFormatsValidationTests : public TextureValidationTest {
+ public:
+ CompressedTextureFormatsValidationTests() : TextureValidationTest() {
+ device = CreateDeviceFromAdapter(adapter, {"texture_compression_bc"});
+ }
+
+ protected:
+ wgpu::TextureDescriptor CreateDefaultTextureDescriptor() {
+ wgpu::TextureDescriptor descriptor =
+ TextureValidationTest::CreateDefaultTextureDescriptor();
+ descriptor.usage = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::CopyDst |
+ wgpu::TextureUsage::Sampled;
+ return descriptor;
+ }
+
+ const std::array<wgpu::TextureFormat, 14> kBCFormats = {
+ wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb,
+ wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb,
+ wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb,
+ wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::BC4RSnorm,
+ wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::BC5RGSnorm,
+ wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::BC6HRGBSfloat,
+ wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb};
+ };
+
+ // Test the validation of texture size when creating textures in compressed texture formats.
+ TEST_F(CompressedTextureFormatsValidationTests, TextureSize) {
+ // Test that it is invalid to use a number that is not a multiple of 4 (the compressed block
+ // width and height of all BC formats) as the width or height of textures in BC formats.
+ for (wgpu::TextureFormat format : kBCFormats) {
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ ASSERT_TRUE(descriptor.size.width % 4 == 0 && descriptor.size.height % 4 == 0);
+ device.CreateTexture(&descriptor);
+ }
+
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.size.width = 31;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.size.height = 31;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.size.width = 12;
+ descriptor.size.height = 32;
+ device.CreateTexture(&descriptor);
+ }
+ }
}
-}
+
+ // Test the creation of a texture with BC format will fail when the extension
+ // textureCompressionBC is not enabled.
+ TEST_F(CompressedTextureFormatsValidationTests, UseBCFormatWithoutEnablingExtension) {
+ const std::vector<const char*> kEmptyVector;
+ wgpu::Device deviceWithoutExtension = CreateDeviceFromAdapter(adapter, kEmptyVector);
+ for (wgpu::TextureFormat format : kBCFormats) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ ASSERT_DEVICE_ERROR(deviceWithoutExtension.CreateTexture(&descriptor));
+ }
+ }
+
+ // Test the validation of texture usages when creating textures in compressed texture formats.
+ TEST_F(CompressedTextureFormatsValidationTests, TextureUsage) {
+ // Test that only CopySrc, CopyDst and Sampled are accepted as the texture usage of the
+ // textures in BC formats.
+ for (wgpu::TextureFormat format : kBCFormats) {
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.usage = wgpu::TextureUsage::OutputAttachment;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.usage = wgpu::TextureUsage::Storage;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+
+ {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.usage = wgpu::TextureUsage::Present;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+ }
+ }
+
+ // Test the validation of sample count when creating textures in compressed texture formats.
+ TEST_F(CompressedTextureFormatsValidationTests, SampleCount) {
+ // Test that it is invalid to specify SampleCount > 1 when we create a texture in BC
+ // formats.
+ for (wgpu::TextureFormat format : kBCFormats) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.sampleCount = 4;
+ ASSERT_DEVICE_ERROR(device.CreateTexture(&descriptor));
+ }
+ }
+
+ // Test the validation of creating 2D array textures in compressed texture formats.
+ TEST_F(CompressedTextureFormatsValidationTests, 2DArrayTexture) {
+ // Test that it is allowed to create a 2D array texture in BC formats.
+ for (wgpu::TextureFormat format : kBCFormats) {
+ wgpu::TextureDescriptor descriptor = CreateDefaultTextureDescriptor();
+ descriptor.format = format;
+ descriptor.size.depth = 6;
+ device.CreateTexture(&descriptor);
+ }
+ }
} // namespace
diff --git a/src/tests/unittests/validation/TextureViewValidationTests.cpp b/src/tests/unittests/validation/TextureViewValidationTests.cpp
index 32bf7a3..c5c3242 100644
--- a/src/tests/unittests/validation/TextureViewValidationTests.cpp
+++ b/src/tests/unittests/validation/TextureViewValidationTests.cpp
@@ -16,349 +16,348 @@
namespace {
-class TextureViewValidationTest : public ValidationTest {
-};
+ class TextureViewValidationTest : public ValidationTest {};
-constexpr uint32_t kWidth = 32u;
-constexpr uint32_t kHeight = 32u;
-constexpr uint32_t kDefaultMipLevels = 6u;
+ constexpr uint32_t kWidth = 32u;
+ constexpr uint32_t kHeight = 32u;
+ constexpr uint32_t kDefaultMipLevels = 6u;
-constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
+ constexpr wgpu::TextureFormat kDefaultTextureFormat = wgpu::TextureFormat::RGBA8Unorm;
-wgpu::Texture Create2DArrayTexture(wgpu::Device& device,
- uint32_t arrayLayerCount,
- uint32_t width = kWidth,
- uint32_t height = kHeight,
- uint32_t mipLevelCount = kDefaultMipLevels,
- uint32_t sampleCount = 1) {
- wgpu::TextureDescriptor descriptor;
- descriptor.dimension = wgpu::TextureDimension::e2D;
- descriptor.size.width = width;
- descriptor.size.height = height;
- descriptor.size.depth = arrayLayerCount;
- descriptor.sampleCount = sampleCount;
- descriptor.format = kDefaultTextureFormat;
- descriptor.mipLevelCount = mipLevelCount;
- descriptor.usage = wgpu::TextureUsage::Sampled;
- return device.CreateTexture(&descriptor);
-}
-
-wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.format = kDefaultTextureFormat;
- descriptor.dimension = dimension;
- descriptor.baseMipLevel = 0;
- descriptor.mipLevelCount = kDefaultMipLevels;
- descriptor.baseArrayLayer = 0;
- descriptor.arrayLayerCount = 1;
- return descriptor;
-}
-
-// Test creating texture view on a 2D non-array texture
-TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2D) {
- wgpu::Texture texture = Create2DArrayTexture(device, 1);
-
- wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
- CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
-
- // It is OK to create a 2D texture view on a 2D texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.arrayLayerCount = 1;
- texture.CreateView(&descriptor);
+ wgpu::Texture Create2DArrayTexture(wgpu::Device& device,
+ uint32_t arrayLayerCount,
+ uint32_t width = kWidth,
+ uint32_t height = kHeight,
+ uint32_t mipLevelCount = kDefaultMipLevels,
+ uint32_t sampleCount = 1) {
+ wgpu::TextureDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureDimension::e2D;
+ descriptor.size.width = width;
+ descriptor.size.height = height;
+ descriptor.size.depth = arrayLayerCount;
+ descriptor.sampleCount = sampleCount;
+ descriptor.format = kDefaultTextureFormat;
+ descriptor.mipLevelCount = mipLevelCount;
+ descriptor.usage = wgpu::TextureUsage::Sampled;
+ return device.CreateTexture(&descriptor);
}
- // It is an error to view a layer past the end of the texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.arrayLayerCount = 2;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-
- // It is OK to create a 1-layer 2D array texture view on a 2D texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
- descriptor.arrayLayerCount = 1;
- texture.CreateView(&descriptor);
- }
-
- // baseMipLevel == k && mipLevelCount == 0 means to use levels k..end.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.mipLevelCount = 0;
-
+ wgpu::TextureViewDescriptor CreateDefaultViewDescriptor(wgpu::TextureViewDimension dimension) {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.format = kDefaultTextureFormat;
+ descriptor.dimension = dimension;
descriptor.baseMipLevel = 0;
- texture.CreateView(&descriptor);
- descriptor.baseMipLevel = 1;
- texture.CreateView(&descriptor);
- descriptor.baseMipLevel = kDefaultMipLevels - 1;
- texture.CreateView(&descriptor);
- descriptor.baseMipLevel = kDefaultMipLevels;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-
- // It is an error to make the mip level out of range.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.baseMipLevel = 0;
- descriptor.mipLevelCount = kDefaultMipLevels + 1;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseMipLevel = 1;
descriptor.mipLevelCount = kDefaultMipLevels;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseMipLevel = kDefaultMipLevels - 1;
- descriptor.mipLevelCount = 2;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseMipLevel = kDefaultMipLevels;
- descriptor.mipLevelCount = 1;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-}
-
-// Test creating texture view on a 2D array texture
-TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2DArray) {
- constexpr uint32_t kDefaultArrayLayers = 6;
-
- wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
-
- wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
- CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
-
- // It is OK to create a 2D texture view on a 2D array texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::e2D;
- descriptor.arrayLayerCount = 1;
- texture.CreateView(&descriptor);
- }
-
- // It is OK to create a 2D array texture view on a 2D array texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.arrayLayerCount = kDefaultArrayLayers;
- texture.CreateView(&descriptor);
- }
-
- // baseArrayLayer == k && arrayLayerCount == 0 means to use layers k..end.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.arrayLayerCount = 0;
-
descriptor.baseArrayLayer = 0;
- texture.CreateView(&descriptor);
- descriptor.baseArrayLayer = 1;
- texture.CreateView(&descriptor);
- descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
- texture.CreateView(&descriptor);
- descriptor.baseArrayLayer = kDefaultArrayLayers;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-
- // It is an error for the array layer range of the view to exceed that of the texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.baseArrayLayer = 0;
- descriptor.arrayLayerCount = kDefaultArrayLayers + 1;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseArrayLayer = 1;
- descriptor.arrayLayerCount = kDefaultArrayLayers;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
- descriptor.arrayLayerCount = 2;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.baseArrayLayer = kDefaultArrayLayers;
descriptor.arrayLayerCount = 1;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-}
-
-// Using the "none" ("default") values validates the same as explicitly
-// specifying the values they're supposed to default to.
-// Variant for a texture with more than 1 array layer.
-TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
- constexpr uint32_t kDefaultArrayLayers = 6;
- wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
-
- { texture.CreateView(); }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.format = wgpu::TextureFormat::Undefined;
- texture.CreateView(&descriptor);
- descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- texture.CreateView(&descriptor);
- descriptor.format = wgpu::TextureFormat::R8Unorm;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.dimension = wgpu::TextureViewDimension::Undefined;
- texture.CreateView(&descriptor);
- descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
- texture.CreateView(&descriptor);
- descriptor.dimension = wgpu::TextureViewDimension::e2D;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
- {
- wgpu::TextureViewDescriptor descriptor;
-
- // Setting array layers to non-0 means the dimensionality will
- // default to 2D so by itself it causes an error.
- descriptor.arrayLayerCount = kDefaultArrayLayers;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
- texture.CreateView(&descriptor);
-
- descriptor.mipLevelCount = kDefaultMipLevels;
- texture.CreateView(&descriptor);
- }
-}
-
-// Using the "none" ("default") values validates the same as explicitly
-// specifying the values they're supposed to default to.
-// Variant for a texture with only 1 array layer.
-TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
- constexpr uint32_t kDefaultArrayLayers = 1;
- wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
-
- { texture.CreateView(); }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.format = wgpu::TextureFormat::Undefined;
- texture.CreateView(&descriptor);
- descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
- texture.CreateView(&descriptor);
- descriptor.format = wgpu::TextureFormat::R8Unorm;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.dimension = wgpu::TextureViewDimension::Undefined;
- texture.CreateView(&descriptor);
- descriptor.dimension = wgpu::TextureViewDimension::e2D;
- texture.CreateView(&descriptor);
- descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
- texture.CreateView(&descriptor);
- }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.arrayLayerCount = 0;
- texture.CreateView(&descriptor);
- descriptor.arrayLayerCount = 1;
- texture.CreateView(&descriptor);
- descriptor.arrayLayerCount = 2;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
- {
- wgpu::TextureViewDescriptor descriptor;
- descriptor.mipLevelCount = kDefaultMipLevels;
- texture.CreateView(&descriptor);
- descriptor.arrayLayerCount = kDefaultArrayLayers;
- texture.CreateView(&descriptor);
- }
-}
-
-// Test creating cube map texture view
-TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) {
- constexpr uint32_t kDefaultArrayLayers = 16;
-
- wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
-
- wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
- CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
-
- // It is OK to create a cube map texture view with arrayLayerCount == 6.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::Cube;
- descriptor.arrayLayerCount = 6;
- texture.CreateView(&descriptor);
+ return descriptor;
}
- // It is an error to create a cube map texture view with arrayLayerCount != 6.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::Cube;
- descriptor.arrayLayerCount = 3;
+ // Test creating texture view on a 2D non-array texture
+ TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2D) {
+ wgpu::Texture texture = Create2DArrayTexture(device, 1);
+
+ wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
+ CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
+
+ // It is OK to create a 2D texture view on a 2D texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.arrayLayerCount = 1;
+ texture.CreateView(&descriptor);
+ }
+
+ // It is an error to view a layer past the end of the texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.arrayLayerCount = 2;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+
+ // It is OK to create a 1-layer 2D array texture view on a 2D texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
+ descriptor.arrayLayerCount = 1;
+ texture.CreateView(&descriptor);
+ }
+
+ // baseMipLevel == k && mipLevelCount == 0 means to use levels k..end.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.mipLevelCount = 0;
+
+ descriptor.baseMipLevel = 0;
+ texture.CreateView(&descriptor);
+ descriptor.baseMipLevel = 1;
+ texture.CreateView(&descriptor);
+ descriptor.baseMipLevel = kDefaultMipLevels - 1;
+ texture.CreateView(&descriptor);
+ descriptor.baseMipLevel = kDefaultMipLevels;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+
+ // It is an error to make the mip level out of range.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.baseMipLevel = 0;
+ descriptor.mipLevelCount = kDefaultMipLevels + 1;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseMipLevel = 1;
+ descriptor.mipLevelCount = kDefaultMipLevels;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseMipLevel = kDefaultMipLevels - 1;
+ descriptor.mipLevelCount = 2;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseMipLevel = kDefaultMipLevels;
+ descriptor.mipLevelCount = 1;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ }
+
+ // Test creating texture view on a 2D array texture
+ TEST_F(TextureViewValidationTest, CreateTextureViewOnTexture2DArray) {
+ constexpr uint32_t kDefaultArrayLayers = 6;
+
+ wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
+
+ wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
+ CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
+
+ // It is OK to create a 2D texture view on a 2D array texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::e2D;
+ descriptor.arrayLayerCount = 1;
+ texture.CreateView(&descriptor);
+ }
+
+ // It is OK to create a 2D array texture view on a 2D array texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.arrayLayerCount = kDefaultArrayLayers;
+ texture.CreateView(&descriptor);
+ }
+
+ // baseArrayLayer == k && arrayLayerCount == 0 means to use layers k..end.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.arrayLayerCount = 0;
+
+ descriptor.baseArrayLayer = 0;
+ texture.CreateView(&descriptor);
+ descriptor.baseArrayLayer = 1;
+ texture.CreateView(&descriptor);
+ descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
+ texture.CreateView(&descriptor);
+ descriptor.baseArrayLayer = kDefaultArrayLayers;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+
+ // It is an error for the array layer range of the view to exceed that of the texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.baseArrayLayer = 0;
+ descriptor.arrayLayerCount = kDefaultArrayLayers + 1;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseArrayLayer = 1;
+ descriptor.arrayLayerCount = kDefaultArrayLayers;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseArrayLayer = kDefaultArrayLayers - 1;
+ descriptor.arrayLayerCount = 2;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.baseArrayLayer = kDefaultArrayLayers;
+ descriptor.arrayLayerCount = 1;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ }
+
+ // Using the "none" ("default") values validates the same as explicitly
+ // specifying the values they're supposed to default to.
+ // Variant for a texture with more than 1 array layer.
+ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsArray) {
+ constexpr uint32_t kDefaultArrayLayers = 6;
+ wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
+
+ { texture.CreateView(); }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.format = wgpu::TextureFormat::Undefined;
+ texture.CreateView(&descriptor);
+ descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ texture.CreateView(&descriptor);
+ descriptor.format = wgpu::TextureFormat::R8Unorm;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::Undefined;
+ texture.CreateView(&descriptor);
+ descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
+ texture.CreateView(&descriptor);
+ descriptor.dimension = wgpu::TextureViewDimension::e2D;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+
+ // Setting array layers to non-0 means the dimensionality will
+ // default to 2D so by itself it causes an error.
+ descriptor.arrayLayerCount = kDefaultArrayLayers;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
+ texture.CreateView(&descriptor);
+
+ descriptor.mipLevelCount = kDefaultMipLevels;
+ texture.CreateView(&descriptor);
+ }
+ }
+
+ // Using the "none" ("default") values validates the same as explicitly
+ // specifying the values they're supposed to default to.
+ // Variant for a texture with only 1 array layer.
+ TEST_F(TextureViewValidationTest, TextureViewDescriptorDefaultsNonArray) {
+ constexpr uint32_t kDefaultArrayLayers = 1;
+ wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
+
+ { texture.CreateView(); }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.format = wgpu::TextureFormat::Undefined;
+ texture.CreateView(&descriptor);
+ descriptor.format = wgpu::TextureFormat::RGBA8Unorm;
+ texture.CreateView(&descriptor);
+ descriptor.format = wgpu::TextureFormat::R8Unorm;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::Undefined;
+ texture.CreateView(&descriptor);
+ descriptor.dimension = wgpu::TextureViewDimension::e2D;
+ texture.CreateView(&descriptor);
+ descriptor.dimension = wgpu::TextureViewDimension::e2DArray;
+ texture.CreateView(&descriptor);
+ }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.arrayLayerCount = 0;
+ texture.CreateView(&descriptor);
+ descriptor.arrayLayerCount = 1;
+ texture.CreateView(&descriptor);
+ descriptor.arrayLayerCount = 2;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ {
+ wgpu::TextureViewDescriptor descriptor;
+ descriptor.mipLevelCount = kDefaultMipLevels;
+ texture.CreateView(&descriptor);
+ descriptor.arrayLayerCount = kDefaultArrayLayers;
+ texture.CreateView(&descriptor);
+ }
+ }
+
+ // Test creating cube map texture view
+ TEST_F(TextureViewValidationTest, CreateCubeMapTextureView) {
+ constexpr uint32_t kDefaultArrayLayers = 16;
+
+ wgpu::Texture texture = Create2DArrayTexture(device, kDefaultArrayLayers);
+
+ wgpu::TextureViewDescriptor base2DArrayTextureViewDescriptor =
+ CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2DArray);
+
+ // It is OK to create a cube map texture view with arrayLayerCount == 6.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::Cube;
+ descriptor.arrayLayerCount = 6;
+ texture.CreateView(&descriptor);
+ }
+
+ // It is an error to create a cube map texture view with arrayLayerCount != 6.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::Cube;
+ descriptor.arrayLayerCount = 3;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+
+ // It is OK to create a cube map array texture view with arrayLayerCount % 6 == 0.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
+ descriptor.arrayLayerCount = 12;
+ texture.CreateView(&descriptor);
+ }
+
+ // It is an error to create a cube map array texture view with arrayLayerCount % 6 != 0.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
+ descriptor.arrayLayerCount = 11;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+
+ // It is an error to create a cube map texture view with width != height.
+ {
+ wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
+
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::Cube;
+ descriptor.arrayLayerCount = 6;
+ ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
+ }
+
+ // It is an error to create a cube map array texture view with width != height.
+ {
+ wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
+
+ wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
+ descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
+ descriptor.arrayLayerCount = 12;
+ ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
+ }
+ }
+
+ // Test the format compatibility rules when creating a texture view.
+ // TODO(jiawei.shao@intel.com): add more tests when the rules are fully implemented.
+ TEST_F(TextureViewValidationTest, TextureViewFormatCompatibility) {
+ wgpu::Texture texture = Create2DArrayTexture(device, 1);
+
+ wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
+ CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
+
+ // It is an error to create a texture view in depth-stencil format on a RGBA texture.
+ {
+ wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
+ descriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
+ }
+ }
+
+ // Test that it's invalid to create a texture view from a destroyed texture
+ TEST_F(TextureViewValidationTest, DestroyCreateTextureView) {
+ wgpu::Texture texture = Create2DArrayTexture(device, 1);
+ wgpu::TextureViewDescriptor descriptor =
+ CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
+ texture.Destroy();
ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
}
- // It is OK to create a cube map array texture view with arrayLayerCount % 6 == 0.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
- descriptor.arrayLayerCount = 12;
- texture.CreateView(&descriptor);
+ // Test that only TextureAspect::All is supported
+ TEST_F(TextureViewValidationTest, AspectMustBeAll) {
+ wgpu::TextureDescriptor descriptor = {};
+ descriptor.size = {1, 1, 1};
+ descriptor.format = wgpu::TextureFormat::Depth32Float;
+ descriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::OutputAttachment;
+ wgpu::Texture texture = device.CreateTexture(&descriptor);
+
+ wgpu::TextureViewDescriptor viewDescriptor = {};
+ viewDescriptor.aspect = wgpu::TextureAspect::All;
+ texture.CreateView(&viewDescriptor);
+
+ viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
+ ASSERT_DEVICE_ERROR(texture.CreateView(&viewDescriptor));
}
- // It is an error to create a cube map array texture view with arrayLayerCount % 6 != 0.
- {
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
- descriptor.arrayLayerCount = 11;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-
- // It is an error to create a cube map texture view with width != height.
- {
- wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
-
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::Cube;
- descriptor.arrayLayerCount = 6;
- ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
- }
-
- // It is an error to create a cube map array texture view with width != height.
- {
- wgpu::Texture nonSquareTexture = Create2DArrayTexture(device, 18, 32, 16, 5);
-
- wgpu::TextureViewDescriptor descriptor = base2DArrayTextureViewDescriptor;
- descriptor.dimension = wgpu::TextureViewDimension::CubeArray;
- descriptor.arrayLayerCount = 12;
- ASSERT_DEVICE_ERROR(nonSquareTexture.CreateView(&descriptor));
- }
-}
-
-// Test the format compatibility rules when creating a texture view.
-// TODO(jiawei.shao@intel.com): add more tests when the rules are fully implemented.
-TEST_F(TextureViewValidationTest, TextureViewFormatCompatibility) {
- wgpu::Texture texture = Create2DArrayTexture(device, 1);
-
- wgpu::TextureViewDescriptor base2DTextureViewDescriptor =
- CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
-
- // It is an error to create a texture view in depth-stencil format on a RGBA texture.
- {
- wgpu::TextureViewDescriptor descriptor = base2DTextureViewDescriptor;
- descriptor.format = wgpu::TextureFormat::Depth24PlusStencil8;
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
- }
-}
-
-// Test that it's invalid to create a texture view from a destroyed texture
-TEST_F(TextureViewValidationTest, DestroyCreateTextureView) {
- wgpu::Texture texture = Create2DArrayTexture(device, 1);
- wgpu::TextureViewDescriptor descriptor =
- CreateDefaultViewDescriptor(wgpu::TextureViewDimension::e2D);
- texture.Destroy();
- ASSERT_DEVICE_ERROR(texture.CreateView(&descriptor));
-}
-
-// Test that only TextureAspect::All is supported
-TEST_F(TextureViewValidationTest, AspectMustBeAll) {
- wgpu::TextureDescriptor descriptor = {};
- descriptor.size = {1, 1, 1};
- descriptor.format = wgpu::TextureFormat::Depth32Float;
- descriptor.usage = wgpu::TextureUsage::Sampled | wgpu::TextureUsage::OutputAttachment;
- wgpu::Texture texture = device.CreateTexture(&descriptor);
-
- wgpu::TextureViewDescriptor viewDescriptor = {};
- viewDescriptor.aspect = wgpu::TextureAspect::All;
- texture.CreateView(&viewDescriptor);
-
- viewDescriptor.aspect = wgpu::TextureAspect::DepthOnly;
- ASSERT_DEVICE_ERROR(texture.CreateView(&viewDescriptor));
-}
-
} // anonymous namespace
diff --git a/src/tests/unittests/validation/ToggleValidationTests.cpp b/src/tests/unittests/validation/ToggleValidationTests.cpp
index 950c889..b0f489f 100644
--- a/src/tests/unittests/validation/ToggleValidationTests.cpp
+++ b/src/tests/unittests/validation/ToggleValidationTests.cpp
@@ -16,34 +16,67 @@
namespace {
-class ToggleValidationTest : public ValidationTest {
-};
+ class ToggleValidationTest : public ValidationTest {};
-// Tests querying the detail of a toggle from dawn_native::InstanceBase works correctly.
-TEST_F(ToggleValidationTest, QueryToggleInfo) {
- // Query with a valid toggle name
- {
- const char* kValidToggleName = "emulate_store_and_msaa_resolve";
- const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kValidToggleName);
- ASSERT_NE(nullptr, toggleInfo);
- ASSERT_NE(nullptr, toggleInfo->name);
- ASSERT_NE(nullptr, toggleInfo->description);
- ASSERT_NE(nullptr, toggleInfo->url);
+ // Tests querying the detail of a toggle from dawn_native::InstanceBase works correctly.
+ TEST_F(ToggleValidationTest, QueryToggleInfo) {
+ // Query with a valid toggle name
+ {
+ const char* kValidToggleName = "emulate_store_and_msaa_resolve";
+ const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kValidToggleName);
+ ASSERT_NE(nullptr, toggleInfo);
+ ASSERT_NE(nullptr, toggleInfo->name);
+ ASSERT_NE(nullptr, toggleInfo->description);
+ ASSERT_NE(nullptr, toggleInfo->url);
+ }
+
+ // Query with an invalid toggle name
+ {
+ const char* kInvalidToggleName = "!@#$%^&*";
+ const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kInvalidToggleName);
+ ASSERT_EQ(nullptr, toggleInfo);
+ }
}
- // Query with an invalid toggle name
- {
- const char* kInvalidToggleName = "!@#$%^&*";
- const dawn_native::ToggleInfo* toggleInfo = instance->GetToggleInfo(kInvalidToggleName);
- ASSERT_EQ(nullptr, toggleInfo);
- }
-}
+ // Tests overriding toggles when creating a device works correctly.
+ TEST_F(ToggleValidationTest, OverrideToggleUsage) {
+ // Create device with a valid name of a toggle
+ {
+ const char* kValidToggleName = "emulate_store_and_msaa_resolve";
+ dawn_native::DeviceDescriptor descriptor;
+ descriptor.forceEnabledToggles.push_back(kValidToggleName);
-// Tests overriding toggles when creating a device works correctly.
-TEST_F(ToggleValidationTest, OverrideToggleUsage) {
- // Create device with a valid name of a toggle
- {
- const char* kValidToggleName = "emulate_store_and_msaa_resolve";
+ WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
+ std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
+ bool validToggleExists = false;
+ for (const char* toggle : toggleNames) {
+ if (strcmp(toggle, kValidToggleName) == 0) {
+ validToggleExists = true;
+ }
+ }
+ ASSERT_EQ(validToggleExists, true);
+ }
+
+ // Create device with an invalid toggle name
+ {
+ const char* kInvalidToggleName = "!@#$%^&*";
+ dawn_native::DeviceDescriptor descriptor;
+ descriptor.forceEnabledToggles.push_back(kInvalidToggleName);
+
+ WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
+ std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
+ bool InvalidToggleExists = false;
+ for (const char* toggle : toggleNames) {
+ if (strcmp(toggle, kInvalidToggleName) == 0) {
+ InvalidToggleExists = true;
+ }
+ }
+ ASSERT_EQ(InvalidToggleExists, false);
+ }
+ }
+
+ TEST_F(ToggleValidationTest, TurnOffVsyncWithToggle) {
+ const char* kValidToggleName = "turn_off_vsync";
dawn_native::DeviceDescriptor descriptor;
descriptor.forceEnabledToggles.push_back(kValidToggleName);
@@ -57,38 +90,4 @@
}
ASSERT_EQ(validToggleExists, true);
}
-
- // Create device with an invalid toggle name
- {
- const char* kInvalidToggleName = "!@#$%^&*";
- dawn_native::DeviceDescriptor descriptor;
- descriptor.forceEnabledToggles.push_back(kInvalidToggleName);
-
- WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
- std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
- bool InvalidToggleExists = false;
- for (const char* toggle : toggleNames) {
- if (strcmp(toggle, kInvalidToggleName) == 0) {
- InvalidToggleExists = true;
- }
- }
- ASSERT_EQ(InvalidToggleExists, false);
- }
-}
-
-TEST_F(ToggleValidationTest, TurnOffVsyncWithToggle) {
- const char* kValidToggleName = "turn_off_vsync";
- dawn_native::DeviceDescriptor descriptor;
- descriptor.forceEnabledToggles.push_back(kValidToggleName);
-
- WGPUDevice deviceWithToggle = adapter.CreateDevice(&descriptor);
- std::vector<const char*> toggleNames = dawn_native::GetTogglesUsed(deviceWithToggle);
- bool validToggleExists = false;
- for (const char* toggle : toggleNames) {
- if (strcmp(toggle, kValidToggleName) == 0) {
- validToggleExists = true;
- }
- }
- ASSERT_EQ(validToggleExists, true);
-}
} // anonymous namespace
diff --git a/src/tests/unittests/validation/ValidationTest.cpp b/src/tests/unittests/validation/ValidationTest.cpp
index 21f028a..6b533b4 100644
--- a/src/tests/unittests/validation/ValidationTest.cpp
+++ b/src/tests/unittests/validation/ValidationTest.cpp
@@ -27,7 +27,7 @@
// Validation tests run against the null backend, find the corresponding adapter
bool foundNullAdapter = false;
- for (auto ¤tAdapter : adapters) {
+ for (auto& currentAdapter : adapters) {
wgpu::AdapterProperties adapterProperties;
currentAdapter.GetProperties(&adapterProperties);
@@ -129,7 +129,7 @@
wgpu::TextureView view = attachment.CreateView();
mColorAttachment.attachment = view;
mColorAttachment.resolveTarget = nullptr;
- mColorAttachment.clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
+ mColorAttachment.clearColor = {0.0f, 0.0f, 0.0f, 0.0f};
mColorAttachment.loadOp = wgpu::LoadOp::Clear;
mColorAttachment.storeOp = wgpu::StoreOp::Store;
diff --git a/src/tests/unittests/validation/ValidationTest.h b/src/tests/unittests/validation/ValidationTest.h
index 7862b4c..c922dd6 100644
--- a/src/tests/unittests/validation/ValidationTest.h
+++ b/src/tests/unittests/validation/ValidationTest.h
@@ -70,4 +70,4 @@
bool mError = false;
};
-#endif // TESTS_UNITTESTS_VALIDATIONTEST_H_
+#endif // TESTS_UNITTESTS_VALIDATIONTEST_H_
diff --git a/src/tests/unittests/validation/VertexBufferValidationTests.cpp b/src/tests/unittests/validation/VertexBufferValidationTests.cpp
index 9c67a0f..4c8722e 100644
--- a/src/tests/unittests/validation/VertexBufferValidationTests.cpp
+++ b/src/tests/unittests/validation/VertexBufferValidationTests.cpp
@@ -21,68 +21,68 @@
#include "utils/WGPUHelpers.h"
class VertexBufferValidationTest : public ValidationTest {
- protected:
- void SetUp() override {
- ValidationTest::SetUp();
+ protected:
+ void SetUp() override {
+ ValidationTest::SetUp();
- fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
+ fsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Fragment, R"(
#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(0.0, 1.0, 0.0, 1.0);
})");
+ }
+
+ wgpu::Buffer MakeVertexBuffer() {
+ wgpu::BufferDescriptor descriptor;
+ descriptor.size = 256;
+ descriptor.usage = wgpu::BufferUsage::Vertex;
+
+ return device.CreateBuffer(&descriptor);
+ }
+
+ wgpu::ShaderModule MakeVertexShader(unsigned int bufferCount) {
+ std::ostringstream vs;
+ vs << "#version 450\n";
+ for (unsigned int i = 0; i < bufferCount; ++i) {
+ vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
}
+ vs << "void main() {\n";
- wgpu::Buffer MakeVertexBuffer() {
- wgpu::BufferDescriptor descriptor;
- descriptor.size = 256;
- descriptor.usage = wgpu::BufferUsage::Vertex;
-
- return device.CreateBuffer(&descriptor);
- }
-
- wgpu::ShaderModule MakeVertexShader(unsigned int bufferCount) {
- std::ostringstream vs;
- vs << "#version 450\n";
- for (unsigned int i = 0; i < bufferCount; ++i) {
- vs << "layout(location = " << i << ") in vec3 a_position" << i << ";\n";
+ vs << "gl_Position = vec4(";
+ for (unsigned int i = 0; i < bufferCount; ++i) {
+ vs << "a_position" << i;
+ if (i != bufferCount - 1) {
+ vs << " + ";
}
- vs << "void main() {\n";
-
- vs << "gl_Position = vec4(";
- for (unsigned int i = 0; i < bufferCount; ++i) {
- vs << "a_position" << i;
- if (i != bufferCount - 1) {
- vs << " + ";
- }
- }
- vs << ", 1.0);";
-
- vs << "}\n";
-
- return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
- vs.str().c_str());
}
+ vs << ", 1.0);";
- wgpu::RenderPipeline MakeRenderPipeline(const wgpu::ShaderModule& vsModule,
- unsigned int bufferCount) {
- utils::ComboRenderPipelineDescriptor descriptor(device);
- descriptor.vertexStage.module = vsModule;
- descriptor.cFragmentStage.module = fsModule;
+ vs << "}\n";
- for (unsigned int i = 0; i < bufferCount; ++i) {
- descriptor.cVertexState.cVertexBuffers[i].attributeCount = 1;
- descriptor.cVertexState.cVertexBuffers[i].attributes =
- &descriptor.cVertexState.cAttributes[i];
- descriptor.cVertexState.cAttributes[i].shaderLocation = i;
- descriptor.cVertexState.cAttributes[i].format = wgpu::VertexFormat::Float3;
- }
- descriptor.cVertexState.vertexBufferCount = bufferCount;
+ return utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex,
+ vs.str().c_str());
+ }
- return device.CreateRenderPipeline(&descriptor);
+ wgpu::RenderPipeline MakeRenderPipeline(const wgpu::ShaderModule& vsModule,
+ unsigned int bufferCount) {
+ utils::ComboRenderPipelineDescriptor descriptor(device);
+ descriptor.vertexStage.module = vsModule;
+ descriptor.cFragmentStage.module = fsModule;
+
+ for (unsigned int i = 0; i < bufferCount; ++i) {
+ descriptor.cVertexState.cVertexBuffers[i].attributeCount = 1;
+ descriptor.cVertexState.cVertexBuffers[i].attributes =
+ &descriptor.cVertexState.cAttributes[i];
+ descriptor.cVertexState.cAttributes[i].shaderLocation = i;
+ descriptor.cVertexState.cAttributes[i].format = wgpu::VertexFormat::Float3;
}
+ descriptor.cVertexState.vertexBufferCount = bufferCount;
- wgpu::ShaderModule fsModule;
+ return device.CreateRenderPipeline(&descriptor);
+ }
+
+ wgpu::ShaderModule fsModule;
};
TEST_F(VertexBufferValidationTest, VertexBuffersInheritedBetweenPipelines) {
diff --git a/src/tests/unittests/wire/WireArgumentTests.cpp b/src/tests/unittests/wire/WireArgumentTests.cpp
index 2185028..95685cf 100644
--- a/src/tests/unittests/wire/WireArgumentTests.cpp
+++ b/src/tests/unittests/wire/WireArgumentTests.cpp
@@ -185,7 +185,6 @@
FlushClient();
}
-
// Test that the wire is able to send objects as value arguments
TEST_F(WireArgumentTests, ObjectAsValueArgument) {
WGPUCommandEncoder cmdBufEncoder = wgpuDeviceCreateCommandEncoder(device, nullptr);
diff --git a/src/tests/unittests/wire/WireBufferMappingTests.cpp b/src/tests/unittests/wire/WireBufferMappingTests.cpp
index 1307b95..990a300 100644
--- a/src/tests/unittests/wire/WireBufferMappingTests.cpp
+++ b/src/tests/unittests/wire/WireBufferMappingTests.cpp
@@ -613,4 +613,3 @@
FlushClient();
}
-
diff --git a/src/tests/unittests/wire/WireErrorCallbackTests.cpp b/src/tests/unittests/wire/WireErrorCallbackTests.cpp
index 6f31977..3fe25f0 100644
--- a/src/tests/unittests/wire/WireErrorCallbackTests.cpp
+++ b/src/tests/unittests/wire/WireErrorCallbackTests.cpp
@@ -64,7 +64,8 @@
WireTest::SetUp();
mockDeviceErrorCallback = std::make_unique<StrictMock<MockDeviceErrorCallback>>();
- mockDevicePopErrorScopeCallback = std::make_unique<StrictMock<MockDevicePopErrorScopeCallback>>();
+ mockDevicePopErrorScopeCallback =
+ std::make_unique<StrictMock<MockDevicePopErrorScopeCallback>>();
mockDeviceLostCallback = std::make_unique<StrictMock<MockDeviceLostCallback>>();
}
@@ -206,8 +207,7 @@
EXPECT_TRUE(wgpuDevicePopErrorScope(device, ToMockDevicePopErrorScopeCallback, this));
- EXPECT_CALL(api, OnDevicePopErrorScopeCallback(apiDevice, _, _))
- .WillOnce(Return(true));
+ EXPECT_CALL(api, OnDevicePopErrorScopeCallback(apiDevice, _, _)).WillOnce(Return(true));
FlushClient();
// Incomplete callback called in Device destructor.
diff --git a/src/tests/unittests/wire/WireExtensionTests.cpp b/src/tests/unittests/wire/WireExtensionTests.cpp
index 78f9de7..d36fc5f 100644
--- a/src/tests/unittests/wire/WireExtensionTests.cpp
+++ b/src/tests/unittests/wire/WireExtensionTests.cpp
@@ -40,8 +40,9 @@
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
- const auto* ext = reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
- serverDesc->nextInChain);
+ const auto* ext =
+ reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
+ serverDesc->nextInChain);
EXPECT_EQ(ext->chain.sType, clientExt.chain.sType);
EXPECT_EQ(ext->maxAnisotropy, clientExt.maxAnisotropy);
@@ -73,13 +74,15 @@
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
- const auto* ext1 = reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
- serverDesc->nextInChain);
+ const auto* ext1 =
+ reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
+ serverDesc->nextInChain);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->maxAnisotropy, clientExt1.maxAnisotropy);
- const auto* ext2 = reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
- ext1->chain.next);
+ const auto* ext2 =
+ reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
+ ext1->chain.next);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy);
@@ -99,13 +102,15 @@
.WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler {
EXPECT_STREQ(serverDesc->label, clientDesc.label);
- const auto* ext2 = reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
- serverDesc->nextInChain);
+ const auto* ext2 =
+ reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
+ serverDesc->nextInChain);
EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType);
EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy);
- const auto* ext1 = reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
- ext2->chain.next);
+ const auto* ext1 =
+ reinterpret_cast<const WGPUSamplerDescriptorDummyAnisotropicFiltering*>(
+ ext2->chain.next);
EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType);
EXPECT_EQ(ext1->maxAnisotropy, clientExt1.maxAnisotropy);
diff --git a/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp b/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp
index bb1efb6..026b52e 100644
--- a/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp
+++ b/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp
@@ -180,9 +180,7 @@
ClientReadHandle* handle = clientMemoryTransferService.NewReadHandle();
EXPECT_CALL(clientMemoryTransferService, OnCreateReadHandle(sizeof(mBufferContent)))
- .WillOnce(InvokeWithoutArgs([=]() {
- return handle;
- }));
+ .WillOnce(InvokeWithoutArgs([=]() { return handle; }));
return handle;
}
@@ -259,9 +257,7 @@
ClientWriteHandle* handle = clientMemoryTransferService.NewWriteHandle();
EXPECT_CALL(clientMemoryTransferService, OnCreateWriteHandle(sizeof(mBufferContent)))
- .WillOnce(InvokeWithoutArgs([=]() {
- return handle;
- }));
+ .WillOnce(InvokeWithoutArgs([=]() { return handle; }));
return handle;
}
@@ -300,22 +296,18 @@
EXPECT_CALL(serverMemoryTransferService,
OnDeserializeWriteHandle(Pointee(Eq(mSerializeCreateInfo)),
sizeof(mSerializeCreateInfo), _))
- .WillOnce(InvokeWithoutArgs([&]() {
- return false;
- }));
+ .WillOnce(InvokeWithoutArgs([&]() { return false; }));
}
void ExpectClientWriteHandleOpen(ClientWriteHandle* handle, uint32_t* mappedData) {
EXPECT_CALL(clientMemoryTransferService, OnWriteHandleOpen(handle))
- .WillOnce(InvokeWithoutArgs([=]() {
- return std::make_pair(mappedData, sizeof(*mappedData));
- }));
+ .WillOnce(InvokeWithoutArgs(
+ [=]() { return std::make_pair(mappedData, sizeof(*mappedData)); }));
}
void MockClientWriteHandleOpenFailure(ClientWriteHandle* handle) {
EXPECT_CALL(clientMemoryTransferService, OnWriteHandleOpen(handle))
- .WillOnce(InvokeWithoutArgs(
- [&]() { return std::make_pair(nullptr, 0); }));
+ .WillOnce(InvokeWithoutArgs([&]() { return std::make_pair(nullptr, 0); }));
}
void ExpectClientWriteHandleSerializeFlush(ClientWriteHandle* handle) {
@@ -348,8 +340,8 @@
// Arbitrary values used within tests to check if serialized data is correctly passed
// between the client and server. The static data changes between runs of the tests and
- // test expectations will check that serialized values are passed to the respective deserialization
- // function.
+ // test expectations will check that serialized values are passed to the respective
+ // deserialization function.
static uint32_t mSerializeCreateInfo;
static uint32_t mSerializeInitialDataInfo;
static uint32_t mSerializeFlushInfo;
@@ -360,8 +352,9 @@
// The client's zero-initialized buffer for writing.
uint32_t mMappedBufferContent = 0;
- // |mMappedBufferContent| should be set equal to |mUpdatedBufferContent| when the client performs a write.
- // Test expectations should check that |mBufferContent == mUpdatedBufferContent| after all writes are flushed.
+ // |mMappedBufferContent| should be set equal to |mUpdatedBufferContent| when the client
+ // performs a write. Test expectations should check that |mBufferContent ==
+ // mUpdatedBufferContent| after all writes are flushed.
static uint32_t mUpdatedBufferContent;
testing::StrictMock<dawn_wire::server::MockMemoryTransferService> serverMemoryTransferService;
diff --git a/src/tests/unittests/wire/WireTest.h b/src/tests/unittests/wire/WireTest.h
index 7a8ed5a..d4537d6 100644
--- a/src/tests/unittests/wire/WireTest.h
+++ b/src/tests/unittests/wire/WireTest.h
@@ -68,9 +68,11 @@
class StringMessageMatcher : public testing::MatcherInterface<const char*> {
public:
- explicit StringMessageMatcher() {}
+ explicit StringMessageMatcher() {
+ }
- bool MatchAndExplain(const char* message, testing::MatchResultListener* listener) const override {
+ bool MatchAndExplain(const char* message,
+ testing::MatchResultListener* listener) const override {
if (message == nullptr) {
*listener << "missing error message";
return false;
@@ -83,11 +85,11 @@
}
void DescribeTo(std::ostream* os) const override {
- *os << "valid error message";
+ *os << "valid error message";
}
void DescribeNegationTo(std::ostream* os) const override {
- *os << "invalid error message";
+ *os << "invalid error message";
}
};