101e04c3fSmrg/*
201e04c3fSmrg * Copyright 2017 Advanced Micro Devices, Inc.
301e04c3fSmrg *
401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
501e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
601e04c3fSmrg * to deal in the Software without restriction, including without limitation
701e04c3fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
801e04c3fSmrg * license, and/or sell copies of the Software, and to permit persons to whom
901e04c3fSmrg * the Software is furnished to do so, subject to the following conditions:
1001e04c3fSmrg *
1101e04c3fSmrg * The above copyright notice and this permission notice (including the next
1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the
1301e04c3fSmrg * Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
1801e04c3fSmrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2101e04c3fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg */
2301e04c3fSmrg
2401e04c3fSmrg#ifndef GLSPIRV_H
2501e04c3fSmrg#define GLSPIRV_H
2601e04c3fSmrg
2701e04c3fSmrg#include "compiler/nir/nir.h"
2801e04c3fSmrg
2901e04c3fSmrg#ifdef __cplusplus
3001e04c3fSmrgextern "C" {
3101e04c3fSmrg#endif
3201e04c3fSmrg
3301e04c3fSmrgstruct gl_shader_program;
3401e04c3fSmrgstruct gl_context;
3501e04c3fSmrgstruct gl_shader;
3601e04c3fSmrg
3701e04c3fSmrg/**
3801e04c3fSmrg * A SPIR-V module contains the raw SPIR-V binary as set by ShaderBinary.
3901e04c3fSmrg *
4001e04c3fSmrg * It is reference-counted, because the same module can be attached to multiple
4101e04c3fSmrg * shader objects simultaneously.
4201e04c3fSmrg */
4301e04c3fSmrgstruct gl_spirv_module {
4401e04c3fSmrg   unsigned RefCount;
4501e04c3fSmrg   GLint Length;
4601e04c3fSmrg   char Binary[0];
4701e04c3fSmrg};
4801e04c3fSmrg
4901e04c3fSmrg/**
5001e04c3fSmrg * SPIR-V data needed to compile and link a SPIR-V shader.
5101e04c3fSmrg *
5201e04c3fSmrg * It includes a SPIR-V binary that is potentially shared among different
5301e04c3fSmrg * shaders; and shader-specific specialization constants and entry point.
5401e04c3fSmrg *
5501e04c3fSmrg * It is reference-counted because it is shared between gl_shader and its
5601e04c3fSmrg * corresponding gl_linked_shader.
5701e04c3fSmrg */
5801e04c3fSmrgstruct gl_shader_spirv_data {
5901e04c3fSmrg   GLint RefCount;
6001e04c3fSmrg
6101e04c3fSmrg   struct gl_spirv_module *SpirVModule;
6201e04c3fSmrg
6301e04c3fSmrg   GLchar *SpirVEntryPoint;
6401e04c3fSmrg
6501e04c3fSmrg   GLuint NumSpecializationConstants;
6601e04c3fSmrg   GLuint *SpecializationConstantsIndex;
6701e04c3fSmrg   GLuint *SpecializationConstantsValue;
6801e04c3fSmrg};
6901e04c3fSmrg
7001e04c3fSmrgvoid
7101e04c3fSmrg_mesa_spirv_module_reference(struct gl_spirv_module **dest,
7201e04c3fSmrg                             struct gl_spirv_module *src);
7301e04c3fSmrg
7401e04c3fSmrgvoid
7501e04c3fSmrg_mesa_shader_spirv_data_reference(struct gl_shader_spirv_data **dest,
7601e04c3fSmrg                                  struct gl_shader_spirv_data *src);
7701e04c3fSmrg
7801e04c3fSmrgvoid
7901e04c3fSmrg_mesa_spirv_shader_binary(struct gl_context *ctx,
8001e04c3fSmrg                          unsigned n, struct gl_shader **shaders,
8101e04c3fSmrg                          const void* binary, size_t length);
8201e04c3fSmrg
8301e04c3fSmrgvoid
8401e04c3fSmrg_mesa_spirv_link_shaders(struct gl_context *ctx,
8501e04c3fSmrg                         struct gl_shader_program *prog);
8601e04c3fSmrg
8701e04c3fSmrgnir_shader *
8801e04c3fSmrg_mesa_spirv_to_nir(struct gl_context *ctx,
8901e04c3fSmrg                   const struct gl_shader_program *prog,
9001e04c3fSmrg                   gl_shader_stage stage,
9101e04c3fSmrg                   const nir_shader_compiler_options *options);
9201e04c3fSmrg
9301e04c3fSmrg/**
9401e04c3fSmrg * \name API functions
9501e04c3fSmrg */
9601e04c3fSmrg/*@{*/
9701e04c3fSmrg
9801e04c3fSmrgvoid GLAPIENTRY
9901e04c3fSmrg_mesa_SpecializeShaderARB(GLuint shader,
10001e04c3fSmrg                          const GLchar *pEntryPoint,
10101e04c3fSmrg                          GLuint numSpecializationConstants,
10201e04c3fSmrg                          const GLuint *pConstantIndex,
10301e04c3fSmrg                          const GLuint *pConstantValue);
10401e04c3fSmrg
10501e04c3fSmrg/*@}*/
10601e04c3fSmrg
10701e04c3fSmrg#ifdef __cplusplus
10801e04c3fSmrg}
10901e04c3fSmrg#endif
11001e04c3fSmrg
11101e04c3fSmrg#endif /* GLSPIRV_H */
112