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