diff options
author | Nicolai Hähnle <[email protected]> | 2017-06-10 20:35:21 +0200 |
---|---|---|
committer | Eduardo Lima Mitev <[email protected]> | 2017-12-12 08:18:32 +0100 |
commit | 5bc03d250861df6836f9c9fe37e0609c1777a87b (patch) | |
tree | 378bee83caef17baf2c2793d06f18c2484afb5a5 /src/mesa/main/glspirv.c | |
parent | a8889f5cc7129c1f8942248d620f64b4496e8f35 (diff) |
mesa: implement SPIR-V loading in glShaderBinary
v2: * Add a gl_shader_spirv_data member to gl_shader, which already
encapsulates a gl_spirv_module where the binary will be saved.
(Eduardo Lima)
* Just use the 'spirv_data' member to know whether a gl_shader has
the SPIR_V_BINARY_ARB state. (Timothy Arceri)
* Remove redundant argument checks. Move extension presence check
to API entry point where the rest of checks are. Retype 'n' and
'length'arguments to use the correct and more standard types.
(Ian Romanick)
* Fix some nitpicks. (Ian Romanick)
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/mesa/main/glspirv.c')
-rw-r--r-- | src/mesa/main/glspirv.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/mesa/main/glspirv.c b/src/mesa/main/glspirv.c index 8d1e652e088..7eb8f906c2d 100644 --- a/src/mesa/main/glspirv.c +++ b/src/mesa/main/glspirv.c @@ -25,6 +25,8 @@ #include "errors.h" +#include "errors.h" + #include "util/u_atomic.h" void @@ -59,6 +61,47 @@ _mesa_shader_spirv_data_reference(struct gl_shader_spirv_data **dest, p_atomic_inc(&src->RefCount); } +void +_mesa_spirv_shader_binary(struct gl_context *ctx, + unsigned n, struct gl_shader **shaders, + const void* binary, size_t length) +{ + struct gl_spirv_module *module; + struct gl_shader_spirv_data *spirv_data; + + assert(length >= 0); + + module = malloc(sizeof(*module) + length); + if (!module) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderBinary"); + return; + } + + p_atomic_set(&module->RefCount, 0); + module->Length = length; + memcpy(&module->Binary[0], binary, length); + + for (int i = 0; i < n; ++i) { + struct gl_shader *sh = shaders[i]; + + spirv_data = rzalloc(NULL, struct gl_shader_spirv_data); + _mesa_shader_spirv_data_reference(&sh->spirv_data, spirv_data); + _mesa_spirv_module_reference(&spirv_data->SpirVModule, module); + + sh->CompileStatus = compile_failure; + + free((void *)sh->Source); + sh->Source = NULL; + free((void *)sh->FallbackSource); + sh->FallbackSource = NULL; + + ralloc_free(sh->ir); + sh->ir = NULL; + ralloc_free(sh->symbols); + sh->symbols = NULL; + } +} + void GLAPIENTRY _mesa_SpecializeShaderARB(GLuint shader, const GLchar *pEntryPoint, |