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 19 #include <limits> 20 21 namespace dawn_wire { namespace client { 22 DoDeviceUncapturedErrorCallback(Device * device,WGPUErrorType errorType,const char * message)23 bool Client::DoDeviceUncapturedErrorCallback(Device* device, 24 WGPUErrorType errorType, 25 const char* message) { 26 switch (errorType) { 27 case WGPUErrorType_NoError: 28 case WGPUErrorType_Validation: 29 case WGPUErrorType_OutOfMemory: 30 case WGPUErrorType_Unknown: 31 case WGPUErrorType_DeviceLost: 32 break; 33 default: 34 return false; 35 } 36 if (device == nullptr) { 37 // The device might have been deleted or recreated so this isn't an error. 38 return true; 39 } 40 device->HandleError(errorType, message); 41 return true; 42 } 43 DoDeviceLoggingCallback(Device * device,WGPULoggingType loggingType,const char * message)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 DoDeviceLostCallback(Device * device,WGPUDeviceLostReason reason,char const * message)55 bool Client::DoDeviceLostCallback(Device* device, 56 WGPUDeviceLostReason reason, 57 char const* message) { 58 if (device == nullptr) { 59 // The device might have been deleted or recreated so this isn't an error. 60 return true; 61 } 62 device->HandleDeviceLost(reason, message); 63 return true; 64 } 65 DoDevicePopErrorScopeCallback(Device * device,uint64_t requestSerial,WGPUErrorType errorType,const char * message)66 bool Client::DoDevicePopErrorScopeCallback(Device* device, 67 uint64_t requestSerial, 68 WGPUErrorType errorType, 69 const char* message) { 70 if (device == nullptr) { 71 // The device might have been deleted or recreated so this isn't an error. 72 return true; 73 } 74 return device->OnPopErrorScopeCallback(requestSerial, errorType, message); 75 } 76 DoBufferMapAsyncCallback(Buffer * buffer,uint64_t requestSerial,uint32_t status,uint64_t readDataUpdateInfoLength,const uint8_t * readDataUpdateInfo)77 bool Client::DoBufferMapAsyncCallback(Buffer* buffer, 78 uint64_t requestSerial, 79 uint32_t status, 80 uint64_t readDataUpdateInfoLength, 81 const uint8_t* readDataUpdateInfo) { 82 // The buffer might have been deleted or recreated so this isn't an error. 83 if (buffer == nullptr) { 84 return true; 85 } 86 return buffer->OnMapAsyncCallback(requestSerial, status, readDataUpdateInfoLength, 87 readDataUpdateInfo); 88 } 89 DoQueueWorkDoneCallback(Queue * queue,uint64_t requestSerial,WGPUQueueWorkDoneStatus status)90 bool Client::DoQueueWorkDoneCallback(Queue* queue, 91 uint64_t requestSerial, 92 WGPUQueueWorkDoneStatus status) { 93 // The queue might have been deleted or recreated so this isn't an error. 94 if (queue == nullptr) { 95 return true; 96 } 97 return queue->OnWorkDoneCallback(requestSerial, status); 98 } 99 DoDeviceCreateComputePipelineAsyncCallback(Device * device,uint64_t requestSerial,WGPUCreatePipelineAsyncStatus status,const char * message)100 bool Client::DoDeviceCreateComputePipelineAsyncCallback(Device* device, 101 uint64_t requestSerial, 102 WGPUCreatePipelineAsyncStatus status, 103 const char* message) { 104 // The device might have been deleted or recreated so this isn't an error. 105 if (device == nullptr) { 106 return true; 107 } 108 return device->OnCreateComputePipelineAsyncCallback(requestSerial, status, message); 109 } 110 DoDeviceCreateRenderPipelineAsyncCallback(Device * device,uint64_t requestSerial,WGPUCreatePipelineAsyncStatus status,const char * message)111 bool Client::DoDeviceCreateRenderPipelineAsyncCallback(Device* device, 112 uint64_t requestSerial, 113 WGPUCreatePipelineAsyncStatus status, 114 const char* message) { 115 // The device might have been deleted or recreated so this isn't an error. 116 if (device == nullptr) { 117 return true; 118 } 119 return device->OnCreateRenderPipelineAsyncCallback(requestSerial, status, message); 120 } 121 DoShaderModuleGetCompilationInfoCallback(ShaderModule * shaderModule,uint64_t requestSerial,WGPUCompilationInfoRequestStatus status,const WGPUCompilationInfo * info)122 bool Client::DoShaderModuleGetCompilationInfoCallback(ShaderModule* shaderModule, 123 uint64_t requestSerial, 124 WGPUCompilationInfoRequestStatus status, 125 const WGPUCompilationInfo* info) { 126 // The shader module might have been deleted or recreated so this isn't an error. 127 if (shaderModule == nullptr) { 128 return true; 129 } 130 return shaderModule->GetCompilationInfoCallback(requestSerial, status, info); 131 } 132 133 }} // namespace dawn_wire::client 134