1/* This file is generated by venus-protocol.  See vn_protocol_driver.h. */
2
3/*
4 * Copyright 2020 Google LLC
5 * SPDX-License-Identifier: MIT
6 */
7
8#ifndef VN_PROTOCOL_DRIVER_FENCE_H
9#define VN_PROTOCOL_DRIVER_FENCE_H
10
11#include "vn_instance.h"
12#include "vn_protocol_driver_structs.h"
13
14/* struct VkExportFenceCreateInfo chain */
15
16static inline size_t
17vn_sizeof_VkExportFenceCreateInfo_pnext(const void *val)
18{
19    /* no known/supported struct */
20    return vn_sizeof_simple_pointer(NULL);
21}
22
23static inline size_t
24vn_sizeof_VkExportFenceCreateInfo_self(const VkExportFenceCreateInfo *val)
25{
26    size_t size = 0;
27    /* skip val->{sType,pNext} */
28    size += vn_sizeof_VkFlags(&val->handleTypes);
29    return size;
30}
31
32static inline size_t
33vn_sizeof_VkExportFenceCreateInfo(const VkExportFenceCreateInfo *val)
34{
35    size_t size = 0;
36
37    size += vn_sizeof_VkStructureType(&val->sType);
38    size += vn_sizeof_VkExportFenceCreateInfo_pnext(val->pNext);
39    size += vn_sizeof_VkExportFenceCreateInfo_self(val);
40
41    return size;
42}
43
44static inline void
45vn_encode_VkExportFenceCreateInfo_pnext(struct vn_cs_encoder *enc, const void *val)
46{
47    /* no known/supported struct */
48    vn_encode_simple_pointer(enc, NULL);
49}
50
51static inline void
52vn_encode_VkExportFenceCreateInfo_self(struct vn_cs_encoder *enc, const VkExportFenceCreateInfo *val)
53{
54    /* skip val->{sType,pNext} */
55    vn_encode_VkFlags(enc, &val->handleTypes);
56}
57
58static inline void
59vn_encode_VkExportFenceCreateInfo(struct vn_cs_encoder *enc, const VkExportFenceCreateInfo *val)
60{
61    assert(val->sType == VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO);
62    vn_encode_VkStructureType(enc, &(VkStructureType){ VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO });
63    vn_encode_VkExportFenceCreateInfo_pnext(enc, val->pNext);
64    vn_encode_VkExportFenceCreateInfo_self(enc, val);
65}
66
67/* struct VkFenceCreateInfo chain */
68
69static inline size_t
70vn_sizeof_VkFenceCreateInfo_pnext(const void *val)
71{
72    const VkBaseInStructure *pnext = val;
73    size_t size = 0;
74
75    while (pnext) {
76        switch ((int32_t)pnext->sType) {
77        case VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO:
78            size += vn_sizeof_simple_pointer(pnext);
79            size += vn_sizeof_VkStructureType(&pnext->sType);
80            size += vn_sizeof_VkFenceCreateInfo_pnext(pnext->pNext);
81            size += vn_sizeof_VkExportFenceCreateInfo_self((const VkExportFenceCreateInfo *)pnext);
82            return size;
83        default:
84            /* ignore unknown/unsupported struct */
85            break;
86        }
87        pnext = pnext->pNext;
88    }
89
90    return vn_sizeof_simple_pointer(NULL);
91}
92
93static inline size_t
94vn_sizeof_VkFenceCreateInfo_self(const VkFenceCreateInfo *val)
95{
96    size_t size = 0;
97    /* skip val->{sType,pNext} */
98    size += vn_sizeof_VkFlags(&val->flags);
99    return size;
100}
101
102static inline size_t
103vn_sizeof_VkFenceCreateInfo(const VkFenceCreateInfo *val)
104{
105    size_t size = 0;
106
107    size += vn_sizeof_VkStructureType(&val->sType);
108    size += vn_sizeof_VkFenceCreateInfo_pnext(val->pNext);
109    size += vn_sizeof_VkFenceCreateInfo_self(val);
110
111    return size;
112}
113
114static inline void
115vn_encode_VkFenceCreateInfo_pnext(struct vn_cs_encoder *enc, const void *val)
116{
117    const VkBaseInStructure *pnext = val;
118
119    while (pnext) {
120        switch ((int32_t)pnext->sType) {
121        case VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO:
122            vn_encode_simple_pointer(enc, pnext);
123            vn_encode_VkStructureType(enc, &pnext->sType);
124            vn_encode_VkFenceCreateInfo_pnext(enc, pnext->pNext);
125            vn_encode_VkExportFenceCreateInfo_self(enc, (const VkExportFenceCreateInfo *)pnext);
126            return;
127        default:
128            /* ignore unknown/unsupported struct */
129            break;
130        }
131        pnext = pnext->pNext;
132    }
133
134    vn_encode_simple_pointer(enc, NULL);
135}
136
137static inline void
138vn_encode_VkFenceCreateInfo_self(struct vn_cs_encoder *enc, const VkFenceCreateInfo *val)
139{
140    /* skip val->{sType,pNext} */
141    vn_encode_VkFlags(enc, &val->flags);
142}
143
144static inline void
145vn_encode_VkFenceCreateInfo(struct vn_cs_encoder *enc, const VkFenceCreateInfo *val)
146{
147    assert(val->sType == VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
148    vn_encode_VkStructureType(enc, &(VkStructureType){ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO });
149    vn_encode_VkFenceCreateInfo_pnext(enc, val->pNext);
150    vn_encode_VkFenceCreateInfo_self(enc, val);
151}
152
153static inline size_t vn_sizeof_vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
154{
155    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkCreateFence_EXT;
156    const VkFlags cmd_flags = 0;
157    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type) + vn_sizeof_VkFlags(&cmd_flags);
158
159    cmd_size += vn_sizeof_VkDevice(&device);
160    cmd_size += vn_sizeof_simple_pointer(pCreateInfo);
161    if (pCreateInfo)
162        cmd_size += vn_sizeof_VkFenceCreateInfo(pCreateInfo);
163    cmd_size += vn_sizeof_simple_pointer(pAllocator);
164    if (pAllocator)
165        assert(false);
166    cmd_size += vn_sizeof_simple_pointer(pFence);
167    if (pFence)
168        cmd_size += vn_sizeof_VkFence(pFence);
169
170    return cmd_size;
171}
172
173static inline void vn_encode_vkCreateFence(struct vn_cs_encoder *enc, VkCommandFlagsEXT cmd_flags, VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
174{
175    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkCreateFence_EXT;
176
177    vn_encode_VkCommandTypeEXT(enc, &cmd_type);
178    vn_encode_VkFlags(enc, &cmd_flags);
179
180    vn_encode_VkDevice(enc, &device);
181    if (vn_encode_simple_pointer(enc, pCreateInfo))
182        vn_encode_VkFenceCreateInfo(enc, pCreateInfo);
183    if (vn_encode_simple_pointer(enc, pAllocator))
184        assert(false);
185    if (vn_encode_simple_pointer(enc, pFence))
186        vn_encode_VkFence(enc, pFence);
187}
188
189static inline size_t vn_sizeof_vkCreateFence_reply(VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
190{
191    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkCreateFence_EXT;
192    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type);
193
194    VkResult ret;
195    cmd_size += vn_sizeof_VkResult(&ret);
196    /* skip device */
197    /* skip pCreateInfo */
198    /* skip pAllocator */
199    cmd_size += vn_sizeof_simple_pointer(pFence);
200    if (pFence)
201        cmd_size += vn_sizeof_VkFence(pFence);
202
203    return cmd_size;
204}
205
206static inline VkResult vn_decode_vkCreateFence_reply(struct vn_cs_decoder *dec, VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
207{
208    VkCommandTypeEXT command_type;
209    vn_decode_VkCommandTypeEXT(dec, &command_type);
210    assert(command_type == VK_COMMAND_TYPE_vkCreateFence_EXT);
211
212    VkResult ret;
213    vn_decode_VkResult(dec, &ret);
214    /* skip device */
215    /* skip pCreateInfo */
216    /* skip pAllocator */
217    if (vn_decode_simple_pointer(dec)) {
218        vn_decode_VkFence(dec, pFence);
219    } else {
220        pFence = NULL;
221    }
222
223    return ret;
224}
225
226static inline size_t vn_sizeof_vkDestroyFence(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
227{
228    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkDestroyFence_EXT;
229    const VkFlags cmd_flags = 0;
230    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type) + vn_sizeof_VkFlags(&cmd_flags);
231
232    cmd_size += vn_sizeof_VkDevice(&device);
233    cmd_size += vn_sizeof_VkFence(&fence);
234    cmd_size += vn_sizeof_simple_pointer(pAllocator);
235    if (pAllocator)
236        assert(false);
237
238    return cmd_size;
239}
240
241static inline void vn_encode_vkDestroyFence(struct vn_cs_encoder *enc, VkCommandFlagsEXT cmd_flags, VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
242{
243    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkDestroyFence_EXT;
244
245    vn_encode_VkCommandTypeEXT(enc, &cmd_type);
246    vn_encode_VkFlags(enc, &cmd_flags);
247
248    vn_encode_VkDevice(enc, &device);
249    vn_encode_VkFence(enc, &fence);
250    if (vn_encode_simple_pointer(enc, pAllocator))
251        assert(false);
252}
253
254static inline size_t vn_sizeof_vkDestroyFence_reply(VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
255{
256    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkDestroyFence_EXT;
257    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type);
258
259    /* skip device */
260    /* skip fence */
261    /* skip pAllocator */
262
263    return cmd_size;
264}
265
266static inline void vn_decode_vkDestroyFence_reply(struct vn_cs_decoder *dec, VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
267{
268    VkCommandTypeEXT command_type;
269    vn_decode_VkCommandTypeEXT(dec, &command_type);
270    assert(command_type == VK_COMMAND_TYPE_vkDestroyFence_EXT);
271
272    /* skip device */
273    /* skip fence */
274    /* skip pAllocator */
275}
276
277static inline size_t vn_sizeof_vkResetFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences)
278{
279    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkResetFences_EXT;
280    const VkFlags cmd_flags = 0;
281    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type) + vn_sizeof_VkFlags(&cmd_flags);
282
283    cmd_size += vn_sizeof_VkDevice(&device);
284    cmd_size += vn_sizeof_uint32_t(&fenceCount);
285    if (pFences) {
286        cmd_size += vn_sizeof_array_size(fenceCount);
287        for (uint32_t i = 0; i < fenceCount; i++)
288            cmd_size += vn_sizeof_VkFence(&pFences[i]);
289    } else {
290        cmd_size += vn_sizeof_array_size(0);
291    }
292
293    return cmd_size;
294}
295
296static inline void vn_encode_vkResetFences(struct vn_cs_encoder *enc, VkCommandFlagsEXT cmd_flags, VkDevice device, uint32_t fenceCount, const VkFence* pFences)
297{
298    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkResetFences_EXT;
299
300    vn_encode_VkCommandTypeEXT(enc, &cmd_type);
301    vn_encode_VkFlags(enc, &cmd_flags);
302
303    vn_encode_VkDevice(enc, &device);
304    vn_encode_uint32_t(enc, &fenceCount);
305    if (pFences) {
306        vn_encode_array_size(enc, fenceCount);
307        for (uint32_t i = 0; i < fenceCount; i++)
308            vn_encode_VkFence(enc, &pFences[i]);
309    } else {
310        vn_encode_array_size(enc, 0);
311    }
312}
313
314static inline size_t vn_sizeof_vkResetFences_reply(VkDevice device, uint32_t fenceCount, const VkFence* pFences)
315{
316    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkResetFences_EXT;
317    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type);
318
319    VkResult ret;
320    cmd_size += vn_sizeof_VkResult(&ret);
321    /* skip device */
322    /* skip fenceCount */
323    /* skip pFences */
324
325    return cmd_size;
326}
327
328static inline VkResult vn_decode_vkResetFences_reply(struct vn_cs_decoder *dec, VkDevice device, uint32_t fenceCount, const VkFence* pFences)
329{
330    VkCommandTypeEXT command_type;
331    vn_decode_VkCommandTypeEXT(dec, &command_type);
332    assert(command_type == VK_COMMAND_TYPE_vkResetFences_EXT);
333
334    VkResult ret;
335    vn_decode_VkResult(dec, &ret);
336    /* skip device */
337    /* skip fenceCount */
338    /* skip pFences */
339
340    return ret;
341}
342
343static inline size_t vn_sizeof_vkGetFenceStatus(VkDevice device, VkFence fence)
344{
345    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkGetFenceStatus_EXT;
346    const VkFlags cmd_flags = 0;
347    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type) + vn_sizeof_VkFlags(&cmd_flags);
348
349    cmd_size += vn_sizeof_VkDevice(&device);
350    cmd_size += vn_sizeof_VkFence(&fence);
351
352    return cmd_size;
353}
354
355static inline void vn_encode_vkGetFenceStatus(struct vn_cs_encoder *enc, VkCommandFlagsEXT cmd_flags, VkDevice device, VkFence fence)
356{
357    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkGetFenceStatus_EXT;
358
359    vn_encode_VkCommandTypeEXT(enc, &cmd_type);
360    vn_encode_VkFlags(enc, &cmd_flags);
361
362    vn_encode_VkDevice(enc, &device);
363    vn_encode_VkFence(enc, &fence);
364}
365
366static inline size_t vn_sizeof_vkGetFenceStatus_reply(VkDevice device, VkFence fence)
367{
368    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkGetFenceStatus_EXT;
369    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type);
370
371    VkResult ret;
372    cmd_size += vn_sizeof_VkResult(&ret);
373    /* skip device */
374    /* skip fence */
375
376    return cmd_size;
377}
378
379static inline VkResult vn_decode_vkGetFenceStatus_reply(struct vn_cs_decoder *dec, VkDevice device, VkFence fence)
380{
381    VkCommandTypeEXT command_type;
382    vn_decode_VkCommandTypeEXT(dec, &command_type);
383    assert(command_type == VK_COMMAND_TYPE_vkGetFenceStatus_EXT);
384
385    VkResult ret;
386    vn_decode_VkResult(dec, &ret);
387    /* skip device */
388    /* skip fence */
389
390    return ret;
391}
392
393static inline size_t vn_sizeof_vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
394{
395    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkWaitForFences_EXT;
396    const VkFlags cmd_flags = 0;
397    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type) + vn_sizeof_VkFlags(&cmd_flags);
398
399    cmd_size += vn_sizeof_VkDevice(&device);
400    cmd_size += vn_sizeof_uint32_t(&fenceCount);
401    if (pFences) {
402        cmd_size += vn_sizeof_array_size(fenceCount);
403        for (uint32_t i = 0; i < fenceCount; i++)
404            cmd_size += vn_sizeof_VkFence(&pFences[i]);
405    } else {
406        cmd_size += vn_sizeof_array_size(0);
407    }
408    cmd_size += vn_sizeof_VkBool32(&waitAll);
409    cmd_size += vn_sizeof_uint64_t(&timeout);
410
411    return cmd_size;
412}
413
414static inline void vn_encode_vkWaitForFences(struct vn_cs_encoder *enc, VkCommandFlagsEXT cmd_flags, VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
415{
416    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkWaitForFences_EXT;
417
418    vn_encode_VkCommandTypeEXT(enc, &cmd_type);
419    vn_encode_VkFlags(enc, &cmd_flags);
420
421    vn_encode_VkDevice(enc, &device);
422    vn_encode_uint32_t(enc, &fenceCount);
423    if (pFences) {
424        vn_encode_array_size(enc, fenceCount);
425        for (uint32_t i = 0; i < fenceCount; i++)
426            vn_encode_VkFence(enc, &pFences[i]);
427    } else {
428        vn_encode_array_size(enc, 0);
429    }
430    vn_encode_VkBool32(enc, &waitAll);
431    vn_encode_uint64_t(enc, &timeout);
432}
433
434static inline size_t vn_sizeof_vkWaitForFences_reply(VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
435{
436    const VkCommandTypeEXT cmd_type = VK_COMMAND_TYPE_vkWaitForFences_EXT;
437    size_t cmd_size = vn_sizeof_VkCommandTypeEXT(&cmd_type);
438
439    VkResult ret;
440    cmd_size += vn_sizeof_VkResult(&ret);
441    /* skip device */
442    /* skip fenceCount */
443    /* skip pFences */
444    /* skip waitAll */
445    /* skip timeout */
446
447    return cmd_size;
448}
449
450static inline VkResult vn_decode_vkWaitForFences_reply(struct vn_cs_decoder *dec, VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
451{
452    VkCommandTypeEXT command_type;
453    vn_decode_VkCommandTypeEXT(dec, &command_type);
454    assert(command_type == VK_COMMAND_TYPE_vkWaitForFences_EXT);
455
456    VkResult ret;
457    vn_decode_VkResult(dec, &ret);
458    /* skip device */
459    /* skip fenceCount */
460    /* skip pFences */
461    /* skip waitAll */
462    /* skip timeout */
463
464    return ret;
465}
466
467static inline void vn_submit_vkCreateFence(struct vn_instance *vn_instance, VkCommandFlagsEXT cmd_flags, VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence, struct vn_instance_submit_command *submit)
468{
469    uint8_t local_cmd_data[VN_SUBMIT_LOCAL_CMD_SIZE];
470    void *cmd_data = local_cmd_data;
471    size_t cmd_size = vn_sizeof_vkCreateFence(device, pCreateInfo, pAllocator, pFence);
472    if (cmd_size > sizeof(local_cmd_data)) {
473        cmd_data = malloc(cmd_size);
474        if (!cmd_data)
475            cmd_size = 0;
476    }
477    const size_t reply_size = cmd_flags & VK_COMMAND_GENERATE_REPLY_BIT_EXT ? vn_sizeof_vkCreateFence_reply(device, pCreateInfo, pAllocator, pFence) : 0;
478
479    struct vn_cs_encoder *enc = vn_instance_submit_command_init(vn_instance, submit, cmd_data, cmd_size, reply_size);
480    if (cmd_size) {
481        vn_encode_vkCreateFence(enc, cmd_flags, device, pCreateInfo, pAllocator, pFence);
482        vn_instance_submit_command(vn_instance, submit);
483        if (cmd_data != local_cmd_data)
484            free(cmd_data);
485    }
486}
487
488static inline void vn_submit_vkDestroyFence(struct vn_instance *vn_instance, VkCommandFlagsEXT cmd_flags, VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator, struct vn_instance_submit_command *submit)
489{
490    uint8_t local_cmd_data[VN_SUBMIT_LOCAL_CMD_SIZE];
491    void *cmd_data = local_cmd_data;
492    size_t cmd_size = vn_sizeof_vkDestroyFence(device, fence, pAllocator);
493    if (cmd_size > sizeof(local_cmd_data)) {
494        cmd_data = malloc(cmd_size);
495        if (!cmd_data)
496            cmd_size = 0;
497    }
498    const size_t reply_size = cmd_flags & VK_COMMAND_GENERATE_REPLY_BIT_EXT ? vn_sizeof_vkDestroyFence_reply(device, fence, pAllocator) : 0;
499
500    struct vn_cs_encoder *enc = vn_instance_submit_command_init(vn_instance, submit, cmd_data, cmd_size, reply_size);
501    if (cmd_size) {
502        vn_encode_vkDestroyFence(enc, cmd_flags, device, fence, pAllocator);
503        vn_instance_submit_command(vn_instance, submit);
504        if (cmd_data != local_cmd_data)
505            free(cmd_data);
506    }
507}
508
509static inline void vn_submit_vkResetFences(struct vn_instance *vn_instance, VkCommandFlagsEXT cmd_flags, VkDevice device, uint32_t fenceCount, const VkFence* pFences, struct vn_instance_submit_command *submit)
510{
511    uint8_t local_cmd_data[VN_SUBMIT_LOCAL_CMD_SIZE];
512    void *cmd_data = local_cmd_data;
513    size_t cmd_size = vn_sizeof_vkResetFences(device, fenceCount, pFences);
514    if (cmd_size > sizeof(local_cmd_data)) {
515        cmd_data = malloc(cmd_size);
516        if (!cmd_data)
517            cmd_size = 0;
518    }
519    const size_t reply_size = cmd_flags & VK_COMMAND_GENERATE_REPLY_BIT_EXT ? vn_sizeof_vkResetFences_reply(device, fenceCount, pFences) : 0;
520
521    struct vn_cs_encoder *enc = vn_instance_submit_command_init(vn_instance, submit, cmd_data, cmd_size, reply_size);
522    if (cmd_size) {
523        vn_encode_vkResetFences(enc, cmd_flags, device, fenceCount, pFences);
524        vn_instance_submit_command(vn_instance, submit);
525        if (cmd_data != local_cmd_data)
526            free(cmd_data);
527    }
528}
529
530static inline void vn_submit_vkGetFenceStatus(struct vn_instance *vn_instance, VkCommandFlagsEXT cmd_flags, VkDevice device, VkFence fence, struct vn_instance_submit_command *submit)
531{
532    uint8_t local_cmd_data[VN_SUBMIT_LOCAL_CMD_SIZE];
533    void *cmd_data = local_cmd_data;
534    size_t cmd_size = vn_sizeof_vkGetFenceStatus(device, fence);
535    if (cmd_size > sizeof(local_cmd_data)) {
536        cmd_data = malloc(cmd_size);
537        if (!cmd_data)
538            cmd_size = 0;
539    }
540    const size_t reply_size = cmd_flags & VK_COMMAND_GENERATE_REPLY_BIT_EXT ? vn_sizeof_vkGetFenceStatus_reply(device, fence) : 0;
541
542    struct vn_cs_encoder *enc = vn_instance_submit_command_init(vn_instance, submit, cmd_data, cmd_size, reply_size);
543    if (cmd_size) {
544        vn_encode_vkGetFenceStatus(enc, cmd_flags, device, fence);
545        vn_instance_submit_command(vn_instance, submit);
546        if (cmd_data != local_cmd_data)
547            free(cmd_data);
548    }
549}
550
551static inline void vn_submit_vkWaitForFences(struct vn_instance *vn_instance, VkCommandFlagsEXT cmd_flags, VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout, struct vn_instance_submit_command *submit)
552{
553    uint8_t local_cmd_data[VN_SUBMIT_LOCAL_CMD_SIZE];
554    void *cmd_data = local_cmd_data;
555    size_t cmd_size = vn_sizeof_vkWaitForFences(device, fenceCount, pFences, waitAll, timeout);
556    if (cmd_size > sizeof(local_cmd_data)) {
557        cmd_data = malloc(cmd_size);
558        if (!cmd_data)
559            cmd_size = 0;
560    }
561    const size_t reply_size = cmd_flags & VK_COMMAND_GENERATE_REPLY_BIT_EXT ? vn_sizeof_vkWaitForFences_reply(device, fenceCount, pFences, waitAll, timeout) : 0;
562
563    struct vn_cs_encoder *enc = vn_instance_submit_command_init(vn_instance, submit, cmd_data, cmd_size, reply_size);
564    if (cmd_size) {
565        vn_encode_vkWaitForFences(enc, cmd_flags, device, fenceCount, pFences, waitAll, timeout);
566        vn_instance_submit_command(vn_instance, submit);
567        if (cmd_data != local_cmd_data)
568            free(cmd_data);
569    }
570}
571
572static inline VkResult vn_call_vkCreateFence(struct vn_instance *vn_instance, VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
573{
574    VN_TRACE_FUNC();
575
576    struct vn_instance_submit_command submit;
577    vn_submit_vkCreateFence(vn_instance, VK_COMMAND_GENERATE_REPLY_BIT_EXT, device, pCreateInfo, pAllocator, pFence, &submit);
578    struct vn_cs_decoder *dec = vn_instance_get_command_reply(vn_instance, &submit);
579    if (dec) {
580        const VkResult ret = vn_decode_vkCreateFence_reply(dec, device, pCreateInfo, pAllocator, pFence);
581        vn_instance_free_command_reply(vn_instance, &submit);
582        return ret;
583    } else {
584        return VK_ERROR_OUT_OF_HOST_MEMORY;
585    }
586}
587
588static inline void vn_async_vkCreateFence(struct vn_instance *vn_instance, VkDevice device, const VkFenceCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkFence* pFence)
589{
590    struct vn_instance_submit_command submit;
591    vn_submit_vkCreateFence(vn_instance, 0, device, pCreateInfo, pAllocator, pFence, &submit);
592}
593
594static inline void vn_call_vkDestroyFence(struct vn_instance *vn_instance, VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
595{
596    VN_TRACE_FUNC();
597
598    struct vn_instance_submit_command submit;
599    vn_submit_vkDestroyFence(vn_instance, VK_COMMAND_GENERATE_REPLY_BIT_EXT, device, fence, pAllocator, &submit);
600    struct vn_cs_decoder *dec = vn_instance_get_command_reply(vn_instance, &submit);
601    if (dec) {
602        vn_decode_vkDestroyFence_reply(dec, device, fence, pAllocator);
603        vn_instance_free_command_reply(vn_instance, &submit);
604    }
605}
606
607static inline void vn_async_vkDestroyFence(struct vn_instance *vn_instance, VkDevice device, VkFence fence, const VkAllocationCallbacks* pAllocator)
608{
609    struct vn_instance_submit_command submit;
610    vn_submit_vkDestroyFence(vn_instance, 0, device, fence, pAllocator, &submit);
611}
612
613static inline VkResult vn_call_vkResetFences(struct vn_instance *vn_instance, VkDevice device, uint32_t fenceCount, const VkFence* pFences)
614{
615    VN_TRACE_FUNC();
616
617    struct vn_instance_submit_command submit;
618    vn_submit_vkResetFences(vn_instance, VK_COMMAND_GENERATE_REPLY_BIT_EXT, device, fenceCount, pFences, &submit);
619    struct vn_cs_decoder *dec = vn_instance_get_command_reply(vn_instance, &submit);
620    if (dec) {
621        const VkResult ret = vn_decode_vkResetFences_reply(dec, device, fenceCount, pFences);
622        vn_instance_free_command_reply(vn_instance, &submit);
623        return ret;
624    } else {
625        return VK_ERROR_OUT_OF_HOST_MEMORY;
626    }
627}
628
629static inline void vn_async_vkResetFences(struct vn_instance *vn_instance, VkDevice device, uint32_t fenceCount, const VkFence* pFences)
630{
631    struct vn_instance_submit_command submit;
632    vn_submit_vkResetFences(vn_instance, 0, device, fenceCount, pFences, &submit);
633}
634
635static inline VkResult vn_call_vkGetFenceStatus(struct vn_instance *vn_instance, VkDevice device, VkFence fence)
636{
637    VN_TRACE_FUNC();
638
639    struct vn_instance_submit_command submit;
640    vn_submit_vkGetFenceStatus(vn_instance, VK_COMMAND_GENERATE_REPLY_BIT_EXT, device, fence, &submit);
641    struct vn_cs_decoder *dec = vn_instance_get_command_reply(vn_instance, &submit);
642    if (dec) {
643        const VkResult ret = vn_decode_vkGetFenceStatus_reply(dec, device, fence);
644        vn_instance_free_command_reply(vn_instance, &submit);
645        return ret;
646    } else {
647        return VK_ERROR_OUT_OF_HOST_MEMORY;
648    }
649}
650
651static inline void vn_async_vkGetFenceStatus(struct vn_instance *vn_instance, VkDevice device, VkFence fence)
652{
653    struct vn_instance_submit_command submit;
654    vn_submit_vkGetFenceStatus(vn_instance, 0, device, fence, &submit);
655}
656
657static inline VkResult vn_call_vkWaitForFences(struct vn_instance *vn_instance, VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
658{
659    VN_TRACE_FUNC();
660
661    struct vn_instance_submit_command submit;
662    vn_submit_vkWaitForFences(vn_instance, VK_COMMAND_GENERATE_REPLY_BIT_EXT, device, fenceCount, pFences, waitAll, timeout, &submit);
663    struct vn_cs_decoder *dec = vn_instance_get_command_reply(vn_instance, &submit);
664    if (dec) {
665        const VkResult ret = vn_decode_vkWaitForFences_reply(dec, device, fenceCount, pFences, waitAll, timeout);
666        vn_instance_free_command_reply(vn_instance, &submit);
667        return ret;
668    } else {
669        return VK_ERROR_OUT_OF_HOST_MEMORY;
670    }
671}
672
673static inline void vn_async_vkWaitForFences(struct vn_instance *vn_instance, VkDevice device, uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, uint64_t timeout)
674{
675    struct vn_instance_submit_command submit;
676    vn_submit_vkWaitForFences(vn_instance, 0, device, fenceCount, pFences, waitAll, timeout, &submit);
677}
678
679#endif /* VN_PROTOCOL_DRIVER_FENCE_H */
680