dawn_native: Add RequestDevice to the Adapter

Adds a basic RequestDevice method to the adapter, only in
dawn_native. We will revisit this when we implement adapters
in dawn_wire.

RequestDevice allows us to have tests of the limit bounds
because it receives a callback which can return status codes
and error messages.

Bug: dawn:685
Change-Id: I7a68922b078c6a436f49a16346cb41fb9df9cfee
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/63982
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2021-09-10 21:07:39 +00:00 committed by Dawn LUCI CQ
parent dc7971ce58
commit 2092a66ab5
5 changed files with 52 additions and 1 deletions

View File

@ -1535,7 +1535,26 @@
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
}
]
},
"request device callback": {
"category": "callback",
"args": [
{"name": "status", "type": "request device status"},
{"name": "device", "type": "device"},
{"name": "message", "type": "char", "annotation": "const*"},
{"name": "userdata", "type": "void", "annotation": "*"}
]
},
"request device status": {
"category": "enum",
"values": [
{"value": 0, "name": "success"},
{"value": 1, "name": "error"},
{"value": 2, "name": "unknown"}
]
},

View File

@ -78,6 +78,24 @@ namespace dawn_native {
return result;
}
void AdapterBase::RequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata) {
DeviceBase* result = nullptr;
MaybeError err = CreateDeviceInternal(&result, descriptor);
WGPUDevice device = reinterpret_cast<WGPUDevice>(result);
if (err.IsError()) {
std::unique_ptr<ErrorData> errorData = err.AcquireError();
callback(WGPURequestDeviceStatus_Error, device, errorData->GetMessage().c_str(),
userdata);
return;
}
WGPURequestDeviceStatus status =
device == nullptr ? WGPURequestDeviceStatus_Unknown : WGPURequestDeviceStatus_Success;
callback(status, device, nullptr, userdata);
}
MaybeError AdapterBase::CreateDeviceInternal(DeviceBase** result,
const DeviceDescriptor* descriptor) {
if (descriptor != nullptr) {

View File

@ -40,6 +40,10 @@ namespace dawn_native {
DeviceBase* CreateDevice(const DeviceDescriptor* descriptor = nullptr);
void RequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
void ResetInternalDeviceForTesting();
ExtensionsSet GetSupportedExtensions() const;

View File

@ -118,6 +118,12 @@ namespace dawn_native {
return reinterpret_cast<WGPUDevice>(mImpl->CreateDevice(deviceDescriptor));
}
void Adapter::RequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata) {
mImpl->RequestDevice(descriptor, callback, userdata);
}
void Adapter::ResetInternalDeviceForTesting() {
mImpl->ResetInternalDeviceForTesting();
}

View File

@ -120,6 +120,10 @@ namespace dawn_native {
// On an error, nullptr is returned.
WGPUDevice CreateDevice(const DeviceDescriptor* deviceDescriptor = nullptr);
void RequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
// Reset the backend device object for testing purposes.
void ResetInternalDeviceForTesting();