-
Notifications
You must be signed in to change notification settings - Fork 206
/
device.c
9353 lines (7847 loc) · 403 KB
/
device.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
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
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2016 Józef Kucia for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define VKD3D_DBG_CHANNEL VKD3D_DBG_CHANNEL_API
#include "vkd3d_private.h"
#include "vkd3d_sonames.h"
#include "vkd3d_descriptor_debug.h"
#include "vkd3d_platform.h"
#ifdef VKD3D_ENABLE_RENDERDOC
#include "vkd3d_renderdoc.h"
#endif
static uint32_t vkd3d_get_vk_version(void)
{
int major, minor, patch;
vkd3d_parse_version(PACKAGE_VERSION, &major, &minor, &patch);
INFO("vkd3d-proton - applicationVersion: %d.%d.%d.\n", major, minor, patch);
return VK_MAKE_VERSION(major, minor, patch);
}
struct vkd3d_optional_extension_info
{
const char *extension_name;
ptrdiff_t vulkan_info_offset;
uint64_t enable_config_flags;
uint64_t disable_config_flags;
uint32_t minimum_spec_version;
};
#define VK_EXTENSION(name, member) \
{VK_ ## name ## _EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, member), 0, 0}
#define VK_EXTENSION_COND(name, member, required_flags) \
{VK_ ## name ## _EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, member), required_flags, 0}
#define VK_EXTENSION_DISABLE_COND(name, member, disable_flags) \
{VK_ ## name ## _EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, member), 0, disable_flags, 0}
#define VK_EXTENSION_VERSION(name, member, spec_version) \
{VK_ ## name ## _EXTENSION_NAME, offsetof(struct vkd3d_vulkan_info, member), 0, 0, spec_version}
static const struct vkd3d_optional_extension_info optional_instance_extensions[] =
{
/* EXT extensions */
VK_EXTENSION_COND(EXT_DEBUG_UTILS, EXT_debug_utils, VKD3D_CONFIG_FLAG_DEBUG_UTILS | VKD3D_CONFIG_FLAG_FAULT),
};
static const struct vkd3d_optional_extension_info optional_device_extensions[] =
{
/* KHR extensions */
VK_EXTENSION(KHR_PUSH_DESCRIPTOR, KHR_push_descriptor),
VK_EXTENSION(KHR_PIPELINE_LIBRARY, KHR_pipeline_library),
VK_EXTENSION_DISABLE_COND(KHR_RAY_TRACING_PIPELINE, KHR_ray_tracing_pipeline, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION_DISABLE_COND(KHR_ACCELERATION_STRUCTURE, KHR_acceleration_structure, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION_DISABLE_COND(KHR_DEFERRED_HOST_OPERATIONS, KHR_deferred_host_operations, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION_DISABLE_COND(KHR_RAY_QUERY, KHR_ray_query, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION_DISABLE_COND(KHR_RAY_TRACING_MAINTENANCE_1, KHR_ray_tracing_maintenance1, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION(KHR_FRAGMENT_SHADING_RATE, KHR_fragment_shading_rate),
VK_EXTENSION(KHR_FRAGMENT_SHADER_BARYCENTRIC, KHR_fragment_shader_barycentric),
VK_EXTENSION(KHR_PRESENT_ID, KHR_present_id),
VK_EXTENSION(KHR_PRESENT_WAIT, KHR_present_wait),
VK_EXTENSION(KHR_MAINTENANCE_5, KHR_maintenance5),
VK_EXTENSION(KHR_MAINTENANCE_6, KHR_maintenance6),
VK_EXTENSION(KHR_SHADER_MAXIMAL_RECONVERGENCE, KHR_shader_maximal_reconvergence),
VK_EXTENSION(KHR_SHADER_QUAD_CONTROL, KHR_shader_quad_control),
#ifdef _WIN32
VK_EXTENSION(KHR_EXTERNAL_MEMORY_WIN32, KHR_external_memory_win32),
VK_EXTENSION(KHR_EXTERNAL_SEMAPHORE_WIN32, KHR_external_semaphore_win32),
#endif
/* EXT extensions */
VK_EXTENSION(EXT_CALIBRATED_TIMESTAMPS, EXT_calibrated_timestamps),
VK_EXTENSION(EXT_CONDITIONAL_RENDERING, EXT_conditional_rendering),
VK_EXTENSION(EXT_CONSERVATIVE_RASTERIZATION, EXT_conservative_rasterization),
VK_EXTENSION(EXT_CUSTOM_BORDER_COLOR, EXT_custom_border_color),
VK_EXTENSION(EXT_DEPTH_CLIP_ENABLE, EXT_depth_clip_enable),
VK_EXTENSION(EXT_IMAGE_VIEW_MIN_LOD, EXT_image_view_min_lod),
VK_EXTENSION(EXT_ROBUSTNESS_2, EXT_robustness2),
VK_EXTENSION(EXT_SHADER_STENCIL_EXPORT, EXT_shader_stencil_export),
VK_EXTENSION(EXT_TRANSFORM_FEEDBACK, EXT_transform_feedback),
VK_EXTENSION(EXT_VERTEX_ATTRIBUTE_DIVISOR, EXT_vertex_attribute_divisor),
VK_EXTENSION(EXT_EXTENDED_DYNAMIC_STATE_2, EXT_extended_dynamic_state2),
VK_EXTENSION(EXT_EXTENDED_DYNAMIC_STATE_3, EXT_extended_dynamic_state3),
VK_EXTENSION(EXT_EXTERNAL_MEMORY_HOST, EXT_external_memory_host),
VK_EXTENSION(EXT_SHADER_IMAGE_ATOMIC_INT64, EXT_shader_image_atomic_int64),
VK_EXTENSION(EXT_MESH_SHADER, EXT_mesh_shader),
VK_EXTENSION(EXT_MUTABLE_DESCRIPTOR_TYPE, EXT_mutable_descriptor_type),
VK_EXTENSION(EXT_HDR_METADATA, EXT_hdr_metadata),
VK_EXTENSION(EXT_SHADER_MODULE_IDENTIFIER, EXT_shader_module_identifier),
VK_EXTENSION(EXT_DESCRIPTOR_BUFFER, EXT_descriptor_buffer),
VK_EXTENSION_DISABLE_COND(EXT_PIPELINE_LIBRARY_GROUP_HANDLES, EXT_pipeline_library_group_handles, VKD3D_CONFIG_FLAG_NO_DXR),
VK_EXTENSION(EXT_IMAGE_SLICED_VIEW_OF_3D, EXT_image_sliced_view_of_3d),
VK_EXTENSION(EXT_GRAPHICS_PIPELINE_LIBRARY, EXT_graphics_pipeline_library),
VK_EXTENSION(EXT_FRAGMENT_SHADER_INTERLOCK, EXT_fragment_shader_interlock),
VK_EXTENSION(EXT_PAGEABLE_DEVICE_LOCAL_MEMORY, EXT_pageable_device_local_memory),
VK_EXTENSION(EXT_MEMORY_PRIORITY, EXT_memory_priority),
VK_EXTENSION(EXT_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS, EXT_dynamic_rendering_unused_attachments),
VK_EXTENSION(EXT_LINE_RASTERIZATION, EXT_line_rasterization),
VK_EXTENSION(EXT_IMAGE_COMPRESSION_CONTROL, EXT_image_compression_control),
VK_EXTENSION_COND(EXT_DEVICE_FAULT, EXT_device_fault, VKD3D_CONFIG_FLAG_FAULT),
VK_EXTENSION(EXT_MEMORY_BUDGET, EXT_memory_budget),
VK_EXTENSION_COND(EXT_DEVICE_ADDRESS_BINDING_REPORT, EXT_device_address_binding_report, VKD3D_CONFIG_FLAG_FAULT),
/* AMD extensions */
VK_EXTENSION(AMD_BUFFER_MARKER, AMD_buffer_marker),
VK_EXTENSION(AMD_DEVICE_COHERENT_MEMORY, AMD_device_coherent_memory),
VK_EXTENSION(AMD_SHADER_CORE_PROPERTIES, AMD_shader_core_properties),
VK_EXTENSION(AMD_SHADER_CORE_PROPERTIES_2, AMD_shader_core_properties2),
/* NV extensions */
VK_EXTENSION(NV_SHADER_SM_BUILTINS, NV_shader_sm_builtins),
VK_EXTENSION(NVX_BINARY_IMPORT, NVX_binary_import),
VK_EXTENSION(NVX_IMAGE_VIEW_HANDLE, NVX_image_view_handle),
VK_EXTENSION(NV_FRAGMENT_SHADER_BARYCENTRIC, NV_fragment_shader_barycentric),
VK_EXTENSION(NV_COMPUTE_SHADER_DERIVATIVES, NV_compute_shader_derivatives),
VK_EXTENSION_COND(NV_DEVICE_DIAGNOSTIC_CHECKPOINTS, NV_device_diagnostic_checkpoints, VKD3D_CONFIG_FLAG_BREADCRUMBS | VKD3D_CONFIG_FLAG_BREADCRUMBS_TRACE),
VK_EXTENSION(NV_DEVICE_GENERATED_COMMANDS, NV_device_generated_commands),
VK_EXTENSION(NV_SHADER_SUBGROUP_PARTITIONED, NV_shader_subgroup_partitioned),
VK_EXTENSION(NV_MEMORY_DECOMPRESSION, NV_memory_decompression),
VK_EXTENSION(NV_DEVICE_GENERATED_COMMANDS_COMPUTE, NV_device_generated_commands_compute),
VK_EXTENSION_VERSION(NV_LOW_LATENCY_2, NV_low_latency2, 2),
VK_EXTENSION(NV_RAW_ACCESS_CHAINS, NV_raw_access_chains),
/* VALVE extensions */
VK_EXTENSION(VALVE_MUTABLE_DESCRIPTOR_TYPE, VALVE_mutable_descriptor_type),
VK_EXTENSION(VALVE_DESCRIPTOR_SET_HOST_MAPPING, VALVE_descriptor_set_host_mapping),
/* MESA extensions */
VK_EXTENSION(MESA_IMAGE_ALIGNMENT_CONTROL, MESA_image_alignment_control),
};
static const struct vkd3d_optional_extension_info optional_extensions_user[] =
{
VK_EXTENSION(EXT_SURFACE_MAINTENANCE_1, EXT_surface_maintenance1),
VK_EXTENSION(EXT_SWAPCHAIN_MAINTENANCE_1, EXT_swapchain_maintenance1),
};
static unsigned int get_spec_version(const VkExtensionProperties *extensions,
unsigned int count, const char *extension_name)
{
unsigned int i;
for (i = 0; i < count; ++i)
{
if (!strcmp(extensions[i].extensionName, extension_name))
return extensions[i].specVersion;
}
return 0;
}
static bool is_extension_disabled(const char *extension_name)
{
char disabled_extensions[VKD3D_PATH_MAX];
if (!vkd3d_get_env_var("VKD3D_DISABLE_EXTENSIONS", disabled_extensions, sizeof(disabled_extensions)))
return false;
return vkd3d_debug_list_has_member(disabled_extensions, extension_name);
}
static bool has_extension(const VkExtensionProperties *extensions,
unsigned int count, const char *extension_name, uint32_t minimum_spec_version)
{
unsigned int i;
for (i = 0; i < count; ++i)
{
if (is_extension_disabled(extension_name))
{
WARN("Extension %s is disabled.\n", debugstr_a(extension_name));
continue;
}
if (!strcmp(extensions[i].extensionName, extension_name) &&
(extensions[i].specVersion >= minimum_spec_version))
return true;
}
return false;
}
static unsigned int vkd3d_check_extensions(const VkExtensionProperties *extensions, unsigned int count,
const char * const *required_extensions, unsigned int required_extension_count,
const struct vkd3d_optional_extension_info *optional_extensions, unsigned int optional_extension_count,
const char * const *user_extensions, unsigned int user_extension_count,
const char * const *optional_user_extensions, unsigned int optional_user_extension_count,
bool *user_extension_supported, struct vkd3d_vulkan_info *vulkan_info, const char *extension_type)
{
unsigned int extension_count = 0;
unsigned int i;
for (i = 0; i < required_extension_count; ++i)
{
if (!has_extension(extensions, count, required_extensions[i], 0))
ERR("Required %s extension %s is not supported.\n",
extension_type, debugstr_a(required_extensions[i]));
++extension_count;
}
for (i = 0; i < optional_extension_count; ++i)
{
uint64_t disable_flags = optional_extensions[i].disable_config_flags;
const char *extension_name = optional_extensions[i].extension_name;
uint64_t enable_flags = optional_extensions[i].enable_config_flags;
uint32_t minimum_spec_version = optional_extensions[i].minimum_spec_version;
ptrdiff_t offset = optional_extensions[i].vulkan_info_offset;
bool *supported = (void *)((uintptr_t)vulkan_info + offset);
if (enable_flags && !(vkd3d_config_flags & enable_flags))
continue;
if (disable_flags && (vkd3d_config_flags & disable_flags))
continue;
if ((*supported = has_extension(extensions, count, extension_name, minimum_spec_version)))
{
TRACE("Found %s extension.\n", debugstr_a(extension_name));
++extension_count;
}
}
for (i = 0; i < user_extension_count; ++i)
{
if (!has_extension(extensions, count, user_extensions[i], 0))
ERR("Required user %s extension %s is not supported.\n",
extension_type, debugstr_a(user_extensions[i]));
++extension_count;
}
assert(!optional_user_extension_count || user_extension_supported);
for (i = 0; i < optional_user_extension_count; ++i)
{
if (has_extension(extensions, count, optional_user_extensions[i], 0))
{
user_extension_supported[i] = true;
++extension_count;
}
else
{
user_extension_supported[i] = false;
WARN("Optional user %s extension %s is not supported.\n",
extension_type, debugstr_a(optional_user_extensions[i]));
}
}
return extension_count;
}
static unsigned int vkd3d_append_extension(const char *extensions[],
unsigned int extension_count, const char *extension_name)
{
unsigned int i;
/* avoid duplicates */
for (i = 0; i < extension_count; ++i)
{
if (!strcmp(extensions[i], extension_name))
return extension_count;
}
extensions[extension_count++] = extension_name;
return extension_count;
}
static void vkd3d_mark_enabled_user_extensions(struct vkd3d_vulkan_info *vulkan_info,
const char * const *optional_user_extensions,
unsigned int optional_user_extension_count,
const bool *user_extension_supported)
{
unsigned int i, j;
for (i = 0; i < optional_user_extension_count; ++i)
{
if (!user_extension_supported[i])
continue;
/* Mark these external extensions as supported if outer code explicitly requested them,
* otherwise, ignore. */
for (j = 0; j < ARRAY_SIZE(optional_extensions_user); j++)
{
if (!strcmp(optional_extensions_user[j].extension_name, optional_user_extensions[i]))
{
ptrdiff_t offset = optional_extensions_user[j].vulkan_info_offset;
bool *supported = (void *)((uintptr_t)vulkan_info + offset);
*supported = true;
break;
}
}
}
}
static unsigned int vkd3d_enable_extensions(const char *extensions[],
const char * const *required_extensions, unsigned int required_extension_count,
const struct vkd3d_optional_extension_info *optional_extensions, unsigned int optional_extension_count,
const char * const *user_extensions, unsigned int user_extension_count,
const char * const *optional_user_extensions, unsigned int optional_user_extension_count,
const bool *user_extension_supported, const struct vkd3d_vulkan_info *vulkan_info)
{
unsigned int extension_count = 0;
unsigned int i;
for (i = 0; i < required_extension_count; ++i)
{
extensions[extension_count++] = required_extensions[i];
}
for (i = 0; i < optional_extension_count; ++i)
{
ptrdiff_t offset = optional_extensions[i].vulkan_info_offset;
const bool *supported = (void *)((uintptr_t)vulkan_info + offset);
if (*supported)
extensions[extension_count++] = optional_extensions[i].extension_name;
}
for (i = 0; i < user_extension_count; ++i)
{
extension_count = vkd3d_append_extension(extensions, extension_count, user_extensions[i]);
}
assert(!optional_user_extension_count || user_extension_supported);
for (i = 0; i < optional_user_extension_count; ++i)
{
if (!user_extension_supported[i])
continue;
extension_count = vkd3d_append_extension(extensions, extension_count, optional_user_extensions[i]);
}
return extension_count;
}
static bool vkd3d_remove_extension(const char *to_remove, const char *extensions[], uint32_t *extension_count)
{
uint32_t i;
for (i = 0; i < *extension_count; i++)
{
if (strcmp(to_remove, extensions[i]) != 0)
continue;
WARN("Removing %s extension from the array.\n", to_remove);
if (i < (*extension_count - 1))
extensions[i] = extensions[*extension_count - 1];
(*extension_count)--;
return true;
}
return false;
}
static bool vkd3d_disable_nvx_extensions(struct d3d12_device *device, const char *extensions[], uint32_t *enabled_extension_count)
{
struct vkd3d_vulkan_info *vk_info = &device->vk_info;
bool disabled = false;
unsigned int i;
static const struct vkd3d_optional_extension_info nvx_extensions[] =
{
VK_EXTENSION(NVX_BINARY_IMPORT, NVX_binary_import),
VK_EXTENSION(NVX_IMAGE_VIEW_HANDLE, NVX_image_view_handle),
};
for (i = 0; i < ARRAY_SIZE(nvx_extensions); ++i)
{
const char *extension_name = nvx_extensions[i].extension_name;
bool *supported = (void *)((uintptr_t)vk_info + nvx_extensions[i].vulkan_info_offset);
if (vkd3d_remove_extension(extension_name, extensions, enabled_extension_count))
{
*supported = false;
disabled = true;
}
}
return disabled;
}
static HRESULT vkd3d_init_instance_caps(struct vkd3d_instance *instance,
const struct vkd3d_instance_create_info *create_info,
uint32_t *instance_extension_count, bool *user_extension_supported)
{
const struct vkd3d_vk_global_procs *vk_procs = &instance->vk_global_procs;
struct vkd3d_vulkan_info *vulkan_info = &instance->vk_info;
VkExtensionProperties *vk_extensions;
uint32_t count;
VkResult vr;
memset(vulkan_info, 0, sizeof(*vulkan_info));
*instance_extension_count = 0;
if ((vr = vk_procs->vkEnumerateInstanceExtensionProperties(NULL, &count, NULL)) < 0)
{
ERR("Failed to enumerate instance extensions, vr %d.\n", vr);
return hresult_from_vk_result(vr);
}
if (!count)
return S_OK;
if (!(vk_extensions = vkd3d_calloc(count, sizeof(*vk_extensions))))
return E_OUTOFMEMORY;
TRACE("Enumerating %u instance extensions.\n", count);
if ((vr = vk_procs->vkEnumerateInstanceExtensionProperties(NULL, &count, vk_extensions)) < 0)
{
ERR("Failed to enumerate instance extensions, vr %d.\n", vr);
vkd3d_free(vk_extensions);
return hresult_from_vk_result(vr);
}
*instance_extension_count = vkd3d_check_extensions(vk_extensions, count, NULL, 0,
optional_instance_extensions, ARRAY_SIZE(optional_instance_extensions),
create_info->instance_extensions,
create_info->instance_extension_count,
create_info->optional_instance_extensions,
create_info->optional_instance_extension_count,
user_extension_supported, vulkan_info, "instance");
vkd3d_free(vk_extensions);
return S_OK;
}
static HRESULT vkd3d_init_vk_global_procs(struct vkd3d_instance *instance,
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr)
{
if (!vkGetInstanceProcAddr)
return E_INVALIDARG;
return vkd3d_load_vk_global_procs(&instance->vk_global_procs, vkGetInstanceProcAddr);
}
static VkBool32 VKAPI_PTR vkd3d_debug_messenger_callback(
VkDebugUtilsMessageSeverityFlagBitsEXT message_severity,
VkDebugUtilsMessageTypeFlagsEXT message_types,
const VkDebugUtilsMessengerCallbackDataEXT *callback_data,
void *userdata)
{
/* Avoid some useless validation warnings which don't contribute much.
* - Map memory, likely validation layer bug due to memory alloc flags.
* - Pipeline layout limits on NV which are not relevant here.
* - SPV_EXT_buffer_device_address shenanigans (need to fix glslang).
* - Sample count mismatch in fallback copy shaders.
* - Threading error in WaitPresentKHR (false positive).
*/
unsigned int i;
static const uint32_t ignored_ids[] = {
0xc05b3a9du,
0x2864340eu,
0xbfcfaec2u,
0x96f03c1cu,
0x8189c842u,
0x3d492883u,
0x1608dec0u,
0x141cb623u,
};
for (i = 0; i < ARRAY_SIZE(ignored_ids); i++)
if ((uint32_t)callback_data->messageIdNumber == ignored_ids[i])
return VK_FALSE;
if (message_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
ERR("%s\n", callback_data->pMessage);
else if (message_severity & VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT)
WARN("%s\n", callback_data->pMessage);
(void)userdata;
(void)message_types;
return VK_FALSE;
}
static void vkd3d_init_debug_messenger_callback(struct vkd3d_instance *instance)
{
const struct vkd3d_vk_instance_procs *vk_procs = &instance->vk_procs;
VkDebugUtilsMessengerCreateInfoEXT callback_info;
VkInstance vk_instance = instance->vk_instance;
VkDebugUtilsMessengerEXT callback;
VkResult vr;
callback_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
callback_info.pNext = NULL;
callback_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
callback_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT;
callback_info.pfnUserCallback = vkd3d_debug_messenger_callback;
callback_info.pUserData = NULL;
callback_info.flags = 0;
if ((vr = VK_CALL(vkCreateDebugUtilsMessengerEXT(vk_instance, &callback_info, NULL, &callback)) < 0))
{
WARN("Failed to create debug report callback, vr %d.\n", vr);
return;
}
instance->vk_debug_callback = callback;
}
/* Could be a flag style enum if needed. */
enum vkd3d_application_feature_override
{
VKD3D_APPLICATION_FEATURE_OVERRIDE_NONE = 0,
VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE,
VKD3D_APPLICATION_FEATURE_NO_DEFAULT_DXR_ON_DECK,
VKD3D_APPLICATION_FEATURE_LIMIT_DXR_1_0,
};
static enum vkd3d_application_feature_override vkd3d_application_feature_override;
uint64_t vkd3d_config_flags;
struct vkd3d_shader_quirk_info vkd3d_shader_quirk_info;
struct vkd3d_instance_application_meta
{
enum vkd3d_string_compare_mode mode;
const char *name;
uint64_t global_flags_add;
uint64_t global_flags_remove;
enum vkd3d_application_feature_override override;
};
static const struct vkd3d_instance_application_meta application_override[] = {
/* MSVC fails to compile empty array. */
{ VKD3D_STRING_COMPARE_EXACT, "GravityMark.exe", VKD3D_CONFIG_FLAG_FORCE_MINIMUM_SUBGROUP_SIZE, 0 },
/* Halo Infinite (1240440).
* Game relies on NON_ZEROED committed UAVs to be cleared to zero on allocation.
* This works okay with zerovram on first game boot, but not later, since this memory is guaranteed to be recycled.
* Game also relies on indirectly modifying CBV root descriptors, which means we are forced to rely on RAW_VA_CBV.
* It also relies on multi-dispatch indirect with state updates which is ... ye.
* Need another config flag to workaround that as well.
* Poor loading times and performance with ReBar on some devices.
*/
{ VKD3D_STRING_COMPARE_EXACT, "HaloInfinite.exe",
VKD3D_CONFIG_FLAG_ZERO_MEMORY_WORKAROUNDS_COMMITTED_BUFFER_UAV | VKD3D_CONFIG_FLAG_FORCE_RAW_VA_CBV |
VKD3D_CONFIG_FLAG_USE_HOST_IMPORT_FALLBACK | VKD3D_CONFIG_FLAG_PREALLOCATE_SRV_MIP_CLAMPS |
VKD3D_CONFIG_FLAG_REQUIRES_COMPUTE_INDIRECT_TEMPLATES | VKD3D_CONFIG_FLAG_NO_UPLOAD_HVV |
VKD3D_CONFIG_FLAG_DISABLE_NV_DGCC, 0 },
/* (1182900) Workaround amdgpu kernel bug with host memory import and concurrent submissions. */
{ VKD3D_STRING_COMPARE_EXACT, "APlagueTaleRequiem_x64.exe",
VKD3D_CONFIG_FLAG_USE_HOST_IMPORT_FALLBACK | VKD3D_CONFIG_FLAG_DISABLE_UAV_COMPRESSION, 0 },
/* Shadow of the Tomb Raider (750920).
* Invariant workarounds actually cause more issues than they resolve on NV.
* RADV already has workarounds by default.
* FIXME: The proper workaround will be a workaround which force-emits mul + add + precise. The vertex shaders
* are broken enough that normal invariance is not enough. */
{ VKD3D_STRING_COMPARE_EXACT, "SOTTR.exe", VKD3D_CONFIG_FLAG_FORCE_NO_INVARIANT_POSITION, 0 },
/* Elden Ring (1245620).
* Game is really churny on committed memory allocations, and does not use NOT_ZEROED. Clearing works causes bubbles.
* It seems to work just fine however to skip the clears. */
{ VKD3D_STRING_COMPARE_EXACT, "eldenring.exe",
VKD3D_CONFIG_FLAG_MEMORY_ALLOCATOR_SKIP_CLEAR | VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_MISMATCH_DRIVER |
VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS, 0 },
/* Serious Sam 4 (257420).
* Invariant workarounds cause graphical glitches when rendering foliage on NV. */
{ VKD3D_STRING_COMPARE_EXACT, "Sam4.exe", VKD3D_CONFIG_FLAG_FORCE_NO_INVARIANT_POSITION, 0 },
/* Cyberpunk 2077 (1091500). */
{ VKD3D_STRING_COMPARE_EXACT, "Cyberpunk2077.exe", VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION, 0 },
/* Resident Evil: Village (1196590).
* Game relies on mesh + sampler feedback to be exposed to use DXR.
* Likely used as a proxy for Turing+ to avoid potential software fallbacks on Pascal. */
{ VKD3D_STRING_COMPARE_EXACT, "re8.exe",
VKD3D_CONFIG_FLAG_FORCE_NATIVE_FP16, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
/* Resident Evil 2 remake (883710). Same as RE: Village. */
{ VKD3D_STRING_COMPARE_EXACT, "re2.exe",
VKD3D_CONFIG_FLAG_FORCE_NATIVE_FP16, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
{ VKD3D_STRING_COMPARE_EXACT, "re3.exe",
VKD3D_CONFIG_FLAG_FORCE_NATIVE_FP16, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
{ VKD3D_STRING_COMPARE_EXACT, "re4.exe",
0, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
{ VKD3D_STRING_COMPARE_EXACT, "re4demo.exe",
0, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
{ VKD3D_STRING_COMPARE_EXACT, "re7.exe",
VKD3D_CONFIG_FLAG_FORCE_NATIVE_FP16, 0, VKD3D_APPLICATION_FEATURE_OVERRIDE_PROMOTE_DXR_TO_ULTIMATE },
/* Control (870780). Control fails to detect DXR if 1.1 is exposed. */
{ VKD3D_STRING_COMPARE_EXACT, "Control_DX12.exe", 0, 0, VKD3D_APPLICATION_FEATURE_LIMIT_DXR_1_0 },
/* Hellblade: Senua's Sacrifice (414340). Enables RT by default if supported which is ... jarring and particularly jarring on Deck. */
{ VKD3D_STRING_COMPARE_EXACT, "HellbladeGame-Win64-Shipping.exe", 0, 0, VKD3D_APPLICATION_FEATURE_NO_DEFAULT_DXR_ON_DECK },
/* Lost Judgment (2058190) */
{ VKD3D_STRING_COMPARE_EXACT, "LostJudgment.exe", VKD3D_CONFIG_FLAG_FORCE_INITIAL_TRANSITION, 0 },
/* Marvel's Spider-Man Remastered (1817070) */
{ VKD3D_STRING_COMPARE_EXACT, "Spider-Man.exe", VKD3D_CONFIG_FLAG_FORCE_INITIAL_TRANSITION, 0 },
/* Marvel’s Spider-Man: Miles Morales (1817190) */
{ VKD3D_STRING_COMPARE_EXACT, "MilesMorales.exe", VKD3D_CONFIG_FLAG_FORCE_INITIAL_TRANSITION, 0 },
/* Deus Ex: Mankind United (337000) */
{ VKD3D_STRING_COMPARE_EXACT, "DXMD.exe", VKD3D_CONFIG_FLAG_FORCE_INITIAL_TRANSITION, 0 },
/* Dead Space (2023) (1693980) */
{ VKD3D_STRING_COMPARE_EXACT, "Dead Space.exe", VKD3D_CONFIG_FLAG_FORCE_DEDICATED_IMAGE_ALLOCATION, 0 },
/* Witcher 3 (2023) (292030) */
{ VKD3D_STRING_COMPARE_EXACT, "witcher3.exe", VKD3D_CONFIG_FLAG_DISABLE_SIMULTANEOUS_UAV_COMPRESSION, 0 },
/* Age of Wonders 4 (1669000). Extremely stuttery performance with ReBAR. */
{ VKD3D_STRING_COMPARE_EXACT, "AOW4.exe", VKD3D_CONFIG_FLAG_NO_UPLOAD_HVV, 0 },
/* Horizon Forbidden West (2420110). Work around RADV 23.3.1 that ships on stableOS at time of making WAR. */
{ VKD3D_STRING_COMPARE_EXACT, "HorizonForbiddenWest.exe", VKD3D_CONFIG_FLAG_DRIVER_VERSION_SENSITIVE_SHADERS, 0 },
/* Starfield (1716740) */
{ VKD3D_STRING_COMPARE_EXACT, "Starfield.exe",
VKD3D_CONFIG_FLAG_REQUIRES_COMPUTE_INDIRECT_TEMPLATES | VKD3D_CONFIG_FLAG_REJECT_PADDED_SMALL_RESOURCE_ALIGNMENT, 0 },
/* Persona 3 Reload (2161700). Enables RT by default on Deck and does not run acceptably for a verified title. */
{ VKD3D_STRING_COMPARE_EXACT, "P3R.exe", 0, 0, VKD3D_APPLICATION_FEATURE_NO_DEFAULT_DXR_ON_DECK },
{ VKD3D_STRING_COMPARE_NEVER, NULL, 0, 0 }
};
struct vkd3d_shader_quirk_meta
{
enum vkd3d_string_compare_mode mode;
const char *name;
const struct vkd3d_shader_quirk_info *info;
};
static const struct vkd3d_shader_quirk_hash ue4_hashes[] = {
{ 0x08a323ee81c1e393ull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0x75dcbd76ee898815ull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0x6c37b5a66059b751ull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0xaf6d07d7b56a3effull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0xa48ead2a618e12d8ull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0xebfd864995d3fc07ull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
{ 0xcca7b582db60199cull, VKD3D_SHADER_QUIRK_FORCE_EXPLICIT_LOD_IN_CONTROL_FLOW },
};
static const struct vkd3d_shader_quirk_info ue4_quirks = {
ue4_hashes, ARRAY_SIZE(ue4_hashes), 0,
};
static const struct vkd3d_shader_quirk_info f1_2019_2020_quirks = {
NULL, 0, VKD3D_SHADER_QUIRK_FORCE_TGSM_BARRIERS,
};
static const struct vkd3d_shader_quirk_hash borderlands3_hashes[] = {
/* Shader breaks due to floor(a / exp(x)) being refactored to floor(a * exp(-x))
* and shader does not expect this.
* See https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19910. */
{ 0xbf0af7db6a7fb86bull, VKD3D_SHADER_QUIRK_FORCE_NOCONTRACT_MATH },
};
static const struct vkd3d_shader_quirk_info borderlands3_quirks = {
borderlands3_hashes, ARRAY_SIZE(borderlands3_hashes), 0,
};
/* Terrain is rendered with extreme tessellation factors. Limit it to something more reasonable. */
static const struct vkd3d_shader_quirk_info wolong_quirks = {
NULL, 0, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_8,
};
/* The subgroup check in CACAO shader is botched and does not handle Wave64 properly.
* Just pretend the subgroup size is non-sensical to use the normal FFX CACAO code path. */
static const struct vkd3d_shader_quirk_hash re_hashes[] = {
/* RE4 */
{ 0xa100b53736f9c1bfull, VKD3D_SHADER_QUIRK_FORCE_SUBGROUP_SIZE_1 },
/* RE2 and RE7 */
{ 0x1c4c8782b75c498bull, VKD3D_SHADER_QUIRK_FORCE_SUBGROUP_SIZE_1 },
/* Temporary driver workaround for RADV. See https://gitlab.freedesktop.org/mesa/mesa/-/issues/9852. */
/* This shader trips on Mesa 23.0.3. */
{ 0xdb1593ced60da3f1ull, VKD3D_SHADER_QUIRK_REWRITE_GRAD_TO_BIAS },
/* This shader hangs on Mesa main. */
{ 0x5784e9e2f7a76819ull, VKD3D_SHADER_QUIRK_REWRITE_GRAD_TO_BIAS },
/* This shader hangs on RDNA1 */
{ 0x7b3cec4ba6d32cacull, VKD3D_SHADER_QUIRK_REWRITE_GRAD_TO_BIAS },
};
static const struct vkd3d_shader_quirk_info re_quirks = {
re_hashes, ARRAY_SIZE(re_hashes), 0,
};
/* There are lots of shaders which cause random flicker due to bad 16-bit behavior.
* These shaders really need 32-bit it seems to render properly, so just do that. */
static const struct vkd3d_shader_quirk_info re4_quirks = {
re_hashes, ARRAY_SIZE(re_hashes), VKD3D_SHADER_QUIRK_FORCE_MIN16_AS_32BIT,
};
static const struct vkd3d_shader_quirk_hash mhr_hashes[] = {
/* Shader is extremely sensitive to nocontract behavior.
* There some places where catastrophic cancellation occurs
* and one ULP difference is the difference between blown out bloom and not. */
{ 0xd892f8024f52d3ca, VKD3D_SHADER_QUIRK_FORCE_NOCONTRACT_MATH },
};
static const struct vkd3d_shader_quirk_info mhr_quirks = {
mhr_hashes, ARRAY_SIZE(mhr_hashes), 0,
};
static const struct vkd3d_shader_quirk_hash witcher3_hashes[] = {
/* In DXR path, the game will write VBO data in a CS which is then followed
* by a VS -> tess -> geom pass that writes out data to a UAV in the GS.
* There appears to be missing synchronization here by game (no UAV -> VBO barrier) and
* forcing barriers fixes a ton of glitches on both NV and RADV. */
{ 0x2c16686e5d9b04a8, VKD3D_SHADER_QUIRK_FORCE_COMPUTE_BARRIER },
};
static const struct vkd3d_shader_quirk_info witcher3_quirks = {
witcher3_hashes, ARRAY_SIZE(witcher3_hashes), 0,
};
static const struct vkd3d_shader_quirk_info pagonia_quirks = {
NULL, 0, VKD3D_SHADER_QUIRK_DESCRIPTOR_HEAP_ROBUSTNESS,
};
static const struct vkd3d_shader_quirk_hash ac_mirage_hashes[] = {
/* There is a write-after-read hazard.
* Index buffer is being read from, and there is a compute shader afterwards
* that writes to that index buffer without a barrier. */
{ 0x0cb130fa374982e3, VKD3D_SHADER_QUIRK_FORCE_PRE_RASTERIZATION_BARRIER },
};
static const struct vkd3d_shader_quirk_info ac_mirage_quirks = {
ac_mirage_hashes, ARRAY_SIZE(ac_mirage_hashes), 0,
};
static const struct vkd3d_shader_quirk_meta application_shader_quirks[] = {
/* F1 2020 (1080110) */
{ VKD3D_STRING_COMPARE_EXACT, "F1_2020_dx12.exe", &f1_2019_2020_quirks },
/* F1 2019 (928600) */
{ VKD3D_STRING_COMPARE_EXACT, "F1_2019_dx12.exe", &f1_2019_2020_quirks },
/* Borderlands 3 (397540) */
{ VKD3D_STRING_COMPARE_EXACT, "Borderlands3.exe", &borderlands3_quirks },
/* Wo Long: Fallen Dynasty (2285240) */
{ VKD3D_STRING_COMPARE_EXACT, "WoLong.exe", &wolong_quirks },
/* Resident Evil 2 (883710) */
{ VKD3D_STRING_COMPARE_EXACT, "re2.exe", &re_quirks },
/* Resident Evil 7 (418370) */
{ VKD3D_STRING_COMPARE_EXACT, "re7.exe", &re_quirks },
/* Resident Evil 4 (2050650) */
{ VKD3D_STRING_COMPARE_EXACT, "re4.exe", &re4_quirks },
/* Monster Hunter Rise (1446780) */
{ VKD3D_STRING_COMPARE_EXACT, "MonsterHunterRise.exe", &mhr_quirks },
/* Witcher 3 (2023) (292030) */
{ VKD3D_STRING_COMPARE_EXACT, "witcher3.exe", &witcher3_quirks },
/* Pioneers of Pagonia (2155180) */
{ VKD3D_STRING_COMPARE_EXACT, "Pioneers of Pagonia.exe", &pagonia_quirks },
/* AC: Mirage */
{ VKD3D_STRING_COMPARE_EXACT, "ACMirage.exe", &ac_mirage_quirks },
{ VKD3D_STRING_COMPARE_EXACT, "ACMirage_plus.exe", &ac_mirage_quirks },
/* Unreal Engine 4 */
{ VKD3D_STRING_COMPARE_ENDS_WITH, "-Shipping.exe", &ue4_quirks },
/* MSVC fails to compile empty array. */
{ VKD3D_STRING_COMPARE_NEVER, NULL, NULL },
};
static void vkd3d_instance_apply_application_workarounds(void)
{
char app[VKD3D_PATH_MAX];
size_t i;
if (!vkd3d_get_program_name(app))
return;
INFO("Program name: \"%s\" (hash: %016"PRIx64")\n", app, hash_fnv1_iterate_string(hash_fnv1_init(), app));
for (i = 0; i < ARRAY_SIZE(application_override); i++)
{
if (vkd3d_string_compare(application_override[i].mode, app, application_override[i].name))
{
vkd3d_config_flags |= application_override[i].global_flags_add;
vkd3d_config_flags &= ~application_override[i].global_flags_remove;
INFO("Detected game %s, adding config 0x%"PRIx64", removing masks 0x%"PRIx64".\n",
app, application_override[i].global_flags_add, application_override[i].global_flags_remove);
vkd3d_application_feature_override = application_override[i].override;
break;
}
}
for (i = 0; i < ARRAY_SIZE(application_shader_quirks); i++)
{
if (vkd3d_string_compare(application_shader_quirks[i].mode, app, application_shader_quirks[i].name))
{
vkd3d_shader_quirk_info = *application_shader_quirks[i].info;
INFO("Detected game %s, adding shader quirks for specific shaders.\n", app);
break;
}
}
}
static void vkd3d_instance_deduce_config_flags_from_environment(void)
{
char env[VKD3D_PATH_MAX];
if (vkd3d_get_env_var("VKD3D_SHADER_OVERRIDE", env, sizeof(env)) ||
vkd3d_get_env_var("VKD3D_SHADER_DUMP_PATH", env, sizeof(env)))
{
INFO("VKD3D_SHADER_OVERRIDE or VKD3D_SHADER_DUMP_PATH is used, pipeline_library_ignore_spirv option is enforced.\n");
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV;
}
vkd3d_get_env_var("VKD3D_SHADER_CACHE_PATH", env, sizeof(env));
if (strcmp(env, "0") == 0)
{
INFO("Shader cache is explicitly disabled, relying solely on application caches.\n");
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY;
}
/* If we're using a global shader cache, it's meaningless to use PSO caches. */
if (!(vkd3d_config_flags & VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY))
{
INFO("shader_cache is used, global_pipeline_cache is enforced.\n");
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE;
}
/* Normally, we would use VK_EXT_tooling_info for this, but we don't observe layers across the winevulkan layer.
* The global env-var on the other hand, does ... */
if (vkd3d_get_env_var("ENABLE_VULKAN_RENDERDOC_CAPTURE", env, sizeof(env)) &&
strcmp(env, "1") == 0)
{
INFO("RenderDoc capture is enabled. Forcing HOST CACHED memory types and disabling pipeline caching completely.\n");
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_FORCE_HOST_CACHED |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY |
VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_NO_SERIALIZE_SPIRV |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV;
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_DEBUG_UTILS;
}
/* RADV_THREAD_TRACE_xxx are deprecated and will be removed at some point. */
if (vkd3d_get_env_var("RADV_THREAD_TRACE", env, sizeof(env)) ||
vkd3d_get_env_var("RADV_THREAD_TRACE_TRIGGER", env, sizeof(env)) ||
(vkd3d_get_env_var("MESA_VK_TRACE", env, sizeof(env)) &&
strcmp(env, "rgp") == 0))
{
INFO("RADV thread trace is enabled. Forcing debug utils to be enabled for labels.\n");
/* Disable caching so we can get full debug information when emitting labels. */
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_DEBUG_UTILS |
VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_NO_SERIALIZE_SPIRV |
VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV;
}
}
static void vkd3d_instance_apply_global_shader_quirks(void)
{
unsigned int level;
char env[64];
struct override
{
uint64_t config;
uint32_t quirk;
bool negative;
};
static const struct override overrides[] =
{
{ VKD3D_CONFIG_FLAG_FORCE_NO_INVARIANT_POSITION, VKD3D_SHADER_QUIRK_INVARIANT_POSITION, true },
};
uint64_t eq_test;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(overrides); i++)
{
eq_test = overrides[i].negative ? 0 : overrides[i].config;
if ((vkd3d_config_flags & overrides[i].config) == eq_test)
vkd3d_shader_quirk_info.global_quirks |= overrides[i].quirk;
}
if (vkd3d_get_env_var("VKD3D_LIMIT_TESS_FACTORS", env, sizeof(env)))
{
static const struct
{
unsigned int level;
uint32_t quirk;
} mapping[] = {
{ 4, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_4 },
{ 8, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_8 },
{ 12, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_12 },
{ 16, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_16 },
{ 32, VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_32 },
};
/* Override what any app profile did. */
vkd3d_shader_quirk_info.global_quirks &= ~(VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_4 |
VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_8 |
VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_12 |
VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_16 |
VKD3D_SHADER_QUIRK_LIMIT_TESS_FACTORS_32);
level = strtoul(env, NULL, 0);
INFO("Attempting to limit tessellation factors to %ux.\n", level);
for (i = 0; i < ARRAY_SIZE(mapping); i++)
{
if (level <= mapping[i].level)
{
INFO("Limiting tessellation factors to %ux.\n", mapping[i].level);
vkd3d_shader_quirk_info.global_quirks |= mapping[i].quirk;
break;
}
}
}
}
static const struct vkd3d_debug_option vkd3d_config_options[] =
{
/* Enable Vulkan debug extensions. */
{"vk_debug", VKD3D_CONFIG_FLAG_VULKAN_DEBUG},
{"skip_application_workarounds", VKD3D_CONFIG_FLAG_SKIP_APPLICATION_WORKAROUNDS},
{"debug_utils", VKD3D_CONFIG_FLAG_DEBUG_UTILS},
{"force_static_cbv", VKD3D_CONFIG_FLAG_FORCE_STATIC_CBV},
{"dxr", VKD3D_CONFIG_FLAG_DXR},
{"nodxr", VKD3D_CONFIG_FLAG_NO_DXR},
{"single_queue", VKD3D_CONFIG_FLAG_SINGLE_QUEUE},
{"descriptor_qa_checks", VKD3D_CONFIG_FLAG_DESCRIPTOR_QA_CHECKS},
{"no_upload_hvv", VKD3D_CONFIG_FLAG_NO_UPLOAD_HVV},
{"log_memory_budget", VKD3D_CONFIG_FLAG_LOG_MEMORY_BUDGET},
{"force_host_cached", VKD3D_CONFIG_FLAG_FORCE_HOST_CACHED},
{"no_invariant_position", VKD3D_CONFIG_FLAG_FORCE_NO_INVARIANT_POSITION},
{"global_pipeline_cache", VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE},
{"pipeline_library_no_serialize_spirv", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_NO_SERIALIZE_SPIRV},
{"pipeline_library_sanitize_spirv", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_SANITIZE_SPIRV},
{"pipeline_library_log", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_LOG},
{"pipeline_library_ignore_spirv", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_SPIRV},
{"mutable_single_set", VKD3D_CONFIG_FLAG_MUTABLE_SINGLE_SET},
{"memory_allocator_skip_clear", VKD3D_CONFIG_FLAG_MEMORY_ALLOCATOR_SKIP_CLEAR},
{"memory_allocator_skip_image_heap_clear", VKD3D_CONFIG_FLAG_MEMORY_ALLOCATOR_SKIP_IMAGE_HEAP_CLEAR},
{"recycle_command_pools", VKD3D_CONFIG_FLAG_RECYCLE_COMMAND_POOLS},
{"pipeline_library_ignore_mismatch_driver", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_IGNORE_MISMATCH_DRIVER},
{"breadcrumbs", VKD3D_CONFIG_FLAG_BREADCRUMBS},
{"breadcrumbs_sync", VKD3D_CONFIG_FLAG_BREADCRUMBS | VKD3D_CONFIG_FLAG_BREADCRUMBS_SYNC},
{"fault", VKD3D_CONFIG_FLAG_FAULT},
{"pipeline_library_app_cache", VKD3D_CONFIG_FLAG_PIPELINE_LIBRARY_APP_CACHE_ONLY},
{"shader_cache_sync", VKD3D_CONFIG_FLAG_SHADER_CACHE_SYNC},
{"force_raw_va_cbv", VKD3D_CONFIG_FLAG_FORCE_RAW_VA_CBV},
{"allow_sbt_collection", VKD3D_CONFIG_FLAG_ALLOW_SBT_COLLECTION},
{"host_import_fallback", VKD3D_CONFIG_FLAG_USE_HOST_IMPORT_FALLBACK},
{"preallocate_srv_mip_clamps", VKD3D_CONFIG_FLAG_PREALLOCATE_SRV_MIP_CLAMPS},
{"force_initial_transition", VKD3D_CONFIG_FLAG_FORCE_INITIAL_TRANSITION},
{"breadcrumbs_trace", VKD3D_CONFIG_FLAG_BREADCRUMBS | VKD3D_CONFIG_FLAG_BREADCRUMBS_TRACE},
{"requires_compute_indirect_templates", VKD3D_CONFIG_FLAG_REQUIRES_COMPUTE_INDIRECT_TEMPLATES},
{"skip_driver_workarounds", VKD3D_CONFIG_FLAG_SKIP_DRIVER_WORKAROUNDS},
{"curb_memory_pso_cache", VKD3D_CONFIG_FLAG_CURB_MEMORY_PSO_CACHE},
{"enable_experimental_features", VKD3D_CONFIG_FLAG_ENABLE_EXPERIMENTAL_FEATURES},
{"reject_padded_small_resource_alignment", VKD3D_CONFIG_FLAG_REJECT_PADDED_SMALL_RESOURCE_ALIGNMENT},
{"disable_simultaneous_uav_compression", VKD3D_CONFIG_FLAG_DISABLE_SIMULTANEOUS_UAV_COMPRESSION},
{"disable_uav_compression", VKD3D_CONFIG_FLAG_DISABLE_UAV_COMPRESSION},
{"disable_depth_compression", VKD3D_CONFIG_FLAG_DISABLE_DEPTH_COMPRESSION},
{"disable_color_compression", VKD3D_CONFIG_FLAG_DISABLE_COLOR_COMPRESSION},
{"app_debug_marker_only", VKD3D_CONFIG_FLAG_APP_DEBUG_MARKER_ONLY},
};
static void vkd3d_config_flags_init_once(void)
{
char config[VKD3D_PATH_MAX];
vkd3d_get_env_var("VKD3D_CONFIG", config, sizeof(config));
vkd3d_config_flags = vkd3d_parse_debug_options(config, vkd3d_config_options, ARRAY_SIZE(vkd3d_config_options));
if (!(vkd3d_config_flags & VKD3D_CONFIG_FLAG_SKIP_APPLICATION_WORKAROUNDS))
vkd3d_instance_apply_application_workarounds();
vkd3d_instance_deduce_config_flags_from_environment();
vkd3d_instance_apply_global_shader_quirks();
/* If we're going to use vk_debug, make sure we can get debug callbacks. */
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_VULKAN_DEBUG)
vkd3d_config_flags |= VKD3D_CONFIG_FLAG_DEBUG_UTILS;
if (vkd3d_config_flags)
INFO("VKD3D_CONFIG='%s'.\n", config);
}
static pthread_once_t vkd3d_config_flags_once = PTHREAD_ONCE_INIT;
static void vkd3d_config_flags_init(void)
{
pthread_once(&vkd3d_config_flags_once, vkd3d_config_flags_init_once);
}
static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance,
const struct vkd3d_instance_create_info *create_info)
{
const struct vkd3d_vk_global_procs *vk_global_procs = &instance->vk_global_procs;
const char *debug_layer_name = "VK_LAYER_KHRONOS_validation";
bool *user_extension_supported = NULL;
VkApplicationInfo application_info;
VkInstanceCreateInfo instance_info;
char application_name[VKD3D_PATH_MAX];
VkLayerProperties *layers;
uint32_t extension_count;
const char **extensions;
uint32_t layer_count, i;
VkInstance vk_instance;
bool dirty_tree_build;
VkResult vr;
HRESULT hr;
uint32_t loader_version = VK_API_VERSION_1_0;
TRACE("Build: %s.\n", vkd3d_version);
memset(instance, 0, sizeof(*instance));
vkd3d_config_flags_init();
if (FAILED(hr = vkd3d_init_vk_global_procs(instance, create_info->pfn_vkGetInstanceProcAddr)))
{
ERR("Failed to initialize Vulkan global procs, hr %#x.\n", hr);
return hr;
}
if (create_info->optional_instance_extension_count)
{
if (!(user_extension_supported = vkd3d_calloc(create_info->optional_instance_extension_count, sizeof(bool))))
return E_OUTOFMEMORY;
}