1 /*
2  * Copyright © 2011 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef BRW_PROGRAM_H
25 #define BRW_PROGRAM_H
26 
27 #include "compiler/brw_compiler.h"
28 #include "nir.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct brw_context;
35 struct blob;
36 struct blob_reader;
37 
38 enum brw_param_domain {
39    BRW_PARAM_DOMAIN_BUILTIN = 0,
40    BRW_PARAM_DOMAIN_PARAMETER,
41    BRW_PARAM_DOMAIN_UNIFORM,
42    BRW_PARAM_DOMAIN_IMAGE,
43 };
44 
45 #define BRW_PARAM(domain, val)   (BRW_PARAM_DOMAIN_##domain << 24 | (val))
46 #define BRW_PARAM_DOMAIN(param)  ((uint32_t)(param) >> 24)
47 #define BRW_PARAM_VALUE(param)   ((uint32_t)(param) & 0x00ffffff)
48 
49 #define BRW_PARAM_PARAMETER(idx, comp) \
50    BRW_PARAM(PARAMETER, ((idx) << 2) | (comp))
51 #define BRW_PARAM_PARAMETER_IDX(param)    (BRW_PARAM_VALUE(param) >> 2)
52 #define BRW_PARAM_PARAMETER_COMP(param)   (BRW_PARAM_VALUE(param) & 0x3)
53 
54 #define BRW_PARAM_UNIFORM(idx)            BRW_PARAM(UNIFORM, (idx))
55 #define BRW_PARAM_UNIFORM_IDX(param)      BRW_PARAM_VALUE(param)
56 
57 #define BRW_PARAM_IMAGE(idx, offset) BRW_PARAM(IMAGE, ((idx) << 8) | (offset))
58 #define BRW_PARAM_IMAGE_IDX(value)        (BRW_PARAM_VALUE(value) >> 8)
59 #define BRW_PARAM_IMAGE_OFFSET(value)     (BRW_PARAM_VALUE(value) & 0xf)
60 
61 struct nir_shader *brw_create_nir(struct brw_context *brw,
62                                   const struct gl_shader_program *shader_prog,
63                                   struct gl_program *prog,
64                                   gl_shader_stage stage,
65                                   bool is_scalar);
66 
67 void brw_nir_lower_resources(nir_shader *nir,
68                              struct gl_shader_program *shader_prog,
69                              struct gl_program *prog,
70                              const struct intel_device_info *devinfo);
71 
72 void brw_shader_gather_info(nir_shader *nir, struct gl_program *prog);
73 
74 void brw_setup_tex_for_precompile(const struct intel_device_info *devinfo,
75                                   struct brw_sampler_prog_key_data *tex,
76                                   const struct gl_program *prog);
77 
78 void brw_populate_base_prog_key(struct gl_context *ctx,
79                                 const struct brw_program *prog,
80                                 struct brw_base_prog_key *key);
81 void brw_populate_default_base_prog_key(const struct intel_device_info *devinfo,
82                                         const struct brw_program *prog,
83                                         struct brw_base_prog_key *key);
84 void brw_debug_recompile(struct brw_context *brw, gl_shader_stage stage,
85                          unsigned api_id, struct brw_base_prog_key *key);
86 
87 uint32_t
88 brw_assign_common_binding_table_offsets(const struct intel_device_info *devinfo,
89                                         const struct gl_program *prog,
90                                         struct brw_stage_prog_data *stage_prog_data,
91                                         uint32_t next_binding_table_offset);
92 
93 void
94 brw_populate_default_key(const struct brw_compiler *compiler,
95                          union brw_any_prog_key *prog_key,
96                          struct gl_shader_program *sh_prog,
97                          struct gl_program *prog);
98 
99 void
100 brw_stage_prog_data_free(const void *prog_data);
101 
102 void
103 brw_dump_arb_asm(const char *stage, struct gl_program *prog);
104 
105 bool brw_vs_precompile(struct gl_context *ctx, struct gl_program *prog);
106 bool brw_tcs_precompile(struct gl_context *ctx,
107                         struct gl_shader_program *shader_prog,
108                         struct gl_program *prog);
109 bool brw_tes_precompile(struct gl_context *ctx,
110                         struct gl_shader_program *shader_prog,
111                         struct gl_program *prog);
112 bool brw_gs_precompile(struct gl_context *ctx, struct gl_program *prog);
113 bool brw_fs_precompile(struct gl_context *ctx, struct gl_program *prog);
114 bool brw_cs_precompile(struct gl_context *ctx, struct gl_program *prog);
115 
116 GLboolean brw_link_shader(struct gl_context *ctx, struct gl_shader_program *prog);
117 
118 void brw_upload_tcs_prog(struct brw_context *brw);
119 void brw_tcs_populate_key(struct brw_context *brw,
120                           struct brw_tcs_prog_key *key);
121 void brw_tcs_populate_default_key(const struct brw_compiler *compiler,
122                                   struct brw_tcs_prog_key *key,
123                                   struct gl_shader_program *sh_prog,
124                                   struct gl_program *prog);
125 void brw_upload_tes_prog(struct brw_context *brw);
126 void brw_tes_populate_key(struct brw_context *brw,
127                           struct brw_tes_prog_key *key);
128 void brw_tes_populate_default_key(const struct brw_compiler *compiler,
129                                   struct brw_tes_prog_key *key,
130                                   struct gl_shader_program *sh_prog,
131                                   struct gl_program *prog);
132 
133 void brw_write_blob_program_data(struct blob *binary, gl_shader_stage stage,
134                                  const void *program,
135                                  struct brw_stage_prog_data *prog_data);
136 bool brw_read_blob_program_data(struct blob_reader *binary,
137                                 struct gl_program *prog, gl_shader_stage stage,
138                                 const uint8_t **program,
139                                 struct brw_stage_prog_data *prog_data);
140 
141 #ifdef __cplusplus
142 } /* extern "C" */
143 #endif
144 
145 #endif
146