radv: fix ignoring the vertex attribute stride if set as dynamic

The vertex attribute stride should be ignored, so make sure it's
initialized to zero if dynamic to avoid computing a wrong offset.

The fact that each element of pStrides must be greater than or equal
to the maximum extent of all vertex input attributes fetched saves us
one user SGPR for the dynamic stride.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/3627
Cc: 20.2
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7101>
(cherry picked from commit 48b988e35f)
This commit is contained in:
Samuel Pitoiset 2020-10-12 17:56:02 +02:00 committed by Dylan Baker
parent 02cd25463d
commit ef7ecc9fa2

View file

@ -2334,6 +2334,7 @@ radv_generate_graphics_pipeline_key(struct radv_pipeline *pipeline,
pCreateInfo->pVertexInputState;
const VkPipelineVertexInputDivisorStateCreateInfoEXT *divisor_state =
vk_find_struct_const(input_state->pNext, PIPELINE_VERTEX_INPUT_DIVISOR_STATE_CREATE_INFO_EXT);
bool uses_dynamic_stride = false;
struct radv_pipeline_key key;
memset(&key, 0, sizeof(key));
@ -2359,6 +2360,16 @@ radv_generate_graphics_pipeline_key(struct radv_pipeline *pipeline,
}
}
if (pCreateInfo->pDynamicState) {
uint32_t count = pCreateInfo->pDynamicState->dynamicStateCount;
for (uint32_t i = 0; i < count; i++) {
if (pCreateInfo->pDynamicState->pDynamicStates[i] == VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT) {
uses_dynamic_stride = true;
break;
}
}
}
for (unsigned i = 0; i < input_state->vertexAttributeDescriptionCount; ++i) {
const VkVertexInputAttributeDescription *desc =
&input_state->pVertexAttributeDescriptions[i];
@ -2382,7 +2393,26 @@ radv_generate_graphics_pipeline_key(struct radv_pipeline *pipeline,
key.vertex_attribute_formats[location] = data_format | (num_format << 4);
key.vertex_attribute_bindings[location] = desc->binding;
key.vertex_attribute_offsets[location] = desc->offset;
key.vertex_attribute_strides[location] = radv_get_attrib_stride(input_state, desc->binding);
if (!uses_dynamic_stride) {
/* From the Vulkan spec 1.2.157:
*
* "If the bound pipeline state object was created
* with the
* VK_DYNAMIC_STATE_VERTEX_INPUT_BINDING_STRIDE_EXT
* dynamic state enabled then pStrides[i] specifies
* the distance in bytes between two consecutive
* elements within the corresponding buffer. In this
* case the VkVertexInputBindingDescription::stride
* state from the pipeline state object is ignored."
*
* Make sure the vertex attribute stride is zero to
* avoid computing a wrong offset if it's initialized
* to something else than zero.
*/
key.vertex_attribute_strides[location] =
radv_get_attrib_stride(input_state, desc->binding);
}
if (pipeline->device->physical_device->rad_info.chip_class <= GFX8 &&
pipeline->device->physical_device->rad_info.family != CHIP_STONEY) {