1 // Copyright 2020 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 #ifndef DAWNWIRE_CLIENT_QUEUE_H_ 16 #define DAWNWIRE_CLIENT_QUEUE_H_ 17 18 #include <dawn/webgpu.h> 19 20 #include "dawn_wire/WireClient.h" 21 #include "dawn_wire/client/ObjectBase.h" 22 #include "dawn_wire/client/RequestTracker.h" 23 24 namespace dawn_wire { namespace client { 25 26 class Queue final : public ObjectBase { 27 public: 28 using ObjectBase::ObjectBase; 29 ~Queue(); 30 31 bool OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus status); 32 33 // Dawn API 34 void OnSubmittedWorkDone(uint64_t signalValue, 35 WGPUQueueWorkDoneCallback callback, 36 void* userdata); 37 void WriteBuffer(WGPUBuffer cBuffer, uint64_t bufferOffset, const void* data, size_t size); 38 void WriteTexture(const WGPUImageCopyTexture* destination, 39 const void* data, 40 size_t dataSize, 41 const WGPUTextureDataLayout* dataLayout, 42 const WGPUExtent3D* writeSize); 43 44 private: 45 void CancelCallbacksForDisconnect() override; 46 void ClearAllCallbacks(WGPUQueueWorkDoneStatus status); 47 48 struct OnWorkDoneData { 49 WGPUQueueWorkDoneCallback callback = nullptr; 50 void* userdata = nullptr; 51 }; 52 RequestTracker<OnWorkDoneData> mOnWorkDoneRequests; 53 }; 54 55 }} // namespace dawn_wire::client 56 57 #endif // DAWNWIRE_CLIENT_QUEUE_H_ 58