1 /* This file is generated by venus-protocol. See vn_protocol_renderer.h. */
2
3 /*
4 * Copyright 2020 Google LLC
5 * SPDX-License-Identifier: MIT
6 */
7
8 #ifndef VN_PROTOCOL_RENDERER_CS_H
9 #define VN_PROTOCOL_RENDERER_CS_H
10
11 #include <assert.h>
12
13 /*
14 * These types/functions are expected
15 *
16 * struct vn_cs_encoder
17 * vn_cs_encoder_write
18 *
19 * struct vn_cs_decoder
20 * vn_cs_decoder_set_fatal
21 * vn_cs_decoder_get_fatal
22 * vn_cs_decoder_lookup_object
23 * vn_cs_decoder_reset_temp_pool
24 * vn_cs_decoder_alloc_temp
25 * vn_cs_decoder_read
26 * vn_cs_decoder_peek
27 *
28 * vn_object_id
29 * vn_cs_handle_indirect_id
30 * vn_cs_handle_load_id
31 * vn_cs_handle_store_id
32 * vn_cs_get_object_handle
33 */
34 #include "vkr_cs.h"
35
36 struct vn_cs_encoder;
37 struct vn_cs_decoder;
38
39 typedef vkr_object_id vn_object_id;
40
41 #pragma GCC diagnostic push
42 #pragma GCC diagnostic ignored "-Wunused-parameter"
43
44 static inline void
vn_cs_encoder_write(struct vn_cs_encoder * enc,size_t size,const void * val,size_t val_size)45 vn_cs_encoder_write(struct vn_cs_encoder *enc, size_t size, const void *val, size_t val_size)
46 {
47 struct vkr_cs_encoder *e = (struct vkr_cs_encoder *)enc;
48 vkr_cs_encoder_write(e, size, val, val_size);
49 }
50
51 static inline void
vn_cs_decoder_set_fatal(const struct vn_cs_decoder * dec)52 vn_cs_decoder_set_fatal(const struct vn_cs_decoder *dec)
53 {
54 const struct vkr_cs_decoder *d = (struct vkr_cs_decoder *)dec;
55 vkr_cs_decoder_set_fatal(d);
56 }
57
58 static inline bool
vn_cs_decoder_get_fatal(const struct vn_cs_decoder * dec)59 vn_cs_decoder_get_fatal(const struct vn_cs_decoder *dec)
60 {
61 const struct vkr_cs_decoder *d = (struct vkr_cs_decoder *)dec;
62 return vkr_cs_decoder_get_fatal(d);
63 }
64
65 static inline void *
vn_cs_decoder_lookup_object(const struct vn_cs_decoder * dec,vn_object_id id,VkObjectType type)66 vn_cs_decoder_lookup_object(const struct vn_cs_decoder *dec, vn_object_id id, VkObjectType type)
67 {
68 const struct vkr_cs_decoder *d = (const struct vkr_cs_decoder *)dec;
69 return vkr_cs_decoder_lookup_object(d, id, type);
70 }
71
72 static inline void
vn_cs_decoder_reset_temp_pool(struct vn_cs_decoder * dec)73 vn_cs_decoder_reset_temp_pool(struct vn_cs_decoder *dec)
74 {
75 struct vkr_cs_decoder *d = (struct vkr_cs_decoder *)dec;
76 vkr_cs_decoder_reset_temp_pool(d);
77 }
78
79 static inline void *
vn_cs_decoder_alloc_temp(struct vn_cs_decoder * dec,size_t size)80 vn_cs_decoder_alloc_temp(struct vn_cs_decoder *dec, size_t size)
81 {
82 struct vkr_cs_decoder *d = (struct vkr_cs_decoder *)dec;
83 return vkr_cs_decoder_alloc_temp(d, size);
84 }
85
86 static inline void
vn_cs_decoder_read(struct vn_cs_decoder * dec,size_t size,void * val,size_t val_size)87 vn_cs_decoder_read(struct vn_cs_decoder *dec, size_t size, void *val, size_t val_size)
88 {
89 struct vkr_cs_decoder *d = (struct vkr_cs_decoder *)dec;
90 vkr_cs_decoder_read(d, size, val, val_size);
91 }
92
93 static inline void
vn_cs_decoder_peek(const struct vn_cs_decoder * dec,size_t size,void * val,size_t val_size)94 vn_cs_decoder_peek(const struct vn_cs_decoder *dec, size_t size, void *val, size_t val_size)
95 {
96 const struct vkr_cs_decoder *d = (const struct vkr_cs_decoder *)dec;
97 vkr_cs_decoder_peek(d, size, val, val_size);
98 }
99
100 static inline bool
vn_cs_handle_indirect_id(VkObjectType type)101 vn_cs_handle_indirect_id(VkObjectType type)
102 {
103 return vkr_cs_handle_indirect_id(type);
104 }
105
106 static inline vn_object_id
vn_cs_handle_load_id(const void ** handle,VkObjectType type)107 vn_cs_handle_load_id(const void **handle, VkObjectType type)
108 {
109 return vkr_cs_handle_load_id(handle, type);
110 }
111
112 static inline void
vn_cs_handle_store_id(void ** handle,vn_object_id id,VkObjectType type)113 vn_cs_handle_store_id(void **handle, vn_object_id id, VkObjectType type)
114 {
115 vkr_cs_handle_store_id(handle, id, type);
116 }
117
118 static inline uint64_t
vn_cs_get_object_handle(const void ** handle,VkObjectType type)119 vn_cs_get_object_handle(const void **handle, VkObjectType type)
120 {
121 const struct vkr_object *obj = *(const struct vkr_object **)handle;
122 return obj ? obj->handle.u64 : 0;
123 }
124
125 static inline void
vn_encode(struct vn_cs_encoder * enc,size_t size,const void * data,size_t data_size)126 vn_encode(struct vn_cs_encoder *enc, size_t size, const void *data, size_t data_size)
127 {
128 assert(size % 4 == 0);
129 /* no vn_cs_encoder_reserve; vn_cs_encoder_write must do size check */
130 /* TODO check if the generated code is optimal */
131 vn_cs_encoder_write(enc, size, data, data_size);
132 }
133
134 static inline void
vn_decode(struct vn_cs_decoder * dec,size_t size,void * data,size_t data_size)135 vn_decode(struct vn_cs_decoder *dec, size_t size, void *data, size_t data_size)
136 {
137 assert(size % 4 == 0);
138 vn_cs_decoder_read(dec, size, data, data_size);
139 }
140
141 #pragma GCC diagnostic pop
142
143 #endif /* VN_PROTOCOL_RENDERER_CS_H */
144