i965: Move program key structures to brw_program.h.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_program.h
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 /**
28 * Program key structures.
29 *
30 * When drawing, we look for the currently bound shaders in the program
31 * cache. This is essentially a hash table lookup, and these are the keys.
32 *
33 * Sometimes OpenGL features specified as state need to be simulated via
34 * shader code, due to a mismatch between the API and the hardware. This
35 * is often referred to as "non-orthagonal state" or "NOS". We store NOS
36 * in the program key so it's considered when searching for a program. If
37 * we haven't seen a particular combination before, we have to recompile a
38 * new specialized version.
39 *
40 * Shader compilation should not look up state in gl_context directly, but
41 * instead use the copy in the program key. This guarantees recompiles will
42 * happen correctly.
43 *
44 * @{
45 */
46
47 /**
48 * Sampler information needed by VS, WM, and GS program cache keys.
49 */
50 struct brw_sampler_prog_key_data {
51 /**
52 * EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzles.
53 */
54 uint16_t swizzles[MAX_SAMPLERS];
55
56 uint32_t gl_clamp_mask[3];
57
58 /**
59 * For RG32F, gather4's channel select is broken.
60 */
61 uint32_t gather_channel_quirk_mask;
62
63 /**
64 * Whether this sampler uses the compressed multisample surface layout.
65 */
66 uint32_t compressed_multisample_layout_mask;
67
68 /**
69 * For Sandybridge, which shader w/a we need for gather quirks.
70 */
71 uint8_t gen6_gather_wa[MAX_SAMPLERS];
72 };
73
74
75 struct brw_vec4_prog_key {
76 GLuint program_string_id;
77
78 /**
79 * True if at least one clip flag is enabled, regardless of whether the
80 * shader uses clip planes or gl_ClipDistance.
81 */
82 GLuint userclip_active:1;
83
84 /**
85 * How many user clipping planes are being uploaded to the vertex shader as
86 * push constants.
87 */
88 GLuint nr_userclip_plane_consts:4;
89
90 GLuint clamp_vertex_color:1;
91
92 struct brw_sampler_prog_key_data tex;
93 };
94
95 /** The program key for Vertex Shaders. */
96 struct brw_vs_prog_key {
97 struct brw_vec4_prog_key base;
98
99 /*
100 * Per-attribute workaround flags
101 */
102 uint8_t gl_attrib_wa_flags[VERT_ATTRIB_MAX];
103
104 GLuint copy_edgeflag:1;
105
106 /**
107 * For pre-Gen6 hardware, a bitfield indicating which texture coordinates
108 * are going to be replaced with point coordinates (as a consequence of a
109 * call to glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)). Because
110 * our SF thread requires exact matching between VS outputs and FS inputs,
111 * these texture coordinates will need to be unconditionally included in
112 * the VUE, even if they aren't written by the vertex shader.
113 */
114 GLuint point_coord_replace:8;
115 };
116
117 /** The program key for Geometry Shaders. */
118 struct brw_gs_prog_key
119 {
120 struct brw_vec4_prog_key base;
121
122 GLbitfield64 input_varyings;
123 };
124
125 /** The program key for Fragment/Pixel Shaders. */
126 struct brw_wm_prog_key {
127 uint8_t iz_lookup;
128 GLuint stats_wm:1;
129 GLuint flat_shade:1;
130 GLuint persample_shading:1;
131 GLuint persample_2x:1;
132 GLuint nr_color_regions:5;
133 GLuint replicate_alpha:1;
134 GLuint render_to_fbo:1;
135 GLuint clamp_fragment_color:1;
136 GLuint compute_pos_offset:1;
137 GLuint compute_sample_id:1;
138 GLuint line_aa:2;
139 GLuint high_quality_derivatives:1;
140
141 GLushort drawable_height;
142 GLbitfield64 input_slots_valid;
143 GLuint program_string_id:32;
144 GLenum alpha_test_func; /* < For Gen4/5 MRT alpha test */
145 float alpha_test_ref;
146
147 struct brw_sampler_prog_key_data tex;
148 };
149
150 /** @} */
151
152 enum gen6_gather_sampler_wa {
153 WA_SIGN = 1, /* whether we need to sign extend */
154 WA_8BIT = 2, /* if we have an 8bit format needing wa */
155 WA_16BIT = 4, /* if we have a 16bit format needing wa */
156 };
157
158 #ifdef __cplusplus
159 extern "C" {
160 #endif
161
162 void brw_populate_sampler_prog_key_data(struct gl_context *ctx,
163 const struct gl_program *prog,
164 unsigned sampler_count,
165 struct brw_sampler_prog_key_data *key);
166 bool brw_debug_recompile_sampler_key(struct brw_context *brw,
167 const struct brw_sampler_prog_key_data *old_key,
168 const struct brw_sampler_prog_key_data *key);
169 void brw_add_texrect_params(struct gl_program *prog);
170
171 void
172 brw_mark_surface_used(struct brw_stage_prog_data *prog_data,
173 unsigned surf_index);
174
175 bool
176 brw_stage_prog_data_compare(const struct brw_stage_prog_data *a,
177 const struct brw_stage_prog_data *b);
178
179 void
180 brw_stage_prog_data_free(const void *prog_data);
181
182 void
183 brw_dump_ir(const char *stage, struct gl_shader_program *shader_prog,
184 struct gl_shader *shader, struct gl_program *prog);
185
186 #ifdef __cplusplus
187 } /* extern "C" */
188 #endif
189
190 #endif