From 74f98ab76f2a21ef511e6bbddaa08ac1748aca2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolai=20H=C3=A4hnle?= Date: Sat, 10 Jun 2017 20:14:44 +0200 Subject: [PATCH] mesa/glspirv: Add struct gl_spirv_module 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) * Readability improvements (Ian Romanick) Reviewed-by: Ian Romanick --- src/mesa/main/glspirv.c | 17 +++++++++++++++++ src/mesa/main/glspirv.h | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 3989f424241..d4832db549d 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -25,6 +25,23 @@ #include "errors.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 && p_atomic_dec_zero(&old->RefCount)) + free(old); + + *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 @@ -30,6 +30,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 */ -- 2.30.2