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.
|
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
#ifndef TESTS_DAWNTEST_H_
|
|
|
|
#define TESTS_DAWNTEST_H_
|
|
|
|
|
2019-12-05 11:13:01 +00:00
|
|
|
#include "common/Log.h"
|
2019-10-15 11:44:38 +00:00
|
|
|
#include "dawn/dawn_proc_table.h"
|
2019-10-28 13:27:36 +00:00
|
|
|
#include "dawn/webgpu_cpp.h"
|
2018-09-19 00:32:52 +00:00
|
|
|
#include "dawn_native/DawnNative.h"
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2017-07-17 13:37:08 +00:00
|
|
|
#include <memory>
|
2019-02-21 16:29:12 +00:00
|
|
|
#include <unordered_map>
|
2019-05-29 00:07:37 +00:00
|
|
|
#include <vector>
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:28:38 +00:00
|
|
|
// Getting data back from Dawn is done in an async manners so all expectations are "deferred"
|
2017-06-16 22:34:35 +00:00
|
|
|
// until the end of the test. Also expectations use a copy to a MapRead buffer to get the data
|
2019-07-08 10:05:46 +00:00
|
|
|
// so resources should have the CopySrc allowed usage bit if you want to add expectations on
|
2018-07-18 13:18:25 +00:00
|
|
|
// them.
|
2020-06-08 12:18:21 +00:00
|
|
|
|
2020-08-04 06:41:56 +00:00
|
|
|
#define EXPECT_BUFFER(buffer, offset, size, expectation) \
|
|
|
|
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, size, expectation)
|
2020-06-08 12:18:21 +00:00
|
|
|
|
2020-08-04 06:41:56 +00:00
|
|
|
#define EXPECT_BUFFER_U16_EQ(expected, buffer, offset) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(uint16_t), new ::detail::ExpectEq<uint16_t>(expected))
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2020-08-04 06:41:56 +00:00
|
|
|
#define EXPECT_BUFFER_U16_RANGE_EQ(expected, buffer, offset, count) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(uint16_t) * (count), \
|
|
|
|
new ::detail::ExpectEq<uint16_t>(expected, count))
|
2017-07-04 14:53:42 +00:00
|
|
|
|
2020-08-04 06:41:56 +00:00
|
|
|
#define EXPECT_BUFFER_U32_EQ(expected, buffer, offset) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(uint32_t), new ::detail::ExpectEq<uint32_t>(expected))
|
2020-06-19 16:21:33 +00:00
|
|
|
|
2020-08-04 06:41:56 +00:00
|
|
|
#define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(uint32_t) * (count), \
|
|
|
|
new ::detail::ExpectEq<uint32_t>(expected, count))
|
|
|
|
|
|
|
|
#define EXPECT_BUFFER_U64_RANGE_EQ(expected, buffer, offset, count) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(uint64_t) * (count), \
|
|
|
|
new ::detail::ExpectEq<uint64_t>(expected, count))
|
|
|
|
|
|
|
|
#define EXPECT_BUFFER_FLOAT_EQ(expected, buffer, offset) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(float), new ::detail::ExpectEq<float>(expected))
|
|
|
|
|
|
|
|
#define EXPECT_BUFFER_FLOAT_RANGE_EQ(expected, buffer, offset, count) \
|
|
|
|
EXPECT_BUFFER(buffer, offset, sizeof(float) * (count), \
|
|
|
|
new ::detail::ExpectEq<float>(expected, count))
|
2020-06-19 16:21:33 +00:00
|
|
|
|
2017-06-27 04:11:16 +00:00
|
|
|
// Test a pixel of the mip level 0 of a 2D texture.
|
2020-08-04 19:46:37 +00:00
|
|
|
#define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, expected, texture, x, y)
|
2017-07-17 20:16:50 +00:00
|
|
|
|
2020-08-04 19:46:37 +00:00
|
|
|
#define EXPECT_TEXTURE_RGBA8_EQ(expected, texture, x, y, width, height, level, slice) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, expected, texture, x, y, width, height, level, slice)
|
2017-06-27 04:11:16 +00:00
|
|
|
|
2020-08-04 19:46:37 +00:00
|
|
|
#define EXPECT_PIXEL_FLOAT_EQ(expected, texture, x, y) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, expected, texture, x, y)
|
2020-01-16 00:12:10 +00:00
|
|
|
|
2020-08-04 19:46:37 +00:00
|
|
|
#define EXPECT_TEXTURE_FLOAT_EQ(expected, texture, x, y, width, height, level, slice) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, expected, texture, x, y, width, height, level, slice)
|
|
|
|
|
|
|
|
// TODO(enga): Migrate other texure expectation helpers to this common one.
|
|
|
|
#define EXPECT_TEXTURE_EQ(...) AddTextureExpectation(__FILE__, __LINE__, __VA_ARGS__)
|
2020-01-16 00:12:10 +00:00
|
|
|
|
2019-02-28 09:45:48 +00:00
|
|
|
// Should only be used to test validation of function that can't be tested by regular validation
|
|
|
|
// tests;
|
2020-04-16 21:36:33 +00:00
|
|
|
#define ASSERT_DEVICE_ERROR(statement) \
|
|
|
|
StartExpectDeviceError(); \
|
|
|
|
statement; \
|
|
|
|
FlushWire(); \
|
|
|
|
if (!EndExpectDeviceError()) { \
|
|
|
|
FAIL() << "Expected device error in:\n " << #statement; \
|
|
|
|
} \
|
|
|
|
do { \
|
|
|
|
} while (0)
|
2019-02-28 09:45:48 +00:00
|
|
|
|
2017-06-27 04:11:16 +00:00
|
|
|
struct RGBA8 {
|
2018-07-18 13:18:25 +00:00
|
|
|
constexpr RGBA8() : RGBA8(0, 0, 0, 0) {
|
|
|
|
}
|
|
|
|
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : r(r), g(g), b(b), a(a) {
|
2017-06-27 04:11:16 +00:00
|
|
|
}
|
|
|
|
bool operator==(const RGBA8& other) const;
|
|
|
|
bool operator!=(const RGBA8& other) const;
|
|
|
|
|
|
|
|
uint8_t r, g, b, a;
|
2019-11-19 17:57:30 +00:00
|
|
|
|
|
|
|
static const RGBA8 kZero;
|
|
|
|
static const RGBA8 kBlack;
|
|
|
|
static const RGBA8 kRed;
|
|
|
|
static const RGBA8 kGreen;
|
|
|
|
static const RGBA8 kBlue;
|
|
|
|
static const RGBA8 kYellow;
|
|
|
|
static const RGBA8 kWhite;
|
2017-06-27 04:11:16 +00:00
|
|
|
};
|
2018-07-18 13:18:25 +00:00
|
|
|
std::ostream& operator<<(std::ostream& stream, const RGBA8& color);
|
2017-06-27 04:11:16 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
struct BackendTestConfig {
|
|
|
|
BackendTestConfig(wgpu::BackendType backendType,
|
|
|
|
std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
|
|
|
|
|
|
|
wgpu::BackendType backendType;
|
|
|
|
|
|
|
|
std::vector<const char*> forceEnabledWorkarounds;
|
|
|
|
std::vector<const char*> forceDisabledWorkarounds;
|
|
|
|
};
|
|
|
|
|
2020-05-15 16:07:12 +00:00
|
|
|
struct TestAdapterProperties : wgpu::AdapterProperties {
|
|
|
|
TestAdapterProperties(const wgpu::AdapterProperties& properties, bool selected);
|
|
|
|
std::string adapterName;
|
|
|
|
bool selected;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// This may be temporary, so it is copied into |adapterName| and made private.
|
|
|
|
using wgpu::AdapterProperties::name;
|
|
|
|
};
|
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
struct AdapterTestParam {
|
|
|
|
AdapterTestParam(const BackendTestConfig& config,
|
|
|
|
const TestAdapterProperties& adapterProperties);
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
TestAdapterProperties adapterProperties;
|
2019-05-29 00:07:37 +00:00
|
|
|
std::vector<const char*> forceEnabledWorkarounds;
|
2019-06-11 18:11:05 +00:00
|
|
|
std::vector<const char*> forceDisabledWorkarounds;
|
2019-04-26 07:52:57 +00:00
|
|
|
};
|
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param);
|
2019-08-27 01:44:29 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2020-03-20 17:07:20 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2020-02-25 16:23:17 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds = {},
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2020-02-25 16:23:17 +00:00
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
namespace utils {
|
2020-08-14 21:02:12 +00:00
|
|
|
class PlatformDebugLogger;
|
2018-07-26 13:07:57 +00:00
|
|
|
class TerribleCommandBuffer;
|
2019-05-29 00:07:37 +00:00
|
|
|
} // namespace utils
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
class Expectation;
|
2020-08-04 19:46:37 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class ExpectEq;
|
2019-05-29 00:07:37 +00:00
|
|
|
} // namespace detail
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
namespace dawn_wire {
|
2019-12-10 23:32:48 +00:00
|
|
|
class CommandHandler;
|
2019-02-11 21:50:16 +00:00
|
|
|
class WireClient;
|
|
|
|
class WireServer;
|
2018-07-26 13:07:57 +00:00
|
|
|
} // namespace dawn_wire
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2019-02-21 16:29:12 +00:00
|
|
|
void InitDawnEnd2EndTestEnvironment(int argc, char** argv);
|
|
|
|
|
|
|
|
class DawnTestEnvironment : public testing::Environment {
|
|
|
|
public:
|
|
|
|
DawnTestEnvironment(int argc, char** argv);
|
2020-08-14 21:02:12 +00:00
|
|
|
~DawnTestEnvironment() override;
|
2019-02-21 16:29:12 +00:00
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
static void SetEnvironment(DawnTestEnvironment* env);
|
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends(
|
|
|
|
const BackendTestConfig* params,
|
|
|
|
size_t numParams);
|
2020-05-15 16:07:12 +00:00
|
|
|
|
2019-02-21 16:29:12 +00:00
|
|
|
void SetUp() override;
|
2019-11-20 09:45:41 +00:00
|
|
|
void TearDown() override;
|
2019-02-21 16:29:12 +00:00
|
|
|
|
2019-05-01 12:57:27 +00:00
|
|
|
bool UsesWire() const;
|
2019-06-25 00:49:56 +00:00
|
|
|
bool IsBackendValidationEnabled() const;
|
2019-11-21 00:48:39 +00:00
|
|
|
bool IsDawnValidationSkipped() const;
|
2019-02-21 16:29:12 +00:00
|
|
|
dawn_native::Instance* GetInstance() const;
|
2019-07-08 03:25:54 +00:00
|
|
|
bool HasVendorIdFilter() const;
|
|
|
|
uint32_t GetVendorIdFilter() const;
|
2019-12-10 23:32:48 +00:00
|
|
|
const char* GetWireTraceDir() const;
|
2019-02-21 16:29:12 +00:00
|
|
|
|
2019-10-17 19:00:32 +00:00
|
|
|
protected:
|
|
|
|
std::unique_ptr<dawn_native::Instance> mInstance;
|
|
|
|
|
2019-02-21 16:29:12 +00:00
|
|
|
private:
|
2020-05-15 16:07:12 +00:00
|
|
|
void ParseArgs(int argc, char** argv);
|
2020-05-15 16:04:32 +00:00
|
|
|
std::unique_ptr<dawn_native::Instance> CreateInstanceAndDiscoverAdapters() const;
|
2020-05-15 20:28:05 +00:00
|
|
|
void SelectPreferredAdapterProperties(const dawn_native::Instance* instance);
|
2020-05-15 16:04:32 +00:00
|
|
|
void PrintTestConfigurationAndAdapterInfo() const;
|
2019-02-21 16:29:12 +00:00
|
|
|
|
|
|
|
bool mUseWire = false;
|
2019-05-15 06:06:26 +00:00
|
|
|
bool mEnableBackendValidation = false;
|
2019-11-21 00:48:39 +00:00
|
|
|
bool mSkipDawnValidation = false;
|
2019-06-21 02:09:05 +00:00
|
|
|
bool mBeginCaptureOnStartup = false;
|
2019-07-08 03:25:54 +00:00
|
|
|
bool mHasVendorIdFilter = false;
|
|
|
|
uint32_t mVendorIdFilter = 0;
|
2019-12-10 23:32:48 +00:00
|
|
|
std::string mWireTraceDir;
|
2020-05-15 20:28:05 +00:00
|
|
|
std::vector<dawn_native::DeviceType> mDevicePreferences;
|
2020-05-15 16:07:12 +00:00
|
|
|
std::vector<TestAdapterProperties> mAdapterProperties;
|
2020-08-14 21:02:12 +00:00
|
|
|
|
|
|
|
std::unique_ptr<utils::PlatformDebugLogger> mPlatformDebugLogger;
|
2019-02-21 16:29:12 +00:00
|
|
|
};
|
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
class DawnTestBase {
|
|
|
|
friend class DawnPerfTestBase;
|
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
public:
|
2020-05-15 20:28:05 +00:00
|
|
|
DawnTestBase(const AdapterTestParam& param);
|
2019-08-28 23:18:10 +00:00
|
|
|
virtual ~DawnTestBase();
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
void SetUp();
|
|
|
|
void TearDown();
|
2018-06-07 11:10:44 +00:00
|
|
|
|
|
|
|
bool IsD3D12() const;
|
|
|
|
bool IsMetal() const;
|
2020-03-20 17:07:20 +00:00
|
|
|
bool IsNull() const;
|
2018-06-07 11:10:44 +00:00
|
|
|
bool IsOpenGL() const;
|
|
|
|
bool IsVulkan() const;
|
|
|
|
|
2018-09-19 00:32:52 +00:00
|
|
|
bool IsAMD() const;
|
|
|
|
bool IsARM() const;
|
|
|
|
bool IsImgTec() const;
|
|
|
|
bool IsIntel() const;
|
|
|
|
bool IsNvidia() const;
|
|
|
|
bool IsQualcomm() const;
|
2020-04-09 08:16:30 +00:00
|
|
|
bool IsSwiftshader() const;
|
2020-07-10 22:58:48 +00:00
|
|
|
bool IsWARP() const;
|
2018-09-19 00:32:52 +00:00
|
|
|
|
|
|
|
bool IsWindows() const;
|
|
|
|
bool IsLinux() const;
|
|
|
|
bool IsMacOS() const;
|
|
|
|
|
2019-05-01 12:57:27 +00:00
|
|
|
bool UsesWire() const;
|
2019-06-25 00:49:56 +00:00
|
|
|
bool IsBackendValidationEnabled() const;
|
2019-11-21 00:48:39 +00:00
|
|
|
bool IsDawnValidationSkipped() const;
|
2020-09-09 23:11:57 +00:00
|
|
|
bool HasWGSL() const;
|
2019-05-01 12:57:27 +00:00
|
|
|
|
2020-06-19 17:35:33 +00:00
|
|
|
bool IsAsan() const;
|
|
|
|
|
2019-02-28 09:45:48 +00:00
|
|
|
void StartExpectDeviceError();
|
|
|
|
bool EndExpectDeviceError();
|
|
|
|
|
2019-07-08 03:25:54 +00:00
|
|
|
bool HasVendorIdFilter() const;
|
|
|
|
uint32_t GetVendorIdFilter() const;
|
|
|
|
|
2020-03-20 17:07:20 +00:00
|
|
|
wgpu::Instance GetInstance() const;
|
|
|
|
dawn_native::Adapter GetAdapter() const;
|
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
protected:
|
2019-10-28 13:27:36 +00:00
|
|
|
wgpu::Device device;
|
|
|
|
wgpu::Queue queue;
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2019-05-24 22:31:36 +00:00
|
|
|
DawnProcTable backendProcs = {};
|
2019-10-28 13:27:36 +00:00
|
|
|
WGPUDevice backendDevice = nullptr;
|
2019-05-24 22:31:36 +00:00
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// Helper methods to implement the EXPECT_ macros
|
|
|
|
std::ostringstream& AddBufferExpectation(const char* file,
|
|
|
|
int line,
|
2019-10-28 13:27:36 +00:00
|
|
|
const wgpu::Buffer& buffer,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t offset,
|
|
|
|
uint64_t size,
|
2018-06-07 11:10:44 +00:00
|
|
|
detail::Expectation* expectation);
|
2020-08-04 19:46:37 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::ostringstream& AddTextureExpectation(const char* file,
|
|
|
|
int line,
|
|
|
|
const T* expectedData,
|
|
|
|
const wgpu::Texture& texture,
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t width = 1,
|
|
|
|
uint32_t height = 1,
|
|
|
|
uint32_t level = 0,
|
|
|
|
uint32_t slice = 0,
|
|
|
|
wgpu::TextureAspect aspect = wgpu::TextureAspect::All,
|
|
|
|
uint32_t bytesPerRow = 0) {
|
|
|
|
return AddTextureExpectationImpl(
|
|
|
|
file, line, new detail::ExpectEq<T>(expectedData, width * height), texture, x, y, width,
|
|
|
|
height, level, slice, aspect, sizeof(T), bytesPerRow);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2018-06-07 11:10:44 +00:00
|
|
|
std::ostringstream& AddTextureExpectation(const char* file,
|
|
|
|
int line,
|
2020-08-04 19:46:37 +00:00
|
|
|
const T& expectedData,
|
2019-10-28 13:27:36 +00:00
|
|
|
const wgpu::Texture& texture,
|
2018-06-07 11:10:44 +00:00
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
2020-08-04 19:46:37 +00:00
|
|
|
uint32_t level = 0,
|
|
|
|
uint32_t slice = 0,
|
|
|
|
wgpu::TextureAspect aspect = wgpu::TextureAspect::All,
|
|
|
|
uint32_t bytesPerRow = 0) {
|
|
|
|
return AddTextureExpectationImpl(file, line, new detail::ExpectEq<T>(expectedData), texture,
|
|
|
|
x, y, 1, 1, level, slice, aspect, sizeof(T), bytesPerRow);
|
|
|
|
}
|
2018-06-07 11:10:44 +00:00
|
|
|
|
|
|
|
void WaitABit();
|
2019-05-01 12:07:37 +00:00
|
|
|
void FlushWire();
|
2020-10-12 22:32:33 +00:00
|
|
|
void WaitForAllOperations();
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
bool SupportsExtensions(const std::vector<const char*>& extensions);
|
|
|
|
|
|
|
|
// Called in SetUp() to get the extensions required to be enabled in the tests. The tests must
|
|
|
|
// check if the required extensions are supported by the adapter in this function and guarantee
|
|
|
|
// the returned extensions are all supported by the adapter. The tests may provide different
|
|
|
|
// code path to handle the situation when not all extensions are supported.
|
|
|
|
virtual std::vector<const char*> GetRequiredExtensions();
|
|
|
|
|
2020-01-10 13:28:18 +00:00
|
|
|
const wgpu::AdapterProperties& GetAdapterProperties() const;
|
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
private:
|
2020-05-15 20:28:05 +00:00
|
|
|
AdapterTestParam mParam;
|
2019-08-28 23:18:10 +00:00
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// Things used to set up testing through the Wire.
|
2019-02-11 21:50:16 +00:00
|
|
|
std::unique_ptr<dawn_wire::WireServer> mWireServer;
|
|
|
|
std::unique_ptr<dawn_wire::WireClient> mWireClient;
|
2018-09-06 13:26:48 +00:00
|
|
|
std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
|
|
|
|
std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
|
2018-06-07 11:10:44 +00:00
|
|
|
|
2019-12-10 23:32:48 +00:00
|
|
|
std::unique_ptr<dawn_wire::CommandHandler> mWireServerTraceLayer;
|
|
|
|
|
2019-02-28 09:45:48 +00:00
|
|
|
// Tracking for validation errors
|
2019-10-28 13:27:36 +00:00
|
|
|
static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata);
|
2020-01-15 19:02:13 +00:00
|
|
|
static void OnDeviceLost(const char* message, void* userdata);
|
2019-02-28 09:45:48 +00:00
|
|
|
bool mExpectError = false;
|
|
|
|
bool mError = false;
|
|
|
|
|
2020-08-04 19:46:37 +00:00
|
|
|
std::ostringstream& AddTextureExpectationImpl(const char* file,
|
|
|
|
int line,
|
|
|
|
detail::Expectation* expectation,
|
|
|
|
const wgpu::Texture& texture,
|
|
|
|
uint32_t x,
|
|
|
|
uint32_t y,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t level,
|
|
|
|
uint32_t slice,
|
|
|
|
wgpu::TextureAspect aspect,
|
|
|
|
uint32_t dataSize,
|
|
|
|
uint32_t bytesPerRow);
|
|
|
|
|
2018-06-07 11:10:44 +00:00
|
|
|
// MapRead buffers used to get data for the expectations
|
|
|
|
struct ReadbackSlot {
|
2019-10-28 13:27:36 +00:00
|
|
|
wgpu::Buffer buffer;
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t bufferSize;
|
2018-06-07 11:10:44 +00:00
|
|
|
const void* mappedData = nullptr;
|
|
|
|
};
|
|
|
|
std::vector<ReadbackSlot> mReadbackSlots;
|
|
|
|
|
|
|
|
// Maps all the buffers and fill ReadbackSlot::mappedData
|
|
|
|
void MapSlotsSynchronously();
|
2020-07-16 16:35:40 +00:00
|
|
|
static void SlotMapCallback(WGPUBufferMapAsyncStatus status, void* userdata);
|
2018-06-07 11:10:44 +00:00
|
|
|
size_t mNumPendingMapOperations = 0;
|
|
|
|
|
|
|
|
// Reserve space where the data for an expectation can be copied
|
|
|
|
struct ReadbackReservation {
|
2019-10-28 13:27:36 +00:00
|
|
|
wgpu::Buffer buffer;
|
2018-06-07 11:10:44 +00:00
|
|
|
size_t slot;
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t offset;
|
2018-06-07 11:10:44 +00:00
|
|
|
};
|
2019-04-05 20:51:29 +00:00
|
|
|
ReadbackReservation ReserveReadback(uint64_t readbackSize);
|
2018-06-07 11:10:44 +00:00
|
|
|
|
|
|
|
struct DeferredExpectation {
|
|
|
|
const char* file;
|
|
|
|
int line;
|
|
|
|
size_t readbackSlot;
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t readbackOffset;
|
|
|
|
uint64_t size;
|
2018-06-07 11:10:44 +00:00
|
|
|
uint32_t rowBytes;
|
2020-04-24 10:02:43 +00:00
|
|
|
uint32_t bytesPerRow;
|
2018-09-06 13:26:48 +00:00
|
|
|
std::unique_ptr<detail::Expectation> expectation;
|
2018-06-07 11:10:44 +00:00
|
|
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
|
|
|
|
// Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream
|
|
|
|
std::unique_ptr<std::ostringstream> message;
|
|
|
|
};
|
|
|
|
std::vector<DeferredExpectation> mDeferredExpectations;
|
|
|
|
|
|
|
|
// Assuming the data is mapped, checks all expectations
|
|
|
|
void ResolveExpectations();
|
|
|
|
|
2019-08-02 00:06:38 +00:00
|
|
|
dawn_native::Adapter mBackendAdapter;
|
2017-06-16 22:34:35 +00:00
|
|
|
};
|
|
|
|
|
2019-10-09 16:23:22 +00:00
|
|
|
// Skip a test when the given condition is satisfied.
|
2020-04-11 03:22:33 +00:00
|
|
|
#define DAWN_SKIP_TEST_IF(condition) \
|
|
|
|
do { \
|
|
|
|
if (condition) { \
|
|
|
|
dawn::InfoLog() << "Test skipped: " #condition "."; \
|
|
|
|
GTEST_SKIP(); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2019-10-09 16:23:22 +00:00
|
|
|
|
2020-05-15 20:28:05 +00:00
|
|
|
template <typename Params = AdapterTestParam>
|
2019-08-28 23:18:10 +00:00
|
|
|
class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> {
|
|
|
|
protected:
|
|
|
|
DawnTestWithParams();
|
|
|
|
~DawnTestWithParams() override = default;
|
|
|
|
|
2020-05-15 22:06:35 +00:00
|
|
|
void SetUp() override {
|
|
|
|
DawnTestBase::SetUp();
|
2019-08-28 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
DawnTestBase::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Params>
|
|
|
|
DawnTestWithParams<Params>::DawnTestWithParams() : DawnTestBase(this->GetParam()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
using DawnTest = DawnTestWithParams<>;
|
|
|
|
|
2020-05-13 08:01:55 +00:00
|
|
|
// Helpers to get the first element of a __VA_ARGS__ without triggering empty __VA_ARGS__ warnings.
|
|
|
|
#define DAWN_INTERNAL_PP_GET_HEAD(firstParam, ...) firstParam
|
|
|
|
#define DAWN_PP_GET_HEAD(...) DAWN_INTERNAL_PP_GET_HEAD(__VA_ARGS__, dummyArg)
|
|
|
|
|
2017-06-16 22:34:35 +00:00
|
|
|
// Instantiate the test once for each backend provided after the first argument. Use it like this:
|
2018-07-18 13:16:37 +00:00
|
|
|
// DAWN_INSTANTIATE_TEST(MyTestFixture, MetalBackend, OpenGLBackend)
|
2020-05-13 08:01:55 +00:00
|
|
|
#define DAWN_INSTANTIATE_TEST(testName, ...) \
|
|
|
|
const decltype(DAWN_PP_GET_HEAD(__VA_ARGS__)) testName##params[] = {__VA_ARGS__}; \
|
|
|
|
INSTANTIATE_TEST_SUITE_P( \
|
|
|
|
, testName, \
|
2020-05-15 20:28:05 +00:00
|
|
|
testing::ValuesIn(::detail::GetAvailableAdapterTestParamsForBackends( \
|
2020-05-13 08:01:55 +00:00
|
|
|
testName##params, sizeof(testName##params) / sizeof(testName##params[0]))), \
|
2019-08-27 01:44:29 +00:00
|
|
|
testing::PrintToStringParamName())
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
namespace detail {
|
2018-07-18 13:16:37 +00:00
|
|
|
// Helper functions used for DAWN_INSTANTIATE_TEST
|
2020-01-10 13:28:18 +00:00
|
|
|
bool IsBackendAvailable(wgpu::BackendType type);
|
2020-05-15 20:28:05 +00:00
|
|
|
std::vector<AdapterTestParam> GetAvailableAdapterTestParamsForBackends(
|
|
|
|
const BackendTestConfig* params,
|
|
|
|
size_t numParams);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
// All classes used to implement the deferred expectations should inherit from this.
|
|
|
|
class Expectation {
|
2018-07-18 13:18:25 +00:00
|
|
|
public:
|
|
|
|
virtual ~Expectation() = default;
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
// Will be called with the buffer or texture data the expectation should check.
|
|
|
|
virtual testing::AssertionResult Check(const void* data, size_t size) = 0;
|
2017-06-16 22:34:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Expectation that checks the data is equal to some expected values.
|
2018-07-18 13:18:25 +00:00
|
|
|
template <typename T>
|
2017-06-16 22:34:35 +00:00
|
|
|
class ExpectEq : public Expectation {
|
2018-07-18 13:18:25 +00:00
|
|
|
public:
|
|
|
|
ExpectEq(T singleValue);
|
|
|
|
ExpectEq(const T* values, const unsigned int count);
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
testing::AssertionResult Check(const void* data, size_t size) override;
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
private:
|
|
|
|
std::vector<T> mExpected;
|
2017-06-16 22:34:35 +00:00
|
|
|
};
|
2018-02-04 16:07:02 +00:00
|
|
|
extern template class ExpectEq<uint8_t>;
|
2020-06-08 12:18:21 +00:00
|
|
|
extern template class ExpectEq<int16_t>;
|
2017-06-16 22:34:35 +00:00
|
|
|
extern template class ExpectEq<uint32_t>;
|
2020-08-04 06:41:56 +00:00
|
|
|
extern template class ExpectEq<uint64_t>;
|
2017-06-27 04:11:16 +00:00
|
|
|
extern template class ExpectEq<RGBA8>;
|
2020-01-16 00:12:10 +00:00
|
|
|
extern template class ExpectEq<float>;
|
2018-07-18 13:18:25 +00:00
|
|
|
} // namespace detail
|
2019-08-28 23:18:10 +00:00
|
|
|
|
|
|
|
#endif // TESTS_DAWNTEST_H_
|