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