• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/server/Server.h"
17 
18 namespace dawn_wire { namespace server {
19 
OnQueueWorkDone(WGPUQueueWorkDoneStatus status,QueueWorkDoneUserdata * data)20     void Server::OnQueueWorkDone(WGPUQueueWorkDoneStatus status, QueueWorkDoneUserdata* data) {
21         ReturnQueueWorkDoneCallbackCmd cmd;
22         cmd.queue = data->queue;
23         cmd.requestSerial = data->requestSerial;
24         cmd.status = status;
25 
26         SerializeCommand(cmd);
27     }
28 
DoQueueOnSubmittedWorkDone(ObjectId queueId,uint64_t signalValue,uint64_t requestSerial)29     bool Server::DoQueueOnSubmittedWorkDone(ObjectId queueId,
30                                             uint64_t signalValue,
31                                             uint64_t requestSerial) {
32         auto* queue = QueueObjects().Get(queueId);
33         if (queue == nullptr) {
34             return false;
35         }
36 
37         auto userdata = MakeUserdata<QueueWorkDoneUserdata>();
38         userdata->queue = ObjectHandle{queueId, queue->generation};
39         userdata->requestSerial = requestSerial;
40 
41         mProcs.queueOnSubmittedWorkDone(
42             queue->handle, signalValue,
43             ForwardToServer<decltype(&Server::OnQueueWorkDone)>::Func<&Server::OnQueueWorkDone>(),
44             userdata.release());
45         return true;
46     }
47 
DoQueueWriteBuffer(ObjectId queueId,ObjectId bufferId,uint64_t bufferOffset,const uint8_t * data,uint64_t size)48     bool Server::DoQueueWriteBuffer(ObjectId queueId,
49                                     ObjectId bufferId,
50                                     uint64_t bufferOffset,
51                                     const uint8_t* data,
52                                     uint64_t size) {
53         // The null object isn't valid as `self` or `buffer` so we can combine the check with the
54         // check that the ID is valid.
55         auto* queue = QueueObjects().Get(queueId);
56         auto* buffer = BufferObjects().Get(bufferId);
57         if (queue == nullptr || buffer == nullptr) {
58             return false;
59         }
60 
61         if (size > std::numeric_limits<size_t>::max()) {
62             auto* device = DeviceObjects().Get(queue->deviceInfo->self.id);
63             if (device == nullptr) {
64                 return false;
65             }
66             return DoDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
67                                        WGPUErrorType_OutOfMemory,
68                                        "Data size too large for write texture.");
69         }
70 
71         mProcs.queueWriteBuffer(queue->handle, buffer->handle, bufferOffset, data,
72                                 static_cast<size_t>(size));
73         return true;
74     }
75 
DoQueueWriteTexture(ObjectId queueId,const WGPUImageCopyTexture * destination,const uint8_t * data,uint64_t dataSize,const WGPUTextureDataLayout * dataLayout,const WGPUExtent3D * writeSize)76     bool Server::DoQueueWriteTexture(ObjectId queueId,
77                                      const WGPUImageCopyTexture* destination,
78                                      const uint8_t* data,
79                                      uint64_t dataSize,
80                                      const WGPUTextureDataLayout* dataLayout,
81                                      const WGPUExtent3D* writeSize) {
82         // The null object isn't valid as `self` so we can combine the check with the
83         // check that the ID is valid.
84         auto* queue = QueueObjects().Get(queueId);
85         if (queue == nullptr) {
86             return false;
87         }
88 
89         if (dataSize > std::numeric_limits<size_t>::max()) {
90             auto* device = DeviceObjects().Get(queue->deviceInfo->self.id);
91             if (device == nullptr) {
92                 return false;
93             }
94             return DoDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
95                                        WGPUErrorType_OutOfMemory,
96                                        "Data size too large for write texture.");
97         }
98 
99         mProcs.queueWriteTexture(queue->handle, destination, data, static_cast<size_t>(dataSize),
100                                  dataLayout, writeSize);
101         return true;
102     }
103 
104 }}  // namespace dawn_wire::server
105