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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
|
/*
* Copyright © 2022 Collabora, Ltd
*
* 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.
*/
#ifndef VK_GRAPHICS_STATE_H
#define VK_GRAPHICS_STATE_H
#include "vulkan/vulkan_core.h"
#include "vk_limits.h"
#include "util/bitset.h"
#ifdef __cplusplus
extern "C" {
#endif
struct vk_command_buffer;
struct vk_device;
/** Enumeration of all Vulkan dynamic graphics states
*
* Enumerants are named with both the abreviation of the state group to which
* the state belongs as well as the name of the state itself. These are
* intended to pretty closely match the VkDynamicState enum but may not match
* perfectly all the time.
*/
enum mesa_vk_dynamic_graphics_state {
MESA_VK_DYNAMIC_VI,
MESA_VK_DYNAMIC_VI_BINDING_STRIDES,
MESA_VK_DYNAMIC_IA_PRIMITIVE_TOPOLOGY,
MESA_VK_DYNAMIC_IA_PRIMITIVE_RESTART_ENABLE,
MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS,
MESA_VK_DYNAMIC_TS_DOMAIN_ORIGIN,
MESA_VK_DYNAMIC_VP_VIEWPORT_COUNT,
MESA_VK_DYNAMIC_VP_VIEWPORTS,
MESA_VK_DYNAMIC_VP_SCISSOR_COUNT,
MESA_VK_DYNAMIC_VP_SCISSORS,
MESA_VK_DYNAMIC_VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE,
MESA_VK_DYNAMIC_DR_RECTANGLES,
MESA_VK_DYNAMIC_DR_MODE,
MESA_VK_DYNAMIC_DR_ENABLE,
MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE,
MESA_VK_DYNAMIC_RS_DEPTH_CLAMP_ENABLE,
MESA_VK_DYNAMIC_RS_DEPTH_CLIP_ENABLE,
MESA_VK_DYNAMIC_RS_POLYGON_MODE,
MESA_VK_DYNAMIC_RS_CULL_MODE,
MESA_VK_DYNAMIC_RS_FRONT_FACE,
MESA_VK_DYNAMIC_RS_CONSERVATIVE_MODE,
MESA_VK_DYNAMIC_RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE,
MESA_VK_DYNAMIC_RS_RASTERIZATION_ORDER_AMD,
MESA_VK_DYNAMIC_RS_PROVOKING_VERTEX,
MESA_VK_DYNAMIC_RS_RASTERIZATION_STREAM,
MESA_VK_DYNAMIC_RS_DEPTH_BIAS_ENABLE,
MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS,
MESA_VK_DYNAMIC_RS_LINE_WIDTH,
MESA_VK_DYNAMIC_RS_LINE_MODE,
MESA_VK_DYNAMIC_RS_LINE_STIPPLE_ENABLE,
MESA_VK_DYNAMIC_RS_LINE_STIPPLE,
MESA_VK_DYNAMIC_FSR,
MESA_VK_DYNAMIC_MS_RASTERIZATION_SAMPLES,
MESA_VK_DYNAMIC_MS_SAMPLE_MASK,
MESA_VK_DYNAMIC_MS_ALPHA_TO_COVERAGE_ENABLE,
MESA_VK_DYNAMIC_MS_ALPHA_TO_ONE_ENABLE,
MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS_ENABLE,
MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS,
MESA_VK_DYNAMIC_DS_DEPTH_TEST_ENABLE,
MESA_VK_DYNAMIC_DS_DEPTH_WRITE_ENABLE,
MESA_VK_DYNAMIC_DS_DEPTH_COMPARE_OP,
MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_ENABLE,
MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_BOUNDS,
MESA_VK_DYNAMIC_DS_STENCIL_TEST_ENABLE,
MESA_VK_DYNAMIC_DS_STENCIL_OP,
MESA_VK_DYNAMIC_DS_STENCIL_COMPARE_MASK,
MESA_VK_DYNAMIC_DS_STENCIL_WRITE_MASK,
MESA_VK_DYNAMIC_DS_STENCIL_REFERENCE,
MESA_VK_DYNAMIC_CB_LOGIC_OP_ENABLE,
MESA_VK_DYNAMIC_CB_LOGIC_OP,
MESA_VK_DYNAMIC_CB_COLOR_WRITE_ENABLES,
MESA_VK_DYNAMIC_CB_BLEND_ENABLES,
MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS,
MESA_VK_DYNAMIC_CB_WRITE_MASKS,
MESA_VK_DYNAMIC_CB_BLEND_CONSTANTS,
MESA_VK_DYNAMIC_ATTACHMENT_FEEDBACK_LOOP_ENABLE,
/* Must be left at the end */
MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX,
};
/** Populate a bitset with dynamic states
*
* This function maps a VkPipelineDynamicStateCreateInfo to a bitset indexed
* by mesa_vk_dynamic_graphics_state enumerants.
*
* @param[out] dynamic Bitset to populate
* @param[in] info VkPipelineDynamicStateCreateInfo or NULL
*/
void
vk_get_dynamic_graphics_states(BITSET_WORD *dynamic,
const VkPipelineDynamicStateCreateInfo *info);
struct vk_vertex_binding_state {
/** VkVertexInputBindingDescription::stride */
uint16_t stride;
/** VkVertexInputBindingDescription::inputRate */
uint16_t input_rate;
/** VkVertexInputBindingDivisorDescriptionEXT::divisor or 1 */
uint32_t divisor;
};
struct vk_vertex_attribute_state {
/** VkVertexInputAttributeDescription::binding */
uint32_t binding;
/** VkVertexInputAttributeDescription::format */
VkFormat format;
/** VkVertexInputAttributeDescription::offset */
uint32_t offset;
};
struct vk_vertex_input_state {
/** Bitset of which bindings are valid, indexed by binding */
uint32_t bindings_valid;
struct vk_vertex_binding_state bindings[MESA_VK_MAX_VERTEX_BINDINGS];
/** Bitset of which attributes are valid, indexed by location */
uint32_t attributes_valid;
struct vk_vertex_attribute_state attributes[MESA_VK_MAX_VERTEX_ATTRIBUTES];
};
struct vk_input_assembly_state {
/** VkPipelineInputAssemblyStateCreateInfo::topology
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_IA_PRIMITIVE_TOPOLOGY
*/
uint8_t primitive_topology;
/** VkPipelineInputAssemblyStateCreateInfo::primitiveRestartEnable
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_IA_PRIMITIVE_RESTART_ENABLE
*/
bool primitive_restart_enable;
};
struct vk_tessellation_state {
/** VkPipelineTessellationStateCreateInfo::patchControlPoints
*
* MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS
*/
uint8_t patch_control_points;
/** VkPipelineTessellationDomainOriginStateCreateInfo::domainOrigin
*
* MESA_VK_DYNAMIC_TS_DOMAIN_ORIGIN
*/
uint8_t domain_origin;
};
struct vk_viewport_state {
/** VkPipelineViewportDepthClipControlCreateInfoEXT::negativeOneToOne
*/
bool depth_clip_negative_one_to_one;
/** VkPipelineViewportStateCreateInfo::viewportCount
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_VIEWPORT_COUNT
*/
uint8_t viewport_count;
/** VkPipelineViewportStateCreateInfo::scissorCount
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_SCISSOR_COUNT
*/
uint8_t scissor_count;
/** VkPipelineViewportStateCreateInfo::pViewports
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_VIEWPORTS
*/
VkViewport viewports[MESA_VK_MAX_VIEWPORTS];
/** VkPipelineViewportStateCreateInfo::pScissors
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_SCISSORS
*/
VkRect2D scissors[MESA_VK_MAX_SCISSORS];
};
struct vk_discard_rectangles_state {
/** VkPipelineDiscardRectangleStateCreateInfoEXT::discardRectangleMode */
VkDiscardRectangleModeEXT mode;
/** VkPipelineDiscardRectangleStateCreateInfoEXT::discardRectangleCount */
uint32_t rectangle_count;
/** VkPipelineDiscardRectangleStateCreateInfoEXT::pDiscardRectangles */
VkRect2D rectangles[MESA_VK_MAX_DISCARD_RECTANGLES];
};
enum PACKED vk_mesa_depth_clip_enable {
/** Depth clipping should be disabled */
VK_MESA_DEPTH_CLIP_ENABLE_FALSE = 0,
/** Depth clipping should be enabled */
VK_MESA_DEPTH_CLIP_ENABLE_TRUE = 1,
/** Depth clipping should be enabled iff depth clamping is disabled */
VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP,
};
struct vk_rasterization_state {
/** VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable
*
* This will be false if rasterizer discard is dynamic
*
* MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE
*/
bool rasterizer_discard_enable;
/** VkPipelineRasterizationStateCreateInfo::depthClampEnable
*
* MESA_VK_DYNAMIC_RS_DEPTH_CLAMP_ENABLE
*/
bool depth_clamp_enable;
/** VkPipelineRasterizationDepthClipStateCreateInfoEXT::depthClipEnable
*
* MESA_VK_DYNAMIC_RS_DEPTH_CLIP_ENABLE
*/
enum vk_mesa_depth_clip_enable depth_clip_enable;
/** VkPipelineRasterizationStateCreateInfo::polygonMode
*
* MESA_VK_DYNAMIC_RS_POLYGON_MODE_ENABLEDEPTH_CLIP_ENABLE
*/
VkPolygonMode polygon_mode;
/** VkPipelineRasterizationStateCreateInfo::cullMode
*
* MESA_VK_DYNAMIC_RS_CULL_MODE
*/
VkCullModeFlags cull_mode;
/** VkPipelineRasterizationStateCreateInfo::frontFace
*
* MESA_VK_DYNAMIC_RS_FRONT_FACE
*/
VkFrontFace front_face;
/** VkPipelineRasterizationConservativeStateCreateInfoEXT::conservativeRasterizationMode
*
* MESA_VK_DYNAMIC_RS_CONSERVATIVE_MODE
*/
VkConservativeRasterizationModeEXT conservative_mode;
/** VkPipelineRasterizationConservativeStateCreateInfoEXT::extraPrimitiveOverestimationSize
*
* MESA_VK_DYNAMIC_RS_EXTRA_PRIMITIVE_OVERESTIMATION_SIZE
*/
float extra_primitive_overestimation_size;
/** VkPipelineRasterizationStateRasterizationOrderAMD::rasterizationOrder */
VkRasterizationOrderAMD rasterization_order_amd;
/** VkPipelineRasterizationProvokingVertexStateCreateInfoEXT::provokingVertexMode
*
* MESA_VK_DYNAMIC_RS_PROVOKING_VERTEX
*/
VkProvokingVertexModeEXT provoking_vertex;
/** VkPipelineRasterizationStateStreamCreateInfoEXT::rasterizationStream
*
* MESA_VK_DYNAMIC_RS_RASTERIZATION_STREAM
*/
uint32_t rasterization_stream;
struct {
/** VkPipelineRasterizationStateCreateInfo::depthBiasEnable
*
* MESA_VK_DYNAMIC_RS_DEPTH_BIAS_ENABLE
*/
bool enable;
/** VkPipelineRasterizationStateCreateInfo::depthBiasConstantFactor
*
* MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
*/
float constant;
/** VkPipelineRasterizationStateCreateInfo::depthBiasClamp
*
* MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
*/
float clamp;
/** VkPipelineRasterizationStateCreateInfo::depthBiasSlopeFactor
*
* MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS
*/
float slope;
} depth_bias;
struct {
/** VkPipelineRasterizationStateCreateInfo::lineWidth
*
* MESA_VK_DYNAMIC_RS_LINE_WIDTH
*/
float width;
/** VkPipelineRasterizationLineStateCreateInfoEXT::lineRasterizationMode
*
* Will be set to VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT if
* VkPipelineRasterizationLineStateCreateInfoEXT is not provided.
*
* MESA_VK_DYNAMIC_RS_LINE_MODE
*/
VkLineRasterizationModeEXT mode;
struct {
/** VkPipelineRasterizationLineStateCreateInfoEXT::stippledLineEnable
*
* MESA_VK_DYNAMIC_RS_LINE_STIPPLE_ENABLE
*/
bool enable;
/** VkPipelineRasterizationLineStateCreateInfoEXT::lineStippleFactor
*
* MESA_VK_DYNAMIC_RS_LINE_STIPPLE
*/
uint32_t factor;
/** VkPipelineRasterizationLineStateCreateInfoEXT::lineStipplePattern
*
* MESA_VK_DYNAMIC_RS_LINE_STIPPLE
*/
uint16_t pattern;
} stipple;
} line;
};
static inline bool
vk_rasterization_state_depth_clip_enable(const struct vk_rasterization_state *rs)
{
switch (rs->depth_clip_enable) {
case VK_MESA_DEPTH_CLIP_ENABLE_FALSE: return false;
case VK_MESA_DEPTH_CLIP_ENABLE_TRUE: return true;
case VK_MESA_DEPTH_CLIP_ENABLE_NOT_CLAMP: return !rs->depth_clamp_enable;
}
unreachable("Invalid depth clip enable");
}
struct vk_fragment_shading_rate_state {
/** VkPipelineFragmentShadingRateStateCreateInfoKHR::fragmentSize
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_FSR
*/
VkExtent2D fragment_size;
/** VkPipelineFragmentShadingRateStateCreateInfoKHR::combinerOps
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_FSR
*/
VkFragmentShadingRateCombinerOpKHR combiner_ops[2];
};
struct vk_sample_locations_state {
/** VkSampleLocationsInfoEXT::sampleLocationsPerPixel */
VkSampleCountFlagBits per_pixel;
/** VkSampleLocationsInfoEXT::sampleLocationGridSize */
VkExtent2D grid_size;
/** VkSampleLocationsInfoEXT::sampleLocations */
VkSampleLocationEXT locations[MESA_VK_MAX_SAMPLE_LOCATIONS];
};
struct vk_multisample_state {
/** VkPipelineMultisampleStateCreateInfo::rasterizationSamples */
VkSampleCountFlagBits rasterization_samples;
/** VkPipelineMultisampleStateCreateInfo::sampleShadingEnable */
bool sample_shading_enable;
/** VkPipelineMultisampleStateCreateInfo::minSampleShading */
float min_sample_shading;
/** VkPipelineMultisampleStateCreateInfo::pSampleMask */
uint16_t sample_mask;
/** VkPipelineMultisampleStateCreateInfo::alphaToCoverageEnable */
bool alpha_to_coverage_enable;
/** VkPipelineMultisampleStateCreateInfo::alphaToOneEnable */
bool alpha_to_one_enable;
/** VkPipelineSampleLocationsStateCreateInfoEXT::sampleLocationsEnable
*
* This will be true if sample locations enable dynamic.
*/
bool sample_locations_enable;
/** VkPipelineSampleLocationsStateCreateInfoEXT::sampleLocationsInfo
*
* May be NULL for dynamic sample locations.
*/
const struct vk_sample_locations_state *sample_locations;
};
/** Represents the stencil test state for a face */
struct vk_stencil_test_face_state {
/*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_OP
*/
struct {
/** VkStencilOpState::failOp */
uint8_t fail;
/** VkStencilOpState::passOp */
uint8_t pass;
/** VkStencilOpState::depthFailOp */
uint8_t depth_fail;
/** VkStencilOpState::compareOp */
uint8_t compare;
} op;
/** VkStencilOpState::compareMask
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_COMPARE_MASK
*/
uint8_t compare_mask;
/** VkStencilOpState::writeMask
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_WRITE_MASK
*/
uint8_t write_mask;
/** VkStencilOpState::reference
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_REFERENCE
*/
uint8_t reference;
};
struct vk_depth_stencil_state {
struct {
/** VkPipelineDepthStencilStateCreateInfo::depthTestEnable
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_TEST_ENABLE
*/
bool test_enable;
/** VkPipelineDepthStencilStateCreateInfo::depthWriteEnable
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_WRITE_ENABLE
*/
bool write_enable;
/** VkPipelineDepthStencilStateCreateInfo::depthCompareOp
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_COMPARE_OP
*/
VkCompareOp compare_op;
struct {
/** VkPipelineDepthStencilStateCreateInfo::depthBoundsTestEnable
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_BOUNDS_TEST_ENABLE
*/
bool enable;
/** VkPipelineDepthStencilStateCreateInfo::min/maxDepthBounds
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_BOUNDS_TEST_BOUNDS
*/
float min, max;
} bounds_test;
} depth;
struct {
/** VkPipelineDepthStencilStateCreateInfo::stencilTestEnable
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_TEST_ENABLE
*/
bool test_enable;
/** Whether or not stencil is should be written
*
* This does not map directly to any particular Vulkan API state and is
* initialized to true. If independent stencil disable ever becomes a
* thing, it will use this state. vk_optimize_depth_stencil_state() may
* set this to false if it can prove that the stencil test will never
* alter the stencil value.
*/
bool write_enable;
/** VkPipelineDepthStencilStateCreateInfo::front */
struct vk_stencil_test_face_state front;
/** VkPipelineDepthStencilStateCreateInfo::back */
struct vk_stencil_test_face_state back;
} stencil;
};
/** Optimize a depth/stencil state
*
* The way depth and stencil testing is specified, there are many case where,
* regardless of depth/stencil writes being enabled, nothing actually gets
* written due to some other bit of state being set. In the presence of
* discards, it's fairly easy to get into cases where early depth/stencil
* testing is disabled on some hardware, leading to a fairly big performance
* hit. This function attempts to optimize the depth stencil state and
* disable writes and sometimes even testing whenever possible.
*
* @param[inout] ds The depth stencil state to optimize
* @param[in] ds_aspects Which image aspects are present in the
* render pass.
* @param[in] consider_write_mask If true, the write mask will be taken
* into account when optimizing. If
* false, it will be ignored.
*/
void vk_optimize_depth_stencil_state(struct vk_depth_stencil_state *ds,
VkImageAspectFlags ds_aspects,
bool consider_write_mask);
struct vk_color_blend_attachment_state {
/** VkPipelineColorBlendAttachmentState::blendEnable
*
* This will be true if blend enables are dynamic
*
* MESA_VK_DYNAMIC_CB_BLEND_ENABLES
*/
bool blend_enable;
/** VkPipelineColorBlendAttachmentState::srcColorBlendFactor
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
uint8_t src_color_blend_factor;
/** VkPipelineColorBlendAttachmentState::dstColorBlendFactor
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
uint8_t dst_color_blend_factor;
/** VkPipelineColorBlendAttachmentState::srcAlphaBlendFactor
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
uint8_t src_alpha_blend_factor;
/** VkPipelineColorBlendAttachmentState::dstAlphaBlendFactor
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
uint8_t dst_alpha_blend_factor;
/** VkPipelineColorBlendAttachmentState::colorWriteMask
*
* MESA_VK_DYNAMIC_CB_WRITE_MASKS
*/
uint8_t write_mask;
/** VkPipelineColorBlendAttachmentState::colorBlendOp
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
VkBlendOp color_blend_op;
/** VkPipelineColorBlendAttachmentState::alphaBlendOp
*
* MESA_VK_DYNAMIC_CB_BLEND_EQUATIONS
*/
VkBlendOp alpha_blend_op;
};
struct vk_color_blend_state {
/** VkPipelineColorBlendStateCreateInfo::logicOpEnable
*
* MESA_VK_DYNAMIC_CB_LOGIC_OP_ENABLE,
*/
bool logic_op_enable;
/** VkPipelineColorBlendStateCreateInfo::logicOp
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_LOGIC_OP,
*/
uint8_t logic_op;
/** VkPipelineColorWriteCreateInfoEXT::pColorWriteEnables
*
* Bitmask of color write enables, indexed by color attachment index.
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_COLOR_WRITE_ENABLES,
*/
uint8_t color_write_enables;
/** VkPipelineColorBlendStateCreateInfo::attachmentCount
*/
uint8_t attachment_count;
/** VkPipelineColorBlendStateCreateInfo::pAttachments */
struct vk_color_blend_attachment_state attachments[MESA_VK_MAX_COLOR_ATTACHMENTS];
/** VkPipelineColorBlendStateCreateInfo::blendConstants
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_BLEND_CONSTANTS,
*/
float blend_constants[4];
};
struct vk_render_pass_state {
/** Set of image aspects bound as color/depth/stencil attachments
*
* Set to VK_IMAGE_ASPECT_METADATA_BIT to indicate that attachment info
* is invalid.
*/
VkImageAspectFlags attachment_aspects;
/** VkGraphicsPipelineCreateInfo::renderPass */
VkRenderPass render_pass;
/** VkGraphicsPipelineCreateInfo::subpass */
uint32_t subpass;
/** VkPipelineRenderingCreateInfo::viewMask */
uint32_t view_mask;
/** Render pass flags from VkGraphicsPipelineCreateInfo::flags
*
* For drivers which use vk_render_pass, this will also include flags
* generated based on subpass self-dependencies and fragment density map.
*/
VkPipelineCreateFlags pipeline_flags;
/** VkPipelineRenderingCreateInfo::colorAttachmentCount */
uint8_t color_attachment_count;
/** VkPipelineRenderingCreateInfo::pColorAttachmentFormats */
VkFormat color_attachment_formats[MESA_VK_MAX_COLOR_ATTACHMENTS];
/** VkPipelineRenderingCreateInfo::depthAttachmentFormat */
VkFormat depth_attachment_format;
/** VkPipelineRenderingCreateInfo::stencilAttachmentFormat */
VkFormat stencil_attachment_format;
/** VkAttachmentSampleCountInfoAMD::pColorAttachmentSamples */
uint8_t color_attachment_samples[MESA_VK_MAX_COLOR_ATTACHMENTS];
/** VkAttachmentSampleCountInfoAMD::depthStencilAttachmentSamples */
uint8_t depth_stencil_attachment_samples;
};
/** Struct representing all dynamic graphics state
*
* Before invoking any core functions, the driver must properly populate
* initialize this struct:
*
* - Initialize using vk_default_dynamic_graphics_state, if desired
* - Set vi to a driver-allocated vk_vertex_input_state struct
* - Set ms.sample_locations to a driver-allocated
* vk_sample_locations_state struct
*/
struct vk_dynamic_graphics_state {
/** Vertex input state
*
* Must be provided by the driver if VK_EXT_vertex_input_dynamic_state is
* supported.
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VI
*/
struct vk_vertex_input_state *vi;
/** Vertex binding strides
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_VI_BINDING_STRIDES
*/
uint16_t vi_binding_strides[MESA_VK_MAX_VERTEX_BINDINGS];
/** Input assembly state */
struct vk_input_assembly_state ia;
/** Tessellation state */
struct vk_tessellation_state ts;
/** Viewport state */
struct vk_viewport_state vp;
/** Discard rectangles state */
struct {
/** Custom enable
*
* MESA_VK_DYNAMIC_DR_ENABLE
*/
bool enable;
/** Mode
*
* MESA_VK_DYNAMIC_DR_MODE
*/
VkDiscardRectangleModeEXT mode;
/** Rectangles
*
* MESA_VK_DYNAMIC_DR_RECTANGLES
*/
VkRect2D rectangles[MESA_VK_MAX_DISCARD_RECTANGLES];
/** Number of rectangles
*
* MESA_VK_DYNAMIC_GRAPHICS_STATE_DR_RECTANGLES
*/
uint32_t rectangle_count;
} dr;
/** Rasterization state */
struct vk_rasterization_state rs;
/* Fragment shading rate state */
struct vk_fragment_shading_rate_state fsr;
/** Multisample state */
struct {
/** Rasterization samples
*
* MESA_VK_DYNAMIC_MS_RASTERIZATION_SAMPLES
*/
VkSampleCountFlagBits rasterization_samples;
/** Sample mask
*
* MESA_VK_DYNAMIC_MS_SAMPLE_MASK
*/
uint16_t sample_mask;
/** Alpha to coverage enable
*
* MESA_VK_DYNAMIC_MS_ALPHA_TO_CONVERAGE_ENABLE
*/
bool alpha_to_coverage_enable;
/** Alpha to one enable
*
* MESA_VK_DYNAMIC_MS_ALPHA_TO_ONE_ENABLE
*/
bool alpha_to_one_enable;
/** Custom sample locations enable
*
* MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS_ENABLE
*/
bool sample_locations_enable;
/** Sample locations
*
* Must be provided by the driver if VK_EXT_sample_locations is
* supported.
*
* MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS
*/
struct vk_sample_locations_state *sample_locations;
} ms;
/** Depth stencil state */
struct vk_depth_stencil_state ds;
/** Color blend state */
struct vk_color_blend_state cb;
/** For pipelines, which bits of dynamic state are set */
BITSET_DECLARE(set, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
/** For command buffers, which bits of dynamic state have changed */
BITSET_DECLARE(dirty, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
};
struct vk_graphics_pipeline_all_state {
struct vk_vertex_input_state vi;
struct vk_input_assembly_state ia;
struct vk_tessellation_state ts;
struct vk_viewport_state vp;
struct vk_discard_rectangles_state dr;
struct vk_rasterization_state rs;
struct vk_fragment_shading_rate_state fsr;
struct vk_multisample_state ms;
struct vk_sample_locations_state ms_sample_locations;
struct vk_depth_stencil_state ds;
struct vk_color_blend_state cb;
struct vk_render_pass_state rp;
};
struct vk_graphics_pipeline_state {
/** Bitset of which states are dynamic */
BITSET_DECLARE(dynamic, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX);
VkShaderStageFlags shader_stages;
/** Vertex input state */
const struct vk_vertex_input_state *vi;
/** Input assembly state */
const struct vk_input_assembly_state *ia;
/** Tessellation state */
const struct vk_tessellation_state *ts;
/** Viewport state */
const struct vk_viewport_state *vp;
/** Discard Rectangles state */
const struct vk_discard_rectangles_state *dr;
/** Rasterization state */
const struct vk_rasterization_state *rs;
/** Fragment shading rate state */
const struct vk_fragment_shading_rate_state *fsr;
/** Multiesample state */
const struct vk_multisample_state *ms;
/** Depth stencil state */
const struct vk_depth_stencil_state *ds;
/** Color blend state */
const struct vk_color_blend_state *cb;
/** Render pass state */
const struct vk_render_pass_state *rp;
};
/** Struct for extra information that we need from the subpass.
*
* This struct need only be provided if the driver has its own render pass
* implementation. If the driver uses the common render pass implementation,
* we can get this information ourselves.
*/
struct vk_subpass_info {
/** VkSubpassDescription2::viewMask */
uint32_t view_mask;
/**
* Aspects of all attachments used as color or depth/stencil attachments
* in the subpass. Input and resolve attachments should not be considered
* when computing the attachments aspect mask. This is used to determine
* whether or not depth/stencil and color blend state are required for a
* pipeline.
*/
VkImageAspectFlags attachment_aspects;
};
/** Populate a vk_graphics_pipeline_state from VkGraphicsPipelineCreateInfo
*
* This function crawls the provided VkGraphicsPipelineCreateInfo and uses it
* to populate the vk_graphics_pipeline_state. Upon returning from this
* function, all pointers in `state` will either be `NULL` or point to a valid
* sub-state structure. Whenever an extension struct is missing, a reasonable
* default value is provided whenever possible. Some states may be left NULL
* if the state does not exist (such as when rasterizer discard is enabled) or
* if all of the corresponding states are dynamic.
*
* This function assumes that the vk_graphics_pipeline_state is already valid
* (i.e., all pointers are NULL or point to valid states). Any states already
* present are assumed to be identical to how we would populate them from
* VkGraphicsPipelineCreateInfo.
*
* This function can operate in one of two modes with respect to how the
* memory for states is allocated. If a `vk_graphics_pipeline_all_state`
* struct is provided, any newly populated states will point to the relevant
* field in `all`. If `all == NULL`, it attempts to dynamically allocate any
* newly required states using the provided allocator and scope. The pointer
* to this new blob of memory is returned via `alloc_ptr_out` and must
* eventually be freed by the driver.
*
* @param[in] device The Vulkan device
* @param[out] state The graphics pipeline state to populate
* @param[in] info The pCreateInfo from vkCreateGraphicsPipelines
* @param[in] sp_info Subpass info if the driver implements render
* passes itself. This should be NULL for drivers
* that use the common render pass infrastructure
* built on top of dynamic rendering.
* @param[in] all The vk_graphics_pipeline_all_state to use to
* back any newly needed states. If NULL, newly
* needed states will be dynamically allocated
* instead.
* @param[in] alloc Allocation callbacks for dynamically allocating
* new state memory.
* @param[in] scope Allocation scope for dynamically allocating new
* state memory.
* @param[out] alloc_ptr_out Will be populated with a pointer to any newly
* allocated state. The driver is responsible for
* freeing this pointer.
*/
VkResult
vk_graphics_pipeline_state_fill(const struct vk_device *device,
struct vk_graphics_pipeline_state *state,
const VkGraphicsPipelineCreateInfo *info,
const struct vk_subpass_info *sp_info,
struct vk_graphics_pipeline_all_state *all,
const VkAllocationCallbacks *alloc,
VkSystemAllocationScope scope,
void **alloc_ptr_out);
/** Merge one vk_graphics_pipeline_state into another
*
* Both the destination and source states are assumed to be valid (i.e., all
* pointers are NULL or point to valid states). Any states which exist in
* both are expected to be identical and the state already in dst is used.
* The only exception here is render pass state which may be only partially
* defined in which case the fully defined one (if any) is used.
*
* @param[out] dst The destination state. When the function returns, this
* will be the union of the original dst and src.
* @param[in] src The source state
*/
void
vk_graphics_pipeline_state_merge(struct vk_graphics_pipeline_state *dst,
const struct vk_graphics_pipeline_state *src);
extern const struct vk_dynamic_graphics_state vk_default_dynamic_graphics_state;
/** Initialize a vk_dynamic_graphics_state with defaults
*
* @param[out] dyn Dynamic graphics state to initizlie
*/
void
vk_dynamic_graphics_state_init(struct vk_dynamic_graphics_state *dyn);
/** Clear a vk_dynamic_graphics_state to defaults
*
* @param[out] dyn Dynamic graphics state to initizlie
*/
void
vk_dynamic_graphics_state_clear(struct vk_dynamic_graphics_state *dyn);
/** Initialize a vk_dynamic_graphics_state for a pipeline
*
* @param[out] dyn Dynamic graphics state to initizlie
* @param[in] supported Bitset of all dynamic state supported by the driver.
* @param[in] p The pipeline state from which to initialize the
* dynamic state.
*/
void
vk_dynamic_graphics_state_fill(struct vk_dynamic_graphics_state *dyn,
const struct vk_graphics_pipeline_state *p);
/** Mark all states in the given vk_dynamic_graphics_state dirty
*
* @param[out] d Dynamic graphics state struct
*/
static inline void
vk_dynamic_graphics_state_dirty_all(struct vk_dynamic_graphics_state *d)
{
BITSET_SET_RANGE(d->dirty, 0, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX - 1);
}
/** Mark all states in the given vk_dynamic_graphics_state not dirty
*
* @param[out] d Dynamic graphics state struct
*/
static inline void
vk_dynamic_graphics_state_clear_dirty(struct vk_dynamic_graphics_state *d)
{
BITSET_ZERO(d->dirty);
}
/** Test if any states in the given vk_dynamic_graphics_state are dirty
*
* @param[in] d Dynamic graphics state struct to test
* @returns true if any state is dirty
*/
static inline bool
vk_dynamic_graphics_state_any_dirty(const struct vk_dynamic_graphics_state *d)
{
return BITSET_TEST_RANGE(d->dirty,
0, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX - 1);
}
/** Copies all set state from src to dst
*
* Both src and dst are assumed to be properly initialized dynamic state
* structs. Anything not set in src, as indicated by src->set, is ignored and
* those bits of dst are left untouched.
*
* @param[out] dst Copy destination
* @param[in] src Copy source
*/
void
vk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state *dst,
const struct vk_dynamic_graphics_state *src);
/** Set all of the state in src on a command buffer
*
* Anything not set, as indicated by src->set, is ignored and those states in
* the command buffer are left untouched.
*
* @param[inout] cmd Command buffer to update
* @param[in] src State to set
*/
void
vk_cmd_set_dynamic_graphics_state(struct vk_command_buffer *cmd,
const struct vk_dynamic_graphics_state *src);
/** Set vertex binding strides on a command buffer
*
* This is the dynamic state part of vkCmdBindVertexBuffers2().
*
* @param[inout] cmd Command buffer to update
* @param[in] first_binding First binding to update
* @param[in] binding_count Number of bindings to update
* @param[in] strides binding_count many stride values to set
*/
void
vk_cmd_set_vertex_binding_strides(struct vk_command_buffer *cmd,
uint32_t first_binding,
uint32_t binding_count,
const VkDeviceSize *strides);
#ifdef __cplusplus
}
#endif
#endif /* VK_GRAPHICS_STATE_H */
|