blob: cf5c8532789924fd5983e6ab664770f80ff6f1e0 [file] [log] [blame]
Dave Airlief4e499e2016-10-07 09:16:09 +10001/*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 */
27
Edward O'Callaghanba437682016-10-07 22:19:19 +110028#ifndef RADV_PRIVATE_H
29#define RADV_PRIVATE_H
Dave Airlief4e499e2016-10-07 09:16:09 +100030
31#include <stdlib.h>
32#include <stdio.h>
33#include <stdbool.h>
34#include <pthread.h>
35#include <assert.h>
36#include <stdint.h>
37#include <string.h>
38#ifdef HAVE_VALGRIND
39#include <valgrind.h>
40#include <memcheck.h>
41#define VG(x) x
Dave Airlief4e499e2016-10-07 09:16:09 +100042#else
43#define VG(x)
44#endif
45
46#include <amdgpu.h>
Dave Airlief4e499e2016-10-07 09:16:09 +100047#include "compiler/shader_enums.h"
48#include "util/macros.h"
49#include "util/list.h"
50#include "main/macros.h"
Alex Smith621b3412017-06-06 12:31:05 +010051#include "vk_alloc.h"
Dave Airlie4450f402016-10-14 13:36:45 +100052
Dave Airlief4e499e2016-10-07 09:16:09 +100053#include "radv_radeon_winsys.h"
54#include "ac_binary.h"
55#include "ac_nir_to_llvm.h"
Nicolai Hähnlebd4493b2017-05-12 01:11:27 +020056#include "ac_gpu_info.h"
Nicolai Hähnledfc06d22017-05-10 23:01:00 +020057#include "ac_surface.h"
Bas Nieuwenhuizenfb7e4e12017-03-05 20:58:31 +010058#include "radv_debug.h"
Dave Airlief4e499e2016-10-07 09:16:09 +100059#include "radv_descriptor_set.h"
60
61#include <llvm-c/TargetMachine.h>
62
63/* Pre-declarations needed for WSI entrypoints */
64struct wl_surface;
65struct wl_display;
66typedef struct xcb_connection_t xcb_connection_t;
67typedef uint32_t xcb_visualid_t;
68typedef uint32_t xcb_window_t;
69
70#include <vulkan/vulkan.h>
71#include <vulkan/vulkan_intel.h>
72#include <vulkan/vk_icd.h>
73
74#include "radv_entrypoints.h"
75
Dave Airlie6c3bd1c2016-10-14 07:49:34 +010076#include "wsi_common.h"
Dave Airlief4e499e2016-10-07 09:16:09 +100077
78#define MAX_VBS 32
79#define MAX_VERTEX_ATTRIBS 32
80#define MAX_RTS 8
81#define MAX_VIEWPORTS 16
82#define MAX_SCISSORS 16
83#define MAX_PUSH_CONSTANTS_SIZE 128
Fredrik Höglundc6487bc2017-03-29 18:12:44 +020084#define MAX_PUSH_DESCRIPTORS 32
Dave Airlief4e499e2016-10-07 09:16:09 +100085#define MAX_DYNAMIC_BUFFERS 16
Grazvydas Ignotascb89d192017-01-11 03:31:24 +020086#define MAX_SAMPLES_LOG2 4
Dave Airliedf61a052017-07-27 21:52:20 +010087#define NUM_META_FS_KEYS 13
Bas Nieuwenhuizen5ae4de12017-01-16 21:25:10 +010088#define RADV_MAX_DRM_DEVICES 8
Bas Nieuwenhuizene3265c12017-08-16 09:20:26 +020089#define MAX_VIEWS 8
Dave Airlief4e499e2016-10-07 09:16:09 +100090
91#define NUM_DEPTH_CLEAR_PIPELINES 3
92
Bas Nieuwenhuizen4ae84ef2016-12-08 22:28:21 +010093enum radv_mem_heap {
94 RADV_MEM_HEAP_VRAM,
95 RADV_MEM_HEAP_VRAM_CPU_ACCESS,
96 RADV_MEM_HEAP_GTT,
97 RADV_MEM_HEAP_COUNT
98};
99
Bas Nieuwenhuizen53e1c972016-12-08 23:06:44 +0100100enum radv_mem_type {
101 RADV_MEM_TYPE_VRAM,
102 RADV_MEM_TYPE_GTT_WRITE_COMBINE,
103 RADV_MEM_TYPE_VRAM_CPU_ACCESS,
104 RADV_MEM_TYPE_GTT_CACHED,
105 RADV_MEM_TYPE_COUNT
106};
107
Dave Airlief4e499e2016-10-07 09:16:09 +1000108#define radv_printflike(a, b) __attribute__((__format__(__printf__, a, b)))
109
Dave Airlief4e499e2016-10-07 09:16:09 +1000110static inline uint32_t
111align_u32(uint32_t v, uint32_t a)
112{
113 assert(a != 0 && a == (a & -a));
114 return (v + a - 1) & ~(a - 1);
115}
116
117static inline uint32_t
118align_u32_npot(uint32_t v, uint32_t a)
119{
120 return (v + a - 1) / a * a;
121}
122
123static inline uint64_t
124align_u64(uint64_t v, uint64_t a)
125{
126 assert(a != 0 && a == (a & -a));
127 return (v + a - 1) & ~(a - 1);
128}
129
130static inline int32_t
131align_i32(int32_t v, int32_t a)
132{
133 assert(a != 0 && a == (a & -a));
134 return (v + a - 1) & ~(a - 1);
135}
136
137/** Alignment must be a power of 2. */
138static inline bool
139radv_is_aligned(uintmax_t n, uintmax_t a)
140{
141 assert(a == (a & -a));
142 return (n & (a - 1)) == 0;
143}
144
145static inline uint32_t
146round_up_u32(uint32_t v, uint32_t a)
147{
148 return (v + a - 1) / a;
149}
150
151static inline uint64_t
152round_up_u64(uint64_t v, uint64_t a)
153{
154 return (v + a - 1) / a;
155}
156
157static inline uint32_t
158radv_minify(uint32_t n, uint32_t levels)
159{
160 if (unlikely(n == 0))
161 return 0;
162 else
Dave Airliec6f10772016-10-14 13:11:20 +1000163 return MAX2(n >> levels, 1);
Dave Airlief4e499e2016-10-07 09:16:09 +1000164}
165static inline float
166radv_clamp_f(float f, float min, float max)
167{
168 assert(min < max);
169
170 if (f > max)
171 return max;
172 else if (f < min)
173 return min;
174 else
175 return f;
176}
177
178static inline bool
179radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask)
180{
181 if (*inout_mask & clear_mask) {
182 *inout_mask &= ~clear_mask;
183 return true;
184 } else {
185 return false;
186 }
187}
188
189#define for_each_bit(b, dword) \
190 for (uint32_t __dword = (dword); \
191 (b) = __builtin_ffs(__dword) - 1, __dword; \
192 __dword &= ~(1 << (b)))
193
194#define typed_memcpy(dest, src, count) ({ \
Edward O'Callaghana77426f2016-12-07 10:30:48 +1100195 STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \
Dave Airlief4e499e2016-10-07 09:16:09 +1000196 memcpy((dest), (src), (count) * sizeof(*(src))); \
197 })
198
199#define zero(x) (memset(&(x), 0, sizeof(x)))
200
Dave Airlief4e499e2016-10-07 09:16:09 +1000201/* Whenever we generate an error, pass it through this function. Useful for
202 * debugging, where we can break on it. Only call at error site, not when
203 * propagating errors. Might be useful to plug in a stack trace here.
204 */
205
206VkResult __vk_errorf(VkResult error, const char *file, int line, const char *format, ...);
207
208#ifdef DEBUG
209#define vk_error(error) __vk_errorf(error, __FILE__, __LINE__, NULL);
210#define vk_errorf(error, format, ...) __vk_errorf(error, __FILE__, __LINE__, format, ## __VA_ARGS__);
211#else
212#define vk_error(error) error
213#define vk_errorf(error, format, ...) error
214#endif
215
216void __radv_finishme(const char *file, int line, const char *format, ...)
217 radv_printflike(3, 4);
218void radv_loge(const char *format, ...) radv_printflike(1, 2);
219void radv_loge_v(const char *format, va_list va);
220
221/**
222 * Print a FINISHME message, including its source location.
223 */
224#define radv_finishme(format, ...) \
Emil Velikovf3a1c172016-11-24 18:18:14 +0000225 do { \
226 static bool reported = false; \
227 if (!reported) { \
228 __radv_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
229 reported = true; \
230 } \
231 } while (0)
Dave Airlief4e499e2016-10-07 09:16:09 +1000232
233/* A non-fatal assert. Useful for debugging. */
234#ifdef DEBUG
235#define radv_assert(x) ({ \
236 if (unlikely(!(x))) \
237 fprintf(stderr, "%s:%d ASSERT: %s\n", __FILE__, __LINE__, #x); \
238 })
239#else
240#define radv_assert(x)
241#endif
242
Dave Airlief4e499e2016-10-07 09:16:09 +1000243#define stub_return(v) \
244 do { \
245 radv_finishme("stub %s", __func__); \
246 return (v); \
247 } while (0)
248
249#define stub() \
250 do { \
251 radv_finishme("stub %s", __func__); \
252 return; \
253 } while (0)
254
Dave Airlief4e499e2016-10-07 09:16:09 +1000255void *radv_lookup_entrypoint(const char *name);
256
Andres Rodriguez1e1bddf2017-01-13 18:44:17 -0500257struct radv_extensions {
258 VkExtensionProperties *ext_array;
259 uint32_t num_ext;
260};
261
Dave Airlief4e499e2016-10-07 09:16:09 +1000262struct radv_physical_device {
263 VK_LOADER_DATA _loader_data;
264
265 struct radv_instance * instance;
266
267 struct radeon_winsys *ws;
268 struct radeon_info rad_info;
Dave Airlief4e499e2016-10-07 09:16:09 +1000269 char path[20];
270 const char * name;
Andres Rodriguez14cad872017-07-12 18:45:31 -0400271 uint8_t driver_uuid[VK_UUID_SIZE];
Bas Nieuwenhuizend515b422017-05-23 09:22:09 +0200272 uint8_t device_uuid[VK_UUID_SIZE];
Andres Rodrigueza973b9a2017-07-12 18:45:29 -0400273 uint8_t cache_uuid[VK_UUID_SIZE];
Bas Nieuwenhuizen43ee4912016-11-22 00:31:44 +0100274
Dave Airlie0a44a682017-02-19 15:27:47 +1000275 int local_fd;
Dave Airlie6c3bd1c2016-10-14 07:49:34 +0100276 struct wsi_device wsi_device;
Andres Rodriguez1e1bddf2017-01-13 18:44:17 -0500277 struct radv_extensions extensions;
Dave Airlie67655cb2017-06-06 09:03:55 +1000278
279 bool has_rbplus; /* if RB+ register exist */
280 bool rbplus_allowed; /* if RB+ is allowed */
Dave Airlief4e499e2016-10-07 09:16:09 +1000281};
282
283struct radv_instance {
284 VK_LOADER_DATA _loader_data;
285
286 VkAllocationCallbacks alloc;
287
288 uint32_t apiVersion;
289 int physicalDeviceCount;
Bas Nieuwenhuizen5ae4de12017-01-16 21:25:10 +0100290 struct radv_physical_device physicalDevices[RADV_MAX_DRM_DEVICES];
Bas Nieuwenhuizen8bc39e22017-01-02 18:57:02 +0100291
292 uint64_t debug_flags;
Dave Airliec2464272017-05-09 04:17:30 +0100293 uint64_t perftest_flags;
Dave Airlief4e499e2016-10-07 09:16:09 +1000294};
295
296VkResult radv_init_wsi(struct radv_physical_device *physical_device);
297void radv_finish_wsi(struct radv_physical_device *physical_device);
298
299struct cache_entry;
300
301struct radv_pipeline_cache {
302 struct radv_device * device;
303 pthread_mutex_t mutex;
304
305 uint32_t total_size;
306 uint32_t table_size;
307 uint32_t kernel_count;
308 struct cache_entry ** hash_table;
309 bool modified;
310
311 VkAllocationCallbacks alloc;
312};
313
314void
315radv_pipeline_cache_init(struct radv_pipeline_cache *cache,
316 struct radv_device *device);
317void
318radv_pipeline_cache_finish(struct radv_pipeline_cache *cache);
319void
320radv_pipeline_cache_load(struct radv_pipeline_cache *cache,
321 const void *data, size_t size);
322
323struct radv_shader_variant *
324radv_create_shader_variant_from_pipeline_cache(struct radv_device *device,
325 struct radv_pipeline_cache *cache,
326 const unsigned char *sha1);
327
328struct radv_shader_variant *
Dave Airlie10c2b582017-03-20 13:24:02 +1000329radv_pipeline_cache_insert_shader(struct radv_pipeline_cache *cache,
Dave Airlief4e499e2016-10-07 09:16:09 +1000330 const unsigned char *sha1,
331 struct radv_shader_variant *variant,
332 const void *code, unsigned code_size);
333
334void radv_shader_variant_destroy(struct radv_device *device,
335 struct radv_shader_variant *variant);
336
337struct radv_meta_state {
338 VkAllocationCallbacks alloc;
339
340 struct radv_pipeline_cache cache;
341
342 /**
343 * Use array element `i` for images with `2^i` samples.
344 */
345 struct {
346 VkRenderPass render_pass[NUM_META_FS_KEYS];
347 struct radv_pipeline *color_pipelines[NUM_META_FS_KEYS];
348
Dave Airlie3634dfd2017-01-17 06:37:36 +1000349 VkRenderPass depthstencil_rp;
Dave Airlief4e499e2016-10-07 09:16:09 +1000350 struct radv_pipeline *depth_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
Dave Airlief4e499e2016-10-07 09:16:09 +1000351 struct radv_pipeline *stencil_only_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
Dave Airlief4e499e2016-10-07 09:16:09 +1000352 struct radv_pipeline *depthstencil_pipeline[NUM_DEPTH_CLEAR_PIPELINES];
353 } clear[1 + MAX_SAMPLES_LOG2];
354
Dave Airlieb29ea492017-04-19 10:34:37 +1000355 VkPipelineLayout clear_color_p_layout;
356 VkPipelineLayout clear_depth_p_layout;
Dave Airlief4e499e2016-10-07 09:16:09 +1000357 struct {
358 VkRenderPass render_pass[NUM_META_FS_KEYS];
359
360 /** Pipeline that blits from a 1D image. */
361 VkPipeline pipeline_1d_src[NUM_META_FS_KEYS];
362
363 /** Pipeline that blits from a 2D image. */
364 VkPipeline pipeline_2d_src[NUM_META_FS_KEYS];
365
366 /** Pipeline that blits from a 3D image. */
367 VkPipeline pipeline_3d_src[NUM_META_FS_KEYS];
368
369 VkRenderPass depth_only_rp;
370 VkPipeline depth_only_1d_pipeline;
371 VkPipeline depth_only_2d_pipeline;
372 VkPipeline depth_only_3d_pipeline;
373
374 VkRenderPass stencil_only_rp;
375 VkPipeline stencil_only_1d_pipeline;
376 VkPipeline stencil_only_2d_pipeline;
377 VkPipeline stencil_only_3d_pipeline;
378 VkPipelineLayout pipeline_layout;
379 VkDescriptorSetLayout ds_layout;
380 } blit;
381
382 struct {
383 VkRenderPass render_passes[NUM_META_FS_KEYS];
384
385 VkPipelineLayout p_layouts[2];
386 VkDescriptorSetLayout ds_layouts[2];
387 VkPipeline pipelines[2][NUM_META_FS_KEYS];
388
389 VkRenderPass depth_only_rp;
390 VkPipeline depth_only_pipeline[2];
391
392 VkRenderPass stencil_only_rp;
393 VkPipeline stencil_only_pipeline[2];
394 } blit2d;
395
396 struct {
397 VkPipelineLayout img_p_layout;
398 VkDescriptorSetLayout img_ds_layout;
399 VkPipeline pipeline;
400 } itob;
401 struct {
402 VkRenderPass render_pass;
403 VkPipelineLayout img_p_layout;
404 VkDescriptorSetLayout img_ds_layout;
405 VkPipeline pipeline;
406 } btoi;
Dave Airlieef5f59c2016-11-30 00:26:47 +0000407 struct {
408 VkPipelineLayout img_p_layout;
409 VkDescriptorSetLayout img_ds_layout;
410 VkPipeline pipeline;
411 } itoi;
Dave Airlief11ea872016-11-30 01:45:24 +0000412 struct {
413 VkPipelineLayout img_p_layout;
414 VkDescriptorSetLayout img_ds_layout;
415 VkPipeline pipeline;
416 } cleari;
Dave Airlief4e499e2016-10-07 09:16:09 +1000417
418 struct {
419 VkPipeline pipeline;
420 VkRenderPass pass;
421 } resolve;
422
423 struct {
424 VkDescriptorSetLayout ds_layout;
425 VkPipelineLayout p_layout;
426 struct {
427 VkPipeline pipeline;
428 VkPipeline i_pipeline;
Dave Airlie588185e2017-04-20 04:42:26 +0100429 VkPipeline srgb_pipeline;
Dave Airlief4e499e2016-10-07 09:16:09 +1000430 } rc[MAX_SAMPLES_LOG2];
431 } resolve_compute;
432
433 struct {
Dave Airlie69136f42017-04-27 01:47:22 +0100434 VkDescriptorSetLayout ds_layout;
435 VkPipelineLayout p_layout;
436
437 struct {
438 VkRenderPass render_pass[NUM_META_FS_KEYS];
439 VkPipeline pipeline[NUM_META_FS_KEYS];
440 } rc[MAX_SAMPLES_LOG2];
441 } resolve_fragment;
442
443 struct {
Dave Airlief4e499e2016-10-07 09:16:09 +1000444 VkPipeline decompress_pipeline;
445 VkPipeline resummarize_pipeline;
446 VkRenderPass pass;
Alex Smith2e9a13b2017-08-03 15:32:46 +0100447 } depth_decomp[1 + MAX_SAMPLES_LOG2];
Dave Airlief4e499e2016-10-07 09:16:09 +1000448
449 struct {
450 VkPipeline cmask_eliminate_pipeline;
451 VkPipeline fmask_decompress_pipeline;
452 VkRenderPass pass;
453 } fast_clear_flush;
454
455 struct {
456 VkPipelineLayout fill_p_layout;
457 VkPipelineLayout copy_p_layout;
458 VkDescriptorSetLayout fill_ds_layout;
459 VkDescriptorSetLayout copy_ds_layout;
460 VkPipeline fill_pipeline;
461 VkPipeline copy_pipeline;
462 } buffer;
Bas Nieuwenhuizence0c8cf2017-02-26 18:21:01 +0100463
464 struct {
Bas Nieuwenhuizen84731932017-04-10 21:49:48 +0200465 VkDescriptorSetLayout ds_layout;
466 VkPipelineLayout p_layout;
Bas Nieuwenhuizence0c8cf2017-02-26 18:21:01 +0100467 VkPipeline occlusion_query_pipeline;
Bas Nieuwenhuizen8475a142017-04-10 22:20:19 +0200468 VkPipeline pipeline_statistics_query_pipeline;
Bas Nieuwenhuizence0c8cf2017-02-26 18:21:01 +0100469 } query;
Dave Airlief4e499e2016-10-07 09:16:09 +1000470};
471
Dave Airliec20701f2016-11-30 04:30:06 +0000472/* queue types */
473#define RADV_QUEUE_GENERAL 0
474#define RADV_QUEUE_COMPUTE 1
475#define RADV_QUEUE_TRANSFER 2
476
477#define RADV_MAX_QUEUE_FAMILIES 3
478
Dave Airlie94a74342016-12-01 00:05:29 +0000479enum ring_type radv_queue_family_to_ring(int f);
480
Dave Airlief4e499e2016-10-07 09:16:09 +1000481struct radv_queue {
482 VK_LOADER_DATA _loader_data;
Dave Airlief4e499e2016-10-07 09:16:09 +1000483 struct radv_device * device;
Andres Rodriguez0eb8b6a2017-01-13 18:44:15 -0500484 struct radeon_winsys_ctx *hw_ctx;
Dave Airliec20701f2016-11-30 04:30:06 +0000485 int queue_family_index;
486 int queue_idx;
Bas Nieuwenhuizenc4d7b9c2017-01-29 13:53:05 +0100487
488 uint32_t scratch_size;
489 uint32_t compute_scratch_size;
Dave Airlie1fa5b752017-01-20 11:06:52 +1000490 uint32_t esgs_ring_size;
491 uint32_t gsvs_ring_size;
Dave Airlie46e52df2017-03-30 08:02:14 +0100492 bool has_tess_rings;
Dave Airlie1171b302017-04-03 04:38:12 +0100493 bool has_sample_positions;
Bas Nieuwenhuizenc4d7b9c2017-01-29 13:53:05 +0100494
495 struct radeon_winsys_bo *scratch_bo;
496 struct radeon_winsys_bo *descriptor_bo;
497 struct radeon_winsys_bo *compute_scratch_bo;
Dave Airlie1fa5b752017-01-20 11:06:52 +1000498 struct radeon_winsys_bo *esgs_ring_bo;
499 struct radeon_winsys_bo *gsvs_ring_bo;
Dave Airlie46e52df2017-03-30 08:02:14 +0100500 struct radeon_winsys_bo *tess_factor_ring_bo;
501 struct radeon_winsys_bo *tess_offchip_ring_bo;
Bas Nieuwenhuizen5241fb02017-02-20 09:26:00 +0100502 struct radeon_winsys_cs *initial_preamble_cs;
503 struct radeon_winsys_cs *continue_preamble_cs;
Dave Airlief4e499e2016-10-07 09:16:09 +1000504};
505
506struct radv_device {
507 VK_LOADER_DATA _loader_data;
508
509 VkAllocationCallbacks alloc;
510
511 struct radv_instance * instance;
512 struct radeon_winsys *ws;
Dave Airlief4e499e2016-10-07 09:16:09 +1000513
514 struct radv_meta_state meta_state;
Dave Airliec20701f2016-11-30 04:30:06 +0000515
516 struct radv_queue *queues[RADV_MAX_QUEUE_FAMILIES];
517 int queue_count[RADV_MAX_QUEUE_FAMILIES];
Bas Nieuwenhuizenf2523eb2016-12-17 21:53:38 +0100518 struct radeon_winsys_cs *empty_cs[RADV_MAX_QUEUE_FAMILIES];
Bas Nieuwenhuizen5241fb02017-02-20 09:26:00 +0100519 struct radeon_winsys_cs *flush_cs[RADV_MAX_QUEUE_FAMILIES];
Dave Airliea5247042017-05-03 07:13:21 +1000520 struct radeon_winsys_cs *flush_shader_cs[RADV_MAX_QUEUE_FAMILIES];
Bas Nieuwenhuizen8bc39e22017-01-02 18:57:02 +0100521 uint64_t debug_flags;
Dave Airlief4e499e2016-10-07 09:16:09 +1000522
Bas Nieuwenhuizenccff93e2017-01-29 15:20:03 +0100523 bool llvm_supports_spill;
Dave Airliebbfb62d2017-03-30 07:58:22 +0100524 bool has_distributed_tess;
525 uint32_t tess_offchip_block_dw_size;
Bas Nieuwenhuizenccff93e2017-01-29 15:20:03 +0100526 uint32_t scratch_waves;
Dave Airlie68c5da72017-01-18 13:54:17 +1000527
528 uint32_t gs_table_depth;
529
Dave Airlief4e499e2016-10-07 09:16:09 +1000530 /* MSAA sample locations.
531 * The first index is the sample index.
532 * The second index is the coordinate: X, Y. */
533 float sample_locations_1x[1][2];
534 float sample_locations_2x[2][2];
535 float sample_locations_4x[4][2];
536 float sample_locations_8x[8][2];
537 float sample_locations_16x[16][2];
Bas Nieuwenhuizen97dfff52016-12-23 23:51:18 +0100538
Dave Airlie592069c2017-02-13 04:00:24 +0000539 /* CIK and later */
540 uint32_t gfx_init_size_dw;
541 struct radeon_winsys_bo *gfx_init;
542
Bas Nieuwenhuizen97dfff52016-12-23 23:51:18 +0100543 struct radeon_winsys_bo *trace_bo;
544 uint32_t *trace_id_ptr;
Bas Nieuwenhuizen8406f792017-01-16 21:23:48 +0100545
546 struct radv_physical_device *physical_device;
Timothy Arceri315e8a92017-03-15 14:14:24 +1100547
548 /* Backup in-memory cache to be used if the app doesn't provide one */
549 struct radv_pipeline_cache * mem_cache;
Dave Airlief8d5b372017-07-07 06:56:57 +0100550
Dave Airlie1e696b92017-08-04 06:54:15 +0100551 /*
552 * use different counters so MSAA MRTs get consecutive surface indices,
553 * even if MASK is allocated in between.
554 */
Dave Airlief8d5b372017-07-07 06:56:57 +0100555 uint32_t image_mrt_offset_counter;
Dave Airlie1e696b92017-08-04 06:54:15 +0100556 uint32_t fmask_mrt_offset_counter;
Bas Nieuwenhuizenc9d4b572017-03-12 22:43:51 +0100557 struct list_head shader_slabs;
558 mtx_t shader_slab_mutex;
Dave Airlief4e499e2016-10-07 09:16:09 +1000559};
560
Dave Airlief4e499e2016-10-07 09:16:09 +1000561struct radv_device_memory {
562 struct radeon_winsys_bo *bo;
Dave Airlie15f47022017-02-26 23:52:08 +0000563 /* for dedicated allocations */
564 struct radv_image *image;
565 struct radv_buffer *buffer;
Dave Airlief4e499e2016-10-07 09:16:09 +1000566 uint32_t type_index;
567 VkDeviceSize map_size;
568 void * map;
569};
570
571
572struct radv_descriptor_range {
573 uint64_t va;
574 uint32_t size;
575};
576
577struct radv_descriptor_set {
578 const struct radv_descriptor_set_layout *layout;
Dave Airlief4e499e2016-10-07 09:16:09 +1000579 uint32_t size;
580
Dave Airlief4e499e2016-10-07 09:16:09 +1000581 struct radeon_winsys_bo *bo;
582 uint64_t va;
583 uint32_t *mapped_ptr;
584 struct radv_descriptor_range *dynamic_descriptors;
Bas Nieuwenhuizend5bf4c72017-02-16 21:23:58 +0100585
586 struct list_head vram_list;
587
Dave Airlief4e499e2016-10-07 09:16:09 +1000588 struct radeon_winsys_bo *descriptors[0];
589};
590
Fredrik Höglundc6487bc2017-03-29 18:12:44 +0200591struct radv_push_descriptor_set
592{
593 struct radv_descriptor_set set;
594 uint32_t capacity;
595};
596
Dave Airlief4e499e2016-10-07 09:16:09 +1000597struct radv_descriptor_pool {
Dave Airlief4e499e2016-10-07 09:16:09 +1000598 struct radeon_winsys_bo *bo;
599 uint8_t *mapped_ptr;
600 uint64_t current_offset;
601 uint64_t size;
602
Bas Nieuwenhuizend5bf4c72017-02-16 21:23:58 +0100603 struct list_head vram_list;
Bas Nieuwenhuizen126d5ad2017-04-17 02:14:06 +0200604
605 uint8_t *host_memory_base;
606 uint8_t *host_memory_ptr;
607 uint8_t *host_memory_end;
Dave Airlief4e499e2016-10-07 09:16:09 +1000608};
609
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200610struct radv_descriptor_update_template_entry {
611 VkDescriptorType descriptor_type;
612
613 /* The number of descriptors to update */
Bas Nieuwenhuizene20eb912017-04-13 23:49:00 +0200614 uint32_t descriptor_count;
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200615
616 /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
Bas Nieuwenhuizene20eb912017-04-13 23:49:00 +0200617 uint32_t dst_offset;
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200618
619 /* In dwords. Not valid/used for dynamic descriptors */
Bas Nieuwenhuizene20eb912017-04-13 23:49:00 +0200620 uint32_t dst_stride;
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200621
Bas Nieuwenhuizene20eb912017-04-13 23:49:00 +0200622 uint32_t buffer_offset;
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200623
624 /* Only valid for combined image samplers and samplers */
625 uint16_t has_sampler;
626
627 /* In bytes */
628 size_t src_offset;
629 size_t src_stride;
630
631 /* For push descriptors */
Bas Nieuwenhuizenbd91caf2017-04-12 00:37:06 +0200632 const uint32_t *immutable_samplers;
Fredrik Höglundc1f8c832017-03-29 19:19:47 +0200633};
634
635struct radv_descriptor_update_template {
636 uint32_t entry_count;
637 struct radv_descriptor_update_template_entry entry[0];
638};
639
Dave Airlief4e499e2016-10-07 09:16:09 +1000640struct radv_buffer {
641 struct radv_device * device;
642 VkDeviceSize size;
643
644 VkBufferUsageFlags usage;
Bas Nieuwenhuizenef0e5052017-02-04 11:15:59 +0100645 VkBufferCreateFlags flags;
Dave Airlief4e499e2016-10-07 09:16:09 +1000646
647 /* Set when bound */
648 struct radeon_winsys_bo * bo;
649 VkDeviceSize offset;
650};
651
652
653enum radv_cmd_dirty_bits {
654 RADV_CMD_DIRTY_DYNAMIC_VIEWPORT = 1 << 0, /* VK_DYNAMIC_STATE_VIEWPORT */
655 RADV_CMD_DIRTY_DYNAMIC_SCISSOR = 1 << 1, /* VK_DYNAMIC_STATE_SCISSOR */
656 RADV_CMD_DIRTY_DYNAMIC_LINE_WIDTH = 1 << 2, /* VK_DYNAMIC_STATE_LINE_WIDTH */
657 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BIAS = 1 << 3, /* VK_DYNAMIC_STATE_DEPTH_BIAS */
658 RADV_CMD_DIRTY_DYNAMIC_BLEND_CONSTANTS = 1 << 4, /* VK_DYNAMIC_STATE_BLEND_CONSTANTS */
659 RADV_CMD_DIRTY_DYNAMIC_DEPTH_BOUNDS = 1 << 5, /* VK_DYNAMIC_STATE_DEPTH_BOUNDS */
660 RADV_CMD_DIRTY_DYNAMIC_STENCIL_COMPARE_MASK = 1 << 6, /* VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK */
661 RADV_CMD_DIRTY_DYNAMIC_STENCIL_WRITE_MASK = 1 << 7, /* VK_DYNAMIC_STATE_STENCIL_WRITE_MASK */
662 RADV_CMD_DIRTY_DYNAMIC_STENCIL_REFERENCE = 1 << 8, /* VK_DYNAMIC_STATE_STENCIL_REFERENCE */
663 RADV_CMD_DIRTY_DYNAMIC_ALL = (1 << 9) - 1,
664 RADV_CMD_DIRTY_PIPELINE = 1 << 9,
665 RADV_CMD_DIRTY_INDEX_BUFFER = 1 << 10,
666 RADV_CMD_DIRTY_RENDER_TARGETS = 1 << 11,
667};
668typedef uint32_t radv_cmd_dirty_mask_t;
669
670enum radv_cmd_flush_bits {
671 RADV_CMD_FLAG_INV_ICACHE = 1 << 0,
672 /* SMEM L1, other names: KCACHE, constant cache, DCACHE, data cache */
673 RADV_CMD_FLAG_INV_SMEM_L1 = 1 << 1,
674 /* VMEM L1 can optionally be bypassed (GLC=1). Other names: TC L1 */
675 RADV_CMD_FLAG_INV_VMEM_L1 = 1 << 2,
676 /* Used by everything except CB/DB, can be bypassed (SLC=1). Other names: TC L2 */
677 RADV_CMD_FLAG_INV_GLOBAL_L2 = 1 << 3,
Bas Nieuwenhuizen66e12d42017-03-06 01:28:53 +0100678 /* Same as above, but only writes back and doesn't invalidate */
679 RADV_CMD_FLAG_WRITEBACK_GLOBAL_L2 = 1 << 4,
Dave Airlief4e499e2016-10-07 09:16:09 +1000680 /* Framebuffer caches */
Bas Nieuwenhuizen66e12d42017-03-06 01:28:53 +0100681 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META = 1 << 5,
682 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META = 1 << 6,
683 RADV_CMD_FLAG_FLUSH_AND_INV_DB = 1 << 7,
684 RADV_CMD_FLAG_FLUSH_AND_INV_CB = 1 << 8,
Dave Airlief4e499e2016-10-07 09:16:09 +1000685 /* Engine synchronization. */
Bas Nieuwenhuizen66e12d42017-03-06 01:28:53 +0100686 RADV_CMD_FLAG_VS_PARTIAL_FLUSH = 1 << 9,
687 RADV_CMD_FLAG_PS_PARTIAL_FLUSH = 1 << 10,
688 RADV_CMD_FLAG_CS_PARTIAL_FLUSH = 1 << 11,
689 RADV_CMD_FLAG_VGT_FLUSH = 1 << 12,
Dave Airlief4e499e2016-10-07 09:16:09 +1000690
691 RADV_CMD_FLUSH_AND_INV_FRAMEBUFFER = (RADV_CMD_FLAG_FLUSH_AND_INV_CB |
692 RADV_CMD_FLAG_FLUSH_AND_INV_CB_META |
693 RADV_CMD_FLAG_FLUSH_AND_INV_DB |
694 RADV_CMD_FLAG_FLUSH_AND_INV_DB_META)
695};
696
697struct radv_vertex_binding {
698 struct radv_buffer * buffer;
699 VkDeviceSize offset;
700};
701
702struct radv_dynamic_state {
703 struct {
704 uint32_t count;
705 VkViewport viewports[MAX_VIEWPORTS];
706 } viewport;
707
708 struct {
709 uint32_t count;
710 VkRect2D scissors[MAX_SCISSORS];
711 } scissor;
712
713 float line_width;
714
715 struct {
716 float bias;
717 float clamp;
718 float slope;
719 } depth_bias;
720
721 float blend_constants[4];
722
723 struct {
724 float min;
725 float max;
726 } depth_bounds;
727
728 struct {
729 uint32_t front;
730 uint32_t back;
731 } stencil_compare_mask;
732
733 struct {
734 uint32_t front;
735 uint32_t back;
736 } stencil_write_mask;
737
738 struct {
739 uint32_t front;
740 uint32_t back;
741 } stencil_reference;
742};
743
744extern const struct radv_dynamic_state default_dynamic_state;
745
746void radv_dynamic_state_copy(struct radv_dynamic_state *dest,
747 const struct radv_dynamic_state *src,
748 uint32_t copy_mask);
749/**
750 * Attachment state when recording a renderpass instance.
751 *
752 * The clear value is valid only if there exists a pending clear.
753 */
754struct radv_attachment_state {
755 VkImageAspectFlags pending_clear_aspects;
Bas Nieuwenhuizen2e86f6b2017-08-16 08:59:41 +0200756 uint32_t cleared_views;
Dave Airlief4e499e2016-10-07 09:16:09 +1000757 VkClearValue clear_value;
758 VkImageLayout current_layout;
759};
760
761struct radv_cmd_state {
762 uint32_t vb_dirty;
Dave Airlief4e499e2016-10-07 09:16:09 +1000763 radv_cmd_dirty_mask_t dirty;
Fredrik Höglundc6487bc2017-03-29 18:12:44 +0200764 bool push_descriptors_dirty;
Dave Airlief4e499e2016-10-07 09:16:09 +1000765
766 struct radv_pipeline * pipeline;
767 struct radv_pipeline * emitted_pipeline;
768 struct radv_pipeline * compute_pipeline;
769 struct radv_pipeline * emitted_compute_pipeline;
770 struct radv_framebuffer * framebuffer;
771 struct radv_render_pass * pass;
772 const struct radv_subpass * subpass;
773 struct radv_dynamic_state dynamic;
774 struct radv_vertex_binding vertex_bindings[MAX_VBS];
775 struct radv_descriptor_set * descriptors[MAX_SETS];
776 struct radv_attachment_state * attachments;
777 VkRect2D render_area;
Dave Airlief4e499e2016-10-07 09:16:09 +1000778 uint32_t index_type;
Dave Airlie00fe30f2017-06-07 09:14:54 +1000779 uint64_t index_va;
780 uint32_t max_index_count;
Alex Smith4603bea2017-04-12 09:20:42 +0100781 int32_t last_primitive_reset_en;
Dave Airlief4e499e2016-10-07 09:16:09 +1000782 uint32_t last_primitive_reset_index;
783 enum radv_cmd_flush_bits flush_bits;
784 unsigned active_occlusion_queries;
785 float offset_scale;
Dave Airlie85118a12016-11-28 00:42:56 +0000786 uint32_t descriptors_dirty;
Bas Nieuwenhuizen97dfff52016-12-23 23:51:18 +0100787 uint32_t trace_id;
Dave Airlie3360dbe2017-02-13 07:30:29 +0000788 uint32_t last_ia_multi_vgt_param;
Dave Airliea6c20012017-06-26 02:13:24 +0100789 bool predicating;
Dave Airlief4e499e2016-10-07 09:16:09 +1000790};
Dave Airlie94a74342016-12-01 00:05:29 +0000791
Dave Airlief4e499e2016-10-07 09:16:09 +1000792struct radv_cmd_pool {
793 VkAllocationCallbacks alloc;
794 struct list_head cmd_buffers;
Bas Nieuwenhuizen682248d2017-03-05 22:25:20 +0100795 struct list_head free_cmd_buffers;
Dave Airlie94a74342016-12-01 00:05:29 +0000796 uint32_t queue_family_index;
Dave Airlief4e499e2016-10-07 09:16:09 +1000797};
798
799struct radv_cmd_buffer_upload {
800 uint8_t *map;
801 unsigned offset;
802 uint64_t size;
803 struct radeon_winsys_bo *upload_bo;
804 struct list_head list;
805};
806
807struct radv_cmd_buffer {
808 VK_LOADER_DATA _loader_data;
809
810 struct radv_device * device;
811
812 struct radv_cmd_pool * pool;
813 struct list_head pool_link;
814
815 VkCommandBufferUsageFlags usage_flags;
816 VkCommandBufferLevel level;
817 struct radeon_winsys_cs *cs;
818 struct radv_cmd_state state;
Dave Airlie94a74342016-12-01 00:05:29 +0000819 uint32_t queue_family_index;
Dave Airlief4e499e2016-10-07 09:16:09 +1000820
821 uint8_t push_constants[MAX_PUSH_CONSTANTS_SIZE];
Fredrik Höglund71bb1a92017-03-07 01:53:21 +0100822 uint32_t dynamic_buffers[4 * MAX_DYNAMIC_BUFFERS];
Dave Airlief4e499e2016-10-07 09:16:09 +1000823 VkShaderStageFlags push_constant_stages;
Fredrik Höglundc6487bc2017-03-29 18:12:44 +0200824 struct radv_push_descriptor_set push_descriptors;
Fredrik Höglundf95caae2017-04-14 00:26:58 +0200825 struct radv_descriptor_set meta_push_descriptors;
Dave Airlief4e499e2016-10-07 09:16:09 +1000826
827 struct radv_cmd_buffer_upload upload;
828
Bas Nieuwenhuizenccff93e2017-01-29 15:20:03 +0100829 uint32_t scratch_size_needed;
830 uint32_t compute_scratch_size_needed;
Dave Airlie1fa5b752017-01-20 11:06:52 +1000831 uint32_t esgs_ring_size_needed;
832 uint32_t gsvs_ring_size_needed;
Dave Airlie46e52df2017-03-30 08:02:14 +0100833 bool tess_rings_needed;
Dave Airlie1171b302017-04-03 04:38:12 +0100834 bool sample_positions_needed;
Dave Airlie1fa5b752017-01-20 11:06:52 +1000835
Samuel Pitoiset2bc3d652017-08-25 16:10:30 +0200836 VkResult record_result;
Dave Airliece0f6922017-05-02 10:32:02 +1000837
Dave Airlie1fa5b752017-01-20 11:06:52 +1000838 int ring_offsets_idx; /* just used for verification */
Dave Airliec2fbeb72017-06-06 09:01:48 +1000839 uint32_t gfx9_fence_offset;
840 struct radeon_winsys_bo *gfx9_fence_bo;
841 uint32_t gfx9_fence_idx;
Dave Airlief4e499e2016-10-07 09:16:09 +1000842};
843
844struct radv_image;
845
Dave Airlie94a74342016-12-01 00:05:29 +0000846bool radv_cmd_buffer_uses_mec(struct radv_cmd_buffer *cmd_buffer);
847
Dave Airlie604e5622017-02-13 03:35:37 +0000848void si_init_compute(struct radv_cmd_buffer *cmd_buffer);
849void si_init_config(struct radv_cmd_buffer *cmd_buffer);
Dave Airlie592069c2017-02-13 04:00:24 +0000850
851void cik_create_gfx_config(struct radv_device *device);
852
Dave Airlief4e499e2016-10-07 09:16:09 +1000853void si_write_viewport(struct radeon_winsys_cs *cs, int first_vp,
854 int count, const VkViewport *viewports);
855void si_write_scissors(struct radeon_winsys_cs *cs, int first,
Bas Nieuwenhuizen0f3de892017-03-01 09:32:19 +0100856 int count, const VkRect2D *scissors,
857 const VkViewport *viewports, bool can_use_guardband);
Dave Airlie3360dbe2017-02-13 07:30:29 +0000858uint32_t si_get_ia_multi_vgt_param(struct radv_cmd_buffer *cmd_buffer,
Dave Airlieae0551b2017-03-28 05:53:50 +1000859 bool instanced_draw, bool indirect_draw,
860 uint32_t draw_vertex_count);
Dave Airliead61eac2017-06-01 05:24:34 +0100861void si_cs_emit_write_event_eop(struct radeon_winsys_cs *cs,
Dave Airliea6c20012017-06-26 02:13:24 +0100862 bool predicated,
Dave Airliead61eac2017-06-01 05:24:34 +0100863 enum chip_class chip_class,
864 bool is_mec,
865 unsigned event, unsigned event_flags,
866 unsigned data_sel,
867 uint64_t va,
868 uint32_t old_fence,
869 uint32_t new_fence);
870
Dave Airlie72054312017-06-01 05:12:19 +0100871void si_emit_wait_fence(struct radeon_winsys_cs *cs,
Dave Airliea6c20012017-06-26 02:13:24 +0100872 bool predicated,
Dave Airlie72054312017-06-01 05:12:19 +0100873 uint64_t va, uint32_t ref,
874 uint32_t mask);
Bas Nieuwenhuizen5241fb02017-02-20 09:26:00 +0100875void si_cs_emit_cache_flush(struct radeon_winsys_cs *cs,
Dave Airliea6c20012017-06-26 02:13:24 +0100876 bool predicated,
Dave Airliec2fbeb72017-06-06 09:01:48 +1000877 enum chip_class chip_class,
878 uint32_t *fence_ptr, uint64_t va,
879 bool is_mec,
880 enum radv_cmd_flush_bits flush_bits);
Dave Airlief4e499e2016-10-07 09:16:09 +1000881void si_emit_cache_flush(struct radv_cmd_buffer *cmd_buffer);
Dave Airlie9ee67462017-03-02 21:39:10 +0000882void si_emit_set_predication_state(struct radv_cmd_buffer *cmd_buffer, uint64_t va);
Dave Airlief4e499e2016-10-07 09:16:09 +1000883void si_cp_dma_buffer_copy(struct radv_cmd_buffer *cmd_buffer,
884 uint64_t src_va, uint64_t dest_va,
885 uint64_t size);
Bas Nieuwenhuizen1e116532017-04-19 22:32:16 +0200886void si_cp_dma_prefetch(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
887 unsigned size);
Dave Airlief4e499e2016-10-07 09:16:09 +1000888void si_cp_dma_clear_buffer(struct radv_cmd_buffer *cmd_buffer, uint64_t va,
889 uint64_t size, unsigned value);
890void radv_set_db_count_control(struct radv_cmd_buffer *cmd_buffer);
891void radv_bind_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
892 struct radv_descriptor_set *set,
893 unsigned idx);
894bool
895radv_cmd_buffer_upload_alloc(struct radv_cmd_buffer *cmd_buffer,
896 unsigned size,
897 unsigned alignment,
898 unsigned *out_offset,
899 void **ptr);
900void
901radv_cmd_buffer_set_subpass(struct radv_cmd_buffer *cmd_buffer,
902 const struct radv_subpass *subpass,
903 bool transitions);
904bool
905radv_cmd_buffer_upload_data(struct radv_cmd_buffer *cmd_buffer,
906 unsigned size, unsigned alignmnet,
907 const void *data, unsigned *out_offset);
908void
909radv_emit_framebuffer_state(struct radv_cmd_buffer *cmd_buffer);
910void radv_cmd_buffer_clear_subpass(struct radv_cmd_buffer *cmd_buffer);
911void radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer);
Dave Airlie19be95f2017-05-04 04:02:08 +0100912void radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer);
Dave Airlie69136f42017-04-27 01:47:22 +0100913void radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer);
Dave Airlief4e499e2016-10-07 09:16:09 +1000914void radv_cayman_emit_msaa_sample_locs(struct radeon_winsys_cs *cs, int nr_samples);
915unsigned radv_cayman_get_maxdist(int log_samples);
916void radv_device_init_msaa(struct radv_device *device);
917void radv_set_depth_clear_regs(struct radv_cmd_buffer *cmd_buffer,
918 struct radv_image *image,
919 VkClearDepthStencilValue ds_clear_value,
920 VkImageAspectFlags aspects);
921void radv_set_color_clear_regs(struct radv_cmd_buffer *cmd_buffer,
922 struct radv_image *image,
923 int idx,
924 uint32_t color_values[2]);
Dave Airlie9ee67462017-03-02 21:39:10 +0000925void radv_set_dcc_need_cmask_elim_pred(struct radv_cmd_buffer *cmd_buffer,
926 struct radv_image *image,
927 bool value);
Dave Airlief4e499e2016-10-07 09:16:09 +1000928void radv_fill_buffer(struct radv_cmd_buffer *cmd_buffer,
929 struct radeon_winsys_bo *bo,
930 uint64_t offset, uint64_t size, uint32_t value);
Bas Nieuwenhuizen97dfff52016-12-23 23:51:18 +0100931void radv_cmd_buffer_trace_emit(struct radv_cmd_buffer *cmd_buffer);
Dave Airlie15f47022017-02-26 23:52:08 +0000932bool radv_get_memory_fd(struct radv_device *device,
933 struct radv_device_memory *memory,
934 int *pFD);
Dave Airlief4e499e2016-10-07 09:16:09 +1000935/*
936 * Takes x,y,z as exact numbers of invocations, instead of blocks.
937 *
938 * Limitations: Can't call normal dispatch functions without binding or rebinding
939 * the compute pipeline.
940 */
941void radv_unaligned_dispatch(
942 struct radv_cmd_buffer *cmd_buffer,
943 uint32_t x,
944 uint32_t y,
945 uint32_t z);
946
947struct radv_event {
948 struct radeon_winsys_bo *bo;
949 uint64_t *map;
950};
951
952struct nir_shader;
953
954struct radv_shader_module {
955 struct nir_shader * nir;
956 unsigned char sha1[20];
957 uint32_t size;
958 char data[0];
959};
960
Bas Nieuwenhuizeneec55782017-07-02 02:48:41 +0200961struct ac_shader_variant_key;
Dave Airlief4e499e2016-10-07 09:16:09 +1000962
963void
964radv_hash_shader(unsigned char *hash, struct radv_shader_module *module,
965 const char *entrypoint,
966 const VkSpecializationInfo *spec_info,
967 const struct radv_pipeline_layout *layout,
Bas Nieuwenhuizeneec55782017-07-02 02:48:41 +0200968 const struct ac_shader_variant_key *key,
Dave Airlie99936d32017-01-20 09:55:37 +1000969 uint32_t is_geom_copy_shader);
Dave Airlief4e499e2016-10-07 09:16:09 +1000970
971static inline gl_shader_stage
972vk_to_mesa_shader_stage(VkShaderStageFlagBits vk_stage)
973{
974 assert(__builtin_popcount(vk_stage) == 1);
975 return ffs(vk_stage) - 1;
976}
977
978static inline VkShaderStageFlagBits
979mesa_to_vk_shader_stage(gl_shader_stage mesa_stage)
980{
981 return (1 << mesa_stage);
982}
983
984#define RADV_STAGE_MASK ((1 << MESA_SHADER_STAGES) - 1)
985
986#define radv_foreach_stage(stage, stage_bits) \
987 for (gl_shader_stage stage, \
988 __tmp = (gl_shader_stage)((stage_bits) & RADV_STAGE_MASK); \
989 stage = __builtin_ffs(__tmp) - 1, __tmp; \
990 __tmp &= ~(1 << (stage)))
991
Bas Nieuwenhuizenc9d4b572017-03-12 22:43:51 +0100992
993struct radv_shader_slab {
994 struct list_head slabs;
995 struct list_head shaders;
996 struct radeon_winsys_bo *bo;
997 uint64_t size;
998 char *ptr;
999};
1000
Dave Airlief4e499e2016-10-07 09:16:09 +10001001struct radv_shader_variant {
1002 uint32_t ref_count;
1003
1004 struct radeon_winsys_bo *bo;
Bas Nieuwenhuizenc9d4b572017-03-12 22:43:51 +01001005 uint64_t bo_offset;
Dave Airlief4e499e2016-10-07 09:16:09 +10001006 struct ac_shader_config config;
1007 struct ac_shader_variant_info info;
1008 unsigned rsrc1;
1009 unsigned rsrc2;
Dave Airlief395e342016-11-22 04:17:49 +00001010 uint32_t code_size;
Bas Nieuwenhuizenc9d4b572017-03-12 22:43:51 +01001011
1012 struct list_head slab_list;
Dave Airlief4e499e2016-10-07 09:16:09 +10001013};
1014
Bas Nieuwenhuizenc9d4b572017-03-12 22:43:51 +01001015
1016void *radv_alloc_shader_memory(struct radv_device *device,
1017 struct radv_shader_variant *shader);
1018
1019void radv_destroy_shader_slabs(struct radv_device *device);
1020
Dave Airlief4e499e2016-10-07 09:16:09 +10001021struct radv_depth_stencil_state {
1022 uint32_t db_depth_control;
1023 uint32_t db_stencil_control;
1024 uint32_t db_render_control;
1025 uint32_t db_render_override2;
1026};
1027
1028struct radv_blend_state {
1029 uint32_t cb_color_control;
1030 uint32_t cb_target_mask;
Dave Airlie9c080102017-08-21 07:17:27 +01001031 uint32_t sx_mrt_blend_opt[8];
Dave Airlief4e499e2016-10-07 09:16:09 +10001032 uint32_t cb_blend_control[8];
1033
1034 uint32_t spi_shader_col_format;
1035 uint32_t cb_shader_mask;
1036 uint32_t db_alpha_to_mask;
1037};
1038
1039unsigned radv_format_meta_fs_key(VkFormat format);
1040
1041struct radv_raster_state {
1042 uint32_t pa_cl_clip_cntl;
Dave Airlief4e499e2016-10-07 09:16:09 +10001043 uint32_t spi_interp_control;
1044 uint32_t pa_su_point_size;
1045 uint32_t pa_su_point_minmax;
1046 uint32_t pa_su_line_cntl;
1047 uint32_t pa_su_vtx_cntl;
1048 uint32_t pa_su_sc_mode_cntl;
1049};
1050
1051struct radv_multisample_state {
1052 uint32_t db_eqaa;
1053 uint32_t pa_sc_line_cntl;
1054 uint32_t pa_sc_mode_cntl_0;
1055 uint32_t pa_sc_mode_cntl_1;
1056 uint32_t pa_sc_aa_config;
1057 uint32_t pa_sc_aa_mask[2];
1058 unsigned num_samples;
1059};
1060
Dave Airlie3360dbe2017-02-13 07:30:29 +00001061struct radv_prim_vertex_count {
1062 uint8_t min;
1063 uint8_t incr;
1064};
1065
Dave Airlie4c60c682017-03-30 08:18:13 +01001066struct radv_tessellation_state {
1067 uint32_t ls_hs_config;
1068 uint32_t tcs_in_layout;
1069 uint32_t tcs_out_layout;
1070 uint32_t tcs_out_offsets;
1071 uint32_t offchip_layout;
1072 unsigned num_patches;
1073 unsigned lds_size;
1074 unsigned num_tcs_input_cp;
1075 uint32_t tf_param;
1076};
1077
Dave Airlief4e499e2016-10-07 09:16:09 +10001078struct radv_pipeline {
1079 struct radv_device * device;
1080 uint32_t dynamic_state_mask;
1081 struct radv_dynamic_state dynamic_state;
1082
1083 struct radv_pipeline_layout * layout;
1084
1085 bool needs_data_cache;
Dave Airlie25a5ee32017-04-18 10:21:59 +10001086 bool need_indirect_descriptor_sets;
Dave Airlief4e499e2016-10-07 09:16:09 +10001087 struct radv_shader_variant * shaders[MESA_SHADER_STAGES];
Dave Airlie99936d32017-01-20 09:55:37 +10001088 struct radv_shader_variant *gs_copy_shader;
Dave Airlief4e499e2016-10-07 09:16:09 +10001089 VkShaderStageFlags active_stages;
1090
1091 uint32_t va_rsrc_word3[MAX_VERTEX_ATTRIBS];
1092 uint32_t va_format_size[MAX_VERTEX_ATTRIBS];
1093 uint32_t va_binding[MAX_VERTEX_ATTRIBS];
1094 uint32_t va_offset[MAX_VERTEX_ATTRIBS];
1095 uint32_t num_vertex_attribs;
1096 uint32_t binding_stride[MAX_VBS];
1097
1098 union {
1099 struct {
1100 struct radv_blend_state blend;
1101 struct radv_depth_stencil_state ds;
1102 struct radv_raster_state raster;
1103 struct radv_multisample_state ms;
Dave Airlie4c60c682017-03-30 08:18:13 +01001104 struct radv_tessellation_state tess;
Dave Airlie8996fdb2017-03-28 11:34:19 +10001105 uint32_t db_shader_control;
Dave Airlie4b467c72017-03-28 11:34:46 +10001106 uint32_t shader_z_format;
Dave Airlief4e499e2016-10-07 09:16:09 +10001107 unsigned prim;
1108 unsigned gs_out;
Dave Airliecd33a5c2017-03-28 11:33:35 +10001109 uint32_t vgt_gs_mode;
Dave Airlie6a681702017-06-20 13:21:04 +10001110 bool vgt_primitiveid_en;
Dave Airlief4e499e2016-10-07 09:16:09 +10001111 bool prim_restart_enable;
Dave Airlie8f41fe42017-01-20 10:21:19 +10001112 unsigned esgs_ring_size;
1113 unsigned gsvs_ring_size;
Dave Airlie92e9c142017-03-28 11:43:48 +10001114 uint32_t ps_input_cntl[32];
1115 uint32_t ps_input_cntl_num;
Dave Airlie0232ea82017-03-28 11:48:38 +10001116 uint32_t pa_cl_vs_out_cntl;
Dave Airlie239a9222017-03-28 12:59:17 +10001117 uint32_t vgt_shader_stages_en;
Dave Airlie734ea162017-06-07 09:04:30 +10001118 uint32_t vtx_base_sgpr;
1119 uint8_t vtx_emit_num;
Dave Airlie3360dbe2017-02-13 07:30:29 +00001120 struct radv_prim_vertex_count prim_vertex_count;
Bas Nieuwenhuizen8a53e6e42017-03-29 22:58:10 +02001121 bool can_use_guardband;
Dave Airlief4e499e2016-10-07 09:16:09 +10001122 } graphics;
1123 };
Bas Nieuwenhuizenccff93e2017-01-29 15:20:03 +01001124
1125 unsigned max_waves;
1126 unsigned scratch_bytes_per_wave;
Dave Airlief4e499e2016-10-07 09:16:09 +10001127};
1128
Dave Airlief26fa872017-01-18 13:50:16 +10001129static inline bool radv_pipeline_has_gs(struct radv_pipeline *pipeline)
1130{
1131 return pipeline->shaders[MESA_SHADER_GEOMETRY] ? true : false;
1132}
1133
Dave Airlie06042842017-03-30 07:44:20 +01001134static inline bool radv_pipeline_has_tess(struct radv_pipeline *pipeline)
1135{
1136 return pipeline->shaders[MESA_SHADER_TESS_EVAL] ? true : false;
1137}
1138
Dave Airlie3f480212017-06-07 09:01:38 +10001139uint32_t radv_shader_stage_to_user_data_0(gl_shader_stage stage, bool has_gs, bool has_tess);
1140struct ac_userdata_info *radv_lookup_user_sgpr(struct radv_pipeline *pipeline,
1141 gl_shader_stage stage,
1142 int idx);
1143
Dave Airlief4e499e2016-10-07 09:16:09 +10001144struct radv_graphics_pipeline_create_info {
1145 bool use_rectlist;
1146 bool db_depth_clear;
1147 bool db_stencil_clear;
1148 bool db_depth_disable_expclear;
1149 bool db_stencil_disable_expclear;
1150 bool db_flush_depth_inplace;
1151 bool db_flush_stencil_inplace;
1152 bool db_resummarize;
1153 uint32_t custom_blend_mode;
1154};
1155
1156VkResult
1157radv_pipeline_init(struct radv_pipeline *pipeline, struct radv_device *device,
1158 struct radv_pipeline_cache *cache,
1159 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1160 const struct radv_graphics_pipeline_create_info *extra,
1161 const VkAllocationCallbacks *alloc);
1162
1163VkResult
1164radv_graphics_pipeline_create(VkDevice device,
1165 VkPipelineCache cache,
1166 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1167 const struct radv_graphics_pipeline_create_info *extra,
1168 const VkAllocationCallbacks *alloc,
1169 VkPipeline *pPipeline);
1170
1171struct vk_format_description;
1172uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *desc,
1173 int first_non_void);
1174uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
1175 int first_non_void);
1176uint32_t radv_translate_colorformat(VkFormat format);
1177uint32_t radv_translate_color_numformat(VkFormat format,
1178 const struct vk_format_description *desc,
1179 int first_non_void);
1180uint32_t radv_colorformat_endian_swap(uint32_t colorformat);
1181unsigned radv_translate_colorswap(VkFormat format, bool do_endian_swap);
1182uint32_t radv_translate_dbformat(VkFormat format);
1183uint32_t radv_translate_tex_dataformat(VkFormat format,
1184 const struct vk_format_description *desc,
1185 int first_non_void);
1186uint32_t radv_translate_tex_numformat(VkFormat format,
1187 const struct vk_format_description *desc,
1188 int first_non_void);
1189bool radv_format_pack_clear_color(VkFormat format,
1190 uint32_t clear_vals[2],
1191 VkClearColorValue *value);
1192bool radv_is_colorbuffer_format_supported(VkFormat format, bool *blendable);
1193
1194struct radv_fmask_info {
1195 uint64_t offset;
1196 uint64_t size;
1197 unsigned alignment;
1198 unsigned pitch_in_pixels;
1199 unsigned bank_height;
1200 unsigned slice_tile_max;
1201 unsigned tile_mode_index;
Dave Airlie1e696b92017-08-04 06:54:15 +01001202 unsigned tile_swizzle;
Dave Airlief4e499e2016-10-07 09:16:09 +10001203};
1204
1205struct radv_cmask_info {
1206 uint64_t offset;
1207 uint64_t size;
1208 unsigned alignment;
Dave Airlief4e499e2016-10-07 09:16:09 +10001209 unsigned slice_tile_max;
1210 unsigned base_address_reg;
1211};
1212
1213struct r600_htile_info {
1214 uint64_t offset;
1215 uint64_t size;
1216 unsigned pitch;
1217 unsigned height;
1218 unsigned xalign;
1219 unsigned yalign;
1220};
1221
1222struct radv_image {
1223 VkImageType type;
1224 /* The original VkFormat provided by the client. This may not match any
1225 * of the actual surface formats.
1226 */
1227 VkFormat vk_format;
1228 VkImageAspectFlags aspects;
Nicolai Hähnledfc06d22017-05-10 23:01:00 +02001229 struct ac_surf_info info;
Dave Airlief4e499e2016-10-07 09:16:09 +10001230 VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
1231 VkImageTiling tiling; /** VkImageCreateInfo::tiling */
Bas Nieuwenhuizen6154efc2017-02-04 15:56:20 +01001232 VkImageCreateFlags flags; /** VkImageCreateInfo::flags */
Dave Airlief4e499e2016-10-07 09:16:09 +10001233
1234 VkDeviceSize size;
1235 uint32_t alignment;
1236
Bas Nieuwenhuizenaccc5fc2016-12-17 21:25:32 +01001237 bool exclusive;
1238 unsigned queue_family_mask;
1239
Jason Ekstrandb7082972017-07-15 02:08:01 +02001240 bool shareable;
1241
Dave Airlief4e499e2016-10-07 09:16:09 +10001242 /* Set when bound */
1243 struct radeon_winsys_bo *bo;
1244 VkDeviceSize offset;
1245 uint32_t dcc_offset;
Bas Nieuwenhuizen3b455c12017-03-07 00:58:04 +01001246 uint32_t htile_offset;
Dave Airlief4e499e2016-10-07 09:16:09 +10001247 struct radeon_surf surface;
1248
1249 struct radv_fmask_info fmask;
1250 struct radv_cmask_info cmask;
1251 uint32_t clear_value_offset;
Dave Airlie9ee67462017-03-02 21:39:10 +00001252 uint32_t dcc_pred_offset;
Dave Airlief4e499e2016-10-07 09:16:09 +10001253};
1254
Bas Nieuwenhuizen06285802017-05-15 01:23:24 +02001255/* Whether the image has a htile that is known consistent with the contents of
1256 * the image. */
Dave Airlief4e499e2016-10-07 09:16:09 +10001257bool radv_layout_has_htile(const struct radv_image *image,
Bas Nieuwenhuizen0b26f0e2017-05-15 23:00:17 +02001258 VkImageLayout layout,
1259 unsigned queue_mask);
Bas Nieuwenhuizen06285802017-05-15 01:23:24 +02001260
1261/* Whether the image has a htile that is known consistent with the contents of
1262 * the image and is allowed to be in compressed form.
1263 *
1264 * If this is false reads that don't use the htile should be able to return
1265 * correct results.
1266 */
Dave Airlief4e499e2016-10-07 09:16:09 +10001267bool radv_layout_is_htile_compressed(const struct radv_image *image,
Bas Nieuwenhuizen0b26f0e2017-05-15 23:00:17 +02001268 VkImageLayout layout,
1269 unsigned queue_mask);
Bas Nieuwenhuizen06285802017-05-15 01:23:24 +02001270
Bas Nieuwenhuizen059af252016-12-27 00:57:36 +01001271bool radv_layout_can_fast_clear(const struct radv_image *image,
1272 VkImageLayout layout,
1273 unsigned queue_mask);
Bas Nieuwenhuizenaccc5fc2016-12-17 21:25:32 +01001274
1275
Dave Airliecda9f3d2017-01-31 15:18:33 +10001276unsigned radv_image_queue_family_mask(const struct radv_image *image, uint32_t family, uint32_t queue_family);
Bas Nieuwenhuizenaccc5fc2016-12-17 21:25:32 +01001277
Dave Airlief4e499e2016-10-07 09:16:09 +10001278static inline uint32_t
1279radv_get_layerCount(const struct radv_image *image,
1280 const VkImageSubresourceRange *range)
1281{
1282 return range->layerCount == VK_REMAINING_ARRAY_LAYERS ?
Dave Airlie7e8d0a42017-05-02 09:49:14 +10001283 image->info.array_size - range->baseArrayLayer : range->layerCount;
Dave Airlief4e499e2016-10-07 09:16:09 +10001284}
1285
1286static inline uint32_t
1287radv_get_levelCount(const struct radv_image *image,
1288 const VkImageSubresourceRange *range)
1289{
1290 return range->levelCount == VK_REMAINING_MIP_LEVELS ?
Dave Airlie7e8d0a42017-05-02 09:49:14 +10001291 image->info.levels - range->baseMipLevel : range->levelCount;
Dave Airlief4e499e2016-10-07 09:16:09 +10001292}
1293
1294struct radeon_bo_metadata;
1295void
1296radv_init_metadata(struct radv_device *device,
1297 struct radv_image *image,
1298 struct radeon_bo_metadata *metadata);
1299
1300struct radv_image_view {
1301 struct radv_image *image; /**< VkImageViewCreateInfo::image */
1302 struct radeon_winsys_bo *bo;
1303
1304 VkImageViewType type;
1305 VkImageAspectFlags aspect_mask;
1306 VkFormat vk_format;
1307 uint32_t base_layer;
1308 uint32_t layer_count;
1309 uint32_t base_mip;
Dave Airlie5378b5d2017-08-21 13:56:33 +10001310 uint32_t level_count;
Dave Airlief4e499e2016-10-07 09:16:09 +10001311 VkExtent3D extent; /**< Extent of VkImageViewCreateInfo::baseMipLevel. */
1312
1313 uint32_t descriptor[8];
1314 uint32_t fmask_descriptor[8];
Alex Smith0e1886e2017-07-12 10:29:52 +01001315
1316 /* Descriptor for use as a storage image as opposed to a sampled image.
1317 * This has a few differences for cube maps (e.g. type).
1318 */
1319 uint32_t storage_descriptor[8];
1320 uint32_t storage_fmask_descriptor[8];
Dave Airlief4e499e2016-10-07 09:16:09 +10001321};
1322
1323struct radv_image_create_info {
1324 const VkImageCreateInfo *vk_info;
Dave Airlief4e499e2016-10-07 09:16:09 +10001325 bool scanout;
1326};
1327
1328VkResult radv_image_create(VkDevice _device,
1329 const struct radv_image_create_info *info,
1330 const VkAllocationCallbacks* alloc,
1331 VkImage *pImage);
1332
1333void radv_image_view_init(struct radv_image_view *view,
1334 struct radv_device *device,
Bas Nieuwenhuizen78bef012017-06-25 22:25:47 +02001335 const VkImageViewCreateInfo* pCreateInfo);
Dave Airlie823e9ea2017-04-28 08:06:09 +01001336
Dave Airlief4e499e2016-10-07 09:16:09 +10001337struct radv_buffer_view {
1338 struct radeon_winsys_bo *bo;
1339 VkFormat vk_format;
1340 uint64_t range; /**< VkBufferViewCreateInfo::range */
1341 uint32_t state[4];
1342};
1343void radv_buffer_view_init(struct radv_buffer_view *view,
1344 struct radv_device *device,
1345 const VkBufferViewCreateInfo* pCreateInfo,
1346 struct radv_cmd_buffer *cmd_buffer);
1347
1348static inline struct VkExtent3D
1349radv_sanitize_image_extent(const VkImageType imageType,
1350 const struct VkExtent3D imageExtent)
1351{
1352 switch (imageType) {
1353 case VK_IMAGE_TYPE_1D:
1354 return (VkExtent3D) { imageExtent.width, 1, 1 };
1355 case VK_IMAGE_TYPE_2D:
1356 return (VkExtent3D) { imageExtent.width, imageExtent.height, 1 };
1357 case VK_IMAGE_TYPE_3D:
1358 return imageExtent;
1359 default:
1360 unreachable("invalid image type");
1361 }
1362}
1363
1364static inline struct VkOffset3D
1365radv_sanitize_image_offset(const VkImageType imageType,
1366 const struct VkOffset3D imageOffset)
1367{
1368 switch (imageType) {
1369 case VK_IMAGE_TYPE_1D:
1370 return (VkOffset3D) { imageOffset.x, 0, 0 };
1371 case VK_IMAGE_TYPE_2D:
1372 return (VkOffset3D) { imageOffset.x, imageOffset.y, 0 };
1373 case VK_IMAGE_TYPE_3D:
1374 return imageOffset;
1375 default:
1376 unreachable("invalid image type");
1377 }
1378}
1379
Dave Airlied5400a52017-05-02 09:40:36 +10001380static inline bool
1381radv_image_extent_compare(const struct radv_image *image,
1382 const VkExtent3D *extent)
1383{
Dave Airlie7e8d0a42017-05-02 09:49:14 +10001384 if (extent->width != image->info.width ||
1385 extent->height != image->info.height ||
1386 extent->depth != image->info.depth)
Dave Airlied5400a52017-05-02 09:40:36 +10001387 return false;
1388 return true;
1389}
1390
Dave Airlief4e499e2016-10-07 09:16:09 +10001391struct radv_sampler {
1392 uint32_t state[4];
1393};
1394
1395struct radv_color_buffer_info {
Dave Airlie745aa172017-06-01 05:32:25 +01001396 uint64_t cb_color_base;
1397 uint64_t cb_color_cmask;
1398 uint64_t cb_color_fmask;
1399 uint64_t cb_dcc_base;
Dave Airlief4e499e2016-10-07 09:16:09 +10001400 uint32_t cb_color_pitch;
1401 uint32_t cb_color_slice;
1402 uint32_t cb_color_view;
1403 uint32_t cb_color_info;
1404 uint32_t cb_color_attrib;
Dave Airlieac3e1892017-06-06 08:38:36 +10001405 uint32_t cb_color_attrib2;
Dave Airlief4e499e2016-10-07 09:16:09 +10001406 uint32_t cb_dcc_control;
Dave Airlief4e499e2016-10-07 09:16:09 +10001407 uint32_t cb_color_cmask_slice;
Dave Airlief4e499e2016-10-07 09:16:09 +10001408 uint32_t cb_color_fmask_slice;
1409 uint32_t cb_clear_value0;
1410 uint32_t cb_clear_value1;
Dave Airlief4e499e2016-10-07 09:16:09 +10001411 uint32_t micro_tile_mode;
Dave Airlieac3e1892017-06-06 08:38:36 +10001412 uint32_t gfx9_epitch;
Dave Airlief4e499e2016-10-07 09:16:09 +10001413};
1414
1415struct radv_ds_buffer_info {
Dave Airlie745aa172017-06-01 05:32:25 +01001416 uint64_t db_z_read_base;
1417 uint64_t db_stencil_read_base;
1418 uint64_t db_z_write_base;
1419 uint64_t db_stencil_write_base;
1420 uint64_t db_htile_data_base;
Dave Airlief4e499e2016-10-07 09:16:09 +10001421 uint32_t db_depth_info;
1422 uint32_t db_z_info;
1423 uint32_t db_stencil_info;
Dave Airlief4e499e2016-10-07 09:16:09 +10001424 uint32_t db_depth_view;
1425 uint32_t db_depth_size;
1426 uint32_t db_depth_slice;
1427 uint32_t db_htile_surface;
Dave Airlief4e499e2016-10-07 09:16:09 +10001428 uint32_t pa_su_poly_offset_db_fmt_cntl;
Dave Airlie41eba752017-06-06 08:39:44 +10001429 uint32_t db_z_info2;
1430 uint32_t db_stencil_info2;
Dave Airlief4e499e2016-10-07 09:16:09 +10001431 float offset_scale;
1432};
1433
1434struct radv_attachment_info {
1435 union {
1436 struct radv_color_buffer_info cb;
1437 struct radv_ds_buffer_info ds;
1438 };
1439 struct radv_image_view *attachment;
1440};
1441
1442struct radv_framebuffer {
1443 uint32_t width;
1444 uint32_t height;
1445 uint32_t layers;
1446
1447 uint32_t attachment_count;
1448 struct radv_attachment_info attachments[0];
1449};
1450
1451struct radv_subpass_barrier {
1452 VkPipelineStageFlags src_stage_mask;
1453 VkAccessFlags src_access_mask;
1454 VkAccessFlags dst_access_mask;
1455};
1456
1457struct radv_subpass {
1458 uint32_t input_count;
Dave Airlief4e499e2016-10-07 09:16:09 +10001459 uint32_t color_count;
Dave Airliece0f6922017-05-02 10:32:02 +10001460 VkAttachmentReference * input_attachments;
Dave Airlief4e499e2016-10-07 09:16:09 +10001461 VkAttachmentReference * color_attachments;
1462 VkAttachmentReference * resolve_attachments;
1463 VkAttachmentReference depth_stencil_attachment;
1464
1465 /** Subpass has at least one resolve attachment */
1466 bool has_resolve;
1467
1468 struct radv_subpass_barrier start_barrier;
Bas Nieuwenhuizen3907d632017-07-02 19:20:47 +02001469
1470 uint32_t view_mask;
Dave Airlief4e499e2016-10-07 09:16:09 +10001471};
1472
1473struct radv_render_pass_attachment {
1474 VkFormat format;
1475 uint32_t samples;
1476 VkAttachmentLoadOp load_op;
1477 VkAttachmentLoadOp stencil_load_op;
1478 VkImageLayout initial_layout;
1479 VkImageLayout final_layout;
Bas Nieuwenhuizen3907d632017-07-02 19:20:47 +02001480 uint32_t view_mask;
Dave Airlief4e499e2016-10-07 09:16:09 +10001481};
1482
1483struct radv_render_pass {
1484 uint32_t attachment_count;
1485 uint32_t subpass_count;
1486 VkAttachmentReference * subpass_attachments;
1487 struct radv_render_pass_attachment * attachments;
1488 struct radv_subpass_barrier end_barrier;
1489 struct radv_subpass subpasses[0];
1490};
1491
1492VkResult radv_device_init_meta(struct radv_device *device);
1493void radv_device_finish_meta(struct radv_device *device);
1494
1495struct radv_query_pool {
1496 struct radeon_winsys_bo *bo;
1497 uint32_t stride;
1498 uint32_t availability_offset;
1499 char *ptr;
1500 VkQueryType type;
Bas Nieuwenhuizen8475a142017-04-10 22:20:19 +02001501 uint32_t pipeline_stats_mask;
Dave Airlief4e499e2016-10-07 09:16:09 +10001502};
1503
Dave Airlieeaa56ea2017-02-27 19:14:00 +00001504struct radv_semaphore {
1505 /* use a winsys sem for non-exportable */
1506 struct radeon_winsys_sem *sem;
1507 uint32_t syncobj;
1508 uint32_t temp_syncobj;
1509};
1510
1511VkResult radv_alloc_sem_info(struct radv_winsys_sem_info *sem_info,
1512 int num_wait_sems,
1513 const VkSemaphore *wait_sems,
1514 int num_signal_sems,
1515 const VkSemaphore *signal_sems);
1516void radv_free_sem_info(struct radv_winsys_sem_info *sem_info);
1517
Fredrik Höglunda6e94a82017-03-29 18:08:06 +02001518void
1519radv_update_descriptor_sets(struct radv_device *device,
1520 struct radv_cmd_buffer *cmd_buffer,
1521 VkDescriptorSet overrideSet,
1522 uint32_t descriptorWriteCount,
1523 const VkWriteDescriptorSet *pDescriptorWrites,
1524 uint32_t descriptorCopyCount,
1525 const VkCopyDescriptorSet *pDescriptorCopies);
1526
Fredrik Höglundc1f8c832017-03-29 19:19:47 +02001527void
1528radv_update_descriptor_set_with_template(struct radv_device *device,
1529 struct radv_cmd_buffer *cmd_buffer,
1530 struct radv_descriptor_set *set,
1531 VkDescriptorUpdateTemplateKHR descriptorUpdateTemplate,
1532 const void *pData);
1533
Fredrik Höglundf95caae2017-04-14 00:26:58 +02001534void radv_meta_push_descriptor_set(struct radv_cmd_buffer *cmd_buffer,
1535 VkPipelineBindPoint pipelineBindPoint,
1536 VkPipelineLayout _layout,
1537 uint32_t set,
1538 uint32_t descriptorWriteCount,
1539 const VkWriteDescriptorSet *pDescriptorWrites);
1540
Dave Airlief4e499e2016-10-07 09:16:09 +10001541void radv_initialise_cmask(struct radv_cmd_buffer *cmd_buffer,
1542 struct radv_image *image, uint32_t value);
1543void radv_initialize_dcc(struct radv_cmd_buffer *cmd_buffer,
1544 struct radv_image *image, uint32_t value);
Fredrik Höglund0a153f42016-10-25 20:31:41 +02001545
1546struct radv_fence {
1547 struct radeon_winsys_fence *fence;
1548 bool submitted;
1549 bool signalled;
1550};
1551
Grazvydas Ignotas5458b022017-03-05 23:04:50 +02001552struct radeon_winsys_sem;
1553
Dave Airlief4e499e2016-10-07 09:16:09 +10001554#define RADV_DEFINE_HANDLE_CASTS(__radv_type, __VkType) \
1555 \
1556 static inline struct __radv_type * \
1557 __radv_type ## _from_handle(__VkType _handle) \
1558 { \
1559 return (struct __radv_type *) _handle; \
1560 } \
1561 \
1562 static inline __VkType \
1563 __radv_type ## _to_handle(struct __radv_type *_obj) \
1564 { \
1565 return (__VkType) _obj; \
1566 }
1567
1568#define RADV_DEFINE_NONDISP_HANDLE_CASTS(__radv_type, __VkType) \
1569 \
1570 static inline struct __radv_type * \
1571 __radv_type ## _from_handle(__VkType _handle) \
1572 { \
1573 return (struct __radv_type *)(uintptr_t) _handle; \
1574 } \
1575 \
1576 static inline __VkType \
1577 __radv_type ## _to_handle(struct __radv_type *_obj) \
1578 { \
1579 return (__VkType)(uintptr_t) _obj; \
1580 }
1581
1582#define RADV_FROM_HANDLE(__radv_type, __name, __handle) \
1583 struct __radv_type *__name = __radv_type ## _from_handle(__handle)
1584
1585RADV_DEFINE_HANDLE_CASTS(radv_cmd_buffer, VkCommandBuffer)
1586RADV_DEFINE_HANDLE_CASTS(radv_device, VkDevice)
1587RADV_DEFINE_HANDLE_CASTS(radv_instance, VkInstance)
1588RADV_DEFINE_HANDLE_CASTS(radv_physical_device, VkPhysicalDevice)
1589RADV_DEFINE_HANDLE_CASTS(radv_queue, VkQueue)
1590
1591RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_cmd_pool, VkCommandPool)
1592RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer, VkBuffer)
1593RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_buffer_view, VkBufferView)
1594RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_pool, VkDescriptorPool)
1595RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set, VkDescriptorSet)
1596RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_set_layout, VkDescriptorSetLayout)
Fredrik Höglundc1f8c832017-03-29 19:19:47 +02001597RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_descriptor_update_template, VkDescriptorUpdateTemplateKHR)
Dave Airlief4e499e2016-10-07 09:16:09 +10001598RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_device_memory, VkDeviceMemory)
1599RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_fence, VkFence)
1600RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_event, VkEvent)
1601RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_framebuffer, VkFramebuffer)
1602RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image, VkImage)
1603RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_image_view, VkImageView);
1604RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_cache, VkPipelineCache)
1605RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline, VkPipeline)
1606RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_pipeline_layout, VkPipelineLayout)
1607RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_query_pool, VkQueryPool)
1608RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_render_pass, VkRenderPass)
1609RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_sampler, VkSampler)
1610RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_shader_module, VkShaderModule)
Dave Airlieeaa56ea2017-02-27 19:14:00 +00001611RADV_DEFINE_NONDISP_HANDLE_CASTS(radv_semaphore, VkSemaphore)
Dave Airlief4e499e2016-10-07 09:16:09 +10001612
Edward O'Callaghanba437682016-10-07 22:19:19 +11001613#endif /* RADV_PRIVATE_H */