1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat.
3bf215546Sopenharmony_ci * Copyright © 2016 Bas Nieuwenhuizen
4bf215546Sopenharmony_ci *
5bf215546Sopenharmony_ci * based in part on anv driver which is:
6bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation
7bf215546Sopenharmony_ci *
8bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
9bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
10bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
11bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
13bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
16bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
17bf215546Sopenharmony_ci * Software.
18bf215546Sopenharmony_ci *
19bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25bf215546Sopenharmony_ci * IN THE SOFTWARE.
26bf215546Sopenharmony_ci */
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#ifndef RADV_PRIVATE_H
29bf215546Sopenharmony_ci#define RADV_PRIVATE_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include <assert.h>
32bf215546Sopenharmony_ci#include <stdbool.h>
33bf215546Sopenharmony_ci#include <stdint.h>
34bf215546Sopenharmony_ci#include <stdio.h>
35bf215546Sopenharmony_ci#include <stdlib.h>
36bf215546Sopenharmony_ci#include <string.h>
37bf215546Sopenharmony_ci#ifdef HAVE_VALGRIND
38bf215546Sopenharmony_ci#include <memcheck.h>
39bf215546Sopenharmony_ci#include <valgrind.h>
40bf215546Sopenharmony_ci#define VG(x) x
41bf215546Sopenharmony_ci#else
42bf215546Sopenharmony_ci#define VG(x) ((void)0)
43bf215546Sopenharmony_ci#endif
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci#include "c11/threads.h"
46bf215546Sopenharmony_ci#ifndef _WIN32
47bf215546Sopenharmony_ci#include <amdgpu.h>
48bf215546Sopenharmony_ci#include <xf86drm.h>
49bf215546Sopenharmony_ci#endif
50bf215546Sopenharmony_ci#include "compiler/shader_enums.h"
51bf215546Sopenharmony_ci#include "util/bitscan.h"
52bf215546Sopenharmony_ci#include "util/list.h"
53bf215546Sopenharmony_ci#include "util/macros.h"
54bf215546Sopenharmony_ci#include "util/rwlock.h"
55bf215546Sopenharmony_ci#include "util/xmlconfig.h"
56bf215546Sopenharmony_ci#include "vk_alloc.h"
57bf215546Sopenharmony_ci#include "vk_buffer.h"
58bf215546Sopenharmony_ci#include "vk_command_buffer.h"
59bf215546Sopenharmony_ci#include "vk_command_pool.h"
60bf215546Sopenharmony_ci#include "vk_debug_report.h"
61bf215546Sopenharmony_ci#include "vk_device.h"
62bf215546Sopenharmony_ci#include "vk_format.h"
63bf215546Sopenharmony_ci#include "vk_instance.h"
64bf215546Sopenharmony_ci#include "vk_log.h"
65bf215546Sopenharmony_ci#include "vk_physical_device.h"
66bf215546Sopenharmony_ci#include "vk_shader_module.h"
67bf215546Sopenharmony_ci#include "vk_queue.h"
68bf215546Sopenharmony_ci#include "vk_util.h"
69bf215546Sopenharmony_ci#include "vk_image.h"
70bf215546Sopenharmony_ci#include "vk_framebuffer.h"
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci#include "ac_binary.h"
73bf215546Sopenharmony_ci#include "ac_gpu_info.h"
74bf215546Sopenharmony_ci#include "ac_shader_util.h"
75bf215546Sopenharmony_ci#include "ac_spm.h"
76bf215546Sopenharmony_ci#include "ac_sqtt.h"
77bf215546Sopenharmony_ci#include "ac_surface.h"
78bf215546Sopenharmony_ci#include "radv_constants.h"
79bf215546Sopenharmony_ci#include "radv_descriptor_set.h"
80bf215546Sopenharmony_ci#include "radv_radeon_winsys.h"
81bf215546Sopenharmony_ci#include "radv_shader.h"
82bf215546Sopenharmony_ci#include "radv_shader_args.h"
83bf215546Sopenharmony_ci#include "sid.h"
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci#include "radix_sort/radix_sort_vk_devaddr.h"
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci/* Pre-declarations needed for WSI entrypoints */
88bf215546Sopenharmony_cistruct wl_surface;
89bf215546Sopenharmony_cistruct wl_display;
90bf215546Sopenharmony_citypedef struct xcb_connection_t xcb_connection_t;
91bf215546Sopenharmony_citypedef uint32_t xcb_visualid_t;
92bf215546Sopenharmony_citypedef uint32_t xcb_window_t;
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci#include <vulkan/vk_android_native_buffer.h>
95bf215546Sopenharmony_ci#include <vulkan/vk_icd.h>
96bf215546Sopenharmony_ci#include <vulkan/vulkan.h>
97bf215546Sopenharmony_ci#include <vulkan/vulkan_android.h>
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci#include "radv_entrypoints.h"
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci#include "wsi_common.h"
102bf215546Sopenharmony_ci
103bf215546Sopenharmony_ci#ifdef __cplusplus
104bf215546Sopenharmony_ciextern "C"
105bf215546Sopenharmony_ci{
106bf215546Sopenharmony_ci#endif
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci/* Helper to determine if we should compile
109bf215546Sopenharmony_ci * any of the Android AHB support.
110bf215546Sopenharmony_ci *
111bf215546Sopenharmony_ci * To actually enable the ext we also need
112bf215546Sopenharmony_ci * the necessary kernel support.
113bf215546Sopenharmony_ci */
114bf215546Sopenharmony_ci#if defined(ANDROID) && ANDROID_API_LEVEL >= 26
115bf215546Sopenharmony_ci#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 1
116bf215546Sopenharmony_ci#include <vndk/hardware_buffer.h>
117bf215546Sopenharmony_ci#else
118bf215546Sopenharmony_ci#define RADV_SUPPORT_ANDROID_HARDWARE_BUFFER 0
119bf215546Sopenharmony_ci#endif
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci#ifdef _WIN32
122bf215546Sopenharmony_ci#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 0
123bf215546Sopenharmony_ci#else
124bf215546Sopenharmony_ci#define RADV_SUPPORT_CALIBRATED_TIMESTAMPS 1
125bf215546Sopenharmony_ci#endif
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci#ifdef _WIN32
128bf215546Sopenharmony_ci#define radv_printflike(a, b)
129bf215546Sopenharmony_ci#else
130bf215546Sopenharmony_ci#define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
131bf215546Sopenharmony_ci#endif
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_cistatic inline uint32_t
134bf215546Sopenharmony_cialign_u32(uint32_t v, uint32_t a)
135bf215546Sopenharmony_ci{
136bf215546Sopenharmony_ci   assert(a != 0 && a == (a & -a));
137bf215546Sopenharmony_ci   return (v + a - 1) & ~(a - 1);
138bf215546Sopenharmony_ci}
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_cistatic inline uint32_t
141bf215546Sopenharmony_cialign_u32_npot(uint32_t v, uint32_t a)
142bf215546Sopenharmony_ci{
143bf215546Sopenharmony_ci   return (v + a - 1) / a * a;
144bf215546Sopenharmony_ci}
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_cistatic inline uint64_t
147bf215546Sopenharmony_cialign_u64(uint64_t v, uint64_t a)
148bf215546Sopenharmony_ci{
149bf215546Sopenharmony_ci   assert(a != 0 && a == (a & -a));
150bf215546Sopenharmony_ci   return (v + a - 1) & ~(a - 1);
151bf215546Sopenharmony_ci}
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_cistatic inline int32_t
154bf215546Sopenharmony_cialign_i32(int32_t v, int32_t a)
155bf215546Sopenharmony_ci{
156bf215546Sopenharmony_ci   assert(a != 0 && a == (a & -a));
157bf215546Sopenharmony_ci   return (v + a - 1) & ~(a - 1);
158bf215546Sopenharmony_ci}
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci/** Alignment must be a power of 2. */
161bf215546Sopenharmony_cistatic inline bool
162bf215546Sopenharmony_ciradv_is_aligned(uintmax_t n, uintmax_t a)
163bf215546Sopenharmony_ci{
164bf215546Sopenharmony_ci   assert(a == (a & -a));
165bf215546Sopenharmony_ci   return (n & (a - 1)) == 0;
166bf215546Sopenharmony_ci}
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_cistatic inline uint32_t
169bf215546Sopenharmony_ciround_up_u32(uint32_t v, uint32_t a)
170bf215546Sopenharmony_ci{
171bf215546Sopenharmony_ci   return (v + a - 1) / a;
172bf215546Sopenharmony_ci}
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_cistatic inline uint64_t
175bf215546Sopenharmony_ciround_up_u64(uint64_t v, uint64_t a)
176bf215546Sopenharmony_ci{
177bf215546Sopenharmony_ci   return (v + a - 1) / a;
178bf215546Sopenharmony_ci}
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_cistatic inline uint32_t
181bf215546Sopenharmony_ciradv_minify(uint32_t n, uint32_t levels)
182bf215546Sopenharmony_ci{
183bf215546Sopenharmony_ci   if (unlikely(n == 0))
184bf215546Sopenharmony_ci      return 0;
185bf215546Sopenharmony_ci   else
186bf215546Sopenharmony_ci      return MAX2(n >> levels, 1);
187bf215546Sopenharmony_ci}
188bf215546Sopenharmony_cistatic inline float
189bf215546Sopenharmony_ciradv_clamp_f(float f, float min, float max)
190bf215546Sopenharmony_ci{
191bf215546Sopenharmony_ci   assert(min < max);
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_ci   if (f > max)
194bf215546Sopenharmony_ci      return max;
195bf215546Sopenharmony_ci   else if (f < min)
196bf215546Sopenharmony_ci      return min;
197bf215546Sopenharmony_ci   else
198bf215546Sopenharmony_ci      return f;
199bf215546Sopenharmony_ci}
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_cistatic inline bool
202bf215546Sopenharmony_ciradv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
203bf215546Sopenharmony_ci{
204bf215546Sopenharmony_ci   if (*inout_mask & clear_mask) {
205bf215546Sopenharmony_ci      *inout_mask &= ~clear_mask;
206bf215546Sopenharmony_ci      return true;
207bf215546Sopenharmony_ci   } else {
208bf215546Sopenharmony_ci      return false;
209bf215546Sopenharmony_ci   }
210bf215546Sopenharmony_ci}
211bf215546Sopenharmony_ci
212bf215546Sopenharmony_cistatic inline int
213bf215546Sopenharmony_ciradv_float_to_sfixed(float value, unsigned frac_bits)
214bf215546Sopenharmony_ci{
215bf215546Sopenharmony_ci   return value * (1 << frac_bits);
216bf215546Sopenharmony_ci}
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_cistatic inline unsigned int
219bf215546Sopenharmony_ciradv_float_to_ufixed(float value, unsigned frac_bits)
220bf215546Sopenharmony_ci{
221bf215546Sopenharmony_ci   return value * (1 << frac_bits);
222bf215546Sopenharmony_ci}
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci/* Whenever we generate an error, pass it through this function. Useful for
225bf215546Sopenharmony_ci * debugging, where we can break on it. Only call at error site, not when
226bf215546Sopenharmony_ci * propagating errors. Might be useful to plug in a stack trace here.
227bf215546Sopenharmony_ci */
228bf215546Sopenharmony_ci
229bf215546Sopenharmony_cistruct radv_image_view;
230bf215546Sopenharmony_cistruct radv_instance;
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ci/* A non-fatal assert.  Useful for debugging. */
233bf215546Sopenharmony_ci#ifdef NDEBUG
234bf215546Sopenharmony_ci#define radv_assert(x)                                                                             \
235bf215546Sopenharmony_ci   do {                                                                                            \
236bf215546Sopenharmony_ci   } while (0)
237bf215546Sopenharmony_ci#else
238bf215546Sopenharmony_ci#define radv_assert(x)                                                                             \
239bf215546Sopenharmony_ci   do {                                                                                            \
240bf215546Sopenharmony_ci      if (unlikely(!(x)))                                                                          \
241bf215546Sopenharmony_ci         fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x);                            \
242bf215546Sopenharmony_ci   } while (0)
243bf215546Sopenharmony_ci#endif
244bf215546Sopenharmony_ci
245bf215546Sopenharmony_ciint radv_get_instance_entrypoint_index(const char *name);
246bf215546Sopenharmony_ciint radv_get_device_entrypoint_index(const char *name);
247bf215546Sopenharmony_ciint radv_get_physical_device_entrypoint_index(const char *name);
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_ciconst char *radv_get_instance_entry_name(int index);
250bf215546Sopenharmony_ciconst char *radv_get_physical_device_entry_name(int index);
251bf215546Sopenharmony_ciconst char *radv_get_device_entry_name(int index);
252bf215546Sopenharmony_ci
253bf215546Sopenharmony_ci/* queue types */
254bf215546Sopenharmony_cienum radv_queue_family {
255bf215546Sopenharmony_ci   RADV_QUEUE_GENERAL,
256bf215546Sopenharmony_ci   RADV_QUEUE_COMPUTE,
257bf215546Sopenharmony_ci   RADV_QUEUE_TRANSFER,
258bf215546Sopenharmony_ci   RADV_MAX_QUEUE_FAMILIES,
259bf215546Sopenharmony_ci   RADV_QUEUE_FOREIGN = RADV_MAX_QUEUE_FAMILIES,
260bf215546Sopenharmony_ci   RADV_QUEUE_IGNORED,
261bf215546Sopenharmony_ci};
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_cistruct radv_perfcounter_desc;
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_cistruct radv_physical_device {
266bf215546Sopenharmony_ci   struct vk_physical_device vk;
267bf215546Sopenharmony_ci
268bf215546Sopenharmony_ci   /* Link in radv_instance::physical_devices */
269bf215546Sopenharmony_ci   struct list_head link;
270bf215546Sopenharmony_ci
271bf215546Sopenharmony_ci   struct radv_instance *instance;
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci   struct radeon_winsys *ws;
274bf215546Sopenharmony_ci   struct radeon_info rad_info;
275bf215546Sopenharmony_ci   char name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
276bf215546Sopenharmony_ci   char marketing_name[VK_MAX_PHYSICAL_DEVICE_NAME_SIZE];
277bf215546Sopenharmony_ci   uint8_t driver_uuid[VK_UUID_SIZE];
278bf215546Sopenharmony_ci   uint8_t device_uuid[VK_UUID_SIZE];
279bf215546Sopenharmony_ci   uint8_t cache_uuid[VK_UUID_SIZE];
280bf215546Sopenharmony_ci
281bf215546Sopenharmony_ci   int local_fd;
282bf215546Sopenharmony_ci   int master_fd;
283bf215546Sopenharmony_ci   struct wsi_device wsi_device;
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_ci   bool out_of_order_rast_allowed;
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci   /* Whether DCC should be enabled for MSAA textures. */
288bf215546Sopenharmony_ci   bool dcc_msaa_allowed;
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_ci   /* Whether to enable NGG. */
291bf215546Sopenharmony_ci   bool use_ngg;
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ci   /* Whether to enable NGG culling. */
294bf215546Sopenharmony_ci   bool use_ngg_culling;
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci   /* Whether to enable NGG streamout. */
297bf215546Sopenharmony_ci   bool use_ngg_streamout;
298bf215546Sopenharmony_ci
299bf215546Sopenharmony_ci   /* Number of threads per wave. */
300bf215546Sopenharmony_ci   uint8_t ps_wave_size;
301bf215546Sopenharmony_ci   uint8_t cs_wave_size;
302bf215546Sopenharmony_ci   uint8_t ge_wave_size;
303bf215546Sopenharmony_ci   uint8_t rt_wave_size;
304bf215546Sopenharmony_ci
305bf215546Sopenharmony_ci   /* Whether to use the LLVM compiler backend */
306bf215546Sopenharmony_ci   bool use_llvm;
307bf215546Sopenharmony_ci
308bf215546Sopenharmony_ci   /* Whether to emulate ETC2 image support on HW without support. */
309bf215546Sopenharmony_ci   bool emulate_etc2;
310bf215546Sopenharmony_ci
311bf215546Sopenharmony_ci   /* This is the drivers on-disk cache used as a fallback as opposed to
312bf215546Sopenharmony_ci    * the pipeline cache defined by apps.
313bf215546Sopenharmony_ci    */
314bf215546Sopenharmony_ci   struct disk_cache *disk_cache;
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci   VkPhysicalDeviceMemoryProperties memory_properties;
317bf215546Sopenharmony_ci   enum radeon_bo_domain memory_domains[VK_MAX_MEMORY_TYPES];
318bf215546Sopenharmony_ci   enum radeon_bo_flag memory_flags[VK_MAX_MEMORY_TYPES];
319bf215546Sopenharmony_ci   unsigned heaps;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci   /* Bitmask of memory types that use the 32-bit address space. */
322bf215546Sopenharmony_ci   uint32_t memory_types_32bit;
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci#ifndef _WIN32
325bf215546Sopenharmony_ci   int available_nodes;
326bf215546Sopenharmony_ci   drmPciBusInfo bus_info;
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   dev_t primary_devid;
329bf215546Sopenharmony_ci   dev_t render_devid;
330bf215546Sopenharmony_ci#endif
331bf215546Sopenharmony_ci
332bf215546Sopenharmony_ci   nir_shader_compiler_options nir_options[MESA_VULKAN_SHADER_STAGES];
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci   enum radv_queue_family vk_queue_to_radv[RADV_MAX_QUEUE_FAMILIES];
335bf215546Sopenharmony_ci   uint32_t num_queues;
336bf215546Sopenharmony_ci
337bf215546Sopenharmony_ci   uint32_t gs_table_depth;
338bf215546Sopenharmony_ci
339bf215546Sopenharmony_ci   struct ac_hs_info hs;
340bf215546Sopenharmony_ci   struct ac_task_info task_info;
341bf215546Sopenharmony_ci
342bf215546Sopenharmony_ci   /* Performance counters. */
343bf215546Sopenharmony_ci   struct ac_perfcounters ac_perfcounters;
344bf215546Sopenharmony_ci
345bf215546Sopenharmony_ci   uint32_t num_perfcounters;
346bf215546Sopenharmony_ci   struct radv_perfcounter_desc *perfcounters;
347bf215546Sopenharmony_ci};
348bf215546Sopenharmony_ci
349bf215546Sopenharmony_cistruct radv_instance {
350bf215546Sopenharmony_ci   struct vk_instance vk;
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_ci   VkAllocationCallbacks alloc;
353bf215546Sopenharmony_ci
354bf215546Sopenharmony_ci   uint64_t debug_flags;
355bf215546Sopenharmony_ci   uint64_t perftest_flags;
356bf215546Sopenharmony_ci
357bf215546Sopenharmony_ci   bool physical_devices_enumerated;
358bf215546Sopenharmony_ci   struct list_head physical_devices;
359bf215546Sopenharmony_ci
360bf215546Sopenharmony_ci   struct driOptionCache dri_options;
361bf215546Sopenharmony_ci   struct driOptionCache available_dri_options;
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci   /**
364bf215546Sopenharmony_ci    * Workarounds for game bugs.
365bf215546Sopenharmony_ci    */
366bf215546Sopenharmony_ci   bool enable_mrt_output_nan_fixup;
367bf215546Sopenharmony_ci   bool disable_tc_compat_htile_in_general;
368bf215546Sopenharmony_ci   bool disable_shrink_image_store;
369bf215546Sopenharmony_ci   bool absolute_depth_bias;
370bf215546Sopenharmony_ci   bool disable_aniso_single_level;
371bf215546Sopenharmony_ci   bool zero_vram;
372bf215546Sopenharmony_ci   bool disable_sinking_load_input_fs;
373bf215546Sopenharmony_ci   bool flush_before_query_copy;
374bf215546Sopenharmony_ci};
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ciVkResult radv_init_wsi(struct radv_physical_device *physical_device);
377bf215546Sopenharmony_civoid radv_finish_wsi(struct radv_physical_device *physical_device);
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_cistruct cache_entry;
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_cistruct radv_pipeline_cache {
382bf215546Sopenharmony_ci   struct vk_object_base base;
383bf215546Sopenharmony_ci   struct radv_device *device;
384bf215546Sopenharmony_ci   mtx_t mutex;
385bf215546Sopenharmony_ci   VkPipelineCacheCreateFlags flags;
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci   uint32_t total_size;
388bf215546Sopenharmony_ci   uint32_t table_size;
389bf215546Sopenharmony_ci   uint32_t kernel_count;
390bf215546Sopenharmony_ci   struct cache_entry **hash_table;
391bf215546Sopenharmony_ci   bool modified;
392bf215546Sopenharmony_ci
393bf215546Sopenharmony_ci   VkAllocationCallbacks alloc;
394bf215546Sopenharmony_ci};
395bf215546Sopenharmony_ci
396bf215546Sopenharmony_cistruct radv_shader_binary;
397bf215546Sopenharmony_cistruct radv_shader;
398bf215546Sopenharmony_cistruct radv_pipeline_shader_stack_size;
399bf215546Sopenharmony_ci
400bf215546Sopenharmony_civoid radv_pipeline_cache_init(struct radv_pipeline_cache *cache, struct radv_device *device);
401bf215546Sopenharmony_civoid radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
402bf215546Sopenharmony_cibool radv_pipeline_cache_load(struct radv_pipeline_cache *cache, const void *data, size_t size);
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_cibool radv_create_shaders_from_pipeline_cache(
405bf215546Sopenharmony_ci   struct radv_device *device, struct radv_pipeline_cache *cache, const unsigned char *sha1,
406bf215546Sopenharmony_ci   struct radv_pipeline *pipeline, struct radv_pipeline_shader_stack_size **stack_sizes,
407bf215546Sopenharmony_ci   uint32_t *num_stack_sizes, bool *found_in_application_cache);
408bf215546Sopenharmony_ci
409bf215546Sopenharmony_civoid radv_pipeline_cache_insert_shaders(
410bf215546Sopenharmony_ci   struct radv_device *device, struct radv_pipeline_cache *cache, const unsigned char *sha1,
411bf215546Sopenharmony_ci   struct radv_pipeline *pipeline, struct radv_shader_binary *const *binaries,
412bf215546Sopenharmony_ci   const struct radv_pipeline_shader_stack_size *stack_sizes, uint32_t num_stack_sizes);
413bf215546Sopenharmony_ci
414bf215546Sopenharmony_ciVkResult radv_upload_shaders(struct radv_device *device, struct radv_pipeline *pipeline,
415bf215546Sopenharmony_ci                             struct radv_shader_binary **binaries,
416bf215546Sopenharmony_ci                             struct radv_shader_binary *gs_copy_binary);
417bf215546Sopenharmony_ci
418bf215546Sopenharmony_cienum radv_blit_ds_layout {
419bf215546Sopenharmony_ci   RADV_BLIT_DS_LAYOUT_TILE_ENABLE,
420bf215546Sopenharmony_ci   RADV_BLIT_DS_LAYOUT_TILE_DISABLE,
421bf215546Sopenharmony_ci   RADV_BLIT_DS_LAYOUT_COUNT,
422bf215546Sopenharmony_ci};
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_cistatic inline enum radv_blit_ds_layout
425bf215546Sopenharmony_ciradv_meta_blit_ds_to_type(VkImageLayout layout)
426bf215546Sopenharmony_ci{
427bf215546Sopenharmony_ci   return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_BLIT_DS_LAYOUT_TILE_DISABLE
428bf215546Sopenharmony_ci                                              : RADV_BLIT_DS_LAYOUT_TILE_ENABLE;
429bf215546Sopenharmony_ci}
430bf215546Sopenharmony_ci
431bf215546Sopenharmony_cistatic inline VkImageLayout
432bf215546Sopenharmony_ciradv_meta_blit_ds_to_layout(enum radv_blit_ds_layout ds_layout)
433bf215546Sopenharmony_ci{
434bf215546Sopenharmony_ci   return ds_layout == RADV_BLIT_DS_LAYOUT_TILE_ENABLE ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
435bf215546Sopenharmony_ci                                                       : VK_IMAGE_LAYOUT_GENERAL;
436bf215546Sopenharmony_ci}
437bf215546Sopenharmony_ci
438bf215546Sopenharmony_cienum radv_meta_dst_layout {
439bf215546Sopenharmony_ci   RADV_META_DST_LAYOUT_GENERAL,
440bf215546Sopenharmony_ci   RADV_META_DST_LAYOUT_OPTIMAL,
441bf215546Sopenharmony_ci   RADV_META_DST_LAYOUT_COUNT,
442bf215546Sopenharmony_ci};
443bf215546Sopenharmony_ci
444bf215546Sopenharmony_cistatic inline enum radv_meta_dst_layout
445bf215546Sopenharmony_ciradv_meta_dst_layout_from_layout(VkImageLayout layout)
446bf215546Sopenharmony_ci{
447bf215546Sopenharmony_ci   return (layout == VK_IMAGE_LAYOUT_GENERAL) ? RADV_META_DST_LAYOUT_GENERAL
448bf215546Sopenharmony_ci                                              : RADV_META_DST_LAYOUT_OPTIMAL;
449bf215546Sopenharmony_ci}
450bf215546Sopenharmony_ci
451bf215546Sopenharmony_cistatic inline VkImageLayout
452bf215546Sopenharmony_ciradv_meta_dst_layout_to_layout(enum radv_meta_dst_layout layout)
453bf215546Sopenharmony_ci{
454bf215546Sopenharmony_ci   return layout == RADV_META_DST_LAYOUT_OPTIMAL ? VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL
455bf215546Sopenharmony_ci                                                 : VK_IMAGE_LAYOUT_GENERAL;
456bf215546Sopenharmony_ci}
457bf215546Sopenharmony_ci
458bf215546Sopenharmony_cistruct radv_meta_state {
459bf215546Sopenharmony_ci   VkAllocationCallbacks alloc;
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ci   struct radv_pipeline_cache cache;
462bf215546Sopenharmony_ci
463bf215546Sopenharmony_ci   /*
464bf215546Sopenharmony_ci    * For on-demand pipeline creation, makes sure that
465bf215546Sopenharmony_ci    * only one thread tries to build a pipeline at the same time.
466bf215546Sopenharmony_ci    */
467bf215546Sopenharmony_ci   mtx_t mtx;
468bf215546Sopenharmony_ci
469bf215546Sopenharmony_ci   /**
470bf215546Sopenharmony_ci    * Use array element `i` for images with `2^i` samples.
471bf215546Sopenharmony_ci    */
472bf215546Sopenharmony_ci   struct {
473bf215546Sopenharmony_ci      VkPipeline color_pipelines[NUM_META_FS_KEYS];
474bf215546Sopenharmony_ci   } color_clear[MAX_SAMPLES_LOG2][MAX_RTS];
475bf215546Sopenharmony_ci
476bf215546Sopenharmony_ci   struct {
477bf215546Sopenharmony_ci      VkPipeline depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
478bf215546Sopenharmony_ci      VkPipeline stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
479bf215546Sopenharmony_ci      VkPipeline depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci      VkPipeline depth_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
482bf215546Sopenharmony_ci      VkPipeline stencil_only_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
483bf215546Sopenharmony_ci      VkPipeline depthstencil_unrestricted_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
484bf215546Sopenharmony_ci   } ds_clear[MAX_SAMPLES_LOG2];
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ci   VkPipelineLayout clear_color_p_layout;
487bf215546Sopenharmony_ci   VkPipelineLayout clear_depth_p_layout;
488bf215546Sopenharmony_ci   VkPipelineLayout clear_depth_unrestricted_p_layout;
489bf215546Sopenharmony_ci
490bf215546Sopenharmony_ci   /* Optimized compute fast HTILE clear for stencil or depth only. */
491bf215546Sopenharmony_ci   VkPipeline clear_htile_mask_pipeline;
492bf215546Sopenharmony_ci   VkPipelineLayout clear_htile_mask_p_layout;
493bf215546Sopenharmony_ci   VkDescriptorSetLayout clear_htile_mask_ds_layout;
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_ci   /* Copy VRS into HTILE. */
496bf215546Sopenharmony_ci   VkPipeline copy_vrs_htile_pipeline;
497bf215546Sopenharmony_ci   VkPipelineLayout copy_vrs_htile_p_layout;
498bf215546Sopenharmony_ci   VkDescriptorSetLayout copy_vrs_htile_ds_layout;
499bf215546Sopenharmony_ci
500bf215546Sopenharmony_ci   /* Clear DCC with comp-to-single. */
501bf215546Sopenharmony_ci   VkPipeline clear_dcc_comp_to_single_pipeline[2]; /* 0: 1x, 1: 2x/4x/8x */
502bf215546Sopenharmony_ci   VkPipelineLayout clear_dcc_comp_to_single_p_layout;
503bf215546Sopenharmony_ci   VkDescriptorSetLayout clear_dcc_comp_to_single_ds_layout;
504bf215546Sopenharmony_ci
505bf215546Sopenharmony_ci   struct {
506bf215546Sopenharmony_ci      /** Pipeline that blits from a 1D image. */
507bf215546Sopenharmony_ci      VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
508bf215546Sopenharmony_ci
509bf215546Sopenharmony_ci      /** Pipeline that blits from a 2D image. */
510bf215546Sopenharmony_ci      VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
511bf215546Sopenharmony_ci
512bf215546Sopenharmony_ci      /** Pipeline that blits from a 3D image. */
513bf215546Sopenharmony_ci      VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
514bf215546Sopenharmony_ci
515bf215546Sopenharmony_ci      VkPipeline depth_only_1d_pipeline;
516bf215546Sopenharmony_ci      VkPipeline depth_only_2d_pipeline;
517bf215546Sopenharmony_ci      VkPipeline depth_only_3d_pipeline;
518bf215546Sopenharmony_ci
519bf215546Sopenharmony_ci      VkPipeline stencil_only_1d_pipeline;
520bf215546Sopenharmony_ci      VkPipeline stencil_only_2d_pipeline;
521bf215546Sopenharmony_ci      VkPipeline stencil_only_3d_pipeline;
522bf215546Sopenharmony_ci      VkPipelineLayout pipeline_layout;
523bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
524bf215546Sopenharmony_ci   } blit;
525bf215546Sopenharmony_ci
526bf215546Sopenharmony_ci   struct {
527bf215546Sopenharmony_ci      VkPipelineLayout p_layouts[5];
528bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layouts[5];
529bf215546Sopenharmony_ci      VkPipeline pipelines[5][NUM_META_FS_KEYS];
530bf215546Sopenharmony_ci
531bf215546Sopenharmony_ci      VkPipeline depth_only_pipeline[5];
532bf215546Sopenharmony_ci
533bf215546Sopenharmony_ci      VkPipeline stencil_only_pipeline[5];
534bf215546Sopenharmony_ci   } blit2d[MAX_SAMPLES_LOG2];
535bf215546Sopenharmony_ci
536bf215546Sopenharmony_ci   struct {
537bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
538bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
539bf215546Sopenharmony_ci      VkPipeline pipeline;
540bf215546Sopenharmony_ci      VkPipeline pipeline_3d;
541bf215546Sopenharmony_ci   } itob;
542bf215546Sopenharmony_ci   struct {
543bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
544bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
545bf215546Sopenharmony_ci      VkPipeline pipeline;
546bf215546Sopenharmony_ci      VkPipeline pipeline_3d;
547bf215546Sopenharmony_ci   } btoi;
548bf215546Sopenharmony_ci   struct {
549bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
550bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
551bf215546Sopenharmony_ci      VkPipeline pipeline;
552bf215546Sopenharmony_ci   } btoi_r32g32b32;
553bf215546Sopenharmony_ci   struct {
554bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
555bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
556bf215546Sopenharmony_ci      VkPipeline pipeline[MAX_SAMPLES_LOG2];
557bf215546Sopenharmony_ci      VkPipeline pipeline_3d;
558bf215546Sopenharmony_ci   } itoi;
559bf215546Sopenharmony_ci   struct {
560bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
561bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
562bf215546Sopenharmony_ci      VkPipeline pipeline;
563bf215546Sopenharmony_ci   } itoi_r32g32b32;
564bf215546Sopenharmony_ci   struct {
565bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
566bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
567bf215546Sopenharmony_ci      VkPipeline pipeline[MAX_SAMPLES_LOG2];
568bf215546Sopenharmony_ci      VkPipeline pipeline_3d;
569bf215546Sopenharmony_ci   } cleari;
570bf215546Sopenharmony_ci   struct {
571bf215546Sopenharmony_ci      VkPipelineLayout img_p_layout;
572bf215546Sopenharmony_ci      VkDescriptorSetLayout img_ds_layout;
573bf215546Sopenharmony_ci      VkPipeline pipeline;
574bf215546Sopenharmony_ci   } cleari_r32g32b32;
575bf215546Sopenharmony_ci   struct {
576bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
577bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
578bf215546Sopenharmony_ci      VkPipeline pipeline[MAX_SAMPLES_LOG2];
579bf215546Sopenharmony_ci   } fmask_copy;
580bf215546Sopenharmony_ci
581bf215546Sopenharmony_ci   struct {
582bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
583bf215546Sopenharmony_ci      VkPipeline pipeline[NUM_META_FS_KEYS];
584bf215546Sopenharmony_ci   } resolve;
585bf215546Sopenharmony_ci
586bf215546Sopenharmony_ci   struct {
587bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
588bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
589bf215546Sopenharmony_ci      struct {
590bf215546Sopenharmony_ci         VkPipeline pipeline;
591bf215546Sopenharmony_ci         VkPipeline i_pipeline;
592bf215546Sopenharmony_ci         VkPipeline srgb_pipeline;
593bf215546Sopenharmony_ci      } rc[MAX_SAMPLES_LOG2];
594bf215546Sopenharmony_ci
595bf215546Sopenharmony_ci      VkPipeline depth_zero_pipeline;
596bf215546Sopenharmony_ci      struct {
597bf215546Sopenharmony_ci         VkPipeline average_pipeline;
598bf215546Sopenharmony_ci         VkPipeline max_pipeline;
599bf215546Sopenharmony_ci         VkPipeline min_pipeline;
600bf215546Sopenharmony_ci      } depth[MAX_SAMPLES_LOG2];
601bf215546Sopenharmony_ci
602bf215546Sopenharmony_ci      VkPipeline stencil_zero_pipeline;
603bf215546Sopenharmony_ci      struct {
604bf215546Sopenharmony_ci         VkPipeline max_pipeline;
605bf215546Sopenharmony_ci         VkPipeline min_pipeline;
606bf215546Sopenharmony_ci      } stencil[MAX_SAMPLES_LOG2];
607bf215546Sopenharmony_ci   } resolve_compute;
608bf215546Sopenharmony_ci
609bf215546Sopenharmony_ci   struct {
610bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
611bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
612bf215546Sopenharmony_ci
613bf215546Sopenharmony_ci      struct {
614bf215546Sopenharmony_ci         VkPipeline pipeline[NUM_META_FS_KEYS];
615bf215546Sopenharmony_ci      } rc[MAX_SAMPLES_LOG2];
616bf215546Sopenharmony_ci
617bf215546Sopenharmony_ci      VkPipeline depth_zero_pipeline;
618bf215546Sopenharmony_ci      struct {
619bf215546Sopenharmony_ci         VkPipeline average_pipeline;
620bf215546Sopenharmony_ci         VkPipeline max_pipeline;
621bf215546Sopenharmony_ci         VkPipeline min_pipeline;
622bf215546Sopenharmony_ci      } depth[MAX_SAMPLES_LOG2];
623bf215546Sopenharmony_ci
624bf215546Sopenharmony_ci      VkPipeline stencil_zero_pipeline;
625bf215546Sopenharmony_ci      struct {
626bf215546Sopenharmony_ci         VkPipeline max_pipeline;
627bf215546Sopenharmony_ci         VkPipeline min_pipeline;
628bf215546Sopenharmony_ci      } stencil[MAX_SAMPLES_LOG2];
629bf215546Sopenharmony_ci   } resolve_fragment;
630bf215546Sopenharmony_ci
631bf215546Sopenharmony_ci   struct {
632bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
633bf215546Sopenharmony_ci      VkPipeline decompress_pipeline;
634bf215546Sopenharmony_ci      VkPipeline resummarize_pipeline;
635bf215546Sopenharmony_ci   } depth_decomp[MAX_SAMPLES_LOG2];
636bf215546Sopenharmony_ci
637bf215546Sopenharmony_ci   VkDescriptorSetLayout expand_depth_stencil_compute_ds_layout;
638bf215546Sopenharmony_ci   VkPipelineLayout expand_depth_stencil_compute_p_layout;
639bf215546Sopenharmony_ci   VkPipeline expand_depth_stencil_compute_pipeline;
640bf215546Sopenharmony_ci
641bf215546Sopenharmony_ci   struct {
642bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
643bf215546Sopenharmony_ci      VkPipeline cmask_eliminate_pipeline;
644bf215546Sopenharmony_ci      VkPipeline fmask_decompress_pipeline;
645bf215546Sopenharmony_ci      VkPipeline dcc_decompress_pipeline;
646bf215546Sopenharmony_ci
647bf215546Sopenharmony_ci      VkDescriptorSetLayout dcc_decompress_compute_ds_layout;
648bf215546Sopenharmony_ci      VkPipelineLayout dcc_decompress_compute_p_layout;
649bf215546Sopenharmony_ci      VkPipeline dcc_decompress_compute_pipeline;
650bf215546Sopenharmony_ci   } fast_clear_flush;
651bf215546Sopenharmony_ci
652bf215546Sopenharmony_ci   struct {
653bf215546Sopenharmony_ci      VkPipelineLayout fill_p_layout;
654bf215546Sopenharmony_ci      VkPipelineLayout copy_p_layout;
655bf215546Sopenharmony_ci      VkPipeline fill_pipeline;
656bf215546Sopenharmony_ci      VkPipeline copy_pipeline;
657bf215546Sopenharmony_ci   } buffer;
658bf215546Sopenharmony_ci
659bf215546Sopenharmony_ci   struct {
660bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
661bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
662bf215546Sopenharmony_ci      VkPipeline occlusion_query_pipeline;
663bf215546Sopenharmony_ci      VkPipeline pipeline_statistics_query_pipeline;
664bf215546Sopenharmony_ci      VkPipeline tfb_query_pipeline;
665bf215546Sopenharmony_ci      VkPipeline timestamp_query_pipeline;
666bf215546Sopenharmony_ci      VkPipeline pg_query_pipeline;
667bf215546Sopenharmony_ci   } query;
668bf215546Sopenharmony_ci
669bf215546Sopenharmony_ci   struct {
670bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
671bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
672bf215546Sopenharmony_ci      VkPipeline pipeline[MAX_SAMPLES_LOG2];
673bf215546Sopenharmony_ci   } fmask_expand;
674bf215546Sopenharmony_ci
675bf215546Sopenharmony_ci   struct {
676bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
677bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
678bf215546Sopenharmony_ci      VkPipeline pipeline[32];
679bf215546Sopenharmony_ci   } dcc_retile;
680bf215546Sopenharmony_ci
681bf215546Sopenharmony_ci   struct {
682bf215546Sopenharmony_ci      VkPipelineLayout leaf_p_layout;
683bf215546Sopenharmony_ci      VkPipeline leaf_pipeline;
684bf215546Sopenharmony_ci      VkPipelineLayout morton_p_layout;
685bf215546Sopenharmony_ci      VkPipeline morton_pipeline;
686bf215546Sopenharmony_ci      VkPipelineLayout internal_p_layout;
687bf215546Sopenharmony_ci      VkPipeline internal_pipeline;
688bf215546Sopenharmony_ci      VkPipelineLayout copy_p_layout;
689bf215546Sopenharmony_ci      VkPipeline copy_pipeline;
690bf215546Sopenharmony_ci
691bf215546Sopenharmony_ci      struct radix_sort_vk *radix_sort;
692bf215546Sopenharmony_ci      struct radix_sort_vk_sort_devaddr_info radix_sort_info;
693bf215546Sopenharmony_ci   } accel_struct_build;
694bf215546Sopenharmony_ci
695bf215546Sopenharmony_ci   struct {
696bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
697bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
698bf215546Sopenharmony_ci      VkPipeline pipeline;
699bf215546Sopenharmony_ci   } etc_decode;
700bf215546Sopenharmony_ci
701bf215546Sopenharmony_ci   struct {
702bf215546Sopenharmony_ci      VkDescriptorSetLayout ds_layout;
703bf215546Sopenharmony_ci      VkPipelineLayout p_layout;
704bf215546Sopenharmony_ci      VkPipeline pipeline;
705bf215546Sopenharmony_ci   } dgc_prepare;
706bf215546Sopenharmony_ci};
707bf215546Sopenharmony_ci
708bf215546Sopenharmony_ci#define RADV_NUM_HW_CTX (RADEON_CTX_PRIORITY_REALTIME + 1)
709bf215546Sopenharmony_ci
710bf215546Sopenharmony_cistruct radv_deferred_queue_submission;
711bf215546Sopenharmony_ci
712bf215546Sopenharmony_cistatic inline enum radv_queue_family
713bf215546Sopenharmony_civk_queue_to_radv(const struct radv_physical_device *phys_dev, int queue_family_index)
714bf215546Sopenharmony_ci{
715bf215546Sopenharmony_ci   if (queue_family_index == VK_QUEUE_FAMILY_EXTERNAL ||
716bf215546Sopenharmony_ci       queue_family_index == VK_QUEUE_FAMILY_FOREIGN_EXT)
717bf215546Sopenharmony_ci      return RADV_QUEUE_FOREIGN;
718bf215546Sopenharmony_ci   if (queue_family_index == VK_QUEUE_FAMILY_IGNORED)
719bf215546Sopenharmony_ci      return RADV_QUEUE_IGNORED;
720bf215546Sopenharmony_ci
721bf215546Sopenharmony_ci   assert(queue_family_index < RADV_MAX_QUEUE_FAMILIES);
722bf215546Sopenharmony_ci   return phys_dev->vk_queue_to_radv[queue_family_index];
723bf215546Sopenharmony_ci}
724bf215546Sopenharmony_ci
725bf215546Sopenharmony_cienum amd_ip_type radv_queue_family_to_ring(struct radv_physical_device *physical_device,
726bf215546Sopenharmony_ci                                         enum radv_queue_family f);
727bf215546Sopenharmony_ci
728bf215546Sopenharmony_cistruct radv_queue_ring_info {
729bf215546Sopenharmony_ci   uint32_t scratch_size_per_wave;
730bf215546Sopenharmony_ci   uint32_t scratch_waves;
731bf215546Sopenharmony_ci   uint32_t compute_scratch_size_per_wave;
732bf215546Sopenharmony_ci   uint32_t compute_scratch_waves;
733bf215546Sopenharmony_ci   uint32_t esgs_ring_size;
734bf215546Sopenharmony_ci   uint32_t gsvs_ring_size;
735bf215546Sopenharmony_ci   bool tess_rings;
736bf215546Sopenharmony_ci   bool task_rings;
737bf215546Sopenharmony_ci   bool mesh_scratch_ring;
738bf215546Sopenharmony_ci   bool gds;
739bf215546Sopenharmony_ci   bool gds_oa;
740bf215546Sopenharmony_ci   bool sample_positions;
741bf215546Sopenharmony_ci};
742bf215546Sopenharmony_ci
743bf215546Sopenharmony_cistruct radv_queue_state {
744bf215546Sopenharmony_ci   enum radv_queue_family qf;
745bf215546Sopenharmony_ci   struct radv_queue_ring_info ring_info;
746bf215546Sopenharmony_ci
747bf215546Sopenharmony_ci   struct radeon_winsys_bo *scratch_bo;
748bf215546Sopenharmony_ci   struct radeon_winsys_bo *descriptor_bo;
749bf215546Sopenharmony_ci   struct radeon_winsys_bo *compute_scratch_bo;
750bf215546Sopenharmony_ci   struct radeon_winsys_bo *esgs_ring_bo;
751bf215546Sopenharmony_ci   struct radeon_winsys_bo *gsvs_ring_bo;
752bf215546Sopenharmony_ci   struct radeon_winsys_bo *tess_rings_bo;
753bf215546Sopenharmony_ci   struct radeon_winsys_bo *task_rings_bo;
754bf215546Sopenharmony_ci   struct radeon_winsys_bo *mesh_scratch_ring_bo;
755bf215546Sopenharmony_ci   struct radeon_winsys_bo *gds_bo;
756bf215546Sopenharmony_ci   struct radeon_winsys_bo *gds_oa_bo;
757bf215546Sopenharmony_ci
758bf215546Sopenharmony_ci   struct radeon_cmdbuf *initial_preamble_cs;
759bf215546Sopenharmony_ci   struct radeon_cmdbuf *initial_full_flush_preamble_cs;
760bf215546Sopenharmony_ci   struct radeon_cmdbuf *continue_preamble_cs;
761bf215546Sopenharmony_ci};
762bf215546Sopenharmony_ci
763bf215546Sopenharmony_cistruct radv_queue {
764bf215546Sopenharmony_ci   struct vk_queue vk;
765bf215546Sopenharmony_ci   struct radv_device *device;
766bf215546Sopenharmony_ci   struct radeon_winsys_ctx *hw_ctx;
767bf215546Sopenharmony_ci   enum radeon_ctx_priority priority;
768bf215546Sopenharmony_ci   struct radv_queue_state state;
769bf215546Sopenharmony_ci   struct radv_queue_state *ace_internal_state;
770bf215546Sopenharmony_ci};
771bf215546Sopenharmony_ci
772bf215546Sopenharmony_ci#define RADV_BORDER_COLOR_COUNT       4096
773bf215546Sopenharmony_ci#define RADV_BORDER_COLOR_BUFFER_SIZE (sizeof(VkClearColorValue) * RADV_BORDER_COLOR_COUNT)
774bf215546Sopenharmony_ci
775bf215546Sopenharmony_cistruct radv_device_border_color_data {
776bf215546Sopenharmony_ci   bool used[RADV_BORDER_COLOR_COUNT];
777bf215546Sopenharmony_ci
778bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
779bf215546Sopenharmony_ci   VkClearColorValue *colors_gpu_ptr;
780bf215546Sopenharmony_ci
781bf215546Sopenharmony_ci   /* Mutex is required to guarantee vkCreateSampler thread safety
782bf215546Sopenharmony_ci    * given that we are writing to a buffer and checking color occupation */
783bf215546Sopenharmony_ci   mtx_t mutex;
784bf215546Sopenharmony_ci};
785bf215546Sopenharmony_ci
786bf215546Sopenharmony_cienum radv_force_vrs {
787bf215546Sopenharmony_ci   RADV_FORCE_VRS_1x1 = 0,
788bf215546Sopenharmony_ci   RADV_FORCE_VRS_2x2,
789bf215546Sopenharmony_ci   RADV_FORCE_VRS_2x1,
790bf215546Sopenharmony_ci   RADV_FORCE_VRS_1x2,
791bf215546Sopenharmony_ci};
792bf215546Sopenharmony_ci
793bf215546Sopenharmony_cistruct radv_notifier {
794bf215546Sopenharmony_ci   int fd;
795bf215546Sopenharmony_ci   int watch;
796bf215546Sopenharmony_ci   bool quit;
797bf215546Sopenharmony_ci   thrd_t thread;
798bf215546Sopenharmony_ci};
799bf215546Sopenharmony_ci
800bf215546Sopenharmony_cistruct radv_device {
801bf215546Sopenharmony_ci   struct vk_device vk;
802bf215546Sopenharmony_ci
803bf215546Sopenharmony_ci   struct radv_instance *instance;
804bf215546Sopenharmony_ci   struct radeon_winsys *ws;
805bf215546Sopenharmony_ci
806bf215546Sopenharmony_ci   struct radeon_winsys_ctx *hw_ctx[RADV_NUM_HW_CTX];
807bf215546Sopenharmony_ci   struct radv_meta_state meta_state;
808bf215546Sopenharmony_ci
809bf215546Sopenharmony_ci   struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
810bf215546Sopenharmony_ci   int queue_count[RADV_MAX_QUEUE_FAMILIES];
811bf215546Sopenharmony_ci
812bf215546Sopenharmony_ci   bool pbb_allowed;
813bf215546Sopenharmony_ci   uint32_t scratch_waves;
814bf215546Sopenharmony_ci   uint32_t dispatch_initiator;
815bf215546Sopenharmony_ci   uint32_t dispatch_initiator_task;
816bf215546Sopenharmony_ci
817bf215546Sopenharmony_ci   /* MSAA sample locations.
818bf215546Sopenharmony_ci    * The first index is the sample index.
819bf215546Sopenharmony_ci    * The second index is the coordinate: X, Y. */
820bf215546Sopenharmony_ci   float sample_locations_1x[1][2];
821bf215546Sopenharmony_ci   float sample_locations_2x[2][2];
822bf215546Sopenharmony_ci   float sample_locations_4x[4][2];
823bf215546Sopenharmony_ci   float sample_locations_8x[8][2];
824bf215546Sopenharmony_ci
825bf215546Sopenharmony_ci   /* GFX7 and later */
826bf215546Sopenharmony_ci   uint32_t gfx_init_size_dw;
827bf215546Sopenharmony_ci   struct radeon_winsys_bo *gfx_init;
828bf215546Sopenharmony_ci
829bf215546Sopenharmony_ci   struct radeon_winsys_bo *trace_bo;
830bf215546Sopenharmony_ci   uint32_t *trace_id_ptr;
831bf215546Sopenharmony_ci
832bf215546Sopenharmony_ci   /* Whether to keep shader debug info, for debugging. */
833bf215546Sopenharmony_ci   bool keep_shader_info;
834bf215546Sopenharmony_ci
835bf215546Sopenharmony_ci   struct radv_physical_device *physical_device;
836bf215546Sopenharmony_ci
837bf215546Sopenharmony_ci   /* Backup in-memory cache to be used if the app doesn't provide one */
838bf215546Sopenharmony_ci   struct radv_pipeline_cache *mem_cache;
839bf215546Sopenharmony_ci
840bf215546Sopenharmony_ci   /*
841bf215546Sopenharmony_ci    * use different counters so MSAA MRTs get consecutive surface indices,
842bf215546Sopenharmony_ci    * even if MASK is allocated in between.
843bf215546Sopenharmony_ci    */
844bf215546Sopenharmony_ci   uint32_t image_mrt_offset_counter;
845bf215546Sopenharmony_ci   uint32_t fmask_mrt_offset_counter;
846bf215546Sopenharmony_ci
847bf215546Sopenharmony_ci   struct list_head shader_arenas;
848bf215546Sopenharmony_ci   unsigned shader_arena_shift;
849bf215546Sopenharmony_ci   uint8_t shader_free_list_mask;
850bf215546Sopenharmony_ci   struct list_head shader_free_lists[RADV_SHADER_ALLOC_NUM_FREE_LISTS];
851bf215546Sopenharmony_ci   struct list_head shader_block_obj_pool;
852bf215546Sopenharmony_ci   mtx_t shader_arena_mutex;
853bf215546Sopenharmony_ci
854bf215546Sopenharmony_ci   /* For detecting VM faults reported by dmesg. */
855bf215546Sopenharmony_ci   uint64_t dmesg_timestamp;
856bf215546Sopenharmony_ci
857bf215546Sopenharmony_ci   /* Whether the app has enabled the robustBufferAccess/robustBufferAccess2 features. */
858bf215546Sopenharmony_ci   bool robust_buffer_access;
859bf215546Sopenharmony_ci   bool robust_buffer_access2;
860bf215546Sopenharmony_ci
861bf215546Sopenharmony_ci   /* Whether to inline the compute dispatch size in user sgprs. */
862bf215546Sopenharmony_ci   bool load_grid_size_from_user_sgpr;
863bf215546Sopenharmony_ci
864bf215546Sopenharmony_ci   /* Whether the driver uses a global BO list. */
865bf215546Sopenharmony_ci   bool use_global_bo_list;
866bf215546Sopenharmony_ci
867bf215546Sopenharmony_ci   /* Whether attachment VRS is enabled. */
868bf215546Sopenharmony_ci   bool attachment_vrs_enabled;
869bf215546Sopenharmony_ci
870bf215546Sopenharmony_ci   /* Whether shader image 32-bit float atomics are enabled. */
871bf215546Sopenharmony_ci   bool image_float32_atomics;
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_ci   /* Whether 2D views of 3D image is enabled. */
874bf215546Sopenharmony_ci   bool image_2d_view_of_3d;
875bf215546Sopenharmony_ci
876bf215546Sopenharmony_ci   /* Whether primitives generated query features are enabled. */
877bf215546Sopenharmony_ci   bool primitives_generated_query;
878bf215546Sopenharmony_ci
879bf215546Sopenharmony_ci   /* Whether anisotropy is forced with RADV_TEX_ANISO (-1 is disabled). */
880bf215546Sopenharmony_ci   int force_aniso;
881bf215546Sopenharmony_ci
882bf215546Sopenharmony_ci   struct radv_device_border_color_data border_color_data;
883bf215546Sopenharmony_ci
884bf215546Sopenharmony_ci   /* Thread trace. */
885bf215546Sopenharmony_ci   struct ac_thread_trace_data thread_trace;
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_ci   /* SPM. */
888bf215546Sopenharmony_ci   struct ac_spm_trace_data spm_trace;
889bf215546Sopenharmony_ci
890bf215546Sopenharmony_ci   /* Trap handler. */
891bf215546Sopenharmony_ci   struct radv_trap_handler_shader *trap_handler_shader;
892bf215546Sopenharmony_ci   struct radeon_winsys_bo *tma_bo; /* Trap Memory Address */
893bf215546Sopenharmony_ci   uint32_t *tma_ptr;
894bf215546Sopenharmony_ci
895bf215546Sopenharmony_ci   /* Overallocation. */
896bf215546Sopenharmony_ci   bool overallocation_disallowed;
897bf215546Sopenharmony_ci   uint64_t allocated_memory_size[VK_MAX_MEMORY_HEAPS];
898bf215546Sopenharmony_ci   mtx_t overallocation_mutex;
899bf215546Sopenharmony_ci
900bf215546Sopenharmony_ci   /* RADV_FORCE_VRS. */
901bf215546Sopenharmony_ci   struct radv_notifier notifier;
902bf215546Sopenharmony_ci   enum radv_force_vrs force_vrs;
903bf215546Sopenharmony_ci
904bf215546Sopenharmony_ci   /* Depth image for VRS when not bound by the app. */
905bf215546Sopenharmony_ci   struct {
906bf215546Sopenharmony_ci      struct radv_image *image;
907bf215546Sopenharmony_ci      struct radv_buffer *buffer; /* HTILE */
908bf215546Sopenharmony_ci      struct radv_device_memory *mem;
909bf215546Sopenharmony_ci   } vrs;
910bf215546Sopenharmony_ci
911bf215546Sopenharmony_ci   struct u_rwlock vs_prologs_lock;
912bf215546Sopenharmony_ci   struct hash_table *vs_prologs;
913bf215546Sopenharmony_ci
914bf215546Sopenharmony_ci   /* Prime blit sdma queue */
915bf215546Sopenharmony_ci   struct radv_queue *private_sdma_queue;
916bf215546Sopenharmony_ci
917bf215546Sopenharmony_ci   struct radv_shader_part *simple_vs_prologs[MAX_VERTEX_ATTRIBS];
918bf215546Sopenharmony_ci   struct radv_shader_part *instance_rate_vs_prologs[816];
919bf215546Sopenharmony_ci
920bf215546Sopenharmony_ci   simple_mtx_t trace_mtx;
921bf215546Sopenharmony_ci
922bf215546Sopenharmony_ci   /* Whether per-vertex VRS is forced. */
923bf215546Sopenharmony_ci   bool force_vrs_enabled;
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ci   /* Whether shaders created through application entrypoints are considered internal. */
926bf215546Sopenharmony_ci   bool app_shaders_internal;
927bf215546Sopenharmony_ci
928bf215546Sopenharmony_ci   simple_mtx_t pstate_mtx;
929bf215546Sopenharmony_ci   unsigned pstate_cnt;
930bf215546Sopenharmony_ci
931bf215546Sopenharmony_ci   /* BO to contain some performance counter helpers:
932bf215546Sopenharmony_ci    * - A lock for profiling cmdbuffers.
933bf215546Sopenharmony_ci    * - a temporary fence for the end query synchronization.
934bf215546Sopenharmony_ci    * - the pass to use for profiling. (as an array of bools)
935bf215546Sopenharmony_ci    */
936bf215546Sopenharmony_ci   struct radeon_winsys_bo *perf_counter_bo;
937bf215546Sopenharmony_ci
938bf215546Sopenharmony_ci   /* Interleaved lock/unlock commandbuffers for perfcounter passes. */
939bf215546Sopenharmony_ci   struct radeon_cmdbuf **perf_counter_lock_cs;
940bf215546Sopenharmony_ci
941bf215546Sopenharmony_ci   bool uses_device_generated_commands;
942bf215546Sopenharmony_ci};
943bf215546Sopenharmony_ci
944bf215546Sopenharmony_cibool radv_device_acquire_performance_counters(struct radv_device *device);
945bf215546Sopenharmony_civoid radv_device_release_performance_counters(struct radv_device *device);
946bf215546Sopenharmony_ci
947bf215546Sopenharmony_cistruct radv_device_memory {
948bf215546Sopenharmony_ci   struct vk_object_base base;
949bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
950bf215546Sopenharmony_ci   /* for dedicated allocations */
951bf215546Sopenharmony_ci   struct radv_image *image;
952bf215546Sopenharmony_ci   struct radv_buffer *buffer;
953bf215546Sopenharmony_ci   uint32_t heap_index;
954bf215546Sopenharmony_ci   uint64_t alloc_size;
955bf215546Sopenharmony_ci   void *map;
956bf215546Sopenharmony_ci   void *user_ptr;
957bf215546Sopenharmony_ci
958bf215546Sopenharmony_ci#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
959bf215546Sopenharmony_ci   struct AHardwareBuffer *android_hardware_buffer;
960bf215546Sopenharmony_ci#endif
961bf215546Sopenharmony_ci};
962bf215546Sopenharmony_ci
963bf215546Sopenharmony_civoid radv_device_memory_init(struct radv_device_memory *mem, struct radv_device *device,
964bf215546Sopenharmony_ci                             struct radeon_winsys_bo *bo);
965bf215546Sopenharmony_civoid radv_device_memory_finish(struct radv_device_memory *mem);
966bf215546Sopenharmony_ci
967bf215546Sopenharmony_cistruct radv_descriptor_range {
968bf215546Sopenharmony_ci   uint64_t va;
969bf215546Sopenharmony_ci   uint32_t size;
970bf215546Sopenharmony_ci};
971bf215546Sopenharmony_ci
972bf215546Sopenharmony_cistruct radv_descriptor_set_header {
973bf215546Sopenharmony_ci   struct vk_object_base base;
974bf215546Sopenharmony_ci   struct radv_descriptor_set_layout *layout;
975bf215546Sopenharmony_ci   uint32_t size;
976bf215546Sopenharmony_ci   uint32_t buffer_count;
977bf215546Sopenharmony_ci
978bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
979bf215546Sopenharmony_ci   uint64_t va;
980bf215546Sopenharmony_ci   uint32_t *mapped_ptr;
981bf215546Sopenharmony_ci   struct radv_descriptor_range *dynamic_descriptors;
982bf215546Sopenharmony_ci};
983bf215546Sopenharmony_ci
984bf215546Sopenharmony_cistruct radv_descriptor_set {
985bf215546Sopenharmony_ci   struct radv_descriptor_set_header header;
986bf215546Sopenharmony_ci
987bf215546Sopenharmony_ci   struct radeon_winsys_bo *descriptors[];
988bf215546Sopenharmony_ci};
989bf215546Sopenharmony_ci
990bf215546Sopenharmony_cistruct radv_push_descriptor_set {
991bf215546Sopenharmony_ci   struct radv_descriptor_set_header set;
992bf215546Sopenharmony_ci   uint32_t capacity;
993bf215546Sopenharmony_ci};
994bf215546Sopenharmony_ci
995bf215546Sopenharmony_cistruct radv_descriptor_pool_entry {
996bf215546Sopenharmony_ci   uint32_t offset;
997bf215546Sopenharmony_ci   uint32_t size;
998bf215546Sopenharmony_ci   struct radv_descriptor_set *set;
999bf215546Sopenharmony_ci};
1000bf215546Sopenharmony_ci
1001bf215546Sopenharmony_cistruct radv_descriptor_pool {
1002bf215546Sopenharmony_ci   struct vk_object_base base;
1003bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
1004bf215546Sopenharmony_ci   uint8_t *host_bo;
1005bf215546Sopenharmony_ci   uint8_t *mapped_ptr;
1006bf215546Sopenharmony_ci   uint64_t current_offset;
1007bf215546Sopenharmony_ci   uint64_t size;
1008bf215546Sopenharmony_ci
1009bf215546Sopenharmony_ci   uint8_t *host_memory_base;
1010bf215546Sopenharmony_ci   uint8_t *host_memory_ptr;
1011bf215546Sopenharmony_ci   uint8_t *host_memory_end;
1012bf215546Sopenharmony_ci
1013bf215546Sopenharmony_ci   uint32_t entry_count;
1014bf215546Sopenharmony_ci   uint32_t max_entry_count;
1015bf215546Sopenharmony_ci   struct radv_descriptor_pool_entry entries[0];
1016bf215546Sopenharmony_ci};
1017bf215546Sopenharmony_ci
1018bf215546Sopenharmony_cistruct radv_descriptor_update_template_entry {
1019bf215546Sopenharmony_ci   VkDescriptorType descriptor_type;
1020bf215546Sopenharmony_ci
1021bf215546Sopenharmony_ci   /* The number of descriptors to update */
1022bf215546Sopenharmony_ci   uint32_t descriptor_count;
1023bf215546Sopenharmony_ci
1024bf215546Sopenharmony_ci   /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
1025bf215546Sopenharmony_ci   uint32_t dst_offset;
1026bf215546Sopenharmony_ci
1027bf215546Sopenharmony_ci   /* In dwords. Not valid/used for dynamic descriptors */
1028bf215546Sopenharmony_ci   uint32_t dst_stride;
1029bf215546Sopenharmony_ci
1030bf215546Sopenharmony_ci   uint32_t buffer_offset;
1031bf215546Sopenharmony_ci
1032bf215546Sopenharmony_ci   /* Only valid for combined image samplers and samplers */
1033bf215546Sopenharmony_ci   uint8_t has_sampler;
1034bf215546Sopenharmony_ci   uint8_t sampler_offset;
1035bf215546Sopenharmony_ci
1036bf215546Sopenharmony_ci   /* In bytes */
1037bf215546Sopenharmony_ci   size_t src_offset;
1038bf215546Sopenharmony_ci   size_t src_stride;
1039bf215546Sopenharmony_ci
1040bf215546Sopenharmony_ci   /* For push descriptors */
1041bf215546Sopenharmony_ci   const uint32_t *immutable_samplers;
1042bf215546Sopenharmony_ci};
1043bf215546Sopenharmony_ci
1044bf215546Sopenharmony_cistruct radv_descriptor_update_template {
1045bf215546Sopenharmony_ci   struct vk_object_base base;
1046bf215546Sopenharmony_ci   uint32_t entry_count;
1047bf215546Sopenharmony_ci   VkPipelineBindPoint bind_point;
1048bf215546Sopenharmony_ci   struct radv_descriptor_update_template_entry entry[0];
1049bf215546Sopenharmony_ci};
1050bf215546Sopenharmony_ci
1051bf215546Sopenharmony_cistruct radv_buffer {
1052bf215546Sopenharmony_ci   struct vk_buffer vk;
1053bf215546Sopenharmony_ci
1054bf215546Sopenharmony_ci   /* Set when bound */
1055bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
1056bf215546Sopenharmony_ci   VkDeviceSize offset;
1057bf215546Sopenharmony_ci};
1058bf215546Sopenharmony_ci
1059bf215546Sopenharmony_civoid radv_buffer_init(struct radv_buffer *buffer, struct radv_device *device,
1060bf215546Sopenharmony_ci                      struct radeon_winsys_bo *bo, uint64_t size, uint64_t offset);
1061bf215546Sopenharmony_civoid radv_buffer_finish(struct radv_buffer *buffer);
1062bf215546Sopenharmony_ci
1063bf215546Sopenharmony_cienum radv_dynamic_state_bits {
1064bf215546Sopenharmony_ci   RADV_DYNAMIC_VIEWPORT = 1ull << 0,
1065bf215546Sopenharmony_ci   RADV_DYNAMIC_SCISSOR = 1ull << 1,
1066bf215546Sopenharmony_ci   RADV_DYNAMIC_LINE_WIDTH = 1ull << 2,
1067bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_BIAS = 1ull << 3,
1068bf215546Sopenharmony_ci   RADV_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,
1069bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,
1070bf215546Sopenharmony_ci   RADV_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,
1071bf215546Sopenharmony_ci   RADV_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,
1072bf215546Sopenharmony_ci   RADV_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,
1073bf215546Sopenharmony_ci   RADV_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,
1074bf215546Sopenharmony_ci   RADV_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,
1075bf215546Sopenharmony_ci   RADV_DYNAMIC_LINE_STIPPLE = 1ull << 11,
1076bf215546Sopenharmony_ci   RADV_DYNAMIC_CULL_MODE = 1ull << 12,
1077bf215546Sopenharmony_ci   RADV_DYNAMIC_FRONT_FACE = 1ull << 13,
1078bf215546Sopenharmony_ci   RADV_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,
1079bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,
1080bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,
1081bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,
1082bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,
1083bf215546Sopenharmony_ci   RADV_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,
1084bf215546Sopenharmony_ci   RADV_DYNAMIC_STENCIL_OP = 1ull << 20,
1085bf215546Sopenharmony_ci   RADV_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,
1086bf215546Sopenharmony_ci   RADV_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,
1087bf215546Sopenharmony_ci   RADV_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,
1088bf215546Sopenharmony_ci   RADV_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,
1089bf215546Sopenharmony_ci   RADV_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,
1090bf215546Sopenharmony_ci   RADV_DYNAMIC_LOGIC_OP = 1ull << 26,
1091bf215546Sopenharmony_ci   RADV_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,
1092bf215546Sopenharmony_ci   RADV_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,
1093bf215546Sopenharmony_ci   RADV_DYNAMIC_VERTEX_INPUT = 1ull << 29,
1094bf215546Sopenharmony_ci   RADV_DYNAMIC_ALL = (1ull << 30) - 1,
1095bf215546Sopenharmony_ci};
1096bf215546Sopenharmony_ci
1097bf215546Sopenharmony_cienum radv_cmd_dirty_bits {
1098bf215546Sopenharmony_ci   /* Keep the dynamic state dirty bits in sync with
1099bf215546Sopenharmony_ci    * enum radv_dynamic_state_bits */
1100bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1ull << 0,
1101bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1ull << 1,
1102bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1ull << 2,
1103bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1ull << 3,
1104bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1ull << 4,
1105bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1ull << 5,
1106bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1ull << 6,
1107bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1ull << 7,
1108bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1ull << 8,
1109bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DISCARD_RECTANGLE = 1ull << 9,
1110bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_SAMPLE_LOCATIONS = 1ull << 10,
1111bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_LINE_STIPPLE = 1ull << 11,
1112bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_CULL_MODE = 1ull << 12,
1113bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_FRONT_FACE = 1ull << 13,
1114bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_TOPOLOGY = 1ull << 14,
1115bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_TEST_ENABLE = 1ull << 15,
1116bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_WRITE_ENABLE = 1ull << 16,
1117bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_COMPARE_OP = 1ull << 17,
1118bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS_TEST_ENABLE = 1ull << 18,
1119bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_STENCIL_TEST_ENABLE = 1ull << 19,
1120bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_STENCIL_OP = 1ull << 20,
1121bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT_BINDING_STRIDE = 1ull << 21,
1122bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_FRAGMENT_SHADING_RATE = 1ull << 22,
1123bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_PATCH_CONTROL_POINTS = 1ull << 23,
1124bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_RASTERIZER_DISCARD_ENABLE = 1ull << 24,
1125bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS_ENABLE = 1ull << 25,
1126bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_LOGIC_OP = 1ull << 26,
1127bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_PRIMITIVE_RESTART_ENABLE = 1ull << 27,
1128bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_COLOR_WRITE_ENABLE = 1ull << 28,
1129bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_VERTEX_INPUT = 1ull << 29,
1130bf215546Sopenharmony_ci   RADV_CMD_DIRTY_DYNAMIC_ALL = (1ull << 30) - 1,
1131bf215546Sopenharmony_ci   RADV_CMD_DIRTY_PIPELINE = 1ull << 30,
1132bf215546Sopenharmony_ci   RADV_CMD_DIRTY_INDEX_BUFFER = 1ull << 31,
1133bf215546Sopenharmony_ci   RADV_CMD_DIRTY_FRAMEBUFFER = 1ull << 32,
1134bf215546Sopenharmony_ci   RADV_CMD_DIRTY_VERTEX_BUFFER = 1ull << 33,
1135bf215546Sopenharmony_ci   RADV_CMD_DIRTY_STREAMOUT_BUFFER = 1ull << 34,
1136bf215546Sopenharmony_ci};
1137bf215546Sopenharmony_ci
1138bf215546Sopenharmony_cienum radv_cmd_flush_bits {
1139bf215546Sopenharmony_ci   /* Instruction cache. */
1140bf215546Sopenharmony_ci   RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
1141bf215546Sopenharmony_ci   /* Scalar L1 cache. */
1142bf215546Sopenharmony_ci   RADV_CMD_FLAG_INV_SCACHE = 1 << 1,
1143bf215546Sopenharmony_ci   /* Vector L1 cache. */
1144bf215546Sopenharmony_ci   RADV_CMD_FLAG_INV_VCACHE = 1 << 2,
1145bf215546Sopenharmony_ci   /* L2 cache + L2 metadata cache writeback & invalidate.
1146bf215546Sopenharmony_ci    * GFX6-8: Used by shaders only. GFX9-10: Used by everything. */
1147bf215546Sopenharmony_ci   RADV_CMD_FLAG_INV_L2 = 1 << 3,
1148bf215546Sopenharmony_ci   /* L2 writeback (write dirty L2 lines to memory for non-L2 clients).
1149bf215546Sopenharmony_ci    * Only used for coherency with non-L2 clients like CB, DB, CP on GFX6-8.
1150bf215546Sopenharmony_ci    * GFX6-7 will do complete invalidation, because the writeback is unsupported. */
1151bf215546Sopenharmony_ci   RADV_CMD_FLAG_WB_L2 = 1 << 4,
1152bf215546Sopenharmony_ci   /* Invalidate the metadata cache. To be used when the DCC/HTILE metadata
1153bf215546Sopenharmony_ci    * changed and we want to read an image from shaders. */
1154bf215546Sopenharmony_ci   RADV_CMD_FLAG_INV_L2_METADATA = 1 << 5,
1155bf215546Sopenharmony_ci   /* Framebuffer caches */
1156bf215546Sopenharmony_ci   RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 6,
1157bf215546Sopenharmony_ci   RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 7,
1158bf215546Sopenharmony_ci   RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 8,
1159bf215546Sopenharmony_ci   RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 9,
1160bf215546Sopenharmony_ci   /* Engine synchronization. */
1161bf215546Sopenharmony_ci   RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 10,
1162bf215546Sopenharmony_ci   RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 11,
1163bf215546Sopenharmony_ci   RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 12,
1164bf215546Sopenharmony_ci   RADV_CMD_FLAG_VGT_FLUSH = 1 << 13,
1165bf215546Sopenharmony_ci   /* Pipeline query controls. */
1166bf215546Sopenharmony_ci   RADV_CMD_FLAG_START_PIPELINE_STATS = 1 << 14,
1167bf215546Sopenharmony_ci   RADV_CMD_FLAG_STOP_PIPELINE_STATS = 1 << 15,
1168bf215546Sopenharmony_ci   RADV_CMD_FLAG_VGT_STREAMOUT_SYNC = 1 << 16,
1169bf215546Sopenharmony_ci
1170bf215546Sopenharmony_ci   RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER =
1171bf215546Sopenharmony_ci      (RADV_CMD_FLAG_FLUSH_AND_INV_CB | RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
1172bf215546Sopenharmony_ci       RADV_CMD_FLAG_FLUSH_AND_INV_DB | RADV_CMD_FLAG_FLUSH_AND_INV_DB_META),
1173bf215546Sopenharmony_ci
1174bf215546Sopenharmony_ci   RADV_CMD_FLUSH_ALL_COMPUTE =
1175bf215546Sopenharmony_ci      (RADV_CMD_FLAG_INV_ICACHE | RADV_CMD_FLAG_INV_SCACHE | RADV_CMD_FLAG_INV_VCACHE |
1176bf215546Sopenharmony_ci       RADV_CMD_FLAG_INV_L2 | RADV_CMD_FLAG_WB_L2 | RADV_CMD_FLAG_CS_PARTIAL_FLUSH),
1177bf215546Sopenharmony_ci};
1178bf215546Sopenharmony_ci
1179bf215546Sopenharmony_cienum radv_nggc_settings {
1180bf215546Sopenharmony_ci   radv_nggc_none = 0,
1181bf215546Sopenharmony_ci   radv_nggc_front_face = 1 << 0,
1182bf215546Sopenharmony_ci   radv_nggc_back_face = 1 << 1,
1183bf215546Sopenharmony_ci   radv_nggc_face_is_ccw = 1 << 2,
1184bf215546Sopenharmony_ci   radv_nggc_small_primitives = 1 << 3,
1185bf215546Sopenharmony_ci};
1186bf215546Sopenharmony_ci
1187bf215546Sopenharmony_cistruct radv_vertex_binding {
1188bf215546Sopenharmony_ci   VkDeviceSize offset;
1189bf215546Sopenharmony_ci   VkDeviceSize size;
1190bf215546Sopenharmony_ci   VkDeviceSize stride;
1191bf215546Sopenharmony_ci};
1192bf215546Sopenharmony_ci
1193bf215546Sopenharmony_cistruct radv_streamout_binding {
1194bf215546Sopenharmony_ci   struct radv_buffer *buffer;
1195bf215546Sopenharmony_ci   VkDeviceSize offset;
1196bf215546Sopenharmony_ci   VkDeviceSize size;
1197bf215546Sopenharmony_ci};
1198bf215546Sopenharmony_ci
1199bf215546Sopenharmony_cistruct radv_streamout_state {
1200bf215546Sopenharmony_ci   /* Mask of bound streamout buffers. */
1201bf215546Sopenharmony_ci   uint8_t enabled_mask;
1202bf215546Sopenharmony_ci
1203bf215546Sopenharmony_ci   /* State of VGT_STRMOUT_BUFFER_(CONFIG|END) */
1204bf215546Sopenharmony_ci   uint32_t hw_enabled_mask;
1205bf215546Sopenharmony_ci
1206bf215546Sopenharmony_ci   /* State of VGT_STRMOUT_(CONFIG|EN) */
1207bf215546Sopenharmony_ci   bool streamout_enabled;
1208bf215546Sopenharmony_ci};
1209bf215546Sopenharmony_ci
1210bf215546Sopenharmony_cistruct radv_viewport_state {
1211bf215546Sopenharmony_ci   uint32_t count;
1212bf215546Sopenharmony_ci   VkViewport viewports[MAX_VIEWPORTS];
1213bf215546Sopenharmony_ci   struct {
1214bf215546Sopenharmony_ci      float scale[3];
1215bf215546Sopenharmony_ci      float translate[3];
1216bf215546Sopenharmony_ci   } xform[MAX_VIEWPORTS];
1217bf215546Sopenharmony_ci};
1218bf215546Sopenharmony_ci
1219bf215546Sopenharmony_cistruct radv_scissor_state {
1220bf215546Sopenharmony_ci   uint32_t count;
1221bf215546Sopenharmony_ci   VkRect2D scissors[MAX_SCISSORS];
1222bf215546Sopenharmony_ci};
1223bf215546Sopenharmony_ci
1224bf215546Sopenharmony_cistruct radv_discard_rectangle_state {
1225bf215546Sopenharmony_ci   uint32_t count;
1226bf215546Sopenharmony_ci   VkRect2D rectangles[MAX_DISCARD_RECTANGLES];
1227bf215546Sopenharmony_ci};
1228bf215546Sopenharmony_ci
1229bf215546Sopenharmony_cistruct radv_sample_locations_state {
1230bf215546Sopenharmony_ci   VkSampleCountFlagBits per_pixel;
1231bf215546Sopenharmony_ci   VkExtent2D grid_size;
1232bf215546Sopenharmony_ci   uint32_t count;
1233bf215546Sopenharmony_ci   VkSampleLocationEXT locations[MAX_SAMPLE_LOCATIONS];
1234bf215546Sopenharmony_ci};
1235bf215546Sopenharmony_ci
1236bf215546Sopenharmony_cistruct radv_dynamic_state {
1237bf215546Sopenharmony_ci   /**
1238bf215546Sopenharmony_ci    * Bitmask of (1ull << VK_DYNAMIC_STATE_*).
1239bf215546Sopenharmony_ci    * Defines the set of saved dynamic state.
1240bf215546Sopenharmony_ci    */
1241bf215546Sopenharmony_ci   uint64_t mask;
1242bf215546Sopenharmony_ci
1243bf215546Sopenharmony_ci   struct radv_viewport_state viewport;
1244bf215546Sopenharmony_ci
1245bf215546Sopenharmony_ci   struct radv_scissor_state scissor;
1246bf215546Sopenharmony_ci
1247bf215546Sopenharmony_ci   float line_width;
1248bf215546Sopenharmony_ci
1249bf215546Sopenharmony_ci   struct {
1250bf215546Sopenharmony_ci      float bias;
1251bf215546Sopenharmony_ci      float clamp;
1252bf215546Sopenharmony_ci      float slope;
1253bf215546Sopenharmony_ci   } depth_bias;
1254bf215546Sopenharmony_ci
1255bf215546Sopenharmony_ci   float blend_constants[4];
1256bf215546Sopenharmony_ci
1257bf215546Sopenharmony_ci   struct {
1258bf215546Sopenharmony_ci      float min;
1259bf215546Sopenharmony_ci      float max;
1260bf215546Sopenharmony_ci   } depth_bounds;
1261bf215546Sopenharmony_ci
1262bf215546Sopenharmony_ci   struct {
1263bf215546Sopenharmony_ci      uint32_t front;
1264bf215546Sopenharmony_ci      uint32_t back;
1265bf215546Sopenharmony_ci   } stencil_compare_mask;
1266bf215546Sopenharmony_ci
1267bf215546Sopenharmony_ci   struct {
1268bf215546Sopenharmony_ci      uint32_t front;
1269bf215546Sopenharmony_ci      uint32_t back;
1270bf215546Sopenharmony_ci   } stencil_write_mask;
1271bf215546Sopenharmony_ci
1272bf215546Sopenharmony_ci   struct {
1273bf215546Sopenharmony_ci      struct {
1274bf215546Sopenharmony_ci         VkStencilOp fail_op;
1275bf215546Sopenharmony_ci         VkStencilOp pass_op;
1276bf215546Sopenharmony_ci         VkStencilOp depth_fail_op;
1277bf215546Sopenharmony_ci         VkCompareOp compare_op;
1278bf215546Sopenharmony_ci      } front;
1279bf215546Sopenharmony_ci
1280bf215546Sopenharmony_ci      struct {
1281bf215546Sopenharmony_ci         VkStencilOp fail_op;
1282bf215546Sopenharmony_ci         VkStencilOp pass_op;
1283bf215546Sopenharmony_ci         VkStencilOp depth_fail_op;
1284bf215546Sopenharmony_ci         VkCompareOp compare_op;
1285bf215546Sopenharmony_ci      } back;
1286bf215546Sopenharmony_ci   } stencil_op;
1287bf215546Sopenharmony_ci
1288bf215546Sopenharmony_ci   struct {
1289bf215546Sopenharmony_ci      uint32_t front;
1290bf215546Sopenharmony_ci      uint32_t back;
1291bf215546Sopenharmony_ci   } stencil_reference;
1292bf215546Sopenharmony_ci
1293bf215546Sopenharmony_ci   struct radv_discard_rectangle_state discard_rectangle;
1294bf215546Sopenharmony_ci
1295bf215546Sopenharmony_ci   struct radv_sample_locations_state sample_location;
1296bf215546Sopenharmony_ci
1297bf215546Sopenharmony_ci   struct {
1298bf215546Sopenharmony_ci      uint32_t factor;
1299bf215546Sopenharmony_ci      uint16_t pattern;
1300bf215546Sopenharmony_ci   } line_stipple;
1301bf215546Sopenharmony_ci
1302bf215546Sopenharmony_ci   VkCullModeFlags cull_mode;
1303bf215546Sopenharmony_ci   VkFrontFace front_face;
1304bf215546Sopenharmony_ci   unsigned primitive_topology;
1305bf215546Sopenharmony_ci
1306bf215546Sopenharmony_ci   bool depth_test_enable;
1307bf215546Sopenharmony_ci   bool depth_write_enable;
1308bf215546Sopenharmony_ci   VkCompareOp depth_compare_op;
1309bf215546Sopenharmony_ci   bool depth_bounds_test_enable;
1310bf215546Sopenharmony_ci   bool stencil_test_enable;
1311bf215546Sopenharmony_ci
1312bf215546Sopenharmony_ci   struct {
1313bf215546Sopenharmony_ci      VkExtent2D size;
1314bf215546Sopenharmony_ci      VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
1315bf215546Sopenharmony_ci   } fragment_shading_rate;
1316bf215546Sopenharmony_ci
1317bf215546Sopenharmony_ci   bool depth_bias_enable;
1318bf215546Sopenharmony_ci   bool primitive_restart_enable;
1319bf215546Sopenharmony_ci   bool rasterizer_discard_enable;
1320bf215546Sopenharmony_ci
1321bf215546Sopenharmony_ci   unsigned logic_op;
1322bf215546Sopenharmony_ci
1323bf215546Sopenharmony_ci   uint32_t color_write_enable;
1324bf215546Sopenharmony_ci};
1325bf215546Sopenharmony_ci
1326bf215546Sopenharmony_ciextern const struct radv_dynamic_state default_dynamic_state;
1327bf215546Sopenharmony_ci
1328bf215546Sopenharmony_ciconst char *radv_get_debug_option_name(int id);
1329bf215546Sopenharmony_ci
1330bf215546Sopenharmony_ciconst char *radv_get_perftest_option_name(int id);
1331bf215546Sopenharmony_ci
1332bf215546Sopenharmony_ciint radv_get_int_debug_option(const char *name, int default_value);
1333bf215546Sopenharmony_ci
1334bf215546Sopenharmony_cistruct radv_color_buffer_info {
1335bf215546Sopenharmony_ci   uint64_t cb_color_base;
1336bf215546Sopenharmony_ci   uint64_t cb_color_cmask;
1337bf215546Sopenharmony_ci   uint64_t cb_color_fmask;
1338bf215546Sopenharmony_ci   uint64_t cb_dcc_base;
1339bf215546Sopenharmony_ci   uint32_t cb_color_slice;
1340bf215546Sopenharmony_ci   uint32_t cb_color_view;
1341bf215546Sopenharmony_ci   uint32_t cb_color_info;
1342bf215546Sopenharmony_ci   uint32_t cb_color_attrib;
1343bf215546Sopenharmony_ci   uint32_t cb_color_attrib2; /* GFX9 and later */
1344bf215546Sopenharmony_ci   uint32_t cb_color_attrib3; /* GFX10 and later */
1345bf215546Sopenharmony_ci   uint32_t cb_dcc_control;
1346bf215546Sopenharmony_ci   uint32_t cb_color_cmask_slice;
1347bf215546Sopenharmony_ci   uint32_t cb_color_fmask_slice;
1348bf215546Sopenharmony_ci   union {
1349bf215546Sopenharmony_ci      uint32_t cb_color_pitch; // GFX6-GFX8
1350bf215546Sopenharmony_ci      uint32_t cb_mrt_epitch;  // GFX9+
1351bf215546Sopenharmony_ci   };
1352bf215546Sopenharmony_ci};
1353bf215546Sopenharmony_ci
1354bf215546Sopenharmony_cistruct radv_ds_buffer_info {
1355bf215546Sopenharmony_ci   uint64_t db_z_read_base;
1356bf215546Sopenharmony_ci   uint64_t db_stencil_read_base;
1357bf215546Sopenharmony_ci   uint64_t db_z_write_base;
1358bf215546Sopenharmony_ci   uint64_t db_stencil_write_base;
1359bf215546Sopenharmony_ci   uint64_t db_htile_data_base;
1360bf215546Sopenharmony_ci   uint32_t db_depth_info;
1361bf215546Sopenharmony_ci   uint32_t db_z_info;
1362bf215546Sopenharmony_ci   uint32_t db_stencil_info;
1363bf215546Sopenharmony_ci   uint32_t db_depth_view;
1364bf215546Sopenharmony_ci   uint32_t db_depth_size;
1365bf215546Sopenharmony_ci   uint32_t db_depth_slice;
1366bf215546Sopenharmony_ci   uint32_t db_htile_surface;
1367bf215546Sopenharmony_ci   uint32_t pa_su_poly_offset_db_fmt_cntl;
1368bf215546Sopenharmony_ci   uint32_t db_z_info2;       /* GFX9 only */
1369bf215546Sopenharmony_ci   uint32_t db_stencil_info2; /* GFX9 only */
1370bf215546Sopenharmony_ci};
1371bf215546Sopenharmony_ci
1372bf215546Sopenharmony_civoid radv_initialise_color_surface(struct radv_device *device, struct radv_color_buffer_info *cb,
1373bf215546Sopenharmony_ci                                   struct radv_image_view *iview);
1374bf215546Sopenharmony_civoid radv_initialise_ds_surface(struct radv_device *device, struct radv_ds_buffer_info *ds,
1375bf215546Sopenharmony_ci                                struct radv_image_view *iview);
1376bf215546Sopenharmony_civoid radv_initialise_vrs_surface(struct radv_image *image, struct radv_buffer *htile_buffer,
1377bf215546Sopenharmony_ci                                 struct radv_ds_buffer_info *ds);
1378bf215546Sopenharmony_ci
1379bf215546Sopenharmony_ci/**
1380bf215546Sopenharmony_ci * Attachment state when recording a renderpass instance.
1381bf215546Sopenharmony_ci *
1382bf215546Sopenharmony_ci * The clear value is valid only if there exists a pending clear.
1383bf215546Sopenharmony_ci */
1384bf215546Sopenharmony_cistruct radv_attachment_state {
1385bf215546Sopenharmony_ci   VkImageAspectFlags pending_clear_aspects;
1386bf215546Sopenharmony_ci   uint32_t cleared_views;
1387bf215546Sopenharmony_ci   VkClearValue clear_value;
1388bf215546Sopenharmony_ci   VkImageLayout current_layout;
1389bf215546Sopenharmony_ci   VkImageLayout current_stencil_layout;
1390bf215546Sopenharmony_ci   bool current_in_render_loop;
1391bf215546Sopenharmony_ci   struct radv_sample_locations_state sample_location;
1392bf215546Sopenharmony_ci
1393bf215546Sopenharmony_ci   union {
1394bf215546Sopenharmony_ci      struct radv_color_buffer_info cb;
1395bf215546Sopenharmony_ci      struct radv_ds_buffer_info ds;
1396bf215546Sopenharmony_ci   };
1397bf215546Sopenharmony_ci   struct radv_image_view *iview;
1398bf215546Sopenharmony_ci};
1399bf215546Sopenharmony_ci
1400bf215546Sopenharmony_cistruct radv_descriptor_state {
1401bf215546Sopenharmony_ci   struct radv_descriptor_set *sets[MAX_SETS];
1402bf215546Sopenharmony_ci   uint32_t dirty;
1403bf215546Sopenharmony_ci   uint32_t valid;
1404bf215546Sopenharmony_ci   struct radv_push_descriptor_set push_set;
1405bf215546Sopenharmony_ci   bool push_dirty;
1406bf215546Sopenharmony_ci   uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
1407bf215546Sopenharmony_ci};
1408bf215546Sopenharmony_ci
1409bf215546Sopenharmony_cistruct radv_subpass_sample_locs_state {
1410bf215546Sopenharmony_ci   uint32_t subpass_idx;
1411bf215546Sopenharmony_ci   struct radv_sample_locations_state sample_location;
1412bf215546Sopenharmony_ci};
1413bf215546Sopenharmony_ci
1414bf215546Sopenharmony_cienum rgp_flush_bits {
1415bf215546Sopenharmony_ci   RGP_FLUSH_WAIT_ON_EOP_TS = 0x1,
1416bf215546Sopenharmony_ci   RGP_FLUSH_VS_PARTIAL_FLUSH = 0x2,
1417bf215546Sopenharmony_ci   RGP_FLUSH_PS_PARTIAL_FLUSH = 0x4,
1418bf215546Sopenharmony_ci   RGP_FLUSH_CS_PARTIAL_FLUSH = 0x8,
1419bf215546Sopenharmony_ci   RGP_FLUSH_PFP_SYNC_ME = 0x10,
1420bf215546Sopenharmony_ci   RGP_FLUSH_SYNC_CP_DMA = 0x20,
1421bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_VMEM_L0 = 0x40,
1422bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_ICACHE = 0x80,
1423bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_SMEM_L0 = 0x100,
1424bf215546Sopenharmony_ci   RGP_FLUSH_FLUSH_L2 = 0x200,
1425bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_L2 = 0x400,
1426bf215546Sopenharmony_ci   RGP_FLUSH_FLUSH_CB = 0x800,
1427bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_CB = 0x1000,
1428bf215546Sopenharmony_ci   RGP_FLUSH_FLUSH_DB = 0x2000,
1429bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_DB = 0x4000,
1430bf215546Sopenharmony_ci   RGP_FLUSH_INVAL_L1 = 0x8000,
1431bf215546Sopenharmony_ci};
1432bf215546Sopenharmony_ci
1433bf215546Sopenharmony_cistruct radv_cmd_state {
1434bf215546Sopenharmony_ci   /* Vertex descriptors */
1435bf215546Sopenharmony_ci   uint64_t vb_va;
1436bf215546Sopenharmony_ci
1437bf215546Sopenharmony_ci   bool predicating;
1438bf215546Sopenharmony_ci   uint64_t dirty;
1439bf215546Sopenharmony_ci
1440bf215546Sopenharmony_ci   uint32_t prefetch_L2_mask;
1441bf215546Sopenharmony_ci
1442bf215546Sopenharmony_ci   struct radv_graphics_pipeline *graphics_pipeline;
1443bf215546Sopenharmony_ci   struct radv_graphics_pipeline *emitted_graphics_pipeline;
1444bf215546Sopenharmony_ci   struct radv_compute_pipeline *compute_pipeline;
1445bf215546Sopenharmony_ci   struct radv_compute_pipeline *emitted_compute_pipeline;
1446bf215546Sopenharmony_ci   struct radv_compute_pipeline *rt_pipeline; /* emitted = emitted_compute_pipeline */
1447bf215546Sopenharmony_ci   struct vk_framebuffer *framebuffer;
1448bf215546Sopenharmony_ci   struct radv_render_pass *pass;
1449bf215546Sopenharmony_ci   const struct radv_subpass *subpass;
1450bf215546Sopenharmony_ci   struct radv_dynamic_state dynamic;
1451bf215546Sopenharmony_ci   struct radv_vs_input_state dynamic_vs_input;
1452bf215546Sopenharmony_ci   struct radv_attachment_state *attachments;
1453bf215546Sopenharmony_ci   struct radv_streamout_state streamout;
1454bf215546Sopenharmony_ci   VkRect2D render_area;
1455bf215546Sopenharmony_ci
1456bf215546Sopenharmony_ci   uint32_t num_subpass_sample_locs;
1457bf215546Sopenharmony_ci   struct radv_subpass_sample_locs_state *subpass_sample_locs;
1458bf215546Sopenharmony_ci
1459bf215546Sopenharmony_ci   /* Index buffer */
1460bf215546Sopenharmony_ci   struct radv_buffer *index_buffer;
1461bf215546Sopenharmony_ci   uint64_t index_offset;
1462bf215546Sopenharmony_ci   uint32_t index_type;
1463bf215546Sopenharmony_ci   uint32_t max_index_count;
1464bf215546Sopenharmony_ci   uint64_t index_va;
1465bf215546Sopenharmony_ci   int32_t last_index_type;
1466bf215546Sopenharmony_ci
1467bf215546Sopenharmony_ci   int32_t last_primitive_reset_en;
1468bf215546Sopenharmony_ci   uint32_t last_primitive_reset_index;
1469bf215546Sopenharmony_ci   enum radv_cmd_flush_bits flush_bits;
1470bf215546Sopenharmony_ci   unsigned active_occlusion_queries;
1471bf215546Sopenharmony_ci   bool perfect_occlusion_queries_enabled;
1472bf215546Sopenharmony_ci   unsigned active_pipeline_queries;
1473bf215546Sopenharmony_ci   unsigned active_pipeline_gds_queries;
1474bf215546Sopenharmony_ci   bool prims_gen_query_enabled;
1475bf215546Sopenharmony_ci   uint32_t trace_id;
1476bf215546Sopenharmony_ci   uint32_t last_ia_multi_vgt_param;
1477bf215546Sopenharmony_ci
1478bf215546Sopenharmony_ci   uint32_t last_num_instances;
1479bf215546Sopenharmony_ci   uint32_t last_first_instance;
1480bf215546Sopenharmony_ci   uint32_t last_vertex_offset;
1481bf215546Sopenharmony_ci   uint32_t last_drawid;
1482bf215546Sopenharmony_ci   uint32_t last_subpass_color_count;
1483bf215546Sopenharmony_ci
1484bf215546Sopenharmony_ci   uint32_t last_sx_ps_downconvert;
1485bf215546Sopenharmony_ci   uint32_t last_sx_blend_opt_epsilon;
1486bf215546Sopenharmony_ci   uint32_t last_sx_blend_opt_control;
1487bf215546Sopenharmony_ci
1488bf215546Sopenharmony_ci   /* Whether CP DMA is busy/idle. */
1489bf215546Sopenharmony_ci   bool dma_is_busy;
1490bf215546Sopenharmony_ci
1491bf215546Sopenharmony_ci   /* Whether any images that are not L2 coherent are dirty from the CB. */
1492bf215546Sopenharmony_ci   bool rb_noncoherent_dirty;
1493bf215546Sopenharmony_ci
1494bf215546Sopenharmony_ci   /* Conditional rendering info. */
1495bf215546Sopenharmony_ci   uint8_t predication_op; /* 32-bit or 64-bit predicate value */
1496bf215546Sopenharmony_ci   int predication_type;   /* -1: disabled, 0: normal, 1: inverted */
1497bf215546Sopenharmony_ci   uint64_t predication_va;
1498bf215546Sopenharmony_ci
1499bf215546Sopenharmony_ci   /* Inheritance info. */
1500bf215546Sopenharmony_ci   VkQueryPipelineStatisticFlags inherited_pipeline_statistics;
1501bf215546Sopenharmony_ci
1502bf215546Sopenharmony_ci   bool context_roll_without_scissor_emitted;
1503bf215546Sopenharmony_ci
1504bf215546Sopenharmony_ci   /* SQTT related state. */
1505bf215546Sopenharmony_ci   uint32_t current_event_type;
1506bf215546Sopenharmony_ci   uint32_t num_events;
1507bf215546Sopenharmony_ci   uint32_t num_layout_transitions;
1508bf215546Sopenharmony_ci   bool pending_sqtt_barrier_end;
1509bf215546Sopenharmony_ci   enum rgp_flush_bits sqtt_flush_bits;
1510bf215546Sopenharmony_ci
1511bf215546Sopenharmony_ci   /* NGG culling state. */
1512bf215546Sopenharmony_ci   uint32_t last_nggc_settings;
1513bf215546Sopenharmony_ci   int8_t last_nggc_settings_sgpr_idx;
1514bf215546Sopenharmony_ci   bool last_nggc_skip;
1515bf215546Sopenharmony_ci
1516bf215546Sopenharmony_ci   /* Mesh shading state. */
1517bf215546Sopenharmony_ci   bool mesh_shading;
1518bf215546Sopenharmony_ci
1519bf215546Sopenharmony_ci   uint8_t cb_mip[MAX_RTS];
1520bf215546Sopenharmony_ci
1521bf215546Sopenharmony_ci   /* Whether DRAW_{INDEX}_INDIRECT_MULTI is emitted. */
1522bf215546Sopenharmony_ci   bool uses_draw_indirect_multi;
1523bf215546Sopenharmony_ci
1524bf215546Sopenharmony_ci   uint32_t rt_stack_size;
1525bf215546Sopenharmony_ci
1526bf215546Sopenharmony_ci   struct radv_shader_part *emitted_vs_prolog;
1527bf215546Sopenharmony_ci   uint32_t *emitted_vs_prolog_key;
1528bf215546Sopenharmony_ci   uint32_t emitted_vs_prolog_key_hash;
1529bf215546Sopenharmony_ci   uint32_t vbo_misaligned_mask;
1530bf215546Sopenharmony_ci   uint32_t vbo_misaligned_mask_invalid;
1531bf215546Sopenharmony_ci   uint32_t vbo_bound_mask;
1532bf215546Sopenharmony_ci
1533bf215546Sopenharmony_ci   /* Whether the cmdbuffer owns the current render pass rather than the app. */
1534bf215546Sopenharmony_ci   bool own_render_pass;
1535bf215546Sopenharmony_ci
1536bf215546Sopenharmony_ci   /* Per-vertex VRS state. */
1537bf215546Sopenharmony_ci   uint32_t last_vrs_rates;
1538bf215546Sopenharmony_ci   int8_t last_vrs_rates_sgpr_idx;
1539bf215546Sopenharmony_ci
1540bf215546Sopenharmony_ci   /* Whether to suspend streamout for internal driver operations. */
1541bf215546Sopenharmony_ci   bool suspend_streamout;
1542bf215546Sopenharmony_ci
1543bf215546Sopenharmony_ci   /* Whether this commandbuffer uses performance counters. */
1544bf215546Sopenharmony_ci   bool uses_perf_counters;
1545bf215546Sopenharmony_ci};
1546bf215546Sopenharmony_ci
1547bf215546Sopenharmony_cistruct radv_cmd_pool {
1548bf215546Sopenharmony_ci   struct vk_command_pool vk;
1549bf215546Sopenharmony_ci   struct list_head cmd_buffers;
1550bf215546Sopenharmony_ci   struct list_head free_cmd_buffers;
1551bf215546Sopenharmony_ci};
1552bf215546Sopenharmony_ci
1553bf215546Sopenharmony_cistruct radv_cmd_buffer_upload {
1554bf215546Sopenharmony_ci   uint8_t *map;
1555bf215546Sopenharmony_ci   unsigned offset;
1556bf215546Sopenharmony_ci   uint64_t size;
1557bf215546Sopenharmony_ci   struct radeon_winsys_bo *upload_bo;
1558bf215546Sopenharmony_ci   struct list_head list;
1559bf215546Sopenharmony_ci};
1560bf215546Sopenharmony_ci
1561bf215546Sopenharmony_cienum radv_cmd_buffer_status {
1562bf215546Sopenharmony_ci   RADV_CMD_BUFFER_STATUS_INVALID,
1563bf215546Sopenharmony_ci   RADV_CMD_BUFFER_STATUS_INITIAL,
1564bf215546Sopenharmony_ci   RADV_CMD_BUFFER_STATUS_RECORDING,
1565bf215546Sopenharmony_ci   RADV_CMD_BUFFER_STATUS_EXECUTABLE,
1566bf215546Sopenharmony_ci   RADV_CMD_BUFFER_STATUS_PENDING,
1567bf215546Sopenharmony_ci};
1568bf215546Sopenharmony_ci
1569bf215546Sopenharmony_cistruct dynamic_vertex_format_cache {
1570bf215546Sopenharmony_ci   VkFormat format;
1571bf215546Sopenharmony_ci   uint8_t hw_fmt;
1572bf215546Sopenharmony_ci   uint8_t fmt_align_req_minus_1;
1573bf215546Sopenharmony_ci   uint8_t fmt_size;
1574bf215546Sopenharmony_ci   bool post_shuffle;
1575bf215546Sopenharmony_ci   bool alpha_adjust_lo;
1576bf215546Sopenharmony_ci   bool alpha_adjust_hi;
1577bf215546Sopenharmony_ci};
1578bf215546Sopenharmony_ci
1579bf215546Sopenharmony_cistruct radv_cmd_buffer {
1580bf215546Sopenharmony_ci   struct vk_command_buffer vk;
1581bf215546Sopenharmony_ci
1582bf215546Sopenharmony_ci   struct radv_device *device;
1583bf215546Sopenharmony_ci
1584bf215546Sopenharmony_ci   struct radv_cmd_pool *pool;
1585bf215546Sopenharmony_ci   struct list_head pool_link;
1586bf215546Sopenharmony_ci
1587bf215546Sopenharmony_ci   struct util_dynarray cached_vertex_formats;
1588bf215546Sopenharmony_ci   VkCommandBufferUsageFlags usage_flags;
1589bf215546Sopenharmony_ci   enum radv_cmd_buffer_status status;
1590bf215546Sopenharmony_ci   struct radeon_cmdbuf *cs;
1591bf215546Sopenharmony_ci   struct radv_cmd_state state;
1592bf215546Sopenharmony_ci   struct radv_buffer *vertex_binding_buffers[MAX_VBS];
1593bf215546Sopenharmony_ci   struct radv_vertex_binding vertex_bindings[MAX_VBS];
1594bf215546Sopenharmony_ci   uint32_t used_vertex_bindings;
1595bf215546Sopenharmony_ci   struct radv_streamout_binding streamout_bindings[MAX_SO_BUFFERS];
1596bf215546Sopenharmony_ci   enum radv_queue_family qf;
1597bf215546Sopenharmony_ci
1598bf215546Sopenharmony_ci   uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
1599bf215546Sopenharmony_ci   VkShaderStageFlags push_constant_stages;
1600bf215546Sopenharmony_ci   struct radv_descriptor_set_header meta_push_descriptors;
1601bf215546Sopenharmony_ci
1602bf215546Sopenharmony_ci   struct radv_descriptor_state descriptors[MAX_BIND_POINTS];
1603bf215546Sopenharmony_ci
1604bf215546Sopenharmony_ci   struct radv_cmd_buffer_upload upload;
1605bf215546Sopenharmony_ci
1606bf215546Sopenharmony_ci   uint32_t scratch_size_per_wave_needed;
1607bf215546Sopenharmony_ci   uint32_t scratch_waves_wanted;
1608bf215546Sopenharmony_ci   uint32_t compute_scratch_size_per_wave_needed;
1609bf215546Sopenharmony_ci   uint32_t compute_scratch_waves_wanted;
1610bf215546Sopenharmony_ci   uint32_t esgs_ring_size_needed;
1611bf215546Sopenharmony_ci   uint32_t gsvs_ring_size_needed;
1612bf215546Sopenharmony_ci   bool tess_rings_needed;
1613bf215546Sopenharmony_ci   bool task_rings_needed;
1614bf215546Sopenharmony_ci   bool mesh_scratch_ring_needed;
1615bf215546Sopenharmony_ci   bool gds_needed;    /* for GFX10 streamout and NGG GS queries */
1616bf215546Sopenharmony_ci   bool gds_oa_needed; /* for GFX10 streamout */
1617bf215546Sopenharmony_ci   bool sample_positions_needed;
1618bf215546Sopenharmony_ci
1619bf215546Sopenharmony_ci   VkResult record_result;
1620bf215546Sopenharmony_ci
1621bf215546Sopenharmony_ci   uint64_t gfx9_fence_va;
1622bf215546Sopenharmony_ci   uint32_t gfx9_fence_idx;
1623bf215546Sopenharmony_ci   uint64_t gfx9_eop_bug_va;
1624bf215546Sopenharmony_ci
1625bf215546Sopenharmony_ci   uint64_t mec_inv_pred_va;  /* For inverted predication when using MEC. */
1626bf215546Sopenharmony_ci   bool mec_inv_pred_emitted; /* To ensure we don't have to repeat inverting the VA. */
1627bf215546Sopenharmony_ci
1628bf215546Sopenharmony_ci   struct {
1629bf215546Sopenharmony_ci      /**
1630bf215546Sopenharmony_ci       * Internal command stream that is used when some graphics work
1631bf215546Sopenharmony_ci       * also requires a submission to the compute queue.
1632bf215546Sopenharmony_ci       */
1633bf215546Sopenharmony_ci      struct radeon_cmdbuf *cs;
1634bf215546Sopenharmony_ci
1635bf215546Sopenharmony_ci      /** Flush bits for the internal cmdbuf. */
1636bf215546Sopenharmony_ci      enum radv_cmd_flush_bits flush_bits;
1637bf215546Sopenharmony_ci
1638bf215546Sopenharmony_ci      /**
1639bf215546Sopenharmony_ci       * For synchronization between the ACE and GFX cmdbuf.
1640bf215546Sopenharmony_ci       * The value of this semaphore is incremented whenever we
1641bf215546Sopenharmony_ci       * encounter a barrier that affects ACE. At sync points,
1642bf215546Sopenharmony_ci       * GFX writes the value to its address, and ACE waits until
1643bf215546Sopenharmony_ci       * it detects that the value has been written.
1644bf215546Sopenharmony_ci       */
1645bf215546Sopenharmony_ci      struct {
1646bf215546Sopenharmony_ci         uint64_t va;                    /* Virtual address of the semaphore. */
1647bf215546Sopenharmony_ci         uint32_t gfx2ace_value;         /* Current value on GFX. */
1648bf215546Sopenharmony_ci         uint32_t emitted_gfx2ace_value; /* Emitted value on GFX. */
1649bf215546Sopenharmony_ci      } sem;
1650bf215546Sopenharmony_ci   } ace_internal;
1651bf215546Sopenharmony_ci
1652bf215546Sopenharmony_ci   /**
1653bf215546Sopenharmony_ci    * Whether a query pool has been resetted and we have to flush caches.
1654bf215546Sopenharmony_ci    */
1655bf215546Sopenharmony_ci   bool pending_reset_query;
1656bf215546Sopenharmony_ci
1657bf215546Sopenharmony_ci   /**
1658bf215546Sopenharmony_ci    * Bitmask of pending active query flushes.
1659bf215546Sopenharmony_ci    */
1660bf215546Sopenharmony_ci   enum radv_cmd_flush_bits active_query_flush_bits;
1661bf215546Sopenharmony_ci};
1662bf215546Sopenharmony_ci
1663bf215546Sopenharmony_cistruct radv_image;
1664bf215546Sopenharmony_cistruct radv_image_view;
1665bf215546Sopenharmony_ci
1666bf215546Sopenharmony_cibool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
1667bf215546Sopenharmony_ci
1668bf215546Sopenharmony_cibool radv_is_streamout_enabled(struct radv_cmd_buffer *cmd_buffer);
1669bf215546Sopenharmony_civoid radv_emit_streamout_enable(struct radv_cmd_buffer *cmd_buffer);
1670bf215546Sopenharmony_ci
1671bf215546Sopenharmony_civoid si_emit_graphics(struct radv_device *device, struct radeon_cmdbuf *cs);
1672bf215546Sopenharmony_civoid si_emit_compute(struct radv_device *device, struct radeon_cmdbuf *cs);
1673bf215546Sopenharmony_ci
1674bf215546Sopenharmony_civoid cik_create_gfx_config(struct radv_device *device);
1675bf215546Sopenharmony_ci
1676bf215546Sopenharmony_civoid si_write_scissors(struct radeon_cmdbuf *cs, int first, int count, const VkRect2D *scissors,
1677bf215546Sopenharmony_ci                       const VkViewport *viewports, unsigned rast_prim, float line_width);
1678bf215546Sopenharmony_ci
1679bf215546Sopenharmony_ciuint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer, bool instanced_draw,
1680bf215546Sopenharmony_ci                                   bool indirect_draw, bool count_from_stream_output,
1681bf215546Sopenharmony_ci                                   uint32_t draw_vertex_count, unsigned topology,
1682bf215546Sopenharmony_ci                                   bool prim_restart_enable);
1683bf215546Sopenharmony_civoid si_cs_emit_write_event_eop(struct radeon_cmdbuf *cs, enum amd_gfx_level gfx_level, bool is_mec,
1684bf215546Sopenharmony_ci                                unsigned event, unsigned event_flags, unsigned dst_sel,
1685bf215546Sopenharmony_ci                                unsigned data_sel, uint64_t va, uint32_t new_fence,
1686bf215546Sopenharmony_ci                                uint64_t gfx9_eop_bug_va);
1687bf215546Sopenharmony_ci
1688bf215546Sopenharmony_civoid radv_cp_wait_mem(struct radeon_cmdbuf *cs, uint32_t op, uint64_t va, uint32_t ref,
1689bf215546Sopenharmony_ci                      uint32_t mask);
1690bf215546Sopenharmony_civoid si_cs_emit_cache_flush(struct radeon_cmdbuf *cs, enum amd_gfx_level gfx_level,
1691bf215546Sopenharmony_ci                            uint32_t *fence_ptr, uint64_t va, bool is_mec,
1692bf215546Sopenharmony_ci                            enum radv_cmd_flush_bits flush_bits,
1693bf215546Sopenharmony_ci                            enum rgp_flush_bits *sqtt_flush_bits, uint64_t gfx9_eop_bug_va);
1694bf215546Sopenharmony_civoid si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
1695bf215546Sopenharmony_civoid si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer, bool draw_visible,
1696bf215546Sopenharmony_ci                                   unsigned pred_op, uint64_t va);
1697bf215546Sopenharmony_civoid si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer, uint64_t src_va, uint64_t dest_va,
1698bf215546Sopenharmony_ci                           uint64_t size);
1699bf215546Sopenharmony_civoid si_cs_cp_dma_prefetch(const struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t va,
1700bf215546Sopenharmony_ci                           unsigned size, bool predicating);
1701bf215546Sopenharmony_civoid si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va, unsigned size);
1702bf215546Sopenharmony_civoid si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va, uint64_t size,
1703bf215546Sopenharmony_ci                            unsigned value);
1704bf215546Sopenharmony_civoid si_cp_dma_wait_for_idle(struct radv_cmd_buffer *cmd_buffer);
1705bf215546Sopenharmony_ci
1706bf215546Sopenharmony_civoid radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer, bool enable_occlusion_queries);
1707bf215546Sopenharmony_ciuint32_t radv_get_pa_su_sc_mode_cntl(const struct radv_cmd_buffer *cmd_buffer);
1708bf215546Sopenharmony_ciuint32_t radv_get_vgt_index_size(uint32_t type);
1709bf215546Sopenharmony_ci
1710bf215546Sopenharmony_ciunsigned radv_instance_rate_prolog_index(unsigned num_attributes, uint32_t instance_rate_inputs);
1711bf215546Sopenharmony_ciuint32_t radv_hash_vs_prolog(const void *key_);
1712bf215546Sopenharmony_cibool radv_cmp_vs_prolog(const void *a_, const void *b_);
1713bf215546Sopenharmony_ci
1714bf215546Sopenharmony_cibool radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer, unsigned size,
1715bf215546Sopenharmony_ci                                  unsigned *out_offset, void **ptr);
1716bf215546Sopenharmony_civoid radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
1717bf215546Sopenharmony_ci                                 const struct radv_subpass *subpass);
1718bf215546Sopenharmony_civoid radv_cmd_buffer_restore_subpass(struct radv_cmd_buffer *cmd_buffer,
1719bf215546Sopenharmony_ci                                     const struct radv_subpass *subpass);
1720bf215546Sopenharmony_cibool radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer, unsigned size,
1721bf215546Sopenharmony_ci                                 const void *data, unsigned *out_offset);
1722bf215546Sopenharmony_civoid radv_write_vertex_descriptors(const struct radv_cmd_buffer *cmd_buffer,
1723bf215546Sopenharmony_ci                                   const struct radv_graphics_pipeline *pipeline,
1724bf215546Sopenharmony_ci                                   bool full_null_descriptors, void *vb_ptr);
1725bf215546Sopenharmony_civoid radv_write_scissors(struct radv_cmd_buffer *cmd_buffer, struct radeon_cmdbuf *cs);
1726bf215546Sopenharmony_ci
1727bf215546Sopenharmony_civoid radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
1728bf215546Sopenharmony_civoid radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
1729bf215546Sopenharmony_civoid radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
1730bf215546Sopenharmony_civoid radv_depth_stencil_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer,
1731bf215546Sopenharmony_ci                                           VkImageAspectFlags aspects,
1732bf215546Sopenharmony_ci                                           VkResolveModeFlagBits resolve_mode);
1733bf215546Sopenharmony_civoid radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
1734bf215546Sopenharmony_civoid radv_depth_stencil_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer,
1735bf215546Sopenharmony_ci                                           VkImageAspectFlags aspects,
1736bf215546Sopenharmony_ci                                           VkResolveModeFlagBits resolve_mode);
1737bf215546Sopenharmony_civoid radv_emit_default_sample_locations(struct radeon_cmdbuf *cs, int nr_samples);
1738bf215546Sopenharmony_ciunsigned radv_get_default_max_sample_dist(int log_samples);
1739bf215546Sopenharmony_civoid radv_device_init_msaa(struct radv_device *device);
1740bf215546Sopenharmony_ciVkResult radv_device_init_vrs_state(struct radv_device *device);
1741bf215546Sopenharmony_ci
1742bf215546Sopenharmony_civoid radv_update_ds_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1743bf215546Sopenharmony_ci                                   const struct radv_image_view *iview,
1744bf215546Sopenharmony_ci                                   VkClearDepthStencilValue ds_clear_value,
1745bf215546Sopenharmony_ci                                   VkImageAspectFlags aspects);
1746bf215546Sopenharmony_ci
1747bf215546Sopenharmony_civoid radv_update_color_clear_metadata(struct radv_cmd_buffer *cmd_buffer,
1748bf215546Sopenharmony_ci                                      const struct radv_image_view *iview, int cb_idx,
1749bf215546Sopenharmony_ci                                      uint32_t color_values[2]);
1750bf215546Sopenharmony_ci
1751bf215546Sopenharmony_cibool radv_image_use_dcc_image_stores(const struct radv_device *device,
1752bf215546Sopenharmony_ci                                     const struct radv_image *image);
1753bf215546Sopenharmony_cibool radv_image_use_dcc_predication(const struct radv_device *device,
1754bf215546Sopenharmony_ci                                    const struct radv_image *image);
1755bf215546Sopenharmony_ci
1756bf215546Sopenharmony_civoid radv_update_fce_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
1757bf215546Sopenharmony_ci                              const VkImageSubresourceRange *range, bool value);
1758bf215546Sopenharmony_ci
1759bf215546Sopenharmony_civoid radv_update_dcc_metadata(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
1760bf215546Sopenharmony_ci                              const VkImageSubresourceRange *range, bool value);
1761bf215546Sopenharmony_cienum radv_cmd_flush_bits radv_src_access_flush(struct radv_cmd_buffer *cmd_buffer,
1762bf215546Sopenharmony_ci                                               VkAccessFlags2 src_flags,
1763bf215546Sopenharmony_ci                                               const struct radv_image *image);
1764bf215546Sopenharmony_cienum radv_cmd_flush_bits radv_dst_access_flush(struct radv_cmd_buffer *cmd_buffer,
1765bf215546Sopenharmony_ci                                               VkAccessFlags2 dst_flags,
1766bf215546Sopenharmony_ci                                               const struct radv_image *image);
1767bf215546Sopenharmony_ciuint32_t radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer, const struct radv_image *image,
1768bf215546Sopenharmony_ci                          struct radeon_winsys_bo *bo, uint64_t va, uint64_t size, uint32_t value);
1769bf215546Sopenharmony_civoid radv_copy_buffer(struct radv_cmd_buffer *cmd_buffer, struct radeon_winsys_bo *src_bo,
1770bf215546Sopenharmony_ci                      struct radeon_winsys_bo *dst_bo, uint64_t src_offset, uint64_t dst_offset,
1771bf215546Sopenharmony_ci                      uint64_t size);
1772bf215546Sopenharmony_ci
1773bf215546Sopenharmony_civoid radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
1774bf215546Sopenharmony_cibool radv_get_memory_fd(struct radv_device *device, struct radv_device_memory *memory, int *pFD);
1775bf215546Sopenharmony_civoid radv_free_memory(struct radv_device *device, const VkAllocationCallbacks *pAllocator,
1776bf215546Sopenharmony_ci                      struct radv_device_memory *mem);
1777bf215546Sopenharmony_ci
1778bf215546Sopenharmony_cistatic inline void
1779bf215546Sopenharmony_ciradv_emit_shader_pointer_head(struct radeon_cmdbuf *cs, unsigned sh_offset, unsigned pointer_count,
1780bf215546Sopenharmony_ci                              bool use_32bit_pointers)
1781bf215546Sopenharmony_ci{
1782bf215546Sopenharmony_ci   radeon_emit(cs, PKT3(PKT3_SET_SH_REG, pointer_count * (use_32bit_pointers ? 1 : 2), 0));
1783bf215546Sopenharmony_ci   radeon_emit(cs, (sh_offset - SI_SH_REG_OFFSET) >> 2);
1784bf215546Sopenharmony_ci}
1785bf215546Sopenharmony_ci
1786bf215546Sopenharmony_cistatic inline void
1787bf215546Sopenharmony_ciradv_emit_shader_pointer_body(struct radv_device *device, struct radeon_cmdbuf *cs, uint64_t va,
1788bf215546Sopenharmony_ci                              bool use_32bit_pointers)
1789bf215546Sopenharmony_ci{
1790bf215546Sopenharmony_ci   radeon_emit(cs, va);
1791bf215546Sopenharmony_ci
1792bf215546Sopenharmony_ci   if (use_32bit_pointers) {
1793bf215546Sopenharmony_ci      assert(va == 0 || (va >> 32) == device->physical_device->rad_info.address32_hi);
1794bf215546Sopenharmony_ci   } else {
1795bf215546Sopenharmony_ci      radeon_emit(cs, va >> 32);
1796bf215546Sopenharmony_ci   }
1797bf215546Sopenharmony_ci}
1798bf215546Sopenharmony_ci
1799bf215546Sopenharmony_cistatic inline void
1800bf215546Sopenharmony_ciradv_emit_shader_pointer(struct radv_device *device, struct radeon_cmdbuf *cs, uint32_t sh_offset,
1801bf215546Sopenharmony_ci                         uint64_t va, bool global)
1802bf215546Sopenharmony_ci{
1803bf215546Sopenharmony_ci   bool use_32bit_pointers = !global;
1804bf215546Sopenharmony_ci
1805bf215546Sopenharmony_ci   radv_emit_shader_pointer_head(cs, sh_offset, 1, use_32bit_pointers);
1806bf215546Sopenharmony_ci   radv_emit_shader_pointer_body(device, cs, va, use_32bit_pointers);
1807bf215546Sopenharmony_ci}
1808bf215546Sopenharmony_ci
1809bf215546Sopenharmony_cistatic inline struct radv_descriptor_state *
1810bf215546Sopenharmony_ciradv_get_descriptors_state(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point)
1811bf215546Sopenharmony_ci{
1812bf215546Sopenharmony_ci   switch (bind_point) {
1813bf215546Sopenharmony_ci   case VK_PIPELINE_BIND_POINT_GRAPHICS:
1814bf215546Sopenharmony_ci   case VK_PIPELINE_BIND_POINT_COMPUTE:
1815bf215546Sopenharmony_ci      return &cmd_buffer->descriptors[bind_point];
1816bf215546Sopenharmony_ci   case VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR:
1817bf215546Sopenharmony_ci      return &cmd_buffer->descriptors[2];
1818bf215546Sopenharmony_ci   default:
1819bf215546Sopenharmony_ci      unreachable("Unhandled bind point");
1820bf215546Sopenharmony_ci   }
1821bf215546Sopenharmony_ci}
1822bf215546Sopenharmony_ci
1823bf215546Sopenharmony_civoid
1824bf215546Sopenharmony_ciradv_get_viewport_xform(const VkViewport *viewport, float scale[3], float translate[3]);
1825bf215546Sopenharmony_ci
1826bf215546Sopenharmony_ci/*
1827bf215546Sopenharmony_ci * Takes x,y,z as exact numbers of invocations, instead of blocks.
1828bf215546Sopenharmony_ci *
1829bf215546Sopenharmony_ci * Limitations: Can't call normal dispatch functions without binding or rebinding
1830bf215546Sopenharmony_ci *              the compute pipeline.
1831bf215546Sopenharmony_ci */
1832bf215546Sopenharmony_civoid radv_unaligned_dispatch(struct radv_cmd_buffer *cmd_buffer, uint32_t x, uint32_t y,
1833bf215546Sopenharmony_ci                             uint32_t z);
1834bf215546Sopenharmony_ci
1835bf215546Sopenharmony_civoid radv_indirect_dispatch(struct radv_cmd_buffer *cmd_buffer, struct radeon_winsys_bo *bo,
1836bf215546Sopenharmony_ci                            uint64_t va);
1837bf215546Sopenharmony_ci
1838bf215546Sopenharmony_cistruct radv_event {
1839bf215546Sopenharmony_ci   struct vk_object_base base;
1840bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
1841bf215546Sopenharmony_ci   uint64_t *map;
1842bf215546Sopenharmony_ci};
1843bf215546Sopenharmony_ci
1844bf215546Sopenharmony_ci#define RADV_HASH_SHADER_CS_WAVE32         (1 << 1)
1845bf215546Sopenharmony_ci#define RADV_HASH_SHADER_PS_WAVE32         (1 << 2)
1846bf215546Sopenharmony_ci#define RADV_HASH_SHADER_GE_WAVE32         (1 << 3)
1847bf215546Sopenharmony_ci#define RADV_HASH_SHADER_LLVM              (1 << 4)
1848bf215546Sopenharmony_ci#define RADV_HASH_SHADER_KEEP_STATISTICS   (1 << 8)
1849bf215546Sopenharmony_ci#define RADV_HASH_SHADER_USE_NGG_CULLING   (1 << 13)
1850bf215546Sopenharmony_ci#define RADV_HASH_SHADER_ROBUST_BUFFER_ACCESS (1 << 14)
1851bf215546Sopenharmony_ci#define RADV_HASH_SHADER_ROBUST_BUFFER_ACCESS2 (1 << 15)
1852bf215546Sopenharmony_ci#define RADV_HASH_SHADER_EMULATE_RT            (1 << 16)
1853bf215546Sopenharmony_ci#define RADV_HASH_SHADER_SPLIT_FMA             (1 << 17)
1854bf215546Sopenharmony_ci#define RADV_HASH_SHADER_RT_WAVE64             (1 << 18)
1855bf215546Sopenharmony_ci
1856bf215546Sopenharmony_cistruct radv_pipeline_key;
1857bf215546Sopenharmony_ci
1858bf215546Sopenharmony_civoid radv_pipeline_stage_init(const VkPipelineShaderStageCreateInfo *sinfo,
1859bf215546Sopenharmony_ci                              struct radv_pipeline_stage *out_stage, gl_shader_stage stage);
1860bf215546Sopenharmony_ci
1861bf215546Sopenharmony_civoid radv_hash_shaders(unsigned char *hash, const struct radv_pipeline_stage *stages,
1862bf215546Sopenharmony_ci                       const struct radv_pipeline_layout *layout,
1863bf215546Sopenharmony_ci                       const struct radv_pipeline_key *key, uint32_t flags);
1864bf215546Sopenharmony_ci
1865bf215546Sopenharmony_civoid radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
1866bf215546Sopenharmony_ci                          uint32_t flags);
1867bf215546Sopenharmony_ci
1868bf215546Sopenharmony_ciuint32_t radv_get_hash_flags(const struct radv_device *device, bool stats);
1869bf215546Sopenharmony_ci
1870bf215546Sopenharmony_cibool radv_rt_pipeline_has_dynamic_stack_size(const VkRayTracingPipelineCreateInfoKHR *pCreateInfo);
1871bf215546Sopenharmony_ci
1872bf215546Sopenharmony_cibool radv_enable_rt(const struct radv_physical_device *pdevice, bool rt_pipelines);
1873bf215546Sopenharmony_ci
1874bf215546Sopenharmony_cibool radv_emulate_rt(const struct radv_physical_device *pdevice);
1875bf215546Sopenharmony_ci
1876bf215546Sopenharmony_cienum {
1877bf215546Sopenharmony_ci   RADV_RT_STAGE_BITS = (VK_SHADER_STAGE_RAYGEN_BIT_KHR | VK_SHADER_STAGE_ANY_HIT_BIT_KHR |
1878bf215546Sopenharmony_ci                         VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR | VK_SHADER_STAGE_MISS_BIT_KHR |
1879bf215546Sopenharmony_ci                         VK_SHADER_STAGE_INTERSECTION_BIT_KHR | VK_SHADER_STAGE_CALLABLE_BIT_KHR)
1880bf215546Sopenharmony_ci};
1881bf215546Sopenharmony_ci
1882bf215546Sopenharmony_ci#define RADV_STAGE_MASK ((1 << MESA_VULKAN_SHADER_STAGES) - 1)
1883bf215546Sopenharmony_ci
1884bf215546Sopenharmony_ci#define radv_foreach_stage(stage, stage_bits)                                                      \
1885bf215546Sopenharmony_ci   for (gl_shader_stage stage, __tmp = (gl_shader_stage)((stage_bits)&RADV_STAGE_MASK);            \
1886bf215546Sopenharmony_ci        stage = ffs(__tmp) - 1, __tmp; __tmp &= ~(1 << (stage)))
1887bf215546Sopenharmony_ci
1888bf215546Sopenharmony_ciextern const VkFormat radv_fs_key_format_exemplars[NUM_META_FS_KEYS];
1889bf215546Sopenharmony_ciunsigned radv_format_meta_fs_key(struct radv_device *device, VkFormat format);
1890bf215546Sopenharmony_ci
1891bf215546Sopenharmony_cistruct radv_multisample_state {
1892bf215546Sopenharmony_ci   uint32_t db_eqaa;
1893bf215546Sopenharmony_ci   uint32_t pa_sc_mode_cntl_0;
1894bf215546Sopenharmony_ci   uint32_t pa_sc_mode_cntl_1;
1895bf215546Sopenharmony_ci   uint32_t pa_sc_aa_config;
1896bf215546Sopenharmony_ci   uint32_t pa_sc_aa_mask[2];
1897bf215546Sopenharmony_ci   unsigned num_samples;
1898bf215546Sopenharmony_ci};
1899bf215546Sopenharmony_ci
1900bf215546Sopenharmony_cistruct radv_vrs_state {
1901bf215546Sopenharmony_ci   uint32_t pa_cl_vrs_cntl;
1902bf215546Sopenharmony_ci};
1903bf215546Sopenharmony_ci
1904bf215546Sopenharmony_cistruct radv_prim_vertex_count {
1905bf215546Sopenharmony_ci   uint8_t min;
1906bf215546Sopenharmony_ci   uint8_t incr;
1907bf215546Sopenharmony_ci};
1908bf215546Sopenharmony_ci
1909bf215546Sopenharmony_cistruct radv_ia_multi_vgt_param_helpers {
1910bf215546Sopenharmony_ci   uint32_t base;
1911bf215546Sopenharmony_ci   bool partial_es_wave;
1912bf215546Sopenharmony_ci   uint8_t primgroup_size;
1913bf215546Sopenharmony_ci   bool ia_switch_on_eoi;
1914bf215546Sopenharmony_ci   bool partial_vs_wave;
1915bf215546Sopenharmony_ci};
1916bf215546Sopenharmony_ci
1917bf215546Sopenharmony_cistruct radv_binning_state {
1918bf215546Sopenharmony_ci   uint32_t pa_sc_binner_cntl_0;
1919bf215546Sopenharmony_ci};
1920bf215546Sopenharmony_ci
1921bf215546Sopenharmony_ci#define SI_GS_PER_ES 128
1922bf215546Sopenharmony_ci
1923bf215546Sopenharmony_cienum radv_pipeline_type {
1924bf215546Sopenharmony_ci   RADV_PIPELINE_GRAPHICS,
1925bf215546Sopenharmony_ci   /* Compute pipeline (incl raytracing pipeline) */
1926bf215546Sopenharmony_ci   RADV_PIPELINE_COMPUTE,
1927bf215546Sopenharmony_ci   /* Pipeline library. This can't actually run and merely is a partial pipeline. */
1928bf215546Sopenharmony_ci   RADV_PIPELINE_LIBRARY
1929bf215546Sopenharmony_ci};
1930bf215546Sopenharmony_ci
1931bf215546Sopenharmony_cistruct radv_pipeline_group_handle {
1932bf215546Sopenharmony_ci   uint32_t handles[2];
1933bf215546Sopenharmony_ci};
1934bf215546Sopenharmony_ci
1935bf215546Sopenharmony_cistruct radv_pipeline_shader_stack_size {
1936bf215546Sopenharmony_ci   uint32_t recursive_size;
1937bf215546Sopenharmony_ci   /* anyhit + intersection */
1938bf215546Sopenharmony_ci   uint32_t non_recursive_size;
1939bf215546Sopenharmony_ci};
1940bf215546Sopenharmony_ci
1941bf215546Sopenharmony_cistruct radv_pipeline_slab {
1942bf215546Sopenharmony_ci   uint32_t ref_count;
1943bf215546Sopenharmony_ci
1944bf215546Sopenharmony_ci   union radv_shader_arena_block *alloc;
1945bf215546Sopenharmony_ci};
1946bf215546Sopenharmony_ci
1947bf215546Sopenharmony_civoid radv_pipeline_slab_destroy(struct radv_device *device, struct radv_pipeline_slab *slab);
1948bf215546Sopenharmony_ci
1949bf215546Sopenharmony_cistruct radv_vertex_input_info {
1950bf215546Sopenharmony_ci   uint32_t instance_rate_inputs;
1951bf215546Sopenharmony_ci   uint32_t instance_rate_divisors[MAX_VERTEX_ATTRIBS];
1952bf215546Sopenharmony_ci   uint8_t vertex_attribute_formats[MAX_VERTEX_ATTRIBS];
1953bf215546Sopenharmony_ci   uint32_t vertex_attribute_bindings[MAX_VERTEX_ATTRIBS];
1954bf215546Sopenharmony_ci   uint32_t vertex_attribute_offsets[MAX_VERTEX_ATTRIBS];
1955bf215546Sopenharmony_ci   uint32_t vertex_attribute_strides[MAX_VERTEX_ATTRIBS];
1956bf215546Sopenharmony_ci   uint8_t vertex_binding_align[MAX_VBS];
1957bf215546Sopenharmony_ci   enum radv_vs_input_alpha_adjust vertex_alpha_adjust[MAX_VERTEX_ATTRIBS];
1958bf215546Sopenharmony_ci   uint32_t vertex_post_shuffle;
1959bf215546Sopenharmony_ci   uint32_t binding_stride[MAX_VBS];
1960bf215546Sopenharmony_ci   uint8_t attrib_bindings[MAX_VERTEX_ATTRIBS];
1961bf215546Sopenharmony_ci   uint32_t attrib_ends[MAX_VERTEX_ATTRIBS];
1962bf215546Sopenharmony_ci   uint32_t attrib_index_offset[MAX_VERTEX_ATTRIBS];
1963bf215546Sopenharmony_ci};
1964bf215546Sopenharmony_ci
1965bf215546Sopenharmony_cistruct radv_input_assembly_info {
1966bf215546Sopenharmony_ci   uint8_t primitive_topology; /* VkPrimitiveTopology */
1967bf215546Sopenharmony_ci   bool primitive_restart_enable;
1968bf215546Sopenharmony_ci};
1969bf215546Sopenharmony_ci
1970bf215546Sopenharmony_cistruct radv_tessellation_info {
1971bf215546Sopenharmony_ci   uint8_t patch_control_points;
1972bf215546Sopenharmony_ci   VkTessellationDomainOrigin domain_origin;
1973bf215546Sopenharmony_ci};
1974bf215546Sopenharmony_ci
1975bf215546Sopenharmony_cistruct radv_viewport_info {
1976bf215546Sopenharmony_ci   bool negative_one_to_one;
1977bf215546Sopenharmony_ci   uint8_t viewport_count;
1978bf215546Sopenharmony_ci   uint8_t scissor_count;
1979bf215546Sopenharmony_ci   VkRect2D scissors[MAX_SCISSORS];
1980bf215546Sopenharmony_ci   VkViewport viewports[MAX_VIEWPORTS];
1981bf215546Sopenharmony_ci};
1982bf215546Sopenharmony_ci
1983bf215546Sopenharmony_cistruct radv_rasterization_info {
1984bf215546Sopenharmony_ci   bool discard_enable;
1985bf215546Sopenharmony_ci   VkFrontFace front_face;
1986bf215546Sopenharmony_ci   VkCullModeFlags cull_mode;
1987bf215546Sopenharmony_ci   uint8_t polygon_mode; /* VkPolygonMode */
1988bf215546Sopenharmony_ci   bool depth_bias_enable;
1989bf215546Sopenharmony_ci   bool depth_clamp_enable;
1990bf215546Sopenharmony_ci   float line_width;
1991bf215546Sopenharmony_ci   float depth_bias_constant_factor;
1992bf215546Sopenharmony_ci   float depth_bias_clamp;
1993bf215546Sopenharmony_ci   float depth_bias_slope_factor;
1994bf215546Sopenharmony_ci   VkConservativeRasterizationModeEXT conservative_mode;
1995bf215546Sopenharmony_ci   bool provoking_vtx_last;
1996bf215546Sopenharmony_ci   bool stippled_line_enable;
1997bf215546Sopenharmony_ci   VkLineRasterizationModeEXT line_raster_mode;
1998bf215546Sopenharmony_ci   uint32_t line_stipple_factor;
1999bf215546Sopenharmony_ci   uint16_t line_stipple_pattern;
2000bf215546Sopenharmony_ci   bool depth_clip_disable;
2001bf215546Sopenharmony_ci   VkRasterizationOrderAMD order;
2002bf215546Sopenharmony_ci};
2003bf215546Sopenharmony_ci
2004bf215546Sopenharmony_cistruct radv_discard_rectangle_info {
2005bf215546Sopenharmony_ci   VkDiscardRectangleModeEXT mode;
2006bf215546Sopenharmony_ci   VkRect2D rects[MAX_DISCARD_RECTANGLES];
2007bf215546Sopenharmony_ci   uint8_t count;
2008bf215546Sopenharmony_ci};
2009bf215546Sopenharmony_ci
2010bf215546Sopenharmony_cistruct radv_multisample_info {
2011bf215546Sopenharmony_ci   bool sample_shading_enable;
2012bf215546Sopenharmony_ci   bool alpha_to_coverage_enable;
2013bf215546Sopenharmony_ci   bool sample_locs_enable;
2014bf215546Sopenharmony_ci   VkSampleCountFlagBits raster_samples;
2015bf215546Sopenharmony_ci   float min_sample_shading;
2016bf215546Sopenharmony_ci   uint16_t sample_mask;
2017bf215546Sopenharmony_ci   uint8_t sample_locs_count;
2018bf215546Sopenharmony_ci   VkSampleCountFlagBits sample_locs_per_pixel;
2019bf215546Sopenharmony_ci   VkExtent2D sample_locs_grid_size;
2020bf215546Sopenharmony_ci   VkSampleLocationEXT sample_locs[MAX_SAMPLE_LOCATIONS];
2021bf215546Sopenharmony_ci};
2022bf215546Sopenharmony_ci
2023bf215546Sopenharmony_cistruct radv_stencil_op_info {
2024bf215546Sopenharmony_ci   VkStencilOp fail_op;
2025bf215546Sopenharmony_ci   VkStencilOp pass_op;
2026bf215546Sopenharmony_ci   VkStencilOp depth_fail_op;
2027bf215546Sopenharmony_ci   VkCompareOp compare_op;
2028bf215546Sopenharmony_ci   uint8_t compare_mask;
2029bf215546Sopenharmony_ci   uint8_t write_mask;
2030bf215546Sopenharmony_ci   uint8_t reference;
2031bf215546Sopenharmony_ci};
2032bf215546Sopenharmony_ci
2033bf215546Sopenharmony_cistruct radv_depth_stencil_info {
2034bf215546Sopenharmony_ci   bool stencil_test_enable;
2035bf215546Sopenharmony_ci   bool depth_test_enable;
2036bf215546Sopenharmony_ci   bool depth_write_enable;
2037bf215546Sopenharmony_ci   bool depth_bounds_test_enable;
2038bf215546Sopenharmony_ci   struct {
2039bf215546Sopenharmony_ci      float min;
2040bf215546Sopenharmony_ci      float max;
2041bf215546Sopenharmony_ci   } depth_bounds;
2042bf215546Sopenharmony_ci   struct radv_stencil_op_info front;
2043bf215546Sopenharmony_ci   struct radv_stencil_op_info back;
2044bf215546Sopenharmony_ci   VkCompareOp depth_compare_op;
2045bf215546Sopenharmony_ci};
2046bf215546Sopenharmony_ci
2047bf215546Sopenharmony_cistruct radv_rendering_info {
2048bf215546Sopenharmony_ci   uint32_t view_mask;
2049bf215546Sopenharmony_ci   uint32_t color_att_count;
2050bf215546Sopenharmony_ci   VkFormat color_att_formats[MAX_RTS];
2051bf215546Sopenharmony_ci   VkFormat depth_att_format;
2052bf215546Sopenharmony_ci   VkFormat stencil_att_format;
2053bf215546Sopenharmony_ci};
2054bf215546Sopenharmony_ci
2055bf215546Sopenharmony_cistruct radv_color_blend_info {
2056bf215546Sopenharmony_ci   bool logic_op_enable;
2057bf215546Sopenharmony_ci   uint8_t att_count;
2058bf215546Sopenharmony_ci   uint16_t logic_op;
2059bf215546Sopenharmony_ci   uint32_t color_write_enable;
2060bf215546Sopenharmony_ci   float blend_constants[4];
2061bf215546Sopenharmony_ci   struct {
2062bf215546Sopenharmony_ci      uint8_t color_write_mask;
2063bf215546Sopenharmony_ci      bool blend_enable;
2064bf215546Sopenharmony_ci      uint16_t color_blend_op;
2065bf215546Sopenharmony_ci      uint16_t alpha_blend_op;
2066bf215546Sopenharmony_ci      uint16_t src_color_blend_factor;
2067bf215546Sopenharmony_ci      uint16_t dst_color_blend_factor;
2068bf215546Sopenharmony_ci      uint16_t src_alpha_blend_factor;
2069bf215546Sopenharmony_ci      uint16_t dst_alpha_blend_factor;
2070bf215546Sopenharmony_ci   } att[MAX_RTS];
2071bf215546Sopenharmony_ci};
2072bf215546Sopenharmony_ci
2073bf215546Sopenharmony_cistruct radv_fragment_shading_rate_info {
2074bf215546Sopenharmony_ci   VkExtent2D size;
2075bf215546Sopenharmony_ci   VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
2076bf215546Sopenharmony_ci};
2077bf215546Sopenharmony_ci
2078bf215546Sopenharmony_cistruct radv_graphics_pipeline_info {
2079bf215546Sopenharmony_ci   struct radv_vertex_input_info vi;
2080bf215546Sopenharmony_ci   struct radv_input_assembly_info ia;
2081bf215546Sopenharmony_ci
2082bf215546Sopenharmony_ci   struct radv_tessellation_info ts;
2083bf215546Sopenharmony_ci   struct radv_viewport_info vp;
2084bf215546Sopenharmony_ci   struct radv_rasterization_info rs;
2085bf215546Sopenharmony_ci   struct radv_discard_rectangle_info dr;
2086bf215546Sopenharmony_ci
2087bf215546Sopenharmony_ci   struct radv_multisample_info ms;
2088bf215546Sopenharmony_ci   struct radv_depth_stencil_info ds;
2089bf215546Sopenharmony_ci   struct radv_rendering_info ri;
2090bf215546Sopenharmony_ci   struct radv_color_blend_info cb;
2091bf215546Sopenharmony_ci
2092bf215546Sopenharmony_ci   struct radv_fragment_shading_rate_info fsr;
2093bf215546Sopenharmony_ci
2094bf215546Sopenharmony_ci   /* VK_AMD_mixed_attachment_samples */
2095bf215546Sopenharmony_ci   uint8_t color_att_samples;
2096bf215546Sopenharmony_ci   uint8_t ds_att_samples;
2097bf215546Sopenharmony_ci};
2098bf215546Sopenharmony_ci
2099bf215546Sopenharmony_cienum radv_depth_clamp_mode {
2100bf215546Sopenharmony_ci   RADV_DEPTH_CLAMP_MODE_VIEWPORT = 0,       /* Clamp to the viewport min/max depth bounds */
2101bf215546Sopenharmony_ci   RADV_DEPTH_CLAMP_MODE_ZERO_TO_ONE = 1,    /* Clamp between 0.0f and 1.0f */
2102bf215546Sopenharmony_ci   RADV_DEPTH_CLAMP_MODE_DISABLED = 2,       /* Disable depth clamping */
2103bf215546Sopenharmony_ci};
2104bf215546Sopenharmony_ci
2105bf215546Sopenharmony_cistruct radv_pipeline {
2106bf215546Sopenharmony_ci   struct vk_object_base base;
2107bf215546Sopenharmony_ci   enum radv_pipeline_type type;
2108bf215546Sopenharmony_ci
2109bf215546Sopenharmony_ci   struct radv_device *device;
2110bf215546Sopenharmony_ci
2111bf215546Sopenharmony_ci   struct radv_pipeline_slab *slab;
2112bf215546Sopenharmony_ci   struct radeon_winsys_bo *slab_bo;
2113bf215546Sopenharmony_ci
2114bf215546Sopenharmony_ci   bool need_indirect_descriptor_sets;
2115bf215546Sopenharmony_ci   struct radv_shader *shaders[MESA_VULKAN_SHADER_STAGES];
2116bf215546Sopenharmony_ci   struct radv_shader *gs_copy_shader;
2117bf215546Sopenharmony_ci
2118bf215546Sopenharmony_ci   struct radeon_cmdbuf cs;
2119bf215546Sopenharmony_ci   uint32_t ctx_cs_hash;
2120bf215546Sopenharmony_ci   struct radeon_cmdbuf ctx_cs;
2121bf215546Sopenharmony_ci
2122bf215546Sopenharmony_ci   uint32_t user_data_0[MESA_VULKAN_SHADER_STAGES];
2123bf215546Sopenharmony_ci
2124bf215546Sopenharmony_ci   unsigned max_waves;
2125bf215546Sopenharmony_ci   unsigned scratch_bytes_per_wave;
2126bf215546Sopenharmony_ci
2127bf215546Sopenharmony_ci   /* Unique pipeline hash identifier. */
2128bf215546Sopenharmony_ci   uint64_t pipeline_hash;
2129bf215546Sopenharmony_ci
2130bf215546Sopenharmony_ci   /* Pipeline layout info. */
2131bf215546Sopenharmony_ci   uint32_t push_constant_size;
2132bf215546Sopenharmony_ci   uint32_t dynamic_offset_count;
2133bf215546Sopenharmony_ci};
2134bf215546Sopenharmony_ci
2135bf215546Sopenharmony_cistruct radv_graphics_pipeline {
2136bf215546Sopenharmony_ci   struct radv_pipeline base;
2137bf215546Sopenharmony_ci
2138bf215546Sopenharmony_ci   VkShaderStageFlags active_stages;
2139bf215546Sopenharmony_ci
2140bf215546Sopenharmony_ci   struct radv_dynamic_state dynamic_state;
2141bf215546Sopenharmony_ci
2142bf215546Sopenharmony_ci   uint64_t dynamic_states;
2143bf215546Sopenharmony_ci   struct radv_multisample_state ms;
2144bf215546Sopenharmony_ci   struct radv_binning_state binning;
2145bf215546Sopenharmony_ci   struct radv_vrs_state vrs;
2146bf215546Sopenharmony_ci   uint32_t spi_baryc_cntl;
2147bf215546Sopenharmony_ci   unsigned esgs_ring_size;
2148bf215546Sopenharmony_ci   unsigned gsvs_ring_size;
2149bf215546Sopenharmony_ci   uint32_t vtx_base_sgpr;
2150bf215546Sopenharmony_ci   struct radv_ia_multi_vgt_param_helpers ia_multi_vgt_param;
2151bf215546Sopenharmony_ci   uint8_t vtx_emit_num;
2152bf215546Sopenharmony_ci   uint64_t needed_dynamic_state;
2153bf215546Sopenharmony_ci   unsigned tess_patch_control_points;
2154bf215546Sopenharmony_ci   unsigned pa_su_sc_mode_cntl;
2155bf215546Sopenharmony_ci   unsigned db_depth_control;
2156bf215546Sopenharmony_ci   unsigned pa_cl_clip_cntl;
2157bf215546Sopenharmony_ci   unsigned cb_color_control;
2158bf215546Sopenharmony_ci   uint32_t binding_stride[MAX_VBS];
2159bf215546Sopenharmony_ci   uint8_t attrib_bindings[MAX_VERTEX_ATTRIBS];
2160bf215546Sopenharmony_ci   uint32_t attrib_ends[MAX_VERTEX_ATTRIBS];
2161bf215546Sopenharmony_ci   uint32_t attrib_index_offset[MAX_VERTEX_ATTRIBS];
2162bf215546Sopenharmony_ci   uint8_t last_vertex_attrib_bit;
2163bf215546Sopenharmony_ci   uint8_t next_vertex_stage : 8;
2164bf215546Sopenharmony_ci   uint32_t vb_desc_usage_mask;
2165bf215546Sopenharmony_ci   uint32_t vb_desc_alloc_size;
2166bf215546Sopenharmony_ci
2167bf215546Sopenharmony_ci   /* Last pre-PS API stage */
2168bf215546Sopenharmony_ci   gl_shader_stage last_vgt_api_stage;
2169bf215546Sopenharmony_ci
2170bf215546Sopenharmony_ci   /* Used for rbplus */
2171bf215546Sopenharmony_ci   uint32_t col_format;
2172bf215546Sopenharmony_ci   uint32_t cb_target_mask;
2173bf215546Sopenharmony_ci
2174bf215546Sopenharmony_ci   bool disable_out_of_order_rast_for_occlusion;
2175bf215546Sopenharmony_ci   bool uses_drawid;
2176bf215546Sopenharmony_ci   bool uses_baseinstance;
2177bf215546Sopenharmony_ci   bool uses_dynamic_stride;
2178bf215546Sopenharmony_ci   bool uses_conservative_overestimate;
2179bf215546Sopenharmony_ci   bool negative_one_to_one;
2180bf215546Sopenharmony_ci   enum radv_depth_clamp_mode depth_clamp_mode;
2181bf215546Sopenharmony_ci   bool use_per_attribute_vb_descs;
2182bf215546Sopenharmony_ci   bool can_use_simple_input;
2183bf215546Sopenharmony_ci   bool uses_user_sample_locations;
2184bf215546Sopenharmony_ci
2185bf215546Sopenharmony_ci   /* Whether the pipeline forces per-vertex VRS (GFX10.3+). */
2186bf215546Sopenharmony_ci   bool force_vrs_per_vertex;
2187bf215546Sopenharmony_ci
2188bf215546Sopenharmony_ci   /* Whether the pipeline uses NGG (GFX10+). */
2189bf215546Sopenharmony_ci   bool is_ngg;
2190bf215546Sopenharmony_ci   bool has_ngg_culling;
2191bf215546Sopenharmony_ci
2192bf215546Sopenharmony_ci   /* Not NULL if graphics pipeline uses streamout. */
2193bf215546Sopenharmony_ci   struct radv_shader *streamout_shader;
2194bf215546Sopenharmony_ci
2195bf215546Sopenharmony_ci   unsigned rast_prim;
2196bf215546Sopenharmony_ci   float line_width;
2197bf215546Sopenharmony_ci};
2198bf215546Sopenharmony_ci
2199bf215546Sopenharmony_cistruct radv_compute_pipeline {
2200bf215546Sopenharmony_ci   struct radv_pipeline base;
2201bf215546Sopenharmony_ci
2202bf215546Sopenharmony_ci   bool cs_regalloc_hang_bug;
2203bf215546Sopenharmony_ci
2204bf215546Sopenharmony_ci   /* Raytracing */
2205bf215546Sopenharmony_ci   struct radv_pipeline_group_handle *rt_group_handles;
2206bf215546Sopenharmony_ci   struct radv_pipeline_shader_stack_size *rt_stack_sizes;
2207bf215546Sopenharmony_ci   bool dynamic_stack_size;
2208bf215546Sopenharmony_ci   uint32_t group_count;
2209bf215546Sopenharmony_ci};
2210bf215546Sopenharmony_ci
2211bf215546Sopenharmony_cistruct radv_library_pipeline {
2212bf215546Sopenharmony_ci   struct radv_pipeline base;
2213bf215546Sopenharmony_ci
2214bf215546Sopenharmony_ci   unsigned stage_count;
2215bf215546Sopenharmony_ci   VkPipelineShaderStageCreateInfo *stages;
2216bf215546Sopenharmony_ci   unsigned group_count;
2217bf215546Sopenharmony_ci   VkRayTracingShaderGroupCreateInfoKHR *groups;
2218bf215546Sopenharmony_ci   VkPipelineShaderStageModuleIdentifierCreateInfoEXT *identifiers;
2219bf215546Sopenharmony_ci   struct {
2220bf215546Sopenharmony_ci      uint8_t sha1[SHA1_DIGEST_LENGTH];
2221bf215546Sopenharmony_ci   } *hashes;
2222bf215546Sopenharmony_ci};
2223bf215546Sopenharmony_ci
2224bf215546Sopenharmony_ci#define RADV_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum)            \
2225bf215546Sopenharmony_ci   static inline struct radv_##pipe_type##_pipeline *                \
2226bf215546Sopenharmony_ci   radv_pipeline_to_##pipe_type(struct radv_pipeline *pipeline)      \
2227bf215546Sopenharmony_ci   {                                                                 \
2228bf215546Sopenharmony_ci      assert(pipeline->type == pipe_enum);                           \
2229bf215546Sopenharmony_ci      return (struct radv_##pipe_type##_pipeline *) pipeline;        \
2230bf215546Sopenharmony_ci   }
2231bf215546Sopenharmony_ci
2232bf215546Sopenharmony_ciRADV_DECL_PIPELINE_DOWNCAST(graphics, RADV_PIPELINE_GRAPHICS)
2233bf215546Sopenharmony_ciRADV_DECL_PIPELINE_DOWNCAST(compute, RADV_PIPELINE_COMPUTE)
2234bf215546Sopenharmony_ciRADV_DECL_PIPELINE_DOWNCAST(library, RADV_PIPELINE_LIBRARY)
2235bf215546Sopenharmony_ci
2236bf215546Sopenharmony_cistruct radv_pipeline_stage {
2237bf215546Sopenharmony_ci   gl_shader_stage stage;
2238bf215546Sopenharmony_ci
2239bf215546Sopenharmony_ci   struct {
2240bf215546Sopenharmony_ci      const struct vk_object_base *object;
2241bf215546Sopenharmony_ci      const char *data;
2242bf215546Sopenharmony_ci      uint32_t size;
2243bf215546Sopenharmony_ci      unsigned char sha1[20];
2244bf215546Sopenharmony_ci   } spirv;
2245bf215546Sopenharmony_ci
2246bf215546Sopenharmony_ci   const char *entrypoint;
2247bf215546Sopenharmony_ci   const VkSpecializationInfo *spec_info;
2248bf215546Sopenharmony_ci
2249bf215546Sopenharmony_ci   unsigned char shader_sha1[20];
2250bf215546Sopenharmony_ci
2251bf215546Sopenharmony_ci   nir_shader *nir;
2252bf215546Sopenharmony_ci   nir_shader *internal_nir; /* meta shaders */
2253bf215546Sopenharmony_ci
2254bf215546Sopenharmony_ci   struct radv_shader_info info;
2255bf215546Sopenharmony_ci   struct radv_shader_args args;
2256bf215546Sopenharmony_ci
2257bf215546Sopenharmony_ci   VkPipelineCreationFeedback feedback;
2258bf215546Sopenharmony_ci};
2259bf215546Sopenharmony_ci
2260bf215546Sopenharmony_cistatic inline bool
2261bf215546Sopenharmony_ciradv_pipeline_has_stage(const struct radv_graphics_pipeline *pipeline, gl_shader_stage stage)
2262bf215546Sopenharmony_ci{
2263bf215546Sopenharmony_ci   return pipeline->base.shaders[stage];
2264bf215546Sopenharmony_ci}
2265bf215546Sopenharmony_ci
2266bf215546Sopenharmony_cibool radv_pipeline_has_ngg_passthrough(const struct radv_graphics_pipeline *pipeline);
2267bf215546Sopenharmony_ci
2268bf215546Sopenharmony_cibool radv_pipeline_has_gs_copy_shader(const struct radv_pipeline *pipeline);
2269bf215546Sopenharmony_ci
2270bf215546Sopenharmony_cistruct radv_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
2271bf215546Sopenharmony_ci                                                 gl_shader_stage stage, int idx);
2272bf215546Sopenharmony_ci
2273bf215546Sopenharmony_cistruct radv_shader *radv_get_shader(const struct radv_pipeline *pipeline, gl_shader_stage stage);
2274bf215546Sopenharmony_ci
2275bf215546Sopenharmony_civoid radv_pipeline_emit_hw_cs(const struct radv_physical_device *pdevice, struct radeon_cmdbuf *cs,
2276bf215546Sopenharmony_ci                              const struct radv_shader *shader);
2277bf215546Sopenharmony_ci
2278bf215546Sopenharmony_civoid radv_pipeline_emit_compute_state(const struct radv_physical_device *pdevice,
2279bf215546Sopenharmony_ci                                      struct radeon_cmdbuf *cs, const struct radv_shader *shader);
2280bf215546Sopenharmony_ci
2281bf215546Sopenharmony_cistruct radv_graphics_pipeline_create_info {
2282bf215546Sopenharmony_ci   bool use_rectlist;
2283bf215546Sopenharmony_ci   bool db_depth_clear;
2284bf215546Sopenharmony_ci   bool db_stencil_clear;
2285bf215546Sopenharmony_ci   bool depth_compress_disable;
2286bf215546Sopenharmony_ci   bool stencil_compress_disable;
2287bf215546Sopenharmony_ci   bool resummarize_enable;
2288bf215546Sopenharmony_ci   uint32_t custom_blend_mode;
2289bf215546Sopenharmony_ci};
2290bf215546Sopenharmony_ci
2291bf215546Sopenharmony_civoid radv_pipeline_init(struct radv_device *device, struct radv_pipeline *pipeline,
2292bf215546Sopenharmony_ci                        enum radv_pipeline_type type);
2293bf215546Sopenharmony_ci
2294bf215546Sopenharmony_ciVkResult radv_graphics_pipeline_create(VkDevice device, VkPipelineCache cache,
2295bf215546Sopenharmony_ci                                       const VkGraphicsPipelineCreateInfo *pCreateInfo,
2296bf215546Sopenharmony_ci                                       const struct radv_graphics_pipeline_create_info *extra,
2297bf215546Sopenharmony_ci                                       const VkAllocationCallbacks *alloc, VkPipeline *pPipeline);
2298bf215546Sopenharmony_ci
2299bf215546Sopenharmony_ciVkResult radv_compute_pipeline_create(VkDevice _device, VkPipelineCache _cache,
2300bf215546Sopenharmony_ci                                      const VkComputePipelineCreateInfo *pCreateInfo,
2301bf215546Sopenharmony_ci                                      const VkAllocationCallbacks *pAllocator,
2302bf215546Sopenharmony_ci                                      const uint8_t *custom_hash,
2303bf215546Sopenharmony_ci                                      struct radv_pipeline_shader_stack_size *rt_stack_sizes,
2304bf215546Sopenharmony_ci                                      uint32_t rt_group_count, VkPipeline *pPipeline);
2305bf215546Sopenharmony_ci
2306bf215546Sopenharmony_civoid radv_pipeline_destroy(struct radv_device *device, struct radv_pipeline *pipeline,
2307bf215546Sopenharmony_ci                           const VkAllocationCallbacks *allocator);
2308bf215546Sopenharmony_ci
2309bf215546Sopenharmony_cistruct radv_binning_settings {
2310bf215546Sopenharmony_ci   unsigned context_states_per_bin;    /* allowed range: [1, 6] */
2311bf215546Sopenharmony_ci   unsigned persistent_states_per_bin; /* allowed range: [1, 32] */
2312bf215546Sopenharmony_ci   unsigned fpovs_per_batch;           /* allowed range: [0, 255], 0 = unlimited */
2313bf215546Sopenharmony_ci};
2314bf215546Sopenharmony_ci
2315bf215546Sopenharmony_cistruct radv_binning_settings radv_get_binning_settings(const struct radv_physical_device *pdev);
2316bf215546Sopenharmony_ci
2317bf215546Sopenharmony_cistruct vk_format_description;
2318bf215546Sopenharmony_ciuint32_t radv_translate_buffer_dataformat(const struct util_format_description *desc,
2319bf215546Sopenharmony_ci                                          int first_non_void);
2320bf215546Sopenharmony_ciuint32_t radv_translate_buffer_numformat(const struct util_format_description *desc,
2321bf215546Sopenharmony_ci                                         int first_non_void);
2322bf215546Sopenharmony_cibool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
2323bf215546Sopenharmony_civoid radv_translate_vertex_format(const struct radv_physical_device *pdevice, VkFormat format,
2324bf215546Sopenharmony_ci                                  const struct util_format_description *desc, unsigned *dfmt,
2325bf215546Sopenharmony_ci                                  unsigned *nfmt, bool *post_shuffle,
2326bf215546Sopenharmony_ci                                  enum radv_vs_input_alpha_adjust *alpha_adjust);
2327bf215546Sopenharmony_ciuint32_t radv_translate_colorformat(VkFormat format);
2328bf215546Sopenharmony_ciuint32_t radv_translate_color_numformat(VkFormat format, const struct util_format_description *desc,
2329bf215546Sopenharmony_ci                                        int first_non_void);
2330bf215546Sopenharmony_ciuint32_t radv_colorformat_endian_swap(uint32_t colorformat);
2331bf215546Sopenharmony_ciunsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
2332bf215546Sopenharmony_ciuint32_t radv_translate_dbformat(VkFormat format);
2333bf215546Sopenharmony_ciuint32_t radv_translate_tex_dataformat(VkFormat format, const struct util_format_description *desc,
2334bf215546Sopenharmony_ci                                       int first_non_void);
2335bf215546Sopenharmony_ciuint32_t radv_translate_tex_numformat(VkFormat format, const struct util_format_description *desc,
2336bf215546Sopenharmony_ci                                      int first_non_void);
2337bf215546Sopenharmony_cibool radv_format_pack_clear_color(VkFormat format, uint32_t clear_vals[2],
2338bf215546Sopenharmony_ci                                  VkClearColorValue *value);
2339bf215546Sopenharmony_cibool radv_is_storage_image_format_supported(struct radv_physical_device *physical_device,
2340bf215546Sopenharmony_ci                                            VkFormat format);
2341bf215546Sopenharmony_cibool radv_is_colorbuffer_format_supported(const struct radv_physical_device *pdevice,
2342bf215546Sopenharmony_ci                                          VkFormat format, bool *blendable);
2343bf215546Sopenharmony_cibool radv_dcc_formats_compatible(enum amd_gfx_level gfx_level, VkFormat format1, VkFormat format2,
2344bf215546Sopenharmony_ci                                 bool *sign_reinterpret);
2345bf215546Sopenharmony_cibool radv_is_atomic_format_supported(VkFormat format);
2346bf215546Sopenharmony_cibool radv_device_supports_etc(struct radv_physical_device *physical_device);
2347bf215546Sopenharmony_ci
2348bf215546Sopenharmony_cistatic const VkImageUsageFlags RADV_IMAGE_USAGE_WRITE_BITS =
2349bf215546Sopenharmony_ci   VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
2350bf215546Sopenharmony_ci   VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT;
2351bf215546Sopenharmony_ci
2352bf215546Sopenharmony_cistruct radv_image_plane {
2353bf215546Sopenharmony_ci   VkFormat format;
2354bf215546Sopenharmony_ci   struct radeon_surf surface;
2355bf215546Sopenharmony_ci};
2356bf215546Sopenharmony_ci
2357bf215546Sopenharmony_cistruct radv_image_binding {
2358bf215546Sopenharmony_ci   /* Set when bound */
2359bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
2360bf215546Sopenharmony_ci   VkDeviceSize offset;
2361bf215546Sopenharmony_ci};
2362bf215546Sopenharmony_ci
2363bf215546Sopenharmony_cistruct radv_image {
2364bf215546Sopenharmony_ci   struct vk_image vk;
2365bf215546Sopenharmony_ci
2366bf215546Sopenharmony_ci   struct ac_surf_info info;
2367bf215546Sopenharmony_ci
2368bf215546Sopenharmony_ci   VkDeviceSize size;
2369bf215546Sopenharmony_ci   uint32_t alignment;
2370bf215546Sopenharmony_ci
2371bf215546Sopenharmony_ci   unsigned queue_family_mask;
2372bf215546Sopenharmony_ci   bool exclusive;
2373bf215546Sopenharmony_ci   bool shareable;
2374bf215546Sopenharmony_ci   bool l2_coherent;
2375bf215546Sopenharmony_ci   bool dcc_sign_reinterpret;
2376bf215546Sopenharmony_ci   bool support_comp_to_single;
2377bf215546Sopenharmony_ci
2378bf215546Sopenharmony_ci   struct radv_image_binding bindings[3];
2379bf215546Sopenharmony_ci   bool tc_compatible_cmask;
2380bf215546Sopenharmony_ci
2381bf215546Sopenharmony_ci   uint64_t clear_value_offset;
2382bf215546Sopenharmony_ci   uint64_t fce_pred_offset;
2383bf215546Sopenharmony_ci   uint64_t dcc_pred_offset;
2384bf215546Sopenharmony_ci
2385bf215546Sopenharmony_ci   /*
2386bf215546Sopenharmony_ci    * Metadata for the TC-compat zrange workaround. If the 32-bit value
2387bf215546Sopenharmony_ci    * stored at this offset is UINT_MAX, the driver will emit
2388bf215546Sopenharmony_ci    * DB_Z_INFO.ZRANGE_PRECISION=0, otherwise it will skip the
2389bf215546Sopenharmony_ci    * SET_CONTEXT_REG packet.
2390bf215546Sopenharmony_ci    */
2391bf215546Sopenharmony_ci   uint64_t tc_compat_zrange_offset;
2392bf215546Sopenharmony_ci
2393bf215546Sopenharmony_ci   /* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
2394bf215546Sopenharmony_ci   VkDeviceMemory owned_memory;
2395bf215546Sopenharmony_ci
2396bf215546Sopenharmony_ci   unsigned plane_count;
2397bf215546Sopenharmony_ci   bool disjoint;
2398bf215546Sopenharmony_ci   struct radv_image_plane planes[0];
2399bf215546Sopenharmony_ci};
2400bf215546Sopenharmony_ci
2401bf215546Sopenharmony_ci/* Whether the image has a htile  that is known consistent with the contents of
2402bf215546Sopenharmony_ci * the image and is allowed to be in compressed form.
2403bf215546Sopenharmony_ci *
2404bf215546Sopenharmony_ci * If this is false reads that don't use the htile should be able to return
2405bf215546Sopenharmony_ci * correct results.
2406bf215546Sopenharmony_ci */
2407bf215546Sopenharmony_cibool radv_layout_is_htile_compressed(const struct radv_device *device,
2408bf215546Sopenharmony_ci                                     const struct radv_image *image, VkImageLayout layout,
2409bf215546Sopenharmony_ci                                     bool in_render_loop, unsigned queue_mask);
2410bf215546Sopenharmony_ci
2411bf215546Sopenharmony_cibool radv_layout_can_fast_clear(const struct radv_device *device, const struct radv_image *image,
2412bf215546Sopenharmony_ci                                unsigned level, VkImageLayout layout, bool in_render_loop,
2413bf215546Sopenharmony_ci                                unsigned queue_mask);
2414bf215546Sopenharmony_ci
2415bf215546Sopenharmony_cibool radv_layout_dcc_compressed(const struct radv_device *device, const struct radv_image *image,
2416bf215546Sopenharmony_ci                                unsigned level, VkImageLayout layout, bool in_render_loop,
2417bf215546Sopenharmony_ci                                unsigned queue_mask);
2418bf215546Sopenharmony_ci
2419bf215546Sopenharmony_cibool radv_layout_fmask_compressed(const struct radv_device *device, const struct radv_image *image,
2420bf215546Sopenharmony_ci                                  VkImageLayout layout, unsigned queue_mask);
2421bf215546Sopenharmony_ci
2422bf215546Sopenharmony_ci/**
2423bf215546Sopenharmony_ci * Return whether the image has CMASK metadata for color surfaces.
2424bf215546Sopenharmony_ci */
2425bf215546Sopenharmony_cistatic inline bool
2426bf215546Sopenharmony_ciradv_image_has_cmask(const struct radv_image *image)
2427bf215546Sopenharmony_ci{
2428bf215546Sopenharmony_ci   return image->planes[0].surface.cmask_offset;
2429bf215546Sopenharmony_ci}
2430bf215546Sopenharmony_ci
2431bf215546Sopenharmony_ci/**
2432bf215546Sopenharmony_ci * Return whether the image has FMASK metadata for color surfaces.
2433bf215546Sopenharmony_ci */
2434bf215546Sopenharmony_cistatic inline bool
2435bf215546Sopenharmony_ciradv_image_has_fmask(const struct radv_image *image)
2436bf215546Sopenharmony_ci{
2437bf215546Sopenharmony_ci   return image->planes[0].surface.fmask_offset;
2438bf215546Sopenharmony_ci}
2439bf215546Sopenharmony_ci
2440bf215546Sopenharmony_ci/**
2441bf215546Sopenharmony_ci * Return whether the image has DCC metadata for color surfaces.
2442bf215546Sopenharmony_ci */
2443bf215546Sopenharmony_cistatic inline bool
2444bf215546Sopenharmony_ciradv_image_has_dcc(const struct radv_image *image)
2445bf215546Sopenharmony_ci{
2446bf215546Sopenharmony_ci   return !(image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER) &&
2447bf215546Sopenharmony_ci          image->planes[0].surface.meta_offset;
2448bf215546Sopenharmony_ci}
2449bf215546Sopenharmony_ci
2450bf215546Sopenharmony_ci/**
2451bf215546Sopenharmony_ci * Return whether the image is TC-compatible CMASK.
2452bf215546Sopenharmony_ci */
2453bf215546Sopenharmony_cistatic inline bool
2454bf215546Sopenharmony_ciradv_image_is_tc_compat_cmask(const struct radv_image *image)
2455bf215546Sopenharmony_ci{
2456bf215546Sopenharmony_ci   return radv_image_has_fmask(image) && image->tc_compatible_cmask;
2457bf215546Sopenharmony_ci}
2458bf215546Sopenharmony_ci
2459bf215546Sopenharmony_ci/**
2460bf215546Sopenharmony_ci * Return whether DCC metadata is enabled for a level.
2461bf215546Sopenharmony_ci */
2462bf215546Sopenharmony_cistatic inline bool
2463bf215546Sopenharmony_ciradv_dcc_enabled(const struct radv_image *image, unsigned level)
2464bf215546Sopenharmony_ci{
2465bf215546Sopenharmony_ci   return radv_image_has_dcc(image) && level < image->planes[0].surface.num_meta_levels;
2466bf215546Sopenharmony_ci}
2467bf215546Sopenharmony_ci
2468bf215546Sopenharmony_ci/**
2469bf215546Sopenharmony_ci * Return whether the image has CB metadata.
2470bf215546Sopenharmony_ci */
2471bf215546Sopenharmony_cistatic inline bool
2472bf215546Sopenharmony_ciradv_image_has_CB_metadata(const struct radv_image *image)
2473bf215546Sopenharmony_ci{
2474bf215546Sopenharmony_ci   return radv_image_has_cmask(image) || radv_image_has_fmask(image) || radv_image_has_dcc(image);
2475bf215546Sopenharmony_ci}
2476bf215546Sopenharmony_ci
2477bf215546Sopenharmony_ci/**
2478bf215546Sopenharmony_ci * Return whether the image has HTILE metadata for depth surfaces.
2479bf215546Sopenharmony_ci */
2480bf215546Sopenharmony_cistatic inline bool
2481bf215546Sopenharmony_ciradv_image_has_htile(const struct radv_image *image)
2482bf215546Sopenharmony_ci{
2483bf215546Sopenharmony_ci   return image->planes[0].surface.flags & RADEON_SURF_Z_OR_SBUFFER &&
2484bf215546Sopenharmony_ci          image->planes[0].surface.meta_size;
2485bf215546Sopenharmony_ci}
2486bf215546Sopenharmony_ci
2487bf215546Sopenharmony_ci/**
2488bf215546Sopenharmony_ci * Return whether the image has VRS HTILE metadata for depth surfaces
2489bf215546Sopenharmony_ci */
2490bf215546Sopenharmony_cistatic inline bool
2491bf215546Sopenharmony_ciradv_image_has_vrs_htile(const struct radv_device *device, const struct radv_image *image)
2492bf215546Sopenharmony_ci{
2493bf215546Sopenharmony_ci   /* Any depth buffer can potentially use VRS. */
2494bf215546Sopenharmony_ci   return device->attachment_vrs_enabled && radv_image_has_htile(image) &&
2495bf215546Sopenharmony_ci          (image->vk.usage & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT);
2496bf215546Sopenharmony_ci}
2497bf215546Sopenharmony_ci
2498bf215546Sopenharmony_ci/**
2499bf215546Sopenharmony_ci * Return whether HTILE metadata is enabled for a level.
2500bf215546Sopenharmony_ci */
2501bf215546Sopenharmony_cistatic inline bool
2502bf215546Sopenharmony_ciradv_htile_enabled(const struct radv_image *image, unsigned level)
2503bf215546Sopenharmony_ci{
2504bf215546Sopenharmony_ci   return radv_image_has_htile(image) && level < image->planes[0].surface.num_meta_levels;
2505bf215546Sopenharmony_ci}
2506bf215546Sopenharmony_ci
2507bf215546Sopenharmony_ci/**
2508bf215546Sopenharmony_ci * Return whether the image is TC-compatible HTILE.
2509bf215546Sopenharmony_ci */
2510bf215546Sopenharmony_cistatic inline bool
2511bf215546Sopenharmony_ciradv_image_is_tc_compat_htile(const struct radv_image *image)
2512bf215546Sopenharmony_ci{
2513bf215546Sopenharmony_ci   return radv_image_has_htile(image) &&
2514bf215546Sopenharmony_ci          (image->planes[0].surface.flags & RADEON_SURF_TC_COMPATIBLE_HTILE);
2515bf215546Sopenharmony_ci}
2516bf215546Sopenharmony_ci
2517bf215546Sopenharmony_ci/**
2518bf215546Sopenharmony_ci * Return whether the entire HTILE buffer can be used for depth in order to
2519bf215546Sopenharmony_ci * improve HiZ Z-Range precision.
2520bf215546Sopenharmony_ci */
2521bf215546Sopenharmony_cistatic inline bool
2522bf215546Sopenharmony_ciradv_image_tile_stencil_disabled(const struct radv_device *device, const struct radv_image *image)
2523bf215546Sopenharmony_ci{
2524bf215546Sopenharmony_ci   if (device->physical_device->rad_info.gfx_level >= GFX9) {
2525bf215546Sopenharmony_ci      return !vk_format_has_stencil(image->vk.format) && !radv_image_has_vrs_htile(device, image);
2526bf215546Sopenharmony_ci   } else {
2527bf215546Sopenharmony_ci      /* Due to a hw bug, TILE_STENCIL_DISABLE must be set to 0 for
2528bf215546Sopenharmony_ci       * the TC-compat ZRANGE issue even if no stencil is used.
2529bf215546Sopenharmony_ci       */
2530bf215546Sopenharmony_ci      return !vk_format_has_stencil(image->vk.format) && !radv_image_is_tc_compat_htile(image);
2531bf215546Sopenharmony_ci   }
2532bf215546Sopenharmony_ci}
2533bf215546Sopenharmony_ci
2534bf215546Sopenharmony_cistatic inline bool
2535bf215546Sopenharmony_ciradv_image_has_clear_value(const struct radv_image *image)
2536bf215546Sopenharmony_ci{
2537bf215546Sopenharmony_ci   return image->clear_value_offset != 0;
2538bf215546Sopenharmony_ci}
2539bf215546Sopenharmony_ci
2540bf215546Sopenharmony_cistatic inline uint64_t
2541bf215546Sopenharmony_ciradv_image_get_fast_clear_va(const struct radv_image *image, uint32_t base_level)
2542bf215546Sopenharmony_ci{
2543bf215546Sopenharmony_ci   assert(radv_image_has_clear_value(image));
2544bf215546Sopenharmony_ci
2545bf215546Sopenharmony_ci   uint64_t va = radv_buffer_get_va(image->bindings[0].bo);
2546bf215546Sopenharmony_ci   va += image->bindings[0].offset + image->clear_value_offset + base_level * 8;
2547bf215546Sopenharmony_ci   return va;
2548bf215546Sopenharmony_ci}
2549bf215546Sopenharmony_ci
2550bf215546Sopenharmony_cistatic inline uint64_t
2551bf215546Sopenharmony_ciradv_image_get_fce_pred_va(const struct radv_image *image, uint32_t base_level)
2552bf215546Sopenharmony_ci{
2553bf215546Sopenharmony_ci   assert(image->fce_pred_offset != 0);
2554bf215546Sopenharmony_ci
2555bf215546Sopenharmony_ci   uint64_t va = radv_buffer_get_va(image->bindings[0].bo);
2556bf215546Sopenharmony_ci   va += image->bindings[0].offset + image->fce_pred_offset + base_level * 8;
2557bf215546Sopenharmony_ci   return va;
2558bf215546Sopenharmony_ci}
2559bf215546Sopenharmony_ci
2560bf215546Sopenharmony_cistatic inline uint64_t
2561bf215546Sopenharmony_ciradv_image_get_dcc_pred_va(const struct radv_image *image, uint32_t base_level)
2562bf215546Sopenharmony_ci{
2563bf215546Sopenharmony_ci   assert(image->dcc_pred_offset != 0);
2564bf215546Sopenharmony_ci
2565bf215546Sopenharmony_ci   uint64_t va = radv_buffer_get_va(image->bindings[0].bo);
2566bf215546Sopenharmony_ci   va += image->bindings[0].offset + image->dcc_pred_offset + base_level * 8;
2567bf215546Sopenharmony_ci   return va;
2568bf215546Sopenharmony_ci}
2569bf215546Sopenharmony_ci
2570bf215546Sopenharmony_cistatic inline uint64_t
2571bf215546Sopenharmony_ciradv_get_tc_compat_zrange_va(const struct radv_image *image, uint32_t base_level)
2572bf215546Sopenharmony_ci{
2573bf215546Sopenharmony_ci   assert(image->tc_compat_zrange_offset != 0);
2574bf215546Sopenharmony_ci
2575bf215546Sopenharmony_ci   uint64_t va = radv_buffer_get_va(image->bindings[0].bo);
2576bf215546Sopenharmony_ci   va += image->bindings[0].offset + image->tc_compat_zrange_offset + base_level * 4;
2577bf215546Sopenharmony_ci   return va;
2578bf215546Sopenharmony_ci}
2579bf215546Sopenharmony_ci
2580bf215546Sopenharmony_cistatic inline uint64_t
2581bf215546Sopenharmony_ciradv_get_ds_clear_value_va(const struct radv_image *image, uint32_t base_level)
2582bf215546Sopenharmony_ci{
2583bf215546Sopenharmony_ci   assert(radv_image_has_clear_value(image));
2584bf215546Sopenharmony_ci
2585bf215546Sopenharmony_ci   uint64_t va = radv_buffer_get_va(image->bindings[0].bo);
2586bf215546Sopenharmony_ci   va += image->bindings[0].offset + image->clear_value_offset + base_level * 8;
2587bf215546Sopenharmony_ci   return va;
2588bf215546Sopenharmony_ci}
2589bf215546Sopenharmony_ci
2590bf215546Sopenharmony_cistatic inline uint32_t
2591bf215546Sopenharmony_ciradv_get_htile_initial_value(const struct radv_device *device, const struct radv_image *image)
2592bf215546Sopenharmony_ci{
2593bf215546Sopenharmony_ci   uint32_t initial_value;
2594bf215546Sopenharmony_ci
2595bf215546Sopenharmony_ci   if (radv_image_tile_stencil_disabled(device, image)) {
2596bf215546Sopenharmony_ci      /* Z only (no stencil):
2597bf215546Sopenharmony_ci       *
2598bf215546Sopenharmony_ci       * |31     18|17      4|3     0|
2599bf215546Sopenharmony_ci       * +---------+---------+-------+
2600bf215546Sopenharmony_ci       * |  Max Z  |  Min Z  | ZMask |
2601bf215546Sopenharmony_ci       */
2602bf215546Sopenharmony_ci      initial_value = 0xfffc000f;
2603bf215546Sopenharmony_ci   } else {
2604bf215546Sopenharmony_ci      /* Z and stencil:
2605bf215546Sopenharmony_ci       *
2606bf215546Sopenharmony_ci       * |31       12|11 10|9    8|7   6|5   4|3     0|
2607bf215546Sopenharmony_ci       * +-----------+-----+------+-----+-----+-------+
2608bf215546Sopenharmony_ci       * |  Z Range  |     | SMem | SR1 | SR0 | ZMask |
2609bf215546Sopenharmony_ci       *
2610bf215546Sopenharmony_ci       * SR0/SR1 contains the stencil test results. Initializing
2611bf215546Sopenharmony_ci       * SR0/SR1 to 0x3 means the stencil test result is unknown.
2612bf215546Sopenharmony_ci       *
2613bf215546Sopenharmony_ci       * Z, stencil and 4 bit VRS encoding:
2614bf215546Sopenharmony_ci       * |31       12|11        10|9    8|7          6|5   4|3     0|
2615bf215546Sopenharmony_ci       * +-----------+------------+------+------------+-----+-------+
2616bf215546Sopenharmony_ci       * |  Z Range  | VRS y-rate | SMem | VRS x-rate | SR0 | ZMask |
2617bf215546Sopenharmony_ci       */
2618bf215546Sopenharmony_ci      if (radv_image_has_vrs_htile(device, image)) {
2619bf215546Sopenharmony_ci         /* Initialize the VRS x-rate value at 0, so the hw interprets it as 1 sample. */
2620bf215546Sopenharmony_ci         initial_value = 0xfffff33f;
2621bf215546Sopenharmony_ci      } else {
2622bf215546Sopenharmony_ci         initial_value = 0xfffff3ff;
2623bf215546Sopenharmony_ci      }
2624bf215546Sopenharmony_ci   }
2625bf215546Sopenharmony_ci
2626bf215546Sopenharmony_ci   return initial_value;
2627bf215546Sopenharmony_ci}
2628bf215546Sopenharmony_ci
2629bf215546Sopenharmony_cistatic inline bool
2630bf215546Sopenharmony_ciradv_image_get_iterate256(struct radv_device *device, struct radv_image *image)
2631bf215546Sopenharmony_ci{
2632bf215546Sopenharmony_ci   /* ITERATE_256 is required for depth or stencil MSAA images that are TC-compatible HTILE. */
2633bf215546Sopenharmony_ci   return device->physical_device->rad_info.gfx_level >= GFX10 &&
2634bf215546Sopenharmony_ci          (image->vk.usage &
2635bf215546Sopenharmony_ci           (VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)) &&
2636bf215546Sopenharmony_ci          radv_image_is_tc_compat_htile(image) && image->info.samples > 1;
2637bf215546Sopenharmony_ci}
2638bf215546Sopenharmony_ci
2639bf215546Sopenharmony_ciunsigned radv_image_queue_family_mask(const struct radv_image *image,
2640bf215546Sopenharmony_ci                                      enum radv_queue_family family,
2641bf215546Sopenharmony_ci                                      enum radv_queue_family queue_family);
2642bf215546Sopenharmony_ci
2643bf215546Sopenharmony_cistatic inline uint32_t
2644bf215546Sopenharmony_ciradv_get_layerCount(const struct radv_image *image, const VkImageSubresourceRange *range)
2645bf215546Sopenharmony_ci{
2646bf215546Sopenharmony_ci   return range->layerCount == VK_REMAINING_ARRAY_LAYERS
2647bf215546Sopenharmony_ci             ? image->info.array_size - range->baseArrayLayer
2648bf215546Sopenharmony_ci             : range->layerCount;
2649bf215546Sopenharmony_ci}
2650bf215546Sopenharmony_ci
2651bf215546Sopenharmony_cistatic inline uint32_t
2652bf215546Sopenharmony_ciradv_get_levelCount(const struct radv_image *image, const VkImageSubresourceRange *range)
2653bf215546Sopenharmony_ci{
2654bf215546Sopenharmony_ci   return range->levelCount == VK_REMAINING_MIP_LEVELS ? image->info.levels - range->baseMipLevel
2655bf215546Sopenharmony_ci                                                       : range->levelCount;
2656bf215546Sopenharmony_ci}
2657bf215546Sopenharmony_ci
2658bf215546Sopenharmony_cibool radv_image_is_renderable(struct radv_device *device, struct radv_image *image);
2659bf215546Sopenharmony_ci
2660bf215546Sopenharmony_cistruct radeon_bo_metadata;
2661bf215546Sopenharmony_civoid radv_init_metadata(struct radv_device *device, struct radv_image *image,
2662bf215546Sopenharmony_ci                        struct radeon_bo_metadata *metadata);
2663bf215546Sopenharmony_ci
2664bf215546Sopenharmony_civoid radv_image_override_offset_stride(struct radv_device *device, struct radv_image *image,
2665bf215546Sopenharmony_ci                                       uint64_t offset, uint32_t stride);
2666bf215546Sopenharmony_ci
2667bf215546Sopenharmony_ciunion radv_descriptor {
2668bf215546Sopenharmony_ci   struct {
2669bf215546Sopenharmony_ci      uint32_t plane0_descriptor[8];
2670bf215546Sopenharmony_ci      uint32_t fmask_descriptor[8];
2671bf215546Sopenharmony_ci   };
2672bf215546Sopenharmony_ci   struct {
2673bf215546Sopenharmony_ci      uint32_t plane_descriptors[3][8];
2674bf215546Sopenharmony_ci   };
2675bf215546Sopenharmony_ci};
2676bf215546Sopenharmony_ci
2677bf215546Sopenharmony_cistruct radv_image_view {
2678bf215546Sopenharmony_ci   struct vk_image_view vk;
2679bf215546Sopenharmony_ci   struct radv_image *image; /**< VkImageViewCreateInfo::image */
2680bf215546Sopenharmony_ci
2681bf215546Sopenharmony_ci   unsigned plane_id;
2682bf215546Sopenharmony_ci   VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
2683bf215546Sopenharmony_ci
2684bf215546Sopenharmony_ci   /* Whether the image iview supports fast clear. */
2685bf215546Sopenharmony_ci   bool support_fast_clear;
2686bf215546Sopenharmony_ci
2687bf215546Sopenharmony_ci   bool disable_dcc_mrt;
2688bf215546Sopenharmony_ci
2689bf215546Sopenharmony_ci   union radv_descriptor descriptor;
2690bf215546Sopenharmony_ci
2691bf215546Sopenharmony_ci   /* Descriptor for use as a storage image as opposed to a sampled image.
2692bf215546Sopenharmony_ci    * This has a few differences for cube maps (e.g. type).
2693bf215546Sopenharmony_ci    */
2694bf215546Sopenharmony_ci   union radv_descriptor storage_descriptor;
2695bf215546Sopenharmony_ci};
2696bf215546Sopenharmony_ci
2697bf215546Sopenharmony_cistruct radv_image_create_info {
2698bf215546Sopenharmony_ci   const VkImageCreateInfo *vk_info;
2699bf215546Sopenharmony_ci   bool scanout;
2700bf215546Sopenharmony_ci   bool no_metadata_planes;
2701bf215546Sopenharmony_ci   bool prime_blit_src;
2702bf215546Sopenharmony_ci   const struct radeon_bo_metadata *bo_metadata;
2703bf215546Sopenharmony_ci};
2704bf215546Sopenharmony_ci
2705bf215546Sopenharmony_ciVkResult
2706bf215546Sopenharmony_ciradv_image_create_layout(struct radv_device *device, struct radv_image_create_info create_info,
2707bf215546Sopenharmony_ci                         const struct VkImageDrmFormatModifierExplicitCreateInfoEXT *mod_info,
2708bf215546Sopenharmony_ci                         struct radv_image *image);
2709bf215546Sopenharmony_ci
2710bf215546Sopenharmony_ciVkResult radv_image_create(VkDevice _device, const struct radv_image_create_info *info,
2711bf215546Sopenharmony_ci                           const VkAllocationCallbacks *alloc, VkImage *pImage);
2712bf215546Sopenharmony_ci
2713bf215546Sopenharmony_cibool radv_are_formats_dcc_compatible(const struct radv_physical_device *pdev, const void *pNext,
2714bf215546Sopenharmony_ci                                     VkFormat format, VkImageCreateFlags flags,
2715bf215546Sopenharmony_ci                                     bool *sign_reinterpret);
2716bf215546Sopenharmony_ci
2717bf215546Sopenharmony_cibool vi_alpha_is_on_msb(struct radv_device *device, VkFormat format);
2718bf215546Sopenharmony_ci
2719bf215546Sopenharmony_ciVkResult radv_image_from_gralloc(VkDevice device_h, const VkImageCreateInfo *base_info,
2720bf215546Sopenharmony_ci                                 const VkNativeBufferANDROID *gralloc_info,
2721bf215546Sopenharmony_ci                                 const VkAllocationCallbacks *alloc, VkImage *out_image_h);
2722bf215546Sopenharmony_ciuint64_t radv_ahb_usage_from_vk_usage(const VkImageCreateFlags vk_create,
2723bf215546Sopenharmony_ci                                      const VkImageUsageFlags vk_usage);
2724bf215546Sopenharmony_ciVkResult radv_import_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,
2725bf215546Sopenharmony_ci                                unsigned priority,
2726bf215546Sopenharmony_ci                                const VkImportAndroidHardwareBufferInfoANDROID *info);
2727bf215546Sopenharmony_ciVkResult radv_create_ahb_memory(struct radv_device *device, struct radv_device_memory *mem,
2728bf215546Sopenharmony_ci                                unsigned priority, const VkMemoryAllocateInfo *pAllocateInfo);
2729bf215546Sopenharmony_ci
2730bf215546Sopenharmony_ciVkFormat radv_select_android_external_format(const void *next, VkFormat default_format);
2731bf215546Sopenharmony_ci
2732bf215546Sopenharmony_cibool radv_android_gralloc_supports_format(VkFormat format, VkImageUsageFlagBits usage);
2733bf215546Sopenharmony_ci
2734bf215546Sopenharmony_cistruct radv_image_view_extra_create_info {
2735bf215546Sopenharmony_ci   bool disable_compression;
2736bf215546Sopenharmony_ci   bool enable_compression;
2737bf215546Sopenharmony_ci   bool disable_dcc_mrt;
2738bf215546Sopenharmony_ci   bool from_client; /**< Set only if this came from vkCreateImage */
2739bf215546Sopenharmony_ci};
2740bf215546Sopenharmony_ci
2741bf215546Sopenharmony_civoid radv_image_view_init(struct radv_image_view *view, struct radv_device *device,
2742bf215546Sopenharmony_ci                          const VkImageViewCreateInfo *pCreateInfo,
2743bf215546Sopenharmony_ci                          VkImageCreateFlags img_create_flags,
2744bf215546Sopenharmony_ci                          const struct radv_image_view_extra_create_info *extra_create_info);
2745bf215546Sopenharmony_civoid radv_image_view_finish(struct radv_image_view *iview);
2746bf215546Sopenharmony_ci
2747bf215546Sopenharmony_ciVkFormat radv_get_aspect_format(struct radv_image *image, VkImageAspectFlags mask);
2748bf215546Sopenharmony_ci
2749bf215546Sopenharmony_cistruct radv_sampler_ycbcr_conversion_state {
2750bf215546Sopenharmony_ci   VkFormat format;
2751bf215546Sopenharmony_ci   VkSamplerYcbcrModelConversion ycbcr_model;
2752bf215546Sopenharmony_ci   VkSamplerYcbcrRange ycbcr_range;
2753bf215546Sopenharmony_ci   VkComponentMapping components;
2754bf215546Sopenharmony_ci   VkChromaLocation chroma_offsets[2];
2755bf215546Sopenharmony_ci   VkFilter chroma_filter;
2756bf215546Sopenharmony_ci};
2757bf215546Sopenharmony_ci
2758bf215546Sopenharmony_cistruct radv_sampler_ycbcr_conversion {
2759bf215546Sopenharmony_ci   struct vk_object_base base;
2760bf215546Sopenharmony_ci   /* The state is hashed for the descriptor set layout. */
2761bf215546Sopenharmony_ci   struct radv_sampler_ycbcr_conversion_state state;
2762bf215546Sopenharmony_ci};
2763bf215546Sopenharmony_ci
2764bf215546Sopenharmony_cistruct radv_buffer_view {
2765bf215546Sopenharmony_ci   struct vk_object_base base;
2766bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
2767bf215546Sopenharmony_ci   VkFormat vk_format;
2768bf215546Sopenharmony_ci   uint64_t range; /**< VkBufferViewCreateInfo::range */
2769bf215546Sopenharmony_ci   uint32_t state[4];
2770bf215546Sopenharmony_ci};
2771bf215546Sopenharmony_civoid radv_buffer_view_init(struct radv_buffer_view *view, struct radv_device *device,
2772bf215546Sopenharmony_ci                           const VkBufferViewCreateInfo *pCreateInfo);
2773bf215546Sopenharmony_civoid radv_buffer_view_finish(struct radv_buffer_view *view);
2774bf215546Sopenharmony_ci
2775bf215546Sopenharmony_cistatic inline bool
2776bf215546Sopenharmony_ciradv_image_extent_compare(const struct radv_image *image, const VkExtent3D *extent)
2777bf215546Sopenharmony_ci{
2778bf215546Sopenharmony_ci   if (extent->width != image->info.width || extent->height != image->info.height ||
2779bf215546Sopenharmony_ci       extent->depth != image->info.depth)
2780bf215546Sopenharmony_ci      return false;
2781bf215546Sopenharmony_ci   return true;
2782bf215546Sopenharmony_ci}
2783bf215546Sopenharmony_ci
2784bf215546Sopenharmony_cistruct radv_sampler {
2785bf215546Sopenharmony_ci   struct vk_object_base base;
2786bf215546Sopenharmony_ci   uint32_t state[4];
2787bf215546Sopenharmony_ci   struct radv_sampler_ycbcr_conversion *ycbcr_sampler;
2788bf215546Sopenharmony_ci   uint32_t border_color_slot;
2789bf215546Sopenharmony_ci};
2790bf215546Sopenharmony_ci
2791bf215546Sopenharmony_cistruct radv_subpass_barrier {
2792bf215546Sopenharmony_ci   VkPipelineStageFlags2 src_stage_mask;
2793bf215546Sopenharmony_ci   VkPipelineStageFlags2 dst_stage_mask;
2794bf215546Sopenharmony_ci   VkAccessFlags2 src_access_mask;
2795bf215546Sopenharmony_ci   VkAccessFlags2 dst_access_mask;
2796bf215546Sopenharmony_ci};
2797bf215546Sopenharmony_ci
2798bf215546Sopenharmony_civoid radv_emit_subpass_barrier(struct radv_cmd_buffer *cmd_buffer,
2799bf215546Sopenharmony_ci                               const struct radv_subpass_barrier *barrier);
2800bf215546Sopenharmony_ci
2801bf215546Sopenharmony_cistruct radv_subpass_attachment {
2802bf215546Sopenharmony_ci   uint32_t attachment;
2803bf215546Sopenharmony_ci   VkImageLayout layout;
2804bf215546Sopenharmony_ci   VkImageLayout stencil_layout;
2805bf215546Sopenharmony_ci   bool in_render_loop;
2806bf215546Sopenharmony_ci};
2807bf215546Sopenharmony_ci
2808bf215546Sopenharmony_cistruct radv_subpass {
2809bf215546Sopenharmony_ci   uint32_t attachment_count;
2810bf215546Sopenharmony_ci   struct radv_subpass_attachment *attachments;
2811bf215546Sopenharmony_ci
2812bf215546Sopenharmony_ci   uint32_t input_count;
2813bf215546Sopenharmony_ci   uint32_t color_count;
2814bf215546Sopenharmony_ci   struct radv_subpass_attachment *input_attachments;
2815bf215546Sopenharmony_ci   struct radv_subpass_attachment *color_attachments;
2816bf215546Sopenharmony_ci   struct radv_subpass_attachment *resolve_attachments;
2817bf215546Sopenharmony_ci   struct radv_subpass_attachment *depth_stencil_attachment;
2818bf215546Sopenharmony_ci   struct radv_subpass_attachment *ds_resolve_attachment;
2819bf215546Sopenharmony_ci   struct radv_subpass_attachment *vrs_attachment;
2820bf215546Sopenharmony_ci   VkResolveModeFlagBits depth_resolve_mode;
2821bf215546Sopenharmony_ci   VkResolveModeFlagBits stencil_resolve_mode;
2822bf215546Sopenharmony_ci
2823bf215546Sopenharmony_ci   /** Subpass has at least one color resolve attachment */
2824bf215546Sopenharmony_ci   bool has_color_resolve;
2825bf215546Sopenharmony_ci
2826bf215546Sopenharmony_ci   struct radv_subpass_barrier start_barrier;
2827bf215546Sopenharmony_ci
2828bf215546Sopenharmony_ci   uint32_t view_mask;
2829bf215546Sopenharmony_ci
2830bf215546Sopenharmony_ci   VkSampleCountFlagBits color_sample_count;
2831bf215546Sopenharmony_ci   VkSampleCountFlagBits depth_sample_count;
2832bf215546Sopenharmony_ci   VkSampleCountFlagBits max_sample_count;
2833bf215546Sopenharmony_ci
2834bf215546Sopenharmony_ci   /* Whether the subpass has ingoing/outgoing external dependencies. */
2835bf215546Sopenharmony_ci   bool has_ingoing_dep;
2836bf215546Sopenharmony_ci   bool has_outgoing_dep;
2837bf215546Sopenharmony_ci};
2838bf215546Sopenharmony_ci
2839bf215546Sopenharmony_ciuint32_t radv_get_subpass_id(struct radv_cmd_buffer *cmd_buffer);
2840bf215546Sopenharmony_ci
2841bf215546Sopenharmony_cistruct radv_render_pass_attachment {
2842bf215546Sopenharmony_ci   VkFormat format;
2843bf215546Sopenharmony_ci   uint32_t samples;
2844bf215546Sopenharmony_ci   VkAttachmentLoadOp load_op;
2845bf215546Sopenharmony_ci   VkAttachmentLoadOp stencil_load_op;
2846bf215546Sopenharmony_ci   VkImageLayout initial_layout;
2847bf215546Sopenharmony_ci   VkImageLayout final_layout;
2848bf215546Sopenharmony_ci   VkImageLayout stencil_initial_layout;
2849bf215546Sopenharmony_ci   VkImageLayout stencil_final_layout;
2850bf215546Sopenharmony_ci
2851bf215546Sopenharmony_ci   /* The subpass id in which the attachment will be used first/last. */
2852bf215546Sopenharmony_ci   uint32_t first_subpass_idx;
2853bf215546Sopenharmony_ci   uint32_t last_subpass_idx;
2854bf215546Sopenharmony_ci};
2855bf215546Sopenharmony_ci
2856bf215546Sopenharmony_cistruct radv_render_pass {
2857bf215546Sopenharmony_ci   struct vk_object_base base;
2858bf215546Sopenharmony_ci   uint32_t attachment_count;
2859bf215546Sopenharmony_ci   uint32_t subpass_count;
2860bf215546Sopenharmony_ci   struct radv_subpass_attachment *subpass_attachments;
2861bf215546Sopenharmony_ci   struct radv_render_pass_attachment *attachments;
2862bf215546Sopenharmony_ci   struct radv_subpass_barrier end_barrier;
2863bf215546Sopenharmony_ci   struct radv_subpass subpasses[0];
2864bf215546Sopenharmony_ci};
2865bf215546Sopenharmony_ci
2866bf215546Sopenharmony_ciVkResult radv_device_init_meta(struct radv_device *device);
2867bf215546Sopenharmony_civoid radv_device_finish_meta(struct radv_device *device);
2868bf215546Sopenharmony_ci
2869bf215546Sopenharmony_cistruct radv_query_pool {
2870bf215546Sopenharmony_ci   struct vk_object_base base;
2871bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
2872bf215546Sopenharmony_ci   uint32_t stride;
2873bf215546Sopenharmony_ci   uint32_t availability_offset;
2874bf215546Sopenharmony_ci   uint64_t size;
2875bf215546Sopenharmony_ci   char *ptr;
2876bf215546Sopenharmony_ci   VkQueryType type;
2877bf215546Sopenharmony_ci   uint32_t pipeline_stats_mask;
2878bf215546Sopenharmony_ci   bool uses_gds; /* For NGG GS on GFX10+ */
2879bf215546Sopenharmony_ci};
2880bf215546Sopenharmony_ci
2881bf215546Sopenharmony_cistruct radv_perfcounter_impl;
2882bf215546Sopenharmony_ci
2883bf215546Sopenharmony_cistruct radv_pc_query_pool {
2884bf215546Sopenharmony_ci   struct radv_query_pool b;
2885bf215546Sopenharmony_ci
2886bf215546Sopenharmony_ci   uint32_t *pc_regs;
2887bf215546Sopenharmony_ci   unsigned num_pc_regs;
2888bf215546Sopenharmony_ci
2889bf215546Sopenharmony_ci   unsigned num_passes;
2890bf215546Sopenharmony_ci
2891bf215546Sopenharmony_ci   unsigned num_counters;
2892bf215546Sopenharmony_ci   struct radv_perfcounter_impl *counters;
2893bf215546Sopenharmony_ci};
2894bf215546Sopenharmony_ci
2895bf215546Sopenharmony_civoid radv_pc_deinit_query_pool(struct radv_pc_query_pool *pool);
2896bf215546Sopenharmony_ciVkResult radv_pc_init_query_pool(struct radv_physical_device *pdevice,
2897bf215546Sopenharmony_ci                                 const VkQueryPoolCreateInfo *pCreateInfo,
2898bf215546Sopenharmony_ci                                 struct radv_pc_query_pool *pool);
2899bf215546Sopenharmony_civoid radv_pc_begin_query(struct radv_cmd_buffer *cmd_buffer, struct radv_pc_query_pool *pool,
2900bf215546Sopenharmony_ci                         uint64_t va);
2901bf215546Sopenharmony_civoid radv_pc_end_query(struct radv_cmd_buffer *cmd_buffer, struct radv_pc_query_pool *pool,
2902bf215546Sopenharmony_ci                       uint64_t va);
2903bf215546Sopenharmony_civoid radv_pc_get_results(const struct radv_pc_query_pool *pc_pool, const uint64_t *data, void *out);
2904bf215546Sopenharmony_ci
2905bf215546Sopenharmony_cibool radv_queue_internal_submit(struct radv_queue *queue, struct radeon_cmdbuf *cs);
2906bf215546Sopenharmony_ci
2907bf215546Sopenharmony_ciint radv_queue_init(struct radv_device *device, struct radv_queue *queue, int idx,
2908bf215546Sopenharmony_ci                    const VkDeviceQueueCreateInfo *create_info,
2909bf215546Sopenharmony_ci                    const VkDeviceQueueGlobalPriorityCreateInfoKHR *global_priority);
2910bf215546Sopenharmony_ci
2911bf215546Sopenharmony_civoid radv_set_descriptor_set(struct radv_cmd_buffer *cmd_buffer, VkPipelineBindPoint bind_point,
2912bf215546Sopenharmony_ci                             struct radv_descriptor_set *set, unsigned idx);
2913bf215546Sopenharmony_ci
2914bf215546Sopenharmony_civoid radv_cmd_update_descriptor_sets(struct radv_device *device, struct radv_cmd_buffer *cmd_buffer,
2915bf215546Sopenharmony_ci                                     VkDescriptorSet overrideSet, uint32_t descriptorWriteCount,
2916bf215546Sopenharmony_ci                                     const VkWriteDescriptorSet *pDescriptorWrites,
2917bf215546Sopenharmony_ci                                     uint32_t descriptorCopyCount,
2918bf215546Sopenharmony_ci                                     const VkCopyDescriptorSet *pDescriptorCopies);
2919bf215546Sopenharmony_ci
2920bf215546Sopenharmony_civoid radv_cmd_update_descriptor_set_with_template(struct radv_device *device,
2921bf215546Sopenharmony_ci                                                  struct radv_cmd_buffer *cmd_buffer,
2922bf215546Sopenharmony_ci                                                  struct radv_descriptor_set *set,
2923bf215546Sopenharmony_ci                                                  VkDescriptorUpdateTemplate descriptorUpdateTemplate,
2924bf215546Sopenharmony_ci                                                  const void *pData);
2925bf215546Sopenharmony_ci
2926bf215546Sopenharmony_civoid radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
2927bf215546Sopenharmony_ci                                   VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout _layout,
2928bf215546Sopenharmony_ci                                   uint32_t set, uint32_t descriptorWriteCount,
2929bf215546Sopenharmony_ci                                   const VkWriteDescriptorSet *pDescriptorWrites);
2930bf215546Sopenharmony_ci
2931bf215546Sopenharmony_ciuint32_t radv_init_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
2932bf215546Sopenharmony_ci                       const VkImageSubresourceRange *range, uint32_t value);
2933bf215546Sopenharmony_ci
2934bf215546Sopenharmony_ciuint32_t radv_init_fmask(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
2935bf215546Sopenharmony_ci                         const VkImageSubresourceRange *range);
2936bf215546Sopenharmony_ci
2937bf215546Sopenharmony_ci/* radv_nir_to_llvm.c */
2938bf215546Sopenharmony_cistruct radv_shader_args;
2939bf215546Sopenharmony_cistruct radv_nir_compiler_options;
2940bf215546Sopenharmony_cistruct radv_shader_info;
2941bf215546Sopenharmony_ci
2942bf215546Sopenharmony_civoid llvm_compile_shader(const struct radv_nir_compiler_options *options,
2943bf215546Sopenharmony_ci                         const struct radv_shader_info *info, unsigned shader_count,
2944bf215546Sopenharmony_ci                         struct nir_shader *const *shaders, struct radv_shader_binary **binary,
2945bf215546Sopenharmony_ci                         const struct radv_shader_args *args);
2946bf215546Sopenharmony_ci
2947bf215546Sopenharmony_ci/* radv_shader_info.h */
2948bf215546Sopenharmony_cistruct radv_shader_info;
2949bf215546Sopenharmony_ci
2950bf215546Sopenharmony_civoid radv_nir_shader_info_pass(struct radv_device *device, const struct nir_shader *nir,
2951bf215546Sopenharmony_ci                               const struct radv_pipeline_layout *layout,
2952bf215546Sopenharmony_ci                               const struct radv_pipeline_key *pipeline_key,
2953bf215546Sopenharmony_ci                               struct radv_shader_info *info);
2954bf215546Sopenharmony_ci
2955bf215546Sopenharmony_civoid radv_nir_shader_info_init(struct radv_shader_info *info);
2956bf215546Sopenharmony_ci
2957bf215546Sopenharmony_cibool radv_thread_trace_init(struct radv_device *device);
2958bf215546Sopenharmony_civoid radv_thread_trace_finish(struct radv_device *device);
2959bf215546Sopenharmony_cibool radv_begin_thread_trace(struct radv_queue *queue);
2960bf215546Sopenharmony_cibool radv_end_thread_trace(struct radv_queue *queue);
2961bf215546Sopenharmony_cibool radv_get_thread_trace(struct radv_queue *queue, struct ac_thread_trace *thread_trace);
2962bf215546Sopenharmony_civoid radv_emit_thread_trace_userdata(struct radv_cmd_buffer *cmd_buffer, const void *data,
2963bf215546Sopenharmony_ci                                     uint32_t num_dwords);
2964bf215546Sopenharmony_cibool radv_is_instruction_timing_enabled(void);
2965bf215546Sopenharmony_ci
2966bf215546Sopenharmony_civoid radv_emit_inhibit_clockgating(struct radv_device *device, struct radeon_cmdbuf *cs,
2967bf215546Sopenharmony_ci                                   bool inhibit);
2968bf215546Sopenharmony_civoid radv_emit_spi_config_cntl(struct radv_device *device, struct radeon_cmdbuf *cs, bool enable);
2969bf215546Sopenharmony_ci
2970bf215546Sopenharmony_cibool radv_sdma_copy_image(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
2971bf215546Sopenharmony_ci                          struct radv_buffer *buffer, const VkBufferImageCopy2 *region);
2972bf215546Sopenharmony_ci
2973bf215546Sopenharmony_ci/* radv_sqtt_layer_.c */
2974bf215546Sopenharmony_cistruct radv_barrier_data {
2975bf215546Sopenharmony_ci   union {
2976bf215546Sopenharmony_ci      struct {
2977bf215546Sopenharmony_ci         uint16_t depth_stencil_expand : 1;
2978bf215546Sopenharmony_ci         uint16_t htile_hiz_range_expand : 1;
2979bf215546Sopenharmony_ci         uint16_t depth_stencil_resummarize : 1;
2980bf215546Sopenharmony_ci         uint16_t dcc_decompress : 1;
2981bf215546Sopenharmony_ci         uint16_t fmask_decompress : 1;
2982bf215546Sopenharmony_ci         uint16_t fast_clear_eliminate : 1;
2983bf215546Sopenharmony_ci         uint16_t fmask_color_expand : 1;
2984bf215546Sopenharmony_ci         uint16_t init_mask_ram : 1;
2985bf215546Sopenharmony_ci         uint16_t reserved : 8;
2986bf215546Sopenharmony_ci      };
2987bf215546Sopenharmony_ci      uint16_t all;
2988bf215546Sopenharmony_ci   } layout_transitions;
2989bf215546Sopenharmony_ci};
2990bf215546Sopenharmony_ci
2991bf215546Sopenharmony_ci/**
2992bf215546Sopenharmony_ci * Value for the reason field of an RGP barrier start marker originating from
2993bf215546Sopenharmony_ci * the Vulkan client (does not include PAL-defined values). (Table 15)
2994bf215546Sopenharmony_ci */
2995bf215546Sopenharmony_cienum rgp_barrier_reason {
2996bf215546Sopenharmony_ci   RGP_BARRIER_UNKNOWN_REASON = 0xFFFFFFFF,
2997bf215546Sopenharmony_ci
2998bf215546Sopenharmony_ci   /* External app-generated barrier reasons, i.e. API synchronization
2999bf215546Sopenharmony_ci    * commands Range of valid values: [0x00000001 ... 0x7FFFFFFF].
3000bf215546Sopenharmony_ci    */
3001bf215546Sopenharmony_ci   RGP_BARRIER_EXTERNAL_CMD_PIPELINE_BARRIER = 0x00000001,
3002bf215546Sopenharmony_ci   RGP_BARRIER_EXTERNAL_RENDER_PASS_SYNC = 0x00000002,
3003bf215546Sopenharmony_ci   RGP_BARRIER_EXTERNAL_CMD_WAIT_EVENTS = 0x00000003,
3004bf215546Sopenharmony_ci
3005bf215546Sopenharmony_ci   /* Internal barrier reasons, i.e. implicit synchronization inserted by
3006bf215546Sopenharmony_ci    * the Vulkan driver Range of valid values: [0xC0000000 ... 0xFFFFFFFE].
3007bf215546Sopenharmony_ci    */
3008bf215546Sopenharmony_ci   RGP_BARRIER_INTERNAL_BASE = 0xC0000000,
3009bf215546Sopenharmony_ci   RGP_BARRIER_INTERNAL_PRE_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 0,
3010bf215546Sopenharmony_ci   RGP_BARRIER_INTERNAL_POST_RESET_QUERY_POOL_SYNC = RGP_BARRIER_INTERNAL_BASE + 1,
3011bf215546Sopenharmony_ci   RGP_BARRIER_INTERNAL_GPU_EVENT_RECYCLE_STALL = RGP_BARRIER_INTERNAL_BASE + 2,
3012bf215546Sopenharmony_ci   RGP_BARRIER_INTERNAL_PRE_COPY_QUERY_POOL_RESULTS_SYNC = RGP_BARRIER_INTERNAL_BASE + 3
3013bf215546Sopenharmony_ci};
3014bf215546Sopenharmony_ci
3015bf215546Sopenharmony_civoid radv_describe_begin_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
3016bf215546Sopenharmony_civoid radv_describe_end_cmd_buffer(struct radv_cmd_buffer *cmd_buffer);
3017bf215546Sopenharmony_civoid radv_describe_draw(struct radv_cmd_buffer *cmd_buffer);
3018bf215546Sopenharmony_civoid radv_describe_dispatch(struct radv_cmd_buffer *cmd_buffer, int x, int y, int z);
3019bf215546Sopenharmony_civoid radv_describe_begin_render_pass_clear(struct radv_cmd_buffer *cmd_buffer,
3020bf215546Sopenharmony_ci                                           VkImageAspectFlagBits aspects);
3021bf215546Sopenharmony_civoid radv_describe_end_render_pass_clear(struct radv_cmd_buffer *cmd_buffer);
3022bf215546Sopenharmony_civoid radv_describe_begin_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);
3023bf215546Sopenharmony_civoid radv_describe_end_render_pass_resolve(struct radv_cmd_buffer *cmd_buffer);
3024bf215546Sopenharmony_civoid radv_describe_barrier_start(struct radv_cmd_buffer *cmd_buffer,
3025bf215546Sopenharmony_ci                                 enum rgp_barrier_reason reason);
3026bf215546Sopenharmony_civoid radv_describe_barrier_end(struct radv_cmd_buffer *cmd_buffer);
3027bf215546Sopenharmony_civoid radv_describe_barrier_end_delayed(struct radv_cmd_buffer *cmd_buffer);
3028bf215546Sopenharmony_civoid radv_describe_layout_transition(struct radv_cmd_buffer *cmd_buffer,
3029bf215546Sopenharmony_ci                                     const struct radv_barrier_data *barrier);
3030bf215546Sopenharmony_ci
3031bf215546Sopenharmony_cistruct radv_indirect_command_layout {
3032bf215546Sopenharmony_ci   struct vk_object_base base;
3033bf215546Sopenharmony_ci
3034bf215546Sopenharmony_ci   uint32_t input_stride;
3035bf215546Sopenharmony_ci   uint32_t token_count;
3036bf215546Sopenharmony_ci
3037bf215546Sopenharmony_ci   bool indexed;
3038bf215546Sopenharmony_ci   bool binds_index_buffer;
3039bf215546Sopenharmony_ci   bool binds_state;
3040bf215546Sopenharmony_ci   uint16_t draw_params_offset;
3041bf215546Sopenharmony_ci   uint16_t index_buffer_offset;
3042bf215546Sopenharmony_ci
3043bf215546Sopenharmony_ci   uint16_t state_offset;
3044bf215546Sopenharmony_ci
3045bf215546Sopenharmony_ci   uint32_t bind_vbo_mask;
3046bf215546Sopenharmony_ci   uint32_t vbo_offsets[MAX_VBS];
3047bf215546Sopenharmony_ci
3048bf215546Sopenharmony_ci   uint64_t push_constant_mask;
3049bf215546Sopenharmony_ci   uint32_t push_constant_offsets[MAX_PUSH_CONSTANTS_SIZE / 4];
3050bf215546Sopenharmony_ci
3051bf215546Sopenharmony_ci   uint32_t ibo_type_32;
3052bf215546Sopenharmony_ci   uint32_t ibo_type_8;
3053bf215546Sopenharmony_ci
3054bf215546Sopenharmony_ci   VkIndirectCommandsLayoutTokenNV tokens[0];
3055bf215546Sopenharmony_ci};
3056bf215546Sopenharmony_ci
3057bf215546Sopenharmony_ciuint32_t radv_get_indirect_cmdbuf_size(const VkGeneratedCommandsInfoNV *cmd_info);
3058bf215546Sopenharmony_ci
3059bf215546Sopenharmony_civoid radv_prepare_dgc(struct radv_cmd_buffer *cmd_buffer,
3060bf215546Sopenharmony_ci                      const VkGeneratedCommandsInfoNV *pGeneratedCommandsInfo);
3061bf215546Sopenharmony_ci
3062bf215546Sopenharmony_ciuint64_t radv_get_current_time(void);
3063bf215546Sopenharmony_ci
3064bf215546Sopenharmony_cistatic inline uint32_t
3065bf215546Sopenharmony_cisi_conv_gl_prim_to_vertices(enum shader_prim gl_prim)
3066bf215546Sopenharmony_ci{
3067bf215546Sopenharmony_ci   switch (gl_prim) {
3068bf215546Sopenharmony_ci   case SHADER_PRIM_POINTS:
3069bf215546Sopenharmony_ci      return 1;
3070bf215546Sopenharmony_ci   case SHADER_PRIM_LINES:
3071bf215546Sopenharmony_ci   case SHADER_PRIM_LINE_STRIP:
3072bf215546Sopenharmony_ci      return 2;
3073bf215546Sopenharmony_ci   case SHADER_PRIM_TRIANGLES:
3074bf215546Sopenharmony_ci   case SHADER_PRIM_TRIANGLE_STRIP:
3075bf215546Sopenharmony_ci      return 3;
3076bf215546Sopenharmony_ci   case SHADER_PRIM_LINES_ADJACENCY:
3077bf215546Sopenharmony_ci      return 4;
3078bf215546Sopenharmony_ci   case SHADER_PRIM_TRIANGLES_ADJACENCY:
3079bf215546Sopenharmony_ci      return 6;
3080bf215546Sopenharmony_ci   case SHADER_PRIM_QUADS:
3081bf215546Sopenharmony_ci      return V_028A6C_TRISTRIP;
3082bf215546Sopenharmony_ci   default:
3083bf215546Sopenharmony_ci      assert(0);
3084bf215546Sopenharmony_ci      return 0;
3085bf215546Sopenharmony_ci   }
3086bf215546Sopenharmony_ci}
3087bf215546Sopenharmony_ci
3088bf215546Sopenharmony_cistatic inline uint32_t
3089bf215546Sopenharmony_cisi_conv_prim_to_gs_out(uint32_t topology)
3090bf215546Sopenharmony_ci{
3091bf215546Sopenharmony_ci   switch (topology) {
3092bf215546Sopenharmony_ci   case V_008958_DI_PT_POINTLIST:
3093bf215546Sopenharmony_ci   case V_008958_DI_PT_PATCH:
3094bf215546Sopenharmony_ci      return V_028A6C_POINTLIST;
3095bf215546Sopenharmony_ci   case V_008958_DI_PT_LINELIST:
3096bf215546Sopenharmony_ci   case V_008958_DI_PT_LINESTRIP:
3097bf215546Sopenharmony_ci   case V_008958_DI_PT_LINELIST_ADJ:
3098bf215546Sopenharmony_ci   case V_008958_DI_PT_LINESTRIP_ADJ:
3099bf215546Sopenharmony_ci      return V_028A6C_LINESTRIP;
3100bf215546Sopenharmony_ci   case V_008958_DI_PT_TRILIST:
3101bf215546Sopenharmony_ci   case V_008958_DI_PT_TRISTRIP:
3102bf215546Sopenharmony_ci   case V_008958_DI_PT_TRIFAN:
3103bf215546Sopenharmony_ci   case V_008958_DI_PT_TRILIST_ADJ:
3104bf215546Sopenharmony_ci   case V_008958_DI_PT_TRISTRIP_ADJ:
3105bf215546Sopenharmony_ci      return V_028A6C_TRISTRIP;
3106bf215546Sopenharmony_ci   default:
3107bf215546Sopenharmony_ci      assert(0);
3108bf215546Sopenharmony_ci      return 0;
3109bf215546Sopenharmony_ci   }
3110bf215546Sopenharmony_ci}
3111bf215546Sopenharmony_ci
3112bf215546Sopenharmony_cistatic inline uint32_t
3113bf215546Sopenharmony_cisi_translate_prim(unsigned topology)
3114bf215546Sopenharmony_ci{
3115bf215546Sopenharmony_ci   switch (topology) {
3116bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
3117bf215546Sopenharmony_ci      return V_008958_DI_PT_POINTLIST;
3118bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
3119bf215546Sopenharmony_ci      return V_008958_DI_PT_LINELIST;
3120bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
3121bf215546Sopenharmony_ci      return V_008958_DI_PT_LINESTRIP;
3122bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
3123bf215546Sopenharmony_ci      return V_008958_DI_PT_TRILIST;
3124bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
3125bf215546Sopenharmony_ci      return V_008958_DI_PT_TRISTRIP;
3126bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
3127bf215546Sopenharmony_ci      return V_008958_DI_PT_TRIFAN;
3128bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
3129bf215546Sopenharmony_ci      return V_008958_DI_PT_LINELIST_ADJ;
3130bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
3131bf215546Sopenharmony_ci      return V_008958_DI_PT_LINESTRIP_ADJ;
3132bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
3133bf215546Sopenharmony_ci      return V_008958_DI_PT_TRILIST_ADJ;
3134bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
3135bf215546Sopenharmony_ci      return V_008958_DI_PT_TRISTRIP_ADJ;
3136bf215546Sopenharmony_ci   case VK_PRIMITIVE_TOPOLOGY_PATCH_LIST:
3137bf215546Sopenharmony_ci      return V_008958_DI_PT_PATCH;
3138bf215546Sopenharmony_ci   default:
3139bf215546Sopenharmony_ci      unreachable("unhandled primitive type");
3140bf215546Sopenharmony_ci   }
3141bf215546Sopenharmony_ci}
3142bf215546Sopenharmony_ci
3143bf215546Sopenharmony_cistatic inline bool
3144bf215546Sopenharmony_ciradv_prim_is_points_or_lines(unsigned topology)
3145bf215546Sopenharmony_ci{
3146bf215546Sopenharmony_ci   switch (topology) {
3147bf215546Sopenharmony_ci   case V_008958_DI_PT_POINTLIST:
3148bf215546Sopenharmony_ci   case V_008958_DI_PT_LINELIST:
3149bf215546Sopenharmony_ci   case V_008958_DI_PT_LINESTRIP:
3150bf215546Sopenharmony_ci   case V_008958_DI_PT_LINELIST_ADJ:
3151bf215546Sopenharmony_ci   case V_008958_DI_PT_LINESTRIP_ADJ:
3152bf215546Sopenharmony_ci      return true;
3153bf215546Sopenharmony_ci   default:
3154bf215546Sopenharmony_ci      return false;
3155bf215546Sopenharmony_ci   }
3156bf215546Sopenharmony_ci}
3157bf215546Sopenharmony_ci
3158bf215546Sopenharmony_cistatic inline bool
3159bf215546Sopenharmony_ciradv_rast_prim_is_point(unsigned rast_prim)
3160bf215546Sopenharmony_ci{
3161bf215546Sopenharmony_ci   return rast_prim == V_028A6C_POINTLIST;
3162bf215546Sopenharmony_ci}
3163bf215546Sopenharmony_ci
3164bf215546Sopenharmony_cistatic inline bool
3165bf215546Sopenharmony_ciradv_rast_prim_is_line(unsigned rast_prim)
3166bf215546Sopenharmony_ci{
3167bf215546Sopenharmony_ci   return rast_prim == V_028A6C_LINESTRIP;
3168bf215546Sopenharmony_ci}
3169bf215546Sopenharmony_ci
3170bf215546Sopenharmony_cistatic inline bool
3171bf215546Sopenharmony_ciradv_rast_prim_is_points_or_lines(unsigned rast_prim)
3172bf215546Sopenharmony_ci{
3173bf215546Sopenharmony_ci   return radv_rast_prim_is_point(rast_prim) || radv_rast_prim_is_line(rast_prim);
3174bf215546Sopenharmony_ci}
3175bf215546Sopenharmony_ci
3176bf215546Sopenharmony_cistatic inline uint32_t
3177bf215546Sopenharmony_cisi_translate_stencil_op(enum VkStencilOp op)
3178bf215546Sopenharmony_ci{
3179bf215546Sopenharmony_ci   switch (op) {
3180bf215546Sopenharmony_ci   case VK_STENCIL_OP_KEEP:
3181bf215546Sopenharmony_ci      return V_02842C_STENCIL_KEEP;
3182bf215546Sopenharmony_ci   case VK_STENCIL_OP_ZERO:
3183bf215546Sopenharmony_ci      return V_02842C_STENCIL_ZERO;
3184bf215546Sopenharmony_ci   case VK_STENCIL_OP_REPLACE:
3185bf215546Sopenharmony_ci      return V_02842C_STENCIL_REPLACE_TEST;
3186bf215546Sopenharmony_ci   case VK_STENCIL_OP_INCREMENT_AND_CLAMP:
3187bf215546Sopenharmony_ci      return V_02842C_STENCIL_ADD_CLAMP;
3188bf215546Sopenharmony_ci   case VK_STENCIL_OP_DECREMENT_AND_CLAMP:
3189bf215546Sopenharmony_ci      return V_02842C_STENCIL_SUB_CLAMP;
3190bf215546Sopenharmony_ci   case VK_STENCIL_OP_INVERT:
3191bf215546Sopenharmony_ci      return V_02842C_STENCIL_INVERT;
3192bf215546Sopenharmony_ci   case VK_STENCIL_OP_INCREMENT_AND_WRAP:
3193bf215546Sopenharmony_ci      return V_02842C_STENCIL_ADD_WRAP;
3194bf215546Sopenharmony_ci   case VK_STENCIL_OP_DECREMENT_AND_WRAP:
3195bf215546Sopenharmony_ci      return V_02842C_STENCIL_SUB_WRAP;
3196bf215546Sopenharmony_ci   default:
3197bf215546Sopenharmony_ci      return 0;
3198bf215546Sopenharmony_ci   }
3199bf215546Sopenharmony_ci}
3200bf215546Sopenharmony_ci
3201bf215546Sopenharmony_cistatic inline uint32_t
3202bf215546Sopenharmony_cisi_translate_blend_logic_op(VkLogicOp op)
3203bf215546Sopenharmony_ci{
3204bf215546Sopenharmony_ci   switch (op) {
3205bf215546Sopenharmony_ci   case VK_LOGIC_OP_CLEAR:
3206bf215546Sopenharmony_ci      return V_028808_ROP3_CLEAR;
3207bf215546Sopenharmony_ci   case VK_LOGIC_OP_AND:
3208bf215546Sopenharmony_ci      return V_028808_ROP3_AND;
3209bf215546Sopenharmony_ci   case VK_LOGIC_OP_AND_REVERSE:
3210bf215546Sopenharmony_ci      return V_028808_ROP3_AND_REVERSE;
3211bf215546Sopenharmony_ci   case VK_LOGIC_OP_COPY:
3212bf215546Sopenharmony_ci      return V_028808_ROP3_COPY;
3213bf215546Sopenharmony_ci   case VK_LOGIC_OP_AND_INVERTED:
3214bf215546Sopenharmony_ci      return V_028808_ROP3_AND_INVERTED;
3215bf215546Sopenharmony_ci   case VK_LOGIC_OP_NO_OP:
3216bf215546Sopenharmony_ci      return V_028808_ROP3_NO_OP;
3217bf215546Sopenharmony_ci   case VK_LOGIC_OP_XOR:
3218bf215546Sopenharmony_ci      return V_028808_ROP3_XOR;
3219bf215546Sopenharmony_ci   case VK_LOGIC_OP_OR:
3220bf215546Sopenharmony_ci      return V_028808_ROP3_OR;
3221bf215546Sopenharmony_ci   case VK_LOGIC_OP_NOR:
3222bf215546Sopenharmony_ci      return V_028808_ROP3_NOR;
3223bf215546Sopenharmony_ci   case VK_LOGIC_OP_EQUIVALENT:
3224bf215546Sopenharmony_ci      return V_028808_ROP3_EQUIVALENT;
3225bf215546Sopenharmony_ci   case VK_LOGIC_OP_INVERT:
3226bf215546Sopenharmony_ci      return V_028808_ROP3_INVERT;
3227bf215546Sopenharmony_ci   case VK_LOGIC_OP_OR_REVERSE:
3228bf215546Sopenharmony_ci      return V_028808_ROP3_OR_REVERSE;
3229bf215546Sopenharmony_ci   case VK_LOGIC_OP_COPY_INVERTED:
3230bf215546Sopenharmony_ci      return V_028808_ROP3_COPY_INVERTED;
3231bf215546Sopenharmony_ci   case VK_LOGIC_OP_OR_INVERTED:
3232bf215546Sopenharmony_ci      return V_028808_ROP3_OR_INVERTED;
3233bf215546Sopenharmony_ci   case VK_LOGIC_OP_NAND:
3234bf215546Sopenharmony_ci      return V_028808_ROP3_NAND;
3235bf215546Sopenharmony_ci   case VK_LOGIC_OP_SET:
3236bf215546Sopenharmony_ci      return V_028808_ROP3_SET;
3237bf215546Sopenharmony_ci   default:
3238bf215546Sopenharmony_ci      unreachable("Unhandled logic op");
3239bf215546Sopenharmony_ci   }
3240bf215546Sopenharmony_ci}
3241bf215546Sopenharmony_ci
3242bf215546Sopenharmony_ci/*
3243bf215546Sopenharmony_ci * Queue helper to get ring.
3244bf215546Sopenharmony_ci * placed here as it needs queue + device structs.
3245bf215546Sopenharmony_ci */
3246bf215546Sopenharmony_cistatic inline enum amd_ip_type
3247bf215546Sopenharmony_ciradv_queue_ring(struct radv_queue *queue)
3248bf215546Sopenharmony_ci{
3249bf215546Sopenharmony_ci   return radv_queue_family_to_ring(queue->device->physical_device, queue->state.qf);
3250bf215546Sopenharmony_ci}
3251bf215546Sopenharmony_ci
3252bf215546Sopenharmony_ci/**
3253bf215546Sopenharmony_ci * Helper used for debugging compiler issues by enabling/disabling LLVM for a
3254bf215546Sopenharmony_ci * specific shader stage (developers only).
3255bf215546Sopenharmony_ci */
3256bf215546Sopenharmony_cistatic inline bool
3257bf215546Sopenharmony_ciradv_use_llvm_for_stage(struct radv_device *device, UNUSED gl_shader_stage stage)
3258bf215546Sopenharmony_ci{
3259bf215546Sopenharmony_ci   return device->physical_device->use_llvm;
3260bf215546Sopenharmony_ci}
3261bf215546Sopenharmony_ci
3262bf215546Sopenharmony_cistatic inline bool
3263bf215546Sopenharmony_ciradv_has_shader_buffer_float_minmax(const struct radv_physical_device *pdevice)
3264bf215546Sopenharmony_ci{
3265bf215546Sopenharmony_ci   return (pdevice->rad_info.gfx_level <= GFX7 && !pdevice->use_llvm) ||
3266bf215546Sopenharmony_ci          pdevice->rad_info.gfx_level >= GFX10;
3267bf215546Sopenharmony_ci}
3268bf215546Sopenharmony_ci
3269bf215546Sopenharmony_cistruct radv_acceleration_structure {
3270bf215546Sopenharmony_ci   struct vk_object_base base;
3271bf215546Sopenharmony_ci
3272bf215546Sopenharmony_ci   struct radeon_winsys_bo *bo;
3273bf215546Sopenharmony_ci   uint64_t mem_offset;
3274bf215546Sopenharmony_ci   uint64_t size;
3275bf215546Sopenharmony_ci};
3276bf215546Sopenharmony_ci
3277bf215546Sopenharmony_cistatic inline uint64_t
3278bf215546Sopenharmony_ciradv_accel_struct_get_va(const struct radv_acceleration_structure *accel)
3279bf215546Sopenharmony_ci{
3280bf215546Sopenharmony_ci   return radv_buffer_get_va(accel->bo) + accel->mem_offset;
3281bf215546Sopenharmony_ci}
3282bf215546Sopenharmony_ci
3283bf215546Sopenharmony_ci/* radv_perfcounter.c */
3284bf215546Sopenharmony_civoid radv_perfcounter_emit_shaders(struct radeon_cmdbuf *cs, unsigned shaders);
3285bf215546Sopenharmony_civoid radv_perfcounter_emit_spm_reset(struct radeon_cmdbuf *cs);
3286bf215546Sopenharmony_civoid radv_perfcounter_emit_spm_start(struct radv_device *device, struct radeon_cmdbuf *cs,
3287bf215546Sopenharmony_ci                                     int family);
3288bf215546Sopenharmony_civoid radv_perfcounter_emit_spm_stop(struct radv_device *device, struct radeon_cmdbuf *cs,
3289bf215546Sopenharmony_ci                                    int family);
3290bf215546Sopenharmony_ci
3291bf215546Sopenharmony_ci/* radv_spm.c */
3292bf215546Sopenharmony_cibool radv_spm_init(struct radv_device *device);
3293bf215546Sopenharmony_civoid radv_spm_finish(struct radv_device *device);
3294bf215546Sopenharmony_civoid radv_emit_spm_setup(struct radv_device *device, struct radeon_cmdbuf *cs);
3295bf215546Sopenharmony_ci
3296bf215546Sopenharmony_ci#define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
3297bf215546Sopenharmony_ci   VK_FROM_HANDLE(__radv_type, __name, __handle)
3298bf215546Sopenharmony_ci
3299bf215546Sopenharmony_ciVK_DEFINE_HANDLE_CASTS(radv_cmd_buffer, vk.base, VkCommandBuffer,
3300bf215546Sopenharmony_ci                       VK_OBJECT_TYPE_COMMAND_BUFFER)
3301bf215546Sopenharmony_ciVK_DEFINE_HANDLE_CASTS(radv_device, vk.base, VkDevice, VK_OBJECT_TYPE_DEVICE)
3302bf215546Sopenharmony_ciVK_DEFINE_HANDLE_CASTS(radv_instance, vk.base, VkInstance, VK_OBJECT_TYPE_INSTANCE)
3303bf215546Sopenharmony_ciVK_DEFINE_HANDLE_CASTS(radv_physical_device, vk.base, VkPhysicalDevice,
3304bf215546Sopenharmony_ci                       VK_OBJECT_TYPE_PHYSICAL_DEVICE)
3305bf215546Sopenharmony_ciVK_DEFINE_HANDLE_CASTS(radv_queue, vk.base, VkQueue, VK_OBJECT_TYPE_QUEUE)
3306bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_acceleration_structure, base,
3307bf215546Sopenharmony_ci                               VkAccelerationStructureKHR,
3308bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_ACCELERATION_STRUCTURE_KHR)
3309bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, vk.base, VkCommandPool,
3310bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_COMMAND_POOL)
3311bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, vk.base, VkBuffer, VK_OBJECT_TYPE_BUFFER)
3312bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, base, VkBufferView,
3313bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_BUFFER_VIEW)
3314bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, base, VkDescriptorPool,
3315bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_POOL)
3316bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, header.base, VkDescriptorSet,
3317bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_SET)
3318bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, vk.base, VkDescriptorSetLayout,
3319bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
3320bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, base,
3321bf215546Sopenharmony_ci                               VkDescriptorUpdateTemplate,
3322bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
3323bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, base, VkDeviceMemory,
3324bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_DEVICE_MEMORY)
3325bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)
3326bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_image, vk.base, VkImage, VK_OBJECT_TYPE_IMAGE)
3327bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, vk.base, VkImageView,
3328bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_IMAGE_VIEW);
3329bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_indirect_command_layout, base, VkIndirectCommandsLayoutNV,
3330bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_INDIRECT_COMMANDS_LAYOUT_NV)
3331bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, base, VkPipelineCache,
3332bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_PIPELINE_CACHE)
3333bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, base, VkPipeline,
3334bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_PIPELINE)
3335bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, base, VkPipelineLayout,
3336bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_PIPELINE_LAYOUT)
3337bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, base, VkQueryPool,
3338bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_QUERY_POOL)
3339bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, base, VkRenderPass,
3340bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_RENDER_PASS)
3341bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, base, VkSampler,
3342bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_SAMPLER)
3343bf215546Sopenharmony_ciVK_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler_ycbcr_conversion, base,
3344bf215546Sopenharmony_ci                               VkSamplerYcbcrConversion,
3345bf215546Sopenharmony_ci                               VK_OBJECT_TYPE_SAMPLER_YCBCR_CONVERSION)
3346bf215546Sopenharmony_ci
3347bf215546Sopenharmony_ci#ifdef __cplusplus
3348bf215546Sopenharmony_ci}
3349bf215546Sopenharmony_ci#endif
3350bf215546Sopenharmony_ci
3351bf215546Sopenharmony_ci#endif /* RADV_PRIVATE_H */
3352