2018-07-18 09:40:26 +00:00
|
|
|
// Copyright 2017 The Dawn Authors
|
2017-06-16 22:34:35 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
#include "tests/DawnTest.h"
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2017-07-10 17:46:05 +00:00
|
|
|
#include "common/Assert.h"
|
2017-07-13 19:10:30 +00:00
|
|
|
#include "common/Constants.h"
|
|
|
|
#include "common/Math.h"
|
2018-09-19 00:32:52 +00:00
|
|
|
#include "common/Platform.h"
|
2018-08-02 20:27:57 +00:00
|
|
|
#include "dawn_native/DawnNative.h"
|
2018-07-26 13:07:57 +00:00
|
|
|
#include "dawn_wire/Wire.h"
|
2017-06-16 22:34:35 +00:00
|
|
|
#include "utils/BackendBinding.h"
|
2018-07-18 12:00:56 +00:00
|
|
|
#include "utils/DawnHelpers.h"
|
2017-07-17 21:13:57 +00:00
|
|
|
#include "utils/SystemUtils.h"
|
2018-07-26 13:07:57 +00:00
|
|
|
#include "utils/TerribleCommandBuffer.h"
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-01-19 17:53:46 +00:00
|
|
|
#include <iostream>
|
2019-02-05 12:17:20 +00:00
|
|
|
#include <unordered_map>
|
2017-06-16 22:34:35 +00:00
|
|
|
#include "GLFW/glfw3.h"
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
namespace {
|
|
|
|
|
2019-02-05 12:17:20 +00:00
|
|
|
std::string ParamName(dawn_native::BackendType type) {
|
2018-07-18 13:18:25 +00:00
|
|
|
switch (type) {
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::D3D12:
|
2017-06-16 22:34:35 +00:00
|
|
|
return "D3D12";
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::Metal:
|
2017-06-16 22:34:35 +00:00
|
|
|
return "Metal";
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::Null:
|
|
|
|
return "Null";
|
|
|
|
case dawn_native::BackendType::OpenGL:
|
2017-06-16 22:34:35 +00:00
|
|
|
return "OpenGL";
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::Vulkan:
|
2017-06-16 22:34:35 +00:00
|
|
|
return "Vulkan";
|
|
|
|
default:
|
2017-07-11 01:48:12 +00:00
|
|
|
UNREACHABLE();
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Windows don't usually like to be bound to one API than the other, for example switching
|
|
|
|
// from Vulkan to OpenGL causes crashes on some drivers. Because of this, we lazily created
|
|
|
|
// a window for each backing API.
|
2019-02-05 12:17:20 +00:00
|
|
|
std::unordered_map<dawn_native::BackendType, GLFWwindow*> windows;
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
// Creates a GLFW window set up for use with a given backend.
|
2019-02-05 12:17:20 +00:00
|
|
|
GLFWwindow* GetWindowForBackend(utils::BackendBinding* binding, dawn_native::BackendType type) {
|
2017-06-16 22:34:35 +00:00
|
|
|
GLFWwindow** window = &windows[type];
|
|
|
|
|
|
|
|
if (*window != nullptr) {
|
|
|
|
return *window;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!glfwInit()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwDefaultWindowHints();
|
|
|
|
binding->SetupGLFWWindowHints();
|
|
|
|
|
2018-07-18 13:32:04 +00:00
|
|
|
std::string windowName = "Dawn " + ParamName(type) + " test window";
|
2017-06-16 22:34:35 +00:00
|
|
|
*window = glfwCreateWindow(400, 400, windowName.c_str(), nullptr, nullptr);
|
|
|
|
|
|
|
|
return *window;
|
|
|
|
}
|
|
|
|
|
|
|
|
// End2end tests should test valid commands produce the expected result so no error
|
|
|
|
// should happen. Failure cases should be tested in the validation tests.
|
2018-07-18 13:12:52 +00:00
|
|
|
void DeviceErrorCauseTestFailure(const char* message, dawnCallbackUserdata) {
|
2018-07-18 13:18:25 +00:00
|
|
|
FAIL() << "Device level failure: " << message;
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct MapReadUserdata {
|
2018-07-18 13:18:25 +00:00
|
|
|
DawnTest* test;
|
2017-06-16 22:34:35 +00:00
|
|
|
size_t slot;
|
|
|
|
};
|
2018-10-16 09:16:15 +00:00
|
|
|
|
|
|
|
constexpr uint32_t kVendorID_AMD = 0x1002;
|
|
|
|
constexpr uint32_t kVendorID_ARM = 0x13B5;
|
|
|
|
constexpr uint32_t kVendorID_ImgTec = 0x1010;
|
|
|
|
constexpr uint32_t kVendorID_Intel = 0x8086;
|
|
|
|
constexpr uint32_t kVendorID_Nvidia = 0x10DE;
|
|
|
|
constexpr uint32_t kVendorID_Qualcomm = 0x5143;
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
} // namespace
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-09-06 13:26:48 +00:00
|
|
|
DawnTest::DawnTest() = default;
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
DawnTest::~DawnTest() {
|
2017-06-16 22:34:35 +00:00
|
|
|
// We need to destroy child objects before the Device
|
2017-11-23 19:51:16 +00:00
|
|
|
mReadbackSlots.clear();
|
2018-07-18 11:43:49 +00:00
|
|
|
queue = dawn::Queue();
|
|
|
|
swapchain = dawn::SwapChain();
|
|
|
|
device = dawn::Device();
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:15:07 +00:00
|
|
|
dawnSetProcs(nullptr);
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
bool DawnTest::IsD3D12() const {
|
2017-07-13 00:36:36 +00:00
|
|
|
return GetParam() == D3D12Backend;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
bool DawnTest::IsMetal() const {
|
2017-07-18 14:31:50 +00:00
|
|
|
return GetParam() == MetalBackend;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
bool DawnTest::IsOpenGL() const {
|
2017-07-18 14:31:50 +00:00
|
|
|
return GetParam() == OpenGLBackend;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
bool DawnTest::IsVulkan() const {
|
2017-07-18 14:31:50 +00:00
|
|
|
return GetParam() == VulkanBackend;
|
|
|
|
}
|
|
|
|
|
2018-09-19 00:32:52 +00:00
|
|
|
bool DawnTest::IsAMD() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_AMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsARM() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_ARM;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsImgTec() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_ImgTec;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsIntel() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_Intel;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsNvidia() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_Nvidia;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsQualcomm() const {
|
|
|
|
return mPCIInfo.vendorId == kVendorID_Qualcomm;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsWindows() const {
|
|
|
|
#ifdef DAWN_PLATFORM_WINDOWS
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsLinux() const {
|
|
|
|
#ifdef DAWN_PLATFORM_LINUX
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DawnTest::IsMacOS() const {
|
|
|
|
#ifdef DAWN_PLATFORM_APPLE
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
bool gTestUsesWire = false;
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::SetUp() {
|
2019-02-05 12:17:20 +00:00
|
|
|
mBinding.reset(utils::CreateBinding(GetParam()));
|
2018-07-18 11:37:54 +00:00
|
|
|
DAWN_ASSERT(mBinding != nullptr);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-09-06 13:26:48 +00:00
|
|
|
GLFWwindow* testWindow = GetWindowForBackend(mBinding.get(), GetParam());
|
2018-07-18 11:37:54 +00:00
|
|
|
DAWN_ASSERT(testWindow != nullptr);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
mBinding->SetWindow(testWindow);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-08-02 20:27:57 +00:00
|
|
|
dawnDevice backendDevice = mBinding->CreateDevice();
|
|
|
|
dawnProcTable backendProcs = dawn_native::GetProcs();
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// Choose whether to use the backend procs and devices directly, or set up the wire.
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnDevice cDevice = nullptr;
|
2018-07-18 13:15:07 +00:00
|
|
|
dawnProcTable procs;
|
2018-06-07 11:10:44 +00:00
|
|
|
|
|
|
|
if (gTestUsesWire) {
|
2018-09-06 13:26:48 +00:00
|
|
|
mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>();
|
|
|
|
mS2cBuf = std::make_unique<utils::TerribleCommandBuffer>();
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2018-09-06 13:26:48 +00:00
|
|
|
mWireServer.reset(
|
|
|
|
dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, mS2cBuf.get()));
|
|
|
|
mC2sBuf->SetHandler(mWireServer.get());
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2018-07-18 13:12:52 +00:00
|
|
|
dawnDevice clientDevice;
|
2018-07-18 13:15:07 +00:00
|
|
|
dawnProcTable clientProcs;
|
2018-09-06 13:26:48 +00:00
|
|
|
mWireClient.reset(dawn_wire::NewClientDevice(&clientProcs, &clientDevice, mC2sBuf.get()));
|
|
|
|
mS2cBuf->SetHandler(mWireClient.get());
|
2018-06-07 11:10:44 +00:00
|
|
|
|
|
|
|
procs = clientProcs;
|
|
|
|
cDevice = clientDevice;
|
|
|
|
} else {
|
|
|
|
procs = backendProcs;
|
|
|
|
cDevice = backendDevice;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
// Set up the device and queue because all tests need them, and DawnTest needs them too for the
|
2018-06-07 11:10:44 +00:00
|
|
|
// deferred expectations.
|
2018-07-18 13:15:07 +00:00
|
|
|
dawnSetProcs(&procs);
|
2018-07-18 11:43:49 +00:00
|
|
|
device = dawn::Device::Acquire(cDevice);
|
2018-06-15 00:26:27 +00:00
|
|
|
queue = device.CreateQueue();
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// The swapchain isn't used by tests but is useful when debugging with graphics debuggers that
|
|
|
|
// capture at frame boundaries.
|
2017-07-28 01:30:57 +00:00
|
|
|
swapchain = device.CreateSwapChainBuilder()
|
2018-07-18 13:18:25 +00:00
|
|
|
.SetImplementation(mBinding->GetSwapChainImplementation())
|
|
|
|
.GetResult();
|
|
|
|
swapchain.Configure(
|
|
|
|
static_cast<dawn::TextureFormat>(mBinding->GetPreferredSwapChainTextureFormat()),
|
|
|
|
dawn::TextureUsageBit::OutputAttachment, 400, 400);
|
2017-07-28 01:30:57 +00:00
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// The end2end tests should never cause validation errors. These should be tested in unittests.
|
2017-06-16 22:34:35 +00:00
|
|
|
device.SetErrorCallback(DeviceErrorCauseTestFailure, 0);
|
2018-09-19 00:32:52 +00:00
|
|
|
|
|
|
|
mPCIInfo = dawn_native::GetPCIInfo(backendDevice);
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::TearDown() {
|
2018-06-07 11:10:44 +00:00
|
|
|
FlushWire();
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
MapSlotsSynchronously();
|
|
|
|
ResolveExpectations();
|
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
for (size_t i = 0; i < mReadbackSlots.size(); ++i) {
|
|
|
|
mReadbackSlots[i].buffer.Unmap();
|
2017-07-25 15:29:28 +00:00
|
|
|
}
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
std::ostringstream& DawnTest::AddBufferExpectation(const char* file,
|
|
|
|
int line,
|
|
|
|
const dawn::Buffer& buffer,
|
|
|
|
uint32_t offset,
|
|
|
|
uint32_t size,
|
|
|
|
detail::Expectation* expectation) {
|
2017-06-16 22:34:35 +00:00
|
|
|
auto readback = ReserveReadback(size);
|
|
|
|
|
|
|
|
// We need to enqueue the copy immediately because by the time we resolve the expectation,
|
|
|
|
// the buffer might have been modified.
|
2018-07-18 13:18:25 +00:00
|
|
|
dawn::CommandBuffer commands =
|
|
|
|
device.CreateCommandBufferBuilder()
|
2018-10-25 10:42:49 +00:00
|
|
|
.CopyBufferToBuffer(buffer, offset, readback.buffer, readback.offset, size)
|
2018-07-18 13:18:25 +00:00
|
|
|
.GetResult();
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
queue.Submit(1, &commands);
|
|
|
|
|
|
|
|
DeferredExpectation deferred;
|
|
|
|
deferred.file = file;
|
|
|
|
deferred.line = line;
|
|
|
|
deferred.readbackSlot = readback.slot;
|
|
|
|
deferred.readbackOffset = readback.offset;
|
|
|
|
deferred.size = size;
|
2017-07-13 19:10:30 +00:00
|
|
|
deferred.rowBytes = size;
|
|
|
|
deferred.rowPitch = size;
|
2018-09-06 13:26:48 +00:00
|
|
|
deferred.expectation.reset(expectation);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
mDeferredExpectations.push_back(std::move(deferred));
|
|
|
|
mDeferredExpectations.back().message = std::make_unique<std::ostringstream>();
|
|
|
|
return *(mDeferredExpectations.back().message.get());
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
std::ostringstream& DawnTest::AddTextureExpectation(const char* file,
|
|
|
|
int line,
|
|
|
|
const dawn::Texture& texture,
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t level,
|
2018-12-05 03:22:04 +00:00
|
|
|
uint32_t slice,
|
2018-07-18 13:18:25 +00:00
|
|
|
uint32_t pixelSize,
|
|
|
|
detail::Expectation* expectation) {
|
2017-07-13 19:10:30 +00:00
|
|
|
uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment);
|
|
|
|
uint32_t size = rowPitch * (height - 1) + width * pixelSize;
|
2017-06-27 04:11:16 +00:00
|
|
|
|
|
|
|
auto readback = ReserveReadback(size);
|
|
|
|
|
|
|
|
// We need to enqueue the copy immediately because by the time we resolve the expectation,
|
|
|
|
// the texture might have been modified.
|
2018-11-28 17:54:13 +00:00
|
|
|
dawn::TextureCopyView textureCopyView =
|
2018-12-12 09:27:46 +00:00
|
|
|
utils::CreateTextureCopyView(texture, level, slice, {x, y, 0});
|
2018-11-28 17:54:13 +00:00
|
|
|
dawn::BufferCopyView bufferCopyView =
|
|
|
|
utils::CreateBufferCopyView(readback.buffer, readback.offset, rowPitch, 0);
|
|
|
|
dawn::Extent3D copySize = {width, height, 1};
|
2018-07-18 13:18:25 +00:00
|
|
|
dawn::CommandBuffer commands =
|
|
|
|
device.CreateCommandBufferBuilder()
|
2018-11-28 17:54:13 +00:00
|
|
|
.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size)
|
2018-07-18 13:18:25 +00:00
|
|
|
.GetResult();
|
2017-06-27 04:11:16 +00:00
|
|
|
|
|
|
|
queue.Submit(1, &commands);
|
|
|
|
|
|
|
|
DeferredExpectation deferred;
|
|
|
|
deferred.file = file;
|
|
|
|
deferred.line = line;
|
|
|
|
deferred.readbackSlot = readback.slot;
|
|
|
|
deferred.readbackOffset = readback.offset;
|
|
|
|
deferred.size = size;
|
2017-07-13 19:10:30 +00:00
|
|
|
deferred.rowBytes = width * pixelSize;
|
|
|
|
deferred.rowPitch = rowPitch;
|
2018-09-06 13:26:48 +00:00
|
|
|
deferred.expectation.reset(expectation);
|
2017-06-27 04:11:16 +00:00
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
mDeferredExpectations.push_back(std::move(deferred));
|
|
|
|
mDeferredExpectations.back().message = std::make_unique<std::ostringstream>();
|
|
|
|
return *(mDeferredExpectations.back().message.get());
|
2017-06-27 04:11:16 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::WaitABit() {
|
2017-07-17 21:13:57 +00:00
|
|
|
device.Tick();
|
2018-06-07 11:10:44 +00:00
|
|
|
FlushWire();
|
|
|
|
|
2017-07-17 21:13:57 +00:00
|
|
|
utils::USleep(100);
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::SwapBuffersForCapture() {
|
2017-07-28 01:30:57 +00:00
|
|
|
// Insert a frame boundary for API capture tools.
|
2018-07-18 11:43:49 +00:00
|
|
|
dawn::Texture backBuffer = swapchain.GetNextTexture();
|
2017-07-28 01:30:57 +00:00
|
|
|
swapchain.Present(backBuffer);
|
2017-07-12 17:17:35 +00:00
|
|
|
}
|
2017-06-27 04:11:16 +00:00
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::FlushWire() {
|
2018-06-07 11:10:44 +00:00
|
|
|
if (gTestUsesWire) {
|
2018-06-21 01:54:18 +00:00
|
|
|
ASSERT(mC2sBuf->Flush());
|
|
|
|
ASSERT(mS2cBuf->Flush());
|
2018-06-07 11:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
DawnTest::ReadbackReservation DawnTest::ReserveReadback(uint32_t readbackSize) {
|
2017-06-16 22:34:35 +00:00
|
|
|
// For now create a new MapRead buffer for each readback
|
|
|
|
// TODO(cwallez@chromium.org): eventually make bigger buffers and allocate linearly?
|
2018-08-22 13:37:29 +00:00
|
|
|
dawn::BufferDescriptor descriptor;
|
|
|
|
descriptor.size = readbackSize;
|
|
|
|
descriptor.usage = dawn::BufferUsageBit::MapRead | dawn::BufferUsageBit::TransferDst;
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
ReadbackSlot slot;
|
|
|
|
slot.bufferSize = readbackSize;
|
2018-08-22 13:37:29 +00:00
|
|
|
slot.buffer = device.CreateBuffer(&descriptor);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
ReadbackReservation reservation;
|
2018-10-25 10:42:49 +00:00
|
|
|
reservation.buffer = slot.buffer;
|
2017-11-23 19:51:16 +00:00
|
|
|
reservation.slot = mReadbackSlots.size();
|
2017-06-16 22:34:35 +00:00
|
|
|
reservation.offset = 0;
|
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
mReadbackSlots.push_back(std::move(slot));
|
2017-06-16 22:34:35 +00:00
|
|
|
return reservation;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::MapSlotsSynchronously() {
|
|
|
|
// Initialize numPendingMapOperations before mapping, just in case the callback is called
|
|
|
|
// immediately.
|
2017-11-23 19:51:16 +00:00
|
|
|
mNumPendingMapOperations = mReadbackSlots.size();
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
// Map all readback slots
|
2017-11-23 19:51:16 +00:00
|
|
|
for (size_t i = 0; i < mReadbackSlots.size(); ++i) {
|
2017-06-16 22:34:35 +00:00
|
|
|
auto userdata = new MapReadUserdata{this, i};
|
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
auto& slot = mReadbackSlots[i];
|
2018-07-18 13:18:25 +00:00
|
|
|
slot.buffer.MapReadAsync(
|
|
|
|
0, slot.bufferSize, SlotMapReadCallback,
|
|
|
|
static_cast<dawn::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata)));
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Busy wait until all map operations are done.
|
2017-11-23 19:51:16 +00:00
|
|
|
while (mNumPendingMapOperations != 0) {
|
2017-07-17 21:13:57 +00:00
|
|
|
WaitABit();
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::SlotMapReadCallback(dawnBufferMapAsyncStatus status,
|
|
|
|
const void* data,
|
|
|
|
dawnCallbackUserdata userdata_) {
|
2018-07-18 13:12:52 +00:00
|
|
|
DAWN_ASSERT(status == DAWN_BUFFER_MAP_ASYNC_STATUS_SUCCESS);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_));
|
2017-11-23 19:51:16 +00:00
|
|
|
userdata->test->mReadbackSlots[userdata->slot].mappedData = data;
|
2018-07-18 13:18:25 +00:00
|
|
|
userdata->test->mNumPendingMapOperations--;
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
delete userdata;
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
void DawnTest::ResolveExpectations() {
|
2017-11-23 19:51:16 +00:00
|
|
|
for (const auto& expectation : mDeferredExpectations) {
|
2018-07-18 11:37:54 +00:00
|
|
|
DAWN_ASSERT(mReadbackSlots[expectation.readbackSlot].mappedData != nullptr);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
// Get a pointer to the mapped copy of the data for the expectation.
|
2018-07-18 13:18:25 +00:00
|
|
|
const char* data =
|
|
|
|
reinterpret_cast<const char*>(mReadbackSlots[expectation.readbackSlot].mappedData);
|
2017-06-16 22:34:35 +00:00
|
|
|
data += expectation.readbackOffset;
|
|
|
|
|
2017-07-13 19:10:30 +00:00
|
|
|
uint32_t size;
|
|
|
|
std::vector<char> packedData;
|
|
|
|
if (expectation.rowBytes != expectation.rowPitch) {
|
2018-07-18 11:37:54 +00:00
|
|
|
DAWN_ASSERT(expectation.rowPitch > expectation.rowBytes);
|
2018-07-18 13:18:25 +00:00
|
|
|
uint32_t rowCount =
|
|
|
|
(expectation.size + expectation.rowPitch - 1) / expectation.rowPitch;
|
2017-07-13 19:10:30 +00:00
|
|
|
uint32_t packedSize = rowCount * expectation.rowBytes;
|
|
|
|
packedData.resize(packedSize);
|
|
|
|
for (uint32_t r = 0; r < rowCount; ++r) {
|
|
|
|
for (uint32_t i = 0; i < expectation.rowBytes; ++i) {
|
|
|
|
packedData[i + r * expectation.rowBytes] = data[i + r * expectation.rowPitch];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data = packedData.data();
|
|
|
|
size = packedSize;
|
|
|
|
} else {
|
|
|
|
size = expectation.size;
|
|
|
|
}
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
// Get the result for the expectation and add context to failures
|
2017-07-13 19:10:30 +00:00
|
|
|
testing::AssertionResult result = expectation.expectation->Check(data, size);
|
2017-06-16 22:34:35 +00:00
|
|
|
if (!result) {
|
2018-07-18 13:18:25 +00:00
|
|
|
result << " Expectation created at " << expectation.file << ":" << expectation.line
|
|
|
|
<< std::endl;
|
2017-07-17 13:37:08 +00:00
|
|
|
result << expectation.message->str();
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_TRUE(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 04:11:16 +00:00
|
|
|
bool RGBA8::operator==(const RGBA8& other) const {
|
|
|
|
return r == other.r && g == other.g && b == other.b && a == other.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RGBA8::operator!=(const RGBA8& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const RGBA8& color) {
|
|
|
|
return stream << "RGBA8(" << static_cast<int>(color.r) << ", " << static_cast<int>(color.g)
|
|
|
|
<< ", " << static_cast<int>(color.b) << ", " << static_cast<int>(color.a) << ")";
|
2017-06-27 04:11:16 +00:00
|
|
|
}
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
namespace detail {
|
2019-02-05 12:17:20 +00:00
|
|
|
bool IsBackendAvailable(dawn_native::BackendType type) {
|
2017-07-12 16:43:24 +00:00
|
|
|
switch (type) {
|
2018-07-18 13:18:25 +00:00
|
|
|
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::D3D12:
|
2018-07-18 13:18:25 +00:00
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::Metal:
|
2018-07-18 13:18:25 +00:00
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_OPENGL)
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::OpenGL:
|
2018-07-18 13:18:25 +00:00
|
|
|
#endif
|
|
|
|
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
2019-02-05 12:17:20 +00:00
|
|
|
case dawn_native::BackendType::Vulkan:
|
2018-07-18 13:18:25 +00:00
|
|
|
#endif
|
2017-07-12 16:43:24 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 12:17:20 +00:00
|
|
|
std::vector<dawn_native::BackendType> FilterBackends(const dawn_native::BackendType* types,
|
|
|
|
size_t numParams) {
|
|
|
|
std::vector<dawn_native::BackendType> backends;
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < numParams; ++i) {
|
|
|
|
if (IsBackendAvailable(types[i])) {
|
|
|
|
backends.push_back(types[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return backends;
|
|
|
|
}
|
|
|
|
|
2019-02-05 12:17:20 +00:00
|
|
|
std::string GetParamName(const testing::TestParamInfo<dawn_native::BackendType>& info) {
|
|
|
|
return ParamName(info.param);
|
|
|
|
}
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
// Helper classes to set expectations
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
template <typename T>
|
2017-06-16 22:34:35 +00:00
|
|
|
ExpectEq<T>::ExpectEq(T singleValue) {
|
2017-11-23 19:51:16 +00:00
|
|
|
mExpected.push_back(singleValue);
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
template <typename T>
|
2017-07-04 14:53:42 +00:00
|
|
|
ExpectEq<T>::ExpectEq(const T* values, const unsigned int count) {
|
2017-11-23 19:51:16 +00:00
|
|
|
mExpected.assign(values, values + count);
|
2017-07-04 14:53:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
template <typename T>
|
2017-06-16 22:34:35 +00:00
|
|
|
testing::AssertionResult ExpectEq<T>::Check(const void* data, size_t size) {
|
2018-07-18 11:37:54 +00:00
|
|
|
DAWN_ASSERT(size == sizeof(T) * mExpected.size());
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
const T* actual = reinterpret_cast<const T*>(data);
|
2017-07-17 13:37:46 +00:00
|
|
|
|
|
|
|
testing::AssertionResult failure = testing::AssertionFailure();
|
2017-11-23 19:51:16 +00:00
|
|
|
for (size_t i = 0; i < mExpected.size(); ++i) {
|
|
|
|
if (actual[i] != mExpected[i]) {
|
2018-07-18 13:18:25 +00:00
|
|
|
testing::AssertionResult result = testing::AssertionFailure()
|
|
|
|
<< "Expected data[" << i << "] to be "
|
|
|
|
<< mExpected[i] << ", actual " << actual[i]
|
|
|
|
<< std::endl;
|
2017-07-17 13:37:46 +00:00
|
|
|
|
|
|
|
auto printBuffer = [&](const T* buffer) {
|
|
|
|
static constexpr unsigned int kBytes = sizeof(T);
|
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
for (size_t index = 0; index < mExpected.size(); ++index) {
|
2017-07-17 13:37:46 +00:00
|
|
|
auto byteView = reinterpret_cast<const uint8_t*>(buffer + index);
|
|
|
|
for (unsigned int b = 0; b < kBytes; ++b) {
|
|
|
|
char buf[4];
|
|
|
|
sprintf(buf, "%02X ", byteView[b]);
|
|
|
|
result << buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result << std::endl;
|
|
|
|
};
|
|
|
|
|
2017-11-23 19:51:16 +00:00
|
|
|
if (mExpected.size() <= 1024) {
|
2017-07-17 13:37:46 +00:00
|
|
|
result << "Expected:" << std::endl;
|
2017-11-23 19:51:16 +00:00
|
|
|
printBuffer(mExpected.data());
|
2017-07-17 13:37:46 +00:00
|
|
|
|
|
|
|
result << "Actual:" << std::endl;
|
|
|
|
printBuffer(actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2017-06-16 22:34:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return testing::AssertionSuccess();
|
|
|
|
}
|
|
|
|
|
2018-02-04 16:07:02 +00:00
|
|
|
template class ExpectEq<uint8_t>;
|
2017-06-16 22:34:35 +00:00
|
|
|
template class ExpectEq<uint32_t>;
|
2017-06-27 04:11:16 +00:00
|
|
|
template class ExpectEq<RGBA8>;
|
2018-07-18 13:18:25 +00:00
|
|
|
} // namespace detail
|