<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 14, 2017 at 3:41 PM, Dave Airlie <span dir="ltr"><<a href="mailto:airlied@gmail.com" target="_blank">airlied@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 15 February 2017 at 09:16, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> These make iterating over Vulkan extension structs much cleaner.<br>
<br>
</span>src/util/vk_utils.h maybe :-)<br>
<br>
vk_struct_common and vk_foreach_struct<br></blockquote><div><br></div><div>Sure, I can do that if you want.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dave.<br>
<div><div class="h5"><br>
> ---<br>
>  src/intel/vulkan/anv_device.c  | 26 ++++++++++++--------------<br>
>  src/intel/vulkan/anv_formats.c | 14 ++++++--------<br>
>  src/intel/vulkan/anv_private.h |  8 ++++++++<br>
>  3 files changed, 26 insertions(+), 22 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
> index 46b83a3..7c2f816 100644<br>
> --- a/src/intel/vulkan/anv_device.<wbr>c<br>
> +++ b/src/intel/vulkan/anv_device.<wbr>c<br>
> @@ -511,10 +511,10 @@ void anv_<wbr>GetPhysicalDeviceFeatures2KHR(<br>
>  {<br>
>     anv_GetPhysicalDeviceFeatures(<wbr>physicalDevice, &pFeatures->features);<br>
><br>
> -   for (struct anv_common *c = pFeatures->pNext; c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pFeatures->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> @@ -669,10 +669,10 @@ void anv_<wbr>GetPhysicalDeviceProperties2KH<wbr>R(<br>
>  {<br>
>     anv_<wbr>GetPhysicalDeviceProperties(<wbr>physicalDevice, &pProperties->properties);<br>
><br>
> -   for (struct anv_common *c = pProperties->pNext; c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pProperties->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> @@ -746,11 +746,10 @@ void anv_<wbr>GetPhysicalDeviceQueueFamilyPr<wbr>operties2KHR(<br>
>     anv_get_queue_family_<wbr>properties(phys_dev,<br>
>           &pQueueFamilyProperties-><wbr>queueFamilyProperties);<br>
><br>
> -   for (struct anv_common *c = pQueueFamilyProperties->pNext;<br>
> -        c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pQueueFamilyProperties->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> @@ -815,11 +814,10 @@ void anv_<wbr>GetPhysicalDeviceMemoryPropert<wbr>ies2KHR(<br>
>     anv_<wbr>GetPhysicalDeviceMemoryPropert<wbr>ies(physicalDevice,<br>
>                                           &pMemoryProperties-><wbr>memoryProperties);<br>
><br>
> -   for (struct anv_common *c = pMemoryProperties->pNext;<br>
> -        c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pMemoryProperties->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> diff --git a/src/intel/vulkan/anv_<wbr>formats.c b/src/intel/vulkan/anv_<wbr>formats.c<br>
> index 0e84960..735d518 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>formats.c<br>
> +++ b/src/intel/vulkan/anv_<wbr>formats.c<br>
> @@ -470,11 +470,10 @@ void anv_<wbr>GetPhysicalDeviceFormatPropert<wbr>ies2KHR(<br>
>     anv_<wbr>GetPhysicalDeviceFormatPropert<wbr>ies(physicalDevice, format,<br>
>                                           &pFormatProperties-><wbr>formatProperties);<br>
><br>
> -   for (struct anv_common *c = pFormatProperties->pNext;<br>
> -        c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pFormatProperties->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> @@ -668,11 +667,10 @@ VkResult anv_<wbr>GetPhysicalDeviceImageFormatPr<wbr>operties2KHR(<br>
>     if (result != VK_SUCCESS)<br>
>        return result;<br>
><br>
> -   for (struct anv_common *c = pImageFormatProperties->pNext;<br>
> -        c != NULL; c = c->pNext) {<br>
> -      switch (c->sType) {<br>
> +   anv_foreach_struct(ext, pImageFormatProperties->pNext) {<br>
> +      switch (ext->sType) {<br>
>        default:<br>
> -         anv_debug_ignored_stype(c-><wbr>sType);<br>
> +         anv_debug_ignored_stype(ext-><wbr>sType);<br>
>           break;<br>
>        }<br>
>     }<br>
> diff --git a/src/intel/vulkan/anv_<wbr>private.h b/src/intel/vulkan/anv_<wbr>private.h<br>
> index ec791a4..527f20f 100644<br>
> --- a/src/intel/vulkan/anv_<wbr>private.h<br>
> +++ b/src/intel/vulkan/anv_<wbr>private.h<br>
> @@ -1881,6 +1881,14 @@ struct anv_common {<br>
>      struct anv_common *pNext;<br>
>  };<br>
><br>
> +#define anv_foreach_struct(__iter, __start)                                \<br>
> +   for (struct anv_common *__iter = (struct anv_common *)(__start);        \<br>
> +        __iter; __iter = __iter->pNext)<br>
> +<br>
> +#define anv_foreach_struct_const(__<wbr>iter, __start)                          \<br>
> +   for (const struct anv_common *__iter = (struct anv_common *)(__start);  \<br>
> +        __iter; __iter = __iter->pNext)<br>
> +<br>
>  #define ANV_DEFINE_HANDLE_CASTS(__anv_<wbr>type, __VkType)                      \<br>
>                                                                             \<br>
>     static inline struct __anv_type *                                       \<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</blockquote></div><br></div></div>