2 * Copyright 2016 Patrick Rudolph <siro@das-labor.org>
4 * Permission is hereby granted, free of charge, f, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, f, copy, modify, merge, f, publish, distribute, f, sub
8 * license, f, and/or sell copies of the Software, f, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISe, f, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23 /* get number of arguments with __NARG__ */
24 #define __NARG__(...) __NARG_I_(__VA_ARGS__,__RSEQ_N())
25 #define __NARG_I_(...) __ARG_N(__VA_ARGS__)
27 _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
28 _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
29 _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
30 _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
31 _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
32 _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
36 59,58,57,56,55,54,53,52,51,50, \
37 49,48,47,46,45,44,43,42,41,40, \
38 39,38,37,36,35,34,33,32,31,30, \
39 29,28,27,26,25,24,23,22,21,20, \
40 19,18,17,16,15,14,13,12,11,10, \
44 #define _args_for_bypass_1(a) a
45 #define _args_for_bypass_7(a, b, c, d, e, f, g) ,g
46 #define _args_for_bypass_14(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_7(__VA_ARGS__)
47 #define _args_for_bypass_21(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_14(__VA_ARGS__)
48 #define _args_for_bypass_28(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_21(__VA_ARGS__)
49 #define _args_for_bypass_35(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_28(__VA_ARGS__)
50 #define _args_for_bypass_42(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_35(__VA_ARGS__)
51 #define _args_for_bypass_49(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_42(__VA_ARGS__)
52 #define _args_for_bypass_56(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_49(__VA_ARGS__)
53 #define _args_for_bypass_63(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_56(__VA_ARGS__)
54 #define _args_for_bypass_70(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_63(__VA_ARGS__)
56 #define _GFUNC_(n) _args_for_bypass_##n
57 #define _GFUNC(n) _GFUNC_(n)
59 #define ARGS_FOR_BYPASS(...) _GFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
61 #define _args_for_mem_1(a) a;
62 #define _args_for_mem_7(a, b, c, d, e, f, g) f;
63 #define _args_for_mem_14(a, b, c, d, e, f, g, ...) f; _args_for_mem_7(__VA_ARGS__)
64 #define _args_for_mem_21(a, b, c, d, e, f, g, ...) f; _args_for_mem_14(__VA_ARGS__)
65 #define _args_for_mem_28(a, b, c, d, e, f, g, ...) f; _args_for_mem_21(__VA_ARGS__)
66 #define _args_for_mem_35(a, b, c, d, e, f, g, ...) f; _args_for_mem_28(__VA_ARGS__)
67 #define _args_for_mem_42(a, b, c, d, e, f, g, ...) f; _args_for_mem_35(__VA_ARGS__)
68 #define _args_for_mem_49(a, b, c, d, e, f, g, ...) f; _args_for_mem_42(__VA_ARGS__)
69 #define _args_for_mem_56(a, b, c, d, e, f, g, ...) f; _args_for_mem_49(__VA_ARGS__)
70 #define _args_for_mem_63(a, b, c, d, e, f, g, ...) f; _args_for_mem_56(__VA_ARGS__)
71 #define _args_for_mem_70(a, b, c, d, e, f, g, ...) f; _args_for_mem_63(__VA_ARGS__)
73 #define _FFUNC_(n) _args_for_mem_##n
74 #define _FFUNC(n) _FFUNC_(n)
76 #define ARGS_FOR_MEM(...) _FFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
78 #define _args_for_unbind_1(a) a;
79 #define _args_for_unbind_7(a, b, c, d, e, f, g) e;
80 #define _args_for_unbind_14(a, b, c, d, e, f, g, ...) e; _args_for_unbind_7(__VA_ARGS__)
81 #define _args_for_unbind_21(a, b, c, d, e, f, g, ...) e; _args_for_unbind_14(__VA_ARGS__)
82 #define _args_for_unbind_28(a, b, c, d, e, f, g, ...) e; _args_for_unbind_21(__VA_ARGS__)
83 #define _args_for_unbind_35(a, b, c, d, e, f, g, ...) e; _args_for_unbind_28(__VA_ARGS__)
84 #define _args_for_unbind_42(a, b, c, d, e, f, g, ...) e; _args_for_unbind_35(__VA_ARGS__)
85 #define _args_for_unbind_49(a, b, c, d, e, f, g, ...) e; _args_for_unbind_42(__VA_ARGS__)
86 #define _args_for_unbind_56(a, b, c, d, e, f, g, ...) e; _args_for_unbind_49(__VA_ARGS__)
87 #define _args_for_unbind_63(a, b, c, d, e, f, g, ...) e; _args_for_unbind_56(__VA_ARGS__)
88 #define _args_for_unbind_70(a, b, c, d, e, f, g, ...) e; _args_for_unbind_63(__VA_ARGS__)
90 #define _EFUNC_(n) _args_for_unbind_##n
91 #define _EFUNC(n) _EFUNC_(n)
93 #define ARGS_FOR_UNBIND(...) _EFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
95 #define _args_for_call_1(a) a
96 #define _args_for_call_7(a, b, c, d, e, f, g) ,d
97 #define _args_for_call_14(a, b, c, d, e, f, g, ...) ,d _args_for_call_7(__VA_ARGS__)
98 #define _args_for_call_21(a, b, c, d, e, f, g, ...) ,d _args_for_call_14(__VA_ARGS__)
99 #define _args_for_call_28(a, b, c, d, e, f, g, ...) ,d _args_for_call_21(__VA_ARGS__)
100 #define _args_for_call_35(a, b, c, d, e, f, g, ...) ,d _args_for_call_28(__VA_ARGS__)
101 #define _args_for_call_42(a, b, c, d, e, f, g, ...) ,d _args_for_call_35(__VA_ARGS__)
102 #define _args_for_call_49(a, b, c, d, e, f, g, ...) ,d _args_for_call_42(__VA_ARGS__)
103 #define _args_for_call_56(a, b, c, d, e, f, g, ...) ,d _args_for_call_49(__VA_ARGS__)
104 #define _args_for_call_63(a, b, c, d, e, f, g, ...) ,d _args_for_call_56(__VA_ARGS__)
105 #define _args_for_call_70(a, b, c, d, e, f, g, ...) ,d _args_for_call_63(__VA_ARGS__)
107 #define _DFUNC_(n) _args_for_call_##n
108 #define _DFUNC(n) _DFUNC_(n)
110 #define ARGS_FOR_CALL(...) _DFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
112 #define _args_for_decl_1(a) a
113 #define _args_for_decl_7(a, b, c, d, e, f, g) ,c
114 #define _args_for_decl_14(a, b, c, d, e, f, g, ...) ,c _args_for_decl_7(__VA_ARGS__)
115 #define _args_for_decl_21(a, b, c, d, e, f, g, ...) ,c _args_for_decl_14(__VA_ARGS__)
116 #define _args_for_decl_28(a, b, c, d, e, f, g, ...) ,c _args_for_decl_21(__VA_ARGS__)
117 #define _args_for_decl_35(a, b, c, d, e, f, g, ...) ,c _args_for_decl_28(__VA_ARGS__)
118 #define _args_for_decl_42(a, b, c, d, e, f, g, ...) ,c _args_for_decl_35(__VA_ARGS__)
119 #define _args_for_decl_49(a, b, c, d, e, f, g, ...) ,c _args_for_decl_42(__VA_ARGS__)
120 #define _args_for_decl_56(a, b, c, d, e, f, g, ...) ,c _args_for_decl_49(__VA_ARGS__)
121 #define _args_for_decl_63(a, b, c, d, e, f, g, ...) ,c _args_for_decl_56(__VA_ARGS__)
122 #define _args_for_decl_70(a, b, c, d, e, f, g, ...) ,c _args_for_decl_63(__VA_ARGS__)
124 #define _CFUNC_(n) _args_for_decl_##n
125 #define _CFUNC(n) _CFUNC_(n)
127 #define ARGS_FOR_DECLARATION(...) _CFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
129 #define _args_for_assign_1(a) a
130 #define _args_for_assign_7(a, b, c, d, e, f, g) b;
131 #define _args_for_assign_14(a, b, c, d, e, f, g, ...) b; _args_for_assign_7(__VA_ARGS__)
132 #define _args_for_assign_21(a, b, c, d, e, f, g, ...) b; _args_for_assign_14(__VA_ARGS__)
133 #define _args_for_assign_28(a, b, c, d, e, f, g, ...) b; _args_for_assign_21(__VA_ARGS__)
134 #define _args_for_assign_35(a, b, c, d, e, f, g, ...) b; _args_for_assign_28(__VA_ARGS__)
135 #define _args_for_assign_42(a, b, c, d, e, f, g, ...) b; _args_for_assign_35(__VA_ARGS__)
136 #define _args_for_assign_49(a, b, c, d, e, f, g, ...) b; _args_for_assign_42(__VA_ARGS__)
137 #define _args_for_assign_56(a, b, c, d, e, f, g, ...) b; _args_for_assign_49(__VA_ARGS__)
138 #define _args_for_assign_63(a, b, c, d, e, f, g, ...) b; _args_for_assign_56(__VA_ARGS__)
139 #define _args_for_assign_70(a, b, c, d, e, f, g, ...) b; _args_for_assign_63(__VA_ARGS__)
141 #define _BFUNC_(n) _args_for_assign_##n
142 #define _BFUNC(n) _BFUNC_(n)
144 #define ARGS_FOR_ASSIGN(...) _BFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
146 #define _args_for_struct_1(a) a;
147 #define _args_for_struct_7(a, b, c, d, e, f, g) a;
148 #define _args_for_struct_14(a, b, c, d, e, f, g, ...) a; _args_for_struct_7(__VA_ARGS__)
149 #define _args_for_struct_21(a, b, c, d, e, f, g, ...) a; _args_for_struct_14(__VA_ARGS__)
150 #define _args_for_struct_28(a, b, c, d, e, f, g, ...) a; _args_for_struct_21(__VA_ARGS__)
151 #define _args_for_struct_35(a, b, c, d, e, f, g, ...) a; _args_for_struct_28(__VA_ARGS__)
152 #define _args_for_struct_42(a, b, c, d, e, f, g, ...) a; _args_for_struct_35(__VA_ARGS__)
153 #define _args_for_struct_49(a, b, c, d, e, f, g, ...) a; _args_for_struct_42(__VA_ARGS__)
154 #define _args_for_struct_56(a, b, c, d, e, f, g, ...) a; _args_for_struct_49(__VA_ARGS__)
155 #define _args_for_struct_63(a, b, c, d, e, f, g, ...) a; _args_for_struct_56(__VA_ARGS__)
156 #define _args_for_struct_70(a, b, c, d, e, f, g, ...) a; _args_for_struct_63(__VA_ARGS__)
158 #define _AFUNC_(n) _args_for_struct_##n
159 #define _AFUNC(n) _AFUNC_(n)
161 #define ARGS_FOR_STRUCT(...) _AFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)
163 /* Serialization and deserialization */
165 #define CSMT_ITEM_NO_WAIT(name, ...) \
167 struct s_##name##_private { \
168 struct csmt_instruction instr; \
169 ARGS_FOR_STRUCT( __VA_ARGS__ ) \
173 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \
176 name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr ) \
178 struct csmt_context *ctx = device->csmt_ctx; \
179 struct s_##name##_private *args = (struct s_##name##_private *)instr; \
184 device ARGS_FOR_CALL( __VA_ARGS__ ) \
186 ARGS_FOR_UNBIND( __VA_ARGS__ ) \
191 name( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \
193 struct csmt_context *ctx = device->csmt_ctx; \
194 struct s_##name##_private *args; \
195 unsigned memsize = sizeof(struct s_##name##_private); \
196 unsigned memsize2 = 0; \
198 if (!device->csmt_active) { \
200 device ARGS_FOR_BYPASS( __VA_ARGS__ ) \
204 ARGS_FOR_MEM ( __VA_ARGS__ ) \
205 args = nine_queue_alloc(ctx->pool, memsize + memsize2); \
207 args->instr.func = &name##_rx; \
208 ARGS_FOR_ASSIGN( __VA_ARGS__ ) \
212 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )
214 #define CSMT_ITEM_NO_WAIT_WITH_COUNTER(name, ...) \
216 struct s_##name##_private { \
217 struct csmt_instruction instr; \
219 ARGS_FOR_STRUCT( __VA_ARGS__ ) \
223 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \
226 name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr ) \
228 struct csmt_context *ctx = device->csmt_ctx; \
229 struct s_##name##_private *args = (struct s_##name##_private *)instr; \
234 device ARGS_FOR_CALL( __VA_ARGS__ ) \
236 p_atomic_dec(args->counter); \
237 ARGS_FOR_UNBIND( __VA_ARGS__ ) \
242 name( struct NineDevice9 *device, unsigned *counter ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \
244 struct csmt_context *ctx = device->csmt_ctx; \
245 struct s_##name##_private *args; \
246 unsigned memsize = sizeof(struct s_##name##_private); \
247 unsigned memsize2 = 0; \
249 if (!device->csmt_active) { \
251 device ARGS_FOR_BYPASS( __VA_ARGS__ ) \
256 p_atomic_inc(counter); \
257 ARGS_FOR_MEM ( __VA_ARGS__ ) \
258 args = nine_queue_alloc(ctx->pool, memsize + memsize2); \
260 args->instr.func = &name##_rx; \
261 args->counter = counter; \
262 ARGS_FOR_ASSIGN( __VA_ARGS__ ) \
266 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )
268 #define CSMT_ITEM_DO_WAIT(name, ...) \
270 struct s_##name##_private { \
271 struct csmt_instruction instr; \
272 ARGS_FOR_STRUCT( __VA_ARGS__ ) \
275 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \
278 name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr) \
280 struct csmt_context *ctx = device->csmt_ctx; \
281 struct s_##name##_private *args = (struct s_##name##_private *)instr; \
286 device ARGS_FOR_CALL( __VA_ARGS__ ) \
288 ARGS_FOR_UNBIND( __VA_ARGS__ ) \
293 name( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \
295 struct csmt_context *ctx = device->csmt_ctx; \
296 struct s_##name##_private *args; \
297 unsigned memsize = sizeof(struct s_##name##_private); \
298 unsigned memsize2 = 0; \
300 if (!device->csmt_active) { \
302 device ARGS_FOR_BYPASS( __VA_ARGS__ ) \
306 ARGS_FOR_MEM ( __VA_ARGS__ ) \
307 args = nine_queue_alloc(ctx->pool, memsize + memsize2); \
309 args->instr.func = &name##_rx; \
310 ARGS_FOR_ASSIGN( __VA_ARGS__ ) \
311 ctx->processed = FALSE; \
312 nine_queue_flush(ctx->pool); \
313 nine_csmt_wait_processed(ctx); \
317 name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )
319 /* ARGS_FOR_STRUCT, ARGS_FOR_ASSIGN, ARGS_FOR_DECLARATION, ARGS_FOR_CALL, ARGS_FOR_UNBIND, ARGS_FOR_MEM, ARGS_FOR_BYPASS */
320 #define ARG_VAL(x, y) \
329 #define ARG_REF(x, y) \
338 #define ARG_COPY_REF(x, y) \
339 x * _##y ; x __##y ; ,\
340 if ( y ) { args->_##y = &args->__##y ; args->__##y = *y ; } else { args->_##y = NULL; } ,\
342 (const x *)args->_##y ,\
347 #define ARG_BIND_REF(x, y) \
350 NineUnknown_Bind( (void *)y ); \
355 NineUnknown_Unbind((void *)(args->_##y)); \
356 args->_##y = NULL; ,\
360 #define ARG_BIND_RES(x, y) \
364 pipe_resource_reference(&args->_##y, y); ,\
368 pipe_resource_reference(&args->_##y, NULL); ,\
372 #define ARG_MEM(x, y) \
374 args->_##y = (void *)args + memsize;\
375 memcpy(args->_##y, y, memsize2); ,\
377 (const x *)args->_##y ,\
382 #define ARG_MEM_SIZE(x, y) \
391 #define ARG_BIND_BLIT(x, y) \
393 memcpy(&args->_##y , y, sizeof(x)); \
394 args->_##y.src.resource = NULL; \
395 args->_##y.dst.resource = NULL; \
396 pipe_resource_reference(&args->_##y.src.resource, y->src.resource); \
397 pipe_resource_reference(&args->_##y.dst.resource, y->dst.resource);,\
400 pipe_resource_reference(&args->_##y.src.resource, NULL); \
401 pipe_resource_reference(&args->_##y.dst.resource, NULL);,\
405 #define ARG_BIND_VBUF(x, y) \
407 memcpy(&args->_##y , y, sizeof(x)); \
408 args->_##y.buffer.resource = NULL; \
409 pipe_resource_reference(&args->_##y.buffer.resource, y->buffer.resource); ,\
412 pipe_resource_reference(&args->_##y.buffer.resource, NULL); ,\
416 #define ARG_BIND_IBUF(x, y) \
418 memcpy(&args->_##y , y, sizeof(x)); \
419 args->_##y.buffer = NULL; \
420 pipe_resource_reference(&args->_##y.buffer, y->buffer); ,\
423 pipe_resource_reference(&args->_##y.buffer, NULL); ,\
427 #define ARG_BIND_VIEW(x, y) \
431 pipe_sampler_view_reference(&args->_##y, y); ,\
435 pipe_sampler_view_reference(&args->_##y, NULL); ,\