mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-15 16:16:08 +00:00
Updates DawnInstanceDescriptor to pass in the Platform.
Notes: - Separates ChainedStruct to be reusable without cpp header. (Also updates native structs to directly use it.) - Manually implements the descriptor in DawnNative. - Reworks ChainUtils with mapping from struct to STypes. - Updates the tests to use either SetPlatformForTesting which is still required because DawnTest uses a "global" instance for all tests and some tests require setting (and cleaning up) a test specific platform. Bug: dawn:1374 Change-Id: I078c78f22c5137030cf3cf0e8358fe4373ee9c6c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132268 Reviewed-by: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
@@ -135,6 +135,19 @@ void Adapter::ResetInternalDeviceForTesting() {
|
||||
AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type)
|
||||
: backendType(type) {}
|
||||
|
||||
// DawnInstanceDescriptor
|
||||
|
||||
DawnInstanceDescriptor::DawnInstanceDescriptor() {
|
||||
sType = wgpu::SType::DawnInstanceDescriptor;
|
||||
}
|
||||
|
||||
bool DawnInstanceDescriptor::operator==(const DawnInstanceDescriptor& rhs) const {
|
||||
return (nextInChain == rhs.nextInChain) &&
|
||||
std::tie(additionalRuntimeSearchPathsCount, additionalRuntimeSearchPaths, platform) ==
|
||||
std::tie(rhs.additionalRuntimeSearchPathsCount, rhs.additionalRuntimeSearchPaths,
|
||||
rhs.platform);
|
||||
}
|
||||
|
||||
// Instance
|
||||
|
||||
Instance::Instance(const WGPUInstanceDescriptor* desc)
|
||||
|
||||
@@ -186,7 +186,7 @@ MaybeError InstanceBase::Initialize(const InstanceDescriptor* descriptor) {
|
||||
|
||||
// Initialize the platform to the default for now.
|
||||
mDefaultPlatform = std::make_unique<dawn::platform::Platform>();
|
||||
SetPlatform(mDefaultPlatform.get());
|
||||
SetPlatform(dawnDesc != nullptr ? dawnDesc->platform : mDefaultPlatform.get());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -49,19 +49,21 @@ void DawnNativeTest::SetUp() {
|
||||
// adapter and device toggles and allow us to test unsafe apis (including experimental
|
||||
// features).
|
||||
const char* allowUnsafeApisToggle = "allow_unsafe_apis";
|
||||
WGPUDawnTogglesDescriptor instanceToggles = {};
|
||||
instanceToggles.chain.sType = WGPUSType::WGPUSType_DawnTogglesDescriptor;
|
||||
wgpu::DawnTogglesDescriptor instanceToggles;
|
||||
instanceToggles.enabledTogglesCount = 1;
|
||||
instanceToggles.enabledToggles = &allowUnsafeApisToggle;
|
||||
|
||||
WGPUInstanceDescriptor instanceDesc = {};
|
||||
instanceDesc.nextInChain = &instanceToggles.chain;
|
||||
|
||||
instance = std::make_unique<dawn::native::Instance>(&instanceDesc);
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
platform = CreateTestPlatform();
|
||||
dawn::native::FromAPI(instance->Get())->SetPlatformForTesting(platform.get());
|
||||
wgpu::DawnInstanceDescriptor dawnInstanceDesc;
|
||||
dawnInstanceDesc.platform = platform.get();
|
||||
dawnInstanceDesc.nextInChain = &instanceToggles;
|
||||
|
||||
wgpu::InstanceDescriptor instanceDesc;
|
||||
instanceDesc.nextInChain = &dawnInstanceDesc;
|
||||
|
||||
instance = std::make_unique<dawn::native::Instance>(
|
||||
reinterpret_cast<const WGPUInstanceDescriptor*>(&instanceDesc));
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
|
||||
std::vector<dawn::native::Adapter> adapters = instance->GetAdapters();
|
||||
|
||||
@@ -373,20 +373,25 @@ void DawnTestEnvironment::ParseArgs(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDiscoverAdapters() {
|
||||
std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDiscoverAdapters(
|
||||
dawn::platform::Platform* platform) {
|
||||
// Create an instance with toggle AllowUnsafeAPIs enabled, which would be inherited to
|
||||
// adapter and device toggles and allow us to test unsafe apis (including experimental
|
||||
// features).
|
||||
const char* allowUnsafeApisToggle = "allow_unsafe_apis";
|
||||
WGPUDawnTogglesDescriptor instanceToggles = {};
|
||||
instanceToggles.chain.sType = WGPUSType::WGPUSType_DawnTogglesDescriptor;
|
||||
wgpu::DawnTogglesDescriptor instanceToggles;
|
||||
instanceToggles.enabledTogglesCount = 1;
|
||||
instanceToggles.enabledToggles = &allowUnsafeApisToggle;
|
||||
|
||||
WGPUInstanceDescriptor instanceDesc = {};
|
||||
instanceDesc.nextInChain = &instanceToggles.chain;
|
||||
wgpu::DawnInstanceDescriptor dawnInstanceDesc;
|
||||
dawnInstanceDesc.platform = platform;
|
||||
dawnInstanceDesc.nextInChain = &instanceToggles;
|
||||
|
||||
auto instance = std::make_unique<dawn::native::Instance>(&instanceDesc);
|
||||
wgpu::InstanceDescriptor instanceDesc;
|
||||
instanceDesc.nextInChain = &dawnInstanceDesc;
|
||||
|
||||
auto instance = std::make_unique<dawn::native::Instance>(
|
||||
reinterpret_cast<const WGPUInstanceDescriptor*>(&instanceDesc));
|
||||
instance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup);
|
||||
instance->SetBackendValidationLevel(mBackendValidationLevel);
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
@@ -1096,6 +1101,9 @@ void DawnTestBase::TearDown() {
|
||||
EXPECT_EQ(mLastWarningCount,
|
||||
dawn::native::GetDeprecationWarningCountForTesting(device.Get()));
|
||||
}
|
||||
|
||||
// Unsets the platform since we are cleaning the per-test platform up with the test case.
|
||||
dawn::native::FromAPI(gTestEnv->GetInstance()->Get())->SetPlatformForTesting(nullptr);
|
||||
}
|
||||
|
||||
void DawnTestBase::DestroyDevice(wgpu::Device device) {
|
||||
|
||||
@@ -183,11 +183,12 @@ class DawnTestEnvironment : public testing::Environment {
|
||||
bool RunSuppressedTests() const;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<dawn::native::Instance> CreateInstanceAndDiscoverAdapters(
|
||||
dawn::platform::Platform* platform = nullptr);
|
||||
std::unique_ptr<dawn::native::Instance> mInstance;
|
||||
|
||||
private:
|
||||
void ParseArgs(int argc, char** argv);
|
||||
std::unique_ptr<dawn::native::Instance> CreateInstanceAndDiscoverAdapters();
|
||||
void SelectPreferredAdapterProperties(const dawn::native::Instance* instance);
|
||||
void PrintTestConfigurationAndAdapterInfo(dawn::native::Instance* instance) const;
|
||||
|
||||
|
||||
@@ -122,10 +122,9 @@ DawnPerfTestEnvironment::DawnPerfTestEnvironment(int argc, char** argv)
|
||||
DawnPerfTestEnvironment::~DawnPerfTestEnvironment() = default;
|
||||
|
||||
void DawnPerfTestEnvironment::SetUp() {
|
||||
DawnTestEnvironment::SetUp();
|
||||
|
||||
mPlatform = std::make_unique<DawnPerfTestPlatform>();
|
||||
mInstance->SetPlatform(mPlatform.get());
|
||||
mInstance = CreateInstanceAndDiscoverAdapters(mPlatform.get());
|
||||
ASSERT(mInstance);
|
||||
|
||||
// Begin writing the trace event array.
|
||||
if (mTraceFile != nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user