1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2022 Collabora, Ltd 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#ifndef VK_GRAPHICS_STATE_H 25bf215546Sopenharmony_ci#define VK_GRAPHICS_STATE_H 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_ci#include "vulkan/vulkan_core.h" 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci#include "vk_limits.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci#include "util/bitset.h" 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_ci#ifdef __cplusplus 34bf215546Sopenharmony_ciextern "C" { 35bf215546Sopenharmony_ci#endif 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_cistruct vk_command_buffer; 38bf215546Sopenharmony_cistruct vk_device; 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci/** Enumeration of all Vulkan dynamic graphics states 41bf215546Sopenharmony_ci * 42bf215546Sopenharmony_ci * Enumerants are named with both the abreviation of the state group to which 43bf215546Sopenharmony_ci * the state belongs as well as the name of the state itself. These are 44bf215546Sopenharmony_ci * intended to pretty closely match the VkDynamicState enum but may not match 45bf215546Sopenharmony_ci * perfectly all the time. 46bf215546Sopenharmony_ci */ 47bf215546Sopenharmony_cienum mesa_vk_dynamic_graphics_state { 48bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VI, 49bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VI_BINDING_STRIDES, 50bf215546Sopenharmony_ci MESA_VK_DYNAMIC_IA_PRIMITIVE_TOPOLOGY, 51bf215546Sopenharmony_ci MESA_VK_DYNAMIC_IA_PRIMITIVE_RESTART_ENABLE, 52bf215546Sopenharmony_ci MESA_VK_DYNAMIC_TS_PATCH_CONTROL_POINTS, 53bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VP_VIEWPORT_COUNT, 54bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VP_VIEWPORTS, 55bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VP_SCISSOR_COUNT, 56bf215546Sopenharmony_ci MESA_VK_DYNAMIC_VP_SCISSORS, 57bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DR_RECTANGLES, 58bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_RASTERIZER_DISCARD_ENABLE, 59bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_CULL_MODE, 60bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_FRONT_FACE, 61bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_DEPTH_BIAS_ENABLE, 62bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_DEPTH_BIAS_FACTORS, 63bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_LINE_WIDTH, 64bf215546Sopenharmony_ci MESA_VK_DYNAMIC_RS_LINE_STIPPLE, 65bf215546Sopenharmony_ci MESA_VK_DYNAMIC_FSR, 66bf215546Sopenharmony_ci MESA_VK_DYNAMIC_MS_SAMPLE_LOCATIONS, 67bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_DEPTH_TEST_ENABLE, 68bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_DEPTH_WRITE_ENABLE, 69bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_DEPTH_COMPARE_OP, 70bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_ENABLE, 71bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_DEPTH_BOUNDS_TEST_BOUNDS, 72bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_STENCIL_TEST_ENABLE, 73bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_STENCIL_OP, 74bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_STENCIL_COMPARE_MASK, 75bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_STENCIL_WRITE_MASK, 76bf215546Sopenharmony_ci MESA_VK_DYNAMIC_DS_STENCIL_REFERENCE, 77bf215546Sopenharmony_ci MESA_VK_DYNAMIC_CB_LOGIC_OP, 78bf215546Sopenharmony_ci MESA_VK_DYNAMIC_CB_COLOR_WRITE_ENABLES, 79bf215546Sopenharmony_ci MESA_VK_DYNAMIC_CB_BLEND_CONSTANTS, 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci /* Must be left at the end */ 82bf215546Sopenharmony_ci MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX, 83bf215546Sopenharmony_ci}; 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci/** Populate a bitset with dynamic states 86bf215546Sopenharmony_ci * 87bf215546Sopenharmony_ci * This function maps a VkPipelineDynamicStateCreateInfo to a bitset indexed 88bf215546Sopenharmony_ci * by mesa_vk_dynamic_graphics_state enumerants. 89bf215546Sopenharmony_ci * 90bf215546Sopenharmony_ci * @param[out] dynamic Bitset to populate 91bf215546Sopenharmony_ci * @param[in] info VkPipelineDynamicStateCreateInfo or NULL 92bf215546Sopenharmony_ci */ 93bf215546Sopenharmony_civoid 94bf215546Sopenharmony_civk_get_dynamic_graphics_states(BITSET_WORD *dynamic, 95bf215546Sopenharmony_ci const VkPipelineDynamicStateCreateInfo *info); 96bf215546Sopenharmony_ci 97bf215546Sopenharmony_cistruct vk_vertex_binding_state { 98bf215546Sopenharmony_ci /** VkVertexInputBindingDescription::stride */ 99bf215546Sopenharmony_ci uint16_t stride; 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci /** VkVertexInputBindingDescription::inputRate */ 102bf215546Sopenharmony_ci uint16_t input_rate; 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci /** VkVertexInputBindingDivisorDescriptionEXT::divisor or 1 */ 105bf215546Sopenharmony_ci uint32_t divisor; 106bf215546Sopenharmony_ci}; 107bf215546Sopenharmony_ci 108bf215546Sopenharmony_cistruct vk_vertex_attribute_state { 109bf215546Sopenharmony_ci /** VkVertexInputAttributeDescription::binding */ 110bf215546Sopenharmony_ci uint32_t binding; 111bf215546Sopenharmony_ci 112bf215546Sopenharmony_ci /** VkVertexInputAttributeDescription::format */ 113bf215546Sopenharmony_ci VkFormat format; 114bf215546Sopenharmony_ci 115bf215546Sopenharmony_ci /** VkVertexInputAttributeDescription::offset */ 116bf215546Sopenharmony_ci uint32_t offset; 117bf215546Sopenharmony_ci}; 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_cistruct vk_vertex_input_state { 120bf215546Sopenharmony_ci /** Bitset of which bindings are valid, indexed by binding */ 121bf215546Sopenharmony_ci uint32_t bindings_valid; 122bf215546Sopenharmony_ci struct vk_vertex_binding_state bindings[MESA_VK_MAX_VERTEX_BINDINGS]; 123bf215546Sopenharmony_ci 124bf215546Sopenharmony_ci /** Bitset of which attributes are valid, indexed by location */ 125bf215546Sopenharmony_ci uint32_t attributes_valid; 126bf215546Sopenharmony_ci struct vk_vertex_attribute_state attributes[MESA_VK_MAX_VERTEX_ATTRIBUTES]; 127bf215546Sopenharmony_ci}; 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_cistruct vk_input_assembly_state { 130bf215546Sopenharmony_ci /** VkPipelineInputAssemblyStateCreateInfo::topology 131bf215546Sopenharmony_ci * 132bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_IA_PRIMITIVE_TOPOLOGY 133bf215546Sopenharmony_ci */ 134bf215546Sopenharmony_ci uint8_t primitive_topology; 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci /** VkPipelineInputAssemblyStateCreateInfo::primitiveRestartEnable 137bf215546Sopenharmony_ci * 138bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_IA_PRIMITIVE_RESTART_ENABLE 139bf215546Sopenharmony_ci */ 140bf215546Sopenharmony_ci bool primitive_restart_enable; 141bf215546Sopenharmony_ci}; 142bf215546Sopenharmony_ci 143bf215546Sopenharmony_cistruct vk_tessellation_state { 144bf215546Sopenharmony_ci /** VkPipelineTessellationStateCreateInfo::patchControlPoints */ 145bf215546Sopenharmony_ci uint8_t patch_control_points; 146bf215546Sopenharmony_ci 147bf215546Sopenharmony_ci /** VkPipelineTessellationDomainOriginStateCreateInfo::domainOrigin */ 148bf215546Sopenharmony_ci uint8_t domain_origin; 149bf215546Sopenharmony_ci}; 150bf215546Sopenharmony_ci 151bf215546Sopenharmony_cistruct vk_viewport_state { 152bf215546Sopenharmony_ci /** VkPipelineViewportDepthClipControlCreateInfoEXT::negativeOneToOne */ 153bf215546Sopenharmony_ci bool negative_one_to_one; 154bf215546Sopenharmony_ci 155bf215546Sopenharmony_ci /** VkPipelineViewportStateCreateInfo::viewportCount */ 156bf215546Sopenharmony_ci uint8_t viewport_count; 157bf215546Sopenharmony_ci 158bf215546Sopenharmony_ci /** VkPipelineViewportStateCreateInfo::scissorCount */ 159bf215546Sopenharmony_ci uint8_t scissor_count; 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci /** VkPipelineViewportStateCreateInfo::pViewports */ 162bf215546Sopenharmony_ci VkRect2D scissors[MESA_VK_MAX_SCISSORS]; 163bf215546Sopenharmony_ci 164bf215546Sopenharmony_ci /** VkPipelineViewportStateCreateInfo::pScissors */ 165bf215546Sopenharmony_ci VkViewport viewports[MESA_VK_MAX_VIEWPORTS]; 166bf215546Sopenharmony_ci}; 167bf215546Sopenharmony_ci 168bf215546Sopenharmony_cistruct vk_discard_rectangles_state { 169bf215546Sopenharmony_ci /** VkPipelineDiscardRectangleStateCreateInfoEXT::discardRectangleMode */ 170bf215546Sopenharmony_ci VkDiscardRectangleModeEXT mode; 171bf215546Sopenharmony_ci 172bf215546Sopenharmony_ci /** VkPipelineDiscardRectangleStateCreateInfoEXT::discardRectangleCount */ 173bf215546Sopenharmony_ci uint32_t rectangle_count; 174bf215546Sopenharmony_ci 175bf215546Sopenharmony_ci /** VkPipelineDiscardRectangleStateCreateInfoEXT::pDiscardRectangles */ 176bf215546Sopenharmony_ci VkRect2D rectangles[MESA_VK_MAX_DISCARD_RECTANGLES]; 177bf215546Sopenharmony_ci}; 178bf215546Sopenharmony_ci 179bf215546Sopenharmony_cistruct vk_rasterization_state { 180bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::rasterizerDiscardEnable 181bf215546Sopenharmony_ci * 182bf215546Sopenharmony_ci * This will be false if rasterizer discard is dynamic 183bf215546Sopenharmony_ci */ 184bf215546Sopenharmony_ci bool rasterizer_discard_enable; 185bf215546Sopenharmony_ci 186bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::depthClampEnable */ 187bf215546Sopenharmony_ci bool depth_clamp_enable; 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci /** VkPipelineRasterizationDepthClipStateCreateInfoEXT::depthClipEnable */ 190bf215546Sopenharmony_ci bool depth_clip_enable; 191bf215546Sopenharmony_ci 192bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::polygonMode */ 193bf215546Sopenharmony_ci VkPolygonMode polygon_mode; 194bf215546Sopenharmony_ci 195bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::cullMode */ 196bf215546Sopenharmony_ci VkCullModeFlags cull_mode; 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::frontFace */ 199bf215546Sopenharmony_ci VkFrontFace front_face; 200bf215546Sopenharmony_ci 201bf215546Sopenharmony_ci /** VkPipelineRasterizationConservativeStateCreateInfoEXT::conservativeRasterizationMode */ 202bf215546Sopenharmony_ci VkConservativeRasterizationModeEXT conservative_mode; 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci /** VkPipelineRasterizationStateRasterizationOrderAMD::rasterizationOrder */ 205bf215546Sopenharmony_ci VkRasterizationOrderAMD rasterization_order_amd; 206bf215546Sopenharmony_ci 207bf215546Sopenharmony_ci /** VkPipelineRasterizationProvokingVertexStateCreateInfoEXT::provokingVertexMode */ 208bf215546Sopenharmony_ci VkProvokingVertexModeEXT provoking_vertex; 209bf215546Sopenharmony_ci 210bf215546Sopenharmony_ci /** VkPipelineRasterizationStateStreamCreateInfoEXT::rasterizationStream */ 211bf215546Sopenharmony_ci uint32_t rasterization_stream; 212bf215546Sopenharmony_ci 213bf215546Sopenharmony_ci struct { 214bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::depthBiasEnable */ 215bf215546Sopenharmony_ci bool enable; 216bf215546Sopenharmony_ci 217bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::depthBiasConstantFactor */ 218bf215546Sopenharmony_ci float constant; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::depthBiasClamp */ 221bf215546Sopenharmony_ci float clamp; 222bf215546Sopenharmony_ci 223bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::depthBiasSlopeFactor */ 224bf215546Sopenharmony_ci float slope; 225bf215546Sopenharmony_ci } depth_bias; 226bf215546Sopenharmony_ci 227bf215546Sopenharmony_ci struct { 228bf215546Sopenharmony_ci /** VkPipelineRasterizationStateCreateInfo::lineWidth */ 229bf215546Sopenharmony_ci float width; 230bf215546Sopenharmony_ci 231bf215546Sopenharmony_ci /** VkPipelineRasterizationLineStateCreateInfoEXT::lineRasterizationMode 232bf215546Sopenharmony_ci * 233bf215546Sopenharmony_ci * Will be set to VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT if 234bf215546Sopenharmony_ci * VkPipelineRasterizationLineStateCreateInfoEXT is not provided. 235bf215546Sopenharmony_ci */ 236bf215546Sopenharmony_ci VkLineRasterizationModeEXT mode; 237bf215546Sopenharmony_ci 238bf215546Sopenharmony_ci struct { 239bf215546Sopenharmony_ci /** VkPipelineRasterizationLineStateCreateInfoEXT::stippledLineEnable */ 240bf215546Sopenharmony_ci bool enable; 241bf215546Sopenharmony_ci 242bf215546Sopenharmony_ci /** VkPipelineRasterizationLineStateCreateInfoEXT::lineStippleFactor */ 243bf215546Sopenharmony_ci uint32_t factor; 244bf215546Sopenharmony_ci 245bf215546Sopenharmony_ci /** VkPipelineRasterizationLineStateCreateInfoEXT::lineStipplePattern */ 246bf215546Sopenharmony_ci uint16_t pattern; 247bf215546Sopenharmony_ci } stipple; 248bf215546Sopenharmony_ci } line; 249bf215546Sopenharmony_ci}; 250bf215546Sopenharmony_ci 251bf215546Sopenharmony_cistruct vk_fragment_shading_rate_state { 252bf215546Sopenharmony_ci /** VkPipelineFragmentShadingRateStateCreateInfoKHR::fragmentSize 253bf215546Sopenharmony_ci * 254bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_FSR 255bf215546Sopenharmony_ci */ 256bf215546Sopenharmony_ci VkExtent2D fragment_size; 257bf215546Sopenharmony_ci 258bf215546Sopenharmony_ci /** VkPipelineFragmentShadingRateStateCreateInfoKHR::combinerOps 259bf215546Sopenharmony_ci * 260bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_FSR 261bf215546Sopenharmony_ci */ 262bf215546Sopenharmony_ci VkFragmentShadingRateCombinerOpKHR combiner_ops[2]; 263bf215546Sopenharmony_ci}; 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_cistruct vk_sample_locations_state { 266bf215546Sopenharmony_ci /** VkSampleLocationsInfoEXT::sampleLocationsPerPixel */ 267bf215546Sopenharmony_ci VkSampleCountFlagBits per_pixel; 268bf215546Sopenharmony_ci 269bf215546Sopenharmony_ci /** VkSampleLocationsInfoEXT::sampleLocationGridSize */ 270bf215546Sopenharmony_ci VkExtent2D grid_size; 271bf215546Sopenharmony_ci 272bf215546Sopenharmony_ci /** VkSampleLocationsInfoEXT::sampleLocations */ 273bf215546Sopenharmony_ci VkSampleLocationEXT locations[MESA_VK_MAX_SAMPLE_LOCATIONS]; 274bf215546Sopenharmony_ci}; 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_cistruct vk_multisample_state { 277bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::rasterizationSamples */ 278bf215546Sopenharmony_ci VkSampleCountFlagBits rasterization_samples; 279bf215546Sopenharmony_ci 280bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::sampleShadingEnable */ 281bf215546Sopenharmony_ci bool sample_shading_enable; 282bf215546Sopenharmony_ci 283bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::minSampleShading */ 284bf215546Sopenharmony_ci float min_sample_shading; 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::pSampleMask */ 287bf215546Sopenharmony_ci uint16_t sample_mask; 288bf215546Sopenharmony_ci 289bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::alphaToCoverageEnable */ 290bf215546Sopenharmony_ci bool alpha_to_coverage_enable; 291bf215546Sopenharmony_ci 292bf215546Sopenharmony_ci /** VkPipelineMultisampleStateCreateInfo::alphaToOneEnable */ 293bf215546Sopenharmony_ci bool alpha_to_one_enable; 294bf215546Sopenharmony_ci 295bf215546Sopenharmony_ci /** VkPipelineSampleLocationsStateCreateInfoEXT::sampleLocationsEnable */ 296bf215546Sopenharmony_ci bool sample_locations_enable; 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci /** VkPipelineSampleLocationsStateCreateInfoEXT::sampleLocationsInfo 299bf215546Sopenharmony_ci * 300bf215546Sopenharmony_ci * May be NULL for dynamic sample locations. 301bf215546Sopenharmony_ci */ 302bf215546Sopenharmony_ci const struct vk_sample_locations_state *sample_locations; 303bf215546Sopenharmony_ci}; 304bf215546Sopenharmony_ci 305bf215546Sopenharmony_ci/** Represents the stencil test state for a face */ 306bf215546Sopenharmony_cistruct vk_stencil_test_face_state { 307bf215546Sopenharmony_ci /* 308bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_OP 309bf215546Sopenharmony_ci */ 310bf215546Sopenharmony_ci struct { 311bf215546Sopenharmony_ci /** VkStencilOpState::failOp */ 312bf215546Sopenharmony_ci uint8_t fail; 313bf215546Sopenharmony_ci 314bf215546Sopenharmony_ci /** VkStencilOpState::passOp */ 315bf215546Sopenharmony_ci uint8_t pass; 316bf215546Sopenharmony_ci 317bf215546Sopenharmony_ci /** VkStencilOpState::depthFailOp */ 318bf215546Sopenharmony_ci uint8_t depth_fail; 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ci /** VkStencilOpState::compareOp */ 321bf215546Sopenharmony_ci uint8_t compare; 322bf215546Sopenharmony_ci } op; 323bf215546Sopenharmony_ci 324bf215546Sopenharmony_ci /** VkStencilOpState::compareMask 325bf215546Sopenharmony_ci * 326bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_COMPARE_MASK 327bf215546Sopenharmony_ci */ 328bf215546Sopenharmony_ci uint8_t compare_mask; 329bf215546Sopenharmony_ci 330bf215546Sopenharmony_ci /** VkStencilOpState::writeMask 331bf215546Sopenharmony_ci * 332bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_WRITE_MASK 333bf215546Sopenharmony_ci */ 334bf215546Sopenharmony_ci uint8_t write_mask; 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci /** VkStencilOpState::reference 337bf215546Sopenharmony_ci * 338bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_REFERENCE 339bf215546Sopenharmony_ci */ 340bf215546Sopenharmony_ci uint8_t reference; 341bf215546Sopenharmony_ci}; 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_cistruct vk_depth_stencil_state { 344bf215546Sopenharmony_ci struct { 345bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::depthTestEnable 346bf215546Sopenharmony_ci * 347bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_TEST_ENABLE 348bf215546Sopenharmony_ci */ 349bf215546Sopenharmony_ci bool test_enable; 350bf215546Sopenharmony_ci 351bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::depthWriteEnable 352bf215546Sopenharmony_ci * 353bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_WRITE_ENABLE 354bf215546Sopenharmony_ci */ 355bf215546Sopenharmony_ci bool write_enable; 356bf215546Sopenharmony_ci 357bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::depthCompareOp 358bf215546Sopenharmony_ci * 359bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_COMPARE_OP 360bf215546Sopenharmony_ci */ 361bf215546Sopenharmony_ci VkCompareOp compare_op; 362bf215546Sopenharmony_ci 363bf215546Sopenharmony_ci struct { 364bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::depthBoundsTestEnable 365bf215546Sopenharmony_ci * 366bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_BOUNDS_TEST_ENABLE 367bf215546Sopenharmony_ci */ 368bf215546Sopenharmony_ci bool enable; 369bf215546Sopenharmony_ci 370bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::min/maxDepthBounds 371bf215546Sopenharmony_ci * 372bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_DEPTH_BOUNDS_TEST_BOUNDS 373bf215546Sopenharmony_ci */ 374bf215546Sopenharmony_ci float min, max; 375bf215546Sopenharmony_ci } bounds_test; 376bf215546Sopenharmony_ci } depth; 377bf215546Sopenharmony_ci 378bf215546Sopenharmony_ci struct { 379bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::stencilTestEnable 380bf215546Sopenharmony_ci * 381bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DS_STENCIL_TEST_ENABLE 382bf215546Sopenharmony_ci */ 383bf215546Sopenharmony_ci bool test_enable; 384bf215546Sopenharmony_ci 385bf215546Sopenharmony_ci /** Whether or not stencil is should be written 386bf215546Sopenharmony_ci * 387bf215546Sopenharmony_ci * This does not map directly to any particular Vulkan API state and is 388bf215546Sopenharmony_ci * initialized to true. If independent stencil disable ever becomes a 389bf215546Sopenharmony_ci * thing, it will use this state. vk_optimize_depth_stencil_state() may 390bf215546Sopenharmony_ci * set this to false if it can prove that the stencil test will never 391bf215546Sopenharmony_ci * alter the stencil value. 392bf215546Sopenharmony_ci */ 393bf215546Sopenharmony_ci bool write_enable; 394bf215546Sopenharmony_ci 395bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::front */ 396bf215546Sopenharmony_ci struct vk_stencil_test_face_state front; 397bf215546Sopenharmony_ci 398bf215546Sopenharmony_ci /** VkPipelineDepthStencilStateCreateInfo::back */ 399bf215546Sopenharmony_ci struct vk_stencil_test_face_state back; 400bf215546Sopenharmony_ci } stencil; 401bf215546Sopenharmony_ci}; 402bf215546Sopenharmony_ci 403bf215546Sopenharmony_ci/** Optimize a depth/stencil state 404bf215546Sopenharmony_ci * 405bf215546Sopenharmony_ci * The way depth and stencil testing is specified, there are many case where, 406bf215546Sopenharmony_ci * regardless of depth/stencil writes being enabled, nothing actually gets 407bf215546Sopenharmony_ci * written due to some other bit of state being set. In the presence of 408bf215546Sopenharmony_ci * discards, it's fairly easy to get into cases where early depth/stencil 409bf215546Sopenharmony_ci * testing is disabled on some hardware, leading to a fairly big performance 410bf215546Sopenharmony_ci * hit. This function attempts to optimize the depth stencil state and 411bf215546Sopenharmony_ci * disable writes and sometimes even testing whenever possible. 412bf215546Sopenharmony_ci * 413bf215546Sopenharmony_ci * @param[inout] ds The depth stencil state to optimize 414bf215546Sopenharmony_ci * @param[in] ds_aspects Which image aspects are present in the 415bf215546Sopenharmony_ci * render pass. 416bf215546Sopenharmony_ci * @param[in] consider_write_mask If true, the write mask will be taken 417bf215546Sopenharmony_ci * into account when optimizing. If 418bf215546Sopenharmony_ci * false, it will be ignored. 419bf215546Sopenharmony_ci */ 420bf215546Sopenharmony_civoid vk_optimize_depth_stencil_state(struct vk_depth_stencil_state *ds, 421bf215546Sopenharmony_ci VkImageAspectFlags ds_aspects, 422bf215546Sopenharmony_ci bool consider_write_mask); 423bf215546Sopenharmony_ci 424bf215546Sopenharmony_cistruct vk_color_blend_attachment_state { 425bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::blendEnable */ 426bf215546Sopenharmony_ci bool blend_enable; 427bf215546Sopenharmony_ci 428bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::srcColorBlendFactor */ 429bf215546Sopenharmony_ci uint8_t src_color_blend_factor; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::dstColorBlendFactor */ 432bf215546Sopenharmony_ci uint8_t dst_color_blend_factor; 433bf215546Sopenharmony_ci 434bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::srcAlphaBlendFactor */ 435bf215546Sopenharmony_ci uint8_t src_alpha_blend_factor; 436bf215546Sopenharmony_ci 437bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::dstAlphaBlendFactor */ 438bf215546Sopenharmony_ci uint8_t dst_alpha_blend_factor; 439bf215546Sopenharmony_ci 440bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::colorWriteMask */ 441bf215546Sopenharmony_ci uint8_t write_mask; 442bf215546Sopenharmony_ci 443bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::colorBlendOp */ 444bf215546Sopenharmony_ci VkBlendOp color_blend_op; 445bf215546Sopenharmony_ci 446bf215546Sopenharmony_ci /** VkPipelineColorBlendAttachmentState::alphaBlendOp */ 447bf215546Sopenharmony_ci VkBlendOp alpha_blend_op; 448bf215546Sopenharmony_ci}; 449bf215546Sopenharmony_ci 450bf215546Sopenharmony_cistruct vk_color_blend_state { 451bf215546Sopenharmony_ci /** VkPipelineColorBlendStateCreateInfo::logicOpEnable */ 452bf215546Sopenharmony_ci bool logic_op_enable; 453bf215546Sopenharmony_ci 454bf215546Sopenharmony_ci /** VkPipelineColorBlendStateCreateInfo::logicOp */ 455bf215546Sopenharmony_ci uint8_t logic_op; 456bf215546Sopenharmony_ci 457bf215546Sopenharmony_ci /** VkPipelineColorWriteCreateInfoEXT::pColorWriteEnables */ 458bf215546Sopenharmony_ci uint8_t color_write_enables; 459bf215546Sopenharmony_ci 460bf215546Sopenharmony_ci /** VkPipelineColorBlendStateCreateInfo::attachmentCount */ 461bf215546Sopenharmony_ci uint8_t attachment_count; 462bf215546Sopenharmony_ci 463bf215546Sopenharmony_ci /** VkPipelineColorBlendStateCreateInfo::pAttachments */ 464bf215546Sopenharmony_ci struct vk_color_blend_attachment_state attachments[MESA_VK_MAX_COLOR_ATTACHMENTS]; 465bf215546Sopenharmony_ci 466bf215546Sopenharmony_ci /** VkPipelineColorBlendStateCreateInfo::blendConstants */ 467bf215546Sopenharmony_ci float blend_constants[4]; 468bf215546Sopenharmony_ci}; 469bf215546Sopenharmony_ci 470bf215546Sopenharmony_cistruct vk_render_pass_state { 471bf215546Sopenharmony_ci /** Set of image aspects bound as color/depth/stencil attachments 472bf215546Sopenharmony_ci * 473bf215546Sopenharmony_ci * Set to VK_IMAGE_ASPECT_METADATA_BIT to indicate that attachment info 474bf215546Sopenharmony_ci * is invalid. 475bf215546Sopenharmony_ci */ 476bf215546Sopenharmony_ci VkImageAspectFlags attachment_aspects; 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_ci /** VkGraphicsPipelineCreateInfo::renderPass */ 479bf215546Sopenharmony_ci VkRenderPass render_pass; 480bf215546Sopenharmony_ci 481bf215546Sopenharmony_ci /** VkGraphicsPipelineCreateInfo::subpass */ 482bf215546Sopenharmony_ci uint32_t subpass; 483bf215546Sopenharmony_ci 484bf215546Sopenharmony_ci /** VkPipelineRenderingCreateInfo::viewMask */ 485bf215546Sopenharmony_ci uint32_t view_mask; 486bf215546Sopenharmony_ci 487bf215546Sopenharmony_ci /** VkRenderingSelfDependencyInfoMESA::colorSelfDependencies */ 488bf215546Sopenharmony_ci uint8_t color_self_dependencies; 489bf215546Sopenharmony_ci 490bf215546Sopenharmony_ci /** VkRenderingSelfDependencyInfoMESA::depthSelfDependency */ 491bf215546Sopenharmony_ci bool depth_self_dependency; 492bf215546Sopenharmony_ci 493bf215546Sopenharmony_ci /** VkRenderingSelfDependencyInfoMESA::stencilSelfDependency */ 494bf215546Sopenharmony_ci bool stencil_self_dependency; 495bf215546Sopenharmony_ci 496bf215546Sopenharmony_ci /** VkPipelineRenderingCreateInfo::colorAttachmentCount */ 497bf215546Sopenharmony_ci uint8_t color_attachment_count; 498bf215546Sopenharmony_ci 499bf215546Sopenharmony_ci /** VkPipelineRenderingCreateInfo::pColorAttachmentFormats */ 500bf215546Sopenharmony_ci VkFormat color_attachment_formats[MESA_VK_MAX_COLOR_ATTACHMENTS]; 501bf215546Sopenharmony_ci 502bf215546Sopenharmony_ci /** VkPipelineRenderingCreateInfo::depthAttachmentFormat */ 503bf215546Sopenharmony_ci VkFormat depth_attachment_format; 504bf215546Sopenharmony_ci 505bf215546Sopenharmony_ci /** VkPipelineRenderingCreateInfo::stencilAttachmentFormat */ 506bf215546Sopenharmony_ci VkFormat stencil_attachment_format; 507bf215546Sopenharmony_ci}; 508bf215546Sopenharmony_ci 509bf215546Sopenharmony_ci/** Struct representing all dynamic graphics state 510bf215546Sopenharmony_ci * 511bf215546Sopenharmony_ci * Before invoking any core functions, the driver must properly populate 512bf215546Sopenharmony_ci * initialize this struct: 513bf215546Sopenharmony_ci * 514bf215546Sopenharmony_ci * - Initialize using vk_default_dynamic_graphics_state, if desired 515bf215546Sopenharmony_ci * - Set vi to a driver-allocated vk_vertex_input_state struct 516bf215546Sopenharmony_ci * - Set ms.sample_locations to a driver-allocated 517bf215546Sopenharmony_ci * vk_sample_locations_state struct 518bf215546Sopenharmony_ci */ 519bf215546Sopenharmony_cistruct vk_dynamic_graphics_state { 520bf215546Sopenharmony_ci /** Vertex input state 521bf215546Sopenharmony_ci * 522bf215546Sopenharmony_ci * Must be provided by the driver if VK_EXT_vertex_input_dynamic_state is 523bf215546Sopenharmony_ci * supported. 524bf215546Sopenharmony_ci * 525bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VI 526bf215546Sopenharmony_ci */ 527bf215546Sopenharmony_ci struct vk_vertex_input_state *vi; 528bf215546Sopenharmony_ci 529bf215546Sopenharmony_ci /** Vertex binding strides 530bf215546Sopenharmony_ci * 531bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VI_BINDING_STRIDES 532bf215546Sopenharmony_ci */ 533bf215546Sopenharmony_ci uint16_t vi_binding_strides[MESA_VK_MAX_VERTEX_BINDINGS]; 534bf215546Sopenharmony_ci 535bf215546Sopenharmony_ci struct vk_input_assembly_state ia; 536bf215546Sopenharmony_ci 537bf215546Sopenharmony_ci struct { 538bf215546Sopenharmony_ci uint32_t patch_control_points; 539bf215546Sopenharmony_ci } ts; 540bf215546Sopenharmony_ci 541bf215546Sopenharmony_ci /** Viewport state */ 542bf215546Sopenharmony_ci struct { 543bf215546Sopenharmony_ci /** Viewport count 544bf215546Sopenharmony_ci * 545bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_VIEWPORT_COUNT 546bf215546Sopenharmony_ci */ 547bf215546Sopenharmony_ci uint32_t viewport_count; 548bf215546Sopenharmony_ci 549bf215546Sopenharmony_ci /** Viewports 550bf215546Sopenharmony_ci * 551bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_VIEWPORTS 552bf215546Sopenharmony_ci */ 553bf215546Sopenharmony_ci VkViewport viewports[MESA_VK_MAX_VIEWPORTS]; 554bf215546Sopenharmony_ci 555bf215546Sopenharmony_ci /** Scissor count 556bf215546Sopenharmony_ci * 557bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_SCISSOR_COUNT 558bf215546Sopenharmony_ci */ 559bf215546Sopenharmony_ci uint32_t scissor_count; 560bf215546Sopenharmony_ci 561bf215546Sopenharmony_ci /** Scissor rects 562bf215546Sopenharmony_ci * 563bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_VP_SCISSORS 564bf215546Sopenharmony_ci */ 565bf215546Sopenharmony_ci VkRect2D scissors[MESA_VK_MAX_SCISSORS]; 566bf215546Sopenharmony_ci } vp; 567bf215546Sopenharmony_ci 568bf215546Sopenharmony_ci /** Discard rectangles 569bf215546Sopenharmony_ci * 570bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_DR_RECTANGLES 571bf215546Sopenharmony_ci */ 572bf215546Sopenharmony_ci struct { 573bf215546Sopenharmony_ci uint32_t rectangle_count; 574bf215546Sopenharmony_ci VkRect2D rectangles[MESA_VK_MAX_DISCARD_RECTANGLES]; 575bf215546Sopenharmony_ci } dr; 576bf215546Sopenharmony_ci 577bf215546Sopenharmony_ci /** Rasterization state */ 578bf215546Sopenharmony_ci struct { 579bf215546Sopenharmony_ci /** Rasterizer discard 580bf215546Sopenharmony_ci * 581bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_RASTERIZER_DISCARD_ENABLE 582bf215546Sopenharmony_ci */ 583bf215546Sopenharmony_ci bool rasterizer_discard_enable; 584bf215546Sopenharmony_ci 585bf215546Sopenharmony_ci /** Cull mode 586bf215546Sopenharmony_ci * 587bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_CULL_MODE 588bf215546Sopenharmony_ci */ 589bf215546Sopenharmony_ci VkCullModeFlags cull_mode; 590bf215546Sopenharmony_ci 591bf215546Sopenharmony_ci /** Front face 592bf215546Sopenharmony_ci * 593bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_FRONT_FACE 594bf215546Sopenharmony_ci */ 595bf215546Sopenharmony_ci VkFrontFace front_face; 596bf215546Sopenharmony_ci 597bf215546Sopenharmony_ci struct { 598bf215546Sopenharmony_ci /** Depth bias enable 599bf215546Sopenharmony_ci * 600bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_DEPTH_BIAS_ENABLE 601bf215546Sopenharmony_ci */ 602bf215546Sopenharmony_ci bool enable; 603bf215546Sopenharmony_ci 604bf215546Sopenharmony_ci /** Depth bias constant factor 605bf215546Sopenharmony_ci * 606bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_DEPTH_BIAS_FACTORS 607bf215546Sopenharmony_ci */ 608bf215546Sopenharmony_ci float constant; 609bf215546Sopenharmony_ci 610bf215546Sopenharmony_ci /** Depth bias clamp 611bf215546Sopenharmony_ci * 612bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_DEPTH_BIAS_FACTORS 613bf215546Sopenharmony_ci */ 614bf215546Sopenharmony_ci float clamp; 615bf215546Sopenharmony_ci 616bf215546Sopenharmony_ci /** Depth bias slope 617bf215546Sopenharmony_ci * 618bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_DEPTH_BIAS_FACTORS 619bf215546Sopenharmony_ci */ 620bf215546Sopenharmony_ci float slope; 621bf215546Sopenharmony_ci } depth_bias; 622bf215546Sopenharmony_ci 623bf215546Sopenharmony_ci struct { 624bf215546Sopenharmony_ci /** Line width 625bf215546Sopenharmony_ci * 626bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_LINE_WIDTH 627bf215546Sopenharmony_ci */ 628bf215546Sopenharmony_ci float width; 629bf215546Sopenharmony_ci 630bf215546Sopenharmony_ci /** Line stipple 631bf215546Sopenharmony_ci * 632bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_RS_LINE_STIPPLE 633bf215546Sopenharmony_ci */ 634bf215546Sopenharmony_ci struct { 635bf215546Sopenharmony_ci uint32_t factor; 636bf215546Sopenharmony_ci uint16_t pattern; 637bf215546Sopenharmony_ci } stipple; 638bf215546Sopenharmony_ci } line; 639bf215546Sopenharmony_ci } rs; 640bf215546Sopenharmony_ci 641bf215546Sopenharmony_ci struct vk_fragment_shading_rate_state fsr; 642bf215546Sopenharmony_ci 643bf215546Sopenharmony_ci /** Multisample state */ 644bf215546Sopenharmony_ci struct { 645bf215546Sopenharmony_ci /** Sample locations 646bf215546Sopenharmony_ci * 647bf215546Sopenharmony_ci * Must be provided by the driver if VK_EXT_sample_locations is 648bf215546Sopenharmony_ci * supported. 649bf215546Sopenharmony_ci * 650bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_MS_SAMPLE_LOCATIONS 651bf215546Sopenharmony_ci */ 652bf215546Sopenharmony_ci struct vk_sample_locations_state *sample_locations; 653bf215546Sopenharmony_ci } ms; 654bf215546Sopenharmony_ci 655bf215546Sopenharmony_ci struct vk_depth_stencil_state ds; 656bf215546Sopenharmony_ci 657bf215546Sopenharmony_ci /** Color blend state */ 658bf215546Sopenharmony_ci struct { 659bf215546Sopenharmony_ci /** Integer color logic op 660bf215546Sopenharmony_ci * 661bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_LOGIC_OP, 662bf215546Sopenharmony_ci */ 663bf215546Sopenharmony_ci VkLogicOp logic_op; 664bf215546Sopenharmony_ci 665bf215546Sopenharmony_ci /** Color write enables 666bf215546Sopenharmony_ci * 667bf215546Sopenharmony_ci * Bitmask of color write enables, indexed by color attachment index. 668bf215546Sopenharmony_ci * 669bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_COLOR_WRITE_ENABLES, 670bf215546Sopenharmony_ci */ 671bf215546Sopenharmony_ci uint32_t color_write_enables; 672bf215546Sopenharmony_ci 673bf215546Sopenharmony_ci /** Blend constants 674bf215546Sopenharmony_ci * 675bf215546Sopenharmony_ci * MESA_VK_DYNAMIC_GRAPHICS_STATE_CB_BLEND_CONSTANTS, 676bf215546Sopenharmony_ci */ 677bf215546Sopenharmony_ci float blend_constants[4]; 678bf215546Sopenharmony_ci } cb; 679bf215546Sopenharmony_ci 680bf215546Sopenharmony_ci /** For pipelines, which bits of dynamic state are set */ 681bf215546Sopenharmony_ci BITSET_DECLARE(set, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX); 682bf215546Sopenharmony_ci 683bf215546Sopenharmony_ci /** For command buffers, which bits of dynamic state have changed */ 684bf215546Sopenharmony_ci BITSET_DECLARE(dirty, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX); 685bf215546Sopenharmony_ci}; 686bf215546Sopenharmony_ci 687bf215546Sopenharmony_cistruct vk_graphics_pipeline_all_state { 688bf215546Sopenharmony_ci struct vk_vertex_input_state vi; 689bf215546Sopenharmony_ci struct vk_input_assembly_state ia; 690bf215546Sopenharmony_ci struct vk_tessellation_state ts; 691bf215546Sopenharmony_ci struct vk_viewport_state vp; 692bf215546Sopenharmony_ci struct vk_discard_rectangles_state dr; 693bf215546Sopenharmony_ci struct vk_rasterization_state rs; 694bf215546Sopenharmony_ci struct vk_fragment_shading_rate_state fsr; 695bf215546Sopenharmony_ci struct vk_multisample_state ms; 696bf215546Sopenharmony_ci struct vk_sample_locations_state ms_sample_locations; 697bf215546Sopenharmony_ci struct vk_depth_stencil_state ds; 698bf215546Sopenharmony_ci struct vk_color_blend_state cb; 699bf215546Sopenharmony_ci struct vk_render_pass_state rp; 700bf215546Sopenharmony_ci}; 701bf215546Sopenharmony_ci 702bf215546Sopenharmony_cistruct vk_graphics_pipeline_state { 703bf215546Sopenharmony_ci /** Bitset of which states are dynamic */ 704bf215546Sopenharmony_ci BITSET_DECLARE(dynamic, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX); 705bf215546Sopenharmony_ci 706bf215546Sopenharmony_ci VkShaderStageFlags shader_stages; 707bf215546Sopenharmony_ci 708bf215546Sopenharmony_ci /** Vertex input state */ 709bf215546Sopenharmony_ci const struct vk_vertex_input_state *vi; 710bf215546Sopenharmony_ci 711bf215546Sopenharmony_ci /** Input assembly state */ 712bf215546Sopenharmony_ci const struct vk_input_assembly_state *ia; 713bf215546Sopenharmony_ci 714bf215546Sopenharmony_ci /** Tessellation state */ 715bf215546Sopenharmony_ci const struct vk_tessellation_state *ts; 716bf215546Sopenharmony_ci 717bf215546Sopenharmony_ci /** Viewport state */ 718bf215546Sopenharmony_ci const struct vk_viewport_state *vp; 719bf215546Sopenharmony_ci 720bf215546Sopenharmony_ci /** Discard Rectangles state */ 721bf215546Sopenharmony_ci const struct vk_discard_rectangles_state *dr; 722bf215546Sopenharmony_ci 723bf215546Sopenharmony_ci /** Rasterization state */ 724bf215546Sopenharmony_ci const struct vk_rasterization_state *rs; 725bf215546Sopenharmony_ci 726bf215546Sopenharmony_ci /** Fragment shading rate state */ 727bf215546Sopenharmony_ci const struct vk_fragment_shading_rate_state *fsr; 728bf215546Sopenharmony_ci 729bf215546Sopenharmony_ci /** Multiesample state */ 730bf215546Sopenharmony_ci const struct vk_multisample_state *ms; 731bf215546Sopenharmony_ci 732bf215546Sopenharmony_ci /** Depth stencil state */ 733bf215546Sopenharmony_ci const struct vk_depth_stencil_state *ds; 734bf215546Sopenharmony_ci 735bf215546Sopenharmony_ci /** Color blend state */ 736bf215546Sopenharmony_ci const struct vk_color_blend_state *cb; 737bf215546Sopenharmony_ci 738bf215546Sopenharmony_ci /** Render pass state */ 739bf215546Sopenharmony_ci const struct vk_render_pass_state *rp; 740bf215546Sopenharmony_ci}; 741bf215546Sopenharmony_ci 742bf215546Sopenharmony_ci/** Struct for extra information that we need from the subpass. 743bf215546Sopenharmony_ci * 744bf215546Sopenharmony_ci * This struct need only be provided if the driver has its own render pass 745bf215546Sopenharmony_ci * implementation. If the driver uses the common render pass implementation, 746bf215546Sopenharmony_ci * we can get this information ourselves. 747bf215546Sopenharmony_ci */ 748bf215546Sopenharmony_cistruct vk_subpass_info { 749bf215546Sopenharmony_ci /** VkSubpassDescription2::viewMask */ 750bf215546Sopenharmony_ci uint32_t view_mask; 751bf215546Sopenharmony_ci 752bf215546Sopenharmony_ci /** 753bf215546Sopenharmony_ci * Aspects of all attachments used as color or depth/stencil attachments 754bf215546Sopenharmony_ci * in the subpass. Input and resolve attachments should not be considered 755bf215546Sopenharmony_ci * when computing the attachments aspect mask. This is used to determine 756bf215546Sopenharmony_ci * whether or not depth/stencil and color blend state are required for a 757bf215546Sopenharmony_ci * pipeline. 758bf215546Sopenharmony_ci */ 759bf215546Sopenharmony_ci VkImageAspectFlags attachment_aspects; 760bf215546Sopenharmony_ci}; 761bf215546Sopenharmony_ci 762bf215546Sopenharmony_ci/** Populate a vk_graphics_pipeline_state from VkGraphicsPipelineCreateInfo 763bf215546Sopenharmony_ci * 764bf215546Sopenharmony_ci * This function crawls the provided VkGraphicsPipelineCreateInfo and uses it 765bf215546Sopenharmony_ci * to populate the vk_graphics_pipeline_state. Upon returning from this 766bf215546Sopenharmony_ci * function, all pointers in `state` will either be `NULL` or point to a valid 767bf215546Sopenharmony_ci * sub-state structure. Whenever an extension struct is missing, a reasonable 768bf215546Sopenharmony_ci * default value is provided whenever possible. Some states may be left NULL 769bf215546Sopenharmony_ci * if the state does not exist (such as when rasterizer discard is enabled) or 770bf215546Sopenharmony_ci * if all of the corresponding states are dynamic. 771bf215546Sopenharmony_ci * 772bf215546Sopenharmony_ci * This function assumes that the vk_graphics_pipeline_state is already valid 773bf215546Sopenharmony_ci * (i.e., all pointers are NULL or point to valid states). Any states already 774bf215546Sopenharmony_ci * present are assumed to be identical to how we would populate them from 775bf215546Sopenharmony_ci * VkGraphicsPipelineCreateInfo. 776bf215546Sopenharmony_ci * 777bf215546Sopenharmony_ci * This function can operate in one of two modes with respect to how the 778bf215546Sopenharmony_ci * memory for states is allocated. If a `vk_graphics_pipeline_all_state` 779bf215546Sopenharmony_ci * struct is provided, any newly populated states will point to the relevant 780bf215546Sopenharmony_ci * field in `all`. If `all == NULL`, it attempts to dynamically allocate any 781bf215546Sopenharmony_ci * newly required states using the provided allocator and scope. The pointer 782bf215546Sopenharmony_ci * to this new blob of memory is returned via `alloc_ptr_out` and must 783bf215546Sopenharmony_ci * eventually be freed by the driver. 784bf215546Sopenharmony_ci * 785bf215546Sopenharmony_ci * @param[in] device The Vulkan device 786bf215546Sopenharmony_ci * @param[out] state The graphics pipeline state to populate 787bf215546Sopenharmony_ci * @param[in] info The pCreateInfo from vkCreateGraphicsPipelines 788bf215546Sopenharmony_ci * @param[in] sp_info Subpass info if the driver implements render 789bf215546Sopenharmony_ci * passes itself. This should be NULL for drivers 790bf215546Sopenharmony_ci * that use the common render pass infrastructure 791bf215546Sopenharmony_ci * built on top of dynamic rendering. 792bf215546Sopenharmony_ci * @param[in] all The vk_graphics_pipeline_all_state to use to 793bf215546Sopenharmony_ci * back any newly needed states. If NULL, newly 794bf215546Sopenharmony_ci * needed states will be dynamically allocated 795bf215546Sopenharmony_ci * instead. 796bf215546Sopenharmony_ci * @param[in] alloc Allocation callbacks for dynamically allocating 797bf215546Sopenharmony_ci * new state memory. 798bf215546Sopenharmony_ci * @param[in] scope Allocation scope for dynamically allocating new 799bf215546Sopenharmony_ci * state memory. 800bf215546Sopenharmony_ci * @param[out] alloc_ptr_out Will be populated with a pointer to any newly 801bf215546Sopenharmony_ci * allocated state. The driver is responsible for 802bf215546Sopenharmony_ci * freeing this pointer. 803bf215546Sopenharmony_ci */ 804bf215546Sopenharmony_ciVkResult 805bf215546Sopenharmony_civk_graphics_pipeline_state_fill(const struct vk_device *device, 806bf215546Sopenharmony_ci struct vk_graphics_pipeline_state *state, 807bf215546Sopenharmony_ci const VkGraphicsPipelineCreateInfo *info, 808bf215546Sopenharmony_ci const struct vk_subpass_info *sp_info, 809bf215546Sopenharmony_ci struct vk_graphics_pipeline_all_state *all, 810bf215546Sopenharmony_ci const VkAllocationCallbacks *alloc, 811bf215546Sopenharmony_ci VkSystemAllocationScope scope, 812bf215546Sopenharmony_ci void **alloc_ptr_out); 813bf215546Sopenharmony_ci 814bf215546Sopenharmony_ci/** Merge one vk_graphics_pipeline_state into another 815bf215546Sopenharmony_ci * 816bf215546Sopenharmony_ci * Both the destination and source states are assumed to be valid (i.e., all 817bf215546Sopenharmony_ci * pointers are NULL or point to valid states). Any states which exist in 818bf215546Sopenharmony_ci * both are expected to be identical and the state already in dst is used. 819bf215546Sopenharmony_ci * The only exception here is render pass state which may be only partially 820bf215546Sopenharmony_ci * defined in which case the fully defined one (if any) is used. 821bf215546Sopenharmony_ci * 822bf215546Sopenharmony_ci * @param[out] dst The destination state. When the function returns, this 823bf215546Sopenharmony_ci * will be the union of the original dst and src. 824bf215546Sopenharmony_ci * @param[in] src The source state 825bf215546Sopenharmony_ci */ 826bf215546Sopenharmony_civoid 827bf215546Sopenharmony_civk_graphics_pipeline_state_merge(struct vk_graphics_pipeline_state *dst, 828bf215546Sopenharmony_ci const struct vk_graphics_pipeline_state *src); 829bf215546Sopenharmony_ci 830bf215546Sopenharmony_ciextern const struct vk_dynamic_graphics_state vk_default_dynamic_graphics_state; 831bf215546Sopenharmony_ci 832bf215546Sopenharmony_ci/** Initialize a vk_dynamic_graphics_state with defaults 833bf215546Sopenharmony_ci * 834bf215546Sopenharmony_ci * @param[out] dyn Dynamic graphics state to initizlie 835bf215546Sopenharmony_ci */ 836bf215546Sopenharmony_civoid 837bf215546Sopenharmony_civk_dynamic_graphics_state_init(struct vk_dynamic_graphics_state *dyn); 838bf215546Sopenharmony_ci 839bf215546Sopenharmony_ci/** Clear a vk_dynamic_graphics_state to defaults 840bf215546Sopenharmony_ci * 841bf215546Sopenharmony_ci * @param[out] dyn Dynamic graphics state to initizlie 842bf215546Sopenharmony_ci */ 843bf215546Sopenharmony_civoid 844bf215546Sopenharmony_civk_dynamic_graphics_state_clear(struct vk_dynamic_graphics_state *dyn); 845bf215546Sopenharmony_ci 846bf215546Sopenharmony_ci/** Initialize a vk_dynamic_graphics_state for a pipeline 847bf215546Sopenharmony_ci * 848bf215546Sopenharmony_ci * @param[out] dyn Dynamic graphics state to initizlie 849bf215546Sopenharmony_ci * @param[in] supported Bitset of all dynamic state supported by the driver. 850bf215546Sopenharmony_ci * @param[in] p The pipeline state from which to initialize the 851bf215546Sopenharmony_ci * dynamic state. 852bf215546Sopenharmony_ci */ 853bf215546Sopenharmony_civoid 854bf215546Sopenharmony_civk_dynamic_graphics_state_fill(struct vk_dynamic_graphics_state *dyn, 855bf215546Sopenharmony_ci const struct vk_graphics_pipeline_state *p); 856bf215546Sopenharmony_ci 857bf215546Sopenharmony_ci/** Mark all states in the given vk_dynamic_graphics_state dirty 858bf215546Sopenharmony_ci * 859bf215546Sopenharmony_ci * @param[out] d Dynamic graphics state struct 860bf215546Sopenharmony_ci */ 861bf215546Sopenharmony_cistatic inline void 862bf215546Sopenharmony_civk_dynamic_graphics_state_dirty_all(struct vk_dynamic_graphics_state *d) 863bf215546Sopenharmony_ci{ 864bf215546Sopenharmony_ci BITSET_SET_RANGE(d->dirty, 0, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX - 1); 865bf215546Sopenharmony_ci} 866bf215546Sopenharmony_ci 867bf215546Sopenharmony_ci/** Mark all states in the given vk_dynamic_graphics_state not dirty 868bf215546Sopenharmony_ci * 869bf215546Sopenharmony_ci * @param[out] d Dynamic graphics state struct 870bf215546Sopenharmony_ci */ 871bf215546Sopenharmony_cistatic inline void 872bf215546Sopenharmony_civk_dynamic_graphics_state_clear_dirty(struct vk_dynamic_graphics_state *d) 873bf215546Sopenharmony_ci{ 874bf215546Sopenharmony_ci BITSET_ZERO(d->dirty); 875bf215546Sopenharmony_ci} 876bf215546Sopenharmony_ci 877bf215546Sopenharmony_ci/** Test if any states in the given vk_dynamic_graphics_state are dirty 878bf215546Sopenharmony_ci * 879bf215546Sopenharmony_ci * @param[in] d Dynamic graphics state struct to test 880bf215546Sopenharmony_ci * @returns true if any state is dirty 881bf215546Sopenharmony_ci */ 882bf215546Sopenharmony_cistatic inline bool 883bf215546Sopenharmony_civk_dynamic_graphics_state_any_dirty(const struct vk_dynamic_graphics_state *d) 884bf215546Sopenharmony_ci{ 885bf215546Sopenharmony_ci return BITSET_TEST_RANGE(d->dirty, 886bf215546Sopenharmony_ci 0, MESA_VK_DYNAMIC_GRAPHICS_STATE_ENUM_MAX - 1); 887bf215546Sopenharmony_ci} 888bf215546Sopenharmony_ci 889bf215546Sopenharmony_ci/** Copies all set state from src to dst 890bf215546Sopenharmony_ci * 891bf215546Sopenharmony_ci * Both src and dst are assumed to be properly initialized dynamic state 892bf215546Sopenharmony_ci * structs. Anything not set in src, as indicated by src->set, is ignored and 893bf215546Sopenharmony_ci * those bits of dst are left untouched. 894bf215546Sopenharmony_ci * 895bf215546Sopenharmony_ci * @param[out] dst Copy destination 896bf215546Sopenharmony_ci * @param[in] src Copy source 897bf215546Sopenharmony_ci */ 898bf215546Sopenharmony_civoid 899bf215546Sopenharmony_civk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state *dst, 900bf215546Sopenharmony_ci const struct vk_dynamic_graphics_state *src); 901bf215546Sopenharmony_ci 902bf215546Sopenharmony_ci/** Set all of the state in src on a command buffer 903bf215546Sopenharmony_ci * 904bf215546Sopenharmony_ci * Anything not set, as indicated by src->set, is ignored and those states in 905bf215546Sopenharmony_ci * the command buffer are left untouched. 906bf215546Sopenharmony_ci * 907bf215546Sopenharmony_ci * @param[inout] cmd Command buffer to update 908bf215546Sopenharmony_ci * @param[in] src State to set 909bf215546Sopenharmony_ci */ 910bf215546Sopenharmony_civoid 911bf215546Sopenharmony_civk_cmd_set_dynamic_graphics_state(struct vk_command_buffer *cmd, 912bf215546Sopenharmony_ci const struct vk_dynamic_graphics_state *src); 913bf215546Sopenharmony_ci 914bf215546Sopenharmony_ci/** Set vertex binding strides on a command buffer 915bf215546Sopenharmony_ci * 916bf215546Sopenharmony_ci * This is the dynamic state part of vkCmdBindVertexBuffers2(). 917bf215546Sopenharmony_ci * 918bf215546Sopenharmony_ci * @param[inout] cmd Command buffer to update 919bf215546Sopenharmony_ci * @param[in] first_binding First binding to update 920bf215546Sopenharmony_ci * @param[in] binding_count Number of bindings to update 921bf215546Sopenharmony_ci * @param[in] strides binding_count many stride values to set 922bf215546Sopenharmony_ci */ 923bf215546Sopenharmony_civoid 924bf215546Sopenharmony_civk_cmd_set_vertex_binding_strides(struct vk_command_buffer *cmd, 925bf215546Sopenharmony_ci uint32_t first_binding, 926bf215546Sopenharmony_ci uint32_t binding_count, 927bf215546Sopenharmony_ci const VkDeviceSize *strides); 928bf215546Sopenharmony_ci 929bf215546Sopenharmony_ci#ifdef __cplusplus 930bf215546Sopenharmony_ci} 931bf215546Sopenharmony_ci#endif 932bf215546Sopenharmony_ci 933bf215546Sopenharmony_ci#endif /* VK_GRAPHICS_STATE_H */ 934