radv: implement VK_EXT_sample_locations and disable it
[mesa.git] / src / amd / vulkan / radv_pipeline.c
index a3076d421a53eae037381796d822f0e4d0fb285f..ddcbe465883a43e15c22cfda3793422e6d6a1102 100644 (file)
@@ -1267,6 +1267,8 @@ static unsigned radv_dynamic_state_mask(VkDynamicState state)
                return RADV_DYNAMIC_STENCIL_REFERENCE;
        case VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT:
                return RADV_DYNAMIC_DISCARD_RECTANGLE;
+       case VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT:
+               return RADV_DYNAMIC_SAMPLE_LOCATIONS;
        default:
                unreachable("Unhandled dynamic state");
        }
@@ -1297,6 +1299,11 @@ static uint32_t radv_pipeline_needed_dynamic_state(const VkGraphicsPipelineCreat
        if (!vk_find_struct_const(pCreateInfo->pNext, PIPELINE_DISCARD_RECTANGLE_STATE_CREATE_INFO_EXT))
                states &= ~RADV_DYNAMIC_DISCARD_RECTANGLE;
 
+       if (!pCreateInfo->pMultisampleState ||
+           !vk_find_struct_const(pCreateInfo->pMultisampleState->pNext,
+                                 PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT))
+               states &= ~RADV_DYNAMIC_SAMPLE_LOCATIONS;
+
        /* TODO: blend constants & line width. */
 
        return states;
@@ -1426,6 +1433,29 @@ radv_pipeline_init_dynamic_state(struct radv_pipeline *pipeline,
                }
        }
 
+       if (needed_states & RADV_DYNAMIC_SAMPLE_LOCATIONS) {
+               const VkPipelineSampleLocationsStateCreateInfoEXT *sample_location_info =
+                       vk_find_struct_const(pCreateInfo->pMultisampleState->pNext,
+                                            PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT);
+               /* If sampleLocationsEnable is VK_FALSE, the default sample
+                * locations are used and the values specified in
+                * sampleLocationsInfo are ignored.
+                */
+               if (sample_location_info->sampleLocationsEnable) {
+                       const VkSampleLocationsInfoEXT *pSampleLocationsInfo =
+                               &sample_location_info->sampleLocationsInfo;
+
+                       assert(pSampleLocationsInfo->sampleLocationsCount <= MAX_SAMPLE_LOCATIONS);
+
+                       dynamic->sample_location.per_pixel = pSampleLocationsInfo->sampleLocationsPerPixel;
+                       dynamic->sample_location.grid_size = pSampleLocationsInfo->sampleLocationGridSize;
+                       dynamic->sample_location.count = pSampleLocationsInfo->sampleLocationsCount;
+                       typed_memcpy(&dynamic->sample_location.locations[0],
+                                    pSampleLocationsInfo->pSampleLocations,
+                                    pSampleLocationsInfo->sampleLocationsCount);
+               }
+       }
+
        pipeline->dynamic_state.mask = states;
 }