1b8e80941Smrg/*
2b8e80941Smrg * Copyright 2017 Advanced Micro Devices, Inc.
3b8e80941Smrg *
4b8e80941Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5b8e80941Smrg * copy of this software and associated documentation files (the "Software"),
6b8e80941Smrg * to deal in the Software without restriction, including without limitation
7b8e80941Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
8b8e80941Smrg * license, and/or sell copies of the Software, and to permit persons to whom
9b8e80941Smrg * the Software is furnished to do so, subject to the following conditions:
10b8e80941Smrg *
11b8e80941Smrg * The above copyright notice and this permission notice (including the next
12b8e80941Smrg * paragraph) shall be included in all copies or substantial portions of the
13b8e80941Smrg * Software.
14b8e80941Smrg *
15b8e80941Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16b8e80941Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17b8e80941Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18b8e80941Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19b8e80941Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20b8e80941Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21b8e80941Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
22b8e80941Smrg */
23b8e80941Smrg
24b8e80941Smrg#ifndef GLSPIRV_H
25b8e80941Smrg#define GLSPIRV_H
26b8e80941Smrg
27b8e80941Smrg#include "compiler/nir/nir.h"
28b8e80941Smrg
29b8e80941Smrg#ifdef __cplusplus
30b8e80941Smrgextern "C" {
31b8e80941Smrg#endif
32b8e80941Smrg
33b8e80941Smrgstruct gl_shader_program;
34b8e80941Smrgstruct gl_context;
35b8e80941Smrgstruct gl_shader;
36b8e80941Smrg
37b8e80941Smrg/**
38b8e80941Smrg * A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
39b8e80941Smrg *
40b8e80941Smrg * It is reference-counted, because the same module can be attached to multiple
41b8e80941Smrg * shader objects simultaneously.
42b8e80941Smrg */
43b8e80941Smrgstruct gl_spirv_module {
44b8e80941Smrg   unsigned RefCount;
45b8e80941Smrg   GLint Length;
46b8e80941Smrg   char Binary[0];
47b8e80941Smrg};
48b8e80941Smrg
49b8e80941Smrg/**
50b8e80941Smrg * SPIR-V data needed to compile and link a SPIR-V shader.
51b8e80941Smrg *
52b8e80941Smrg * It includes a SPIR-V binary that is potentially shared among different
53b8e80941Smrg * shaders; and shader-specific specialization constants and entry point.
54b8e80941Smrg *
55b8e80941Smrg * It is reference-counted because it is shared between gl_shader and its
56b8e80941Smrg * corresponding gl_linked_shader.
57b8e80941Smrg */
58b8e80941Smrgstruct gl_shader_spirv_data {
59b8e80941Smrg   GLint RefCount;
60b8e80941Smrg
61b8e80941Smrg   struct gl_spirv_module *SpirVModule;
62b8e80941Smrg
63b8e80941Smrg   GLchar *SpirVEntryPoint;
64b8e80941Smrg
65b8e80941Smrg   GLuint NumSpecializationConstants;
66b8e80941Smrg   GLuint *SpecializationConstantsIndex;
67b8e80941Smrg   GLuint *SpecializationConstantsValue;
68b8e80941Smrg};
69b8e80941Smrg
70b8e80941Smrgvoid
71b8e80941Smrg_mesa_spirv_module_reference(struct gl_spirv_module **dest,
72b8e80941Smrg                             struct gl_spirv_module *src);
73b8e80941Smrg
74b8e80941Smrgvoid
75b8e80941Smrg_mesa_shader_spirv_data_reference(struct gl_shader_spirv_data **dest,
76b8e80941Smrg                                  struct gl_shader_spirv_data *src);
77b8e80941Smrg
78b8e80941Smrgvoid
79b8e80941Smrg_mesa_spirv_shader_binary(struct gl_context *ctx,
80b8e80941Smrg                          unsigned n, struct gl_shader **shaders,
81b8e80941Smrg                          const void* binary, size_t length);
82b8e80941Smrg
83b8e80941Smrgvoid
84b8e80941Smrg_mesa_spirv_link_shaders(struct gl_context *ctx,
85b8e80941Smrg                         struct gl_shader_program *prog);
86b8e80941Smrg
87b8e80941Smrgnir_shader *
88b8e80941Smrg_mesa_spirv_to_nir(struct gl_context *ctx,
89b8e80941Smrg                   const struct gl_shader_program *prog,
90b8e80941Smrg                   gl_shader_stage stage,
91b8e80941Smrg                   const nir_shader_compiler_options *options);
92b8e80941Smrg
93b8e80941Smrg/**
94b8e80941Smrg * \name API functions
95b8e80941Smrg */
96b8e80941Smrg/*@{*/
97b8e80941Smrg
98b8e80941Smrgvoid GLAPIENTRY
99b8e80941Smrg_mesa_SpecializeShaderARB(GLuint shader,
100b8e80941Smrg                          const GLchar *pEntryPoint,
101b8e80941Smrg                          GLuint numSpecializationConstants,
102b8e80941Smrg                          const GLuint *pConstantIndex,
103b8e80941Smrg                          const GLuint *pConstantValue);
104b8e80941Smrg
105b8e80941Smrg/*@}*/
106b8e80941Smrg
107b8e80941Smrg#ifdef __cplusplus
108b8e80941Smrg}
109b8e80941Smrg#endif
110b8e80941Smrg
111b8e80941Smrg#endif /* GLSPIRV_H */
112