[Mesa-dev] [PATCH 04/24] mesa/glspirv: Add struct gl_spirv_module

Ian Romanick idr at freedesktop.org
Mon Nov 27 22:20:32 UTC 2017


On 11/15/2017 05:22 AM, Eduardo Lima Mitev wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
> 
> v2: Make the SPIR-V module struct part of a larger gl_shader_spirv_data
>     struct that will be introduced later, and don't reference it directly
>     in gl_shader. (Eduardo Lima)
> ---
>  src/mesa/main/glspirv.c | 19 +++++++++++++++++++
>  src/mesa/main/glspirv.h | 16 ++++++++++++++++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c
> index 57068023091..eb869356632 100644
> --- a/src/mesa/main/glspirv.c
> +++ b/src/mesa/main/glspirv.c
> @@ -23,6 +23,25 @@
>  
>  #include "glspirv.h"
>  
> +#include "util/u_atomic.h"
> +
> +void
> +_mesa_spirv_module_reference(struct gl_spirv_module **dest,
> +                             struct gl_spirv_module *src)
> +{
> +   struct gl_spirv_module *old = *dest;
> +
> +   if (old) {
> +      if (p_atomic_dec_zero(&old->RefCount))
> +         free(old);
> +   }

I feel like this reads better as:

   if (old && p_atomic_dec_zero(&old->RefCount))
      free(old);

With or without that change, this patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> +
> +   *dest = src;
> +
> +   if (src)
> +      p_atomic_inc(&src->RefCount);
> +}
> +
>  void GLAPIENTRY
>  _mesa_SpecializeShaderARB(GLuint shader,
>                            const GLchar *pEntryPoint,
> diff --git a/src/mesa/main/glspirv.h b/src/mesa/main/glspirv.h
> index 1de88717faa..4e033735cfe 100644
> --- a/src/mesa/main/glspirv.h
> +++ b/src/mesa/main/glspirv.h
> @@ -31,6 +31,22 @@ extern "C" {
>  #endif
>  
>  /**
> + * A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
> + *
> + * It is reference-counted, because the same module can be attached to multiple
> + * shader objects simultaneously.
> + */
> +struct gl_spirv_module {
> +   unsigned RefCount;
> +   GLint Length;
> +   char Binary[0];
> +};
> +
> +void
> +_mesa_spirv_module_reference(struct gl_spirv_module **dest,
> +                             struct gl_spirv_module *src);
> +
> +/**
>   * \name API functions
>   */
>  /*@{*/
> 



More information about the mesa-dev mailing list