2 * Copyright © 2011 Intel Corporation
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:
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
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
28 * Program key structures.
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.
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.
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
47 enum PACKED gen6_gather_sampler_wa
{
48 WA_SIGN
= 1, /* whether we need to sign extend */
49 WA_8BIT
= 2, /* if we have an 8bit format needing wa */
50 WA_16BIT
= 4, /* if we have a 16bit format needing wa */
54 * Sampler information needed by VS, WM, and GS program cache keys.
56 struct brw_sampler_prog_key_data
{
58 * EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzles.
60 uint16_t swizzles
[MAX_SAMPLERS
];
62 uint32_t gl_clamp_mask
[3];
65 * For RG32F, gather4's channel select is broken.
67 uint32_t gather_channel_quirk_mask
;
70 * Whether this sampler uses the compressed multisample surface layout.
72 uint32_t compressed_multisample_layout_mask
;
75 * For Sandybridge, which shader w/a we need for gather quirks.
77 enum gen6_gather_sampler_wa gen6_gather_wa
[MAX_SAMPLERS
];
81 /** The program key for Vertex Shaders. */
82 struct brw_vs_prog_key
{
83 unsigned program_string_id
;
86 * Per-attribute workaround flags
88 uint8_t gl_attrib_wa_flags
[VERT_ATTRIB_MAX
];
92 bool clamp_vertex_color
:1;
95 * How many user clipping planes are being uploaded to the vertex shader as
98 * These are used for lowering legacy gl_ClipVertex/gl_Position clipping to
101 unsigned nr_userclip_plane_consts
:4;
104 * For pre-Gen6 hardware, a bitfield indicating which texture coordinates
105 * are going to be replaced with point coordinates (as a consequence of a
106 * call to glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)). Because
107 * our SF thread requires exact matching between VS outputs and FS inputs,
108 * these texture coordinates will need to be unconditionally included in
109 * the VUE, even if they aren't written by the vertex shader.
111 uint8_t point_coord_replace
;
113 struct brw_sampler_prog_key_data tex
;
116 /** The program key for Geometry Shaders. */
117 struct brw_gs_prog_key
119 unsigned program_string_id
;
121 struct brw_sampler_prog_key_data tex
;
124 /** The program key for Fragment/Pixel Shaders. */
125 struct brw_wm_prog_key
{
129 bool persample_shading
:1;
131 unsigned nr_color_regions
:5;
132 bool replicate_alpha
:1;
133 bool render_to_fbo
:1;
134 bool clamp_fragment_color
:1;
135 bool compute_pos_offset
:1;
136 bool compute_sample_id
:1;
138 bool high_quality_derivatives
:1;
140 uint16_t drawable_height
;
141 uint64_t input_slots_valid
;
142 unsigned program_string_id
;
143 GLenum alpha_test_func
; /* < For Gen4/5 MRT alpha test */
144 float alpha_test_ref
;
146 struct brw_sampler_prog_key_data tex
;
155 void brw_setup_tex_for_precompile(struct brw_context
*brw
,
156 struct brw_sampler_prog_key_data
*tex
,
157 struct gl_program
*prog
);
159 void brw_populate_sampler_prog_key_data(struct gl_context
*ctx
,
160 const struct gl_program
*prog
,
161 unsigned sampler_count
,
162 struct brw_sampler_prog_key_data
*key
);
163 bool brw_debug_recompile_sampler_key(struct brw_context
*brw
,
164 const struct brw_sampler_prog_key_data
*old_key
,
165 const struct brw_sampler_prog_key_data
*key
);
166 void brw_add_texrect_params(struct gl_program
*prog
);
169 brw_mark_surface_used(struct brw_stage_prog_data
*prog_data
,
170 unsigned surf_index
);
173 brw_stage_prog_data_free(const void *prog_data
);
176 brw_dump_ir(const char *stage
, struct gl_shader_program
*shader_prog
,
177 struct gl_shader
*shader
, struct gl_program
*prog
);