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.
|
|
|
|
#define EXPECT_BUFFER_U32_EQ(expected, buffer, offset) \
|
|
|
|
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t), \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<uint32_t>(expected))
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-07-18 13:18:25 +00:00
|
|
|
#define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \
|
|
|
|
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t) * count, \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<uint32_t>(expected, count))
|
2017-07-04 14:53:42 +00:00
|
|
|
|
2017-06-27 04:11:16 +00:00
|
|
|
// Test a pixel of the mip level 0 of a 2D texture.
|
2018-12-05 03:22:04 +00:00
|
|
|
#define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, 0, 0, sizeof(RGBA8), \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<RGBA8>(expected))
|
2017-07-17 20:16:50 +00:00
|
|
|
|
2018-12-05 03:22:04 +00:00
|
|
|
#define EXPECT_TEXTURE_RGBA8_EQ(expected, texture, x, y, width, height, level, slice) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, width, height, level, slice, \
|
|
|
|
sizeof(RGBA8), \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<RGBA8>(expected, (width) * (height)))
|
2017-06-27 04:11:16 +00:00
|
|
|
|
2020-01-16 00:12:10 +00:00
|
|
|
#define EXPECT_PIXEL_FLOAT_EQ(expected, texture, x, y) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, 0, 0, sizeof(float), \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<float>(expected))
|
2020-01-16 00:12:10 +00:00
|
|
|
|
|
|
|
#define EXPECT_TEXTURE_FLOAT_EQ(expected, texture, x, y, width, height, level, slice) \
|
|
|
|
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, width, height, level, slice, \
|
|
|
|
sizeof(float), \
|
Revert "Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper"
This reverts commit 4e17d5c2483b63d4863162d692a1a961d1dcb958.
Reason for revert: broken on chromeos
Original change's description:
> Remove VK_DEFINE_NON_DISPATCHABLE_HANDLE magic, use explicit VkHandle wrapper
>
> Overriding VK_DEFINE_NON_DISPATCHABLE_HANDLE changes the function
> signatures of Vulkan functions, changing their ABI and making us
> incompatible with real drivers. This removes that magic, and replaces it
> with an explicit wrapper, VkHandle, which has much of the same
> functionality as the original VkNonDispatchableHandle.
>
> It adds definitions for dawn_native::vulkan::VkBuffer et al, which
> shadow the native ::VkBuffer et al. This retains type safety throughout
> the Vulkan backend without changing every single usage.
>
> Notably, the following things had to change:
> - An explicit conversion from VkBuffer* to ::VkBuffer* is needed for
> arrays. This is implemented as a reinterpret_cast, which is still
> safe as the new VkHandle still has the same memory layout properties
> as VkNonDispatchableHandle did.
> - When pointing to a VkHandle as an output pointer, it's now necessary
> to explicitly get the native ::VkBuffer (via operator*) and point to it.
>
> Bug: chromium:1046362
> Change-Id: I9c5691b6e295aca1b46d4e3d0203956e4d570285
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15580
> Reviewed-by: Austin Eng <enga@chromium.org>
> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
> Commit-Queue: Kai Ninomiya <kainino@chromium.org>
TBR=cwallez@chromium.org,kainino@chromium.org,enga@chromium.org
Change-Id: I500df2e34fd0f245ad04c517ff028ddd7bb5a2bf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:1046362
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15620
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
2020-01-31 02:09:06 +00:00
|
|
|
new detail::ExpectEq<float>(expected, (width) * (height)))
|
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;
|
|
|
|
#define ASSERT_DEVICE_ERROR(statement) \
|
|
|
|
StartExpectDeviceError(); \
|
|
|
|
statement; \
|
2019-05-01 12:07:37 +00:00
|
|
|
FlushWire(); \
|
2019-02-28 09:45:48 +00:00
|
|
|
ASSERT_TRUE(EndExpectDeviceError());
|
|
|
|
|
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
|
|
|
|
2019-04-26 07:52:57 +00:00
|
|
|
struct DawnTestParam {
|
2020-01-10 13:28:18 +00:00
|
|
|
explicit DawnTestParam(wgpu::BackendType backendType) : backendType(backendType) {
|
2019-04-26 07:52:57 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 13:28:18 +00:00
|
|
|
wgpu::BackendType backendType;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-08-27 01:44:29 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const DawnTestParam& param);
|
|
|
|
|
2019-02-05 12:17:20 +00:00
|
|
|
// Shorthands for backend types used in the DAWN_INSTANTIATE_TEST
|
2019-05-29 00:07:37 +00:00
|
|
|
extern const DawnTestParam D3D12Backend;
|
|
|
|
extern const DawnTestParam MetalBackend;
|
|
|
|
extern const DawnTestParam OpenGLBackend;
|
|
|
|
extern const DawnTestParam VulkanBackend;
|
2019-04-26 07:52:57 +00:00
|
|
|
|
2019-12-05 14:02:11 +00:00
|
|
|
DawnTestParam ForceToggles(const DawnTestParam& originParam,
|
|
|
|
std::initializer_list<const char*> forceEnabledWorkarounds,
|
|
|
|
std::initializer_list<const char*> forceDisabledWorkarounds = {});
|
2017-06-16 22:34:35 +00:00
|
|
|
|
|
|
|
namespace utils {
|
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;
|
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);
|
|
|
|
~DawnTestEnvironment() = default;
|
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
static void SetEnvironment(DawnTestEnvironment* env);
|
|
|
|
|
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-12-04 20:05:36 +00:00
|
|
|
bool IsSpvcBeingUsed() 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:
|
2019-08-13 21:45:44 +00:00
|
|
|
void DiscoverOpenGLAdapter();
|
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-12-04 20:05:36 +00:00
|
|
|
bool mUseSpvc = 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;
|
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:
|
2019-08-28 23:18:10 +00:00
|
|
|
DawnTestBase(const DawnTestParam& param);
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
2019-12-04 20:05:36 +00:00
|
|
|
bool IsSpvcBeingUsed() const;
|
2019-05-01 12:57:27 +00:00
|
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
std::ostringstream& AddTextureExpectation(const char* file,
|
|
|
|
int line,
|
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,
|
|
|
|
uint32_t width,
|
|
|
|
uint32_t height,
|
|
|
|
uint32_t level,
|
2018-12-05 03:22:04 +00:00
|
|
|
uint32_t slice,
|
2018-06-07 11:10:44 +00:00
|
|
|
uint32_t pixelSize,
|
|
|
|
detail::Expectation* expectation);
|
|
|
|
|
2019-10-09 16:23:22 +00:00
|
|
|
bool HasAdapter() const;
|
2018-06-07 11:10:44 +00:00
|
|
|
void WaitABit();
|
2019-05-01 12:07:37 +00:00
|
|
|
void FlushWire();
|
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:
|
2019-08-28 23:18:10 +00:00
|
|
|
DawnTestParam mParam;
|
|
|
|
|
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;
|
|
|
|
|
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();
|
2019-10-28 13:27:36 +00:00
|
|
|
static void SlotMapReadCallback(WGPUBufferMapAsyncStatus status,
|
2018-06-07 11:10:44 +00:00
|
|
|
const void* data,
|
2019-04-05 20:51:29 +00:00
|
|
|
uint64_t dataLength,
|
2019-05-29 13:03:50 +00:00
|
|
|
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;
|
|
|
|
uint32_t rowPitch;
|
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;
|
2020-01-10 13:28:18 +00:00
|
|
|
wgpu::AdapterProperties mAdapterProperties;
|
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.
|
2019-12-06 18:21:39 +00:00
|
|
|
#define DAWN_SKIP_TEST_IF(condition) \
|
|
|
|
if (condition) { \
|
|
|
|
dawn::InfoLog() << "Test skipped: " #condition "."; \
|
|
|
|
GTEST_SKIP(); \
|
|
|
|
return; \
|
2019-10-09 16:23:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
template <typename Params = DawnTestParam>
|
|
|
|
class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> {
|
2019-10-09 16:23:22 +00:00
|
|
|
private:
|
|
|
|
void SetUp() override final {
|
|
|
|
// DawnTestBase::SetUp() gets the adapter, and creates the device and wire.
|
|
|
|
// It's separate from TestSetUp() so we can skip tests completely if no adapter
|
|
|
|
// is available.
|
|
|
|
DawnTestBase::SetUp();
|
|
|
|
DAWN_SKIP_TEST_IF(!HasAdapter());
|
|
|
|
TestSetUp();
|
|
|
|
}
|
|
|
|
|
2019-08-28 23:18:10 +00:00
|
|
|
protected:
|
|
|
|
DawnTestWithParams();
|
|
|
|
~DawnTestWithParams() override = default;
|
|
|
|
|
2019-10-09 16:23:22 +00:00
|
|
|
virtual void TestSetUp() {
|
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<>;
|
|
|
|
|
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)
|
2019-02-21 09:43:40 +00:00
|
|
|
#define DAWN_INSTANTIATE_TEST(testName, firstParam, ...) \
|
|
|
|
const decltype(firstParam) testName##params[] = {firstParam, ##__VA_ARGS__}; \
|
|
|
|
INSTANTIATE_TEST_SUITE_P( \
|
|
|
|
, testName, \
|
|
|
|
testing::ValuesIn(::detail::FilterBackends( \
|
|
|
|
testName##params, sizeof(testName##params) / sizeof(firstParam))), \
|
2019-08-27 01:44:29 +00:00
|
|
|
testing::PrintToStringParamName())
|
2017-06-16 22:34:35 +00:00
|
|
|
|
2018-08-30 05:10:52 +00:00
|
|
|
|
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);
|
2019-04-26 07:52:57 +00:00
|
|
|
std::vector<DawnTestParam> FilterBackends(const DawnTestParam* 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>;
|
2017-06-16 22:34:35 +00:00
|
|
|
extern template class ExpectEq<uint32_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_
|