From: Eleni Maria Stea <es...@igalia.com> Allowing the user to set custom sample locations non-dynamically, by filling the extension structs and chaining them to the pipeline structs according to the Vulkan specification section [26.5. Custom Sample Locations] for the following structures:
'VkPipelineSampleLocationsStateCreateInfoEXT' 'VkSampleLocationsInfoEXT' 'VkSampleLocationEXT' Once custom locations are used, the default locations are lost and need to be re-emitted again in the next pipeline creation. For that, we emit the 3DSTATE_SAMPLE_PATTERN at every pipeline creation. v2: In v1, we used the custom anv_sample struct to store the location and the distance from the pixel center because we would then use this distance to sort the locations and send them in increasing monotonical order to the GPU. That was because the Skylake PRM Vol. 2a "3DSTATE_SAMPLE_PATTERN" says that the samples must have monotonically increasing distance from the pixel center to get the correct centroid computation in the device. However, the Vulkan spec seems to require that the samples occur in the order provided through the API and this requirement is only for the standard locations. As long as this only affects centroid calculations as the docs say, we should be ok because OpenGL and Vulkan only require that the centroid be some lit sample and that it's the same for all samples in a pixel; they have no requirement that it be the one closest to center. (Jason Ekstrand) For that we made the following changes: 1- We removed the custom structs and functions from anv_private.h and anv_sample_locations.h and anv_sample_locations.c (the last two files were removed). (Jason Ekstrand) 2- We modified the macros used to take also the array as parameter and we renamed them to start by GEN_. (Jason Ekstrand) 3- We don't sort the samples anymore. (Jason Ekstrand) v3 (Jason Ekstrand): Break the refactoring out into multiple commits --- src/intel/vulkan/anv_private.h | 1 + src/intel/vulkan/genX_pipeline.c | 37 +++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index eed282ff985..a39195733cd 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -165,6 +165,7 @@ struct gen_l3_config; #define MAX_PUSH_DESCRIPTORS 32 /* Minimum requirement */ #define MAX_INLINE_UNIFORM_BLOCK_SIZE 4096 #define MAX_INLINE_UNIFORM_BLOCK_DESCRIPTORS 32 +#define MAX_SAMPLE_LOCATIONS 16 /* The kernel relocation API has a limitation of a 32-bit delta value * applied to the address before it is written which, in spite of it being diff --git a/src/intel/vulkan/genX_pipeline.c b/src/intel/vulkan/genX_pipeline.c index 430b095c5b1..828fcb17fcc 100644 --- a/src/intel/vulkan/genX_pipeline.c +++ b/src/intel/vulkan/genX_pipeline.c @@ -547,13 +547,43 @@ emit_rs_state(struct anv_pipeline *pipeline, #endif } +static bool +is_dynamic_state(VkDynamicState state, + const VkPipelineDynamicStateCreateInfo *dinfo) +{ + for (uint32_t i = 0; i < dinfo->dynamicStateCount; i++) { + if (state == dinfo->pDynamicStates[i]) + return true; + } + + return false; +} + static void emit_ms_state(struct anv_pipeline *pipeline, - const VkPipelineMultisampleStateCreateInfo *info) + const VkPipelineMultisampleStateCreateInfo *info, + const VkPipelineDynamicStateCreateInfo *dinfo) { uint32_t samples = info ? info->rasterizationSamples : 1; - genX(emit_multisample)(&pipeline->batch, samples, NULL); + const VkSampleLocationEXT *locations = NULL; + const VkPipelineSampleLocationsStateCreateInfoEXT *sl_info = + vk_find_struct_const(info, PIPELINE_SAMPLE_LOCATIONS_STATE_CREATE_INFO_EXT); + if (sl_info && sl_info->sampleLocationsEnable && + !is_dynamic_state(VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, dinfo)) { + + assert(sl_info->sampleLocationsInfo.sampleLocationsPerPixel == samples); + assert(sl_info->sampleLocationsInfo.sampleLocationGridSize.width == 1); + assert(sl_info->sampleLocationsInfo.sampleLocationGridSize.height == 1); + assert(sl_info->sampleLocationsInfo.sampleLocationsCount == samples); + locations = sl_info->sampleLocationsInfo.pSampleLocations; + } + +#if GEN_GEN >= 8 + genX(emit_sample_pattern)(&pipeline->batch, samples, locations); +#endif + + genX(emit_multisample)(&pipeline->batch, samples, locations); anv_batch_emit(&pipeline->batch, GENX(3DSTATE_SAMPLE_MASK), sm) { /* From the Vulkan 1.0 spec: @@ -1899,7 +1929,8 @@ genX(graphics_pipeline_create)( assert(pCreateInfo->pRasterizationState); emit_rs_state(pipeline, pCreateInfo->pRasterizationState, pCreateInfo->pMultisampleState, pass, subpass); - emit_ms_state(pipeline, pCreateInfo->pMultisampleState); + emit_ms_state(pipeline, pCreateInfo->pMultisampleState, + pCreateInfo->pDynamicState); emit_ds_state(pipeline, pCreateInfo->pDepthStencilState, pass, subpass); emit_cb_state(pipeline, pCreateInfo->pColorBlendState, pCreateInfo->pMultisampleState); -- 2.20.1 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev