1b8e80941Smrg/*
2b8e80941Smrg * Copyright © 2015 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8b8e80941Smrg * and/or sell copies of the Software, and to permit persons to whom the
9b8e80941Smrg * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
18b8e80941Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19b8e80941Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20b8e80941Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21b8e80941Smrg * IN THE SOFTWARE.
22b8e80941Smrg *
23b8e80941Smrg * Authors:
24b8e80941Smrg *    Jason Ekstrand (jason@jlekstrand.net)
25b8e80941Smrg *
26b8e80941Smrg */
27b8e80941Smrg
28b8e80941Smrg#ifndef _NIR_SPIRV_H_
29b8e80941Smrg#define _NIR_SPIRV_H_
30b8e80941Smrg
31b8e80941Smrg#include "compiler/nir/nir.h"
32b8e80941Smrg#include "compiler/shader_info.h"
33b8e80941Smrg
34b8e80941Smrg#ifdef __cplusplus
35b8e80941Smrgextern "C" {
36b8e80941Smrg#endif
37b8e80941Smrg
38b8e80941Smrgstruct nir_spirv_specialization {
39b8e80941Smrg   uint32_t id;
40b8e80941Smrg   union {
41b8e80941Smrg      uint32_t data32;
42b8e80941Smrg      uint64_t data64;
43b8e80941Smrg   };
44b8e80941Smrg   bool defined_on_module;
45b8e80941Smrg};
46b8e80941Smrg
47b8e80941Smrgenum nir_spirv_debug_level {
48b8e80941Smrg   NIR_SPIRV_DEBUG_LEVEL_INFO,
49b8e80941Smrg   NIR_SPIRV_DEBUG_LEVEL_WARNING,
50b8e80941Smrg   NIR_SPIRV_DEBUG_LEVEL_ERROR,
51b8e80941Smrg};
52b8e80941Smrg
53b8e80941Smrgenum nir_spirv_execution_environment {
54b8e80941Smrg   NIR_SPIRV_VULKAN = 0,
55b8e80941Smrg   NIR_SPIRV_OPENCL,
56b8e80941Smrg   NIR_SPIRV_OPENGL,
57b8e80941Smrg};
58b8e80941Smrg
59b8e80941Smrgstruct spirv_to_nir_options {
60b8e80941Smrg   enum nir_spirv_execution_environment environment;
61b8e80941Smrg
62b8e80941Smrg   /* Whether or not to lower all workgroup variable access to offsets
63b8e80941Smrg    * up-front.  This means you will _shared intrinsics instead of _var
64b8e80941Smrg    * for workgroup data access.
65b8e80941Smrg    *
66b8e80941Smrg    * This is currently required for full variable pointers support.
67b8e80941Smrg    */
68b8e80941Smrg   bool lower_workgroup_access_to_offsets;
69b8e80941Smrg
70b8e80941Smrg   /* Whether or not to lower all UBO/SSBO access to offsets up-front. */
71b8e80941Smrg   bool lower_ubo_ssbo_access_to_offsets;
72b8e80941Smrg
73b8e80941Smrg   struct spirv_supported_capabilities caps;
74b8e80941Smrg
75b8e80941Smrg   /* Storage types for various kinds of pointers. */
76b8e80941Smrg   const struct glsl_type *ubo_ptr_type;
77b8e80941Smrg   const struct glsl_type *ssbo_ptr_type;
78b8e80941Smrg   const struct glsl_type *phys_ssbo_ptr_type;
79b8e80941Smrg   const struct glsl_type *push_const_ptr_type;
80b8e80941Smrg   const struct glsl_type *shared_ptr_type;
81b8e80941Smrg   const struct glsl_type *global_ptr_type;
82b8e80941Smrg   const struct glsl_type *temp_ptr_type;
83b8e80941Smrg
84b8e80941Smrg   struct {
85b8e80941Smrg      void (*func)(void *private_data,
86b8e80941Smrg                   enum nir_spirv_debug_level level,
87b8e80941Smrg                   size_t spirv_offset,
88b8e80941Smrg                   const char *message);
89b8e80941Smrg      void *private_data;
90b8e80941Smrg   } debug;
91b8e80941Smrg};
92b8e80941Smrg
93b8e80941Smrgbool gl_spirv_validation(const uint32_t *words, size_t word_count,
94b8e80941Smrg                         struct nir_spirv_specialization *spec, unsigned num_spec,
95b8e80941Smrg                         gl_shader_stage stage, const char *entry_point_name);
96b8e80941Smrg
97b8e80941Smrgnir_function *spirv_to_nir(const uint32_t *words, size_t word_count,
98b8e80941Smrg                           struct nir_spirv_specialization *specializations,
99b8e80941Smrg                           unsigned num_specializations,
100b8e80941Smrg                           gl_shader_stage stage, const char *entry_point_name,
101b8e80941Smrg                           const struct spirv_to_nir_options *options,
102b8e80941Smrg                           const nir_shader_compiler_options *nir_options);
103b8e80941Smrg
104b8e80941Smrg#ifdef __cplusplus
105b8e80941Smrg}
106b8e80941Smrg#endif
107b8e80941Smrg
108b8e80941Smrg#endif /* _NIR_SPIRV_H_ */
109