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.

radv_private.h 63KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076
  1. /*
  2. * Copyright © 2016 Red Hat.
  3. * Copyright © 2016 Bas Nieuwenhuizen
  4. *
  5. * based in part on anv driver which is:
  6. * Copyright © 2015 Intel Corporation
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the next
  16. * paragraph) shall be included in all copies or substantial portions of the
  17. * Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  25. * IN THE SOFTWARE.
  26. */
  27. #ifndef RADV_PRIVATE_H
  28. #define RADV_PRIVATE_H
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <stdbool.h>
  32. #include <pthread.h>
  33. #include <assert.h>
  34. #include <stdint.h>
  35. #include <string.h>
  36. #ifdef HAVE_VALGRIND
  37. #include <valgrind.h>
  38. #include <memcheck.h>
  39. #define VG(x) x
  40. #else
  41. #define VG(x)
  42. #endif
  43. #include "c11/threads.h"
  44. #include <amdgpu.h>
  45. #include "compiler/shader_enums.h"
  46. #include "util/macros.h"
  47. #include "util/list.h"
  48. #include "util/xmlconfig.h"
  49. #include "main/macros.h"
  50. #include "vk_alloc.h"
  51. #include "vk_debug_report.h"
  52. #include "radv_radeon_winsys.h"
  53. #include "ac_binary.h"
  54. #include "ac_nir_to_llvm.h"
  55. #include "ac_gpu_info.h"
  56. #include "ac_surface.h"
  57. #include "ac_llvm_build.h"
  58. #include "ac_llvm_util.h"
  59. #include "radv_descriptor_set.h"
  60. #include "radv_extensions.h"
  61. #include "radv_cs.h"
  62. #include <llvm-c/TargetMachine.h>
  63. /* Pre-declarations needed for WSI entrypoints */
  64. struct wl_surface;
  65. struct wl_display;
  66. typedef struct xcb_connection_t xcb_connection_t;
  67. typedef uint32_t xcb_visualid_t;
  68. typedef uint32_t xcb_window_t;
  69. #include <vulkan/vulkan.h>
  70. #include <vulkan/vulkan_intel.h>
  71. #include <vulkan/vk_icd.h>
  72. #include <vulkan/vk_android_native_buffer.h>
  73. #include "radv_entrypoints.h"
  74. #include "wsi_common.h"
  75. #include "wsi_common_display.h"
  76. #define ATI_VENDOR_ID 0x1002
  77. #define MAX_VBS 32
  78. #define MAX_VERTEX_ATTRIBS 32
  79. #define MAX_RTS 8
  80. #define MAX_VIEWPORTS 16
  81. #define MAX_SCISSORS 16
  82. #define MAX_DISCARD_RECTANGLES 4
  83. #define MAX_PUSH_CONSTANTS_SIZE 128
  84. #define MAX_PUSH_DESCRIPTORS 32
  85. #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
  86. #define MAX_DYNAMIC_STORAGE_BUFFERS 8
  87. #define MAX_DYNAMIC_BUFFERS (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
  88. #define MAX_SAMPLES_LOG2 4
  89. #define NUM_META_FS_KEYS 12
  90. #define RADV_MAX_DRM_DEVICES 8
  91. #define MAX_VIEWS 8
  92. #define MAX_SO_STREAMS 4
  93. #define MAX_SO_BUFFERS 4
  94. #define MAX_SO_OUTPUTS 64
  95. #define MAX_INLINE_UNIFORM_BLOCK_SIZE (4ull * 1024 * 1024)
  96. #define MAX_INLINE_UNIFORM_BLOCK_COUNT 64
  97. #define NUM_DEPTH_CLEAR_PIPELINES 3
  98. /*
  99. * This is the point we switch from using CP to compute shader
  100. * for certain buffer operations.
  101. */
  102. #define RADV_BUFFER_OPS_CS_THRESHOLD 4096
  103. #define RADV_BUFFER_UPDATE_THRESHOLD 1024
  104. enum radv_mem_heap {
  105. RADV_MEM_HEAP_VRAM,
  106. RADV_MEM_HEAP_VRAM_CPU_ACCESS,
  107. RADV_MEM_HEAP_GTT,
  108. RADV_MEM_HEAP_COUNT
  109. };
  110. enum radv_mem_type {
  111. RADV_MEM_TYPE_VRAM,
  112. RADV_MEM_TYPE_GTT_WRITE_COMBINE,
  113. RADV_MEM_TYPE_VRAM_CPU_ACCESS,
  114. RADV_MEM_TYPE_GTT_CACHED,
  115. RADV_MEM_TYPE_COUNT
  116. };
  117. #define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
  118. static inline uint32_t
  119. align_u32(uint32_t v, uint32_t a)
  120. {
  121. assert(a != 0 && a == (a & -a));
  122. return (v + a - 1) & ~(a - 1);
  123. }
  124. static inline uint32_t
  125. align_u32_npot(uint32_t v, uint32_t a)
  126. {
  127. return (v + a - 1) / a * a;
  128. }
  129. static inline uint64_t
  130. align_u64(uint64_t v, uint64_t a)
  131. {
  132. assert(a != 0 && a == (a & -a));
  133. return (v + a - 1) & ~(a - 1);
  134. }
  135. static inline int32_t
  136. align_i32(int32_t v, int32_t a)
  137. {
  138. assert(a != 0 && a == (a & -a));
  139. return (v + a - 1) & ~(a - 1);
  140. }
  141. /** Alignment must be a power of 2. */
  142. static inline bool
  143. radv_is_aligned(uintmax_t n, uintmax_t a)
  144. {
  145. assert(a == (a & -a));
  146. return (n & (a - 1)) == 0;
  147. }
  148. static inline uint32_t
  149. round_up_u32(uint32_t v, uint32_t a)
  150. {
  151. return (v + a - 1) / a;
  152. }
  153. static inline uint64_t
  154. round_up_u64(uint64_t v, uint64_t a)
  155. {
  156. return (v + a - 1) / a;
  157. }
  158. static inline uint32_t
  159. radv_minify(uint32_t n, uint32_t levels)
  160. {
  161. if (unlikely(n == 0))
  162. return 0;
  163. else
  164. return MAX2(n >> levels, 1);
  165. }
  166. static inline float
  167. radv_clamp_f(float f, float min, float max)
  168. {
  169. assert(min < max);
  170. if (f > max)
  171. return max;
  172. else if (f < min)
  173. return min;
  174. else
  175. return f;
  176. }
  177. static inline bool
  178. radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
  179. {
  180. if (*inout_mask & clear_mask) {
  181. *inout_mask &= ~clear_mask;
  182. return true;
  183. } else {
  184. return false;
  185. }
  186. }
  187. #define for_each_bit(b, dword) \
  188. for (uint32_t __dword = (dword); \
  189. (b) = __builtin_ffs(__dword) - 1, __dword; \
  190. __dword &= ~(1 << (b)))
  191. #define typed_memcpy(dest, src, count) ({ \
  192. STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
  193. memcpy((dest), (src), (count) * sizeof(*(src))); \
  194. })
  195. /* Whenever we generate an error, pass it through this function. Useful for
  196. * debugging, where we can break on it. Only call at error site, not when
  197. * propagating errors. Might be useful to plug in a stack trace here.
  198. */
  199. struct radv_instance;
  200. VkResult __vk_errorf(struct radv_instance *instance, VkResult error, const char *file, int line, const char *format, ...);
  201. #define vk_error(instance, error) __vk_errorf(instance, error, __FILE__, __LINE__, NULL);
  202. #define vk_errorf(instance, error, format, ...) __vk_errorf(instance, error, __FILE__, __LINE__, format, ## __VA_ARGS__);
  203. void __radv_finishme(const char *file, int line, const char *format, ...)
  204. radv_printflike(3, 4);
  205. void radv_loge(const char *format, ...) radv_printflike(1, 2);
  206. void radv_loge_v(const char *format, va_list va);
  207. void radv_logi(const char *format, ...) radv_printflike(1, 2);
  208. void radv_logi_v(const char *format, va_list va);
  209. /**
  210. * Print a FINISHME message, including its source location.
  211. */
  212. #define radv_finishme(format, ...) \
  213. do { \
  214. static bool reported = false; \
  215. if (!reported) { \
  216. __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
  217. reported = true; \
  218. } \
  219. } while (0)
  220. /* A non-fatal assert. Useful for debugging. */
  221. #ifdef DEBUG
  222. #define radv_assert(x) ({ \
  223. if (unlikely(!(x))) \
  224. fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
  225. })
  226. #else
  227. #define radv_assert(x)
  228. #endif
  229. #define stub_return(v) \
  230. do { \
  231. radv_finishme("stub %s", __func__); \
  232. return (v); \
  233. } while (0)
  234. #define stub() \
  235. do { \
  236. radv_finishme("stub %s", __func__); \
  237. return; \
  238. } while (0)
  239. void *radv_lookup_entrypoint_unchecked(const char *name);
  240. void *radv_lookup_entrypoint_checked(const char *name,
  241. uint32_t core_version,
  242. const struct radv_instance_extension_table *instance,
  243. const struct radv_device_extension_table *device);
  244. struct radv_physical_device {
  245. VK_LOADER_DATA _loader_data;
  246. struct radv_instance * instance;
  247. struct radeon_winsys *ws;
  248. struct radeon_info rad_info;
  249. char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
  250. uint8_t driver_uuid[VK_UUID_SIZE];
  251. uint8_t device_uuid[VK_UUID_SIZE];
  252. uint8_t cache_uuid[VK_UUID_SIZE];
  253. int local_fd;
  254. int master_fd;
  255. struct wsi_device wsi_device;
  256. bool has_rbplus; /* if RB+ register exist */
  257. bool rbplus_allowed; /* if RB+ is allowed */
  258. bool has_clear_state;
  259. bool cpdma_prefetch_writes_memory;
  260. bool has_scissor_bug;
  261. bool has_out_of_order_rast;
  262. bool out_of_order_rast_allowed;
  263. /* Whether DCC should be enabled for MSAA textures. */
  264. bool dcc_msaa_allowed;
  265. /* Whether LOAD_CONTEXT_REG packets are supported. */
  266. bool has_load_ctx_reg_pkt;
  267. /* This is the drivers on-disk cache used as a fallback as opposed to
  268. * the pipeline cache defined by apps.
  269. */
  270. struct disk_cache * disk_cache;
  271. VkPhysicalDeviceMemoryProperties memory_properties;
  272. enum radv_mem_type mem_type_indices[RADV_MEM_TYPE_COUNT];
  273. drmPciBusInfo bus_info;
  274. struct radv_device_extension_table supported_extensions;
  275. };
  276. struct radv_instance {
  277. VK_LOADER_DATA _loader_data;
  278. VkAllocationCallbacks alloc;
  279. uint32_t apiVersion;
  280. int physicalDeviceCount;
  281. struct radv_physical_device physicalDevices[RADV_MAX_DRM_DEVICES];
  282. uint64_t debug_flags;
  283. uint64_t perftest_flags;
  284. struct vk_debug_report_instance debug_report_callbacks;
  285. struct radv_instance_extension_table enabled_extensions;
  286. struct driOptionCache dri_options;
  287. struct driOptionCache available_dri_options;
  288. };
  289. VkResult radv_init_wsi(struct radv_physical_device *physical_device);
  290. void radv_finish_wsi(struct radv_physical_device *physical_device);
  291. bool radv_instance_extension_supported(const char *name);
  292. uint32_t radv_physical_device_api_version(struct radv_physical_device *dev);
  293. bool radv_physical_device_extension_supported(struct radv_physical_device *dev,
  294. const char *name);
  295. struct cache_entry;
  296. struct radv_pipeline_cache {
  297. struct radv_device * device;
  298. pthread_mutex_t mutex;
  299. uint32_t total_size;
  300. uint32_t table_size;
  301. uint32_t kernel_count;
  302. struct cache_entry ** hash_table;
  303. bool modified;
  304. VkAllocationCallbacks alloc;
  305. };
  306. struct radv_pipeline_key {
  307. uint32_t instance_rate_inputs;
  308. uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];
  309. uint8_t vertex_attribute_formats[MAX_VERTEX_ATTRIBS];
  310. uint32_t vertex_attribute_bindings[MAX_VERTEX_ATTRIBS];
  311. uint32_t vertex_attribute_offsets[MAX_VERTEX_ATTRIBS];
  312. uint32_t vertex_attribute_strides[MAX_VERTEX_ATTRIBS];
  313. uint64_t vertex_alpha_adjust;
  314. uint32_t vertex_post_shuffle;
  315. unsigned tess_input_vertices;
  316. uint32_t col_format;
  317. uint32_t is_int8;
  318. uint32_t is_int10;
  319. uint8_t log2_ps_iter_samples;
  320. uint8_t num_samples;
  321. uint32_t has_multiview_view_index : 1;
  322. uint32_t optimisations_disabled : 1;
  323. };
  324. void
  325. radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
  326. struct radv_device *device);
  327. void
  328. radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
  329. bool
  330. radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
  331. const void *data, size_t size);
  332. struct radv_shader_variant;
  333. bool
  334. radv_create_shader_variants_from_pipeline_cache(struct radv_device *device,
  335. struct radv_pipeline_cache *cache,
  336. const unsigned char *sha1,
  337. struct radv_shader_variant **variants,
  338. bool *found_in_application_cache);
  339. void
  340. radv_pipeline_cache_insert_shaders(struct radv_device *device,
  341. struct radv_pipeline_cache *cache,
  342. const unsigned char *sha1,
  343. struct radv_shader_variant **variants,
  344. const void *const *codes,
  345. const unsigned *code_sizes);
  346. enum radv_blit_ds_layout {
  347. RADV_BLIT_DS_LAYOUT_TILE_ENABLE,
  348. RADV_BLIT_DS_LAYOUT_TILE_DISABLE,
  349. RADV_BLIT_DS_LAYOUT_COUNT,
  350. };
  351. static inline enum radv_blit_ds_layout radv_meta_blit_ds_to_type(VkImageLayout layout)
  352. {
  353. return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE : RADV_BLIT_DS_LAYOUT_TILE_ENABLE;
  354. }
  355. static inline VkImageLayout radv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)
  356. {
  357. return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
  358. }
  359. enum radv_meta_dst_layout {
  360. RADV_META_DST_LAYOUT_GENERAL,
  361. RADV_META_DST_LAYOUT_OPTIMAL,
  362. RADV_META_DST_LAYOUT_COUNT,
  363. };
  364. static inline enum radv_meta_dst_layout radv_meta_dst_layout_from_layout(VkImageLayout layout)
  365. {
  366. return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL : RADV_META_DST_LAYOUT_OPTIMAL;
  367. }
  368. static inline VkImageLayout radv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)
  369. {
  370. return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL : VK_IMAGE_LAYOUT_GENERAL;
  371. }
  372. struct radv_meta_state {
  373. VkAllocationCallbacks alloc;
  374. struct radv_pipeline_cache cache;
  375. /*
  376. * For on-demand pipeline creation, makes sure that
  377. * only one thread tries to build a pipeline at the same time.
  378. */
  379. mtx_t mtx;
  380. /**
  381. * Use array element `i` for images with `2^i` samples.
  382. */
  383. struct {
  384. VkRenderPass render_pass[NUM_META_FS_KEYS];
  385. VkPipeline color_pipelines[NUM_META_FS_KEYS];
  386. VkRenderPass depthstencil_rp;
  387. VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
  388. VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
  389. VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
  390. } clear[1 + MAX_SAMPLES_LOG2];
  391. VkPipelineLayout clear_color_p_layout;
  392. VkPipelineLayout clear_depth_p_layout;
  393. /* Optimized compute fast HTILE clear for stencil or depth only. */
  394. VkPipeline clear_htile_mask_pipeline;
  395. VkPipelineLayout clear_htile_mask_p_layout;
  396. VkDescriptorSetLayout clear_htile_mask_ds_layout;
  397. struct {
  398. VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
  399. /** Pipeline that blits from a 1D image. */
  400. VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
  401. /** Pipeline that blits from a 2D image. */
  402. VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
  403. /** Pipeline that blits from a 3D image. */
  404. VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
  405. VkRenderPass depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
  406. VkPipeline depth_only_1d_pipeline;
  407. VkPipeline depth_only_2d_pipeline;
  408. VkPipeline depth_only_3d_pipeline;
  409. VkRenderPass stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
  410. VkPipeline stencil_only_1d_pipeline;
  411. VkPipeline stencil_only_2d_pipeline;
  412. VkPipeline stencil_only_3d_pipeline;
  413. VkPipelineLayout pipeline_layout;
  414. VkDescriptorSetLayout ds_layout;
  415. } blit;
  416. struct {
  417. VkPipelineLayout p_layouts[5];
  418. VkDescriptorSetLayout ds_layouts[5];
  419. VkPipeline pipelines[5][NUM_META_FS_KEYS];
  420. VkPipeline depth_only_pipeline[5];
  421. VkPipeline stencil_only_pipeline[5];
  422. } blit2d[1 + MAX_SAMPLES_LOG2];
  423. VkRenderPass blit2d_render_passes[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
  424. VkRenderPass blit2d_depth_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
  425. VkRenderPass blit2d_stencil_only_rp[RADV_BLIT_DS_LAYOUT_COUNT];
  426. struct {
  427. VkPipelineLayout img_p_layout;
  428. VkDescriptorSetLayout img_ds_layout;
  429. VkPipeline pipeline;
  430. VkPipeline pipeline_3d;
  431. } itob;
  432. struct {
  433. VkPipelineLayout img_p_layout;
  434. VkDescriptorSetLayout img_ds_layout;
  435. VkPipeline pipeline;
  436. VkPipeline pipeline_3d;
  437. } btoi;
  438. struct {
  439. VkPipelineLayout img_p_layout;
  440. VkDescriptorSetLayout img_ds_layout;
  441. VkPipeline pipeline;
  442. } btoi_r32g32b32;
  443. struct {
  444. VkPipelineLayout img_p_layout;
  445. VkDescriptorSetLayout img_ds_layout;
  446. VkPipeline pipeline;
  447. VkPipeline pipeline_3d;
  448. } itoi;
  449. struct {
  450. VkPipelineLayout img_p_layout;
  451. VkDescriptorSetLayout img_ds_layout;
  452. VkPipeline pipeline;
  453. } itoi_r32g32b32;
  454. struct {
  455. VkPipelineLayout img_p_layout;
  456. VkDescriptorSetLayout img_ds_layout;
  457. VkPipeline pipeline;
  458. VkPipeline pipeline_3d;
  459. } cleari;
  460. struct {
  461. VkPipelineLayout img_p_layout;
  462. VkDescriptorSetLayout img_ds_layout;
  463. VkPipeline pipeline;
  464. } cleari_r32g32b32;
  465. struct {
  466. VkPipelineLayout p_layout;
  467. VkPipeline pipeline[NUM_META_FS_KEYS];
  468. VkRenderPass pass[NUM_META_FS_KEYS];
  469. } resolve;
  470. struct {
  471. VkDescriptorSetLayout ds_layout;
  472. VkPipelineLayout p_layout;
  473. struct {
  474. VkPipeline pipeline;
  475. VkPipeline i_pipeline;
  476. VkPipeline srgb_pipeline;
  477. } rc[MAX_SAMPLES_LOG2];
  478. } resolve_compute;
  479. struct {
  480. VkDescriptorSetLayout ds_layout;
  481. VkPipelineLayout p_layout;
  482. struct {
  483. VkRenderPass render_pass[NUM_META_FS_KEYS][RADV_META_DST_LAYOUT_COUNT];
  484. VkPipeline pipeline[NUM_META_FS_KEYS];
  485. } rc[MAX_SAMPLES_LOG2];
  486. } resolve_fragment;
  487. struct {
  488. VkPipelineLayout p_layout;
  489. VkPipeline decompress_pipeline;
  490. VkPipeline resummarize_pipeline;
  491. VkRenderPass pass;
  492. } depth_decomp[1 + MAX_SAMPLES_LOG2];
  493. struct {
  494. VkPipelineLayout p_layout;
  495. VkPipeline cmask_eliminate_pipeline;
  496. VkPipeline fmask_decompress_pipeline;
  497. VkPipeline dcc_decompress_pipeline;
  498. VkRenderPass pass;
  499. VkDescriptorSetLayout dcc_decompress_compute_ds_layout;
  500. VkPipelineLayout dcc_decompress_compute_p_layout;
  501. VkPipeline dcc_decompress_compute_pipeline;
  502. } fast_clear_flush;
  503. struct {
  504. VkPipelineLayout fill_p_layout;
  505. VkPipelineLayout copy_p_layout;
  506. VkDescriptorSetLayout fill_ds_layout;
  507. VkDescriptorSetLayout copy_ds_layout;
  508. VkPipeline fill_pipeline;
  509. VkPipeline copy_pipeline;
  510. } buffer;
  511. struct {
  512. VkDescriptorSetLayout ds_layout;
  513. VkPipelineLayout p_layout;
  514. VkPipeline occlusion_query_pipeline;
  515. VkPipeline pipeline_statistics_query_pipeline;
  516. VkPipeline tfb_query_pipeline;
  517. } query;
  518. struct {
  519. VkDescriptorSetLayout ds_layout;
  520. VkPipelineLayout p_layout;
  521. VkPipeline pipeline[MAX_SAMPLES_LOG2];
  522. } fmask_expand;
  523. };
  524. /* queue types */
  525. #define RADV_QUEUE_GENERAL 0
  526. #define RADV_QUEUE_COMPUTE 1
  527. #define RADV_QUEUE_TRANSFER 2
  528. #define RADV_MAX_QUEUE_FAMILIES 3
  529. enum ring_type radv_queue_family_to_ring(int f);
  530. struct radv_queue {
  531. VK_LOADER_DATA _loader_data;
  532. struct radv_device * device;
  533. struct radeon_winsys_ctx *hw_ctx;
  534. enum radeon_ctx_priority priority;
  535. uint32_t queue_family_index;
  536. int queue_idx;
  537. VkDeviceQueueCreateFlags flags;
  538. uint32_t scratch_size;
  539. uint32_t compute_scratch_size;
  540. uint32_t esgs_ring_size;
  541. uint32_t gsvs_ring_size;
  542. bool has_tess_rings;
  543. bool has_sample_positions;
  544. struct radeon_winsys_bo *scratch_bo;
  545. struct radeon_winsys_bo *descriptor_bo;
  546. struct radeon_winsys_bo *compute_scratch_bo;
  547. struct radeon_winsys_bo *esgs_ring_bo;
  548. struct radeon_winsys_bo *gsvs_ring_bo;
  549. struct radeon_winsys_bo *tess_rings_bo;
  550. struct radeon_cmdbuf *initial_preamble_cs;
  551. struct radeon_cmdbuf *initial_full_flush_preamble_cs;
  552. struct radeon_cmdbuf *continue_preamble_cs;
  553. };
  554. struct radv_bo_list {
  555. struct radv_winsys_bo_list list;
  556. unsigned capacity;
  557. pthread_mutex_t mutex;
  558. };
  559. struct radv_device {
  560. VK_LOADER_DATA _loader_data;
  561. VkAllocationCallbacks alloc;
  562. struct radv_instance * instance;
  563. struct radeon_winsys *ws;
  564. struct radv_meta_state meta_state;
  565. struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
  566. int queue_count[RADV_MAX_QUEUE_FAMILIES];
  567. struct radeon_cmdbuf *empty_cs[RADV_MAX_QUEUE_FAMILIES];
  568. bool always_use_syncobj;
  569. bool has_distributed_tess;
  570. bool pbb_allowed;
  571. bool dfsm_allowed;
  572. uint32_t tess_offchip_block_dw_size;
  573. uint32_t scratch_waves;
  574. uint32_t dispatch_initiator;
  575. uint32_t gs_table_depth;
  576. /* MSAA sample locations.
  577. * The first index is the sample index.
  578. * The second index is the coordinate: X, Y. */
  579. float sample_locations_1x[1][2];
  580. float sample_locations_2x[2][2];
  581. float sample_locations_4x[4][2];
  582. float sample_locations_8x[8][2];
  583. float sample_locations_16x[16][2];
  584. /* CIK and later */
  585. uint32_t gfx_init_size_dw;
  586. struct radeon_winsys_bo *gfx_init;
  587. struct radeon_winsys_bo *trace_bo;
  588. uint32_t *trace_id_ptr;
  589. /* Whether to keep shader debug info, for tracing or VK_AMD_shader_info */
  590. bool keep_shader_info;
  591. struct radv_physical_device *physical_device;
  592. /* Backup in-memory cache to be used if the app doesn't provide one */
  593. struct radv_pipeline_cache * mem_cache;
  594. /*
  595. * use different counters so MSAA MRTs get consecutive surface indices,
  596. * even if MASK is allocated in between.
  597. */
  598. uint32_t image_mrt_offset_counter;
  599. uint32_t fmask_mrt_offset_counter;
  600. struct list_head shader_slabs;
  601. mtx_t shader_slab_mutex;
  602. /* For detecting VM faults reported by dmesg. */
  603. uint64_t dmesg_timestamp;
  604. struct radv_device_extension_table enabled_extensions;
  605. /* Whether the driver uses a global BO list. */
  606. bool use_global_bo_list;
  607. struct radv_bo_list bo_list;
  608. /* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */
  609. int force_aniso;
  610. };
  611. struct radv_device_memory {
  612. struct radeon_winsys_bo *bo;
  613. /* for dedicated allocations */
  614. struct radv_image *image;
  615. struct radv_buffer *buffer;
  616. uint32_t type_index;
  617. VkDeviceSize map_size;
  618. void * map;
  619. void * user_ptr;
  620. };
  621. struct radv_descriptor_range {
  622. uint64_t va;
  623. uint32_t size;
  624. };
  625. struct radv_descriptor_set {
  626. const struct radv_descriptor_set_layout *layout;
  627. uint32_t size;
  628. struct radeon_winsys_bo *bo;
  629. uint64_t va;
  630. uint32_t *mapped_ptr;
  631. struct radv_descriptor_range *dynamic_descriptors;
  632. struct radeon_winsys_bo *descriptors[0];
  633. };
  634. struct radv_push_descriptor_set
  635. {
  636. struct radv_descriptor_set set;
  637. uint32_t capacity;
  638. };
  639. struct radv_descriptor_pool_entry {
  640. uint32_t offset;
  641. uint32_t size;
  642. struct radv_descriptor_set *set;
  643. };
  644. struct radv_descriptor_pool {
  645. struct radeon_winsys_bo *bo;
  646. uint8_t *mapped_ptr;
  647. uint64_t current_offset;
  648. uint64_t size;
  649. uint8_t *host_memory_base;
  650. uint8_t *host_memory_ptr;
  651. uint8_t *host_memory_end;
  652. uint32_t entry_count;
  653. uint32_t max_entry_count;
  654. struct radv_descriptor_pool_entry entries[0];
  655. };
  656. struct radv_descriptor_update_template_entry {
  657. VkDescriptorType descriptor_type;
  658. /* The number of descriptors to update */
  659. uint32_t descriptor_count;
  660. /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
  661. uint32_t dst_offset;
  662. /* In dwords. Not valid/used for dynamic descriptors */
  663. uint32_t dst_stride;
  664. uint32_t buffer_offset;
  665. /* Only valid for combined image samplers and samplers */
  666. uint8_t has_sampler;
  667. uint8_t sampler_offset;
  668. /* In bytes */
  669. size_t src_offset;
  670. size_t src_stride;
  671. /* For push descriptors */
  672. const uint32_t *immutable_samplers;
  673. };
  674. struct radv_descriptor_update_template {
  675. uint32_t entry_count;
  676. VkPipelineBindPoint bind_point;
  677. struct radv_descriptor_update_template_entry entry[0];
  678. };
  679. struct radv_buffer {
  680. VkDeviceSize size;
  681. VkBufferUsageFlags usage;
  682. VkBufferCreateFlags flags;
  683. /* Set when bound */
  684. struct radeon_winsys_bo * bo;
  685. VkDeviceSize offset;
  686. bool shareable;
  687. };
  688. enum radv_dynamic_state_bits {
  689. RADV_DYNAMIC_VIEWPORT = 1 << 0,
  690. RADV_DYNAMIC_SCISSOR = 1 << 1,
  691. RADV_DYNAMIC_LINE_WIDTH = 1 << 2,
  692. RADV_DYNAMIC_DEPTH_BIAS = 1 << 3,
  693. RADV_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
  694. RADV_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
  695. RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
  696. RADV_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
  697. RADV_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
  698. RADV_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
  699. RADV_DYNAMIC_ALL = (1 << 10) - 1,
  700. };
  701. enum radv_cmd_dirty_bits {
  702. /* Keep the dynamic state dirty bits in sync with
  703. * enum radv_dynamic_state_bits */
  704. RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0,
  705. RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1,
  706. RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2,
  707. RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3,
  708. RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4,
  709. RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5,
  710. RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6,
  711. RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7,
  712. RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8,
  713. RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1 << 9,
  714. RADV_CMD_DIRTY_DYNAMIC_ALL = (1 << 10) - 1,
  715. RADV_CMD_DIRTY_PIPELINE = 1 << 10,
  716. RADV_CMD_DIRTY_INDEX_BUFFER = 1 << 11,
  717. RADV_CMD_DIRTY_FRAMEBUFFER = 1 << 12,
  718. RADV_CMD_DIRTY_VERTEX_BUFFER = 1 << 13,
  719. RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1 << 14,
  720. };
  721. enum radv_cmd_flush_bits {
  722. RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
  723. /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
  724. RADV_CMD_FLAG_INV_SMEM_L1 = 1 << 1,
  725. /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
  726. RADV_CMD_FLAG_INV_VMEM_L1 = 1 << 2,
  727. /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
  728. RADV_CMD_FLAG_INV_GLOBAL_L2 = 1 << 3,
  729. /* Same as above, but only writes back and doesn't invalidate */
  730. RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2 = 1 << 4,
  731. /* Framebuffer caches */
  732. RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 5,
  733. RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 6,
  734. RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 7,
  735. RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 8,
  736. /* Engine synchronization. */
  737. RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 9,
  738. RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 10,
  739. RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 11,
  740. RADV_CMD_FLAG_VGT_FLUSH = 1 << 12,
  741. /* Pipeline query controls. */
  742. RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 13,
  743. RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 14,
  744. RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 15,
  745. RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER = (RADV_CMD_FLAG_FLUSH_AND_INV_CB |
  746. RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
  747. RADV_CMD_FLAG_FLUSH_AND_INV_DB |
  748. RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
  749. };
  750. struct radv_vertex_binding {
  751. struct radv_buffer * buffer;
  752. VkDeviceSize offset;
  753. };
  754. struct radv_streamout_binding {
  755. struct radv_buffer *buffer;
  756. VkDeviceSize offset;
  757. VkDeviceSize size;
  758. };
  759. struct radv_streamout_state {
  760. /* Mask of bound streamout buffers. */
  761. uint8_t enabled_mask;
  762. /* External state that comes from the last vertex stage, it must be
  763. * set explicitely when binding a new graphics pipeline.
  764. */
  765. uint16_t stride_in_dw[MAX_SO_BUFFERS];
  766. uint32_t enabled_stream_buffers_mask; /* stream0 buffers0-3 in 4 LSB */
  767. /* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */
  768. uint32_t hw_enabled_mask;
  769. /* State of VGT_STRMOUT_(CONFIG|EN) */
  770. bool streamout_enabled;
  771. };
  772. struct radv_viewport_state {
  773. uint32_t count;
  774. VkViewport viewports[MAX_VIEWPORTS];
  775. };
  776. struct radv_scissor_state {
  777. uint32_t count;
  778. VkRect2D scissors[MAX_SCISSORS];
  779. };
  780. struct radv_discard_rectangle_state {
  781. uint32_t count;
  782. VkRect2D rectangles[MAX_DISCARD_RECTANGLES];
  783. };
  784. struct radv_dynamic_state {
  785. /**
  786. * Bitmask of (1 << VK_DYNAMIC_STATE_*).
  787. * Defines the set of saved dynamic state.
  788. */
  789. uint32_t mask;
  790. struct radv_viewport_state viewport;
  791. struct radv_scissor_state scissor;
  792. float line_width;
  793. struct {
  794. float bias;
  795. float clamp;
  796. float slope;
  797. } depth_bias;
  798. float blend_constants[4];
  799. struct {
  800. float min;
  801. float max;
  802. } depth_bounds;
  803. struct {
  804. uint32_t front;
  805. uint32_t back;
  806. } stencil_compare_mask;
  807. struct {
  808. uint32_t front;
  809. uint32_t back;
  810. } stencil_write_mask;
  811. struct {
  812. uint32_t front;
  813. uint32_t back;
  814. } stencil_reference;
  815. struct radv_discard_rectangle_state discard_rectangle;
  816. };
  817. extern const struct radv_dynamic_state default_dynamic_state;
  818. const char *
  819. radv_get_debug_option_name(int id);
  820. const char *
  821. radv_get_perftest_option_name(int id);
  822. /**
  823. * Attachment state when recording a renderpass instance.
  824. *
  825. * The clear value is valid only if there exists a pending clear.
  826. */
  827. struct radv_attachment_state {
  828. VkImageAspectFlags pending_clear_aspects;
  829. uint32_t cleared_views;
  830. VkClearValue clear_value;
  831. VkImageLayout current_layout;
  832. };
  833. struct radv_descriptor_state {
  834. struct radv_descriptor_set *sets[MAX_SETS];
  835. uint32_t dirty;
  836. uint32_t valid;
  837. struct radv_push_descriptor_set push_set;
  838. bool push_dirty;
  839. uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
  840. };
  841. struct radv_cmd_state {
  842. /* Vertex descriptors */
  843. uint64_t vb_va;
  844. unsigned vb_size;
  845. bool predicating;
  846. uint32_t dirty;
  847. uint32_t prefetch_L2_mask;
  848. struct radv_pipeline * pipeline;
  849. struct radv_pipeline * emitted_pipeline;
  850. struct radv_pipeline * compute_pipeline;
  851. struct radv_pipeline * emitted_compute_pipeline;
  852. struct radv_framebuffer * framebuffer;
  853. struct radv_render_pass * pass;
  854. const struct radv_subpass * subpass;
  855. struct radv_dynamic_state dynamic;
  856. struct radv_attachment_state * attachments;
  857. struct radv_streamout_state streamout;
  858. VkRect2D render_area;
  859. /* Index buffer */
  860. struct radv_buffer *index_buffer;
  861. uint64_t index_offset;
  862. uint32_t index_type;
  863. uint32_t max_index_count;
  864. uint64_t index_va;
  865. int32_t last_index_type;
  866. int32_t last_primitive_reset_en;
  867. uint32_t last_primitive_reset_index;
  868. enum radv_cmd_flush_bits flush_bits;
  869. unsigned active_occlusion_queries;
  870. bool perfect_occlusion_queries_enabled;
  871. unsigned active_pipeline_queries;
  872. float offset_scale;
  873. uint32_t trace_id;
  874. uint32_t last_ia_multi_vgt_param;
  875. uint32_t last_num_instances;
  876. uint32_t last_first_instance;
  877. uint32_t last_vertex_offset;
  878. /* Whether CP DMA is busy/idle. */
  879. bool dma_is_busy;
  880. /* Conditional rendering info. */
  881. int predication_type; /* -1: disabled, 0: normal, 1: inverted */
  882. uint64_t predication_va;
  883. bool context_roll_without_scissor_emitted;
  884. };
  885. struct radv_cmd_pool {
  886. VkAllocationCallbacks alloc;
  887. struct list_head cmd_buffers;
  888. struct list_head free_cmd_buffers;
  889. uint32_t queue_family_index;
  890. };
  891. struct radv_cmd_buffer_upload {
  892. uint8_t *map;
  893. unsigned offset;
  894. uint64_t size;
  895. struct radeon_winsys_bo *upload_bo;
  896. struct list_head list;
  897. };
  898. enum radv_cmd_buffer_status {
  899. RADV_CMD_BUFFER_STATUS_INVALID,
  900. RADV_CMD_BUFFER_STATUS_INITIAL,
  901. RADV_CMD_BUFFER_STATUS_RECORDING,
  902. RADV_CMD_BUFFER_STATUS_EXECUTABLE,
  903. RADV_CMD_BUFFER_STATUS_PENDING,
  904. };
  905. struct radv_cmd_buffer {
  906. VK_LOADER_DATA _loader_data;
  907. struct radv_device * device;
  908. struct radv_cmd_pool * pool;
  909. struct list_head pool_link;
  910. VkCommandBufferUsageFlags usage_flags;
  911. VkCommandBufferLevel level;
  912. enum radv_cmd_buffer_status status;
  913. struct radeon_cmdbuf *cs;
  914. struct radv_cmd_state state;
  915. struct radv_vertex_binding vertex_bindings[MAX_VBS];
  916. struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
  917. uint32_t queue_family_index;
  918. uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
  919. VkShaderStageFlags push_constant_stages;
  920. struct radv_descriptor_set meta_push_descriptors;
  921. struct radv_descriptor_state descriptors[VK_PIPELINE_BIND_POINT_RANGE_SIZE];
  922. struct radv_cmd_buffer_upload upload;
  923. uint32_t scratch_size_needed;
  924. uint32_t compute_scratch_size_needed;
  925. uint32_t esgs_ring_size_needed;
  926. uint32_t gsvs_ring_size_needed;
  927. bool tess_rings_needed;
  928. bool sample_positions_needed;
  929. VkResult record_result;
  930. uint64_t gfx9_fence_va;
  931. uint32_t gfx9_fence_idx;
  932. uint64_t gfx9_eop_bug_va;
  933. /**
  934. * Whether a query pool has been resetted and we have to flush caches.
  935. */
  936. bool pending_reset_query;
  937. };
  938. struct radv_image;
  939. bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
  940. void si_emit_graphics(struct radv_physical_device *physical_device,
  941. struct radeon_cmdbuf *cs);
  942. void si_emit_compute(struct radv_physical_device *physical_device,
  943. struct radeon_cmdbuf *cs);
  944. void cik_create_gfx_config(struct radv_device *device);
  945. void si_write_viewport(struct radeon_cmdbuf *cs, int first_vp,
  946. int count, const VkViewport *viewports);
  947. void si_write_scissors(struct radeon_cmdbuf *cs, int first,
  948. int count, const VkRect2D *scissors,
  949. const VkViewport *viewports, bool can_use_guardband);
  950. uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer,
  951. bool instanced_draw, bool indirect_draw,
  952. bool count_from_stream_output,
  953. uint32_t draw_vertex_count);
  954. void si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs,
  955. enum chip_class chip_class,
  956. bool is_mec,
  957. unsigned event, unsigned event_flags,
  958. unsigned data_sel,
  959. uint64_t va,
  960. uint32_t new_fence,
  961. uint64_t gfx9_eop_bug_va);
  962. void radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va,
  963. uint32_t ref, uint32_t mask);
  964. void si_cs_emit_cache_flush(struct radeon_cmdbuf *cs,
  965. enum chip_class chip_class,
  966. uint32_t *fence_ptr, uint64_t va,
  967. bool is_mec,
  968. enum radv_cmd_flush_bits flush_bits,
  969. uint64_t gfx9_eop_bug_va);
  970. void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
  971. void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer,
  972. bool inverted, uint64_t va);
  973. void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer,
  974. uint64_t src_va, uint64_t dest_va,
  975. uint64_t size);
  976. void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
  977. unsigned size);
  978. void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
  979. uint64_t size, unsigned value);
  980. void si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);
  981. void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
  982. bool
  983. radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer,
  984. unsigned size,
  985. unsigned alignment,
  986. unsigned *out_offset,
  987. void **ptr);
  988. void
  989. radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
  990. const struct radv_subpass *subpass);
  991. bool
  992. radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer,
  993. unsigned size, unsigned alignmnet,
  994. const void *data, unsigned *out_offset);
  995. void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
  996. void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
  997. void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
  998. void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
  999. void radv_cayman_emit_msaa_sample_locs(struct radeon_cmdbuf *cs, int nr_samples);
  1000. unsigned radv_cayman_get_maxdist(int log_samples);
  1001. void radv_device_init_msaa(struct radv_device *device);
  1002. void radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
  1003. struct radv_image *image,
  1004. VkClearDepthStencilValue ds_clear_value,
  1005. VkImageAspectFlags aspects);
  1006. void radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
  1007. struct radv_image *image,
  1008. int cb_idx,
  1009. uint32_t color_values[2]);
  1010. void radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer,
  1011. struct radv_image *image, bool value);
  1012. void radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer,
  1013. struct radv_image *image, bool value);
  1014. uint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
  1015. struct radeon_winsys_bo *bo,
  1016. uint64_t offset, uint64_t size, uint32_t value);
  1017. void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
  1018. bool radv_get_memory_fd(struct radv_device *device,
  1019. struct radv_device_memory *memory,
  1020. int *pFD);
  1021. static inline void
  1022. radv_emit_shader_pointer_head(struct radeon_cmdbuf *cs,
  1023. unsigned sh_offset, unsigned pointer_count,
  1024. bool use_32bit_pointers)
  1025. {
  1026. radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));
  1027. radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);
  1028. }
  1029. static inline void
  1030. radv_emit_shader_pointer_body(struct radv_device *device,
  1031. struct radeon_cmdbuf *cs,
  1032. uint64_t va, bool use_32bit_pointers)
  1033. {
  1034. radeon_emit(cs, va);
  1035. if (use_32bit_pointers) {
  1036. assert(va == 0 ||
  1037. (va >> 32) == device->physical_device->rad_info.address32_hi);
  1038. } else {
  1039. radeon_emit(cs, va >> 32);
  1040. }
  1041. }
  1042. static inline void
  1043. radv_emit_shader_pointer(struct radv_device *device,
  1044. struct radeon_cmdbuf *cs,
  1045. uint32_t sh_offset, uint64_t va, bool global)
  1046. {
  1047. bool use_32bit_pointers = !global;
  1048. radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);
  1049. radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);
  1050. }
  1051. static inline struct radv_descriptor_state *
  1052. radv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer,
  1053. VkPipelineBindPoint bind_point)
  1054. {
  1055. assert(bind_point == VK_PIPELINE_BIND_POINT_GRAPHICS ||
  1056. bind_point == VK_PIPELINE_BIND_POINT_COMPUTE);
  1057. return &cmd_buffer->descriptors[bind_point];
  1058. }
  1059. /*
  1060. * Takes x,y,z as exact numbers of invocations, instead of blocks.
  1061. *
  1062. * Limitations: Can't call normal dispatch functions without binding or rebinding
  1063. * the compute pipeline.
  1064. */
  1065. void radv_unaligned_dispatch(
  1066. struct radv_cmd_buffer *cmd_buffer,
  1067. uint32_t x,
  1068. uint32_t y,
  1069. uint32_t z);
  1070. struct radv_event {
  1071. struct radeon_winsys_bo *bo;
  1072. uint64_t *map;
  1073. };
  1074. struct radv_shader_module;
  1075. #define RADV_HASH_SHADER_IS_GEOM_COPY_SHADER (1 << 0)
  1076. #define RADV_HASH_SHADER_SISCHED (1 << 1)
  1077. #define RADV_HASH_SHADER_UNSAFE_MATH (1 << 2)
  1078. void
  1079. radv_hash_shaders(unsigned char *hash,
  1080. const VkPipelineShaderStageCreateInfo **stages,
  1081. const struct radv_pipeline_layout *layout,
  1082. const struct radv_pipeline_key *key,
  1083. uint32_t flags);
  1084. static inline gl_shader_stage
  1085. vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
  1086. {
  1087. assert(__builtin_popcount(vk_stage) == 1);
  1088. return ffs(vk_stage) - 1;
  1089. }
  1090. static inline VkShaderStageFlagBits
  1091. mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
  1092. {
  1093. return (1 << mesa_stage);
  1094. }
  1095. #define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
  1096. #define radv_foreach_stage(stage, stage_bits) \
  1097. for (gl_shader_stage stage, \
  1098. __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
  1099. stage = __builtin_ffs(__tmp) - 1, __tmp; \
  1100. __tmp &= ~(1 << (stage)))
  1101. extern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
  1102. unsigned radv_format_meta_fs_key(VkFormat format);
  1103. struct radv_multisample_state {
  1104. uint32_t db_eqaa;
  1105. uint32_t pa_sc_line_cntl;
  1106. uint32_t pa_sc_mode_cntl_0;
  1107. uint32_t pa_sc_mode_cntl_1;
  1108. uint32_t pa_sc_aa_config;
  1109. uint32_t pa_sc_aa_mask[2];
  1110. unsigned num_samples;
  1111. };
  1112. struct radv_prim_vertex_count {
  1113. uint8_t min;
  1114. uint8_t incr;
  1115. };
  1116. struct radv_vertex_elements_info {
  1117. uint32_t format_size[MAX_VERTEX_ATTRIBS];
  1118. };
  1119. struct radv_ia_multi_vgt_param_helpers {
  1120. uint32_t base;
  1121. bool partial_es_wave;
  1122. uint8_t primgroup_size;
  1123. bool wd_switch_on_eop;
  1124. bool ia_switch_on_eoi;
  1125. bool partial_vs_wave;
  1126. };
  1127. #define SI_GS_PER_ES 128
  1128. struct radv_pipeline {
  1129. struct radv_device * device;
  1130. struct radv_dynamic_state dynamic_state;
  1131. struct radv_pipeline_layout * layout;
  1132. bool need_indirect_descriptor_sets;
  1133. struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
  1134. struct radv_shader_variant *gs_copy_shader;
  1135. VkShaderStageFlags active_stages;
  1136. struct radeon_cmdbuf cs;
  1137. uint32_t ctx_cs_hash;
  1138. struct radeon_cmdbuf ctx_cs;
  1139. struct radv_vertex_elements_info vertex_elements;
  1140. uint32_t binding_stride[MAX_VBS];
  1141. uint8_t num_vertex_bindings;
  1142. uint32_t user_data_0[MESA_SHADER_STAGES];
  1143. union {
  1144. struct {
  1145. struct radv_multisample_state ms;
  1146. uint32_t spi_baryc_cntl;
  1147. bool prim_restart_enable;
  1148. unsigned esgs_ring_size;
  1149. unsigned gsvs_ring_size;
  1150. uint32_t vtx_base_sgpr;
  1151. struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
  1152. uint8_t vtx_emit_num;
  1153. struct radv_prim_vertex_count prim_vertex_count;
  1154. bool can_use_guardband;
  1155. uint32_t needed_dynamic_state;
  1156. bool disable_out_of_order_rast_for_occlusion;
  1157. /* Used for rbplus */
  1158. uint32_t col_format;
  1159. uint32_t cb_target_mask;
  1160. } graphics;
  1161. };
  1162. unsigned max_waves;
  1163. unsigned scratch_bytes_per_wave;
  1164. /* Not NULL if graphics pipeline uses streamout. */
  1165. struct radv_shader_variant *streamout_shader;
  1166. };
  1167. static inline bool radv_pipeline_has_gs(const struct radv_pipeline *pipeline)
  1168. {
  1169. return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
  1170. }
  1171. static inline bool radv_pipeline_has_tess(const struct radv_pipeline *pipeline)
  1172. {
  1173. return pipeline->shaders[MESA_SHADER_TESS_CTRL] ? true : false;
  1174. }
  1175. struct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
  1176. gl_shader_stage stage,
  1177. int idx);
  1178. struct radv_shader_variant *radv_get_shader(struct radv_pipeline *pipeline,
  1179. gl_shader_stage stage);
  1180. struct radv_graphics_pipeline_create_info {
  1181. bool use_rectlist;
  1182. bool db_depth_clear;
  1183. bool db_stencil_clear;
  1184. bool db_depth_disable_expclear;
  1185. bool db_stencil_disable_expclear;
  1186. bool db_flush_depth_inplace;
  1187. bool db_flush_stencil_inplace;
  1188. bool db_resummarize;
  1189. uint32_t custom_blend_mode;
  1190. };
  1191. VkResult
  1192. radv_graphics_pipeline_create(VkDevice device,
  1193. VkPipelineCache cache,
  1194. const VkGraphicsPipelineCreateInfo *pCreateInfo,
  1195. const struct radv_graphics_pipeline_create_info *extra,
  1196. const VkAllocationCallbacks *alloc,
  1197. VkPipeline *pPipeline);
  1198. struct vk_format_description;
  1199. uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
  1200. int first_non_void);
  1201. uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
  1202. int first_non_void);
  1203. uint32_t radv_translate_colorformat(VkFormat format);
  1204. uint32_t radv_translate_color_numformat(VkFormat format,
  1205. const struct vk_format_description *desc,
  1206. int first_non_void);
  1207. uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
  1208. unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
  1209. uint32_t radv_translate_dbformat(VkFormat format);
  1210. uint32_t radv_translate_tex_dataformat(VkFormat format,
  1211. const struct vk_format_description *desc,
  1212. int first_non_void);
  1213. uint32_t radv_translate_tex_numformat(VkFormat format,
  1214. const struct vk_format_description *desc,
  1215. int first_non_void);
  1216. bool radv_format_pack_clear_color(VkFormat format,
  1217. uint32_t clear_vals[2],
  1218. VkClearColorValue *value);
  1219. bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
  1220. bool radv_dcc_formats_compatible(VkFormat format1,
  1221. VkFormat format2);
  1222. bool radv_device_supports_etc(struct radv_physical_device *physical_device);
  1223. struct radv_fmask_info {
  1224. uint64_t offset;
  1225. uint64_t size;
  1226. unsigned alignment;
  1227. unsigned pitch_in_pixels;
  1228. unsigned bank_height;
  1229. unsigned slice_tile_max;
  1230. unsigned tile_mode_index;
  1231. unsigned tile_swizzle;
  1232. };
  1233. struct radv_cmask_info {
  1234. uint64_t offset;
  1235. uint64_t size;
  1236. unsigned alignment;
  1237. unsigned slice_tile_max;
  1238. };
  1239. struct radv_image_plane {
  1240. VkFormat format;
  1241. struct radeon_surf surface;
  1242. uint64_t offset;
  1243. };
  1244. struct radv_image {
  1245. VkImageType type;
  1246. /* The original VkFormat provided by the client. This may not match any
  1247. * of the actual surface formats.
  1248. */
  1249. VkFormat vk_format;
  1250. VkImageAspectFlags aspects;
  1251. VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
  1252. struct ac_surf_info info;
  1253. VkImageTiling tiling; /** VkImageCreateInfo::tiling */
  1254. VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
  1255. VkDeviceSize size;
  1256. uint32_t alignment;
  1257. unsigned queue_family_mask;
  1258. bool exclusive;
  1259. bool shareable;
  1260. /* Set when bound */
  1261. struct radeon_winsys_bo *bo;
  1262. VkDeviceSize offset;
  1263. uint64_t dcc_offset;
  1264. uint64_t htile_offset;
  1265. bool tc_compatible_htile;
  1266. struct radv_fmask_info fmask;
  1267. struct radv_cmask_info cmask;
  1268. uint64_t clear_value_offset;
  1269. uint64_t fce_pred_offset;
  1270. uint64_t dcc_pred_offset;
  1271. /*
  1272. * Metadata for the TC-compat zrange workaround. If the 32-bit value
  1273. * stored at this offset is UINT_MAX, the driver will emit
  1274. * DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
  1275. * SET_CONTEXT_REG packet.
  1276. */
  1277. uint64_t tc_compat_zrange_offset;
  1278. /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
  1279. VkDeviceMemory owned_memory;
  1280. unsigned plane_count;
  1281. struct radv_image_plane planes[0];
  1282. };
  1283. /* Whether the image has a htile that is known consistent with the contents of
  1284. * the image. */
  1285. bool radv_layout_has_htile(const struct radv_image *image,
  1286. VkImageLayout layout,
  1287. unsigned queue_mask);
  1288. /* Whether the image has a htile that is known consistent with the contents of
  1289. * the image and is allowed to be in compressed form.
  1290. *
  1291. * If this is false reads that don't use the htile should be able to return
  1292. * correct results.
  1293. */
  1294. bool radv_layout_is_htile_compressed(const struct radv_image *image,
  1295. VkImageLayout layout,
  1296. unsigned queue_mask);
  1297. bool radv_layout_can_fast_clear(const struct radv_image *image,
  1298. VkImageLayout layout,
  1299. unsigned queue_mask);
  1300. bool radv_layout_dcc_compressed(const struct radv_image *image,
  1301. VkImageLayout layout,
  1302. unsigned queue_mask);
  1303. /**
  1304. * Return whether the image has CMASK metadata for color surfaces.
  1305. */
  1306. static inline bool
  1307. radv_image_has_cmask(const struct radv_image *image)
  1308. {
  1309. return image->cmask.size;
  1310. }
  1311. /**
  1312. * Return whether the image has FMASK metadata for color surfaces.
  1313. */
  1314. static inline bool
  1315. radv_image_has_fmask(const struct radv_image *image)
  1316. {
  1317. return image->fmask.size;
  1318. }
  1319. /**
  1320. * Return whether the image has DCC metadata for color surfaces.
  1321. */
  1322. static inline bool
  1323. radv_image_has_dcc(const struct radv_image *image)
  1324. {
  1325. return image->planes[0].surface.dcc_size;
  1326. }
  1327. /**
  1328. * Return whether DCC metadata is enabled for a level.
  1329. */
  1330. static inline bool
  1331. radv_dcc_enabled(const struct radv_image *image, unsigned level)
  1332. {
  1333. return radv_image_has_dcc(image) &&
  1334. level < image->planes[0].surface.num_dcc_levels;
  1335. }
  1336. /**
  1337. * Return whether the image has CB metadata.
  1338. */
  1339. static inline bool
  1340. radv_image_has_CB_metadata(const struct radv_image *image)
  1341. {
  1342. return radv_image_has_cmask(image) ||
  1343. radv_image_has_fmask(image) ||
  1344. radv_image_has_dcc(image);
  1345. }
  1346. /**
  1347. * Return whether the image has HTILE metadata for depth surfaces.
  1348. */
  1349. static inline bool
  1350. radv_image_has_htile(const struct radv_image *image)
  1351. {
  1352. return image->planes[0].surface.htile_size;
  1353. }
  1354. /**
  1355. * Return whether HTILE metadata is enabled for a level.
  1356. */
  1357. static inline bool
  1358. radv_htile_enabled(const struct radv_image *image, unsigned level)
  1359. {
  1360. return radv_image_has_htile(image) && level == 0;
  1361. }
  1362. /**
  1363. * Return whether the image is TC-compatible HTILE.
  1364. */
  1365. static inline bool
  1366. radv_image_is_tc_compat_htile(const struct radv_image *image)
  1367. {
  1368. return radv_image_has_htile(image) && image->tc_compatible_htile;
  1369. }
  1370. unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
  1371. static inline uint32_t
  1372. radv_get_layerCount(const struct radv_image *image,
  1373. const VkImageSubresourceRange *range)
  1374. {
  1375. return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
  1376. image->info.array_size - range->baseArrayLayer : range->layerCount;
  1377. }
  1378. static inline uint32_t
  1379. radv_get_levelCount(const struct radv_image *image,
  1380. const VkImageSubresourceRange *range)
  1381. {
  1382. return range->levelCount == VK_REMAINING_MIP_LEVELS ?
  1383. image->info.levels - range->baseMipLevel : range->levelCount;
  1384. }
  1385. struct radeon_bo_metadata;
  1386. void
  1387. radv_init_metadata(struct radv_device *device,
  1388. struct radv_image *image,
  1389. struct radeon_bo_metadata *metadata);
  1390. void
  1391. radv_image_override_offset_stride(struct radv_device *device,
  1392. struct radv_image *image,
  1393. uint64_t offset, uint32_t stride);
  1394. union radv_descriptor {
  1395. struct {
  1396. uint32_t plane0_descriptor[8];
  1397. uint32_t fmask_descriptor[8];
  1398. };
  1399. struct {
  1400. uint32_t plane_descriptors[3][8];
  1401. };
  1402. };
  1403. struct radv_image_view {
  1404. struct radv_image *image; /**< VkImageViewCreateInfo::image */
  1405. struct radeon_winsys_bo *bo;
  1406. VkImageViewType type;
  1407. VkImageAspectFlags aspect_mask;
  1408. VkFormat vk_format;
  1409. unsigned plane_id;
  1410. bool multiple_planes;
  1411. uint32_t base_layer;
  1412. uint32_t layer_count;
  1413. uint32_t base_mip;
  1414. uint32_t level_count;
  1415. VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
  1416. union radv_descriptor descriptor;
  1417. /* Descriptor for use as a storage image as opposed to a sampled image.
  1418. * This has a few differences for cube maps (e.g. type).
  1419. */
  1420. union radv_descriptor storage_descriptor;
  1421. };
  1422. struct radv_image_create_info {
  1423. const VkImageCreateInfo *vk_info;
  1424. bool scanout;
  1425. bool no_metadata_planes;
  1426. };
  1427. VkResult radv_image_create(VkDevice _device,
  1428. const struct radv_image_create_info *info,
  1429. const VkAllocationCallbacks* alloc,
  1430. VkImage *pImage);
  1431. VkResult
  1432. radv_image_from_gralloc(VkDevice device_h,
  1433. const VkImageCreateInfo *base_info,
  1434. const VkNativeBufferANDROID *gralloc_info,
  1435. const VkAllocationCallbacks *alloc,
  1436. VkImage *out_image_h);
  1437. void radv_image_view_init(struct radv_image_view *view,
  1438. struct radv_device *device,
  1439. const VkImageViewCreateInfo* pCreateInfo);
  1440. VkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
  1441. struct radv_sampler_ycbcr_conversion {
  1442. VkFormat format;
  1443. VkSamplerYcbcrModelConversion ycbcr_model;
  1444. VkSamplerYcbcrRange ycbcr_range;
  1445. VkComponentMapping components;
  1446. VkChromaLocation chroma_offsets[2];
  1447. VkFilter chroma_filter;
  1448. };
  1449. struct radv_buffer_view {
  1450. struct radeon_winsys_bo *bo;
  1451. VkFormat vk_format;
  1452. uint64_t range; /**< VkBufferViewCreateInfo::range */
  1453. uint32_t state[4];
  1454. };
  1455. void radv_buffer_view_init(struct radv_buffer_view *view,
  1456. struct radv_device *device,
  1457. const VkBufferViewCreateInfo* pCreateInfo);
  1458. static inline struct VkExtent3D
  1459. radv_sanitize_image_extent(const VkImageType imageType,
  1460. const struct VkExtent3D imageExtent)
  1461. {
  1462. switch (imageType) {
  1463. case VK_IMAGE_TYPE_1D:
  1464. return (VkExtent3D) { imageExtent.width, 1, 1 };
  1465. case VK_IMAGE_TYPE_2D:
  1466. return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
  1467. case VK_IMAGE_TYPE_3D:
  1468. return imageExtent;
  1469. default:
  1470. unreachable("invalid image type");
  1471. }
  1472. }
  1473. static inline struct VkOffset3D
  1474. radv_sanitize_image_offset(const VkImageType imageType,
  1475. const struct VkOffset3D imageOffset)
  1476. {
  1477. switch (imageType) {
  1478. case VK_IMAGE_TYPE_1D:
  1479. return (VkOffset3D) { imageOffset.x, 0, 0 };
  1480. case VK_IMAGE_TYPE_2D:
  1481. return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
  1482. case VK_IMAGE_TYPE_3D:
  1483. return imageOffset;
  1484. default:
  1485. unreachable("invalid image type");
  1486. }
  1487. }
  1488. static inline bool
  1489. radv_image_extent_compare(const struct radv_image *image,
  1490. const VkExtent3D *extent)
  1491. {
  1492. if (extent->width != image->info.width ||
  1493. extent->height != image->info.height ||
  1494. extent->depth != image->info.depth)
  1495. return false;
  1496. return true;
  1497. }
  1498. struct radv_sampler {
  1499. uint32_t state[4];
  1500. struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
  1501. };
  1502. struct radv_color_buffer_info {
  1503. uint64_t cb_color_base;
  1504. uint64_t cb_color_cmask;
  1505. uint64_t cb_color_fmask;
  1506. uint64_t cb_dcc_base;
  1507. uint32_t cb_color_slice;
  1508. uint32_t cb_color_view;
  1509. uint32_t cb_color_info;
  1510. uint32_t cb_color_attrib;
  1511. uint32_t cb_color_attrib2;
  1512. uint32_t cb_dcc_control;
  1513. uint32_t cb_color_cmask_slice;
  1514. uint32_t cb_color_fmask_slice;
  1515. union {
  1516. uint32_t cb_color_pitch; // GFX6-GFX8
  1517. uint32_t cb_mrt_epitch; // GFX9+
  1518. };
  1519. };
  1520. struct radv_ds_buffer_info {
  1521. uint64_t db_z_read_base;
  1522. uint64_t db_stencil_read_base;
  1523. uint64_t db_z_write_base;
  1524. uint64_t db_stencil_write_base;
  1525. uint64_t db_htile_data_base;
  1526. uint32_t db_depth_info;
  1527. uint32_t db_z_info;
  1528. uint32_t db_stencil_info;
  1529. uint32_t db_depth_view;
  1530. uint32_t db_depth_size;
  1531. uint32_t db_depth_slice;
  1532. uint32_t db_htile_surface;
  1533. uint32_t pa_su_poly_offset_db_fmt_cntl;
  1534. uint32_t db_z_info2;
  1535. uint32_t db_stencil_info2;
  1536. float offset_scale;
  1537. };
  1538. struct radv_attachment_info {
  1539. union {
  1540. struct radv_color_buffer_info cb;
  1541. struct radv_ds_buffer_info ds;
  1542. };
  1543. struct radv_image_view *attachment;
  1544. };
  1545. struct radv_framebuffer {
  1546. uint32_t width;
  1547. uint32_t height;
  1548. uint32_t layers;
  1549. uint32_t attachment_count;
  1550. struct radv_attachment_info attachments[0];
  1551. };
  1552. struct radv_subpass_barrier {
  1553. VkPipelineStageFlags src_stage_mask;
  1554. VkAccessFlags src_access_mask;
  1555. VkAccessFlags dst_access_mask;
  1556. };
  1557. void radv_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
  1558. const struct radv_subpass_barrier *barrier);
  1559. struct radv_subpass_attachment {
  1560. uint32_t attachment;
  1561. VkImageLayout layout;
  1562. };
  1563. struct radv_subpass {
  1564. uint32_t attachment_count;
  1565. struct radv_subpass_attachment * attachments;
  1566. uint32_t input_count;
  1567. uint32_t color_count;
  1568. struct radv_subpass_attachment * input_attachments;
  1569. struct radv_subpass_attachment * color_attachments;
  1570. struct radv_subpass_attachment * resolve_attachments;
  1571. struct radv_subpass_attachment * depth_stencil_attachment;
  1572. /** Subpass has at least one resolve attachment */
  1573. bool has_resolve;
  1574. /** Subpass has at least one color attachment */
  1575. bool has_color_att;
  1576. struct radv_subpass_barrier start_barrier;
  1577. uint32_t view_mask;
  1578. VkSampleCountFlagBits max_sample_count;
  1579. };
  1580. struct radv_render_pass_attachment {
  1581. VkFormat format;
  1582. uint32_t samples;
  1583. VkAttachmentLoadOp load_op;
  1584. VkAttachmentLoadOp stencil_load_op;
  1585. VkImageLayout initial_layout;
  1586. VkImageLayout final_layout;
  1587. /* The subpass id in which the attachment will be used last. */
  1588. uint32_t last_subpass_idx;
  1589. };
  1590. struct radv_render_pass {
  1591. uint32_t attachment_count;
  1592. uint32_t subpass_count;
  1593. struct radv_subpass_attachment * subpass_attachments;
  1594. struct radv_render_pass_attachment * attachments;
  1595. struct radv_subpass_barrier end_barrier;
  1596. struct radv_subpass subpasses[0];
  1597. };
  1598. VkResult radv_device_init_meta(struct radv_device *device);
  1599. void radv_device_finish_meta(struct radv_device *device);
  1600. struct radv_query_pool {
  1601. struct radeon_winsys_bo *bo;
  1602. uint32_t stride;
  1603. uint32_t availability_offset;
  1604. uint64_t size;
  1605. char *ptr;
  1606. VkQueryType type;
  1607. uint32_t pipeline_stats_mask;
  1608. };
  1609. struct radv_semaphore {
  1610. /* use a winsys sem for non-exportable */
  1611. struct radeon_winsys_sem *sem;
  1612. uint32_t syncobj;
  1613. uint32_t temp_syncobj;
  1614. };
  1615. void radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
  1616. VkPipelineBindPoint bind_point,
  1617. struct radv_descriptor_set *set,
  1618. unsigned idx);
  1619. void
  1620. radv_update_descriptor_sets(struct radv_device *device,
  1621. struct radv_cmd_buffer *cmd_buffer,
  1622. VkDescriptorSet overrideSet,
  1623. uint32_t descriptorWriteCount,
  1624. const VkWriteDescriptorSet *pDescriptorWrites,
  1625. uint32_t descriptorCopyCount,
  1626. const VkCopyDescriptorSet *pDescriptorCopies);
  1627. void
  1628. radv_update_descriptor_set_with_template(struct radv_device *device,
  1629. struct radv_cmd_buffer *cmd_buffer,
  1630. struct radv_descriptor_set *set,
  1631. VkDescriptorUpdateTemplate descriptorUpdateTemplate,
  1632. const void *pData);
  1633. void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
  1634. VkPipelineBindPoint pipelineBindPoint,
  1635. VkPipelineLayout _layout,
  1636. uint32_t set,
  1637. uint32_t descriptorWriteCount,
  1638. const VkWriteDescriptorSet *pDescriptorWrites);
  1639. void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
  1640. struct radv_image *image, uint32_t value);
  1641. void radv_initialize_fmask(struct radv_cmd_buffer *cmd_buffer,
  1642. struct radv_image *image);
  1643. struct radv_fence {
  1644. struct radeon_winsys_fence *fence;
  1645. struct wsi_fence *fence_wsi;
  1646. bool submitted;
  1647. bool signalled;
  1648. uint32_t syncobj;
  1649. uint32_t temp_syncobj;
  1650. };
  1651. /* radv_nir_to_llvm.c */
  1652. struct radv_shader_variant_info;
  1653. struct radv_nir_compiler_options;
  1654. void radv_compile_gs_copy_shader(struct ac_llvm_compiler *ac_llvm,
  1655. struct nir_shader *geom_shader,
  1656. struct ac_shader_binary *binary,
  1657. struct ac_shader_config *config,
  1658. struct radv_shader_variant_info *shader_info,
  1659. const struct radv_nir_compiler_options *option);
  1660. void radv_compile_nir_shader(struct ac_llvm_compiler *ac_llvm,
  1661. struct ac_shader_binary *binary,
  1662. struct ac_shader_config *config,
  1663. struct radv_shader_variant_info *shader_info,
  1664. struct nir_shader *const *nir,
  1665. int nir_count,
  1666. const struct radv_nir_compiler_options *options);
  1667. unsigned radv_nir_get_max_workgroup_size(enum chip_class chip_class,
  1668. const struct nir_shader *nir);
  1669. /* radv_shader_info.h */
  1670. struct radv_shader_info;
  1671. void radv_nir_shader_info_pass(const struct nir_shader *nir,
  1672. const struct radv_nir_compiler_options *options,
  1673. struct radv_shader_info *info);
  1674. void radv_nir_shader_info_init(struct radv_shader_info *info);
  1675. struct radeon_winsys_sem;
  1676. uint64_t radv_get_current_time(void);
  1677. #define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
  1678. \
  1679. static inline struct __radv_type * \
  1680. __radv_type ## _from_handle(__VkType _handle) \
  1681. { \
  1682. return (struct __radv_type *) _handle; \
  1683. } \
  1684. \
  1685. static inline __VkType \
  1686. __radv_type ## _to_handle(struct __radv_type *_obj) \
  1687. { \
  1688. return (__VkType) _obj; \
  1689. }
  1690. #define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
  1691. \
  1692. static inline struct __radv_type * \
  1693. __radv_type ## _from_handle(__VkType _handle) \
  1694. { \
  1695. return (struct __radv_type *)(uintptr_t) _handle; \
  1696. } \
  1697. \
  1698. static inline __VkType \
  1699. __radv_type ## _to_handle(struct __radv_type *_obj) \
  1700. { \
  1701. return (__VkType)(uintptr_t) _obj; \
  1702. }
  1703. #define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
  1704. struct __radv_type *__name = __radv_type ## _from_handle(__handle)
  1705. RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
  1706. RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
  1707. RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
  1708. RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
  1709. RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
  1710. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
  1711. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
  1712. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
  1713. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
  1714. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
  1715. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
  1716. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplate)
  1717. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
  1718. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
  1719. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
  1720. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
  1721. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
  1722. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
  1723. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
  1724. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
  1725. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
  1726. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
  1727. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
  1728. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
  1729. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, VkSamplerYcbcrConversion)
  1730. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
  1731. RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
  1732. #endif /* RADV_PRIVATE_H */