Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

anv_private.h 108KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937
  1. /*
  2. * Copyright © 2015 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, 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. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  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
  13. * Software.
  14. *
  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 NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. #ifndef ANV_PRIVATE_H
  24. #define ANV_PRIVATE_H
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #include <stdbool.h>
  28. #include <pthread.h>
  29. #include <assert.h>
  30. #include <stdint.h>
  31. #include <i915_drm.h>
  32. #ifdef HAVE_VALGRIND
  33. #include <valgrind.h>
  34. #include <memcheck.h>
  35. #define VG(x) x
  36. #define __gen_validate_value(x) VALGRIND_CHECK_MEM_IS_DEFINED(&(x), sizeof(x))
  37. #else
  38. #define VG(x)
  39. #endif
  40. #include "common/gen_clflush.h"
  41. #include "common/gen_device_info.h"
  42. #include "blorp/blorp.h"
  43. #include "compiler/brw_compiler.h"
  44. #include "util/macros.h"
  45. #include "util/list.h"
  46. #include "util/u_atomic.h"
  47. #include "util/u_vector.h"
  48. #include "vk_alloc.h"
  49. #include "vk_debug_report.h"
  50. /* Pre-declarations needed for WSI entrypoints */
  51. struct wl_surface;
  52. struct wl_display;
  53. typedef struct xcb_connection_t xcb_connection_t;
  54. typedef uint32_t xcb_visualid_t;
  55. typedef uint32_t xcb_window_t;
  56. struct anv_buffer;
  57. struct anv_buffer_view;
  58. struct anv_image_view;
  59. struct anv_instance;
  60. struct gen_l3_config;
  61. #include <vulkan/vulkan.h>
  62. #include <vulkan/vulkan_intel.h>
  63. #include <vulkan/vk_icd.h>
  64. #include <vulkan/vk_android_native_buffer.h>
  65. #include "anv_entrypoints.h"
  66. #include "anv_extensions.h"
  67. #include "isl/isl.h"
  68. #include "common/gen_debug.h"
  69. #include "common/intel_log.h"
  70. #include "wsi_common.h"
  71. /* Allowing different clear colors requires us to perform a depth resolve at
  72. * the end of certain render passes. This is because while slow clears store
  73. * the clear color in the HiZ buffer, fast clears (without a resolve) don't.
  74. * See the PRMs for examples describing when additional resolves would be
  75. * necessary. To enable fast clears without requiring extra resolves, we set
  76. * the clear value to a globally-defined one. We could allow different values
  77. * if the user doesn't expect coherent data during or after a render passes
  78. * (VK_ATTACHMENT_STORE_OP_DONT_CARE), but such users (aside from the CTS)
  79. * don't seem to exist yet. In almost all Vulkan applications tested thus far,
  80. * 1.0f seems to be the only value used. The only application that doesn't set
  81. * this value does so through the usage of an seemingly uninitialized clear
  82. * value.
  83. */
  84. #define ANV_HZ_FC_VAL 1.0f
  85. #define MAX_VBS 28
  86. #define MAX_SETS 8
  87. #define MAX_RTS 8
  88. #define MAX_VIEWPORTS 16
  89. #define MAX_SCISSORS 16
  90. #define MAX_PUSH_CONSTANTS_SIZE 128
  91. #define MAX_DYNAMIC_BUFFERS 16
  92. #define MAX_IMAGES 8
  93. #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */
  94. #define ANV_SVGS_VB_INDEX MAX_VBS
  95. #define ANV_DRAWID_VB_INDEX (MAX_VBS + 1)
  96. #define anv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
  97. static inline uint32_t
  98. align_down_npot_u32(uint32_t v, uint32_t a)
  99. {
  100. return v - (v % a);
  101. }
  102. static inline uint32_t
  103. align_u32(uint32_t v, uint32_t a)
  104. {
  105. assert(a != 0 && a == (a & -a));
  106. return (v + a - 1) & ~(a - 1);
  107. }
  108. static inline uint64_t
  109. align_u64(uint64_t v, uint64_t a)
  110. {
  111. assert(a != 0 && a == (a & -a));
  112. return (v + a - 1) & ~(a - 1);
  113. }
  114. static inline int32_t
  115. align_i32(int32_t v, int32_t a)
  116. {
  117. assert(a != 0 && a == (a & -a));
  118. return (v + a - 1) & ~(a - 1);
  119. }
  120. /** Alignment must be a power of 2. */
  121. static inline bool
  122. anv_is_aligned(uintmax_t n, uintmax_t a)
  123. {
  124. assert(a == (a & -a));
  125. return (n & (a - 1)) == 0;
  126. }
  127. static inline uint32_t
  128. anv_minify(uint32_t n, uint32_t levels)
  129. {
  130. if (unlikely(n == 0))
  131. return 0;
  132. else
  133. return MAX2(n >> levels, 1);
  134. }
  135. static inline float
  136. anv_clamp_f(float f, float min, float max)
  137. {
  138. assert(min < max);
  139. if (f > max)
  140. return max;
  141. else if (f < min)
  142. return min;
  143. else
  144. return f;
  145. }
  146. static inline bool
  147. anv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
  148. {
  149. if (*inout_mask & clear_mask) {
  150. *inout_mask &= ~clear_mask;
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. }
  156. static inline union isl_color_value
  157. vk_to_isl_color(VkClearColorValue color)
  158. {
  159. return (union isl_color_value) {
  160. .u32 = {
  161. color.uint32[0],
  162. color.uint32[1],
  163. color.uint32[2],
  164. color.uint32[3],
  165. },
  166. };
  167. }
  168. #define for_each_bit(b, dword) \
  169. for (uint32_t __dword = (dword); \
  170. (b) = __builtin_ffs(__dword) - 1, __dword; \
  171. __dword &= ~(1 << (b)))
  172. #define typed_memcpy(dest, src, count) ({ \
  173. STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
  174. memcpy((dest), (src), (count) * sizeof(*(src))); \
  175. })
  176. /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need
  177. * to be added here in order to utilize mapping in debug/error/perf macros.
  178. */
  179. #define REPORT_OBJECT_TYPE(o) \
  180. __builtin_choose_expr ( \
  181. __builtin_types_compatible_p (__typeof (o), struct anv_instance*), \
  182. VK_DEBUG_REPORT_OBJECT_TYPE_INSTANCE_EXT, \
  183. __builtin_choose_expr ( \
  184. __builtin_types_compatible_p (__typeof (o), struct anv_physical_device*), \
  185. VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, \
  186. __builtin_choose_expr ( \
  187. __builtin_types_compatible_p (__typeof (o), struct anv_device*), \
  188. VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
  189. __builtin_choose_expr ( \
  190. __builtin_types_compatible_p (__typeof (o), const struct anv_device*), \
  191. VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, \
  192. __builtin_choose_expr ( \
  193. __builtin_types_compatible_p (__typeof (o), struct anv_queue*), \
  194. VK_DEBUG_REPORT_OBJECT_TYPE_QUEUE_EXT, \
  195. __builtin_choose_expr ( \
  196. __builtin_types_compatible_p (__typeof (o), struct anv_semaphore*), \
  197. VK_DEBUG_REPORT_OBJECT_TYPE_SEMAPHORE_EXT, \
  198. __builtin_choose_expr ( \
  199. __builtin_types_compatible_p (__typeof (o), struct anv_cmd_buffer*), \
  200. VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, \
  201. __builtin_choose_expr ( \
  202. __builtin_types_compatible_p (__typeof (o), struct anv_fence*), \
  203. VK_DEBUG_REPORT_OBJECT_TYPE_FENCE_EXT, \
  204. __builtin_choose_expr ( \
  205. __builtin_types_compatible_p (__typeof (o), struct anv_device_memory*), \
  206. VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_MEMORY_EXT, \
  207. __builtin_choose_expr ( \
  208. __builtin_types_compatible_p (__typeof (o), struct anv_buffer*), \
  209. VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT, \
  210. __builtin_choose_expr ( \
  211. __builtin_types_compatible_p (__typeof (o), struct anv_image*), \
  212. VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
  213. __builtin_choose_expr ( \
  214. __builtin_types_compatible_p (__typeof (o), const struct anv_image*), \
  215. VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, \
  216. __builtin_choose_expr ( \
  217. __builtin_types_compatible_p (__typeof (o), struct anv_event*), \
  218. VK_DEBUG_REPORT_OBJECT_TYPE_EVENT_EXT, \
  219. __builtin_choose_expr ( \
  220. __builtin_types_compatible_p (__typeof (o), struct anv_query_pool*), \
  221. VK_DEBUG_REPORT_OBJECT_TYPE_QUERY_POOL_EXT, \
  222. __builtin_choose_expr ( \
  223. __builtin_types_compatible_p (__typeof (o), struct anv_buffer_view*), \
  224. VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_VIEW_EXT, \
  225. __builtin_choose_expr ( \
  226. __builtin_types_compatible_p (__typeof (o), struct anv_image_view*), \
  227. VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_VIEW_EXT, \
  228. __builtin_choose_expr ( \
  229. __builtin_types_compatible_p (__typeof (o), struct anv_shader_module*), \
  230. VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, \
  231. __builtin_choose_expr ( \
  232. __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_cache*), \
  233. VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_CACHE_EXT, \
  234. __builtin_choose_expr ( \
  235. __builtin_types_compatible_p (__typeof (o), struct anv_pipeline_layout*), \
  236. VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_LAYOUT_EXT, \
  237. __builtin_choose_expr ( \
  238. __builtin_types_compatible_p (__typeof (o), struct anv_render_pass*), \
  239. VK_DEBUG_REPORT_OBJECT_TYPE_RENDER_PASS_EXT, \
  240. __builtin_choose_expr ( \
  241. __builtin_types_compatible_p (__typeof (o), struct anv_pipeline*), \
  242. VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, \
  243. __builtin_choose_expr ( \
  244. __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set_layout*), \
  245. VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT, \
  246. __builtin_choose_expr ( \
  247. __builtin_types_compatible_p (__typeof (o), struct anv_sampler*), \
  248. VK_DEBUG_REPORT_OBJECT_TYPE_SAMPLER_EXT, \
  249. __builtin_choose_expr ( \
  250. __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_pool*), \
  251. VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, \
  252. __builtin_choose_expr ( \
  253. __builtin_types_compatible_p (__typeof (o), struct anv_descriptor_set*), \
  254. VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_EXT, \
  255. __builtin_choose_expr ( \
  256. __builtin_types_compatible_p (__typeof (o), struct anv_framebuffer*), \
  257. VK_DEBUG_REPORT_OBJECT_TYPE_FRAMEBUFFER_EXT, \
  258. __builtin_choose_expr ( \
  259. __builtin_types_compatible_p (__typeof (o), struct anv_cmd_pool*), \
  260. VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_POOL_EXT, \
  261. __builtin_choose_expr ( \
  262. __builtin_types_compatible_p (__typeof (o), struct anv_surface*), \
  263. VK_DEBUG_REPORT_OBJECT_TYPE_SURFACE_KHR_EXT, \
  264. __builtin_choose_expr ( \
  265. __builtin_types_compatible_p (__typeof (o), struct wsi_swapchain*), \
  266. VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, \
  267. __builtin_choose_expr ( \
  268. __builtin_types_compatible_p (__typeof (o), struct vk_debug_callback*), \
  269. VK_DEBUG_REPORT_OBJECT_TYPE_DEBUG_REPORT_CALLBACK_EXT_EXT, \
  270. __builtin_choose_expr ( \
  271. __builtin_types_compatible_p (__typeof (o), void*), \
  272. VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, \
  273. /* The void expression results in a compile-time error \
  274. when assigning the result to something. */ \
  275. (void)0)))))))))))))))))))))))))))))))
  276. /* Whenever we generate an error, pass it through this function. Useful for
  277. * debugging, where we can break on it. Only call at error site, not when
  278. * propagating errors. Might be useful to plug in a stack trace here.
  279. */
  280. VkResult __vk_errorf(struct anv_instance *instance, const void *object,
  281. VkDebugReportObjectTypeEXT type, VkResult error,
  282. const char *file, int line, const char *format, ...);
  283. #ifdef DEBUG
  284. #define vk_error(error) __vk_errorf(NULL, NULL,\
  285. VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,\
  286. error, __FILE__, __LINE__, NULL);
  287. #define vk_errorf(instance, obj, error, format, ...)\
  288. __vk_errorf(instance, obj, REPORT_OBJECT_TYPE(obj), error,\
  289. __FILE__, __LINE__, format, ## __VA_ARGS__);
  290. #else
  291. #define vk_error(error) error
  292. #define vk_errorf(instance, obj, error, format, ...) error
  293. #endif
  294. /**
  295. * Warn on ignored extension structs.
  296. *
  297. * The Vulkan spec requires us to ignore unsupported or unknown structs in
  298. * a pNext chain. In debug mode, emitting warnings for ignored structs may
  299. * help us discover structs that we should not have ignored.
  300. *
  301. *
  302. * From the Vulkan 1.0.38 spec:
  303. *
  304. * Any component of the implementation (the loader, any enabled layers,
  305. * and drivers) must skip over, without processing (other than reading the
  306. * sType and pNext members) any chained structures with sType values not
  307. * defined by extensions supported by that component.
  308. */
  309. #define anv_debug_ignored_stype(sType) \
  310. intel_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
  311. void __anv_perf_warn(struct anv_instance *instance, const void *object,
  312. VkDebugReportObjectTypeEXT type, const char *file,
  313. int line, const char *format, ...)
  314. anv_printflike(6, 7);
  315. void anv_loge(const char *format, ...) anv_printflike(1, 2);
  316. void anv_loge_v(const char *format, va_list va);
  317. /**
  318. * Print a FINISHME message, including its source location.
  319. */
  320. #define anv_finishme(format, ...) \
  321. do { \
  322. static bool reported = false; \
  323. if (!reported) { \
  324. intel_logw("%s:%d: FINISHME: " format, __FILE__, __LINE__, \
  325. ##__VA_ARGS__); \
  326. reported = true; \
  327. } \
  328. } while (0)
  329. /**
  330. * Print a perf warning message. Set INTEL_DEBUG=perf to see these.
  331. */
  332. #define anv_perf_warn(instance, obj, format, ...) \
  333. do { \
  334. static bool reported = false; \
  335. if (!reported && unlikely(INTEL_DEBUG & DEBUG_PERF)) { \
  336. __anv_perf_warn(instance, obj, REPORT_OBJECT_TYPE(obj), __FILE__, __LINE__,\
  337. format, ##__VA_ARGS__); \
  338. reported = true; \
  339. } \
  340. } while (0)
  341. /* A non-fatal assert. Useful for debugging. */
  342. #ifdef DEBUG
  343. #define anv_assert(x) ({ \
  344. if (unlikely(!(x))) \
  345. intel_loge("%s:%d ASSERT: %s", __FILE__, __LINE__, #x); \
  346. })
  347. #else
  348. #define anv_assert(x)
  349. #endif
  350. /* A multi-pointer allocator
  351. *
  352. * When copying data structures from the user (such as a render pass), it's
  353. * common to need to allocate data for a bunch of different things. Instead
  354. * of doing several allocations and having to handle all of the error checking
  355. * that entails, it can be easier to do a single allocation. This struct
  356. * helps facilitate that. The intended usage looks like this:
  357. *
  358. * ANV_MULTIALLOC(ma)
  359. * anv_multialloc_add(&ma, &main_ptr, 1);
  360. * anv_multialloc_add(&ma, &substruct1, substruct1Count);
  361. * anv_multialloc_add(&ma, &substruct2, substruct2Count);
  362. *
  363. * if (!anv_multialloc_alloc(&ma, pAllocator, VK_ALLOCATION_SCOPE_FOO))
  364. * return vk_error(VK_ERROR_OUT_OF_HOST_MEORY);
  365. */
  366. struct anv_multialloc {
  367. size_t size;
  368. size_t align;
  369. uint32_t ptr_count;
  370. void **ptrs[8];
  371. };
  372. #define ANV_MULTIALLOC_INIT \
  373. ((struct anv_multialloc) { 0, })
  374. #define ANV_MULTIALLOC(_name) \
  375. struct anv_multialloc _name = ANV_MULTIALLOC_INIT
  376. __attribute__((always_inline))
  377. static inline void
  378. _anv_multialloc_add(struct anv_multialloc *ma,
  379. void **ptr, size_t size, size_t align)
  380. {
  381. size_t offset = align_u64(ma->size, align);
  382. ma->size = offset + size;
  383. ma->align = MAX2(ma->align, align);
  384. /* Store the offset in the pointer. */
  385. *ptr = (void *)(uintptr_t)offset;
  386. assert(ma->ptr_count < ARRAY_SIZE(ma->ptrs));
  387. ma->ptrs[ma->ptr_count++] = ptr;
  388. }
  389. #define anv_multialloc_add_size(_ma, _ptr, _size) \
  390. _anv_multialloc_add((_ma), (void **)(_ptr), (_size), __alignof__(**(_ptr)))
  391. #define anv_multialloc_add(_ma, _ptr, _count) \
  392. anv_multialloc_add_size(_ma, _ptr, (_count) * sizeof(**(_ptr)));
  393. __attribute__((always_inline))
  394. static inline void *
  395. anv_multialloc_alloc(struct anv_multialloc *ma,
  396. const VkAllocationCallbacks *alloc,
  397. VkSystemAllocationScope scope)
  398. {
  399. void *ptr = vk_alloc(alloc, ma->size, ma->align, scope);
  400. if (!ptr)
  401. return NULL;
  402. /* Fill out each of the pointers with their final value.
  403. *
  404. * for (uint32_t i = 0; i < ma->ptr_count; i++)
  405. * *ma->ptrs[i] = ptr + (uintptr_t)*ma->ptrs[i];
  406. *
  407. * Unfortunately, even though ma->ptr_count is basically guaranteed to be a
  408. * constant, GCC is incapable of figuring this out and unrolling the loop
  409. * so we have to give it a little help.
  410. */
  411. STATIC_ASSERT(ARRAY_SIZE(ma->ptrs) == 8);
  412. #define _ANV_MULTIALLOC_UPDATE_POINTER(_i) \
  413. if ((_i) < ma->ptr_count) \
  414. *ma->ptrs[_i] = ptr + (uintptr_t)*ma->ptrs[_i]
  415. _ANV_MULTIALLOC_UPDATE_POINTER(0);
  416. _ANV_MULTIALLOC_UPDATE_POINTER(1);
  417. _ANV_MULTIALLOC_UPDATE_POINTER(2);
  418. _ANV_MULTIALLOC_UPDATE_POINTER(3);
  419. _ANV_MULTIALLOC_UPDATE_POINTER(4);
  420. _ANV_MULTIALLOC_UPDATE_POINTER(5);
  421. _ANV_MULTIALLOC_UPDATE_POINTER(6);
  422. _ANV_MULTIALLOC_UPDATE_POINTER(7);
  423. #undef _ANV_MULTIALLOC_UPDATE_POINTER
  424. return ptr;
  425. }
  426. __attribute__((always_inline))
  427. static inline void *
  428. anv_multialloc_alloc2(struct anv_multialloc *ma,
  429. const VkAllocationCallbacks *parent_alloc,
  430. const VkAllocationCallbacks *alloc,
  431. VkSystemAllocationScope scope)
  432. {
  433. return anv_multialloc_alloc(ma, alloc ? alloc : parent_alloc, scope);
  434. }
  435. struct anv_bo {
  436. uint32_t gem_handle;
  437. /* Index into the current validation list. This is used by the
  438. * validation list building alrogithm to track which buffers are already
  439. * in the validation list so that we can ensure uniqueness.
  440. */
  441. uint32_t index;
  442. /* Last known offset. This value is provided by the kernel when we
  443. * execbuf and is used as the presumed offset for the next bunch of
  444. * relocations.
  445. */
  446. uint64_t offset;
  447. uint64_t size;
  448. void *map;
  449. /** Flags to pass to the kernel through drm_i915_exec_object2::flags */
  450. uint32_t flags;
  451. };
  452. static inline void
  453. anv_bo_init(struct anv_bo *bo, uint32_t gem_handle, uint64_t size)
  454. {
  455. bo->gem_handle = gem_handle;
  456. bo->index = 0;
  457. bo->offset = -1;
  458. bo->size = size;
  459. bo->map = NULL;
  460. bo->flags = 0;
  461. }
  462. /* Represents a lock-free linked list of "free" things. This is used by
  463. * both the block pool and the state pools. Unfortunately, in order to
  464. * solve the ABA problem, we can't use a single uint32_t head.
  465. */
  466. union anv_free_list {
  467. struct {
  468. int32_t offset;
  469. /* A simple count that is incremented every time the head changes. */
  470. uint32_t count;
  471. };
  472. uint64_t u64;
  473. };
  474. #define ANV_FREE_LIST_EMPTY ((union anv_free_list) { { 1, 0 } })
  475. struct anv_block_state {
  476. union {
  477. struct {
  478. uint32_t next;
  479. uint32_t end;
  480. };
  481. uint64_t u64;
  482. };
  483. };
  484. struct anv_block_pool {
  485. struct anv_device *device;
  486. uint64_t bo_flags;
  487. struct anv_bo bo;
  488. /* The offset from the start of the bo to the "center" of the block
  489. * pool. Pointers to allocated blocks are given by
  490. * bo.map + center_bo_offset + offsets.
  491. */
  492. uint32_t center_bo_offset;
  493. /* Current memory map of the block pool. This pointer may or may not
  494. * point to the actual beginning of the block pool memory. If
  495. * anv_block_pool_alloc_back has ever been called, then this pointer
  496. * will point to the "center" position of the buffer and all offsets
  497. * (negative or positive) given out by the block pool alloc functions
  498. * will be valid relative to this pointer.
  499. *
  500. * In particular, map == bo.map + center_offset
  501. */
  502. void *map;
  503. int fd;
  504. /**
  505. * Array of mmaps and gem handles owned by the block pool, reclaimed when
  506. * the block pool is destroyed.
  507. */
  508. struct u_vector mmap_cleanups;
  509. struct anv_block_state state;
  510. struct anv_block_state back_state;
  511. };
  512. /* Block pools are backed by a fixed-size 1GB memfd */
  513. #define BLOCK_POOL_MEMFD_SIZE (1ul << 30)
  514. /* The center of the block pool is also the middle of the memfd. This may
  515. * change in the future if we decide differently for some reason.
  516. */
  517. #define BLOCK_POOL_MEMFD_CENTER (BLOCK_POOL_MEMFD_SIZE / 2)
  518. static inline uint32_t
  519. anv_block_pool_size(struct anv_block_pool *pool)
  520. {
  521. return pool->state.end + pool->back_state.end;
  522. }
  523. struct anv_state {
  524. int32_t offset;
  525. uint32_t alloc_size;
  526. void *map;
  527. };
  528. #define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
  529. struct anv_fixed_size_state_pool {
  530. union anv_free_list free_list;
  531. struct anv_block_state block;
  532. };
  533. #define ANV_MIN_STATE_SIZE_LOG2 6
  534. #define ANV_MAX_STATE_SIZE_LOG2 20
  535. #define ANV_STATE_BUCKETS (ANV_MAX_STATE_SIZE_LOG2 - ANV_MIN_STATE_SIZE_LOG2 + 1)
  536. struct anv_state_pool {
  537. struct anv_block_pool block_pool;
  538. /* The size of blocks which will be allocated from the block pool */
  539. uint32_t block_size;
  540. /** Free list for "back" allocations */
  541. union anv_free_list back_alloc_free_list;
  542. struct anv_fixed_size_state_pool buckets[ANV_STATE_BUCKETS];
  543. };
  544. struct anv_state_stream_block;
  545. struct anv_state_stream {
  546. struct anv_state_pool *state_pool;
  547. /* The size of blocks to allocate from the state pool */
  548. uint32_t block_size;
  549. /* Current block we're allocating from */
  550. struct anv_state block;
  551. /* Offset into the current block at which to allocate the next state */
  552. uint32_t next;
  553. /* List of all blocks allocated from this pool */
  554. struct anv_state_stream_block *block_list;
  555. };
  556. /* The block_pool functions exported for testing only. The block pool should
  557. * only be used via a state pool (see below).
  558. */
  559. VkResult anv_block_pool_init(struct anv_block_pool *pool,
  560. struct anv_device *device,
  561. uint32_t initial_size,
  562. uint64_t bo_flags);
  563. void anv_block_pool_finish(struct anv_block_pool *pool);
  564. int32_t anv_block_pool_alloc(struct anv_block_pool *pool,
  565. uint32_t block_size);
  566. int32_t anv_block_pool_alloc_back(struct anv_block_pool *pool,
  567. uint32_t block_size);
  568. VkResult anv_state_pool_init(struct anv_state_pool *pool,
  569. struct anv_device *device,
  570. uint32_t block_size,
  571. uint64_t bo_flags);
  572. void anv_state_pool_finish(struct anv_state_pool *pool);
  573. struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool,
  574. uint32_t state_size, uint32_t alignment);
  575. struct anv_state anv_state_pool_alloc_back(struct anv_state_pool *pool);
  576. void anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state);
  577. void anv_state_stream_init(struct anv_state_stream *stream,
  578. struct anv_state_pool *state_pool,
  579. uint32_t block_size);
  580. void anv_state_stream_finish(struct anv_state_stream *stream);
  581. struct anv_state anv_state_stream_alloc(struct anv_state_stream *stream,
  582. uint32_t size, uint32_t alignment);
  583. /**
  584. * Implements a pool of re-usable BOs. The interface is identical to that
  585. * of block_pool except that each block is its own BO.
  586. */
  587. struct anv_bo_pool {
  588. struct anv_device *device;
  589. uint64_t bo_flags;
  590. void *free_list[16];
  591. };
  592. void anv_bo_pool_init(struct anv_bo_pool *pool, struct anv_device *device,
  593. uint64_t bo_flags);
  594. void anv_bo_pool_finish(struct anv_bo_pool *pool);
  595. VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, struct anv_bo *bo,
  596. uint32_t size);
  597. void anv_bo_pool_free(struct anv_bo_pool *pool, const struct anv_bo *bo);
  598. struct anv_scratch_bo {
  599. bool exists;
  600. struct anv_bo bo;
  601. };
  602. struct anv_scratch_pool {
  603. /* Indexed by Per-Thread Scratch Space number (the hardware value) and stage */
  604. struct anv_scratch_bo bos[16][MESA_SHADER_STAGES];
  605. };
  606. void anv_scratch_pool_init(struct anv_device *device,
  607. struct anv_scratch_pool *pool);
  608. void anv_scratch_pool_finish(struct anv_device *device,
  609. struct anv_scratch_pool *pool);
  610. struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
  611. struct anv_scratch_pool *pool,
  612. gl_shader_stage stage,
  613. unsigned per_thread_scratch);
  614. /** Implements a BO cache that ensures a 1-1 mapping of GEM BOs to anv_bos */
  615. struct anv_bo_cache {
  616. struct hash_table *bo_map;
  617. pthread_mutex_t mutex;
  618. };
  619. VkResult anv_bo_cache_init(struct anv_bo_cache *cache);
  620. void anv_bo_cache_finish(struct anv_bo_cache *cache);
  621. VkResult anv_bo_cache_alloc(struct anv_device *device,
  622. struct anv_bo_cache *cache,
  623. uint64_t size, struct anv_bo **bo);
  624. VkResult anv_bo_cache_import(struct anv_device *device,
  625. struct anv_bo_cache *cache,
  626. int fd, struct anv_bo **bo);
  627. VkResult anv_bo_cache_export(struct anv_device *device,
  628. struct anv_bo_cache *cache,
  629. struct anv_bo *bo_in, int *fd_out);
  630. void anv_bo_cache_release(struct anv_device *device,
  631. struct anv_bo_cache *cache,
  632. struct anv_bo *bo);
  633. struct anv_memory_type {
  634. /* Standard bits passed on to the client */
  635. VkMemoryPropertyFlags propertyFlags;
  636. uint32_t heapIndex;
  637. /* Driver-internal book-keeping */
  638. VkBufferUsageFlags valid_buffer_usage;
  639. };
  640. struct anv_memory_heap {
  641. /* Standard bits passed on to the client */
  642. VkDeviceSize size;
  643. VkMemoryHeapFlags flags;
  644. /* Driver-internal book-keeping */
  645. bool supports_48bit_addresses;
  646. };
  647. struct anv_physical_device {
  648. VK_LOADER_DATA _loader_data;
  649. struct anv_instance * instance;
  650. uint32_t chipset_id;
  651. char path[20];
  652. const char * name;
  653. struct gen_device_info info;
  654. /** Amount of "GPU memory" we want to advertise
  655. *
  656. * Clearly, this value is bogus since Intel is a UMA architecture. On
  657. * gen7 platforms, we are limited by GTT size unless we want to implement
  658. * fine-grained tracking and GTT splitting. On Broadwell and above we are
  659. * practically unlimited. However, we will never report more than 3/4 of
  660. * the total system ram to try and avoid running out of RAM.
  661. */
  662. bool supports_48bit_addresses;
  663. struct brw_compiler * compiler;
  664. struct isl_device isl_dev;
  665. int cmd_parser_version;
  666. bool has_exec_async;
  667. bool has_exec_capture;
  668. bool has_exec_fence;
  669. bool has_syncobj;
  670. bool has_syncobj_wait;
  671. struct anv_device_extension_table supported_extensions;
  672. uint32_t eu_total;
  673. uint32_t subslice_total;
  674. struct {
  675. uint32_t type_count;
  676. struct anv_memory_type types[VK_MAX_MEMORY_TYPES];
  677. uint32_t heap_count;
  678. struct anv_memory_heap heaps[VK_MAX_MEMORY_HEAPS];
  679. } memory;
  680. uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
  681. uint8_t driver_uuid[VK_UUID_SIZE];
  682. uint8_t device_uuid[VK_UUID_SIZE];
  683. struct wsi_device wsi_device;
  684. int local_fd;
  685. };
  686. struct anv_instance {
  687. VK_LOADER_DATA _loader_data;
  688. VkAllocationCallbacks alloc;
  689. uint32_t apiVersion;
  690. struct anv_instance_extension_table enabled_extensions;
  691. struct anv_dispatch_table dispatch;
  692. int physicalDeviceCount;
  693. struct anv_physical_device physicalDevice;
  694. struct vk_debug_report_instance debug_report_callbacks;
  695. };
  696. VkResult anv_init_wsi(struct anv_physical_device *physical_device);
  697. void anv_finish_wsi(struct anv_physical_device *physical_device);
  698. uint32_t anv_physical_device_api_version(struct anv_physical_device *dev);
  699. bool anv_physical_device_extension_supported(struct anv_physical_device *dev,
  700. const char *name);
  701. struct anv_queue {
  702. VK_LOADER_DATA _loader_data;
  703. struct anv_device * device;
  704. struct anv_state_pool * pool;
  705. };
  706. struct anv_pipeline_cache {
  707. struct anv_device * device;
  708. pthread_mutex_t mutex;
  709. struct hash_table * cache;
  710. };
  711. struct anv_pipeline_bind_map;
  712. void anv_pipeline_cache_init(struct anv_pipeline_cache *cache,
  713. struct anv_device *device,
  714. bool cache_enabled);
  715. void anv_pipeline_cache_finish(struct anv_pipeline_cache *cache);
  716. struct anv_shader_bin *
  717. anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
  718. const void *key, uint32_t key_size);
  719. struct anv_shader_bin *
  720. anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
  721. const void *key_data, uint32_t key_size,
  722. const void *kernel_data, uint32_t kernel_size,
  723. const struct brw_stage_prog_data *prog_data,
  724. uint32_t prog_data_size,
  725. const struct anv_pipeline_bind_map *bind_map);
  726. struct anv_device {
  727. VK_LOADER_DATA _loader_data;
  728. VkAllocationCallbacks alloc;
  729. struct anv_instance * instance;
  730. uint32_t chipset_id;
  731. struct gen_device_info info;
  732. struct isl_device isl_dev;
  733. int context_id;
  734. int fd;
  735. bool can_chain_batches;
  736. bool robust_buffer_access;
  737. struct anv_device_extension_table enabled_extensions;
  738. struct anv_bo_pool batch_bo_pool;
  739. struct anv_bo_cache bo_cache;
  740. struct anv_state_pool dynamic_state_pool;
  741. struct anv_state_pool instruction_state_pool;
  742. struct anv_state_pool surface_state_pool;
  743. struct anv_bo workaround_bo;
  744. struct anv_bo trivial_batch_bo;
  745. struct anv_pipeline_cache blorp_shader_cache;
  746. struct blorp_context blorp;
  747. struct anv_state border_colors;
  748. struct anv_queue queue;
  749. struct anv_scratch_pool scratch_pool;
  750. uint32_t default_mocs;
  751. pthread_mutex_t mutex;
  752. pthread_cond_t queue_submit;
  753. bool lost;
  754. };
  755. static void inline
  756. anv_state_flush(struct anv_device *device, struct anv_state state)
  757. {
  758. if (device->info.has_llc)
  759. return;
  760. gen_flush_range(state.map, state.alloc_size);
  761. }
  762. void anv_device_init_blorp(struct anv_device *device);
  763. void anv_device_finish_blorp(struct anv_device *device);
  764. VkResult anv_device_execbuf(struct anv_device *device,
  765. struct drm_i915_gem_execbuffer2 *execbuf,
  766. struct anv_bo **execbuf_bos);
  767. VkResult anv_device_query_status(struct anv_device *device);
  768. VkResult anv_device_bo_busy(struct anv_device *device, struct anv_bo *bo);
  769. VkResult anv_device_wait(struct anv_device *device, struct anv_bo *bo,
  770. int64_t timeout);
  771. void* anv_gem_mmap(struct anv_device *device,
  772. uint32_t gem_handle, uint64_t offset, uint64_t size, uint32_t flags);
  773. void anv_gem_munmap(void *p, uint64_t size);
  774. uint32_t anv_gem_create(struct anv_device *device, uint64_t size);
  775. void anv_gem_close(struct anv_device *device, uint32_t gem_handle);
  776. uint32_t anv_gem_userptr(struct anv_device *device, void *mem, size_t size);
  777. int anv_gem_busy(struct anv_device *device, uint32_t gem_handle);
  778. int anv_gem_wait(struct anv_device *device, uint32_t gem_handle, int64_t *timeout_ns);
  779. int anv_gem_execbuffer(struct anv_device *device,
  780. struct drm_i915_gem_execbuffer2 *execbuf);
  781. int anv_gem_set_tiling(struct anv_device *device, uint32_t gem_handle,
  782. uint32_t stride, uint32_t tiling);
  783. int anv_gem_create_context(struct anv_device *device);
  784. int anv_gem_destroy_context(struct anv_device *device, int context);
  785. int anv_gem_get_context_param(int fd, int context, uint32_t param,
  786. uint64_t *value);
  787. int anv_gem_get_param(int fd, uint32_t param);
  788. int anv_gem_get_tiling(struct anv_device *device, uint32_t gem_handle);
  789. bool anv_gem_get_bit6_swizzle(int fd, uint32_t tiling);
  790. int anv_gem_get_aperture(int fd, uint64_t *size);
  791. bool anv_gem_supports_48b_addresses(int fd);
  792. int anv_gem_gpu_get_reset_stats(struct anv_device *device,
  793. uint32_t *active, uint32_t *pending);
  794. int anv_gem_handle_to_fd(struct anv_device *device, uint32_t gem_handle);
  795. uint32_t anv_gem_fd_to_handle(struct anv_device *device, int fd);
  796. int anv_gem_set_caching(struct anv_device *device, uint32_t gem_handle, uint32_t caching);
  797. int anv_gem_set_domain(struct anv_device *device, uint32_t gem_handle,
  798. uint32_t read_domains, uint32_t write_domain);
  799. int anv_gem_sync_file_merge(struct anv_device *device, int fd1, int fd2);
  800. uint32_t anv_gem_syncobj_create(struct anv_device *device, uint32_t flags);
  801. void anv_gem_syncobj_destroy(struct anv_device *device, uint32_t handle);
  802. int anv_gem_syncobj_handle_to_fd(struct anv_device *device, uint32_t handle);
  803. uint32_t anv_gem_syncobj_fd_to_handle(struct anv_device *device, int fd);
  804. int anv_gem_syncobj_export_sync_file(struct anv_device *device,
  805. uint32_t handle);
  806. int anv_gem_syncobj_import_sync_file(struct anv_device *device,
  807. uint32_t handle, int fd);
  808. void anv_gem_syncobj_reset(struct anv_device *device, uint32_t handle);
  809. bool anv_gem_supports_syncobj_wait(int fd);
  810. int anv_gem_syncobj_wait(struct anv_device *device,
  811. uint32_t *handles, uint32_t num_handles,
  812. int64_t abs_timeout_ns, bool wait_all);
  813. VkResult anv_bo_init_new(struct anv_bo *bo, struct anv_device *device, uint64_t size);
  814. struct anv_reloc_list {
  815. uint32_t num_relocs;
  816. uint32_t array_length;
  817. struct drm_i915_gem_relocation_entry * relocs;
  818. struct anv_bo ** reloc_bos;
  819. };
  820. VkResult anv_reloc_list_init(struct anv_reloc_list *list,
  821. const VkAllocationCallbacks *alloc);
  822. void anv_reloc_list_finish(struct anv_reloc_list *list,
  823. const VkAllocationCallbacks *alloc);
  824. VkResult anv_reloc_list_add(struct anv_reloc_list *list,
  825. const VkAllocationCallbacks *alloc,
  826. uint32_t offset, struct anv_bo *target_bo,
  827. uint32_t delta);
  828. struct anv_batch_bo {
  829. /* Link in the anv_cmd_buffer.owned_batch_bos list */
  830. struct list_head link;
  831. struct anv_bo bo;
  832. /* Bytes actually consumed in this batch BO */
  833. uint32_t length;
  834. struct anv_reloc_list relocs;
  835. };
  836. struct anv_batch {
  837. const VkAllocationCallbacks * alloc;
  838. void * start;
  839. void * end;
  840. void * next;
  841. struct anv_reloc_list * relocs;
  842. /* This callback is called (with the associated user data) in the event
  843. * that the batch runs out of space.
  844. */
  845. VkResult (*extend_cb)(struct anv_batch *, void *);
  846. void * user_data;
  847. /**
  848. * Current error status of the command buffer. Used to track inconsistent
  849. * or incomplete command buffer states that are the consequence of run-time
  850. * errors such as out of memory scenarios. We want to track this in the
  851. * batch because the command buffer object is not visible to some parts
  852. * of the driver.
  853. */
  854. VkResult status;
  855. };
  856. void *anv_batch_emit_dwords(struct anv_batch *batch, int num_dwords);
  857. void anv_batch_emit_batch(struct anv_batch *batch, struct anv_batch *other);
  858. uint64_t anv_batch_emit_reloc(struct anv_batch *batch,
  859. void *location, struct anv_bo *bo, uint32_t offset);
  860. VkResult anv_device_submit_simple_batch(struct anv_device *device,
  861. struct anv_batch *batch);
  862. static inline VkResult
  863. anv_batch_set_error(struct anv_batch *batch, VkResult error)
  864. {
  865. assert(error != VK_SUCCESS);
  866. if (batch->status == VK_SUCCESS)
  867. batch->status = error;
  868. return batch->status;
  869. }
  870. static inline bool
  871. anv_batch_has_error(struct anv_batch *batch)
  872. {
  873. return batch->status != VK_SUCCESS;
  874. }
  875. struct anv_address {
  876. struct anv_bo *bo;
  877. uint32_t offset;
  878. };
  879. static inline uint64_t
  880. _anv_combine_address(struct anv_batch *batch, void *location,
  881. const struct anv_address address, uint32_t delta)
  882. {
  883. if (address.bo == NULL) {
  884. return address.offset + delta;
  885. } else {
  886. assert(batch->start <= location && location < batch->end);
  887. return anv_batch_emit_reloc(batch, location, address.bo, address.offset + delta);
  888. }
  889. }
  890. #define __gen_address_type struct anv_address
  891. #define __gen_user_data struct anv_batch
  892. #define __gen_combine_address _anv_combine_address
  893. /* Wrapper macros needed to work around preprocessor argument issues. In
  894. * particular, arguments don't get pre-evaluated if they are concatenated.
  895. * This means that, if you pass GENX(3DSTATE_PS) into the emit macro, the
  896. * GENX macro won't get evaluated if the emit macro contains "cmd ## foo".
  897. * We can work around this easily enough with these helpers.
  898. */
  899. #define __anv_cmd_length(cmd) cmd ## _length
  900. #define __anv_cmd_length_bias(cmd) cmd ## _length_bias
  901. #define __anv_cmd_header(cmd) cmd ## _header
  902. #define __anv_cmd_pack(cmd) cmd ## _pack
  903. #define __anv_reg_num(reg) reg ## _num
  904. #define anv_pack_struct(dst, struc, ...) do { \
  905. struct struc __template = { \
  906. __VA_ARGS__ \
  907. }; \
  908. __anv_cmd_pack(struc)(NULL, dst, &__template); \
  909. VG(VALGRIND_CHECK_MEM_IS_DEFINED(dst, __anv_cmd_length(struc) * 4)); \
  910. } while (0)
  911. #define anv_batch_emitn(batch, n, cmd, ...) ({ \
  912. void *__dst = anv_batch_emit_dwords(batch, n); \
  913. if (__dst) { \
  914. struct cmd __template = { \
  915. __anv_cmd_header(cmd), \
  916. .DWordLength = n - __anv_cmd_length_bias(cmd), \
  917. __VA_ARGS__ \
  918. }; \
  919. __anv_cmd_pack(cmd)(batch, __dst, &__template); \
  920. } \
  921. __dst; \
  922. })
  923. #define anv_batch_emit_merge(batch, dwords0, dwords1) \
  924. do { \
  925. uint32_t *dw; \
  926. \
  927. STATIC_ASSERT(ARRAY_SIZE(dwords0) == ARRAY_SIZE(dwords1)); \
  928. dw = anv_batch_emit_dwords((batch), ARRAY_SIZE(dwords0)); \
  929. if (!dw) \
  930. break; \
  931. for (uint32_t i = 0; i < ARRAY_SIZE(dwords0); i++) \
  932. dw[i] = (dwords0)[i] | (dwords1)[i]; \
  933. VG(VALGRIND_CHECK_MEM_IS_DEFINED(dw, ARRAY_SIZE(dwords0) * 4));\
  934. } while (0)
  935. #define anv_batch_emit(batch, cmd, name) \
  936. for (struct cmd name = { __anv_cmd_header(cmd) }, \
  937. *_dst = anv_batch_emit_dwords(batch, __anv_cmd_length(cmd)); \
  938. __builtin_expect(_dst != NULL, 1); \
  939. ({ __anv_cmd_pack(cmd)(batch, _dst, &name); \
  940. VG(VALGRIND_CHECK_MEM_IS_DEFINED(_dst, __anv_cmd_length(cmd) * 4)); \
  941. _dst = NULL; \
  942. }))
  943. #define GEN7_MOCS (struct GEN7_MEMORY_OBJECT_CONTROL_STATE) { \
  944. .GraphicsDataTypeGFDT = 0, \
  945. .LLCCacheabilityControlLLCCC = 0, \
  946. .L3CacheabilityControlL3CC = 1, \
  947. }
  948. #define GEN75_MOCS (struct GEN75_MEMORY_OBJECT_CONTROL_STATE) { \
  949. .LLCeLLCCacheabilityControlLLCCC = 0, \
  950. .L3CacheabilityControlL3CC = 1, \
  951. }
  952. #define GEN8_MOCS (struct GEN8_MEMORY_OBJECT_CONTROL_STATE) { \
  953. .MemoryTypeLLCeLLCCacheabilityControl = WB, \
  954. .TargetCache = L3DefertoPATforLLCeLLCselection, \
  955. .AgeforQUADLRU = 0 \
  956. }
  957. /* Skylake: MOCS is now an index into an array of 62 different caching
  958. * configurations programmed by the kernel.
  959. */
  960. #define GEN9_MOCS (struct GEN9_MEMORY_OBJECT_CONTROL_STATE) { \
  961. /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
  962. .IndextoMOCSTables = 2 \
  963. }
  964. #define GEN9_MOCS_PTE { \
  965. /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
  966. .IndextoMOCSTables = 1 \
  967. }
  968. /* Cannonlake MOCS defines are duplicates of Skylake MOCS defines. */
  969. #define GEN10_MOCS (struct GEN10_MEMORY_OBJECT_CONTROL_STATE) { \
  970. /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
  971. .IndextoMOCSTables = 2 \
  972. }
  973. #define GEN10_MOCS_PTE { \
  974. /* TC=LLC/eLLC, LeCC=WB, LRUM=3, L3CC=WB */ \
  975. .IndextoMOCSTables = 1 \
  976. }
  977. struct anv_device_memory {
  978. struct anv_bo * bo;
  979. struct anv_memory_type * type;
  980. VkDeviceSize map_size;
  981. void * map;
  982. };
  983. /**
  984. * Header for Vertex URB Entry (VUE)
  985. */
  986. struct anv_vue_header {
  987. uint32_t Reserved;
  988. uint32_t RTAIndex; /* RenderTargetArrayIndex */
  989. uint32_t ViewportIndex;
  990. float PointWidth;
  991. };
  992. struct anv_descriptor_set_binding_layout {
  993. #ifndef NDEBUG
  994. /* The type of the descriptors in this binding */
  995. VkDescriptorType type;
  996. #endif
  997. /* Number of array elements in this binding */
  998. uint16_t array_size;
  999. /* Index into the flattend descriptor set */
  1000. uint16_t descriptor_index;
  1001. /* Index into the dynamic state array for a dynamic buffer */
  1002. int16_t dynamic_offset_index;
  1003. /* Index into the descriptor set buffer views */
  1004. int16_t buffer_index;
  1005. struct {
  1006. /* Index into the binding table for the associated surface */
  1007. int16_t surface_index;
  1008. /* Index into the sampler table for the associated sampler */
  1009. int16_t sampler_index;
  1010. /* Index into the image table for the associated image */
  1011. int16_t image_index;
  1012. } stage[MESA_SHADER_STAGES];
  1013. /* Immutable samplers (or NULL if no immutable samplers) */
  1014. struct anv_sampler **immutable_samplers;
  1015. };
  1016. struct anv_descriptor_set_layout {
  1017. /* Number of bindings in this descriptor set */
  1018. uint16_t binding_count;
  1019. /* Total size of the descriptor set with room for all array entries */
  1020. uint16_t size;
  1021. /* Shader stages affected by this descriptor set */
  1022. uint16_t shader_stages;
  1023. /* Number of buffers in this descriptor set */
  1024. uint16_t buffer_count;
  1025. /* Number of dynamic offsets used by this descriptor set */
  1026. uint16_t dynamic_offset_count;
  1027. /* Bindings in this descriptor set */
  1028. struct anv_descriptor_set_binding_layout binding[0];
  1029. };
  1030. struct anv_descriptor {
  1031. VkDescriptorType type;
  1032. union {
  1033. struct {
  1034. VkImageLayout layout;
  1035. struct anv_image_view *image_view;
  1036. struct anv_sampler *sampler;
  1037. };
  1038. struct {
  1039. struct anv_buffer *buffer;
  1040. uint64_t offset;
  1041. uint64_t range;
  1042. };
  1043. struct anv_buffer_view *buffer_view;
  1044. };
  1045. };
  1046. struct anv_descriptor_set {
  1047. const struct anv_descriptor_set_layout *layout;
  1048. uint32_t size;
  1049. uint32_t buffer_count;
  1050. struct anv_buffer_view *buffer_views;
  1051. struct anv_descriptor descriptors[0];
  1052. };
  1053. struct anv_buffer_view {
  1054. enum isl_format format; /**< VkBufferViewCreateInfo::format */
  1055. struct anv_bo *bo;
  1056. uint32_t offset; /**< Offset into bo. */
  1057. uint64_t range; /**< VkBufferViewCreateInfo::range */
  1058. struct anv_state surface_state;
  1059. struct anv_state storage_surface_state;
  1060. struct anv_state writeonly_storage_surface_state;
  1061. struct brw_image_param storage_image_param;
  1062. };
  1063. struct anv_push_descriptor_set {
  1064. struct anv_descriptor_set set;
  1065. /* Put this field right behind anv_descriptor_set so it fills up the
  1066. * descriptors[0] field. */
  1067. struct anv_descriptor descriptors[MAX_PUSH_DESCRIPTORS];
  1068. struct anv_buffer_view buffer_views[MAX_PUSH_DESCRIPTORS];
  1069. };
  1070. struct anv_descriptor_pool {
  1071. uint32_t size;
  1072. uint32_t next;
  1073. uint32_t free_list;
  1074. struct anv_state_stream surface_state_stream;
  1075. void *surface_state_free_list;
  1076. char data[0];
  1077. };
  1078. enum anv_descriptor_template_entry_type {
  1079. ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_IMAGE,
  1080. ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER,
  1081. ANV_DESCRIPTOR_TEMPLATE_ENTRY_TYPE_BUFFER_VIEW
  1082. };
  1083. struct anv_descriptor_template_entry {
  1084. /* The type of descriptor in this entry */
  1085. VkDescriptorType type;
  1086. /* Binding in the descriptor set */
  1087. uint32_t binding;
  1088. /* Offset at which to write into the descriptor set binding */
  1089. uint32_t array_element;
  1090. /* Number of elements to write into the descriptor set binding */
  1091. uint32_t array_count;
  1092. /* Offset into the user provided data */
  1093. size_t offset;
  1094. /* Stride between elements into the user provided data */
  1095. size_t stride;
  1096. };
  1097. struct anv_descriptor_update_template {
  1098. /* The descriptor set this template corresponds to. This value is only
  1099. * valid if the template was created with the templateType
  1100. * VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET_KHR.
  1101. */
  1102. uint8_t set;
  1103. /* Number of entries in this template */
  1104. uint32_t entry_count;
  1105. /* Entries of the template */
  1106. struct anv_descriptor_template_entry entries[0];
  1107. };
  1108. size_t
  1109. anv_descriptor_set_binding_layout_get_hw_size(const struct anv_descriptor_set_binding_layout *binding);
  1110. size_t
  1111. anv_descriptor_set_layout_size(const struct anv_descriptor_set_layout *layout);
  1112. void
  1113. anv_descriptor_set_write_image_view(struct anv_descriptor_set *set,
  1114. const struct gen_device_info * const devinfo,
  1115. const VkDescriptorImageInfo * const info,
  1116. VkDescriptorType type,
  1117. uint32_t binding,
  1118. uint32_t element);
  1119. void
  1120. anv_descriptor_set_write_buffer_view(struct anv_descriptor_set *set,
  1121. VkDescriptorType type,
  1122. struct anv_buffer_view *buffer_view,
  1123. uint32_t binding,
  1124. uint32_t element);
  1125. void
  1126. anv_descriptor_set_write_buffer(struct anv_descriptor_set *set,
  1127. struct anv_device *device,
  1128. struct anv_state_stream *alloc_stream,
  1129. VkDescriptorType type,
  1130. struct anv_buffer *buffer,
  1131. uint32_t binding,
  1132. uint32_t element,
  1133. VkDeviceSize offset,
  1134. VkDeviceSize range);
  1135. void
  1136. anv_descriptor_set_write_template(struct anv_descriptor_set *set,
  1137. struct anv_device *device,
  1138. struct anv_state_stream *alloc_stream,
  1139. const struct anv_descriptor_update_template *template,
  1140. const void *data);
  1141. VkResult
  1142. anv_descriptor_set_create(struct anv_device *device,
  1143. struct anv_descriptor_pool *pool,
  1144. const struct anv_descriptor_set_layout *layout,
  1145. struct anv_descriptor_set **out_set);
  1146. void
  1147. anv_descriptor_set_destroy(struct anv_device *device,
  1148. struct anv_descriptor_pool *pool,
  1149. struct anv_descriptor_set *set);
  1150. #define ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS UINT8_MAX
  1151. struct anv_pipeline_binding {
  1152. /* The descriptor set this surface corresponds to. The special value of
  1153. * ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS indicates that the offset refers
  1154. * to a color attachment and not a regular descriptor.
  1155. */
  1156. uint8_t set;
  1157. /* Binding in the descriptor set */
  1158. uint32_t binding;
  1159. /* Index in the binding */
  1160. uint32_t index;
  1161. /* Plane in the binding index */
  1162. uint8_t plane;
  1163. /* Input attachment index (relative to the subpass) */
  1164. uint8_t input_attachment_index;
  1165. /* For a storage image, whether it is write-only */
  1166. bool write_only;
  1167. };
  1168. struct anv_pipeline_layout {
  1169. struct {
  1170. struct anv_descriptor_set_layout *layout;
  1171. uint32_t dynamic_offset_start;
  1172. } set[MAX_SETS];
  1173. uint32_t num_sets;
  1174. struct {
  1175. bool has_dynamic_offsets;
  1176. } stage[MESA_SHADER_STAGES];
  1177. unsigned char sha1[20];
  1178. };
  1179. struct anv_buffer {
  1180. struct anv_device * device;
  1181. VkDeviceSize size;
  1182. VkBufferUsageFlags usage;
  1183. /* Set when bound */
  1184. struct anv_bo * bo;
  1185. VkDeviceSize offset;
  1186. };
  1187. static inline uint64_t
  1188. anv_buffer_get_range(struct anv_buffer *buffer, uint64_t offset, uint64_t range)
  1189. {
  1190. assert(offset <= buffer->size);
  1191. if (range == VK_WHOLE_SIZE) {
  1192. return buffer->size - offset;
  1193. } else {
  1194. assert(range <= buffer->size);
  1195. return range;
  1196. }
  1197. }
  1198. enum anv_cmd_dirty_bits {
  1199. ANV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
  1200. ANV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
  1201. ANV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
  1202. ANV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
  1203. ANV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
  1204. ANV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
  1205. ANV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
  1206. ANV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
  1207. ANV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
  1208. ANV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
  1209. ANV_CMD_DIRTY_PIPELINE = 1 << 9,
  1210. ANV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
  1211. ANV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
  1212. };
  1213. typedef uint32_t anv_cmd_dirty_mask_t;
  1214. enum anv_pipe_bits {
  1215. ANV_PIPE_DEPTH_CACHE_FLUSH_BIT = (1 << 0),
  1216. ANV_PIPE_STALL_AT_SCOREBOARD_BIT = (1 << 1),
  1217. ANV_PIPE_STATE_CACHE_INVALIDATE_BIT = (1 << 2),
  1218. ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT = (1 << 3),
  1219. ANV_PIPE_VF_CACHE_INVALIDATE_BIT = (1 << 4),
  1220. ANV_PIPE_DATA_CACHE_FLUSH_BIT = (1 << 5),
  1221. ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT = (1 << 10),
  1222. ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT = (1 << 11),
  1223. ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT = (1 << 12),
  1224. ANV_PIPE_DEPTH_STALL_BIT = (1 << 13),
  1225. ANV_PIPE_CS_STALL_BIT = (1 << 20),
  1226. /* This bit does not exist directly in PIPE_CONTROL. Instead it means that
  1227. * a flush has happened but not a CS stall. The next time we do any sort
  1228. * of invalidation we need to insert a CS stall at that time. Otherwise,
  1229. * we would have to CS stall on every flush which could be bad.
  1230. */
  1231. ANV_PIPE_NEEDS_CS_STALL_BIT = (1 << 21),
  1232. };
  1233. #define ANV_PIPE_FLUSH_BITS ( \
  1234. ANV_PIPE_DEPTH_CACHE_FLUSH_BIT | \
  1235. ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
  1236. ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT)
  1237. #define ANV_PIPE_STALL_BITS ( \
  1238. ANV_PIPE_STALL_AT_SCOREBOARD_BIT | \
  1239. ANV_PIPE_DEPTH_STALL_BIT | \
  1240. ANV_PIPE_CS_STALL_BIT)
  1241. #define ANV_PIPE_INVALIDATE_BITS ( \
  1242. ANV_PIPE_STATE_CACHE_INVALIDATE_BIT | \
  1243. ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT | \
  1244. ANV_PIPE_VF_CACHE_INVALIDATE_BIT | \
  1245. ANV_PIPE_DATA_CACHE_FLUSH_BIT | \
  1246. ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT | \
  1247. ANV_PIPE_INSTRUCTION_CACHE_INVALIDATE_BIT)
  1248. static inline enum anv_pipe_bits
  1249. anv_pipe_flush_bits_for_access_flags(VkAccessFlags flags)
  1250. {
  1251. enum anv_pipe_bits pipe_bits = 0;
  1252. unsigned b;
  1253. for_each_bit(b, flags) {
  1254. switch ((VkAccessFlagBits)(1 << b)) {
  1255. case VK_ACCESS_SHADER_WRITE_BIT:
  1256. pipe_bits |= ANV_PIPE_DATA_CACHE_FLUSH_BIT;
  1257. break;
  1258. case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT:
  1259. pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
  1260. break;
  1261. case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT:
  1262. pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
  1263. break;
  1264. case VK_ACCESS_TRANSFER_WRITE_BIT:
  1265. pipe_bits |= ANV_PIPE_RENDER_TARGET_CACHE_FLUSH_BIT;
  1266. pipe_bits |= ANV_PIPE_DEPTH_CACHE_FLUSH_BIT;
  1267. break;
  1268. default:
  1269. break; /* Nothing to do */
  1270. }
  1271. }
  1272. return pipe_bits;
  1273. }
  1274. static inline enum anv_pipe_bits
  1275. anv_pipe_invalidate_bits_for_access_flags(VkAccessFlags flags)
  1276. {
  1277. enum anv_pipe_bits pipe_bits = 0;
  1278. unsigned b;
  1279. for_each_bit(b, flags) {
  1280. switch ((VkAccessFlagBits)(1 << b)) {
  1281. case VK_ACCESS_INDIRECT_COMMAND_READ_BIT:
  1282. case VK_ACCESS_INDEX_READ_BIT:
  1283. case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT:
  1284. pipe_bits |= ANV_PIPE_VF_CACHE_INVALIDATE_BIT;
  1285. break;
  1286. case VK_ACCESS_UNIFORM_READ_BIT:
  1287. pipe_bits |= ANV_PIPE_CONSTANT_CACHE_INVALIDATE_BIT;
  1288. pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
  1289. break;
  1290. case VK_ACCESS_SHADER_READ_BIT:
  1291. case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT:
  1292. case VK_ACCESS_TRANSFER_READ_BIT:
  1293. pipe_bits |= ANV_PIPE_TEXTURE_CACHE_INVALIDATE_BIT;
  1294. break;
  1295. default:
  1296. break; /* Nothing to do */
  1297. }
  1298. }
  1299. return pipe_bits;
  1300. }
  1301. #define VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV ( \
  1302. VK_IMAGE_ASPECT_COLOR_BIT | \
  1303. VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | \
  1304. VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | \
  1305. VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)
  1306. #define VK_IMAGE_ASPECT_PLANES_BITS_ANV ( \
  1307. VK_IMAGE_ASPECT_PLANE_0_BIT_KHR | \
  1308. VK_IMAGE_ASPECT_PLANE_1_BIT_KHR | \
  1309. VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)
  1310. struct anv_vertex_binding {
  1311. struct anv_buffer * buffer;
  1312. VkDeviceSize offset;
  1313. };
  1314. #define ANV_PARAM_PUSH(offset) ((1 << 16) | (uint32_t)(offset))
  1315. #define ANV_PARAM_PUSH_OFFSET(param) ((param) & 0xffff)
  1316. struct anv_push_constants {
  1317. /* Current allocated size of this push constants data structure.
  1318. * Because a decent chunk of it may not be used (images on SKL, for
  1319. * instance), we won't actually allocate the entire structure up-front.
  1320. */
  1321. uint32_t size;
  1322. /* Push constant data provided by the client through vkPushConstants */
  1323. uint8_t client_data[MAX_PUSH_CONSTANTS_SIZE];
  1324. /* Image data for image_load_store on pre-SKL */
  1325. struct brw_image_param images[MAX_IMAGES];
  1326. };
  1327. struct anv_dynamic_state {
  1328. struct {
  1329. uint32_t count;
  1330. VkViewport viewports[MAX_VIEWPORTS];
  1331. } viewport;
  1332. struct {
  1333. uint32_t count;
  1334. VkRect2D scissors[MAX_SCISSORS];
  1335. } scissor;
  1336. float line_width;
  1337. struct {
  1338. float bias;
  1339. float clamp;
  1340. float slope;
  1341. } depth_bias;
  1342. float blend_constants[4];
  1343. struct {
  1344. float min;
  1345. float max;
  1346. } depth_bounds;
  1347. struct {
  1348. uint32_t front;
  1349. uint32_t back;
  1350. } stencil_compare_mask;
  1351. struct {
  1352. uint32_t front;
  1353. uint32_t back;
  1354. } stencil_write_mask;
  1355. struct {
  1356. uint32_t front;
  1357. uint32_t back;
  1358. } stencil_reference;
  1359. };
  1360. extern const struct anv_dynamic_state default_dynamic_state;
  1361. void anv_dynamic_state_copy(struct anv_dynamic_state *dest,
  1362. const struct anv_dynamic_state *src,
  1363. uint32_t copy_mask);
  1364. struct anv_surface_state {
  1365. struct anv_state state;
  1366. /** Address of the surface referred to by this state
  1367. *
  1368. * This address is relative to the start of the BO.
  1369. */
  1370. uint64_t address;
  1371. /* Address of the aux surface, if any
  1372. *
  1373. * This field is 0 if and only if no aux surface exists.
  1374. *
  1375. * This address is relative to the start of the BO. On gen7, the bottom 12
  1376. * bits of this address include extra aux information.
  1377. */
  1378. uint64_t aux_address;
  1379. };
  1380. /**
  1381. * Attachment state when recording a renderpass instance.
  1382. *
  1383. * The clear value is valid only if there exists a pending clear.
  1384. */
  1385. struct anv_attachment_state {
  1386. enum isl_aux_usage aux_usage;
  1387. enum isl_aux_usage input_aux_usage;
  1388. struct anv_surface_state color;
  1389. struct anv_surface_state input;
  1390. VkImageLayout current_layout;
  1391. VkImageAspectFlags pending_clear_aspects;
  1392. bool fast_clear;
  1393. VkClearValue clear_value;
  1394. bool clear_color_is_zero_one;
  1395. bool clear_color_is_zero;
  1396. };
  1397. /** State required while building cmd buffer */
  1398. struct anv_cmd_state {
  1399. /* PIPELINE_SELECT.PipelineSelection */
  1400. uint32_t current_pipeline;
  1401. const struct gen_l3_config * current_l3_config;
  1402. uint32_t vb_dirty;
  1403. anv_cmd_dirty_mask_t dirty;
  1404. anv_cmd_dirty_mask_t compute_dirty;
  1405. enum anv_pipe_bits pending_pipe_bits;
  1406. uint32_t num_workgroups_offset;
  1407. struct anv_bo *num_workgroups_bo;
  1408. VkShaderStageFlags descriptors_dirty;
  1409. VkShaderStageFlags push_constants_dirty;
  1410. uint32_t scratch_size;
  1411. struct anv_pipeline * pipeline;
  1412. struct anv_pipeline * compute_pipeline;
  1413. struct anv_framebuffer * framebuffer;
  1414. struct anv_render_pass * pass;
  1415. struct anv_subpass * subpass;
  1416. VkRect2D render_area;
  1417. uint32_t restart_index;
  1418. struct anv_vertex_binding vertex_bindings[MAX_VBS];
  1419. struct anv_descriptor_set * descriptors[MAX_SETS];
  1420. uint32_t dynamic_offsets[MAX_DYNAMIC_BUFFERS];
  1421. VkShaderStageFlags push_constant_stages;
  1422. struct anv_push_constants * push_constants[MESA_SHADER_STAGES];
  1423. struct anv_state binding_tables[MESA_SHADER_STAGES];
  1424. struct anv_state samplers[MESA_SHADER_STAGES];
  1425. struct anv_dynamic_state dynamic;
  1426. bool need_query_wa;
  1427. struct anv_push_descriptor_set * push_descriptors[MAX_SETS];
  1428. /**
  1429. * Whether or not the gen8 PMA fix is enabled. We ensure that, at the top
  1430. * of any command buffer it is disabled by disabling it in EndCommandBuffer
  1431. * and before invoking the secondary in ExecuteCommands.
  1432. */
  1433. bool pma_fix_enabled;
  1434. /**
  1435. * Whether or not we know for certain that HiZ is enabled for the current
  1436. * subpass. If, for whatever reason, we are unsure as to whether HiZ is
  1437. * enabled or not, this will be false.
  1438. */
  1439. bool hiz_enabled;
  1440. /**
  1441. * Array length is anv_cmd_state::pass::attachment_count. Array content is
  1442. * valid only when recording a render pass instance.
  1443. */
  1444. struct anv_attachment_state * attachments;
  1445. /**
  1446. * Surface states for color render targets. These are stored in a single
  1447. * flat array. For depth-stencil attachments, the surface state is simply
  1448. * left blank.
  1449. */
  1450. struct anv_state render_pass_states;
  1451. /**
  1452. * A null surface state of the right size to match the framebuffer. This
  1453. * is one of the states in render_pass_states.
  1454. */
  1455. struct anv_state null_surface_state;
  1456. struct {
  1457. struct anv_buffer * index_buffer;
  1458. uint32_t index_type; /**< 3DSTATE_INDEX_BUFFER.IndexFormat */
  1459. uint32_t index_offset;
  1460. } gen7;
  1461. };
  1462. struct anv_cmd_pool {
  1463. VkAllocationCallbacks alloc;
  1464. struct list_head cmd_buffers;
  1465. };
  1466. #define ANV_CMD_BUFFER_BATCH_SIZE 8192
  1467. enum anv_cmd_buffer_exec_mode {
  1468. ANV_CMD_BUFFER_EXEC_MODE_PRIMARY,
  1469. ANV_CMD_BUFFER_EXEC_MODE_EMIT,
  1470. ANV_CMD_BUFFER_EXEC_MODE_GROW_AND_EMIT,
  1471. ANV_CMD_BUFFER_EXEC_MODE_CHAIN,
  1472. ANV_CMD_BUFFER_EXEC_MODE_COPY_AND_CHAIN,
  1473. };
  1474. struct anv_cmd_buffer {
  1475. VK_LOADER_DATA _loader_data;
  1476. struct anv_device * device;
  1477. struct anv_cmd_pool * pool;
  1478. struct list_head pool_link;
  1479. struct anv_batch batch;
  1480. /* Fields required for the actual chain of anv_batch_bo's.
  1481. *
  1482. * These fields are initialized by anv_cmd_buffer_init_batch_bo_chain().
  1483. */
  1484. struct list_head batch_bos;
  1485. enum anv_cmd_buffer_exec_mode exec_mode;
  1486. /* A vector of anv_batch_bo pointers for every batch or surface buffer
  1487. * referenced by this command buffer
  1488. *
  1489. * initialized by anv_cmd_buffer_init_batch_bo_chain()
  1490. */
  1491. struct u_vector seen_bbos;
  1492. /* A vector of int32_t's for every block of binding tables.
  1493. *
  1494. * initialized by anv_cmd_buffer_init_batch_bo_chain()
  1495. */
  1496. struct u_vector bt_block_states;
  1497. uint32_t bt_next;
  1498. struct anv_reloc_list surface_relocs;
  1499. /** Last seen surface state block pool center bo offset */
  1500. uint32_t last_ss_pool_center;
  1501. /* Serial for tracking buffer completion */
  1502. uint32_t serial;
  1503. /* Stream objects for storing temporary data */
  1504. struct anv_state_stream surface_state_stream;
  1505. struct anv_state_stream dynamic_state_stream;
  1506. VkCommandBufferUsageFlags usage_flags;
  1507. VkCommandBufferLevel level;
  1508. struct anv_cmd_state state;
  1509. };
  1510. VkResult anv_cmd_buffer_init_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
  1511. void anv_cmd_buffer_fini_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
  1512. void anv_cmd_buffer_reset_batch_bo_chain(struct anv_cmd_buffer *cmd_buffer);
  1513. void anv_cmd_buffer_end_batch_buffer(struct anv_cmd_buffer *cmd_buffer);
  1514. void anv_cmd_buffer_add_secondary(struct anv_cmd_buffer *primary,
  1515. struct anv_cmd_buffer *secondary);
  1516. void anv_cmd_buffer_prepare_execbuf(struct anv_cmd_buffer *cmd_buffer);
  1517. VkResult anv_cmd_buffer_execbuf(struct anv_device *device,
  1518. struct anv_cmd_buffer *cmd_buffer,
  1519. const VkSemaphore *in_semaphores,
  1520. uint32_t num_in_semaphores,
  1521. const VkSemaphore *out_semaphores,
  1522. uint32_t num_out_semaphores,
  1523. VkFence fence);
  1524. VkResult anv_cmd_buffer_reset(struct anv_cmd_buffer *cmd_buffer);
  1525. VkResult
  1526. anv_cmd_buffer_ensure_push_constants_size(struct anv_cmd_buffer *cmd_buffer,
  1527. gl_shader_stage stage, uint32_t size);
  1528. #define anv_cmd_buffer_ensure_push_constant_field(cmd_buffer, stage, field) \
  1529. anv_cmd_buffer_ensure_push_constants_size(cmd_buffer, stage, \
  1530. (offsetof(struct anv_push_constants, field) + \
  1531. sizeof(cmd_buffer->state.push_constants[0]->field)))
  1532. struct anv_state anv_cmd_buffer_emit_dynamic(struct anv_cmd_buffer *cmd_buffer,
  1533. const void *data, uint32_t size, uint32_t alignment);
  1534. struct anv_state anv_cmd_buffer_merge_dynamic(struct anv_cmd_buffer *cmd_buffer,
  1535. uint32_t *a, uint32_t *b,
  1536. uint32_t dwords, uint32_t alignment);
  1537. struct anv_address
  1538. anv_cmd_buffer_surface_base_address(struct anv_cmd_buffer *cmd_buffer);
  1539. struct anv_state
  1540. anv_cmd_buffer_alloc_binding_table(struct anv_cmd_buffer *cmd_buffer,
  1541. uint32_t entries, uint32_t *state_offset);
  1542. struct anv_state
  1543. anv_cmd_buffer_alloc_surface_state(struct anv_cmd_buffer *cmd_buffer);
  1544. struct anv_state
  1545. anv_cmd_buffer_alloc_dynamic_state(struct anv_cmd_buffer *cmd_buffer,
  1546. uint32_t size, uint32_t alignment);
  1547. VkResult
  1548. anv_cmd_buffer_new_binding_table_block(struct anv_cmd_buffer *cmd_buffer);
  1549. void gen8_cmd_buffer_emit_viewport(struct anv_cmd_buffer *cmd_buffer);
  1550. void gen8_cmd_buffer_emit_depth_viewport(struct anv_cmd_buffer *cmd_buffer,
  1551. bool depth_clamp_enable);
  1552. void gen7_cmd_buffer_emit_scissor(struct anv_cmd_buffer *cmd_buffer);
  1553. void anv_cmd_buffer_setup_attachments(struct anv_cmd_buffer *cmd_buffer,
  1554. struct anv_render_pass *pass,
  1555. struct anv_framebuffer *framebuffer,
  1556. const VkClearValue *clear_values);
  1557. void anv_cmd_buffer_emit_state_base_address(struct anv_cmd_buffer *cmd_buffer);
  1558. struct anv_state
  1559. anv_cmd_buffer_push_constants(struct anv_cmd_buffer *cmd_buffer,
  1560. gl_shader_stage stage);
  1561. struct anv_state
  1562. anv_cmd_buffer_cs_push_constants(struct anv_cmd_buffer *cmd_buffer);
  1563. void anv_cmd_buffer_clear_subpass(struct anv_cmd_buffer *cmd_buffer);
  1564. void anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer);
  1565. const struct anv_image_view *
  1566. anv_cmd_buffer_get_depth_stencil_view(const struct anv_cmd_buffer *cmd_buffer);
  1567. VkResult
  1568. anv_cmd_buffer_alloc_blorp_binding_table(struct anv_cmd_buffer *cmd_buffer,
  1569. uint32_t num_entries,
  1570. uint32_t *state_offset,
  1571. struct anv_state *bt_state);
  1572. void anv_cmd_buffer_dump(struct anv_cmd_buffer *cmd_buffer);
  1573. enum anv_fence_type {
  1574. ANV_FENCE_TYPE_NONE = 0,
  1575. ANV_FENCE_TYPE_BO,
  1576. ANV_FENCE_TYPE_SYNCOBJ,
  1577. };
  1578. enum anv_bo_fence_state {
  1579. /** Indicates that this is a new (or newly reset fence) */
  1580. ANV_BO_FENCE_STATE_RESET,
  1581. /** Indicates that this fence has been submitted to the GPU but is still
  1582. * (as far as we know) in use by the GPU.
  1583. */
  1584. ANV_BO_FENCE_STATE_SUBMITTED,
  1585. ANV_BO_FENCE_STATE_SIGNALED,
  1586. };
  1587. struct anv_fence_impl {
  1588. enum anv_fence_type type;
  1589. union {
  1590. /** Fence implementation for BO fences
  1591. *
  1592. * These fences use a BO and a set of CPU-tracked state flags. The BO
  1593. * is added to the object list of the last execbuf call in a QueueSubmit
  1594. * and is marked EXEC_WRITE. The state flags track when the BO has been
  1595. * submitted to the kernel. We need to do this because Vulkan lets you
  1596. * wait on a fence that has not yet been submitted and I915_GEM_BUSY
  1597. * will say it's idle in this case.
  1598. */
  1599. struct {
  1600. struct anv_bo bo;
  1601. enum anv_bo_fence_state state;
  1602. } bo;
  1603. /** DRM syncobj handle for syncobj-based fences */
  1604. uint32_t syncobj;
  1605. };
  1606. };
  1607. struct anv_fence {
  1608. /* Permanent fence state. Every fence has some form of permanent state
  1609. * (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on (for
  1610. * cross-process fences) or it could just be a dummy for use internally.
  1611. */
  1612. struct anv_fence_impl permanent;
  1613. /* Temporary fence state. A fence *may* have temporary state. That state
  1614. * is added to the fence by an import operation and is reset back to
  1615. * ANV_SEMAPHORE_TYPE_NONE when the fence is reset. A fence with temporary
  1616. * state cannot be signaled because the fence must already be signaled
  1617. * before the temporary state can be exported from the fence in the other
  1618. * process and imported here.
  1619. */
  1620. struct anv_fence_impl temporary;
  1621. };
  1622. struct anv_event {
  1623. uint64_t semaphore;
  1624. struct anv_state state;
  1625. };
  1626. enum anv_semaphore_type {
  1627. ANV_SEMAPHORE_TYPE_NONE = 0,
  1628. ANV_SEMAPHORE_TYPE_DUMMY,
  1629. ANV_SEMAPHORE_TYPE_BO,
  1630. ANV_SEMAPHORE_TYPE_SYNC_FILE,
  1631. ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ,
  1632. };
  1633. struct anv_semaphore_impl {
  1634. enum anv_semaphore_type type;
  1635. union {
  1636. /* A BO representing this semaphore when type == ANV_SEMAPHORE_TYPE_BO.
  1637. * This BO will be added to the object list on any execbuf2 calls for
  1638. * which this semaphore is used as a wait or signal fence. When used as
  1639. * a signal fence, the EXEC_OBJECT_WRITE flag will be set.
  1640. */
  1641. struct anv_bo *bo;
  1642. /* The sync file descriptor when type == ANV_SEMAPHORE_TYPE_SYNC_FILE.
  1643. * If the semaphore is in the unsignaled state due to either just being
  1644. * created or because it has been used for a wait, fd will be -1.
  1645. */
  1646. int fd;
  1647. /* Sync object handle when type == ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ.
  1648. * Unlike GEM BOs, DRM sync objects aren't deduplicated by the kernel on
  1649. * import so we don't need to bother with a userspace cache.
  1650. */
  1651. uint32_t syncobj;
  1652. };
  1653. };
  1654. struct anv_semaphore {
  1655. /* Permanent semaphore state. Every semaphore has some form of permanent
  1656. * state (type != ANV_SEMAPHORE_TYPE_NONE). This may be a BO to fence on
  1657. * (for cross-process semaphores0 or it could just be a dummy for use
  1658. * internally.
  1659. */
  1660. struct anv_semaphore_impl permanent;
  1661. /* Temporary semaphore state. A semaphore *may* have temporary state.
  1662. * That state is added to the semaphore by an import operation and is reset
  1663. * back to ANV_SEMAPHORE_TYPE_NONE when the semaphore is waited on. A
  1664. * semaphore with temporary state cannot be signaled because the semaphore
  1665. * must already be signaled before the temporary state can be exported from
  1666. * the semaphore in the other process and imported here.
  1667. */
  1668. struct anv_semaphore_impl temporary;
  1669. };
  1670. void anv_semaphore_reset_temporary(struct anv_device *device,
  1671. struct anv_semaphore *semaphore);
  1672. struct anv_shader_module {
  1673. unsigned char sha1[20];
  1674. uint32_t size;
  1675. char data[0];
  1676. };
  1677. static inline gl_shader_stage
  1678. vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
  1679. {
  1680. assert(__builtin_popcount(vk_stage) == 1);
  1681. return ffs(vk_stage) - 1;
  1682. }
  1683. static inline VkShaderStageFlagBits
  1684. mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
  1685. {
  1686. return (1 << mesa_stage);
  1687. }
  1688. #define ANV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
  1689. #define anv_foreach_stage(stage, stage_bits) \
  1690. for (gl_shader_stage stage, \
  1691. __tmp = (gl_shader_stage)((stage_bits) & ANV_STAGE_MASK); \
  1692. stage = __builtin_ffs(__tmp) - 1, __tmp; \
  1693. __tmp &= ~(1 << (stage)))
  1694. struct anv_pipeline_bind_map {
  1695. uint32_t surface_count;
  1696. uint32_t sampler_count;
  1697. uint32_t image_count;
  1698. struct anv_pipeline_binding * surface_to_descriptor;
  1699. struct anv_pipeline_binding * sampler_to_descriptor;
  1700. };
  1701. struct anv_shader_bin_key {
  1702. uint32_t size;
  1703. uint8_t data[0];
  1704. };
  1705. struct anv_shader_bin {
  1706. uint32_t ref_cnt;
  1707. const struct anv_shader_bin_key *key;
  1708. struct anv_state kernel;
  1709. uint32_t kernel_size;
  1710. const struct brw_stage_prog_data *prog_data;
  1711. uint32_t prog_data_size;
  1712. struct anv_pipeline_bind_map bind_map;
  1713. };
  1714. struct anv_shader_bin *
  1715. anv_shader_bin_create(struct anv_device *device,
  1716. const void *key, uint32_t key_size,
  1717. const void *kernel, uint32_t kernel_size,
  1718. const struct brw_stage_prog_data *prog_data,
  1719. uint32_t prog_data_size, const void *prog_data_param,
  1720. const struct anv_pipeline_bind_map *bind_map);
  1721. void
  1722. anv_shader_bin_destroy(struct anv_device *device, struct anv_shader_bin *shader);
  1723. static inline void
  1724. anv_shader_bin_ref(struct anv_shader_bin *shader)
  1725. {
  1726. assert(shader && shader->ref_cnt >= 1);
  1727. p_atomic_inc(&shader->ref_cnt);
  1728. }
  1729. static inline void
  1730. anv_shader_bin_unref(struct anv_device *device, struct anv_shader_bin *shader)
  1731. {
  1732. assert(shader && shader->ref_cnt >= 1);
  1733. if (p_atomic_dec_zero(&shader->ref_cnt))
  1734. anv_shader_bin_destroy(device, shader);
  1735. }
  1736. struct anv_pipeline {
  1737. struct anv_device * device;
  1738. struct anv_batch batch;
  1739. uint32_t batch_data[512];
  1740. struct anv_reloc_list batch_relocs;
  1741. uint32_t dynamic_state_mask;
  1742. struct anv_dynamic_state dynamic_state;
  1743. struct anv_subpass * subpass;
  1744. struct anv_pipeline_layout * layout;
  1745. bool needs_data_cache;
  1746. struct anv_shader_bin * shaders[MESA_SHADER_STAGES];
  1747. struct {
  1748. const struct gen_l3_config * l3_config;
  1749. uint32_t total_size;
  1750. } urb;
  1751. VkShaderStageFlags active_stages;
  1752. struct anv_state blend_state;
  1753. uint32_t vb_used;
  1754. uint32_t binding_stride[MAX_VBS];
  1755. bool instancing_enable[MAX_VBS];
  1756. bool primitive_restart;
  1757. uint32_t topology;
  1758. uint32_t cs_right_mask;
  1759. bool writes_depth;
  1760. bool depth_test_enable;
  1761. bool writes_stencil;
  1762. bool stencil_test_enable;
  1763. bool depth_clamp_enable;
  1764. bool sample_shading_enable;
  1765. bool kill_pixel;
  1766. struct {
  1767. uint32_t sf[7];
  1768. uint32_t depth_stencil_state[3];
  1769. } gen7;
  1770. struct {
  1771. uint32_t sf[4];
  1772. uint32_t raster[5];
  1773. uint32_t wm_depth_stencil[3];
  1774. } gen8;
  1775. struct {
  1776. uint32_t wm_depth_stencil[4];
  1777. } gen9;
  1778. uint32_t interface_descriptor_data[8];
  1779. };
  1780. static inline bool
  1781. anv_pipeline_has_stage(const struct anv_pipeline *pipeline,
  1782. gl_shader_stage stage)
  1783. {
  1784. return (pipeline->active_stages & mesa_to_vk_shader_stage(stage)) != 0;
  1785. }
  1786. #define ANV_DECL_GET_PROG_DATA_FUNC(prefix, stage) \
  1787. static inline const struct brw_##prefix##_prog_data * \
  1788. get_##prefix##_prog_data(const struct anv_pipeline *pipeline) \
  1789. { \
  1790. if (anv_pipeline_has_stage(pipeline, stage)) { \
  1791. return (const struct brw_##prefix##_prog_data *) \
  1792. pipeline->shaders[stage]->prog_data; \
  1793. } else { \
  1794. return NULL; \
  1795. } \
  1796. }
  1797. ANV_DECL_GET_PROG_DATA_FUNC(vs, MESA_SHADER_VERTEX)
  1798. ANV_DECL_GET_PROG_DATA_FUNC(tcs, MESA_SHADER_TESS_CTRL)
  1799. ANV_DECL_GET_PROG_DATA_FUNC(tes, MESA_SHADER_TESS_EVAL)
  1800. ANV_DECL_GET_PROG_DATA_FUNC(gs, MESA_SHADER_GEOMETRY)
  1801. ANV_DECL_GET_PROG_DATA_FUNC(wm, MESA_SHADER_FRAGMENT)
  1802. ANV_DECL_GET_PROG_DATA_FUNC(cs, MESA_SHADER_COMPUTE)
  1803. static inline const struct brw_vue_prog_data *
  1804. anv_pipeline_get_last_vue_prog_data(const struct anv_pipeline *pipeline)
  1805. {
  1806. if (anv_pipeline_has_stage(pipeline, MESA_SHADER_GEOMETRY))
  1807. return &get_gs_prog_data(pipeline)->base;
  1808. else if (anv_pipeline_has_stage(pipeline, MESA_SHADER_TESS_EVAL))
  1809. return &get_tes_prog_data(pipeline)->base;
  1810. else
  1811. return &get_vs_prog_data(pipeline)->base;
  1812. }
  1813. VkResult
  1814. anv_pipeline_init(struct anv_pipeline *pipeline, struct anv_device *device,
  1815. struct anv_pipeline_cache *cache,
  1816. const VkGraphicsPipelineCreateInfo *pCreateInfo,
  1817. const VkAllocationCallbacks *alloc);
  1818. VkResult
  1819. anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
  1820. struct anv_pipeline_cache *cache,
  1821. const VkComputePipelineCreateInfo *info,
  1822. struct anv_shader_module *module,
  1823. const char *entrypoint,
  1824. const VkSpecializationInfo *spec_info);
  1825. struct anv_format_plane {
  1826. enum isl_format isl_format:16;
  1827. struct isl_swizzle swizzle;
  1828. /* Whether this plane contains chroma channels */
  1829. bool has_chroma;
  1830. /* For downscaling of YUV planes */
  1831. uint8_t denominator_scales[2];
  1832. /* How to map sampled ycbcr planes to a single 4 component element. */
  1833. struct isl_swizzle ycbcr_swizzle;
  1834. };
  1835. struct anv_format {
  1836. struct anv_format_plane planes[3];
  1837. uint8_t n_planes;
  1838. bool can_ycbcr;
  1839. };
  1840. static inline uint32_t
  1841. anv_image_aspect_to_plane(VkImageAspectFlags image_aspects,
  1842. VkImageAspectFlags aspect_mask)
  1843. {
  1844. switch (aspect_mask) {
  1845. case VK_IMAGE_ASPECT_COLOR_BIT:
  1846. case VK_IMAGE_ASPECT_DEPTH_BIT:
  1847. case VK_IMAGE_ASPECT_PLANE_0_BIT_KHR:
  1848. return 0;
  1849. case VK_IMAGE_ASPECT_STENCIL_BIT:
  1850. if ((image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT) == 0)
  1851. return 0;
  1852. /* Fall-through */
  1853. case VK_IMAGE_ASPECT_PLANE_1_BIT_KHR:
  1854. return 1;
  1855. case VK_IMAGE_ASPECT_PLANE_2_BIT_KHR:
  1856. return 2;
  1857. default:
  1858. /* Purposefully assert with depth/stencil aspects. */
  1859. unreachable("invalid image aspect");
  1860. }
  1861. }
  1862. static inline uint32_t
  1863. anv_image_aspect_get_planes(VkImageAspectFlags aspect_mask)
  1864. {
  1865. uint32_t planes = 0;
  1866. if (aspect_mask & (VK_IMAGE_ASPECT_COLOR_BIT |
  1867. VK_IMAGE_ASPECT_DEPTH_BIT |
  1868. VK_IMAGE_ASPECT_STENCIL_BIT |
  1869. VK_IMAGE_ASPECT_PLANE_0_BIT_KHR))
  1870. planes++;
  1871. if (aspect_mask & VK_IMAGE_ASPECT_PLANE_1_BIT_KHR)
  1872. planes++;
  1873. if (aspect_mask & VK_IMAGE_ASPECT_PLANE_2_BIT_KHR)
  1874. planes++;
  1875. return planes;
  1876. }
  1877. static inline VkImageAspectFlags
  1878. anv_plane_to_aspect(VkImageAspectFlags image_aspects,
  1879. uint32_t plane)
  1880. {
  1881. if (image_aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) {
  1882. if (_mesa_bitcount(image_aspects) > 1)
  1883. return VK_IMAGE_ASPECT_PLANE_0_BIT_KHR << plane;
  1884. return VK_IMAGE_ASPECT_COLOR_BIT;
  1885. }
  1886. if (image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT)
  1887. return VK_IMAGE_ASPECT_DEPTH_BIT << plane;
  1888. assert(image_aspects == VK_IMAGE_ASPECT_STENCIL_BIT);
  1889. return VK_IMAGE_ASPECT_STENCIL_BIT;
  1890. }
  1891. #define anv_foreach_image_aspect_bit(b, image, aspects) \
  1892. for_each_bit(b, anv_image_expand_aspects(image, aspects))
  1893. const struct anv_format *
  1894. anv_get_format(VkFormat format);
  1895. static inline uint32_t
  1896. anv_get_format_planes(VkFormat vk_format)
  1897. {
  1898. const struct anv_format *format = anv_get_format(vk_format);
  1899. return format != NULL ? format->n_planes : 0;
  1900. }
  1901. struct anv_format_plane
  1902. anv_get_format_plane(const struct gen_device_info *devinfo, VkFormat vk_format,
  1903. VkImageAspectFlagBits aspect, VkImageTiling tiling);
  1904. static inline enum isl_format
  1905. anv_get_isl_format(const struct gen_device_info *devinfo, VkFormat vk_format,
  1906. VkImageAspectFlags aspect, VkImageTiling tiling)
  1907. {
  1908. return anv_get_format_plane(devinfo, vk_format, aspect, tiling).isl_format;
  1909. }
  1910. static inline struct isl_swizzle
  1911. anv_swizzle_for_render(struct isl_swizzle swizzle)
  1912. {
  1913. /* Sometimes the swizzle will have alpha map to one. We do this to fake
  1914. * RGB as RGBA for texturing
  1915. */
  1916. assert(swizzle.a == ISL_CHANNEL_SELECT_ONE ||
  1917. swizzle.a == ISL_CHANNEL_SELECT_ALPHA);
  1918. /* But it doesn't matter what we render to that channel */
  1919. swizzle.a = ISL_CHANNEL_SELECT_ALPHA;
  1920. return swizzle;
  1921. }
  1922. void
  1923. anv_pipeline_setup_l3_config(struct anv_pipeline *pipeline, bool needs_slm);
  1924. /**
  1925. * Subsurface of an anv_image.
  1926. */
  1927. struct anv_surface {
  1928. /** Valid only if isl_surf::size > 0. */
  1929. struct isl_surf isl;
  1930. /**
  1931. * Offset from VkImage's base address, as bound by vkBindImageMemory().
  1932. */
  1933. uint32_t offset;
  1934. };
  1935. struct anv_image {
  1936. VkImageType type;
  1937. /* The original VkFormat provided by the client. This may not match any
  1938. * of the actual surface formats.
  1939. */
  1940. VkFormat vk_format;
  1941. const struct anv_format *format;
  1942. VkImageAspectFlags aspects;
  1943. VkExtent3D extent;
  1944. uint32_t levels;
  1945. uint32_t array_size;
  1946. uint32_t samples; /**< VkImageCreateInfo::samples */
  1947. uint32_t n_planes;
  1948. VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
  1949. VkImageTiling tiling; /** VkImageCreateInfo::tiling */
  1950. /**
  1951. * DRM format modifier for this image or DRM_FORMAT_MOD_INVALID.
  1952. */
  1953. uint64_t drm_format_mod;
  1954. VkDeviceSize size;
  1955. uint32_t alignment;
  1956. /* Whether the image is made of several underlying buffer objects rather a
  1957. * single one with different offsets.
  1958. */
  1959. bool disjoint;
  1960. /**
  1961. * Image subsurfaces
  1962. *
  1963. * For each foo, anv_image::planes[x].surface is valid if and only if
  1964. * anv_image::aspects has a x aspect. Refer to anv_image_aspect_to_plane()
  1965. * to figure the number associated with a given aspect.
  1966. *
  1967. * The hardware requires that the depth buffer and stencil buffer be
  1968. * separate surfaces. From Vulkan's perspective, though, depth and stencil
  1969. * reside in the same VkImage. To satisfy both the hardware and Vulkan, we
  1970. * allocate the depth and stencil buffers as separate surfaces in the same
  1971. * bo.
  1972. *
  1973. * Memory layout :
  1974. *
  1975. * -----------------------
  1976. * | surface0 | /|\
  1977. * ----------------------- |
  1978. * | shadow surface0 | |
  1979. * ----------------------- | Plane 0
  1980. * | aux surface0 | |
  1981. * ----------------------- |
  1982. * | fast clear colors0 | \|/
  1983. * -----------------------
  1984. * | surface1 | /|\
  1985. * ----------------------- |
  1986. * | shadow surface1 | |
  1987. * ----------------------- | Plane 1
  1988. * | aux surface1 | |
  1989. * ----------------------- |
  1990. * | fast clear colors1 | \|/
  1991. * -----------------------
  1992. * | ... |
  1993. * | |
  1994. * -----------------------
  1995. */
  1996. struct {
  1997. /**
  1998. * Offset of the entire plane (whenever the image is disjoint this is
  1999. * set to 0).
  2000. */
  2001. uint32_t offset;
  2002. VkDeviceSize size;
  2003. uint32_t alignment;
  2004. struct anv_surface surface;
  2005. /**
  2006. * A surface which shadows the main surface and may have different
  2007. * tiling. This is used for sampling using a tiling that isn't supported
  2008. * for other operations.
  2009. */
  2010. struct anv_surface shadow_surface;
  2011. /**
  2012. * For color images, this is the aux usage for this image when not used
  2013. * as a color attachment.
  2014. *
  2015. * For depth/stencil images, this is set to ISL_AUX_USAGE_HIZ if the
  2016. * image has a HiZ buffer.
  2017. */
  2018. enum isl_aux_usage aux_usage;
  2019. struct anv_surface aux_surface;
  2020. /**
  2021. * Offset of the fast clear state (used to compute the
  2022. * fast_clear_state_offset of the following planes).
  2023. */
  2024. uint32_t fast_clear_state_offset;
  2025. /**
  2026. * BO associated with this plane, set when bound.
  2027. */
  2028. struct anv_bo *bo;
  2029. VkDeviceSize bo_offset;
  2030. /**
  2031. * When destroying the image, also free the bo.
  2032. * */
  2033. bool bo_is_owned;
  2034. } planes[3];
  2035. };
  2036. /* Returns the number of auxiliary buffer levels attached to an image. */
  2037. static inline uint8_t
  2038. anv_image_aux_levels(const struct anv_image * const image,
  2039. VkImageAspectFlagBits aspect)
  2040. {
  2041. uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
  2042. return image->planes[plane].aux_surface.isl.size > 0 ?
  2043. image->planes[plane].aux_surface.isl.levels : 0;
  2044. }
  2045. /* Returns the number of auxiliary buffer layers attached to an image. */
  2046. static inline uint32_t
  2047. anv_image_aux_layers(const struct anv_image * const image,
  2048. VkImageAspectFlagBits aspect,
  2049. const uint8_t miplevel)
  2050. {
  2051. assert(image);
  2052. /* The miplevel must exist in the main buffer. */
  2053. assert(miplevel < image->levels);
  2054. if (miplevel >= anv_image_aux_levels(image, aspect)) {
  2055. /* There are no layers with auxiliary data because the miplevel has no
  2056. * auxiliary data.
  2057. */
  2058. return 0;
  2059. } else {
  2060. uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
  2061. return MAX2(image->planes[plane].aux_surface.isl.logical_level0_px.array_len,
  2062. image->planes[plane].aux_surface.isl.logical_level0_px.depth >> miplevel);
  2063. }
  2064. }
  2065. static inline unsigned
  2066. anv_fast_clear_state_entry_size(const struct anv_device *device)
  2067. {
  2068. assert(device);
  2069. /* Entry contents:
  2070. * +--------------------------------------------+
  2071. * | clear value dword(s) | needs resolve dword |
  2072. * +--------------------------------------------+
  2073. */
  2074. /* Ensure that the needs resolve dword is in fact dword-aligned to enable
  2075. * GPU memcpy operations.
  2076. */
  2077. assert(device->isl_dev.ss.clear_value_size % 4 == 0);
  2078. return device->isl_dev.ss.clear_value_size + 4;
  2079. }
  2080. static inline struct anv_address
  2081. anv_image_get_clear_color_addr(const struct anv_device *device,
  2082. const struct anv_image *image,
  2083. VkImageAspectFlagBits aspect,
  2084. unsigned level)
  2085. {
  2086. uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
  2087. return (struct anv_address) {
  2088. .bo = image->planes[plane].bo,
  2089. .offset = image->planes[plane].bo_offset +
  2090. image->planes[plane].fast_clear_state_offset +
  2091. anv_fast_clear_state_entry_size(device) * level,
  2092. };
  2093. }
  2094. static inline struct anv_address
  2095. anv_image_get_needs_resolve_addr(const struct anv_device *device,
  2096. const struct anv_image *image,
  2097. VkImageAspectFlagBits aspect,
  2098. unsigned level)
  2099. {
  2100. struct anv_address addr =
  2101. anv_image_get_clear_color_addr(device, image, aspect, level);
  2102. addr.offset += device->isl_dev.ss.clear_value_size;
  2103. return addr;
  2104. }
  2105. /* Returns true if a HiZ-enabled depth buffer can be sampled from. */
  2106. static inline bool
  2107. anv_can_sample_with_hiz(const struct gen_device_info * const devinfo,
  2108. const struct anv_image *image)
  2109. {
  2110. if (!(image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT))
  2111. return false;
  2112. if (devinfo->gen < 8)
  2113. return false;
  2114. return image->samples == 1;
  2115. }
  2116. void
  2117. anv_gen8_hiz_op_resolve(struct anv_cmd_buffer *cmd_buffer,
  2118. const struct anv_image *image,
  2119. enum blorp_hiz_op op);
  2120. void
  2121. anv_ccs_resolve(struct anv_cmd_buffer * const cmd_buffer,
  2122. const struct anv_image * const image,
  2123. VkImageAspectFlagBits aspect,
  2124. const uint8_t level,
  2125. const uint32_t start_layer, const uint32_t layer_count,
  2126. const enum blorp_fast_clear_op op);
  2127. void
  2128. anv_image_fast_clear(struct anv_cmd_buffer *cmd_buffer,
  2129. const struct anv_image *image,
  2130. VkImageAspectFlagBits aspect,
  2131. const uint32_t base_level, const uint32_t level_count,
  2132. const uint32_t base_layer, uint32_t layer_count);
  2133. void
  2134. anv_image_copy_to_shadow(struct anv_cmd_buffer *cmd_buffer,
  2135. const struct anv_image *image,
  2136. uint32_t base_level, uint32_t level_count,
  2137. uint32_t base_layer, uint32_t layer_count);
  2138. enum isl_aux_usage
  2139. anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
  2140. const struct anv_image *image,
  2141. const VkImageAspectFlagBits aspect,
  2142. const VkImageLayout layout);
  2143. /* This is defined as a macro so that it works for both
  2144. * VkImageSubresourceRange and VkImageSubresourceLayers
  2145. */
  2146. #define anv_get_layerCount(_image, _range) \
  2147. ((_range)->layerCount == VK_REMAINING_ARRAY_LAYERS ? \
  2148. (_image)->array_size - (_range)->baseArrayLayer : (_range)->layerCount)
  2149. static inline uint32_t
  2150. anv_get_levelCount(const struct anv_image *image,
  2151. const VkImageSubresourceRange *range)
  2152. {
  2153. return range->levelCount == VK_REMAINING_MIP_LEVELS ?
  2154. image->levels - range->baseMipLevel : range->levelCount;
  2155. }
  2156. static inline VkImageAspectFlags
  2157. anv_image_expand_aspects(const struct anv_image *image,
  2158. VkImageAspectFlags aspects)
  2159. {
  2160. /* If the underlying image has color plane aspects and
  2161. * VK_IMAGE_ASPECT_COLOR_BIT has been requested, then return the aspects of
  2162. * the underlying image. */
  2163. if ((image->aspects & VK_IMAGE_ASPECT_PLANES_BITS_ANV) != 0 &&
  2164. aspects == VK_IMAGE_ASPECT_COLOR_BIT)
  2165. return image->aspects;
  2166. return aspects;
  2167. }
  2168. static inline bool
  2169. anv_image_aspects_compatible(VkImageAspectFlags aspects1,
  2170. VkImageAspectFlags aspects2)
  2171. {
  2172. if (aspects1 == aspects2)
  2173. return true;
  2174. /* Only 1 color aspects are compatibles. */
  2175. if ((aspects1 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
  2176. (aspects2 & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) != 0 &&
  2177. _mesa_bitcount(aspects1) == _mesa_bitcount(aspects2))
  2178. return true;
  2179. return false;
  2180. }
  2181. struct anv_image_view {
  2182. const struct anv_image *image; /**< VkImageViewCreateInfo::image */
  2183. VkImageAspectFlags aspect_mask;
  2184. VkFormat vk_format;
  2185. VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
  2186. unsigned n_planes;
  2187. struct {
  2188. uint32_t image_plane;
  2189. struct isl_view isl;
  2190. /**
  2191. * RENDER_SURFACE_STATE when using image as a sampler surface with an
  2192. * image layout of SHADER_READ_ONLY_OPTIMAL or
  2193. * DEPTH_STENCIL_READ_ONLY_OPTIMAL.
  2194. */
  2195. struct anv_surface_state optimal_sampler_surface_state;
  2196. /**
  2197. * RENDER_SURFACE_STATE when using image as a sampler surface with an
  2198. * image layout of GENERAL.
  2199. */
  2200. struct anv_surface_state general_sampler_surface_state;
  2201. /**
  2202. * RENDER_SURFACE_STATE when using image as a storage image. Separate
  2203. * states for write-only and readable, using the real format for
  2204. * write-only and the lowered format for readable.
  2205. */
  2206. struct anv_surface_state storage_surface_state;
  2207. struct anv_surface_state writeonly_storage_surface_state;
  2208. struct brw_image_param storage_image_param;
  2209. } planes[3];
  2210. };
  2211. enum anv_image_view_state_flags {
  2212. ANV_IMAGE_VIEW_STATE_STORAGE_WRITE_ONLY = (1 << 0),
  2213. ANV_IMAGE_VIEW_STATE_TEXTURE_OPTIMAL = (1 << 1),
  2214. };
  2215. void anv_image_fill_surface_state(struct anv_device *device,
  2216. const struct anv_image *image,
  2217. VkImageAspectFlagBits aspect,
  2218. const struct isl_view *view,
  2219. isl_surf_usage_flags_t view_usage,
  2220. enum isl_aux_usage aux_usage,
  2221. const union isl_color_value *clear_color,
  2222. enum anv_image_view_state_flags flags,
  2223. struct anv_surface_state *state_inout,
  2224. struct brw_image_param *image_param_out);
  2225. struct anv_image_create_info {
  2226. const VkImageCreateInfo *vk_info;
  2227. /** An opt-in bitmask which filters an ISL-mapping of the Vulkan tiling. */
  2228. isl_tiling_flags_t isl_tiling_flags;
  2229. /** These flags will be added to any derived from VkImageCreateInfo. */
  2230. isl_surf_usage_flags_t isl_extra_usage_flags;
  2231. uint32_t stride;
  2232. };
  2233. VkResult anv_image_create(VkDevice _device,
  2234. const struct anv_image_create_info *info,
  2235. const VkAllocationCallbacks* alloc,
  2236. VkImage *pImage);
  2237. #ifdef ANDROID
  2238. VkResult anv_image_from_gralloc(VkDevice device_h,
  2239. const VkImageCreateInfo *base_info,
  2240. const VkNativeBufferANDROID *gralloc_info,
  2241. const VkAllocationCallbacks *alloc,
  2242. VkImage *pImage);
  2243. #endif
  2244. const struct anv_surface *
  2245. anv_image_get_surface_for_aspect_mask(const struct anv_image *image,
  2246. VkImageAspectFlags aspect_mask);
  2247. enum isl_format
  2248. anv_isl_format_for_descriptor_type(VkDescriptorType type);
  2249. static inline struct VkExtent3D
  2250. anv_sanitize_image_extent(const VkImageType imageType,
  2251. const struct VkExtent3D imageExtent)
  2252. {
  2253. switch (imageType) {
  2254. case VK_IMAGE_TYPE_1D:
  2255. return (VkExtent3D) { imageExtent.width, 1, 1 };
  2256. case VK_IMAGE_TYPE_2D:
  2257. return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
  2258. case VK_IMAGE_TYPE_3D:
  2259. return imageExtent;
  2260. default:
  2261. unreachable("invalid image type");
  2262. }
  2263. }
  2264. static inline struct VkOffset3D
  2265. anv_sanitize_image_offset(const VkImageType imageType,
  2266. const struct VkOffset3D imageOffset)
  2267. {
  2268. switch (imageType) {
  2269. case VK_IMAGE_TYPE_1D:
  2270. return (VkOffset3D) { imageOffset.x, 0, 0 };
  2271. case VK_IMAGE_TYPE_2D:
  2272. return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
  2273. case VK_IMAGE_TYPE_3D:
  2274. return imageOffset;
  2275. default:
  2276. unreachable("invalid image type");
  2277. }
  2278. }
  2279. void anv_fill_buffer_surface_state(struct anv_device *device,
  2280. struct anv_state state,
  2281. enum isl_format format,
  2282. uint32_t offset, uint32_t range,
  2283. uint32_t stride);
  2284. struct anv_ycbcr_conversion {
  2285. const struct anv_format * format;
  2286. VkSamplerYcbcrModelConversionKHR ycbcr_model;
  2287. VkSamplerYcbcrRangeKHR ycbcr_range;
  2288. VkComponentSwizzle mapping[4];
  2289. VkChromaLocationKHR chroma_offsets[2];
  2290. VkFilter chroma_filter;
  2291. bool chroma_reconstruction;
  2292. };
  2293. struct anv_sampler {
  2294. uint32_t state[3][4];
  2295. uint32_t n_planes;
  2296. struct anv_ycbcr_conversion *conversion;
  2297. };
  2298. struct anv_framebuffer {
  2299. uint32_t width;
  2300. uint32_t height;
  2301. uint32_t layers;
  2302. uint32_t attachment_count;
  2303. struct anv_image_view * attachments[0];
  2304. };
  2305. struct anv_subpass {
  2306. uint32_t attachment_count;
  2307. /**
  2308. * A pointer to all attachment references used in this subpass.
  2309. * Only valid if ::attachment_count > 0.
  2310. */
  2311. VkAttachmentReference * attachments;
  2312. uint32_t input_count;
  2313. VkAttachmentReference * input_attachments;
  2314. uint32_t color_count;
  2315. VkAttachmentReference * color_attachments;
  2316. VkAttachmentReference * resolve_attachments;
  2317. VkAttachmentReference depth_stencil_attachment;
  2318. uint32_t view_mask;
  2319. /** Subpass has a depth/stencil self-dependency */
  2320. bool has_ds_self_dep;
  2321. /** Subpass has at least one resolve attachment */
  2322. bool has_resolve;
  2323. };
  2324. static inline unsigned
  2325. anv_subpass_view_count(const struct anv_subpass *subpass)
  2326. {
  2327. return MAX2(1, _mesa_bitcount(subpass->view_mask));
  2328. }
  2329. struct anv_render_pass_attachment {
  2330. /* TODO: Consider using VkAttachmentDescription instead of storing each of
  2331. * its members individually.
  2332. */
  2333. VkFormat format;
  2334. uint32_t samples;
  2335. VkImageUsageFlags usage;
  2336. VkAttachmentLoadOp load_op;
  2337. VkAttachmentStoreOp store_op;
  2338. VkAttachmentLoadOp stencil_load_op;
  2339. VkImageLayout initial_layout;
  2340. VkImageLayout final_layout;
  2341. VkImageLayout first_subpass_layout;
  2342. /* The subpass id in which the attachment will be used last. */
  2343. uint32_t last_subpass_idx;
  2344. };
  2345. struct anv_render_pass {
  2346. uint32_t attachment_count;
  2347. uint32_t subpass_count;
  2348. /* An array of subpass_count+1 flushes, one per subpass boundary */
  2349. enum anv_pipe_bits * subpass_flushes;
  2350. struct anv_render_pass_attachment * attachments;
  2351. struct anv_subpass subpasses[0];
  2352. };
  2353. #define ANV_PIPELINE_STATISTICS_MASK 0x000007ff
  2354. struct anv_query_pool {
  2355. VkQueryType type;
  2356. VkQueryPipelineStatisticFlags pipeline_statistics;
  2357. /** Stride between slots, in bytes */
  2358. uint32_t stride;
  2359. /** Number of slots in this query pool */
  2360. uint32_t slots;
  2361. struct anv_bo bo;
  2362. };
  2363. int anv_get_entrypoint_index(const char *name);
  2364. void *anv_lookup_entrypoint(const struct gen_device_info *devinfo,
  2365. const char *name);
  2366. void anv_dump_image_to_ppm(struct anv_device *device,
  2367. struct anv_image *image, unsigned miplevel,
  2368. unsigned array_layer, VkImageAspectFlagBits aspect,
  2369. const char *filename);
  2370. enum anv_dump_action {
  2371. ANV_DUMP_FRAMEBUFFERS_BIT = 0x1,
  2372. };
  2373. void anv_dump_start(struct anv_device *device, enum anv_dump_action actions);
  2374. void anv_dump_finish(void);
  2375. void anv_dump_add_framebuffer(struct anv_cmd_buffer *cmd_buffer,
  2376. struct anv_framebuffer *fb);
  2377. static inline uint32_t
  2378. anv_get_subpass_id(const struct anv_cmd_state * const cmd_state)
  2379. {
  2380. /* This function must be called from within a subpass. */
  2381. assert(cmd_state->pass && cmd_state->subpass);
  2382. const uint32_t subpass_id = cmd_state->subpass - cmd_state->pass->subpasses;
  2383. /* The id of this subpass shouldn't exceed the number of subpasses in this
  2384. * render pass minus 1.
  2385. */
  2386. assert(subpass_id < cmd_state->pass->subpass_count);
  2387. return subpass_id;
  2388. }
  2389. #define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \
  2390. \
  2391. static inline struct __anv_type * \
  2392. __anv_type ## _from_handle(__VkType _handle) \
  2393. { \
  2394. return (struct __anv_type *) _handle; \
  2395. } \
  2396. \
  2397. static inline __VkType \
  2398. __anv_type ## _to_handle(struct __anv_type *_obj) \
  2399. { \
  2400. return (__VkType) _obj; \
  2401. }
  2402. #define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \
  2403. \
  2404. static inline struct __anv_type * \
  2405. __anv_type ## _from_handle(__VkType _handle) \
  2406. { \
  2407. return (struct __anv_type *)(uintptr_t) _handle; \
  2408. } \
  2409. \
  2410. static inline __VkType \
  2411. __anv_type ## _to_handle(struct __anv_type *_obj) \
  2412. { \
  2413. return (__VkType)(uintptr_t) _obj; \
  2414. }
  2415. #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \
  2416. struct __anv_type *__name = __anv_type ## _from_handle(__handle)
  2417. ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCommandBuffer)
  2418. ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
  2419. ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
  2420. ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
  2421. ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
  2422. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_cmd_pool, VkCommandPool)
  2423. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
  2424. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView)
  2425. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_pool, VkDescriptorPool)
  2426. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet)
  2427. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout)
  2428. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
  2429. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory)
  2430. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence)
  2431. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_event, VkEvent)
  2432. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer)
  2433. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage)
  2434. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView);
  2435. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_cache, VkPipelineCache)
  2436. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline)
  2437. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout)
  2438. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool)
  2439. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass)
  2440. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
  2441. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_semaphore, VkSemaphore)
  2442. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
  2443. ANV_DEFINE_NONDISP_HANDLE_CASTS(vk_debug_report_callback, VkDebugReportCallbackEXT)
  2444. ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_ycbcr_conversion, VkSamplerYcbcrConversionKHR)
  2445. /* Gen-specific function declarations */
  2446. #ifdef genX
  2447. # include "anv_genX.h"
  2448. #else
  2449. # define genX(x) gen7_##x
  2450. # include "anv_genX.h"
  2451. # undef genX
  2452. # define genX(x) gen75_##x
  2453. # include "anv_genX.h"
  2454. # undef genX
  2455. # define genX(x) gen8_##x
  2456. # include "anv_genX.h"
  2457. # undef genX
  2458. # define genX(x) gen9_##x
  2459. # include "anv_genX.h"
  2460. # undef genX
  2461. # define genX(x) gen10_##x
  2462. # include "anv_genX.h"
  2463. # undef genX
  2464. #endif
  2465. #endif /* ANV_PRIVATE_H */