diff --git a/examples/Animometer.cpp b/examples/Animometer.cpp index dfd041cabe..5c197c4cf5 100644 --- a/examples/Animometer.cpp +++ b/examples/Animometer.cpp @@ -18,8 +18,8 @@ #include "utils/SystemUtils.h" #include "utils/WGPUHelpers.h" -#include #include +#include #include wgpu::Device device; @@ -138,8 +138,7 @@ void init() { 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 39ef9c521f..96ae72fbe9 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -49,9 +49,7 @@ static_library("dawn_sample_utils") { # 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 @@ template("dawn_sample") { } 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 048fba1987..22d820295c 100644 --- a/examples/CHelloTriangle.cpp +++ b/examples/CHelloTriangle.cpp @@ -120,7 +120,7 @@ void frame() { { 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 59538dfa65..f958ab4002 100644 --- a/examples/ComputeBoids.cpp +++ b/examples/ComputeBoids.cpp @@ -67,7 +67,7 @@ void initBuffers() { 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 @@ void initBuffers() { { std::mt19937 generator; std::uniform_real_distribution 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 @@ void initSim() { 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 fbc598daa0..378afa8db5 100644 --- a/examples/CppHelloTriangle.cpp +++ b/examples/CppHelloTriangle.cpp @@ -36,15 +36,15 @@ wgpu::BindGroup bindGroup; 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 @@ void init() { 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 becec8728b..4ff18e003c 100644 --- a/examples/CubeReflection.cpp +++ b/examples/CubeReflection.cpp @@ -18,10 +18,10 @@ #include "utils/SystemUtils.h" #include "utils/WGPUHelpers.h" -#include #include #include #include +#include wgpu::Device device; @@ -43,67 +43,44 @@ wgpu::RenderPipeline planePipeline; 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 @@ void init() { 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 @@ void init() { 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 ee924d3dba..9e3990d820 100644 --- a/examples/ManualSwapChainTest.cpp +++ b/examples/ManualSwapChainTest.cpp @@ -150,7 +150,8 @@ void DoRender(WindowData* data) { 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 17b7c9e7c5..ee7e006156 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -60,7 +60,7 @@ void PrintGLFWError(int code, const char* message) { 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 @@ static wgpu::BackendType backendType = wgpu::BackendType::Vulkan; #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 @@ wgpu::Device CreateCppDawnDevice() { 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 @@ bool InitSample(int argc, const char** argv) { 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 98ecb2e69b..4a0409fd9d 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 118a4ee169..780f482af4 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 bindingInitializer) const { - wgpu::PipelineLayoutDescriptor descriptor; + wgpu::PipelineLayout MakeBasicPipelineLayout( + std::vector 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 bindingTypes) const { - ASSERT(bindingTypes.size() <= kMaxBindGroups); + wgpu::ShaderModule MakeFSModule(std::vector 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 bindingTypes, - std::vector bindGroupLayouts) { - wgpu::ShaderModule vsModule = MakeSimpleVSModule(); - wgpu::ShaderModule fsModule = MakeFSModule(bindingTypes); + wgpu::RenderPipeline MakeTestPipeline(const utils::BasicRenderPass& renderPass, + std::vector bindingTypes, + std::vector 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 @@ TEST_P(BindGroupTests, ReusedUBO) { }; 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 @@ TEST_P(BindGroupTests, ReusedUBO) { 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 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { 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 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { 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 @@ TEST_P(BindGroupTests, ReadonlyStorage) { 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 f010be64a0..4b626ee98d 100644 --- a/src/tests/end2end/BufferTests.cpp +++ b/src/tests/end2end/BufferTests.cpp @@ -17,34 +17,34 @@ #include 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(userdata)->mappedData = data; - } + static_cast(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 @@ TEST_P(BufferMapReadTests, GetMappedRangeZeroSized) { 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(userdata)->mappedData = data; - } + static_cast(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 @@ TEST_P(BufferMapWriteTests, GetMappedRangeZeroSized) { 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(userdata)->mappedData = data; - } + static_cast(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(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(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& 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& 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 be97ced650..33c78e92b6 100644 --- a/src/tests/end2end/ClipSpaceTests.cpp +++ b/src/tests/end2end/ClipSpaceTests.cpp @@ -97,4 +97,8 @@ TEST_P(ClipSpaceTest, ClipSpace) { 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 f0fa1e5e3b..b4f935dac8 100644 --- a/src/tests/end2end/ColorStateTests.cpp +++ b/src/tests/end2end/ColorStateTests.cpp @@ -758,8 +758,8 @@ TEST_P(ColorStateTest, IndependentColorState) { 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 @@ TEST_P(ColorStateTest, ColorWriteMaskDoesNotAffectRenderPassLoadOpClear) { 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 dcb762e982..f127acdb36 100644 --- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp +++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp @@ -173,7 +173,7 @@ TEST_P(ComputeCopyStorageBufferTests, DISABLED_UnsizedDescriptorArray) { } 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 bb33856d04..a11c01a0a5 100644 --- a/src/tests/end2end/ComputeSharedMemoryTests.cpp +++ b/src/tests/end2end/ComputeSharedMemoryTests.cpp @@ -98,7 +98,7 @@ TEST_P(ComputeSharedMemoryTests, Basic) { } 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 5d592a13cc..75de2f6e8e 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 GetExpectedTextureData( - const utils::BufferTextureCopyLayout& layout) { - std::vector 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((x + layer * x) % 256), - static_cast((y + layer * y) % 256), - static_cast(x / 256), static_cast(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 GetExpectedTextureData(const utils::BufferTextureCopyLayout& layout) { + std::vector 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((x + layer * x) % 256), + static_cast((y + layer * y) % 256), + static_cast(x / 256), static_cast(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 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 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 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 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 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 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(expected.data()), buffer, - bufferOffset, static_cast(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(expected.data()), buffer, + bufferOffset, static_cast(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(i % 256), - static_cast((i / 256) % 256), - static_cast((i / 256 / 256) % 256), - 255); + data[i] = RGBA8(static_cast(i % 256), static_cast((i / 256) % 256), + static_cast((i / 256 / 256) % 256), 255); } } @@ -510,7 +510,7 @@ TEST_P(CopyTests_T2B, TextureRegionAligned) { 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 @@ TEST_P(CopyTests_T2B, TextureRegionUnaligned) { 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 @@ TEST_P(CopyTests_T2B, Texture2DArrayRegionNonzeroRowsPerImage) { 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 @@ TEST_P(CopyTests_B2T, TextureRegionAligned) { 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 @@ TEST_P(CopyTests_B2T, Texture2DArrayRegionNonzeroRowsPerImage) { 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 @@ TEST_P(CopyTests_T2T, MultipleMipSrcSingleMipDst) { } } -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 79a2303979..726df138db 100644 --- a/src/tests/end2end/CullingTests.cpp +++ b/src/tests/end2end/CullingTests.cpp @@ -127,4 +127,8 @@ TEST_P(CullingTest, CullBackFaceWhenCWIsFrontFace) { 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 2907a877fb..364f48fa22 100644 --- a/src/tests/end2end/D3D12ResourceWrappingTests.cpp +++ b/src/tests/end2end/D3D12ResourceWrappingTests.cpp @@ -130,8 +130,7 @@ namespace { // 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 f9fab77202..d368a175f6 100644 --- a/src/tests/end2end/DebugMarkerTests.cpp +++ b/src/tests/end2end/DebugMarkerTests.cpp @@ -42,4 +42,8 @@ TEST_P(DebugMarkerTests, NoFailureWithoutDebugToolAttached) { 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 7c24a69e3e..06dcce6eac 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 @@ class DepthSamplingTest : public DawnTest { 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 @@ class DepthSamplingTest : public DawnTest { 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 @@ class DepthSamplingTest : public DawnTest { 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 @@ class DepthSamplingTest : public DawnTest { 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 4881437332..4788094e59 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 @@ class DepthStencilStateTest : public DawnTest { } )"); - 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 @@ class DepthStencilStateTest : public DawnTest { 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 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 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 &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& 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(test.color.r) / 255.f, static_cast(test.color.g) / 255.f, + static_cast(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(test.color.r) / 255.f, static_cast(test.color.g) / 255.f, static_cast(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 &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& 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 @@ TEST_P(DepthStencilStateTest, Basic) { 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 @@ TEST_P(DepthStencilStateTest, DepthStencilDisabled) { 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 @@ TEST_P(DepthStencilStateTest, DepthStencilDisabled) { 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 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) { 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 @@ TEST_P(DepthStencilStateTest, StencilReadMask) { 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 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) { 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 @@ TEST_P(DepthStencilStateTest, StencilFail) { 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 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) { 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 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) { 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 82c43a64eb..4122001189 100644 --- a/src/tests/end2end/DestroyTests.cpp +++ b/src/tests/end2end/DestroyTests.cpp @@ -157,4 +157,8 @@ TEST_P(DestroyTest, TextureSubmitDestroySubmit) { 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 48abdadce7..f980af3ceb 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( - 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( + 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( - 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( + 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_P(DrawIndexedTest, BaseVertex) { 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 3f14375733..56b55ec89e 100644 --- a/src/tests/end2end/DrawIndirectTests.cpp +++ b/src/tests/end2end/DrawIndirectTests.cpp @@ -124,4 +124,8 @@ TEST_P(DrawIndirectTest, IndirectOffset) { 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 3b4dcd1576..4cf64d0929 100644 --- a/src/tests/end2end/GpuMemorySynchronizationTests.cpp +++ b/src/tests/end2end/GpuMemorySynchronizationTests.cpp @@ -231,7 +231,11 @@ TEST_P(GpuMemorySyncTests, ComputePassToRenderPass) { 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 af40c1b9d0..9e44cb7a7c 100644 --- a/src/tests/end2end/IOSurfaceWrappingTests.cpp +++ b/src/tests/end2end/IOSurfaceWrappingTests.cpp @@ -369,7 +369,8 @@ class IOSurfaceUsageTests : public IOSurfaceTestBase { // 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_P(IOSurfaceUsageTests, SampleFromR8IOSurface) { // 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_P(IOSurfaceUsageTests, ClearR8IOSurface) { // 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_P(IOSurfaceUsageTests, SampleFromRG8IOSurface) { // 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 ea83e9184c..554c674d00 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 @@ TEST_P(IndexFormatTest, DISABLED_SetIndexBufferBeforeSetPipeline) { 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 ef03bf2f89..0605594c5f 100644 --- a/src/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/tests/end2end/MultisampledRenderingTests.cpp @@ -61,7 +61,6 @@ class MultisampledRenderingTest : public DawnTest { const char* fs = testDepth ? kFsOneOutputWithDepth : kFsOneOutputWithoutDepth; - return CreateRenderPipelineForTest(fs, 1, testDepth); } @@ -285,8 +284,8 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) { utils::ComboRenderPassDescriptor renderPass = CreateComboRenderPassDescriptorForTest({mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, true); - std::array kUniformData = {kGreen.r, kGreen.g, kGreen.b, kGreen.a, // Color - 0.2f}; // depth + std::array 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 @@ TEST_P(MultisampledRenderingTest, MultisampledRenderingWithDepthTest) { {mMultisampledColorView}, {mResolveView}, wgpu::LoadOp::Load, wgpu::LoadOp::Load, kTestDepth); - std::array kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color - 0.5f}; // depth + std::array 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 @@ TEST_P(MultisampledRenderingTest, ResolveIntoMultipleResolveTargets) { {mMultisampledColorView, multisampledColorView2}, {mResolveView, resolveView2}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth); - std::array kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1 - kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2 + std::array 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 @@ TEST_P(MultisampledRenderingTest, ResolveInto2DArrayTexture) { {mMultisampledColorView, multisampledColorView2}, {resolveView1, resolveView2}, wgpu::LoadOp::Clear, wgpu::LoadOp::Clear, kTestDepth); - std::array kUniformData = {kRed.r, kRed.g, kRed.b, kRed.a, // color1 - kGreen.r, kGreen.g, kGreen.b, kGreen.a}; // color2 + std::array 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 9ee9e800b4..97759afd33 100644 --- a/src/tests/end2end/NonzeroTextureCreationTests.cpp +++ b/src/tests/end2end/NonzeroTextureCreationTests.cpp @@ -292,6 +292,6 @@ DAWN_INSTANTIATE_TEST(NonzeroTextureCreationTests, 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 d27a3f5f84..20705a9d2f 100644 --- a/src/tests/end2end/ObjectCachingTests.cpp +++ b/src/tests/end2end/ObjectCachingTests.cpp @@ -400,4 +400,8 @@ TEST_P(ObjectCachingTest, SamplerDeduplication) { 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 3e6a043869..2d8e465b33 100644 --- a/src/tests/end2end/OpArrayLengthTests.cpp +++ b/src/tests/end2end/OpArrayLengthTests.cpp @@ -262,4 +262,8 @@ TEST_P(OpArrayLengthTest, Vertex) { 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 6e71234106..a4a02e9e1d 100644 --- a/src/tests/end2end/PipelineLayoutTests.cpp +++ b/src/tests/end2end/PipelineLayoutTests.cpp @@ -62,4 +62,4 @@ DAWN_INSTANTIATE_TEST(PipelineLayoutTests, 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 822bfee3a4..0c0c285176 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 @@ struct TestLocation { }; 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 @@ constexpr static float kVertices[] = { // 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 @@ class PrimitiveTopologyTest : public DawnTest { 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 + 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& 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 - 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& 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 @@ TEST_P(PrimitiveTopologyTest, TriangleStrip) { }); } -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 0df87c3474..c58eb8cac7 100644 --- a/src/tests/end2end/RenderBundleTests.cpp +++ b/src/tests/end2end/RenderBundleTests.cpp @@ -196,4 +196,8 @@ TEST_P(RenderBundleTest, BundleAndRenderPassCommands) { 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 db7b6a9ff8..011c6e0fe6 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 @@ class RenderPassLoadOpTests : public DawnTest { 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 expectZero; - std::array expectGreen; - std::array expectBlue; + std::array expectZero; + std::array expectGreen; + std::array expectBlue; - DrawQuad blueQuad = {}; + DrawQuad blueQuad = {}; }; // Tests clearing, loading, and drawing into color attachments @@ -144,7 +143,12 @@ TEST_P(RenderPassLoadOpTests, ColorClearThenLoadAndDraw) { // 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 ead9bee23e..74069fff48 100644 --- a/src/tests/end2end/RenderPassTests.cpp +++ b/src/tests/end2end/RenderPassTests.cpp @@ -21,7 +21,7 @@ constexpr uint32_t kRTSize = 16; constexpr wgpu::TextureFormat kFormat = wgpu::TextureFormat::RGBA8Unorm; class RenderPassTest : public DawnTest { -protected: + protected: void SetUp() override { DawnTest::SetUp(); @@ -71,9 +71,9 @@ protected: // 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 d40f0992c0..ad5ed92142 100644 --- a/src/tests/end2end/SamplerTests.cpp +++ b/src/tests/end2end/SamplerTests.cpp @@ -46,10 +46,10 @@ namespace { 255, }, }; -} +} // namespace class SamplerTest : public DawnTest { -protected: + protected: void SetUp() override { DawnTest::SetUp(); mRenderPass = utils::CreateBasicRenderPass(device, kRTSize, kRTSize); @@ -177,4 +177,8 @@ TEST_P(SamplerTest, AddressMode) { } } -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 f6743032d5..98722d02d5 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 @@ TEST_P(ScissorTest, NoInheritanceBetweenRenderPass) { 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 06f70a56ca..cad7b31ea0 100644 --- a/src/tests/end2end/TextureFormatTests.cpp +++ b/src/tests/end2end/TextureFormatTests.cpp @@ -404,7 +404,7 @@ class TextureFormatTest : public DawnTest { ASSERT(sizeof(float) * formatInfo.componentCount == formatInfo.texelByteSize); ASSERT(formatInfo.type == wgpu::TextureComponentType::Float); - std::vector textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f, + std::vector textureData = {+0.0f, -0.0f, 1.0f, 1.0e-29f, 1.0e29f, NAN, INFINITY, -INFINITY}; DoFloatFormatSamplingTest(formatInfo, textureData, textureData); @@ -733,4 +733,8 @@ TEST_P(TextureFormatTest, RG11B10Float) { // 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 acab158dd2..4697169179 100644 --- a/src/tests/end2end/TextureViewTests.cpp +++ b/src/tests/end2end/TextureViewTests.cpp @@ -70,7 +70,7 @@ namespace { } // 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 @@ protected: 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 @@ protected: 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 @@ protected: 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 @@ protected: std::string CreateFragmentShaderForCubeMapFace(uint32_t layer, bool isCubeMapArray) { // Reference: https://en.wikipedia.org/wiki/Cube_mapping const std::array 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 @@ protected: 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 @@ protected: // 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 @@ TEST_P(TextureViewSamplingTest, Default2DArrayTexture) { } )"; - 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 @@ TEST_P(TextureViewSamplingTest, TextureCubeMapArrayViewOnPartOfTexture) { 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 @@ class TextureViewRenderingTest : public DawnTest { bytesPerRow / kBytesPerTexel * (textureWidthLevel0 - 1) + textureHeightLevel0; constexpr RGBA8 kExpectedPixel(0, 255, 0, 255); std::vector 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 @@ TEST_P(TextureViewRenderingTest, Texture2DViewOnALayerOf2DArrayTextureAsColorAtt 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 @@ TEST_P(TextureViewRenderingTest, Texture2DArrayViewOnALayerOf2DArrayTextureAsCol } } -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 3333007b70..dbd2e76b62 100644 --- a/src/tests/end2end/TextureZeroInitTests.cpp +++ b/src/tests/end2end/TextureZeroInitTests.cpp @@ -1144,11 +1144,10 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferNonRenderableUnaligned) { 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 6030adc296..a4e773af6c 100644 --- a/src/tests/end2end/VertexFormatTests.cpp +++ b/src/tests/end2end/VertexFormatTests.cpp @@ -915,4 +915,8 @@ TEST_P(VertexFormatTest, Int4) { 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 e65fefaa01..1c92f3450b 100644 --- a/src/tests/end2end/VertexStateTests.cpp +++ b/src/tests/end2end/VertexStateTests.cpp @@ -543,7 +543,7 @@ TEST_P(VertexStateTest, OverlappingVertexAttributes) { 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 @@ TEST_P(VertexStateTest, OverlappingVertexAttributes) { 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 b592c212c1..7c2a04af08 100644 --- a/src/tests/end2end/ViewportOrientationTests.cpp +++ b/src/tests/end2end/ViewportOrientationTests.cpp @@ -64,4 +64,8 @@ TEST_P(ViewportOrientationTests, OriginAt0x0) { 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 56dac87db0..2145ab445c 100644 --- a/src/tests/end2end/ViewportTests.cpp +++ b/src/tests/end2end/ViewportTests.cpp @@ -404,4 +404,8 @@ TEST_P(ViewportTest, DoNotTruncateWidthAndHeight2) { 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 34cfb6c2f4..7bed713a54 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 cdb8908dc4..5d46630372 100644 --- a/src/tests/unittests/BuddyAllocatorTests.cpp +++ b/src/tests/unittests/BuddyAllocatorTests.cpp @@ -324,4 +324,4 @@ TEST(BuddyAllocatorTests, VariousSizeSameAlignment) { 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 a2d60eaf16..55da40175e 100644 --- a/src/tests/unittests/BuddyMemoryAllocatorTests.cpp +++ b/src/tests/unittests/BuddyMemoryAllocatorTests.cpp @@ -355,4 +355,4 @@ TEST(BuddyMemoryAllocatorTests, AllocationOverflow) { 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 206261fc0e..bc1d736cd8 100644 --- a/src/tests/unittests/CommandAllocatorTests.cpp +++ b/src/tests/unittests/CommandAllocatorTests.cpp @@ -121,7 +121,8 @@ TEST(CommandAllocator, BasicWithData) { uint32_t myValues[5] = {6, 42, 0xFFFFFFFF, 0, 54}; { - CommandPushConstants* pushConstants = allocator.Allocate(CommandType::PushConstants); + CommandPushConstants* pushConstants = + allocator.Allocate(CommandType::PushConstants); pushConstants->size = mySize; pushConstants->offset = myOffset; @@ -209,7 +210,7 @@ TEST(CommandAllocator, LargeCommands) { for (int i = 0; i < kCommandCount; i++) { CommandBig* big = allocator.Allocate(CommandType::Big); for (int j = 0; j < kBigBufferSize; j++) { - big->buffer[j] = count ++; + big->buffer[j] = count++; } } @@ -223,9 +224,9 @@ TEST(CommandAllocator, LargeCommands) { CommandBig* big = iterator.NextCommand(); 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 @@ TEST(CommandAllocator, ManySmallCommands) { uint16_t count = 0; for (int i = 0; i < kCommandCount; i++) { CommandSmall* small = allocator.Allocate(CommandType::Small); - small->data = count ++; + small->data = count++; } CommandIterator iterator(std::move(allocator)); @@ -254,8 +255,8 @@ TEST(CommandAllocator, ManySmallCommands) { CommandSmall* small = iterator.NextCommand(); 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 b706e490ae..c87f09f1e8 100644 --- a/src/tests/unittests/EnumClassBitmasksTests.cpp +++ b/src/tests/unittests/EnumClassBitmasksTests.cpp @@ -25,7 +25,7 @@ namespace wgpu { A = 8, }; - template<> + template <> struct IsDawnBitmask { static constexpr bool enable = true; }; diff --git a/src/tests/unittests/ErrorTests.cpp b/src/tests/unittests/ErrorTests.cpp index 514c740865..042784db6d 100644 --- a/src/tests/unittests/ErrorTests.cpp +++ b/src/tests/unittests/ErrorTests.cpp @@ -21,278 +21,260 @@ using namespace dawn_native; 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 = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr errorData = result.AcquireError(); + ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); + } -// Check returning a success ResultOrError with an implicit conversion -TEST(ErrorTests, ResultOrError_Success) { - auto ReturnSuccess = []() -> ResultOrError { - return &dummySuccess; - }; + // Check returning a success ResultOrError with an implicit conversion + TEST(ErrorTests, ResultOrError_Success) { + auto ReturnSuccess = []() -> ResultOrError { return &dummySuccess; }; - ResultOrError result = ReturnSuccess(); - ASSERT_TRUE(result.IsSuccess()); - ASSERT_EQ(result.AcquireSuccess(), &dummySuccess); -} + ResultOrError 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 { - return DAWN_VALIDATION_ERROR(dummyErrorMessage); - }; + // Check returning an error ResultOrError with "return DAWN_VALIDATION_ERROR" + TEST(ErrorTests, ResultOrError_Error) { + auto ReturnError = []() -> ResultOrError { + return DAWN_VALIDATION_ERROR(dummyErrorMessage); + }; - ResultOrError result = ReturnError(); - ASSERT_TRUE(result.IsError()); + ResultOrError result = ReturnError(); + ASSERT_TRUE(result.IsError()); - std::unique_ptr errorData = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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 = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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 singleData = singleResult.AcquireError(); - std::unique_ptr doubleData = doubleResult.AcquireError(); + std::unique_ptr singleData = singleResult.AcquireError(); + std::unique_ptr 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 { - return &dummySuccess; - }; + // Check DAWN_TRY_ASSIGN handles successes correctly. + TEST(ErrorTests, TRY_RESULT_Success) { + auto ReturnSuccess = []() -> ResultOrError { 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* result = nullptr; - DAWN_TRY_ASSIGN(result, ReturnSuccess()); - tryReturned = false; + auto Try = [ReturnSuccess, &tryReturned]() -> ResultOrError { + int* result = nullptr; + DAWN_TRY_ASSIGN(result, ReturnSuccess()); + tryReturned = false; - EXPECT_EQ(result, &dummySuccess); - return result; - }; + EXPECT_EQ(result, &dummySuccess); + return result; + }; - ResultOrError result = Try(); - ASSERT_TRUE(result.IsSuccess()); - ASSERT_FALSE(tryReturned); - ASSERT_EQ(result.AcquireSuccess(), &dummySuccess); -} + ResultOrError 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 { - return DAWN_VALIDATION_ERROR(dummyErrorMessage); - }; + // Check DAWN_TRY_ASSIGN handles errors correctly. + TEST(ErrorTests, TRY_RESULT_Error) { + auto ReturnError = []() -> ResultOrError { + return DAWN_VALIDATION_ERROR(dummyErrorMessage); + }; - auto Try = [ReturnError]() -> ResultOrError { - int* result = nullptr; - DAWN_TRY_ASSIGN(result, ReturnError()); - DAWN_UNUSED(result); + auto Try = [ReturnError]() -> ResultOrError { + 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 result = Try(); - ASSERT_TRUE(result.IsError()); + ResultOrError result = Try(); + ASSERT_TRUE(result.IsError()); - std::unique_ptr errorData = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr errorData = result.AcquireError(); + ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); + } -// Check DAWN_TRY_ASSIGN adds to the backtrace. -TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) { - auto ReturnError = []() -> ResultOrError { - return DAWN_VALIDATION_ERROR(dummyErrorMessage); - }; + // Check DAWN_TRY_ASSIGN adds to the backtrace. + TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) { + auto ReturnError = []() -> ResultOrError { + return DAWN_VALIDATION_ERROR(dummyErrorMessage); + }; - auto SingleTry = [ReturnError]() -> ResultOrError { - DAWN_TRY(ReturnError()); - return &dummySuccess; - }; + auto SingleTry = [ReturnError]() -> ResultOrError { + DAWN_TRY(ReturnError()); + return &dummySuccess; + }; - auto DoubleTry = [SingleTry]() -> ResultOrError { - DAWN_TRY(SingleTry()); - return &dummySuccess; - }; + auto DoubleTry = [SingleTry]() -> ResultOrError { + DAWN_TRY(SingleTry()); + return &dummySuccess; + }; - ResultOrError singleResult = SingleTry(); - ASSERT_TRUE(singleResult.IsError()); + ResultOrError singleResult = SingleTry(); + ASSERT_TRUE(singleResult.IsError()); - ResultOrError doubleResult = DoubleTry(); - ASSERT_TRUE(doubleResult.IsError()); + ResultOrError doubleResult = DoubleTry(); + ASSERT_TRUE(doubleResult.IsError()); - std::unique_ptr singleData = singleResult.AcquireError(); - std::unique_ptr doubleData = doubleResult.AcquireError(); + std::unique_ptr singleData = singleResult.AcquireError(); + std::unique_ptr 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 { - 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 { + 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 = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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 -TEST(ErrorTests, TRY_RESULT_ConversionToErrorNonPointer) { - auto ReturnError = []() -> ResultOrError { - return DAWN_VALIDATION_ERROR(dummyErrorMessage); - }; + // Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error + // Version without Result + TEST(ErrorTests, TRY_RESULT_ConversionToErrorNonPointer) { + auto ReturnError = []() -> ResultOrError { + 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 = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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{ - DAWN_TRY(ReturnError()); - return &dummySuccess; - }; + auto Try = [ReturnError]() -> ResultOrError { + DAWN_TRY(ReturnError()); + return &dummySuccess; + }; - ResultOrError result = Try(); - ASSERT_TRUE(result.IsError()); + ResultOrError result = Try(); + ASSERT_TRUE(result.IsError()); - std::unique_ptr errorData = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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 -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 + TEST(ErrorTests, TRY_ConversionToErrorOrResultNonPointer) { + auto ReturnError = []() -> MaybeError { return DAWN_VALIDATION_ERROR(dummyErrorMessage); }; - auto Try = [ReturnError]() -> ResultOrError{ - DAWN_TRY(ReturnError()); - return 42; - }; + auto Try = [ReturnError]() -> ResultOrError { + DAWN_TRY(ReturnError()); + return 42; + }; - ResultOrError result = Try(); - ASSERT_TRUE(result.IsError()); + ResultOrError result = Try(); + ASSERT_TRUE(result.IsError()); - std::unique_ptr errorData = result.AcquireError(); - ASSERT_EQ(errorData->GetMessage(), dummyErrorMessage); -} + std::unique_ptr 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 94f2ecdc6a..7dcb37f009 100644 --- a/src/tests/unittests/LinkedListTests.cpp +++ b/src/tests/unittests/LinkedListTests.cpp @@ -362,4 +362,4 @@ TEST(LinkedList, IsInList) { 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 6c3f2d7403..ab141d3e7a 100644 --- a/src/tests/unittests/ObjectBaseTests.cpp +++ b/src/tests/unittests/ObjectBaseTests.cpp @@ -194,4 +194,3 @@ TEST(ObjectBase, AssignNullptr) { obj = nullptr; ASSERT_EQ(refcount, 1); } - diff --git a/src/tests/unittests/PerStageTests.cpp b/src/tests/unittests/PerStageTests.cpp index a8c4cf49d1..dcecd83dc0 100644 --- a/src/tests/unittests/PerStageTests.cpp +++ b/src/tests/unittests/PerStageTests.cpp @@ -48,7 +48,7 @@ TEST(PerStage, IterateAllStages) { counts[SingleShaderStage::Compute] = 0; for (auto stage : IterateStages(kAllStages)) { - counts[stage] ++; + counts[stage]++; } ASSERT_EQ(counts[wgpu::ShaderStage::Vertex], 1); @@ -64,7 +64,7 @@ TEST(PerStage, IterateOneStage) { 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 @@ TEST(PerStage, IterateNoStages) { 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 5981dc936b..7e5c959c52 100644 --- a/src/tests/unittests/RefCountedTests.cpp +++ b/src/tests/unittests/RefCountedTests.cpp @@ -410,4 +410,4 @@ TEST(Ref, MoveAssignmentDerived) { 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 7b21d2e398..bd48217d44 100644 --- a/src/tests/unittests/ResultTests.cpp +++ b/src/tests/unittests/ResultTests.cpp @@ -19,363 +19,367 @@ namespace { -template -void TestError(Result* result, E expectedError) { - EXPECT_TRUE(result->IsError()); - EXPECT_FALSE(result->IsSuccess()); + template + void TestError(Result* result, E expectedError) { + EXPECT_TRUE(result->IsError()); + EXPECT_FALSE(result->IsSuccess()); - std::unique_ptr storedError = result->AcquireError(); - EXPECT_EQ(*storedError, expectedError); -} - -template -void TestSuccess(Result* 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 -void TestSuccess(Result, 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 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 - -// Test constructing an error Result -TEST(ResultOnlyPointerError, ConstructingError) { - Result result(std::make_unique(dummyError)); - TestError(&result, dummyError); -} - -// Test moving an error Result -TEST(ResultOnlyPointerError, MovingError) { - Result result(std::make_unique(dummyError)); - Result movedResult(std::move(result)); - TestError(&movedResult, dummyError); -} - -// Test returning an error Result -TEST(ResultOnlyPointerError, ReturningError) { - auto CreateError = []() -> Result { return {std::make_unique(dummyError)}; }; - - Result result = CreateError(); - TestError(&result, dummyError); -} - -// Test constructing a success Result -TEST(ResultOnlyPointerError, ConstructingSuccess) { - Result result; - EXPECT_TRUE(result.IsSuccess()); - EXPECT_FALSE(result.IsError()); -} - -// Test moving a success Result -TEST(ResultOnlyPointerError, MovingSuccess) { - Result result; - Result movedResult(std::move(result)); - EXPECT_TRUE(movedResult.IsSuccess()); - EXPECT_FALSE(movedResult.IsError()); -} - -// Test returning a success Result -TEST(ResultOnlyPointerError, ReturningSuccess) { - auto CreateError = []() -> Result { return {}; }; - - Result result = CreateError(); - EXPECT_TRUE(result.IsSuccess()); - EXPECT_FALSE(result.IsError()); -} - -// Result - -// Test constructing an error Result -TEST(ResultBothPointer, ConstructingError) { - Result result(std::make_unique(dummyError)); - TestError(&result, dummyError); -} - -// Test moving an error Result -TEST(ResultBothPointer, MovingError) { - Result result(std::make_unique(dummyError)); - Result movedResult(std::move(result)); - TestError(&movedResult, dummyError); -} - -// Test returning an error Result -TEST(ResultBothPointer, ReturningError) { - auto CreateError = []() -> Result { return {std::make_unique(dummyError)}; }; - - Result result = CreateError(); - TestError(&result, dummyError); -} - -// Test constructing a success Result -TEST(ResultBothPointer, ConstructingSuccess) { - Result result(&dummySuccess); - TestSuccess(&result, &dummySuccess); -} - -// Test moving a success Result -TEST(ResultBothPointer, MovingSuccess) { - Result result(&dummySuccess); - Result movedResult(std::move(result)); - TestSuccess(&movedResult, &dummySuccess); -} - -// Test returning a success Result -TEST(ResultBothPointer, ReturningSuccess) { - auto CreateSuccess = []() -> Result { - return {&dummySuccess}; - }; - - Result result = CreateSuccess(); - TestSuccess(&result, &dummySuccess); -} - -// Tests converting from a Result -TEST(ResultBothPointer, ConversionFromChildClass) { - struct T { - int a; - }; - struct TChild : T {}; - - TChild child; - T* childAsT = &child; - { - Result result(&child); - TestSuccess(&result, childAsT); + std::unique_ptr storedError = result->AcquireError(); + EXPECT_EQ(*storedError, expectedError); } - { - Result resultChild(&child); - Result result(std::move(resultChild)); - TestSuccess(&result, childAsT); + + template + void TestSuccess(Result* 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 resultChild(&child); - Result 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 + void TestSuccess(Result, 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 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 + // Result -// Test constructing an error Result -TEST(ResultBothPointerWithConstResult, ConstructingError) { - Result result(std::make_unique(dummyError)); - TestError(&result, dummyError); -} + // Test constructing an error Result + TEST(ResultOnlyPointerError, ConstructingError) { + Result result(std::make_unique(dummyError)); + TestError(&result, dummyError); + } -// Test moving an error Result -TEST(ResultBothPointerWithConstResult, MovingError) { - Result result(std::make_unique(dummyError)); - Result movedResult(std::move(result)); - TestError(&movedResult, dummyError); -} + // Test moving an error Result + TEST(ResultOnlyPointerError, MovingError) { + Result result(std::make_unique(dummyError)); + Result movedResult(std::move(result)); + TestError(&movedResult, dummyError); + } -// Test returning an error Result -TEST(ResultBothPointerWithConstResult, ReturningError) { - auto CreateError = []() -> Result { - return {std::make_unique(dummyError)}; + // Test returning an error Result + TEST(ResultOnlyPointerError, ReturningError) { + auto CreateError = []() -> Result { + return {std::make_unique(dummyError)}; + }; + + Result result = CreateError(); + TestError(&result, dummyError); + } + + // Test constructing a success Result + TEST(ResultOnlyPointerError, ConstructingSuccess) { + Result result; + EXPECT_TRUE(result.IsSuccess()); + EXPECT_FALSE(result.IsError()); + } + + // Test moving a success Result + TEST(ResultOnlyPointerError, MovingSuccess) { + Result result; + Result movedResult(std::move(result)); + EXPECT_TRUE(movedResult.IsSuccess()); + EXPECT_FALSE(movedResult.IsError()); + } + + // Test returning a success Result + TEST(ResultOnlyPointerError, ReturningSuccess) { + auto CreateError = []() -> Result { return {}; }; + + Result result = CreateError(); + EXPECT_TRUE(result.IsSuccess()); + EXPECT_FALSE(result.IsError()); + } + + // Result + + // Test constructing an error Result + TEST(ResultBothPointer, ConstructingError) { + Result result(std::make_unique(dummyError)); + TestError(&result, dummyError); + } + + // Test moving an error Result + TEST(ResultBothPointer, MovingError) { + Result result(std::make_unique(dummyError)); + Result movedResult(std::move(result)); + TestError(&movedResult, dummyError); + } + + // Test returning an error Result + TEST(ResultBothPointer, ReturningError) { + auto CreateError = []() -> Result { + return {std::make_unique(dummyError)}; + }; + + Result result = CreateError(); + TestError(&result, dummyError); + } + + // Test constructing a success Result + TEST(ResultBothPointer, ConstructingSuccess) { + Result result(&dummySuccess); + TestSuccess(&result, &dummySuccess); + } + + // Test moving a success Result + TEST(ResultBothPointer, MovingSuccess) { + Result result(&dummySuccess); + Result movedResult(std::move(result)); + TestSuccess(&movedResult, &dummySuccess); + } + + // Test returning a success Result + TEST(ResultBothPointer, ReturningSuccess) { + auto CreateSuccess = []() -> Result { return {&dummySuccess}; }; + + Result result = CreateSuccess(); + TestSuccess(&result, &dummySuccess); + } + + // Tests converting from a Result + TEST(ResultBothPointer, ConversionFromChildClass) { + struct T { + int a; + }; + struct TChild : T {}; + + TChild child; + T* childAsT = &child; + { + Result result(&child); + TestSuccess(&result, childAsT); + } + { + Result resultChild(&child); + Result result(std::move(resultChild)); + TestSuccess(&result, childAsT); + } + { + Result resultChild(&child); + Result result = std::move(resultChild); + TestSuccess(&result, childAsT); + } + } + + // Result + + // Test constructing an error Result + TEST(ResultBothPointerWithConstResult, ConstructingError) { + Result result(std::make_unique(dummyError)); + TestError(&result, dummyError); + } + + // Test moving an error Result + TEST(ResultBothPointerWithConstResult, MovingError) { + Result result(std::make_unique(dummyError)); + Result movedResult(std::move(result)); + TestError(&movedResult, dummyError); + } + + // Test returning an error Result + TEST(ResultBothPointerWithConstResult, ReturningError) { + auto CreateError = []() -> Result { + return {std::make_unique(dummyError)}; + }; + + Result result = CreateError(); + TestError(&result, dummyError); + } + + // Test constructing a success Result + TEST(ResultBothPointerWithConstResult, ConstructingSuccess) { + Result result(&dummyConstSuccess); + TestSuccess(&result, &dummyConstSuccess); + } + + // Test moving a success Result + TEST(ResultBothPointerWithConstResult, MovingSuccess) { + Result result(&dummyConstSuccess); + Result movedResult(std::move(result)); + TestSuccess(&movedResult, &dummyConstSuccess); + } + + // Test returning a success Result + TEST(ResultBothPointerWithConstResult, ReturningSuccess) { + auto CreateSuccess = []() -> Result { return {&dummyConstSuccess}; }; + + Result result = CreateSuccess(); + TestSuccess(&result, &dummyConstSuccess); + } + + // Result, E> + + // Test constructing an error Result, E> + TEST(ResultRefT, ConstructingError) { + Result, int> result(std::make_unique(dummyError)); + TestError(&result, dummyError); + } + + // Test moving an error Result, E> + TEST(ResultRefT, MovingError) { + Result, int> result(std::make_unique(dummyError)); + Result, int> movedResult(std::move(result)); + TestError(&movedResult, dummyError); + } + + // Test returning an error Result, E> + TEST(ResultRefT, ReturningError) { + auto CreateError = []() -> Result, int> { + return {std::make_unique(dummyError)}; + }; + + Result, int> result = CreateError(); + TestError(&result, dummyError); + } + + // Test constructing a success Result, E> + TEST(ResultRefT, ConstructingSuccess) { + AClass success; + + Ref refObj(&success); + Result, int> result(std::move(refObj)); + TestSuccess(&result, &success); + } + + // Test moving a success Result, E> + TEST(ResultRefT, MovingSuccess) { + AClass success; + + Ref refObj(&success); + Result, int> result(std::move(refObj)); + Result, int> movedResult(std::move(result)); + TestSuccess(&movedResult, &success); + } + + // Test returning a success Result, E> + TEST(ResultRefT, ReturningSuccess) { + AClass success; + auto CreateSuccess = [&success]() -> Result, int> { + return Ref(&success); + }; + + Result, int> result = CreateSuccess(); + TestSuccess(&result, &success); + } + + class OtherClass { + public: + int a = 0; }; + class Base : public RefCounted {}; + class Child : public OtherClass, public Base {}; - Result result = CreateError(); - TestError(&result, dummyError); -} + // Test constructing a Result, E> + TEST(ResultRefT, ConversionFromChildConstructor) { + Child child; + Ref refChild(&child); -// Test constructing a success Result -TEST(ResultBothPointerWithConstResult, ConstructingSuccess) { - Result result(&dummyConstSuccess); - TestSuccess(&result, &dummyConstSuccess); -} + Result, int> result(std::move(refChild)); + TestSuccess(&result, &child); + } -// Test moving a success Result -TEST(ResultBothPointerWithConstResult, MovingSuccess) { - Result result(&dummyConstSuccess); - Result movedResult(std::move(result)); - TestSuccess(&movedResult, &dummyConstSuccess); -} + // Test copy constructing Result, E> + TEST(ResultRefT, ConversionFromChildCopyConstructor) { + Child child; + Ref refChild(&child); -// Test returning a success Result -TEST(ResultBothPointerWithConstResult, ReturningSuccess) { - auto CreateSuccess = []() -> Result { return {&dummyConstSuccess}; }; + Result, int> resultChild(std::move(refChild)); + Result, int> result(std::move(resultChild)); + TestSuccess(&result, &child); + } - Result result = CreateSuccess(); - TestSuccess(&result, &dummyConstSuccess); -} + // Test assignment operator for Result, E> + TEST(ResultRefT, ConversionFromChildAssignmentOperator) { + Child child; + Ref refChild(&child); -// Result, E> + Result, int> resultChild(std::move(refChild)); + Result, int> result = std::move(resultChild); + TestSuccess(&result, &child); + } -// Test constructing an error Result, E> -TEST(ResultRefT, ConstructingError) { - Result, int> result(std::make_unique(dummyError)); - TestError(&result, dummyError); -} + // Result -// Test moving an error Result, E> -TEST(ResultRefT, MovingError) { - Result, int> result(std::make_unique(dummyError)); - Result, int> movedResult(std::move(result)); - TestError(&movedResult, dummyError); -} + // Test constructing an error Result + TEST(ResultGeneric, ConstructingError) { + Result, int> result(std::make_unique(dummyError)); + TestError(&result, dummyError); + } -// Test returning an error Result, E> -TEST(ResultRefT, ReturningError) { - auto CreateError = []() -> Result, int> { - return {std::make_unique(dummyError)}; - }; + // Test moving an error Result + TEST(ResultGeneric, MovingError) { + Result, int> result(std::make_unique(dummyError)); + Result, int> movedResult(std::move(result)); + TestError(&movedResult, dummyError); + } - Result, int> result = CreateError(); - TestError(&result, dummyError); -} + // Test returning an error Result + TEST(ResultGeneric, ReturningError) { + auto CreateError = []() -> Result, int> { + return {std::make_unique(dummyError)}; + }; -// Test constructing a success Result, E> -TEST(ResultRefT, ConstructingSuccess) { - AClass success; + Result, int> result = CreateError(); + TestError(&result, dummyError); + } - Ref refObj(&success); - Result, int> result(std::move(refObj)); - TestSuccess(&result, &success); -} + // Test constructing a success Result + TEST(ResultGeneric, ConstructingSuccess) { + Result, int> result({1.0f}); + TestSuccess(&result, {1.0f}); + } -// Test moving a success Result, E> -TEST(ResultRefT, MovingSuccess) { - AClass success; + // Test moving a success Result + TEST(ResultGeneric, MovingSuccess) { + Result, int> result({1.0f}); + Result, int> movedResult(std::move(result)); + TestSuccess(&movedResult, {1.0f}); + } - Ref refObj(&success); - Result, int> result(std::move(refObj)); - Result, int> movedResult(std::move(result)); - TestSuccess(&movedResult, &success); -} + // Test returning a success Result + TEST(ResultGeneric, ReturningSuccess) { + auto CreateSuccess = []() -> Result, int> { return {{1.0f}}; }; -// Test returning a success Result, E> -TEST(ResultRefT, ReturningSuccess) { - AClass success; - auto CreateSuccess = [&success]() -> Result, int> { return Ref(&success); }; - - Result, 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, E> -TEST(ResultRefT, ConversionFromChildConstructor) { - Child child; - Ref refChild(&child); - - Result, int> result(std::move(refChild)); - TestSuccess(&result, &child); -} - -// Test copy constructing Result, E> -TEST(ResultRefT, ConversionFromChildCopyConstructor) { - Child child; - Ref refChild(&child); - - Result, int> resultChild(std::move(refChild)); - Result, int> result(std::move(resultChild)); - TestSuccess(&result, &child); -} - -// Test assignment operator for Result, E> -TEST(ResultRefT, ConversionFromChildAssignmentOperator) { - Child child; - Ref refChild(&child); - - Result, int> resultChild(std::move(refChild)); - Result, int> result = std::move(resultChild); - TestSuccess(&result, &child); -} - -// Result - -// Test constructing an error Result -TEST(ResultGeneric, ConstructingError) { - Result, int> result(std::make_unique(dummyError)); - TestError(&result, dummyError); -} - -// Test moving an error Result -TEST(ResultGeneric, MovingError) { - Result, int> result(std::make_unique(dummyError)); - Result, int> movedResult(std::move(result)); - TestError(&movedResult, dummyError); -} - -// Test returning an error Result -TEST(ResultGeneric, ReturningError) { - auto CreateError = []() -> Result, int> { - return {std::make_unique(dummyError)}; - }; - - Result, int> result = CreateError(); - TestError(&result, dummyError); -} - -// Test constructing a success Result -TEST(ResultGeneric, ConstructingSuccess) { - Result, int> result({1.0f}); - TestSuccess(&result, {1.0f}); -} - -// Test moving a success Result -TEST(ResultGeneric, MovingSuccess) { - Result, int> result({1.0f}); - Result, int> movedResult(std::move(result)); - TestSuccess(&movedResult, {1.0f}); -} - -// Test returning a success Result -TEST(ResultGeneric, ReturningSuccess) { - auto CreateSuccess = []() -> Result, int> { return {{1.0f}}; }; - - Result, int> result = CreateSuccess(); - TestSuccess(&result, {1.0f}); -} + Result, int> result = CreateSuccess(); + TestSuccess(&result, {1.0f}); + } } // anonymous namespace diff --git a/src/tests/unittests/RingBufferAllocatorTests.cpp b/src/tests/unittests/RingBufferAllocatorTests.cpp index a3e5a62134..f0c256b358 100644 --- a/src/tests/unittests/RingBufferAllocatorTests.cpp +++ b/src/tests/unittests/RingBufferAllocatorTests.cpp @@ -174,4 +174,4 @@ TEST(RingBufferAllocatorTests, RingBufferOverflow) { ASSERT_EQ(allocator.Allocate(1, serial), 0u); ASSERT_EQ(allocator.Allocate(std::numeric_limits::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 6f75eb78ae..2545c51929 100644 --- a/src/tests/unittests/SerialQueueTests.cpp +++ b/src/tests/unittests/SerialQueueTests.cpp @@ -153,4 +153,4 @@ TEST(SerialQueue, LastSerial) { 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 c537a8e959..5234e40f18 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 +template auto ToBackend(T&& common) -> decltype(ToBackendBase(common)) { return ToBackendBase(common); } @@ -71,7 +69,8 @@ TEST(ToBackend, Ref) { const Ref base(cmdBuf); const auto& backendCmdBuf = ToBackend(base); - static_assert(std::is_same&>::value, ""); + static_assert(std::is_same&>::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 46f7047b4c..f867fefc39 100644 --- a/src/tests/unittests/d3d12/CopySplitTests.cpp +++ b/src/tests/unittests/d3d12/CopySplitTests.cpp @@ -55,7 +55,8 @@ namespace { // 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 @@ namespace { 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 @@ namespace { 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 @@ namespace { } // 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 @@ namespace { } } - 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 @@ namespace { 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 @@ namespace { } // 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 @@ TEST_F(CopySplitTest, TextureWidth) { } 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 @@ TEST_F(CopySplitTest, TextureHeight) { } 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 @@ TEST_F(CopySplitTest, TextureX) { 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 @@ TEST_F(CopySplitTest, TextureY) { 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 @@ TEST_F(CopySplitTest, TexelSize) { 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 @@ TEST_F(CopySplitTest, BufferOffset) { 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 @@ TEST_F(CopySplitTest, RowPitch) { 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 6dec9764f6..9b3aeb5567 100644 --- a/src/tests/unittests/validation/BindGroupValidationTests.cpp +++ b/src/tests/unittests/validation/BindGroupValidationTests.cpp @@ -121,16 +121,10 @@ TEST_F(BindGroupValidationTest, BindingSetTwice) { {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 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) { 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 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) { 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 @@ TEST_F(SetBindGroupValidationTest, DynamicOffsetOrder) { // 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 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest { wgpu::RenderPipeline CreateFSRenderPipeline( const char* fsShader, std::vector bindGroupLayout) { - wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, utils::SingleShaderStage::Vertex, R"( #version 450 @@ -1520,7 +1514,7 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest { layout(location = 0) out vec4 fragColor; void main() { })", - std::move(bindGroupLayout)); + std::move(bindGroupLayout)); } wgpu::ComputePipeline CreateComputePipeline( @@ -1558,7 +1552,7 @@ class BindGroupLayoutCompatibilityTest : public ValidationTest { } 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 f807b52322..a724057111 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; @@ -41,11 +41,11 @@ static void ToMockBufferMapReadCallback(WGPUBufferMapAsyncStatus status, } 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; @@ -59,57 +59,57 @@ static void ToMockBufferMapWriteCallback(WGPUBufferMapAsyncStatus status, } 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(); - mockBufferMapWriteCallback = std::make_unique(); - queue = device.GetDefaultQueue(); - } + mockBufferMapReadCallback = std::make_unique(); + mockBufferMapWriteCallback = std::make_unique(); + 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 @@ TEST_F(BufferValidationTest, UnmapInsideMapWriteCallback) { 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 @@ TEST_F(BufferValidationTest, DestroyInsideMapReadCallback) { 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 e8909ac5a9..e31879bcb6 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 fded92564f..8135997c99 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 1cd9e281ed..e5877af1f4 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -1168,8 +1168,8 @@ TEST_F(CopyCommandTest_T2T, 2DTextureDepthStencil) { 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 @@ TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) { } { - 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 @@ 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, 3, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst); @@ -1659,4 +1659,4 @@ TEST_F(CopyCommandTest_CompressedTextureFormats, CopyToMultipleArrayLayers) { {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 62e9ca9e2b..cc166400a7 100644 --- a/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp +++ b/src/tests/unittests/validation/DynamicStateCommandValidationTests.cpp @@ -223,8 +223,7 @@ TEST_F(SetViewportTest, MinDepthEqualOrGreaterThanMaxDepth) { } } -class SetScissorRectTest : public ValidationTest { -}; +class SetScissorRectTest : public ValidationTest {}; // Test to check basic use of SetScissor TEST_F(SetScissorRectTest, Success) { @@ -284,8 +283,7 @@ TEST_F(SetScissorRectTest, ScissorLargerThanFramebuffer) { 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 @@ TEST_F(SetBlendColorTest, AnyValueAllowed) { 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 566c7469bd..8779ce3413 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) { - 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 - { + // 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; - 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 039da1128f..c238acf3e7 100644 --- a/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp +++ b/src/tests/unittests/validation/QueueWriteTextureValidationTests.cpp @@ -636,4 +636,4 @@ namespace { } } -} // 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 7c9b11b256..5b99a1fc63 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 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 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 867cd116e8..19cc817e81 100644 --- a/src/tests/unittests/validation/RenderPipelineValidationTests.cpp +++ b/src/tests/unittests/validation/RenderPipelineValidationTests.cpp @@ -22,26 +22,26 @@ #include 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 bb08ecc702..1e570eb421 100644 --- a/src/tests/unittests/validation/ShaderModuleValidationTests.cpp +++ b/src/tests/unittests/validation/ShaderModuleValidationTests.cpp @@ -20,8 +20,7 @@ #include -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_F(ShaderModuleValidationTest, FragmentOutputLocationExceedsMaxColorAttachme // 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 c3d9612338..52dc1597fa 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 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 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 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 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 32bf7a39a4..c5c324220c 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 950c889814..b0f489f5fe 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 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 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 @@ TEST_F(ToggleValidationTest, OverrideToggleUsage) { } 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 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 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 21f028ad94..6b533b4ef8 100644 --- a/src/tests/unittests/validation/ValidationTest.cpp +++ b/src/tests/unittests/validation/ValidationTest.cpp @@ -27,7 +27,7 @@ ValidationTest::ValidationTest() { // 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 @@ ValidationTest::DummyRenderPass::DummyRenderPass(const wgpu::Device& device) 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 7862b4c96d..c922dd634a 100644 --- a/src/tests/unittests/validation/ValidationTest.h +++ b/src/tests/unittests/validation/ValidationTest.h @@ -70,4 +70,4 @@ class ValidationTest : public testing::Test { 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 9c67a0fd7b..4c8722ed58 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 2185028f99..95685cf4f2 100644 --- a/src/tests/unittests/wire/WireArgumentTests.cpp +++ b/src/tests/unittests/wire/WireArgumentTests.cpp @@ -185,7 +185,6 @@ TEST_F(WireArgumentTests, CStringArgument) { 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 1307b95850..990a3000e7 100644 --- a/src/tests/unittests/wire/WireBufferMappingTests.cpp +++ b/src/tests/unittests/wire/WireBufferMappingTests.cpp @@ -613,4 +613,3 @@ TEST_F(WireBufferMappingTests, CreateBufferMappedThenMapFailure) { FlushClient(); } - diff --git a/src/tests/unittests/wire/WireErrorCallbackTests.cpp b/src/tests/unittests/wire/WireErrorCallbackTests.cpp index 6f31977ec6..3fe25f0171 100644 --- a/src/tests/unittests/wire/WireErrorCallbackTests.cpp +++ b/src/tests/unittests/wire/WireErrorCallbackTests.cpp @@ -64,7 +64,8 @@ class WireErrorCallbackTests : public WireTest { WireTest::SetUp(); mockDeviceErrorCallback = std::make_unique>(); - mockDevicePopErrorScopeCallback = std::make_unique>(); + mockDevicePopErrorScopeCallback = + std::make_unique>(); mockDeviceLostCallback = std::make_unique>(); } @@ -206,8 +207,7 @@ TEST_F(WireErrorCallbackTests, PopErrorScopeDeviceDestroyed) { 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 78f9de737b..d36fc5f7f2 100644 --- a/src/tests/unittests/wire/WireExtensionTests.cpp +++ b/src/tests/unittests/wire/WireExtensionTests.cpp @@ -40,8 +40,9 @@ TEST_F(WireExtensionTests, ChainedStruct) { .WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler { EXPECT_STREQ(serverDesc->label, clientDesc.label); - const auto* ext = reinterpret_cast( - serverDesc->nextInChain); + const auto* ext = + reinterpret_cast( + serverDesc->nextInChain); EXPECT_EQ(ext->chain.sType, clientExt.chain.sType); EXPECT_EQ(ext->maxAnisotropy, clientExt.maxAnisotropy); @@ -73,13 +74,15 @@ TEST_F(WireExtensionTests, MutlipleChainedStructs) { .WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler { EXPECT_STREQ(serverDesc->label, clientDesc.label); - const auto* ext1 = reinterpret_cast( - serverDesc->nextInChain); + const auto* ext1 = + reinterpret_cast( + serverDesc->nextInChain); EXPECT_EQ(ext1->chain.sType, clientExt1.chain.sType); EXPECT_EQ(ext1->maxAnisotropy, clientExt1.maxAnisotropy); - const auto* ext2 = reinterpret_cast( - ext1->chain.next); + const auto* ext2 = + reinterpret_cast( + ext1->chain.next); EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType); EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy); @@ -99,13 +102,15 @@ TEST_F(WireExtensionTests, MutlipleChainedStructs) { .WillOnce(Invoke([&](Unused, const WGPUSamplerDescriptor* serverDesc) -> WGPUSampler { EXPECT_STREQ(serverDesc->label, clientDesc.label); - const auto* ext2 = reinterpret_cast( - serverDesc->nextInChain); + const auto* ext2 = + reinterpret_cast( + serverDesc->nextInChain); EXPECT_EQ(ext2->chain.sType, clientExt2.chain.sType); EXPECT_EQ(ext2->maxAnisotropy, clientExt2.maxAnisotropy); - const auto* ext1 = reinterpret_cast( - ext2->chain.next); + const auto* ext1 = + reinterpret_cast( + 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 bb1efb6b10..026b52eeef 100644 --- a/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp +++ b/src/tests/unittests/wire/WireMemoryTransferServiceTests.cpp @@ -180,9 +180,7 @@ class WireMemoryTransferServiceTests : public WireTest { ClientReadHandle* handle = clientMemoryTransferService.NewReadHandle(); EXPECT_CALL(clientMemoryTransferService, OnCreateReadHandle(sizeof(mBufferContent))) - .WillOnce(InvokeWithoutArgs([=]() { - return handle; - })); + .WillOnce(InvokeWithoutArgs([=]() { return handle; })); return handle; } @@ -259,9 +257,7 @@ class WireMemoryTransferServiceTests : public WireTest { ClientWriteHandle* handle = clientMemoryTransferService.NewWriteHandle(); EXPECT_CALL(clientMemoryTransferService, OnCreateWriteHandle(sizeof(mBufferContent))) - .WillOnce(InvokeWithoutArgs([=]() { - return handle; - })); + .WillOnce(InvokeWithoutArgs([=]() { return handle; })); return handle; } @@ -300,22 +296,18 @@ class WireMemoryTransferServiceTests : public WireTest { 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 @@ class WireMemoryTransferServiceTests : public WireTest { // 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 @@ class WireMemoryTransferServiceTests : public WireTest { // 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 serverMemoryTransferService; diff --git a/src/tests/unittests/wire/WireTest.h b/src/tests/unittests/wire/WireTest.h index 7a8ed5a6ed..d4537d67e0 100644 --- a/src/tests/unittests/wire/WireTest.h +++ b/src/tests/unittests/wire/WireTest.h @@ -68,9 +68,11 @@ inline testing::Matcher> MatchesLambda(Lambda lamb class StringMessageMatcher : public testing::MatcherInterface { 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 @@ class StringMessageMatcher : public testing::MatcherInterface { } 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"; } };