mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user