blob: 2e864a4645b6a54973e66055aff2d545a2a6b9ea [file] [log] [blame]
Austin Eng1139d1c2019-01-30 03:00:17 +00001// 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 Chiasson09cc2b92019-09-25 19:32:01 +000019#include <limits>
20
Austin Eng1139d1c2019-01-30 03:00:17 +000021namespace dawn_wire { namespace client {
22
Austin Eng4d66fb22021-01-25 08:38:47 +000023 bool Client::DoDeviceUncapturedErrorCallback(Device* device,
24 WGPUErrorType errorType,
25 const char* message) {
Austin Engcb0cb652019-08-27 21:41:56 +000026 switch (errorType) {
Corentin Wallez1fdcb162019-10-24 22:27:27 +000027 case WGPUErrorType_NoError:
28 case WGPUErrorType_Validation:
29 case WGPUErrorType_OutOfMemory:
30 case WGPUErrorType_Unknown:
31 case WGPUErrorType_DeviceLost:
Austin Engcb0cb652019-08-27 21:41:56 +000032 break;
33 default:
34 return false;
35 }
Zhaoming Jiangb44000e2021-06-04 07:10:56 +000036 if (device == nullptr) {
37 // The device might have been deleted or recreated so this isn't an error.
38 return true;
39 }
Austin Eng4d66fb22021-01-25 08:38:47 +000040 device->HandleError(errorType, message);
Austin Eng1139d1c2019-01-30 03:00:17 +000041 return true;
42 }
43
Zhaoming Jiangb44000e2021-06-04 07:10:56 +000044 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 Eng4d66fb22021-01-25 08:38:47 +000055 bool Client::DoDeviceLostCallback(Device* device, char const* message) {
Austin Enga75b2302021-02-04 20:38:02 +000056 if (device == nullptr) {
57 // The device might have been deleted or recreated so this isn't an error.
58 return true;
59 }
Austin Eng4d66fb22021-01-25 08:38:47 +000060 device->HandleDeviceLost(message);
Natasha Lee9bba4a92019-12-18 18:59:20 +000061 return true;
62 }
63
Austin Eng4d66fb22021-01-25 08:38:47 +000064 bool Client::DoDevicePopErrorScopeCallback(Device* device,
65 uint64_t requestSerial,
Corentin Wallez1fdcb162019-10-24 22:27:27 +000066 WGPUErrorType errorType,
Austin Eng45238d72019-09-04 22:54:03 +000067 const char* message) {
Austin Enga75b2302021-02-04 20:38:02 +000068 if (device == nullptr) {
69 // The device might have been deleted or recreated so this isn't an error.
70 return true;
71 }
Austin Eng4d66fb22021-01-25 08:38:47 +000072 return device->OnPopErrorScopeCallback(requestSerial, errorType, message);
Austin Eng45238d72019-09-04 22:54:03 +000073 }
74
Corentin Wallez450b6f42020-07-17 07:38:36 +000075 bool Client::DoBufferMapAsyncCallback(Buffer* buffer,
76 uint32_t requestSerial,
77 uint32_t status,
78 uint64_t readInitialDataInfoLength,
79 const uint8_t* readInitialDataInfo) {
Austin Eng1139d1c2019-01-30 03:00:17 +000080 // The buffer might have been deleted or recreated so this isn't an error.
81 if (buffer == nullptr) {
82 return true;
83 }
Corentin Wallez450b6f42020-07-17 07:38:36 +000084 return buffer->OnMapAsyncCallback(requestSerial, status, readInitialDataInfoLength,
85 readInitialDataInfo);
Austin Eng1139d1c2019-01-30 03:00:17 +000086 }
87
Corentin Wallezc093db22021-02-25 13:17:01 +000088 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 Eng0b89b272020-08-28 21:23:50 +000096 }
97
Corentin Wallez2d3c2e32021-02-22 18:27:36 +000098 bool Client::DoDeviceCreateComputePipelineAsyncCallback(Device* device,
Austin Eng4d66fb22021-01-25 08:38:47 +000099 uint64_t requestSerial,
Corentin Wallez2d3c2e32021-02-22 18:27:36 +0000100 WGPUCreatePipelineAsyncStatus status,
Jiawei Shaoae5f9502020-10-19 01:56:08 +0000101 const char* message) {
Austin Eng4d66fb22021-01-25 08:38:47 +0000102 // The device might have been deleted or recreated so this isn't an error.
103 if (device == nullptr) {
104 return true;
105 }
Corentin Wallez2d3c2e32021-02-22 18:27:36 +0000106 return device->OnCreateComputePipelineAsyncCallback(requestSerial, status, message);
Jiawei Shao03e14002020-10-21 04:37:41 +0000107 }
108
Corentin Wallez2d3c2e32021-02-22 18:27:36 +0000109 bool Client::DoDeviceCreateRenderPipelineAsyncCallback(Device* device,
Austin Eng4d66fb22021-01-25 08:38:47 +0000110 uint64_t requestSerial,
Corentin Wallez2d3c2e32021-02-22 18:27:36 +0000111 WGPUCreatePipelineAsyncStatus status,
Jiawei Shao03e14002020-10-21 04:37:41 +0000112 const char* message) {
Austin Eng4d66fb22021-01-25 08:38:47 +0000113 // The device might have been deleted or recreated so this isn't an error.
114 if (device == nullptr) {
115 return true;
116 }
Corentin Wallez2d3c2e32021-02-22 18:27:36 +0000117 return device->OnCreateRenderPipelineAsyncCallback(requestSerial, status, message);
Jiawei Shaoae5f9502020-10-19 01:56:08 +0000118 }
119
Brandon Jones6f2bbe92021-04-05 23:34:17 +0000120 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 Eng1139d1c2019-01-30 03:00:17 +0000131}} // namespace dawn_wire::client