1 // Copyright 2021 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 "dawn_wire/client/ShaderModule.h" 16 17 #include "dawn_wire/client/Client.h" 18 19 namespace dawn_wire { namespace client { 20 ~ShaderModule()21 ShaderModule::~ShaderModule() { 22 ClearAllCallbacks(WGPUCompilationInfoRequestStatus_Unknown); 23 } 24 GetCompilationInfo(WGPUCompilationInfoCallback callback,void * userdata)25 void ShaderModule::GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata) { 26 if (client->IsDisconnected()) { 27 callback(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, userdata); 28 return; 29 } 30 31 uint64_t serial = mCompilationInfoRequests.Add({callback, userdata}); 32 33 ShaderModuleGetCompilationInfoCmd cmd; 34 cmd.shaderModuleId = this->id; 35 cmd.requestSerial = serial; 36 37 client->SerializeCommand(cmd); 38 } 39 GetCompilationInfoCallback(uint64_t requestSerial,WGPUCompilationInfoRequestStatus status,const WGPUCompilationInfo * info)40 bool ShaderModule::GetCompilationInfoCallback(uint64_t requestSerial, 41 WGPUCompilationInfoRequestStatus status, 42 const WGPUCompilationInfo* info) { 43 CompilationInfoRequest request; 44 if (!mCompilationInfoRequests.Acquire(requestSerial, &request)) { 45 return false; 46 } 47 48 request.callback(status, info, request.userdata); 49 return true; 50 } 51 CancelCallbacksForDisconnect()52 void ShaderModule::CancelCallbacksForDisconnect() { 53 ClearAllCallbacks(WGPUCompilationInfoRequestStatus_DeviceLost); 54 } 55 ClearAllCallbacks(WGPUCompilationInfoRequestStatus status)56 void ShaderModule::ClearAllCallbacks(WGPUCompilationInfoRequestStatus status) { 57 mCompilationInfoRequests.CloseAll([status](CompilationInfoRequest* request) { 58 if (request->callback != nullptr) { 59 request->callback(status, nullptr, request->userdata); 60 } 61 }); 62 } 63 64 }} // namespace dawn_wire::client 65