radv_device.c 259 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright © 2016 Red Hat.
 * Copyright © 2016 Bas Nieuwenhuizen
 *
 * based in part on anv driver which is:
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

28
#include "dirent.h"
29
30
31
32
33
34
35
#include <errno.h>
#include <fcntl.h>
#include <linux/audit.h>
#include <linux/bpf.h>
#include <linux/filter.h>
#include <linux/seccomp.h>
#include <linux/unistd.h>
36
#include <stdbool.h>
37
38
#include <stddef.h>
#include <stdio.h>
39
#include <string.h>
40
41
#include <sys/prctl.h>
#include <sys/wait.h>
42
43
#include <unistd.h>
#include <fcntl.h>
44
#include <llvm/Config/llvm-config.h>
45

46
#include "radv_debug.h"
47
#include "radv_private.h"
48
#include "radv_shader.h"
49
#include "radv_cs.h"
50
#include "util/disk_cache.h"
51
#include "vk_util.h"
52
#include <xf86drm.h>
53
54
55
56
57
58
#include <amdgpu.h>
#include <amdgpu_drm.h>
#include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
#include "ac_llvm_util.h"
#include "vk_format.h"
#include "sid.h"
59
#include "git_sha1.h"
60
#include "util/build_id.h"
61
#include "util/debug.h"
62
#include "util/mesa-sha1.h"
63
#include "util/timespec.h"
64
#include "util/u_atomic.h"
65
#include "compiler/glsl_types.h"
66
#include "util/xmlpool.h"
67

68
69
70
71
72
73
74
75
76
77
static struct radv_timeline_point *
radv_timeline_find_point_at_least_locked(struct radv_device *device,
                                         struct radv_timeline *timeline,
                                         uint64_t p);

static struct radv_timeline_point *
radv_timeline_add_point_locked(struct radv_device *device,
                               struct radv_timeline *timeline,
                               uint64_t p);

78
79
80
static void
radv_timeline_trigger_waiters_locked(struct radv_timeline *timeline,
                                     struct list_head *processing_list);
81

82
83
84
85
static
void radv_destroy_semaphore_part(struct radv_device *device,
                                 struct radv_semaphore_part *part);

86
static int
87
radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
88
{
89
90
91
	struct mesa_sha1 ctx;
	unsigned char sha1[20];
	unsigned ptr_size = sizeof(void*);
92

93
	memset(uuid, 0, VK_UUID_SIZE);
94
	_mesa_sha1_init(&ctx);
95

96
97
	if (!disk_cache_get_function_identifier(radv_device_get_cache_uuid, &ctx) ||
	    !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo, &ctx))
98
99
		return -1;

100
101
102
103
104
	_mesa_sha1_update(&ctx, &family, sizeof(family));
	_mesa_sha1_update(&ctx, &ptr_size, sizeof(ptr_size));
	_mesa_sha1_final(&ctx, sha1);

	memcpy(uuid, sha1, VK_UUID_SIZE);
105
	return 0;
106
107
}

108
109
110
111
112
113
static void
radv_get_driver_uuid(void *uuid)
{
	ac_compute_driver_uuid(uuid, VK_UUID_SIZE);
}

114
static void
115
116
117
radv_get_device_uuid(struct radeon_info *info, void *uuid)
{
	ac_compute_device_uuid(info, uuid, VK_UUID_SIZE);
118
119
}

120
121
122
123
124
125
126
127
128
129
130
131
static uint64_t
radv_get_visible_vram_size(struct radv_physical_device *device)
{
	return MIN2(device->rad_info.vram_size, device->rad_info.vram_vis_size);
}

static uint64_t
radv_get_vram_size(struct radv_physical_device *device)
{
	return device->rad_info.vram_size - radv_get_visible_vram_size(device);
}

132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
static bool
radv_is_mem_type_vram(enum radv_mem_type type)
{
	return type == RADV_MEM_TYPE_VRAM ||
	       type == RADV_MEM_TYPE_VRAM_UNCACHED;
}

static bool
radv_is_mem_type_vram_visible(enum radv_mem_type type)
{
	return type == RADV_MEM_TYPE_VRAM_CPU_ACCESS ||
	       type == RADV_MEM_TYPE_VRAM_CPU_ACCESS_UNCACHED;
}
static bool
radv_is_mem_type_gtt_wc(enum radv_mem_type type)
{
	return type == RADV_MEM_TYPE_GTT_WRITE_COMBINE ||
	       type == RADV_MEM_TYPE_GTT_WRITE_COMBINE_VRAM_UNCACHED;
}

static bool
radv_is_mem_type_gtt_cached(enum radv_mem_type type)
{
	return type == RADV_MEM_TYPE_GTT_CACHED ||
	       type == RADV_MEM_TYPE_GTT_CACHED_VRAM_UNCACHED;
}

static bool
radv_is_mem_type_uncached(enum radv_mem_type type)
{
	return type == RADV_MEM_TYPE_VRAM_UNCACHED ||
	       type == RADV_MEM_TYPE_VRAM_CPU_ACCESS_UNCACHED ||
	       type == RADV_MEM_TYPE_GTT_WRITE_COMBINE_VRAM_UNCACHED ||
	       type == RADV_MEM_TYPE_GTT_CACHED_VRAM_UNCACHED;
}

168
169
170
171
static void
radv_physical_device_init_mem_types(struct radv_physical_device *device)
{
	STATIC_ASSERT(RADV_MEM_HEAP_COUNT <= VK_MAX_MEMORY_HEAPS);
172
173
	uint64_t visible_vram_size = radv_get_visible_vram_size(device);
	uint64_t vram_size = radv_get_vram_size(device);
174
175
	int vram_index = -1, visible_vram_index = -1, gart_index = -1;
	device->memory_properties.memoryHeapCount = 0;
176
	if (vram_size > 0) {
177
178
		vram_index = device->memory_properties.memoryHeapCount++;
		device->memory_properties.memoryHeaps[vram_index] = (VkMemoryHeap) {
179
			.size = vram_size,
180
181
182
183
184
185
186
187
188
189
190
191
192
193
			.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
		};
	}
	if (visible_vram_size) {
		visible_vram_index = device->memory_properties.memoryHeapCount++;
		device->memory_properties.memoryHeaps[visible_vram_index] = (VkMemoryHeap) {
			.size = visible_vram_size,
			.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
		};
	}
	if (device->rad_info.gart_size > 0) {
		gart_index = device->memory_properties.memoryHeapCount++;
		device->memory_properties.memoryHeaps[gart_index] = (VkMemoryHeap) {
			.size = device->rad_info.gart_size,
194
			.flags = device->rad_info.has_dedicated_vram ? 0 : VK_MEMORY_HEAP_DEVICE_LOCAL_BIT,
195
196
197
198
199
200
201
202
203
204
205
206
		};
	}

	STATIC_ASSERT(RADV_MEM_TYPE_COUNT <= VK_MAX_MEMORY_TYPES);
	unsigned type_count = 0;
	if (vram_index >= 0) {
		device->mem_type_indices[type_count] = RADV_MEM_TYPE_VRAM;
		device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
			.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
			.heapIndex = vram_index,
		};
	}
207
	if (gart_index >= 0 && device->rad_info.has_dedicated_vram) {
208
209
210
		device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_WRITE_COMBINE;
		device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
			.propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
211
			VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
212
213
214
215
216
217
218
219
220
221
222
223
			.heapIndex = gart_index,
		};
	}
	if (visible_vram_index >= 0) {
		device->mem_type_indices[type_count] = RADV_MEM_TYPE_VRAM_CPU_ACCESS;
		device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
			.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
			VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
			VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
			.heapIndex = visible_vram_index,
		};
	}
224
225
226
227
228
229
230
231
232
233
234
235
236
	if (gart_index >= 0 && !device->rad_info.has_dedicated_vram) {
		/* Put GTT after visible VRAM for GPUs without dedicated VRAM
		 * as they have identical property flags, and according to the
		 * spec, for types with identical flags, the one with greater
		 * performance must be given a lower index. */
		device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_WRITE_COMBINE;
		device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
			.propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
			VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
			VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
			.heapIndex = gart_index,
		};
	}
237
238
239
240
241
	if (gart_index >= 0) {
		device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_CACHED;
		device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
			.propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
			VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
242
243
			VK_MEMORY_PROPERTY_HOST_CACHED_BIT |
			(device->rad_info.has_dedicated_vram ? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
244
245
246
247
			.heapIndex = gart_index,
		};
	}
	device->memory_properties.memoryTypeCount = type_count;
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

	if (device->rad_info.has_l2_uncached) {
		for (int i = 0; i < device->memory_properties.memoryTypeCount; i++) {
			VkMemoryType mem_type = device->memory_properties.memoryTypes[i];

			if ((mem_type.propertyFlags & (VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
						       VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) ||
			    mem_type.propertyFlags == VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
				enum radv_mem_type mem_type_id;

				switch (device->mem_type_indices[i]) {
				case RADV_MEM_TYPE_VRAM:
					mem_type_id = RADV_MEM_TYPE_VRAM_UNCACHED;
					break;
				case RADV_MEM_TYPE_VRAM_CPU_ACCESS:
					mem_type_id = RADV_MEM_TYPE_VRAM_CPU_ACCESS_UNCACHED;
					break;
				case RADV_MEM_TYPE_GTT_WRITE_COMBINE:
					mem_type_id = RADV_MEM_TYPE_GTT_WRITE_COMBINE_VRAM_UNCACHED;
					break;
				case RADV_MEM_TYPE_GTT_CACHED:
					mem_type_id = RADV_MEM_TYPE_GTT_CACHED_VRAM_UNCACHED;
					break;
				default:
					unreachable("invalid memory type");
				}

				VkMemoryPropertyFlags property_flags = mem_type.propertyFlags |
					VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD |
					VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD;

				device->mem_type_indices[type_count] = mem_type_id;
				device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
					.propertyFlags = property_flags,
					.heapIndex = mem_type.heapIndex,
				};
			}
		}
		device->memory_properties.memoryTypeCount = type_count;
	}
288
289
}

290
291
292
293
294
295
296
297
298
299
300
301
302
static void
radv_handle_env_var_force_family(struct radv_physical_device *device)
{
	const char *family = getenv("RADV_FORCE_FAMILY");
	unsigned i;

	if (!family)
		return;

	for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
		if (!strcmp(family, ac_get_llvm_processor_name(i))) {
			/* Override family and chip_class. */
			device->rad_info.family = i;
303
			device->rad_info.name = "OVERRIDDEN";
304

305
306
307
			if (i >= CHIP_NAVI10)
				device->rad_info.chip_class = GFX10;
			else if (i >= CHIP_VEGA10)
308
309
				device->rad_info.chip_class = GFX9;
			else if (i >= CHIP_TONGA)
310
				device->rad_info.chip_class = GFX8;
311
			else if (i >= CHIP_BONAIRE)
312
				device->rad_info.chip_class = GFX7;
313
			else
314
				device->rad_info.chip_class = GFX6;
315

316
317
			/* Don't submit any IBs. */
			device->instance->debug_flags |= RADV_DEBUG_NOOP;
318
319
320
321
322
323
324
325
			return;
		}
	}

	fprintf(stderr, "radv: Unknown family: %s\n", family);
	exit(1);
}

326
327
328
static VkResult
radv_physical_device_init(struct radv_physical_device *device,
			  struct radv_instance *instance,
329
			  drmDevicePtr drm_device)
330
{
331
	const char *path = drm_device->nodes[DRM_NODE_RENDER];
332
	VkResult result;
333
	drmVersionPtr version;
334
	int fd;
335
	int master_fd = -1;
336
337

	fd = open(path, O_RDWR | O_CLOEXEC);
338
339
340
341
	if (fd < 0) {
		if (instance->debug_flags & RADV_DEBUG_STARTUP)
			radv_logi("Could not open device '%s'", path);

342
		return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
343
	}
344

345
346
347
	version = drmGetVersion(fd);
	if (!version) {
		close(fd);
348
349
350
351

		if (instance->debug_flags & RADV_DEBUG_STARTUP)
			radv_logi("Could not get the kernel driver version for device '%s'", path);

352
		return vk_errorf(instance, VK_ERROR_INCOMPATIBLE_DRIVER,
353
354
355
356
357
358
				 "failed to get version %s: %m", path);
	}

	if (strcmp(version->name, "amdgpu")) {
		drmFreeVersion(version);
		close(fd);
359
360
361
362

		if (instance->debug_flags & RADV_DEBUG_STARTUP)
			radv_logi("Device '%s' is not using the amdgpu kernel driver.", path);

363
		return VK_ERROR_INCOMPATIBLE_DRIVER;
364
365
366
	}
	drmFreeVersion(version);

367
368
369
	if (instance->debug_flags & RADV_DEBUG_STARTUP)
			radv_logi("Found compatible device '%s'.", path);

370
371
372
	device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
	device->instance = instance;

373
374
	device->ws = radv_amdgpu_winsys_create(fd, instance->debug_flags,
					       instance->perftest_flags);
375
	if (!device->ws) {
376
		result = vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
377
378
		goto fail;
	}
379

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
	if (instance->enabled_extensions.KHR_display) {
		master_fd = open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
		if (master_fd >= 0) {
			uint32_t accel_working = 0;
			struct drm_amdgpu_info request = {
				.return_pointer = (uintptr_t)&accel_working,
				.return_size = sizeof(accel_working),
				.query = AMDGPU_INFO_ACCEL_WORKING
			};

			if (drmCommandWrite(master_fd, DRM_AMDGPU_INFO, &request, sizeof (struct drm_amdgpu_info)) < 0 || !accel_working) {
				close(master_fd);
				master_fd = -1;
			}
		}
	}

397
	device->master_fd = master_fd;
398
	device->local_fd = fd;
399
400
	device->ws->query_info(device->ws, &device->rad_info);

401
402
	radv_handle_env_var_force_family(device);

403
404
	device->use_aco = instance->perftest_flags & RADV_PERFTEST_ACO;

405
406
407
	snprintf(device->name, sizeof(device->name),
		 "AMD RADV%s %s (LLVM " MESA_LLVM_VERSION_STRING ")", device->use_aco ? "/ACO" : "",
		 device->rad_info.name);
408

409
	if (radv_device_get_cache_uuid(device->rad_info.family, device->cache_uuid)) {
410
		device->ws->destroy(device->ws);
411
		result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
412
				   "cannot generate UUID");
413
414
		goto fail;
	}
415

416
417
418
	/* These flags affect shader compilation. */
	uint64_t shader_env_flags =
		(device->instance->perftest_flags & RADV_PERFTEST_SISCHED ? 0x1 : 0) |
419
		(device->use_aco ? 0x2 : 0);
420

Grazvydas Ignotas's avatar
Grazvydas Ignotas committed
421
	/* The gpu id is already embedded in the uuid so we just pass "radv"
422
423
	 * when creating the cache.
	 */
424
425
	char buf[VK_UUID_SIZE * 2 + 1];
	disk_cache_format_hex_id(buf, device->cache_uuid, VK_UUID_SIZE * 2);
426
	device->disk_cache = disk_cache_create(device->name, buf, shader_env_flags);
427

428
	if (device->rad_info.chip_class < GFX8)
429
		fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
430

Józef Kucia's avatar
Józef Kucia committed
431
	radv_get_driver_uuid(&device->driver_uuid);
432
	radv_get_device_uuid(&device->rad_info, &device->device_uuid);
433

434
	device->out_of_order_rast_allowed = device->rad_info.has_out_of_order_rast &&
435
					    !(device->instance->debug_flags & RADV_DEBUG_NO_OUT_OF_ORDER);
436

437
438
	device->dcc_msaa_allowed =
		(device->instance->perftest_flags & RADV_PERFTEST_DCC_MSAA);
439

440
441
	device->use_shader_ballot = (device->use_aco && device->rad_info.chip_class >= GFX8) ||
				    (device->instance->perftest_flags & RADV_PERFTEST_SHADER_BALLOT);
442

443
444
445
	device->use_ngg = device->rad_info.chip_class >= GFX10 &&
			  device->rad_info.family != CHIP_NAVI14 &&
			  !(device->instance->debug_flags & RADV_DEBUG_NO_NGG);
446
447
448
449
	if (device->use_aco && device->use_ngg) {
		fprintf(stderr, "WARNING: disabling NGG because ACO is used.\n");
		device->use_ngg = false;
	}
450

451
452
	device->use_ngg_streamout = false;

453
454
	/* Determine the number of threads per wave for all stages. */
	device->cs_wave_size = 64;
455
	device->ps_wave_size = 64;
456
	device->ge_wave_size = 64;
457
458
459
460

	if (device->rad_info.chip_class >= GFX10) {
		if (device->instance->perftest_flags & RADV_PERFTEST_CS_WAVE_32)
			device->cs_wave_size = 32;
461
462
463
464

		/* For pixel shaders, wave64 is recommanded. */
		if (device->instance->perftest_flags & RADV_PERFTEST_PS_WAVE_32)
			device->ps_wave_size = 32;
465
466
467

		if (device->instance->perftest_flags & RADV_PERFTEST_GE_WAVE_32)
			device->ge_wave_size = 32;
468
469
	}

470
	radv_physical_device_init_mem_types(device);
471
	radv_fill_device_extension_table(device, &device->supported_extensions);
472

473
474
475
476
477
478
479
480
481
	device->bus_info = *drm_device->businfo.pci;

	if ((device->instance->debug_flags & RADV_DEBUG_INFO))
		ac_print_gpu_info(&device->rad_info);

	/* The WSI is structured as a layer on top of the driver, so this has
	 * to be the last part of initialization (at least until we get other
	 * semi-layers).
	 */
482
483
484
	result = radv_init_wsi(device);
	if (result != VK_SUCCESS) {
		device->ws->destroy(device->ws);
485
		vk_error(instance, result);
486
487
488
		goto fail;
	}

489
490
491
492
	return VK_SUCCESS;

fail:
	close(fd);
493
494
	if (master_fd != -1)
		close(master_fd);
495
496
497
498
499
500
501
502
	return result;
}

static void
radv_physical_device_finish(struct radv_physical_device *device)
{
	radv_finish_wsi(device);
	device->ws->destroy(device->ws);
503
	disk_cache_destroy(device->disk_cache);
504
	close(device->local_fd);
505
506
	if (device->master_fd != -1)
		close(device->master_fd);
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
}

static void *
default_alloc_func(void *pUserData, size_t size, size_t align,
                   VkSystemAllocationScope allocationScope)
{
	return malloc(size);
}

static void *
default_realloc_func(void *pUserData, void *pOriginal, size_t size,
                     size_t align, VkSystemAllocationScope allocationScope)
{
	return realloc(pOriginal, size);
}

static void
default_free_func(void *pUserData, void *pMemory)
{
	free(pMemory);
}

static const VkAllocationCallbacks default_alloc = {
	.pUserData = NULL,
	.pfnAllocation = default_alloc_func,
	.pfnReallocation = default_realloc_func,
	.pfnFree = default_free_func,
};

536
static const struct debug_control radv_debug_options[] = {
537
	{"nofastclears", RADV_DEBUG_NO_FAST_CLEARS},
538
539
540
541
542
543
	{"nodcc", RADV_DEBUG_NO_DCC},
	{"shaders", RADV_DEBUG_DUMP_SHADERS},
	{"nocache", RADV_DEBUG_NO_CACHE},
	{"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS},
	{"nohiz", RADV_DEBUG_NO_HIZ},
	{"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE},
544
545
	{"allbos", RADV_DEBUG_ALL_BOS},
	{"noibs", RADV_DEBUG_NO_IBS},
546
	{"spirv", RADV_DEBUG_DUMP_SPIRV},
547
	{"vmfaults", RADV_DEBUG_VM_FAULTS},
548
	{"zerovram", RADV_DEBUG_ZERO_VRAM},
549
	{"syncshaders", RADV_DEBUG_SYNC_SHADERS},
550
	{"nosisched", RADV_DEBUG_NO_SISCHED},
551
	{"preoptir", RADV_DEBUG_PREOPTIR},
552
	{"nodynamicbounds", RADV_DEBUG_NO_DYNAMIC_BOUNDS},
553
	{"nooutoforder", RADV_DEBUG_NO_OUT_OF_ORDER},
554
	{"info", RADV_DEBUG_INFO},
555
	{"errors", RADV_DEBUG_ERRORS},
556
	{"startup", RADV_DEBUG_STARTUP},
Samuel Pitoiset's avatar
Samuel Pitoiset committed
557
	{"checkir", RADV_DEBUG_CHECKIR},
558
	{"nothreadllvm", RADV_DEBUG_NOTHREADLLVM},
559
	{"nobinning", RADV_DEBUG_NOBINNING},
560
	{"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT},
561
	{"nongg", RADV_DEBUG_NO_NGG},
562
	{"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT},
563
	{"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS},
564
	{"metashaders", RADV_DEBUG_DUMP_META_SHADERS},
565
	{"nomemorycache", RADV_DEBUG_NO_MEMORY_CACHE},
566
	{"noop", RADV_DEBUG_NOOP},
567
568
569
	{NULL, 0}
};

570
571
572
573
574
575
576
const char *
radv_get_debug_option_name(int id)
{
	assert(id < ARRAY_SIZE(radv_debug_options) - 1);
	return radv_debug_options[id].string;
}

577
static const struct debug_control radv_perftest_options[] = {
578
	{"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN},
579
	{"sisched", RADV_PERFTEST_SISCHED},
580
	{"localbos", RADV_PERFTEST_LOCAL_BOS},
581
	{"dccmsaa", RADV_PERFTEST_DCC_MSAA},
582
	{"bolist", RADV_PERFTEST_BO_LIST},
583
	{"shader_ballot", RADV_PERFTEST_SHADER_BALLOT},
584
	{"tccompatcmask", RADV_PERFTEST_TC_COMPAT_CMASK},
585
	{"cswave32", RADV_PERFTEST_CS_WAVE_32},
586
	{"pswave32", RADV_PERFTEST_PS_WAVE_32},
587
	{"gewave32", RADV_PERFTEST_GE_WAVE_32},
588
	{"dfsm", RADV_PERFTEST_DFSM},
589
	{"aco", RADV_PERFTEST_ACO},
590
591
592
	{NULL, 0}
};

593
594
595
const char *
radv_get_perftest_option_name(int id)
{
596
	assert(id < ARRAY_SIZE(radv_perftest_options) - 1);
597
598
599
	return radv_perftest_options[id].string;
}

600
601
602
603
604
605
606
607
608
609
610
static void
radv_handle_per_app_options(struct radv_instance *instance,
			    const VkApplicationInfo *info)
{
	const char *name = info ? info->pApplicationName : NULL;

	if (!name)
		return;

	if (!strcmp(name, "Talos - Linux - 32bit") ||
	    !strcmp(name, "Talos - Linux - 64bit")) {
611
612
613
614
615
616
		if (!(instance->debug_flags & RADV_DEBUG_NO_SISCHED)) {
			/* Force enable LLVM sisched for Talos because it looks
			 * safe and it gives few more FPS.
			 */
			instance->perftest_flags |= RADV_PERFTEST_SISCHED;
		}
Timothy Arceri's avatar
Timothy Arceri committed
617
618
619
	} else if (!strcmp(name, "DOOM_VFR")) {
		/* Work around a Doom VFR game bug */
		instance->debug_flags |= RADV_DEBUG_NO_DYNAMIC_BOUNDS;
620
621
622
623
624
	} else if (!strcmp(name, "MonsterHunterWorld.exe")) {
		/* Workaround for a WaW hazard when LLVM moves/merges
		 * load/store memory operations.
		 * See https://reviews.llvm.org/D61313
		 */
625
		if (LLVM_VERSION_MAJOR < 9)
626
			instance->debug_flags |= RADV_DEBUG_NO_LOAD_STORE_OPT;
627
	} else if (!strcmp(name, "Wolfenstein: Youngblood")) {
628
629
		if (!(instance->debug_flags & RADV_DEBUG_NO_SHADER_BALLOT) &&
		    !(instance->perftest_flags & RADV_PERFTEST_ACO)) {
630
631
			/* Force enable VK_AMD_shader_ballot because it looks
			 * safe and it gives a nice boost (+20% on Vega 56 at
632
			 * this time). It also prevents corruption on LLVM.
633
634
635
			 */
			instance->perftest_flags |= RADV_PERFTEST_SHADER_BALLOT;
		}
636
637
638
639
640
641
642
643
	} else if (!strcmp(name, "Fledge")) {
		/*
		 * Zero VRAM for "The Surge 2"
		 *
		 * This avoid a hang when when rendering any level. Likely
		 * uninitialized data in an indirect draw.
		 */
		instance->debug_flags |= RADV_DEBUG_ZERO_VRAM;
644
645
646
	}
}

647
648
649
650
651
652
653
654
655
static int radv_get_instance_extension_index(const char *name)
{
	for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) {
		if (strcmp(name, radv_instance_extensions[i].extensionName) == 0)
			return i;
	}
	return -1;
}

656
657
static const char radv_dri_options_xml[] =
DRI_CONF_BEGIN
658
	DRI_CONF_SECTION_PERFORMANCE
659
		DRI_CONF_ADAPTIVE_SYNC("true")
660
		DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
661
		DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
662
	DRI_CONF_SECTION_END
663
664
665
666

	DRI_CONF_SECTION_DEBUG
		DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
	DRI_CONF_SECTION_END
667
668
669
670
671
672
673
DRI_CONF_END;

static void  radv_init_dri_options(struct radv_instance *instance)
{
	driParseOptionInfo(&instance->available_dri_options, radv_dri_options_xml);
	driParseConfigFiles(&instance->dri_options,
	                    &instance->available_dri_options,
674
675
676
	                    0, "radv", NULL,
	                    instance->engineName,
	                    instance->engineVersion);
677
}
678

679
680
681
682
683
684
VkResult radv_CreateInstance(
	const VkInstanceCreateInfo*                 pCreateInfo,
	const VkAllocationCallbacks*                pAllocator,
	VkInstance*                                 pInstance)
{
	struct radv_instance *instance;
685
	VkResult result;
686
687
688
689
690
691
692
693

	assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO);

	uint32_t client_version;
	if (pCreateInfo->pApplicationInfo &&
	    pCreateInfo->pApplicationInfo->apiVersion != 0) {
		client_version = pCreateInfo->pApplicationInfo->apiVersion;
	} else {
694
		client_version = VK_API_VERSION_1_0;
695
696
	}

Lionel Landwerlin's avatar
Lionel Landwerlin committed
697
698
699
700
701
702
703
	const char *engine_name = NULL;
	uint32_t engine_version = 0;
	if (pCreateInfo->pApplicationInfo) {
		engine_name = pCreateInfo->pApplicationInfo->pEngineName;
		engine_version = pCreateInfo->pApplicationInfo->engineVersion;
	}

704
705
	instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
			      VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
706
	if (!instance)
707
		return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
708
709
710
711
712
713
714
715
716
717
718

	instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;

	if (pAllocator)
		instance->alloc = *pAllocator;
	else
		instance->alloc = default_alloc;

	instance->apiVersion = client_version;
	instance->physicalDeviceCount = -1;

719
720
721
722
723
724
	/* Get secure compile thread count. NOTE: We cap this at 32 */
#define MAX_SC_PROCS 32
	char *num_sc_threads = getenv("RADV_SECURE_COMPILE_THREADS");
	if (num_sc_threads)
		instance->num_sc_threads = MIN2(strtoul(num_sc_threads, NULL, 10), MAX_SC_PROCS);

725
726
727
	instance->debug_flags = parse_debug_string(getenv("RADV_DEBUG"),
						   radv_debug_options);

728
729
730
731
	/* Disable memory cache when secure compile is set */
	if (radv_device_use_secure_compile(instance))
		instance->debug_flags |= RADV_DEBUG_NO_MEMORY_CACHE;

732
733
734
	instance->perftest_flags = parse_debug_string(getenv("RADV_PERFTEST"),
						   radv_perftest_options);

735
736
	if (instance->perftest_flags & RADV_PERFTEST_ACO)
		fprintf(stderr, "WARNING: Experimental compiler backend enabled. Here be dragons! Incorrect rendering, GPU hangs and/or resets are likely\n");
737
738
739
740

	if (instance->debug_flags & RADV_DEBUG_STARTUP)
		radv_logi("Created an instance");

741
742
743
744
745
746
	for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
		const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
		int index = radv_get_instance_extension_index(ext_name);

		if (index < 0 || !radv_supported_instance_extensions.extensions[index]) {
			vk_free2(&default_alloc, pAllocator, instance);
747
			return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT);
748
749
750
751
752
		}

		instance->enabled_extensions.extensions[index] = true;
	}

753
754
755
	result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
	if (result != VK_SUCCESS) {
		vk_free2(&default_alloc, pAllocator, instance);
756
		return vk_error(instance, result);
757
758
	}

Lionel Landwerlin's avatar
Lionel Landwerlin committed
759
760
761
762
	instance->engineName = vk_strdup(&instance->alloc, engine_name,
					 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
	instance->engineVersion = engine_version;

763
	glsl_type_singleton_init_or_ref();
764
765
766

	VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));

767
	radv_init_dri_options(instance);
768
769
	radv_handle_per_app_options(instance, pCreateInfo->pApplicationInfo);

770
771
772
773
774
775
776
777
778
779
780
	*pInstance = radv_instance_to_handle(instance);

	return VK_SUCCESS;
}

void radv_DestroyInstance(
	VkInstance                                  _instance,
	const VkAllocationCallbacks*                pAllocator)
{
	RADV_FROM_HANDLE(radv_instance, instance, _instance);

781
782
783
	if (!instance)
		return;

784
785
	for (int i = 0; i < instance->physicalDeviceCount; ++i) {
		radv_physical_device_finish(instance->physicalDevices + i);
786
787
	}

Lionel Landwerlin's avatar
Lionel Landwerlin committed
788
789
	vk_free(&instance->alloc, instance->engineName);

790
791
	VG(VALGRIND_DESTROY_MEMPOOL(instance));

792
	glsl_type_singleton_decref();
793

794
795
796
	driDestroyOptionCache(&instance->dri_options);
	driDestroyOptionInfo(&instance->available_dri_options);

797
798
	vk_debug_report_instance_destroy(&instance->debug_report_callbacks);

799
	vk_free(&instance->alloc, instance);
800
801
}

802
803
static VkResult
radv_enumerate_devices(struct radv_instance *instance)
804
{
805
806
807
808
809
810
811
	/* TODO: Check for more devices ? */
	drmDevicePtr devices[8];
	VkResult result = VK_ERROR_INCOMPATIBLE_DRIVER;
	int max_devices;

	instance->physicalDeviceCount = 0;

812
	max_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
813
814
815
816

	if (instance->debug_flags & RADV_DEBUG_STARTUP)
		radv_logi("Found %d drm nodes", max_devices);

817
	if (max_devices < 1)
818
		return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER);
819
820
821
822

	for (unsigned i = 0; i < (unsigned)max_devices; i++) {
		if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
		    devices[i]->bustype == DRM_BUS_PCI &&
823
		    devices[i]->deviceinfo.pci->vendor_id == ATI_VENDOR_ID) {
824

825
826
			result = radv_physical_device_init(instance->physicalDevices +
			                                   instance->physicalDeviceCount,
827
			                                   instance,
828
			                                   devices[i]);
829
830
831
			if (result == VK_SUCCESS)
				++instance->physicalDeviceCount;
			else if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
832
				break;
833
834
		}
	}
835
836
	drmFreeDevices(devices, max_devices);

837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
	return result;
}

VkResult radv_EnumeratePhysicalDevices(
	VkInstance                                  _instance,
	uint32_t*                                   pPhysicalDeviceCount,
	VkPhysicalDevice*                           pPhysicalDevices)
{
	RADV_FROM_HANDLE(radv_instance, instance, _instance);
	VkResult result;

	if (instance->physicalDeviceCount < 0) {
		result = radv_enumerate_devices(instance);
		if (result != VK_SUCCESS &&
		    result != VK_ERROR_INCOMPATIBLE_DRIVER)
			return result;
	}
854
855
856
857

	if (!pPhysicalDevices) {
		*pPhysicalDeviceCount = instance->physicalDeviceCount;
	} else {
858
859
860
		*pPhysicalDeviceCount = MIN2(*pPhysicalDeviceCount, instance->physicalDeviceCount);
		for (unsigned i = 0; i < *pPhysicalDeviceCount; ++i)
			pPhysicalDevices[i] = radv_physical_device_to_handle(instance->physicalDevices + i);
861
862
	}

863
864
	return *pPhysicalDeviceCount < instance->physicalDeviceCount ? VK_INCOMPLETE
	                                                             : VK_SUCCESS;
865
866
}

867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
VkResult radv_EnumeratePhysicalDeviceGroups(
    VkInstance                                  _instance,
    uint32_t*                                   pPhysicalDeviceGroupCount,
    VkPhysicalDeviceGroupProperties*            pPhysicalDeviceGroupProperties)
{
	RADV_FROM_HANDLE(radv_instance, instance, _instance);
	VkResult result;

	if (instance->physicalDeviceCount < 0) {
		result = radv_enumerate_devices(instance);
		if (result != VK_SUCCESS &&
		    result != VK_ERROR_INCOMPATIBLE_DRIVER)
			return result;
	}

	if (!pPhysicalDeviceGroupProperties) {
		*pPhysicalDeviceGroupCount = instance->physicalDeviceCount;
	} else {
		*pPhysicalDeviceGroupCount = MIN2(*pPhysicalDeviceGroupCount, instance->physicalDeviceCount);
		for (unsigned i = 0; i < *pPhysicalDeviceGroupCount; ++i) {
			pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
			pPhysicalDeviceGroupProperties[i].physicalDevices[0] = radv_physical_device_to_handle(instance->physicalDevices + i);
			pPhysicalDeviceGroupProperties[i].subsetAllocation = false;
		}
	}
	return *pPhysicalDeviceGroupCount < instance->physicalDeviceCount ? VK_INCOMPLETE
	                                                                  : VK_SUCCESS;
}

896
897
898
899
void radv_GetPhysicalDeviceFeatures(
	VkPhysicalDevice                            physicalDevice,
	VkPhysicalDeviceFeatures*                   pFeatures)
{
900
	RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
901
902
903
904
905
906
907
	memset(pFeatures, 0, sizeof(*pFeatures));

	*pFeatures = (VkPhysicalDeviceFeatures) {
		.robustBufferAccess                       = true,
		.fullDrawIndexUint32                      = true,
		.imageCubeArray                           = true,
		.independentBlend                         = true,
908
		.geometryShader                           = true,
Bas Nieuwenhuizen's avatar
Bas Nieuwenhuizen committed
909
		.tessellationShader                       = true,
Dave Airlie's avatar
Dave Airlie committed
910
		.sampleRateShading                        = true,
911
912
913
914
915
916
917
918
919
920
921
		.dualSrcBlend                             = true,
		.logicOp                                  = true,
		.multiDrawIndirect                        = true,
		.drawIndirectFirstInstance                = true,
		.depthClamp                               = true,
		.depthBiasClamp                           = true,
		.fillModeNonSolid                         = true,
		.depthBounds                              = true,
		.wideLines                                = true,
		.largePoints                              = true,
		.alphaToOne                               = true,
922
		.multiViewport                            = true,
923
		.samplerAnisotropy                        = true,
924
		.textureCompressionETC2                   = radv_device_supports_etc(pdevice),
925
926
927
		.textureCompressionASTC_LDR               = false,
		.textureCompressionBC                     = true,
		.occlusionQueryPrecise                    = true,
928
		.pipelineStatisticsQuery                  = true,
929
930
931
		.vertexPipelineStoresAndAtomics           = true,
		.fragmentStoresAndAtomics                 = true,
		.shaderTessellationAndGeometryPointSize   = true,
932
		.shaderImageGatherExtended                = true,
933
		.shaderStorageImageExtendedFormats        = true,
934
		.shaderStorageImageMultisample            = pdevice->rad_info.chip_class >= GFX8,
935
936
937
938
		.shaderUniformBufferArrayDynamicIndexing  = true,
		.shaderSampledImageArrayDynamicIndexing   = true,
		.shaderStorageBufferArrayDynamicIndexing  = true,
		.shaderStorageImageArrayDynamicIndexing   = true,
939
		.shaderStorageImageReadWithoutFormat      = true,
940
		.shaderStorageImageWriteWithoutFormat     = true,
941
942
		.shaderClipDistance                       = true,
		.shaderCullDistance                       = true,
943
		.shaderFloat64                            = true,
944
		.shaderInt64                              = true,
945
		.shaderInt16                              = pdevice->rad_info.chip_class >= GFX9 && !pdevice->use_aco,
946
		.sparseBinding                            = true,
947
		.variableMultisampleRate                  = true,
948
		.inheritedQueries                         = true,
949
950
951
	};
}

952
void radv_GetPhysicalDeviceFeatures2(
953
	VkPhysicalDevice                            physicalDevice,
954
	VkPhysicalDeviceFeatures2                  *pFeatures)
955
{
956
	RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
957
958
	vk_foreach_struct(ext, pFeatures->pNext) {
		switch (ext->sType) {
959
960
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES: {
			VkPhysicalDeviceVariablePointersFeatures *features = (void *)ext;
961
			features->variablePointersStorageBuffer = true;
962
			features->variablePointers = true;
963
964
			break;
		}
965
966
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES: {
			VkPhysicalDeviceMultiviewFeatures *features = (VkPhysicalDeviceMultiviewFeatures*)ext;
967
968
969
970
971
			features->multiview = true;
			features->multiviewGeometryShader = true;
			features->multiviewTessellationShader = true;
			break;
		}
972
973
974
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DRAW_PARAMETERS_FEATURES: {
			VkPhysicalDeviceShaderDrawParametersFeatures *features =
			    (VkPhysicalDeviceShaderDrawParametersFeatures*)ext;
975
976
977
			features->shaderDrawParameters = true;
			break;
		}
978
979
980
981
982
983
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES: {
			VkPhysicalDeviceProtectedMemoryFeatures *features =
			    (VkPhysicalDeviceProtectedMemoryFeatures*)ext;
			features->protectedMemory = false;
			break;
		}
984
985
986
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES: {
			VkPhysicalDevice16BitStorageFeatures *features =
			    (VkPhysicalDevice16BitStorageFeatures*)ext;
987
			bool enabled = pdevice->rad_info.chip_class >= GFX8 && !pdevice->use_aco;
988
989
990
			features->storageBuffer16BitAccess = enabled;
			features->uniformAndStorageBuffer16BitAccess = enabled;
			features->storagePushConstant16 = enabled;
991
			features->storageInputOutput16 = enabled && LLVM_VERSION_MAJOR >= 9;
992
993
			break;
		}
994
995
996
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
			VkPhysicalDeviceSamplerYcbcrConversionFeatures *features =
			    (VkPhysicalDeviceSamplerYcbcrConversionFeatures*)ext;
997
			features->samplerYcbcrConversion = true;
998
999
			break;
		}
1000
1001
1002
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES: {
			VkPhysicalDeviceDescriptorIndexingFeatures *features =
				(VkPhysicalDeviceDescriptorIndexingFeatures*)ext;
1003
1004
1005
			features->shaderInputAttachmentArrayDynamicIndexing = true;
			features->shaderUniformTexelBufferArrayDynamicIndexing = true;
			features->shaderStorageTexelBufferArrayDynamicIndexing = true;
1006
1007
1008
1009
1010
1011
1012
			features->shaderUniformBufferArrayNonUniformIndexing = true;
			features->shaderSampledImageArrayNonUniformIndexing = true;
			features->shaderStorageBufferArrayNonUniformIndexing = true;
			features->shaderStorageImageArrayNonUniformIndexing = true;
			features->shaderInputAttachmentArrayNonUniformIndexing = true;
			features->shaderUniformTexelBufferArrayNonUniformIndexing = true;
			features->shaderStorageTexelBufferArrayNonUniformIndexing = true;
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
			features->descriptorBindingUniformBufferUpdateAfterBind = true;
			features->descriptorBindingSampledImageUpdateAfterBind = true;
			features->descriptorBindingStorageImageUpdateAfterBind = true;
			features->descriptorBindingStorageBufferUpdateAfterBind = true;
			features->descriptorBindingUniformTexelBufferUpdateAfterBind = true;
			features->descriptorBindingStorageTexelBufferUpdateAfterBind = true;
			features->descriptorBindingUpdateUnusedWhilePending = true;
			features->descriptorBindingPartiallyBound = true;
			features->descriptorBindingVariableDescriptorCount = true;
			features->runtimeDescriptorArray = true;
			break;
		}
1025
1026
1027
1028
1029
1030
1031
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT: {
			VkPhysicalDeviceConditionalRenderingFeaturesEXT *features =
				(VkPhysicalDeviceConditionalRenderingFeaturesEXT*)ext;
			features->conditionalRendering = true;
			features->inheritedConditionalRendering = false;
			break;
		}
1032
1033
1034
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_FEATURES_EXT: {
			VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *features =
				(VkPhysicalDeviceVertexAttributeDivisorFeaturesEXT *)ext;
1035
1036
			features->vertexAttributeInstanceRateDivisor = true;
			features->vertexAttributeInstanceRateZeroDivisor = true;
1037
1038
			break;
		}
1039
1040
1041
1042
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT: {
			VkPhysicalDeviceTransformFeedbackFeaturesEXT *features =
				(VkPhysicalDeviceTransformFeedbackFeaturesEXT*)ext;
			features->transformFeedback = true;
1043
			features->geometryStreams = !pdevice->use_ngg_streamout;
1044
1045
			break;
		}
1046
1047
1048
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES: {
			VkPhysicalDeviceScalarBlockLayoutFeatures *features =
				(VkPhysicalDeviceScalarBlockLayoutFeatures *)ext;
1049
			features->scalarBlockLayout = pdevice->rad_info.chip_class >= GFX7;
1050
1051
			break;
		}
1052
1053
1054
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT: {
			VkPhysicalDeviceMemoryPriorityFeaturesEXT *features =
				(VkPhysicalDeviceMemoryPriorityFeaturesEXT *)ext;
1055
			features->memoryPriority = true;
1056
1057
			break;
		}
1058
1059
1060
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT: {
			VkPhysicalDeviceBufferDeviceAddressFeaturesEXT *features =
				(VkPhysicalDeviceBufferDeviceAddressFeaturesEXT *)ext;
1061
1062
1063
1064
1065
			features->bufferDeviceAddress = true;
			features->bufferDeviceAddressCaptureReplay = false;
			features->bufferDeviceAddressMultiDevice = false;
			break;
		}
1066
1067
1068
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES: {
			VkPhysicalDeviceBufferDeviceAddressFeatures *features =
				(VkPhysicalDeviceBufferDeviceAddressFeatures *)ext;
1069
1070
1071
1072
1073
			features->bufferDeviceAddress = true;
			features->bufferDeviceAddressCaptureReplay = false;
			features->bufferDeviceAddressMultiDevice = false;
			break;
		}
1074
1075
1076
1077
1078
1079
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: {
			VkPhysicalDeviceDepthClipEnableFeaturesEXT *features =
				(VkPhysicalDeviceDepthClipEnableFeaturesEXT *)ext;
			features->depthClipEnable = true;
			break;
		}
1080
1081
1082
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES: {
			VkPhysicalDeviceHostQueryResetFeatures *features =
				(VkPhysicalDeviceHostQueryResetFeatures *)ext;
1083
1084
1085
			features->hostQueryReset = true;
			break;
		}
1086
1087
1088
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES: {
			VkPhysicalDevice8BitStorageFeatures *features =
			    (VkPhysicalDevice8BitStorageFeatures *)ext;
1089
			bool enabled = pdevice->rad_info.chip_class >= GFX8 && !pdevice->use_aco;
Rhys Perry's avatar
Rhys Perry committed
1090
1091
1092
1093
1094
			features->storageBuffer8BitAccess = enabled;
			features->uniformAndStorageBuffer8BitAccess = enabled;
			features->storagePushConstant8 = enabled;
			break;
		}
1095
1096
1097
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES: {
			VkPhysicalDeviceShaderFloat16Int8Features *features =
				(VkPhysicalDeviceShaderFloat16Int8Features*)ext;
1098
1099
			features->shaderFloat16 = pdevice->rad_info.chip_class >= GFX8 && !pdevice->use_aco;
			features->shaderInt8 = !pdevice->use_aco;
1100
1101
			break;
		}
1102
1103
1104
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES: {
			VkPhysicalDeviceShaderAtomicInt64Features *features =
				(VkPhysicalDeviceShaderAtomicInt64Features *)ext;
1105
1106
			features->shaderBufferInt64Atomics = LLVM_VERSION_MAJOR >= 9;
			features->shaderSharedInt64Atomics = LLVM_VERSION_MAJOR >= 9;
1107
1108
			break;
		}
1109
1110
1111
1112
1113
1114
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT: {
			VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT *features =
				(VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT *)ext;
			features->shaderDemoteToHelperInvocation = pdevice->use_aco;
			break;
		}
1115
1116
1117
1118
1119
1120
1121
1122
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
			VkPhysicalDeviceInlineUniformBlockFeaturesEXT *features =
				(VkPhysicalDeviceInlineUniformBlockFeaturesEXT *)ext;

			features->inlineUniformBlock = true;
			features->descriptorBindingInlineUniformBlockUpdateAfterBind = true;
			break;
		}
1123
1124
1125
1126
1127
1128
1129
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: {
			VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features =
				(VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext;
			features->computeDerivativeGroupQuads = false;
			features->computeDerivativeGroupLinear = true;
			break;
		}
1130
1131
1132
1133
1134
1135
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT: {
			VkPhysicalDeviceYcbcrImageArraysFeaturesEXT *features =
				(VkPhysicalDeviceYcbcrImageArraysFeaturesEXT*)ext;
			features->ycbcrImageArrays = true;
			break;
		}
1136
1137
1138
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES: {
			VkPhysicalDeviceUniformBufferStandardLayoutFeatures *features =
				(VkPhysicalDeviceUniformBufferStandardLayoutFeatures *)ext;
1139
1140
1141
			features->uniformBufferStandardLayout = true;
			break;
		}
1142
1143
1144
1145
1146
1147
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT: {
			VkPhysicalDeviceIndexTypeUint8FeaturesEXT *features =
				(VkPhysicalDeviceIndexTypeUint8FeaturesEXT *)ext;
			features->indexTypeUint8 = pdevice->rad_info.chip_class >= GFX8;
			break;
		}
1148
1149
1150
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES: {
			VkPhysicalDeviceImagelessFramebufferFeatures *features =
				(VkPhysicalDeviceImagelessFramebufferFeatures *)ext;
1151
1152
1153
			features->imagelessFramebuffer = true;
			break;
		}
1154
1155
1156
1157
1158
1159
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR: {
			VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *features =
				(VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR *)ext;
			features->pipelineExecutableInfo = true;
			break;
		}
1160
1161
1162
1163
1164
1165
1166
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CLOCK_FEATURES_KHR: {
			VkPhysicalDeviceShaderClockFeaturesKHR *features =
				(VkPhysicalDeviceShaderClockFeaturesKHR *)ext;
			features->shaderSubgroupClock = true;
			features->shaderDeviceClock = false;
			break;
		}
1167
1168
1169
1170
1171
1172
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TEXEL_BUFFER_ALIGNMENT_FEATURES_EXT: {
			VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT *features =
				(VkPhysicalDeviceTexelBufferAlignmentFeaturesEXT *)ext;
			features->texelBufferAlignment = true;
			break;
		}
1173
1174
1175
		case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES: {
			VkPhysicalDeviceTimelineSemaphoreFeatures *features =
				(VkPhysicalDeviceTimelineSemaphoreFeatures *) ext;
1176
1177
1178
			features->timelineSemaphore = true;
			break;
		}
1179
1180
1181
1182