-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathshader_object.cpp
3501 lines (3049 loc) · 164 KB
/
shader_object.cpp
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 2023-2024 Nintendo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// clang-format off
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <bitset>
#include <utility>
#include <mutex>
#include <shared_mutex>
#include <functional>
#include <vector>
#include <atomic>
#include <algorithm>
#include <vulkan/vulkan.h>
#include <vulkan/vk_layer.h>
#include <vulkan/layer/vk_layer_settings.hpp>
#include <vulkan/utility/vk_safe_struct.hpp>
#include "log.h"
#include "vk_api_hash.h"
#include "vk_util.h"
#include "vk_common.h"
#include "shader_object/shader_object_structs.h"
#define kLayerSettingsForceEnable "force_enable"
#define kLayerSettingsDisablePipelinePreCaching "disable_pipeline_pre_caching"
#define kLayerSettingsCustomSTypeInfo "custom_stype_list"
#define SHADER_OBJECT_BINARY_VERSION 1
//#define ENABLE_DEBUG_LOG
//#define DEBUG_LOG_TO_OUTPUT
#if defined(ENABLE_DEBUG_LOG)
#if defined(DEBUG_LOG_TO_OUTPUT)
#define WIN32_MEAN_AND_LEAN
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
#include <Windows.h>
#define DEBUG_LOG(...) \
{ \
char msg[256] = {}; \
sprintf(msg, "[VkLayer_khronos_shader_object] " __VA_ARGS__); \
OutputDebugString(msg); \
}
#else
#define DEBUG_LOG(...) \
fprintf(stderr, "[VkLayer_khronos_shader_object] " __VA_ARGS__); \
fflush(stderr)
#endif
#else
#define DEBUG_LOG(...)
#endif
#define ASSERT_VK_FALSE(state) ASSERT((state) == VK_FALSE)
#define ASSERT_VK_TRUE(state) ASSERT((state) == VK_TRUE)
#define UNIMPLEMENTED() ASSERT(!"Unimplemented")
#define UNUSED(x) ((void)x)
namespace shader_object {
static const char* kLayerName = "VK_LAYER_KHRONOS_shader_object";
static const VkExtensionProperties kExtensionProperties = {VK_EXT_SHADER_OBJECT_EXTENSION_NAME, VK_EXT_SHADER_OBJECT_SPEC_VERSION};
// Instance extensions that this layer provides:
const VkExtensionProperties kInstanceExtensionProperties[] = {
VkExtensionProperties{VK_EXT_LAYER_SETTINGS_EXTENSION_NAME, VK_EXT_LAYER_SETTINGS_SPEC_VERSION}};
const uint32_t kInstanceExtensionPropertiesCount = static_cast<uint32_t>(std::size(kInstanceExtensionProperties));
template <typename T>
T* AllocateArray(VkAllocationCallbacks const& allocator, uint32_t count, VkSystemAllocationScope scope) {
return static_cast<T*>(allocator.pfnAllocation(allocator.pUserData, sizeof(T) * count, alignof(T), scope));
}
static uint64_t ChecksumFletcher64(uint32_t const* data, size_t count) {
constexpr uint32_t mod_value = 0xFFFFFFFF;
uint64_t num1 = 0;
uint64_t num2 = 0;
for (size_t i = 0; i < count; ++i) {
num1 = (num1 + data[i]) % mod_value;
num2 = (num2 + num1) % mod_value;
}
return (num1 << 32) | num2;
}
#include "generated/shader_object_constants.h"
#include "generated/shader_object_entry_points_x_macros.inl"
// These LayerDispatch* structs hold pointers to the next layer's version of these functions so that we can call down the chain
struct LayerDispatchInstance {
#define ENTRY_POINT(name) PFN_vk##name name = nullptr;
#define ENTRY_POINT_ALIAS(alias, canon)
ENTRY_POINTS_INSTANCE
ADDITIONAL_INSTANCE_FUNCTIONS
ENTRY_POINTS_DEVICE
ADDITIONAL_DEVICE_FUNCTIONS
#undef ENTRY_POINT_ALIAS
#undef ENTRY_POINT
void Initialize(VkInstance instance, PFN_vkGetInstanceProcAddr get_proc_addr) {
#define ENTRY_POINT_ALIAS(alias, canon) if (canon == nullptr) { canon = (PFN_vk##canon)get_proc_addr(instance, "vk" #alias); }
#define ENTRY_POINT(name) ENTRY_POINT_ALIAS(name, name)
ENTRY_POINTS_INSTANCE
ADDITIONAL_INSTANCE_FUNCTIONS
ENTRY_POINTS_DEVICE
ADDITIONAL_DEVICE_FUNCTIONS
#undef ENTRY_POINT
#undef ENTRY_POINT_ALIAS
}
};
static ShaderType ShaderStageToShaderType(VkShaderStageFlagBits stage) {
switch (stage) {
case VK_SHADER_STAGE_VERTEX_BIT:
return VERTEX_SHADER;
case VK_SHADER_STAGE_FRAGMENT_BIT:
return FRAGMENT_SHADER;
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
return TESSELLATION_CONTROL_SHADER;
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
return TESSELLATION_EVALUATION_SHADER;
case VK_SHADER_STAGE_GEOMETRY_BIT:
return GEOMETRY_SHADER;
case VK_SHADER_STAGE_MESH_BIT_EXT:
return MESH_SHADER;
case VK_SHADER_STAGE_TASK_BIT_EXT:
return TASK_SHADER;
default:
ASSERT(false);
return NUM_SHADERS;
}
}
} // namespace shader_object
#if defined(__GNUC__) && __GNUC__ >= 4
#define VEL_EXPORT __attribute__((visibility("default")))
#else
#define VEL_EXPORT
#endif
namespace shader_object {
struct LayerSettings {
bool force_enable{false};
bool disable_pipeline_pre_caching{false};
};
struct InstanceData {
LayerDispatchInstance vtable;
VkInstance instance;
VkPhysicalDevice* physical_devices;
uint32_t physical_device_count;
LayerSettings layer_settings;
};
struct PhysicalDeviceData {
InstanceData* instance;
uint32_t vendor_id;
AdditionalExtensionFlags supported_additional_extensions;
};
static HashMap<VkInstance, InstanceData*> instance_data_map;
static HashMap<VkDevice, DeviceData*> device_data_map;
static HashMap<VkPhysicalDevice, PhysicalDeviceData*> physical_device_data_map;
static HashMap<VkQueue, DeviceData*> queue_to_device_data_map;
static HashMap<VkCommandBuffer, VkCommandPool> command_buffer_to_pool_map;
// Used if the device does not support private data
static HashMap<VkDescriptorUpdateTemplate, VkPipelineBindPoint> descriptor_update_template_to_bind_point_map;
// Used if device does not support private data or if there's more than one device
static HashMap<VkCommandBuffer, CommandBufferData*> command_buffer_to_command_buffer_data;
// Keeps track of the first created device
static ReaderWriterContainer<DeviceData*> first_device_container = nullptr;
static bool ContainsValidShaderBinary(DeviceData const& deviceData, VkShaderCreateInfoEXT const& createInfo);
static VkResult CreatePipelineLayoutForShader(DeviceData const& deviceData, VkAllocationCallbacks const& allocator, Shader* shader) {
ASSERT(shader->pipeline_layout == VK_NULL_HANDLE);
VkPipelineLayoutCreateInfo pipeline_layout_create_info{
VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
nullptr,
0,
shader->num_descriptor_set_layouts,
shader->descriptor_set_layouts,
shader->num_push_constant_ranges,
shader->push_constant_ranges
};
return deviceData.vtable.CreatePipelineLayout(deviceData.device, &pipeline_layout_create_info, &allocator, &shader->pipeline_layout);
}
ComparableShader::ComparableShader(Shader *shader) : shader_(shader), id_(shader ? shader->id : 0) {}
void DeviceData::AddDynamicState(VkDynamicState state) {
ASSERT(dynamic_state_count < kMaxDynamicStates);
dynamic_states[dynamic_state_count] = state;
++dynamic_state_count;
}
bool DeviceData::HasDynamicState(VkDynamicState state) const {
for (uint32_t i = 0; i < dynamic_state_count; ++i) {
if (dynamic_states[i] == state) {
return true;
}
}
return false;
}
void CommandBufferData::ReserveMemory(AlignedMemory& aligned_memory, VkPhysicalDeviceProperties const& properties) {
aligned_memory.Add<CommandBufferData>();
FullDrawStateData::ReserveMemory(aligned_memory, properties);
}
CommandBufferData* CommandBufferData::Create(DeviceData* data, VkAllocationCallbacks allocator) {
AlignedMemory aligned_memory;
ReserveMemory(aligned_memory, data->properties);
aligned_memory.Allocate(allocator, VkSystemAllocationScope::VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!aligned_memory) {
return nullptr;
}
memset(aligned_memory.GetMemoryWritePtr(), 0, aligned_memory.GetSize());
auto cmd_data = aligned_memory.GetNextAlignedPtr<CommandBufferData>();
cmd_data->device_data = data;
cmd_data->allocator = allocator;
cmd_data->draw_state_data_ = aligned_memory.GetNextAlignedPtr<FullDrawStateData>();
FullDrawStateData::InitializeMemory(cmd_data->draw_state_data_, data->properties, cmd_data->device_data->enabled_extensions & DYNAMIC_RENDERING_UNUSED_ATTACHMENTS);
return cmd_data;
}
void CommandBufferData::Destroy(CommandBufferData** data) {
ASSERT(data);
VkAllocationCallbacks allocator = (*data)->allocator;
allocator.pfnFree(allocator.pUserData, *data);
*data = nullptr;
}
VkResult Shader::Create(DeviceData const& deviceData, VkShaderCreateInfoEXT const& createInfo, VkAllocationCallbacks const& allocator,
Shader** ppOutShader) {
auto& vtable = deviceData.vtable;
// Get SPIR-V information
size_t spirv_size;
void const* spirv_data;
if (createInfo.codeType == VK_SHADER_CODE_TYPE_SPIRV_EXT) {
// SPIR-V is stored directly in the create info
spirv_size = createInfo.codeSize;
spirv_data = createInfo.pCode;
} else if (createInfo.codeType == VK_SHADER_CODE_TYPE_BINARY_EXT && ContainsValidShaderBinary(deviceData, createInfo)) {
// SPIR-V is stored in the shader binary
auto shader_binary = static_cast<ShaderBinary const*>(createInfo.pCode);
spirv_size = shader_binary->spirv_data_size;
spirv_data = shader_binary->GetSprivData();
} else {
return VK_ERROR_INCOMPATIBLE_SHADER_BINARY_EXT;
}
size_t name_size = createInfo.pName == nullptr ? 0 : strlen(createInfo.pName) + 1;
AlignedMemory aligned_memory;
aligned_memory.Add<Shader>();
aligned_memory.Add<char>(name_size);
aligned_memory.Add<uint32_t>(spirv_size / sizeof(uint32_t));
aligned_memory.Add<VkPushConstantRange>(createInfo.pushConstantRangeCount);
aligned_memory.Add<VkDescriptorSetLayout>(createInfo.setLayoutCount);
aligned_memory.Add<PrivateDataSlotPair>(deviceData.reserved_private_data_slot_count);
if (createInfo.pSpecializationInfo) {
aligned_memory.Add<uint32_t>(createInfo.pSpecializationInfo->dataSize / sizeof(uint32_t));
aligned_memory.Add<VkSpecializationMapEntry>(createInfo.pSpecializationInfo->mapEntryCount);
}
aligned_memory.Allocate(allocator, VkSystemAllocationScope::VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (!aligned_memory) {
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
Shader* shader = new (aligned_memory.GetNextAlignedPtr<Shader>()) Shader();
static std::atomic<uint64_t> id_counter{1};
shader->id = id_counter.fetch_add(1, std::memory_order_relaxed);
*ppOutShader = shader;
shader->stage = createInfo.stage;
if (createInfo.flags & VK_SHADER_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) {
shader->flags |= VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT;
}
if (createInfo.flags & VK_SHADER_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) {
shader->flags |= VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT;
}
// Copy data over from create info struct
aligned_memory.CopyBytes<char>(shader->name, shader->name_byte_count, createInfo.pName, name_size);
aligned_memory.CopyBytes<uint32_t>(shader->spirv_data, shader->spirv_data_size, spirv_data, spirv_size);
aligned_memory.CopyStruct(shader->push_constant_ranges, shader->num_push_constant_ranges, createInfo.pPushConstantRanges,
createInfo.pushConstantRangeCount);
aligned_memory.CopyStruct(shader->descriptor_set_layouts, shader->num_descriptor_set_layouts, createInfo.pSetLayouts,
createInfo.setLayoutCount);
shader->reserved_private_data_slots = aligned_memory.GetNextAlignedPtr<PrivateDataSlotPair>(deviceData.reserved_private_data_slot_count);
if (createInfo.pSpecializationInfo) {
shader->specialization_info = *createInfo.pSpecializationInfo;
shader->specialization_info_ptr = &shader->specialization_info;
aligned_memory.CopyBytes<uint32_t>(shader->specialization_info.pData, shader->specialization_info.dataSize,
createInfo.pSpecializationInfo->pData, createInfo.pSpecializationInfo->dataSize);
aligned_memory.CopyStruct(shader->specialization_info.pMapEntries, shader->specialization_info.mapEntryCount,
createInfo.pSpecializationInfo->pMapEntries, createInfo.pSpecializationInfo->mapEntryCount);
}
// Create shader module from SPIR-V
VkShaderModuleCreateInfo module_create_info{
VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
nullptr,
0,
spirv_size,
static_cast<uint32_t const*>(spirv_data)
};
VkResult result = vtable.CreateShaderModule(deviceData.device, &module_create_info, &allocator, &shader->shader_module);
if (result != VK_SUCCESS) {
return result;
}
// Create pipeline caches for vertex/mesh (which are always present in a pipeline) and fragment (which is always present in a fragment shader pipeline library)
if (createInfo.stage & (VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_MESH_BIT_EXT | VK_SHADER_STAGE_FRAGMENT_BIT)) {
VkPipelineCacheCreateInfo cache_create_info{
VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
};
// ShaderBinary may hold existing pipeline cache data
if (createInfo.codeType == VK_SHADER_CODE_TYPE_BINARY_EXT) {
auto shader_binary = static_cast<ShaderBinary const*>(createInfo.pCode);
if (shader_binary->flags & ShaderBinary::HAS_PIPELINE_CACHE) {
cache_create_info.initialDataSize = shader_binary->pipeline_cache_size;
cache_create_info.pInitialData = shader_binary->GetPipelineCacheData();
}
}
// Shader has two caches:
// `pristine_cache` is used for shader create time and is for serializing to/from the ShaderBinary
// `cache` is used for pipeline creation at command buffer record time. Initially, it is equal to `pristine_cache`.
result = vtable.CreatePipelineCache(deviceData.device, &cache_create_info, nullptr, &shader->pristine_cache);
if (result != VK_SUCCESS) {
return result;
}
result = vtable.CreatePipelineCache(deviceData.device, &cache_create_info, nullptr, &shader->cache);
if (result != VK_SUCCESS) {
return result;
}
} else if (createInfo.stage & VK_SHADER_STAGE_COMPUTE_BIT) {
// Compute shaders do not require any additional data for a pipeline to be created
result = CreatePipelineLayoutForShader(deviceData, allocator, shader);
if (result != VK_SUCCESS) {
return result;
}
VkPipelineShaderStageCreateInfo compute_stage{
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
nullptr,
shader->flags,
shader->stage,
shader->shader_module,
shader->name,
shader->specialization_info_ptr
};
VkComputePipelineCreateInfo compute_pipeline_create_info{
VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
nullptr,
0,
compute_stage,
shader->pipeline_layout
};
if (createInfo.flags & VK_SHADER_CREATE_DISPATCH_BASE_BIT_EXT) {
compute_pipeline_create_info.flags |= VK_PIPELINE_CREATE_DISPATCH_BASE;
}
result = vtable.CreateComputePipelines(deviceData.device, shader->cache, 1, &compute_pipeline_create_info, &allocator, &shader->partial_pipeline.pipeline);
}
return result;
}
void Shader::Destroy(DeviceData const& device_data, Shader* pShader, VkAllocationCallbacks const& allocator) {
if (pShader == nullptr) {
return;
}
auto device = device_data.device;
auto& vtable = device_data.vtable;
if (pShader->shader_module != VK_NULL_HANDLE) {
vtable.DestroyShaderModule(device, pShader->shader_module, &allocator);
}
if (pShader->pristine_cache != VK_NULL_HANDLE) {
vtable.DestroyPipelineCache(device, pShader->pristine_cache, nullptr);
}
if (pShader->cache != VK_NULL_HANDLE) {
vtable.DestroyPipelineCache(device, pShader->cache, nullptr);
}
if (pShader->pipeline_layout != VK_NULL_HANDLE) {
vtable.DestroyPipelineLayout(device, pShader->pipeline_layout, &allocator);
}
if (pShader->partial_pipeline.pipeline != VK_NULL_HANDLE) {
vtable.DestroyPipeline(device, pShader->partial_pipeline.pipeline, &allocator);
if (pShader->partial_pipeline.draw_state) {
FullDrawStateData::Destroy(pShader->partial_pipeline.draw_state);
}
}
auto& pipelines = pShader->pipelines.GetDataUnsafe();
for (auto const& pair : pipelines) {
vtable.DestroyPipeline(device, pair.value, nullptr);
}
pipelines.Clear();
pShader->private_data.Clear();
pShader->~Shader();
allocator.pfnFree(allocator.pUserData, pShader);
}
uint64_t Shader::GetPrivateData(DeviceData const& device_data, VkPrivateDataSlot slot) {
// first, search through the reserved slots
for (uint32_t i = 0; i < device_data.reserved_private_data_slot_count; ++i) {
if (reserved_private_data_slots[i].slot == slot) {
return reserved_private_data_slots[i].data;
}
}
// then, look up in the map
const uint64_t* found = private_data.GetOrNullptr(slot);
if (found) {
return *found;
}
// otherwise, return default value
return 0;
}
void Shader::SetPrivateData(DeviceData const& device_data, VkPrivateDataSlot slot, uint64_t data) {
// first, search through the reserved slots
for (uint32_t i = 0; i < device_data.reserved_private_data_slot_count; ++i) {
if (reserved_private_data_slots[i].slot == VK_NULL_HANDLE || reserved_private_data_slots[i].slot == slot) {
reserved_private_data_slots[i] = {slot, data};
return;
}
}
// otherwise, set it in the map
private_data.Add(slot, data);
}
static VkResult CalculateBinarySizeForShader(DeviceData const& deviceData, Shader const& shader, size_t* out_binary_size, size_t* out_pipeline_cache_size) {
VkResult result = VK_SUCCESS;
size_t pipeline_cache_size = 0;
if (shader.pristine_cache != VK_NULL_HANDLE) {
result = deviceData.vtable.GetPipelineCacheData(deviceData.device, shader.pristine_cache, &pipeline_cache_size, nullptr);
}
if (out_pipeline_cache_size) {
*out_pipeline_cache_size = pipeline_cache_size;
}
if (out_binary_size) {
*out_binary_size = sizeof(ShaderBinary) + shader.spirv_data_size + pipeline_cache_size;
}
return result;
}
static uint64_t CalculateSpirvChecksum(void const* spirv_data, size_t spirv_data_size) {
ASSERT(spirv_data_size % sizeof(uint32_t) == 0);
return ChecksumFletcher64(static_cast<uint32_t const*>(spirv_data), spirv_data_size / sizeof(uint32_t));
}
VkResult ShaderBinary::Create(DeviceData const& deviceData, Shader const& shader, void* out) {
auto& vtable = deviceData.vtable;
auto binary = static_cast<ShaderBinary*>(out);
binary->magic = kMagic;
binary->version = SHADER_OBJECT_BINARY_VERSION;
binary->stage = shader.stage;
binary->spirv_data_size = shader.spirv_data_size;
binary->spirv_checksum = CalculateSpirvChecksum(shader.spirv_data, shader.spirv_data_size);
memcpy(binary->GetSprivData(), shader.spirv_data, shader.spirv_data_size);
if (shader.pristine_cache != VK_NULL_HANDLE) {
binary->flags = ShaderBinary::HAS_PIPELINE_CACHE;
VkResult result = vtable.GetPipelineCacheData(deviceData.device, shader.pristine_cache, &binary->pipeline_cache_size, nullptr);
if (result != VK_SUCCESS) {
return result;
}
return vtable.GetPipelineCacheData(deviceData.device, shader.pristine_cache, &binary->pipeline_cache_size, binary->GetPipelineCacheData());
} else {
binary->flags = 0;
binary->pipeline_cache_size = 0;
}
return VK_SUCCESS;
}
static bool ContainsValidShaderBinary(DeviceData const& deviceData, VkShaderCreateInfoEXT const& createInfo) {
if (createInfo.codeSize < sizeof(ShaderBinary)) {
return false;
}
auto shader_binary = static_cast<ShaderBinary const*>(createInfo.pCode);
if (shader_binary->magic != ShaderBinary::kMagic) {
return false;
}
if (shader_binary->version != SHADER_OBJECT_BINARY_VERSION) {
return false;
}
if (shader_binary->spirv_data_size == 0) {
return false;
}
if (shader_binary->stage != createInfo.stage) {
return false;
}
if (shader_binary->spirv_checksum != CalculateSpirvChecksum(shader_binary->GetSprivData(), shader_binary->spirv_data_size)) {
return false;
}
if (shader_binary->flags & ShaderBinary::HAS_PIPELINE_CACHE) {
if (shader_binary->pipeline_cache_size < sizeof(VkPipelineCacheHeaderVersionOne)) {
return false;
}
auto pipeline_cache_header = reinterpret_cast<VkPipelineCacheHeaderVersionOne const*>(shader_binary->GetPipelineCacheData());
if (memcmp(pipeline_cache_header->pipelineCacheUUID, deviceData.properties.pipelineCacheUUID, VK_UUID_SIZE) != 0) {
return false;
}
}
return true;
}
static CommandBufferData* GetCommandBufferData(VkCommandBuffer cmd) {
// Ideal scenario is CommandBufferData* is stored in the private data for the command buffer. However, this can only
// happen if there's only one device and that device supports private data.
// A potential performance improvement may be caching the previous VkCommandBuffer and CommandBufferData in thread-local storage
std::shared_lock<std::shared_mutex> lock;
auto first_device = first_device_container.GetDataForReading(lock);
if (device_data_map.NumEntries() != 1 || first_device->private_data.privateData == VK_FALSE) {
// >1 existing device => Don't know which device the command buffer belongs to. Need to search the map
// No private data => Need to search the map
auto found = command_buffer_to_command_buffer_data.GetOrNullptr(cmd);
if (found) {
return *found;
}
}
// Command buffer belongs to the first device
uint64_t cmd_data;
first_device->vtable.GetPrivateData(first_device->device, VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast<uint64_t>(cmd), first_device->private_data_slot, &cmd_data);
return reinterpret_cast<CommandBufferData*>(cmd_data);
}
static VkPipelineBindPoint GetDescriptorUpdateTemplateBindPoint(DeviceData* deviceData, VkDescriptorUpdateTemplate descriptorUpdateTemplate) {
auto& vtable = deviceData->vtable;
if (deviceData->private_data.privateData == VK_TRUE) {
uint64_t data;
vtable.GetPrivateData(deviceData->device, VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE, (uint64_t)(descriptorUpdateTemplate), deviceData->private_data_slot, &data);
return static_cast<VkPipelineBindPoint>(data);
}
return descriptor_update_template_to_bind_point_map.Get(descriptorUpdateTemplate);
}
static void SetDescriptorUpdateTemplateBindPoint(DeviceData* deviceData, VkDescriptorUpdateTemplate descriptorUpdateTemplate, VkPipelineBindPoint bindPoint) {
auto& vtable = deviceData->vtable;
if (deviceData->private_data.privateData == VK_TRUE) {
vtable.SetPrivateData(deviceData->device, VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE, (uint64_t)(descriptorUpdateTemplate), deviceData->private_data_slot, static_cast<uint64_t>(bindPoint));
return;
}
descriptor_update_template_to_bind_point_map.Add(descriptorUpdateTemplate, bindPoint);
}
static void RemoveDescriptorUpdateTemplateBindPoint(DeviceData* deviceData, VkDescriptorUpdateTemplate descriptorUpdateTemplate) {
if (deviceData->private_data.privateData == VK_TRUE) {
return;
}
descriptor_update_template_to_bind_point_map.Remove(descriptorUpdateTemplate);
}
static void SetCommandBufferDataForCommandBuffer(DeviceData* device_data, VkCommandBuffer cmd, CommandBufferData* cmd_data) {
std::shared_lock<std::shared_mutex> lock;
DeviceData* first_device = first_device_container.GetDataForReading(lock);
if (device_data == first_device && device_data->private_data.privateData == VK_TRUE) {
VkResult result = device_data->vtable.SetPrivateData(device_data->device, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)cmd,
device_data->private_data_slot, (uint64_t)cmd_data);
ASSERT(result == VK_SUCCESS);
UNUSED(result);
} else {
command_buffer_to_command_buffer_data.Add(cmd, cmd_data);
}
}
static void RemoveCommandBufferDataForCommandBuffer(DeviceData* device_data, VkCommandBuffer cmd) {
std::shared_lock<std::shared_mutex> lock;
DeviceData* first_device = first_device_container.GetDataForReading(lock);
auto cmd_data = GetCommandBufferData(cmd);
CommandBufferData::Destroy(&cmd_data);
if (device_data != first_device) {
command_buffer_to_command_buffer_data.Remove(cmd);
}
}
static const char* GetShaderName(uint32_t shader_type) {
switch (shader_type) {
case VERTEX_SHADER:
return "V";
case FRAGMENT_SHADER:
return "F";
case TESSELLATION_CONTROL_SHADER:
return "TC";
case TESSELLATION_EVALUATION_SHADER:
return "TE";
case GEOMETRY_SHADER:
return "G";
case MESH_SHADER:
return "M";
case TASK_SHADER:
return "T";
default:
break;
}
return "";
}
static void SetComputeShaderDebugUtilsName(DeviceData& data, Shader* shader, const VkDebugUtilsObjectNameInfoEXT *pNameInfo) {
VkDebugUtilsObjectNameInfoEXT name_info{
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
nullptr,
VK_OBJECT_TYPE_PIPELINE,
(uint64_t)shader->partial_pipeline.pipeline,
pNameInfo->pObjectName
};
data.vtable.SetDebugUtilsObjectNameEXT(data.device, &name_info);
}
static void SetComputeShaderDebugUtilsTag(DeviceData& data, Shader* shader, const VkDebugUtilsObjectTagInfoEXT* pTagInfo) {
VkDebugUtilsObjectTagInfoEXT tag_info{
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT,
nullptr,
VK_OBJECT_TYPE_PIPELINE,
(uint64_t)shader->partial_pipeline.pipeline,
pTagInfo->tagName,
pTagInfo->tagSize,
pTagInfo->pTag
};
data.vtable.SetDebugUtilsObjectTagEXT(data.device, &tag_info);
}
static void SetDebugUtilsNameAndTag(CommandBufferData& cmd_data, VkPipeline pipeline) {
auto& device_data = *cmd_data.device_data;
auto const state = cmd_data.GetDrawStateData();
if (device_data.debug_utils_object_name_map.NumEntries() > 0) {
bool first_shader = true;
bool same_name = true;
char same_shader_name[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH];
char pipeline_name[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH* 5 + 26];
pipeline_name[0] = '\0';
char temp[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH + 5];
for (uint32_t shader_type = 0; shader_type < NUM_SHADERS; ++shader_type) {
Shader* shader = state->GetComparableShader(shader_type).GetShaderPtr();
if (shader == nullptr) {
continue;
}
auto iter = device_data.debug_utils_object_name_map.Find(shader);
if (iter != device_data.debug_utils_object_name_map.end()) {
const auto& shader_name = iter.GetValue().name;
if (first_shader) {
first_shader = false;
strncpy(same_shader_name, shader_name, sizeof(same_shader_name));
} else if (strncmp(shader_name, same_shader_name, sizeof(shader_name)) == 0) {
same_name = false;
strncat(pipeline_name, "/", sizeof(pipeline_name) - strlen(pipeline_name) - 1);
}
bool has_space_or_slash = strchr(shader_name, ' ') != NULL || strchr(shader_name, '/') != NULL;
if (has_space_or_slash) {
snprintf(temp, sizeof(temp), "%s:\"%s\"", GetShaderName(shader_type), shader_name);
} else {
snprintf(temp, sizeof(temp), "%s:%s", GetShaderName(shader_type), shader_name);
}
strncat(pipeline_name, temp, sizeof(pipeline_name) - strlen(pipeline_name) - 1);
pipeline_name[sizeof(pipeline_name) - 1] = '\0';
}
}
if (!first_shader) {
VkDebugUtilsObjectNameInfoEXT name_info{
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
nullptr,
VK_OBJECT_TYPE_PIPELINE,
(uint64_t)pipeline,
same_name ? same_shader_name : pipeline_name
};
device_data.vtable.SetDebugUtilsObjectNameEXT(device_data.device, &name_info);
}
}
if (device_data.debug_utils_object_tag_map.NumEntries() > 0) {
bool first_shader = true;
bool same_tag = true;
char same_shader_tag[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH];
char pipeline_tag[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH * 5 + 26];
pipeline_tag[0] = '\0';
char temp[SHADER_OBJECT_DEBUG_UTILS_STR_LENGTH + 5];
uint64_t tagName = 0;
for (uint32_t shader_type = 0; shader_type < NUM_SHADERS; ++shader_type) {
Shader* shader = state->GetComparableShader(shader_type).GetShaderPtr();
if (shader == nullptr) {
continue;
}
auto iter = device_data.debug_utils_object_tag_map.Find(shader);
if (iter != device_data.debug_utils_object_tag_map.end()) {
const auto& shader_tag = iter.GetValue().tag;
if (first_shader) {
first_shader = false;
strncpy(same_shader_tag, shader_tag, sizeof(same_shader_tag));
} else if (strncmp(shader_tag, same_shader_tag, sizeof(same_shader_tag)) != 0) {
same_tag = false;
strncat(pipeline_tag, "/", sizeof(pipeline_tag) - strlen(pipeline_tag) - 1);
}
if (shader_type == VERTEX_SHADER || shader_type == MESH_SHADER) {
tagName = iter.GetValue().tagName;
}
bool has_space_or_slash = strchr(shader_tag, ' ') != NULL || strchr(shader_tag, '/') != NULL;
if (has_space_or_slash) {
snprintf(temp, sizeof(temp), "%s:\"%s\"", GetShaderName(shader_type), shader_tag);
} else {
snprintf(temp, sizeof(temp), "%s:%s", GetShaderName(shader_type), shader_tag);
}
strncat(pipeline_tag, temp, sizeof(pipeline_tag) - strlen(pipeline_tag) - 1);
pipeline_tag[sizeof(pipeline_tag) - 1] = '\0';
}
}
if (!first_shader) {
VkDebugUtilsObjectTagInfoEXT tag_info{
VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_TAG_INFO_EXT,
nullptr,
VK_OBJECT_TYPE_PIPELINE,
(uint64_t)pipeline,
tagName,
same_tag ? strlen(same_shader_tag) : strlen(pipeline_tag),
same_tag ? same_shader_tag : pipeline_tag
};
device_data.vtable.SetDebugUtilsObjectTagEXT(device_data.device, &tag_info);
}
}
}
static VkPipeline CreateGraphicsPipelineForCommandBufferState(CommandBufferData& cmd_data) {
auto& device_data = *cmd_data.device_data;
auto const state = cmd_data.GetDrawStateData();
// gather shaders
uint32_t num_stages = 0;
VkPipelineShaderStageCreateInfo stages[NUM_SHADERS] = {};
Shader* vertex_or_mesh_shader = nullptr;
VkShaderStageFlags present_stages = 0;
for (uint32_t shader_type = 0; shader_type < NUM_SHADERS; ++shader_type) {
Shader* shader = state->GetComparableShader(shader_type).GetShaderPtr();
if (shader == nullptr) {
continue;
}
present_stages |= shader->stage;
VkPipelineShaderStageCreateInfo stage = {};
stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
stage.flags = shader->flags;
stage.module = shader->shader_module;
stage.pName = shader->name;
stage.stage = shader->stage;
stage.pSpecializationInfo = shader->specialization_info_ptr;
switch (shader_type) {
case VERTEX_SHADER:
case MESH_SHADER:
vertex_or_mesh_shader = shader;
break;
default:
break;
}
stages[num_stages] = stage;
++num_stages;
}
// vertex or mesh shader is required
ASSERT(vertex_or_mesh_shader != nullptr);
VkPipelineLayout pipeline_layout = vertex_or_mesh_shader->pipeline_layout;
if (pipeline_layout == VK_NULL_HANDLE) {
pipeline_layout = cmd_data.last_seen_pipeline_layout_;
}
if (pipeline_layout == VK_NULL_HANDLE) {
pipeline_layout = cmd_data.device_data->dummy_pipeline_layout;
}
const uint32_t num_color_attachments = (device_data.enabled_extensions & DYNAMIC_RENDERING_UNUSED_ATTACHMENTS) ? device_data.properties.limits.maxColorAttachments : state->GetNumColorAttachments();
VkPipelineViewportStateCreateInfo viewport_state{};
viewport_state.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
viewport_state.viewportCount = cmd_data.device_data->HasDynamicState(VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT) ? 0u : state->GetNumViewports();
viewport_state.scissorCount = cmd_data.device_data->HasDynamicState(VK_DYNAMIC_STATE_SCISSOR_WITH_COUNT) ? 0u : state->GetNumScissors();
VkPipelineViewportDepthClipControlCreateInfoEXT depth_clip_control_state{
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_DEPTH_CLIP_CONTROL_CREATE_INFO_EXT,
nullptr,
state->GetNegativeOneToOne()
};
VkPipelineViewportWScalingStateCreateInfoNV viewport_w_scaling_state{
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV,
nullptr,
state->GetViewportWScalingEnable()
};
VkPipelineViewportSwizzleStateCreateInfoNV viewport_swizzle_state{
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
nullptr,
0,
state->GetViewportSwizzleCount(),
state->GetViewportSwizzlePtr()
};
VkPipelineViewportShadingRateImageStateCreateInfoNV viewport_shading_rate{
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SHADING_RATE_IMAGE_STATE_CREATE_INFO_NV,
nullptr,
state->GetShadingRateImageEnable()
};
auto viewport_chain = reinterpret_cast<VkBaseOutStructure*>(&viewport_state);
if (device_data.enabled_extensions & DEPTH_CLIP_CONTROL) {
viewport_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&depth_clip_control_state);
viewport_chain = viewport_chain->pNext;
}
if (device_data.enabled_extensions & NV_CLIP_SPACE_W_SCALING) {
viewport_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&viewport_w_scaling_state);
viewport_chain = viewport_chain->pNext;
}
if (device_data.enabled_extensions & NV_VIEWPORT_SWIZZLE) {
viewport_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&viewport_swizzle_state);
viewport_chain = viewport_chain->pNext;
}
if (device_data.enabled_extensions & NV_SHADING_RATE_IMAGE) {
viewport_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&viewport_shading_rate);
viewport_chain = viewport_chain->pNext;
}
// Set pointers to NULL when count is 0, workaround for a driver bug
VkPipelineVertexInputStateCreateInfo vertex_input{};
vertex_input.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertex_input.vertexBindingDescriptionCount = state->GetNumVertexInputBindingDescriptions();
vertex_input.pVertexBindingDescriptions = vertex_input.vertexBindingDescriptionCount > 0 ? state->GetVertexInputBindingDescriptionPtr() : nullptr;
vertex_input.vertexAttributeDescriptionCount = state->GetNumVertexInputAttributeDescriptions();
vertex_input.pVertexAttributeDescriptions = vertex_input.vertexAttributeDescriptionCount > 0 ? state->GetVertexInputAttributeDescriptionPtr() : nullptr;
VkPipelineInputAssemblyStateCreateInfo input_assembly{};
input_assembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
input_assembly.topology = state->GetPrimitiveTopology();
input_assembly.primitiveRestartEnable = state->GetPrimitiveRestartEnable();
VkPipelineTessellationDomainOriginStateCreateInfo domain_origin_state{};
domain_origin_state.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO;
domain_origin_state.domainOrigin = state->GetDomainOrigin();
VkPipelineTessellationStateCreateInfo tessellation_state{};
tessellation_state.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
tessellation_state.pNext = &domain_origin_state;
tessellation_state.patchControlPoints = state->GetPatchControlPoints();
VkPipelineRasterizationStateCreateInfo rasterization_state{};
rasterization_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rasterization_state.polygonMode = state->GetPolygonMode();
rasterization_state.cullMode = state->GetCullMode();
rasterization_state.frontFace = state->GetFrontFace();
rasterization_state.rasterizerDiscardEnable = state->GetRasterizerDiscardEnable();
rasterization_state.depthBiasEnable = state->GetDepthBiasEnable();
rasterization_state.depthClampEnable = state->GetDepthClampEnable();
rasterization_state.lineWidth = 1.0f;
VkPipelineRasterizationStateStreamCreateInfoEXT rasterization_stream_state{
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT,
nullptr,
0,
state->GetRasterizationStream()
};
VkPipelineRasterizationConservativeStateCreateInfoEXT rasterization_conservative_state{
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT,
nullptr,
0,
state->GetConservativeRasterizationMode(),
state->GetExtraPrimitiveOverestimationSize()
};
VkPipelineRasterizationDepthClipStateCreateInfoEXT rasterization_depth_clip_state{
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_DEPTH_CLIP_STATE_CREATE_INFO_EXT,
nullptr,
0,
state->GetDepthClipEnable()
};
VkPipelineRasterizationProvokingVertexStateCreateInfoEXT provoking_vertex_state{
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_PROVOKING_VERTEX_STATE_CREATE_INFO_EXT,
nullptr,
state->GetProvokingVertexMode()
};
VkPipelineRasterizationLineStateCreateInfoEXT line_rasterization_state{
VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT,
nullptr,
state->GetLineRasterizationMode(),
state->GetStippledLineEnable()
};
auto rasterization_chain = reinterpret_cast<VkBaseOutStructure*>(&rasterization_state);
if (device_data.transform_feedback.transformFeedback == VK_TRUE) {
rasterization_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&rasterization_stream_state);
rasterization_chain = rasterization_chain->pNext;
}
if (device_data.enabled_extensions & CONSERVATIVE_RASTERIZATION) {
rasterization_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&rasterization_conservative_state);
rasterization_chain = rasterization_chain->pNext;
}
if (device_data.enabled_extensions & DEPTH_CLIP_ENABLE) {
rasterization_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&rasterization_depth_clip_state);
rasterization_chain = rasterization_chain->pNext;
}
if (device_data.enabled_extensions & PROVOKING_VERTEX) {
rasterization_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&provoking_vertex_state);
rasterization_chain = rasterization_chain->pNext;
}
if (device_data.enabled_extensions & LINE_RASTERIZATION) {
rasterization_chain->pNext = reinterpret_cast<VkBaseOutStructure*>(&line_rasterization_state);
rasterization_chain = rasterization_chain->pNext;
}
VkPipelineMultisampleStateCreateInfo multisample_state{};
multisample_state.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
multisample_state.rasterizationSamples = state->GetRasterizationSamples();
multisample_state.alphaToOneEnable = state->GetAlphaToOneEnable();
multisample_state.alphaToCoverageEnable = state->GetAlphaToCoverageEnable();
multisample_state.pSampleMask = state->GetSampleMaskPtr();
VkPipelineSampleLocationsStateCreateInfoEXT sample_location_state{
VK_STRUCTURE_TYPE_PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT,
nullptr,
state->GetSampleLocationsEnable(),
{
VK_STRUCTURE_TYPE_SAMPLE_LOCATIONS_INFO_EXT
}
};
VkPipelineCoverageModulationStateCreateInfoNV coverage_modulation_state{
VK_STRUCTURE_TYPE_PIPELINE_COVERAGE_MODULATION_STATE_CREATE_INFO_NV,
nullptr,
0,
state->GetCoverageModulationMode(),
state->GetCoverageModulationTableEnable(),
state->GetCoverageModulationTableCount(),
state->GetCoverageModulationTableValuesPtr()
};
VkPipelineCoverageReductionStateCreateInfoNV coverage_reduction_state{