• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef R600_SHADER_H
24 #define R600_SHADER_H
25 
26 #include "r600_asm.h"
27 
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /* Valid shader configurations:
34  *
35  * API shaders       VS | TCS | TES | GS |pass| PS
36  * are compiled as:     |     |     |    |thru|
37  *                      |     |     |    |    |
38  * Only VS & PS:     VS | --  | --  | -- | -- | PS
39  * With GS:          ES | --  | --  | GS | VS | PS
40  * With Tessel.:     LS | HS  | VS  | -- | -- | PS
41  * With both:        LS | HS  | ES  | GS | VS | PS
42  */
43 
44 struct r600_shader_io {
45 	unsigned		name;
46 	unsigned		gpr;
47 	unsigned		done;
48 	unsigned		sid;
49 	int			spi_sid;
50 	unsigned		interpolate;
51 	unsigned		ij_index;
52 	unsigned		interpolate_location; //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
53 	unsigned		lds_pos; /* for evergreen */
54 	unsigned		back_color_input;
55 	unsigned		write_mask;
56 	int			ring_offset;
57 	unsigned		uses_interpolate_at_centroid;
58 };
59 
60 struct r600_shader_atomic {
61 	unsigned start, end;
62 	unsigned buffer_id;
63 	unsigned hw_idx;
64 };
65 
66 struct r600_shader {
67 	unsigned		processor_type;
68 	struct r600_bytecode		bc;
69 	unsigned		ninput;
70 	unsigned		noutput;
71 	unsigned                nhwatomic;
72 	unsigned		nlds;
73 	unsigned		nsys_inputs;
74 	struct r600_shader_io	input[PIPE_MAX_SHADER_INPUTS];
75 	struct r600_shader_io	output[PIPE_MAX_SHADER_OUTPUTS];
76 	struct r600_shader_atomic atomics[8];
77 	unsigned                nhwatomic_ranges;
78 	boolean			uses_kill;
79 	boolean			fs_write_all;
80 	boolean			two_side;
81 	boolean			needs_scratch_space;
82 	/* Real number of ps color exports compiled in the bytecode */
83 	unsigned		nr_ps_color_exports;
84 	unsigned                ps_color_export_mask;
85 	unsigned                ps_export_highest;
86 	/* bit n is set if the shader writes gl_ClipDistance[n] */
87 	unsigned		cc_dist_mask;
88 	unsigned		clip_dist_write;
89 	unsigned                cull_dist_write;
90 	boolean			vs_position_window_space;
91 	/* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
92 	boolean			vs_out_misc_write;
93 	boolean			vs_out_point_size;
94 	boolean			vs_out_layer;
95 	boolean			vs_out_viewport;
96 	boolean			vs_out_edgeflag;
97 	boolean			has_txq_cube_array_z_comp;
98 	boolean			uses_tex_buffers;
99 	boolean                 gs_prim_id_input;
100 	boolean                 gs_tri_strip_adj_fix;
101 	uint8_t			ps_conservative_z;
102 
103 	/* Size in bytes of a data item in the ring(s) (single vertex data).
104 	   Stages with only one ring items 123 will be set to 0. */
105 	unsigned		ring_item_sizes[4];
106 
107 	unsigned		indirect_files;
108 	unsigned		max_arrays;
109 	unsigned		num_arrays;
110 	unsigned		vs_as_es;
111 	unsigned		vs_as_ls;
112 	unsigned		vs_as_gs_a;
113 	unsigned                tes_as_es;
114 	unsigned                tcs_prim_mode;
115 	unsigned                ps_prim_id_input;
116 	unsigned                num_loops;
117 
118 	struct r600_shader_array * arrays;
119 
120 	boolean			uses_doubles;
121 	boolean                 uses_atomics;
122 	boolean			uses_images;
123 	boolean			uses_helper_invocation;
124 	boolean			uses_interpolate_at_sample;
125 	uint8_t                 atomic_base;
126 	uint8_t			rat_base;
127 	uint8_t                 image_size_const_offset;
128 };
129 
130 union r600_shader_key {
131 	struct {
132 		unsigned	nr_cbufs:4;
133 		unsigned        first_atomic_counter:4;
134 		unsigned        image_size_const_offset:5;
135 		unsigned	color_two_side:1;
136 		unsigned	alpha_to_one:1;
137 		unsigned        apply_sample_id_mask:1;
138 		unsigned        dual_source_blend:1;
139 	} ps;
140 	struct {
141 		unsigned	prim_id_out:8;
142 		unsigned        first_atomic_counter:4;
143 		unsigned	as_es:1; /* export shader */
144 		unsigned	as_ls:1; /* local shader */
145 		unsigned	as_gs_a:1;
146 	} vs;
147 	struct {
148 		unsigned        first_atomic_counter:4;
149 		unsigned	as_es:1;
150 	} tes;
151 	struct {
152 		unsigned        first_atomic_counter:4;
153 		unsigned	prim_mode:3;
154 	} tcs;
155 	struct {
156 		unsigned        first_atomic_counter:4;
157 		unsigned        tri_strip_adj_fix:1;
158 	} gs;
159 };
160 
161 struct r600_shader_array {
162 	unsigned gpr_start;
163 	unsigned gpr_count;
164 	unsigned comp_mask;
165 };
166 
167 struct r600_pipe_shader {
168 	struct r600_pipe_shader_selector *selector;
169 	struct r600_pipe_shader	*next_variant;
170 	/* for GS - corresponding copy shader (installed as VS) */
171 	struct r600_pipe_shader *gs_copy_shader;
172 	struct r600_shader	shader;
173 	struct r600_command_buffer command_buffer; /* register writes */
174 	struct r600_resource	*bo;
175 	unsigned		sprite_coord_enable;
176 	unsigned		flatshade;
177 	unsigned		msaa;
178 	unsigned		pa_cl_vs_out_cntl;
179 	unsigned		nr_ps_color_outputs;
180 	unsigned                ps_color_export_mask;
181 
182 	union r600_shader_key	key;
183 	unsigned		db_shader_control;
184 	unsigned		ps_depth_export;
185 	unsigned		enabled_stream_buffers_mask;
186 	unsigned		scratch_space_needed; /* size of scratch space (if > 0) counted in vec4 */
187 };
188 
189 /* return the table index 0-5 for TGSI_INTERPOLATE_LINEAR/PERSPECTIVE and
190  TGSI_INTERPOLATE_LOC_CENTER/SAMPLE/COUNT. Other input values return -1. */
191 int eg_get_interpolator_index(unsigned interpolate, unsigned location);
192 
193 int r600_get_lds_unique_index(unsigned semantic_name, unsigned index);
194 
195 int generate_gs_copy_shader(struct r600_context *rctx,
196                             struct r600_pipe_shader *gs,
197                             struct pipe_stream_output_info *so);
198 
199 #ifdef __cplusplus
200 }  // extern "C"
201 #endif
202 
203 
204 #endif
205