<p dir="ltr"></p>
<p dir="ltr">On Jul 27, 2016 6:03 AM, "Emil Velikov" <<a href="mailto:emil.l.velikov@gmail.com">emil.l.velikov@gmail.com</a>> wrote:<br>
><br>
> From: Emil Velikov <<a href="mailto:emil.velikov@collabora.com">emil.velikov@collabora.com</a>><br>
><br>
> Presently the layer has only a single entry point, which uses asserts solely.<br>
> Thus even on release builds the function (and thus the whole layer) will do<br>
> nothing but adding runtime and binary(size) overhead.<br>
><br>
> Cc: "12.0" <<a href="mailto:mesa-stable@lists.freedesktop.org">mesa-stable@lists.freedesktop.org</a>><br>
> Cc: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
> Signed-off-by: Emil Velikov <<a href="mailto:emil.velikov@collabora.com">emil.velikov@collabora.com</a>><br>
> ---<br>
> We can use a ANV_USE_VALIDATE macro which atm will default to == DEBUG.<br>
> ---<br>
> src/intel/vulkan/anv_entrypoints_gen.py | 36 +++++++++++++++++++++++----------<br>
> src/intel/vulkan/anv_image.c | 2 ++<br>
> 2 files changed, 27 insertions(+), 11 deletions(-)<br>
><br>
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py<br>
> index 2896174..a4922c2 100644<br>
> --- a/src/intel/vulkan/anv_entrypoints_gen.py<br>
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py<br>
> @@ -134,7 +134,9 @@ if opt_header:<br>
> print "%s gen75_%s%s;" % (type, name, args)<br>
> print "%s gen8_%s%s;" % (type, name, args)<br>
> print "%s gen9_%s%s;" % (type, name, args)<br>
> + print "#ifdef DEBUG"<br>
> print "%s anv_validate_%s%s;" % (type, name, args)<br>
> + print "#endif // DEBUG"<br>
> print_guard_end(name)<br>
> exit()<br>
><br>
> @@ -185,14 +187,7 @@ for type, name, args, num, h in entrypoints:<br>
> print " \"vk%s\\0\"" % name<br>
> offsets.append(i)<br>
> i += 2 + len(name) + 1<br>
> -print """ ;<br>
> -<br>
> -/* Weak aliases for all potential validate functions. These will resolve to<br>
> - * NULL if they're not defined, which lets the resolve_entrypoint() function<br>
> - * either pick a validate wrapper if available or just plug in the actual<br>
> - * entry point.<br>
> - */<br>
> -"""<br>
> +print " ;"<br>
><br>
> # Now generate the table of all entry points and their validation functions<br>
><br>
> @@ -201,7 +196,18 @@ for type, name, args, num, h in entrypoints:<br>
> print " { %5d, 0x%08x }," % (offsets[num], h)<br>
> print "};\n"<br>
><br>
> +print """<br>
> +<br>
> +/* Weak aliases for all potential validate functions. These will resolve to<br>
> + * NULL if they're not defined, which lets the resolve_entrypoint() function<br>
> + * either pick a validate wrapper if available or just plug in the actual<br>
> + * entry point.<br>
> + */<br>
> +"""<br>
> +<br>
> for layer in [ "anv", "validate", "gen7", "gen75", "gen8", "gen9" ]:<br>
> + if "validate" in layer:<br>
> + print "#ifdef DEBUG"<br>
> for type, name, args, num, h in entrypoints:<br>
> print_guard_start(name)<br>
> print "%s %s_%s%s __attribute__ ((weak));" % (type, layer, name, args)<br>
> @@ -211,13 +217,13 @@ for layer in [ "anv", "validate", "gen7", "gen75", "gen8", "gen9" ]:<br>
> print_guard_start(name)<br>
> print " .%s = %s_%s," % (name, layer, name)<br>
> print_guard_end(name)<br>
> + if "validate" in layer:<br>
> + print "#endif // DEBUG"<br>
> print "};\n"<br>
><br>
> print """<br>
> #ifdef DEBUG<br>
> static bool enable_validate = true;<br>
> -#else<br>
> -static bool enable_validate = false;<br>
> #endif<br>
><br>
> /* We can't use symbols that need resolving (like, oh, getenv) in the resolve<br>
> @@ -231,8 +237,14 @@ determine_validate(void)<br>
> {<br>
> const char *s = getenv("ANV_VALIDATE");<br>
><br>
> - if (s)<br>
> + if (s) {<br>
> +#ifdef DEBUG<br>
> enable_validate = atoi(s);<br>
> +#else<br>
> + fprintf(stderr, "libvulkand-intel was built without VALIDATE support.\\n");<br>
> + abort();<br>
> +#endif<br>
> + }<br>
> }<br>
><br>
> static const struct brw_device_info *dispatch_devinfo;<br>
> @@ -246,8 +258,10 @@ anv_set_dispatch_devinfo(const struct brw_device_info *devinfo)<br>
> void * __attribute__ ((noinline))<br>
> anv_resolve_entrypoint(uint32_t index)<br>
> {<br>
> +#ifdef DEBUG<br>
> if (enable_validate && validate_layer.entrypoints[index])<br>
> return validate_layer.entrypoints[index];<br>
> +#endif<br>
><br>
> if (dispatch_devinfo == NULL) {<br>
> return anv_layer.entrypoints[index];<br>
> diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c<br>
> index dff51bc..43d19f5 100644<br>
> --- a/src/intel/vulkan/anv_image.c<br>
> +++ b/src/intel/vulkan/anv_image.c<br>
> @@ -332,6 +332,7 @@ void anv_GetImageSubresourceLayout(<br>
> }<br>
> }<br>
><br>
> +#ifdef DEBUG<br>
> VkResult<br>
> anv_validate_CreateImageView(VkDevice _device,</p>
<p dir="ltr">As long as anv_entrypoints contains a declaration of this function, we don't need to #ifdef around it. Hopefully, the linker is smart enough to detect that it's not used and delete the code.</p>
<p dir="ltr">Otherwise, this patch seems perfectly reasonable for now. At one point we had the idea that we could use the validate endpoints to do some extra validation that would be shipped in release mode but disabled by default at zero cost. However, we're not really taking advantage of that now and do we might as well drop it.</p>
<p dir="ltr">> const VkImageViewCreateInfo *pCreateInfo,<br>
> @@ -406,6 +407,7 @@ anv_validate_CreateImageView(VkDevice _device,<br>
><br>
> return anv_CreateImageView(_device, pCreateInfo, pAllocator, pView);<br>
> }<br>
> +#endif // DEBUG<br>
><br>
> static struct anv_state<br>
> alloc_surface_state(struct anv_device *device,<br>
> --<br>
> 2.9.0<br>
></p>