[virglrenderer-devel] [PATCH v2 1/4] utils: added some macros for future implems

Nathan Gauër nathan at gauer.org
Fri Jul 27 14:04:25 UTC 2018


On 07/27/2018 02:28 PM, Nathan Gauer wrote:
> This commit adds some macros designed for a future use:
> ARRAY_SIZE: gives the size of an array
> UNUSED_PARAMETER: cast a parameter to void. Only a bit more explicit.
> TRACE_IN/TRACE_OUT: macros available in debug builds. Inspired from
> virtio-gpu ones.
> 
> RETURN: encapsulates a return and a TRACE_OUT.
> 
> Signed-off-by: Nathan Gauer <nathan at gauer.org>
> ---
>  src/Makefile.am   | 31 +++++++++++++------------
>  src/util/macros.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 74 insertions(+), 15 deletions(-)
>  create mode 100644 src/util/macros.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 76f4162..b42bac0 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -17,21 +17,22 @@ AM_CFLAGS = \
>  	$(VISIBILITY_CFLAGS) \
>  	$(CODE_COVERAGE_CFLAGS)
>  
> -libvrend_la_SOURCES = \
> -        virgl_hw.h \
> -        virgl_protocol.h \
> -        vrend_iov.h \
> -        vrend_renderer.c \
> -        vrend_renderer.h \
> -        vrend_shader.c \
> -        vrend_shader.h \
> -        vrend_object.c \
> -        vrend_object.h \
> -        vrend_decode.c \
> -        vrend_formats.c \
> -        vrend_blitter.c \
> -        vrend_blitter.h \
> -        iov.c
> +libvrend_la_SOURCES = 		\
> +		  utils/macro.h		\
> +        iov.c					\
> +        virgl_hw.h 			\
> +        virgl_protocol.h 	\
> +        vrend_blitter.c 	\
> +        vrend_blitter.h 	\
> +        vrend_decode.c 		\
> +        vrend_formats.c 	\
> +        vrend_iov.h 			\
> +        vrend_object.c 		\
> +        vrend_object.h 		\
> +        vrend_renderer.c 	\
> +        vrend_renderer.h 	\
> +        vrend_shader.c 		\
> +        vrend_shader.h 		\
>  
>  if HAVE_EPOXY_EGL
>  libvrend_la_SOURCES += \
> diff --git a/src/util/macros.h b/src/util/macros.h
> new file mode 100644
> index 0000000..3d6ff2c
> --- /dev/null
> +++ b/src/util/macros.h
> @@ -0,0 +1,58 @@
> +#ifndef UTIL_MACRO_H
> +#define UTIL_MACRO_H
> +
> +#define UNUSED_PARAMETER(Param) (void)(Param)
> +#define ARRAY_SIZE(Array) (sizeof(Array) / sizeof((Array)[0]))
> +
> +#ifdef DEBUG
> +
> +/* Loggin/Tracing related macros.
> + *    - LOG_LEVEL can be changed by redefining the MIN_LOG_LEVEL macro.
> + *    - TRACE_IN and TRACE_OUT are disabled on non-debug builds.
> + * note: tracing is disabled on release builds
> + */
> +
> +#define LOG_LEVEL_VERBOSE 0
> +#define LOG_LEVEL_INFO    1
> +#define LOG_LEVEL_WARNING 2
> +#define LOG_LEVEL_ERROR   3
> +#define LOG_LEVEL_NONE    10
> +
> +
> +/* Change this define to update the tracing level */
> +#ifdef DEBUG
> +   #define MIN_LOG_LEVEL LOG_LEVEL_INFO
> +#else
> +   #define MIN_LOG_LEVEL LOG_LEVEL_WARNING
> +#endif
> +
> +#define PRINT_LOG(LogLevel, Expression)                     \
> +   do {                                                     \
> +      if ((LogLevel) >= MIN_LOG_LEVEL) {                    \
> +         printf Expression;                                 \
> +      }                                                     \
> +   } while (0)
> +
> +#ifdef DEBUG
> +
> +   #define TRACE_IN()   \
> +      PRINT_LOG(LOG_LEVEL_VERBOSE, ("--> %s\n", __func__))
> +
> +   #define TRACE_OUT(ReturnValue)  \
> +      PRINT_LOG(LOG_LEVEL_VERBOSE, ("<-- %s (%d)\n", __func__, (ReturnValue)))
> +
> +   #define TRACE_OUTV() \
> +      PRINT_LOG(LOG_LEVEL_VERBOSE, ("<-- %s\n", __func__))
> +
> +#else
> +   #define TRACE_IN()
> +   #define TRACE_OUT(ReturnValue)
> +   #define TRACE_OUTV()
> +#endif
> +
> +
> +#define RETURN(ReturnValue)   \
> +   TRACE_OUT(ReturnValue);    \
> +   return ReturnValue
> +
> +#endif
> 

Hi,

Due to a missed email, I failed to take a comment in consideration.
This patch should will be omitted.
UNUSED and ARRAY_SIZE taken from the two existing includes.

Also, tracing will be removed.
Any Vulkan-related macro will me moved to virgl_vk.h (Or the
equivalent once renamed)

Kindly,

-- 
Nathan Gauër


More information about the virglrenderer-devel mailing list