On Thu, Oct 6, 2016 at 6:12 AM, Emil Velikov <emil.l.veli...@gmail.com>
wrote:

> From: Emil Velikov <emil.veli...@collabora.com>
>
> Driver should enumerate only up-to min2(num_available, num_requested)
> properties and return VK_INCOMPLETE if the # of requested props is
> smaller than the ones available.
>

Thanks for fixing this!


> Presently we assert out in such cases.
>
> Inspired by a similar fix for RADV.
>
> Should fix: dEQP-VK.api.info.device.extensions
> Signed-off-by: Emil Velikov <emil.veli...@collabora.com>
> ---
>  src/intel/vulkan/anv_device.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index c7b9979..497bf9f 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -1003,15 +1003,19 @@ VkResult anv_EnumerateInstanceExtensionProperties(
>      uint32_t*                                   pPropertyCount,
>      VkExtensionProperties*                      pProperties)
>  {
> +   unsigned i;
> +
>     if (pProperties == NULL) {
>        *pPropertyCount = ARRAY_SIZE(global_extensions);
>        return VK_SUCCESS;
>     }
>
> -   assert(*pPropertyCount >= ARRAY_SIZE(global_extensions));
> +   for (i = 0; i < MIN2(*pPropertyCount, ARRAY_SIZE(global_extensions));
> i++)
> +      memcpy(&pProperties[i], &global_extensions[i],
> sizeof(VkExtensionProperties));
>

We can do this a bit easier using type typed_memcpy helper.  Perhaps
something like this:

*pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(global_extensions));
typed_memcpy(pProperties, global_extensions, *pPropertyCount);

if (*pPropertyCount < ARRAY_SIZE(global_extensions))
   return VK_INCOMPLETE;

I don't know.  Maybe that's not any better.  Either way,

Reviewed-by: Jason Ekstrand <ja...@jlekstrand.net>
Cc: "13.0" <mesa-sta...@lists.freedesktop.org>


>
> -   *pPropertyCount = ARRAY_SIZE(global_extensions);
> -   memcpy(pProperties, global_extensions, sizeof(global_extensions));
> +   *pPropertyCount = i;
> +   if (i < ARRAY_SIZE(global_extensions))
> +      return VK_INCOMPLETE;
>
>     return VK_SUCCESS;
>  }
> @@ -1022,15 +1026,19 @@ VkResult anv_EnumerateDeviceExtensionProperties(
>      uint32_t*                                   pPropertyCount,
>      VkExtensionProperties*                      pProperties)
>  {
> +   unsigned i;
> +
>     if (pProperties == NULL) {
>        *pPropertyCount = ARRAY_SIZE(device_extensions);
>        return VK_SUCCESS;
>     }
>
> -   assert(*pPropertyCount >= ARRAY_SIZE(device_extensions));
> +   for (i = 0; i < MIN2(*pPropertyCount, ARRAY_SIZE(device_extensions));
> i++)
> +      memcpy(&pProperties[i], &device_extensions[i],
> sizeof(VkExtensionProperties));
>
> -   *pPropertyCount = ARRAY_SIZE(device_extensions);
> -   memcpy(pProperties, device_extensions, sizeof(device_extensions));
> +   *pPropertyCount = i;
> +   if (i < ARRAY_SIZE(device_extensions))
> +      return VK_INCOMPLETE;
>
>     return VK_SUCCESS;
>  }
> --
> 2.9.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to