Path: blob/21.2-virgl/src/gallium/frontends/nine/nine_csmt_helper.h
4561 views
/*1* Copyright 2016 Patrick Rudolph <[email protected]>2*3* Permission is hereby granted, free of charge, f, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* on the rights to use, f, copy, modify, merge, f, publish, distribute, f, sub7* license, f, and/or sell copies of the Software, f, and to permit persons to whom8* the Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,18* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR19* OTHERWISe, f, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE20* USE OR OTHER DEALINGS IN THE SOFTWARE. */2122/* get number of arguments with __NARG__ */23#define __NARG__(...) __NARG_I_(__VA_ARGS__,__RSEQ_N())24#define __NARG_I_(...) __ARG_N(__VA_ARGS__)25#define __ARG_N( \26_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \27_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \28_21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \29_31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \30_41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \31_51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \32_61,_62,_63,N,...) N33#define __RSEQ_N() \3463,62,61,60, \3559,58,57,56,55,54,53,52,51,50, \3649,48,47,46,45,44,43,42,41,40, \3739,38,37,36,35,34,33,32,31,30, \3829,28,27,26,25,24,23,22,21,20, \3919,18,17,16,15,14,13,12,11,10, \409,8,7,6,5,4,3,2,1,0414243#define _args_for_bypass_1(a) a44#define _args_for_bypass_7(a, b, c, d, e, f, g) ,g45#define _args_for_bypass_14(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_7(__VA_ARGS__)46#define _args_for_bypass_21(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_14(__VA_ARGS__)47#define _args_for_bypass_28(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_21(__VA_ARGS__)48#define _args_for_bypass_35(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_28(__VA_ARGS__)49#define _args_for_bypass_42(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_35(__VA_ARGS__)50#define _args_for_bypass_49(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_42(__VA_ARGS__)51#define _args_for_bypass_56(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_49(__VA_ARGS__)52#define _args_for_bypass_63(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_56(__VA_ARGS__)53#define _args_for_bypass_70(a, b, c, d, e, f, g, ...) ,g _args_for_bypass_63(__VA_ARGS__)5455#define _GFUNC_(n) _args_for_bypass_##n56#define _GFUNC(n) _GFUNC_(n)5758#define ARGS_FOR_BYPASS(...) _GFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)5960#define _args_for_mem_1(a) a;61#define _args_for_mem_7(a, b, c, d, e, f, g) f;62#define _args_for_mem_14(a, b, c, d, e, f, g, ...) f; _args_for_mem_7(__VA_ARGS__)63#define _args_for_mem_21(a, b, c, d, e, f, g, ...) f; _args_for_mem_14(__VA_ARGS__)64#define _args_for_mem_28(a, b, c, d, e, f, g, ...) f; _args_for_mem_21(__VA_ARGS__)65#define _args_for_mem_35(a, b, c, d, e, f, g, ...) f; _args_for_mem_28(__VA_ARGS__)66#define _args_for_mem_42(a, b, c, d, e, f, g, ...) f; _args_for_mem_35(__VA_ARGS__)67#define _args_for_mem_49(a, b, c, d, e, f, g, ...) f; _args_for_mem_42(__VA_ARGS__)68#define _args_for_mem_56(a, b, c, d, e, f, g, ...) f; _args_for_mem_49(__VA_ARGS__)69#define _args_for_mem_63(a, b, c, d, e, f, g, ...) f; _args_for_mem_56(__VA_ARGS__)70#define _args_for_mem_70(a, b, c, d, e, f, g, ...) f; _args_for_mem_63(__VA_ARGS__)7172#define _FFUNC_(n) _args_for_mem_##n73#define _FFUNC(n) _FFUNC_(n)7475#define ARGS_FOR_MEM(...) _FFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)7677#define _args_for_unbind_1(a) a;78#define _args_for_unbind_7(a, b, c, d, e, f, g) e;79#define _args_for_unbind_14(a, b, c, d, e, f, g, ...) e; _args_for_unbind_7(__VA_ARGS__)80#define _args_for_unbind_21(a, b, c, d, e, f, g, ...) e; _args_for_unbind_14(__VA_ARGS__)81#define _args_for_unbind_28(a, b, c, d, e, f, g, ...) e; _args_for_unbind_21(__VA_ARGS__)82#define _args_for_unbind_35(a, b, c, d, e, f, g, ...) e; _args_for_unbind_28(__VA_ARGS__)83#define _args_for_unbind_42(a, b, c, d, e, f, g, ...) e; _args_for_unbind_35(__VA_ARGS__)84#define _args_for_unbind_49(a, b, c, d, e, f, g, ...) e; _args_for_unbind_42(__VA_ARGS__)85#define _args_for_unbind_56(a, b, c, d, e, f, g, ...) e; _args_for_unbind_49(__VA_ARGS__)86#define _args_for_unbind_63(a, b, c, d, e, f, g, ...) e; _args_for_unbind_56(__VA_ARGS__)87#define _args_for_unbind_70(a, b, c, d, e, f, g, ...) e; _args_for_unbind_63(__VA_ARGS__)8889#define _EFUNC_(n) _args_for_unbind_##n90#define _EFUNC(n) _EFUNC_(n)9192#define ARGS_FOR_UNBIND(...) _EFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)9394#define _args_for_call_1(a) a95#define _args_for_call_7(a, b, c, d, e, f, g) ,d96#define _args_for_call_14(a, b, c, d, e, f, g, ...) ,d _args_for_call_7(__VA_ARGS__)97#define _args_for_call_21(a, b, c, d, e, f, g, ...) ,d _args_for_call_14(__VA_ARGS__)98#define _args_for_call_28(a, b, c, d, e, f, g, ...) ,d _args_for_call_21(__VA_ARGS__)99#define _args_for_call_35(a, b, c, d, e, f, g, ...) ,d _args_for_call_28(__VA_ARGS__)100#define _args_for_call_42(a, b, c, d, e, f, g, ...) ,d _args_for_call_35(__VA_ARGS__)101#define _args_for_call_49(a, b, c, d, e, f, g, ...) ,d _args_for_call_42(__VA_ARGS__)102#define _args_for_call_56(a, b, c, d, e, f, g, ...) ,d _args_for_call_49(__VA_ARGS__)103#define _args_for_call_63(a, b, c, d, e, f, g, ...) ,d _args_for_call_56(__VA_ARGS__)104#define _args_for_call_70(a, b, c, d, e, f, g, ...) ,d _args_for_call_63(__VA_ARGS__)105106#define _DFUNC_(n) _args_for_call_##n107#define _DFUNC(n) _DFUNC_(n)108109#define ARGS_FOR_CALL(...) _DFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)110111#define _args_for_decl_1(a) a112#define _args_for_decl_7(a, b, c, d, e, f, g) ,c113#define _args_for_decl_14(a, b, c, d, e, f, g, ...) ,c _args_for_decl_7(__VA_ARGS__)114#define _args_for_decl_21(a, b, c, d, e, f, g, ...) ,c _args_for_decl_14(__VA_ARGS__)115#define _args_for_decl_28(a, b, c, d, e, f, g, ...) ,c _args_for_decl_21(__VA_ARGS__)116#define _args_for_decl_35(a, b, c, d, e, f, g, ...) ,c _args_for_decl_28(__VA_ARGS__)117#define _args_for_decl_42(a, b, c, d, e, f, g, ...) ,c _args_for_decl_35(__VA_ARGS__)118#define _args_for_decl_49(a, b, c, d, e, f, g, ...) ,c _args_for_decl_42(__VA_ARGS__)119#define _args_for_decl_56(a, b, c, d, e, f, g, ...) ,c _args_for_decl_49(__VA_ARGS__)120#define _args_for_decl_63(a, b, c, d, e, f, g, ...) ,c _args_for_decl_56(__VA_ARGS__)121#define _args_for_decl_70(a, b, c, d, e, f, g, ...) ,c _args_for_decl_63(__VA_ARGS__)122123#define _CFUNC_(n) _args_for_decl_##n124#define _CFUNC(n) _CFUNC_(n)125126#define ARGS_FOR_DECLARATION(...) _CFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)127128#define _args_for_assign_1(a) a129#define _args_for_assign_7(a, b, c, d, e, f, g) b;130#define _args_for_assign_14(a, b, c, d, e, f, g, ...) b; _args_for_assign_7(__VA_ARGS__)131#define _args_for_assign_21(a, b, c, d, e, f, g, ...) b; _args_for_assign_14(__VA_ARGS__)132#define _args_for_assign_28(a, b, c, d, e, f, g, ...) b; _args_for_assign_21(__VA_ARGS__)133#define _args_for_assign_35(a, b, c, d, e, f, g, ...) b; _args_for_assign_28(__VA_ARGS__)134#define _args_for_assign_42(a, b, c, d, e, f, g, ...) b; _args_for_assign_35(__VA_ARGS__)135#define _args_for_assign_49(a, b, c, d, e, f, g, ...) b; _args_for_assign_42(__VA_ARGS__)136#define _args_for_assign_56(a, b, c, d, e, f, g, ...) b; _args_for_assign_49(__VA_ARGS__)137#define _args_for_assign_63(a, b, c, d, e, f, g, ...) b; _args_for_assign_56(__VA_ARGS__)138#define _args_for_assign_70(a, b, c, d, e, f, g, ...) b; _args_for_assign_63(__VA_ARGS__)139140#define _BFUNC_(n) _args_for_assign_##n141#define _BFUNC(n) _BFUNC_(n)142143#define ARGS_FOR_ASSIGN(...) _BFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)144145#define _args_for_struct_1(a) a;146#define _args_for_struct_7(a, b, c, d, e, f, g) a;147#define _args_for_struct_14(a, b, c, d, e, f, g, ...) a; _args_for_struct_7(__VA_ARGS__)148#define _args_for_struct_21(a, b, c, d, e, f, g, ...) a; _args_for_struct_14(__VA_ARGS__)149#define _args_for_struct_28(a, b, c, d, e, f, g, ...) a; _args_for_struct_21(__VA_ARGS__)150#define _args_for_struct_35(a, b, c, d, e, f, g, ...) a; _args_for_struct_28(__VA_ARGS__)151#define _args_for_struct_42(a, b, c, d, e, f, g, ...) a; _args_for_struct_35(__VA_ARGS__)152#define _args_for_struct_49(a, b, c, d, e, f, g, ...) a; _args_for_struct_42(__VA_ARGS__)153#define _args_for_struct_56(a, b, c, d, e, f, g, ...) a; _args_for_struct_49(__VA_ARGS__)154#define _args_for_struct_63(a, b, c, d, e, f, g, ...) a; _args_for_struct_56(__VA_ARGS__)155#define _args_for_struct_70(a, b, c, d, e, f, g, ...) a; _args_for_struct_63(__VA_ARGS__)156157#define _AFUNC_(n) _args_for_struct_##n158#define _AFUNC(n) _AFUNC_(n)159160#define ARGS_FOR_STRUCT(...) _AFUNC(__NARG__(__VA_ARGS__)) (__VA_ARGS__)161162/* Serialization and deserialization */163164#define CSMT_ITEM_NO_WAIT(name, ...) \165\166struct s_##name##_private { \167struct csmt_instruction instr; \168ARGS_FOR_STRUCT( __VA_ARGS__ ) \169}; \170\171static void \172name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \173\174static int \175name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr ) \176{ \177struct csmt_context *ctx = device->csmt_ctx; \178struct s_##name##_private *args = (struct s_##name##_private *)instr; \179\180(void) args; \181(void) ctx; \182name##_priv( \183device ARGS_FOR_CALL( __VA_ARGS__ ) \184); \185ARGS_FOR_UNBIND( __VA_ARGS__ ) \186return 0; \187} \188\189void \190name( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \191{ \192struct csmt_context *ctx = device->csmt_ctx; \193struct s_##name##_private *args; \194unsigned memsize = sizeof(struct s_##name##_private); \195unsigned memsize2 = 0; \196\197if (!device->csmt_active) { \198name##_priv( \199device ARGS_FOR_BYPASS( __VA_ARGS__ ) \200); \201return; \202} \203ARGS_FOR_MEM ( __VA_ARGS__ ) \204args = nine_queue_alloc(ctx->pool, memsize + memsize2); \205assert(args); \206args->instr.func = &name##_rx; \207ARGS_FOR_ASSIGN( __VA_ARGS__ ) \208} \209\210static void \211name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )212213#define CSMT_ITEM_NO_WAIT_WITH_COUNTER(name, ...) \214\215struct s_##name##_private { \216struct csmt_instruction instr; \217unsigned *counter; \218ARGS_FOR_STRUCT( __VA_ARGS__ ) \219}; \220\221static void \222name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \223\224static int \225name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr ) \226{ \227struct csmt_context *ctx = device->csmt_ctx; \228struct s_##name##_private *args = (struct s_##name##_private *)instr; \229\230(void) args; \231(void) ctx; \232name##_priv( \233device ARGS_FOR_CALL( __VA_ARGS__ ) \234); \235p_atomic_dec(args->counter); \236ARGS_FOR_UNBIND( __VA_ARGS__ ) \237return 0; \238} \239\240void \241name( struct NineDevice9 *device, unsigned *counter ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \242{ \243struct csmt_context *ctx = device->csmt_ctx; \244struct s_##name##_private *args; \245unsigned memsize = sizeof(struct s_##name##_private); \246unsigned memsize2 = 0; \247\248if (!device->csmt_active) { \249name##_priv( \250device ARGS_FOR_BYPASS( __VA_ARGS__ ) \251); \252return; \253} \254assert(counter); \255p_atomic_inc(counter); \256ARGS_FOR_MEM ( __VA_ARGS__ ) \257args = nine_queue_alloc(ctx->pool, memsize + memsize2); \258assert(args); \259args->instr.func = &name##_rx; \260args->counter = counter; \261ARGS_FOR_ASSIGN( __VA_ARGS__ ) \262} \263\264static void \265name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )266267#define CSMT_ITEM_DO_WAIT(name, ...) \268\269struct s_##name##_private { \270struct csmt_instruction instr; \271ARGS_FOR_STRUCT( __VA_ARGS__ ) \272}; \273static void \274name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ); \275\276static int \277name##_rx( struct NineDevice9 *device, struct csmt_instruction *instr) \278{ \279struct csmt_context *ctx = device->csmt_ctx; \280struct s_##name##_private *args = (struct s_##name##_private *)instr; \281\282(void) args; \283(void) ctx; \284name##_priv( \285device ARGS_FOR_CALL( __VA_ARGS__ ) \286); \287ARGS_FOR_UNBIND( __VA_ARGS__ ) \288return 1; \289} \290\291void \292name( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) ) \293{ \294struct csmt_context *ctx = device->csmt_ctx; \295struct s_##name##_private *args; \296unsigned memsize = sizeof(struct s_##name##_private); \297unsigned memsize2 = 0; \298\299if (!device->csmt_active) { \300name##_priv( \301device ARGS_FOR_BYPASS( __VA_ARGS__ ) \302); \303return; \304} \305ARGS_FOR_MEM ( __VA_ARGS__ ) \306args = nine_queue_alloc(ctx->pool, memsize + memsize2); \307assert(args); \308args->instr.func = &name##_rx; \309ARGS_FOR_ASSIGN( __VA_ARGS__ ) \310ctx->processed = FALSE; \311nine_queue_flush(ctx->pool); \312nine_csmt_wait_processed(ctx); \313} \314\315static void \316name##_priv( struct NineDevice9 *device ARGS_FOR_DECLARATION( __VA_ARGS__ ) )317318/* ARGS_FOR_STRUCT, ARGS_FOR_ASSIGN, ARGS_FOR_DECLARATION, ARGS_FOR_CALL, ARGS_FOR_UNBIND, ARGS_FOR_MEM, ARGS_FOR_BYPASS */319#define ARG_VAL(x, y) \320x _##y ; ,\321args->_##y = y ; ,\322x y ,\323args->_##y ,\324,\325,\326y327328#define ARG_REF(x, y) \329x* _##y ; ,\330args->_##y = y; ,\331x *y ,\332args->_##y ,\333,\334,\335y336337#define ARG_COPY_REF(x, y) \338x * _##y ; x __##y ; ,\339if ( y ) { args->_##y = &args->__##y ; args->__##y = *y ; } else { args->_##y = NULL; } ,\340const x *y ,\341(const x *)args->_##y ,\342,\343,\344(const x *)y345346#define ARG_BIND_REF(x, y) \347x * _##y ,\348if ( y ) \349NineUnknown_Bind( (void *)y ); \350args->_##y = y ; ,\351x *y ,\352args->_##y,\353if (args->_##y) \354NineUnknown_Unbind((void *)(args->_##y)); \355args->_##y = NULL; ,\356,\357y358359#define ARG_BIND_RES(x, y) \360x * _##y ,\361args->_##y = NULL; \362if (y) \363pipe_resource_reference(&args->_##y, y); ,\364x *y ,\365args->_##y ,\366if (args->_##y) \367pipe_resource_reference(&args->_##y, NULL); ,\368,\369y370371#define ARG_MEM(x, y) \372x * _##y ,\373args->_##y = (void *)args + memsize;\374memcpy(args->_##y, y, memsize2); ,\375const x *y ,\376(const x *)args->_##y ,\377,\378,\379(const x *)y380381#define ARG_MEM_SIZE(x, y) \382x _##y ,\383args->_##y = y; ,\384x y ,\385args->_##y ,\386,\387memsize2 = y, \388y389390#define ARG_BIND_BLIT(x, y) \391x _##y ,\392memcpy(&args->_##y , y, sizeof(x)); \393args->_##y.src.resource = NULL; \394args->_##y.dst.resource = NULL; \395pipe_resource_reference(&args->_##y.src.resource, y->src.resource); \396pipe_resource_reference(&args->_##y.dst.resource, y->dst.resource);,\397x *y ,\398&args->_##y ,\399pipe_resource_reference(&args->_##y.src.resource, NULL); \400pipe_resource_reference(&args->_##y.dst.resource, NULL);,\401,\402y403404#define ARG_BIND_VBUF(x, y) \405x _##y ,\406memcpy(&args->_##y , y, sizeof(x)); \407args->_##y.buffer.resource = NULL; \408pipe_resource_reference(&args->_##y.buffer.resource, y->buffer.resource); ,\409x *y ,\410&args->_##y ,\411pipe_resource_reference(&args->_##y.buffer.resource, NULL); ,\412,\413y414415#define ARG_BIND_IBUF(x, y) \416x _##y ,\417memcpy(&args->_##y , y, sizeof(x)); \418args->_##y.buffer = NULL; \419pipe_resource_reference(&args->_##y.buffer, y->buffer); ,\420x *y ,\421&args->_##y ,\422pipe_resource_reference(&args->_##y.buffer, NULL); ,\423,\424y425426#define ARG_BIND_VIEW(x, y) \427x * _##y ,\428args->_##y = NULL; \429if (y) \430pipe_sampler_view_reference(&args->_##y, y); ,\431x *y ,\432args->_##y ,\433if (args->_##y) \434pipe_sampler_view_reference(&args->_##y, NULL); ,\435,\436y437438439440