Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 1 | // Copyright 2019 The Dawn Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "common/Assert.h" |
| 16 | #include "dawn_wire/client/Client.h" |
| 17 | #include "dawn_wire/client/Device.h" |
| 18 | |
Mathieu-Andre Chiasson | 09cc2b9 | 2019-09-25 19:32:01 +0000 | [diff] [blame] | 19 | #include <limits> |
| 20 | |
Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 21 | namespace dawn_wire { namespace client { |
| 22 | |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 23 | bool Client::DoDeviceUncapturedErrorCallback(Device* device, |
| 24 | WGPUErrorType errorType, |
| 25 | const char* message) { |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 26 | switch (errorType) { |
Corentin Wallez | 1fdcb16 | 2019-10-24 22:27:27 +0000 | [diff] [blame] | 27 | case WGPUErrorType_NoError: |
| 28 | case WGPUErrorType_Validation: |
| 29 | case WGPUErrorType_OutOfMemory: |
| 30 | case WGPUErrorType_Unknown: |
| 31 | case WGPUErrorType_DeviceLost: |
Austin Eng | cb0cb65 | 2019-08-27 21:41:56 +0000 | [diff] [blame] | 32 | break; |
| 33 | default: |
| 34 | return false; |
| 35 | } |
Zhaoming Jiang | b44000e | 2021-06-04 07:10:56 +0000 | [diff] [blame] | 36 | if (device == nullptr) { |
| 37 | // The device might have been deleted or recreated so this isn't an error. |
| 38 | return true; |
| 39 | } |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 40 | device->HandleError(errorType, message); |
Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | |
Zhaoming Jiang | b44000e | 2021-06-04 07:10:56 +0000 | [diff] [blame] | 44 | bool Client::DoDeviceLoggingCallback(Device* device, |
| 45 | WGPULoggingType loggingType, |
| 46 | const char* message) { |
| 47 | if (device == nullptr) { |
| 48 | // The device might have been deleted or recreated so this isn't an error. |
| 49 | return true; |
| 50 | } |
| 51 | device->HandleLogging(loggingType, message); |
| 52 | return true; |
| 53 | } |
| 54 | |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 55 | bool Client::DoDeviceLostCallback(Device* device, char const* message) { |
Austin Eng | a75b230 | 2021-02-04 20:38:02 +0000 | [diff] [blame] | 56 | if (device == nullptr) { |
| 57 | // The device might have been deleted or recreated so this isn't an error. |
| 58 | return true; |
| 59 | } |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 60 | device->HandleDeviceLost(message); |
Natasha Lee | 9bba4a9 | 2019-12-18 18:59:20 +0000 | [diff] [blame] | 61 | return true; |
| 62 | } |
| 63 | |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 64 | bool Client::DoDevicePopErrorScopeCallback(Device* device, |
| 65 | uint64_t requestSerial, |
Corentin Wallez | 1fdcb16 | 2019-10-24 22:27:27 +0000 | [diff] [blame] | 66 | WGPUErrorType errorType, |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 67 | const char* message) { |
Austin Eng | a75b230 | 2021-02-04 20:38:02 +0000 | [diff] [blame] | 68 | if (device == nullptr) { |
| 69 | // The device might have been deleted or recreated so this isn't an error. |
| 70 | return true; |
| 71 | } |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 72 | return device->OnPopErrorScopeCallback(requestSerial, errorType, message); |
Austin Eng | 45238d7 | 2019-09-04 22:54:03 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Corentin Wallez | 450b6f4 | 2020-07-17 07:38:36 +0000 | [diff] [blame] | 75 | bool Client::DoBufferMapAsyncCallback(Buffer* buffer, |
| 76 | uint32_t requestSerial, |
| 77 | uint32_t status, |
| 78 | uint64_t readInitialDataInfoLength, |
| 79 | const uint8_t* readInitialDataInfo) { |
Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 80 | // The buffer might have been deleted or recreated so this isn't an error. |
| 81 | if (buffer == nullptr) { |
| 82 | return true; |
| 83 | } |
Corentin Wallez | 450b6f4 | 2020-07-17 07:38:36 +0000 | [diff] [blame] | 84 | return buffer->OnMapAsyncCallback(requestSerial, status, readInitialDataInfoLength, |
| 85 | readInitialDataInfo); |
Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Corentin Wallez | c093db2 | 2021-02-25 13:17:01 +0000 | [diff] [blame] | 88 | bool Client::DoQueueWorkDoneCallback(Queue* queue, |
| 89 | uint64_t requestSerial, |
| 90 | WGPUQueueWorkDoneStatus status) { |
| 91 | // The queue might have been deleted or recreated so this isn't an error. |
| 92 | if (queue == nullptr) { |
| 93 | return true; |
| 94 | } |
| 95 | return queue->OnWorkDoneCallback(requestSerial, status); |
Austin Eng | 0b89b27 | 2020-08-28 21:23:50 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 98 | bool Client::DoDeviceCreateComputePipelineAsyncCallback(Device* device, |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 99 | uint64_t requestSerial, |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 100 | WGPUCreatePipelineAsyncStatus status, |
Jiawei Shao | ae5f950 | 2020-10-19 01:56:08 +0000 | [diff] [blame] | 101 | const char* message) { |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 102 | // The device might have been deleted or recreated so this isn't an error. |
| 103 | if (device == nullptr) { |
| 104 | return true; |
| 105 | } |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 106 | return device->OnCreateComputePipelineAsyncCallback(requestSerial, status, message); |
Jiawei Shao | 03e1400 | 2020-10-21 04:37:41 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 109 | bool Client::DoDeviceCreateRenderPipelineAsyncCallback(Device* device, |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 110 | uint64_t requestSerial, |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 111 | WGPUCreatePipelineAsyncStatus status, |
Jiawei Shao | 03e1400 | 2020-10-21 04:37:41 +0000 | [diff] [blame] | 112 | const char* message) { |
Austin Eng | 4d66fb2 | 2021-01-25 08:38:47 +0000 | [diff] [blame] | 113 | // The device might have been deleted or recreated so this isn't an error. |
| 114 | if (device == nullptr) { |
| 115 | return true; |
| 116 | } |
Corentin Wallez | 2d3c2e3 | 2021-02-22 18:27:36 +0000 | [diff] [blame] | 117 | return device->OnCreateRenderPipelineAsyncCallback(requestSerial, status, message); |
Jiawei Shao | ae5f950 | 2020-10-19 01:56:08 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Brandon Jones | 6f2bbe9 | 2021-04-05 23:34:17 +0000 | [diff] [blame] | 120 | bool Client::DoShaderModuleGetCompilationInfoCallback(ShaderModule* shaderModule, |
| 121 | uint64_t requestSerial, |
| 122 | WGPUCompilationInfoRequestStatus status, |
| 123 | const WGPUCompilationInfo* info) { |
| 124 | // The shader module might have been deleted or recreated so this isn't an error. |
| 125 | if (shaderModule == nullptr) { |
| 126 | return true; |
| 127 | } |
| 128 | return shaderModule->GetCompilationInfoCallback(requestSerial, status, info); |
| 129 | } |
| 130 | |
Austin Eng | 1139d1c | 2019-01-30 03:00:17 +0000 | [diff] [blame] | 131 | }} // namespace dawn_wire::client |