1848b8605Smrg/*
2848b8605Smrg * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3848b8605Smrg *
4848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
5848b8605Smrg * copy of this software and associated documentation files (the "Software"),
6848b8605Smrg * to deal in the Software without restriction, including without limitation
7848b8605Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
8848b8605Smrg * license, and/or sell copies of the Software, and to permit persons to whom
9848b8605Smrg * the Software is furnished to do so, subject to the following conditions:
10848b8605Smrg *
11848b8605Smrg * The above copyright notice and this permission notice (including the next
12848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
13848b8605Smrg * Software.
14848b8605Smrg *
15848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18848b8605Smrg * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19848b8605Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20848b8605Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21848b8605Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
22848b8605Smrg */
23848b8605Smrg#ifndef R600_SHADER_H
24848b8605Smrg#define R600_SHADER_H
25848b8605Smrg
26848b8605Smrg#include "r600_asm.h"
27848b8605Smrg
28b8e80941Smrg
29b8e80941Smrg#ifdef __cplusplus
30b8e80941Smrgextern "C" {
31b8e80941Smrg#endif
32b8e80941Smrg
33b8e80941Smrg/* Valid shader configurations:
34b8e80941Smrg *
35b8e80941Smrg * API shaders       VS | TCS | TES | GS |pass| PS
36b8e80941Smrg * are compiled as:     |     |     |    |thru|
37b8e80941Smrg *                      |     |     |    |    |
38b8e80941Smrg * Only VS & PS:     VS | --  | --  | -- | -- | PS
39b8e80941Smrg * With GS:          ES | --  | --  | GS | VS | PS
40b8e80941Smrg * With Tessel.:     LS | HS  | VS  | -- | -- | PS
41b8e80941Smrg * With both:        LS | HS  | ES  | GS | VS | PS
42b8e80941Smrg */
43b8e80941Smrg
44848b8605Smrgstruct r600_shader_io {
45848b8605Smrg	unsigned		name;
46848b8605Smrg	unsigned		gpr;
47848b8605Smrg	unsigned		done;
48848b8605Smrg	int			sid;
49848b8605Smrg	int			spi_sid;
50848b8605Smrg	unsigned		interpolate;
51848b8605Smrg	unsigned		ij_index;
52b8e80941Smrg	unsigned		interpolate_location; //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
53848b8605Smrg	unsigned		lds_pos; /* for evergreen */
54848b8605Smrg	unsigned		back_color_input;
55848b8605Smrg	unsigned		write_mask;
56b8e80941Smrg	int			ring_offset;
57b8e80941Smrg};
58b8e80941Smrg
59b8e80941Smrgstruct r600_shader_atomic {
60b8e80941Smrg	unsigned start, end;
61b8e80941Smrg	unsigned buffer_id;
62b8e80941Smrg	unsigned hw_idx;
63b8e80941Smrg	unsigned array_id;
64848b8605Smrg};
65848b8605Smrg
66848b8605Smrgstruct r600_shader {
67848b8605Smrg	unsigned		processor_type;
68848b8605Smrg	struct r600_bytecode		bc;
69848b8605Smrg	unsigned		ninput;
70848b8605Smrg	unsigned		noutput;
71b8e80941Smrg	unsigned                nhwatomic;
72848b8605Smrg	unsigned		nlds;
73b8e80941Smrg	unsigned		nsys_inputs;
74b8e80941Smrg	struct r600_shader_io	input[64];
75b8e80941Smrg	struct r600_shader_io	output[64];
76b8e80941Smrg	struct r600_shader_atomic atomics[8];
77b8e80941Smrg	unsigned                nhwatomic_ranges;
78848b8605Smrg	boolean			uses_kill;
79848b8605Smrg	boolean			fs_write_all;
80848b8605Smrg	boolean			two_side;
81b8e80941Smrg	boolean			needs_scratch_space;
82848b8605Smrg	/* Number of color outputs in the TGSI shader,
83848b8605Smrg	 * sometimes it could be higher than nr_cbufs (bug?).
84848b8605Smrg	 * Also with writes_all property on eg+ it will be set to max CB number */
85848b8605Smrg	unsigned		nr_ps_max_color_exports;
86848b8605Smrg	/* Real number of ps color exports compiled in the bytecode */
87848b8605Smrg	unsigned		nr_ps_color_exports;
88b8e80941Smrg	unsigned                ps_color_export_mask;
89b8e80941Smrg	unsigned                ps_export_highest;
90848b8605Smrg	/* bit n is set if the shader writes gl_ClipDistance[n] */
91b8e80941Smrg	unsigned		cc_dist_mask;
92848b8605Smrg	unsigned		clip_dist_write;
93b8e80941Smrg	unsigned                cull_dist_write;
94848b8605Smrg	boolean			vs_position_window_space;
95848b8605Smrg	/* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
96848b8605Smrg	boolean			vs_out_misc_write;
97848b8605Smrg	boolean			vs_out_point_size;
98848b8605Smrg	boolean			vs_out_layer;
99848b8605Smrg	boolean			vs_out_viewport;
100848b8605Smrg	boolean			vs_out_edgeflag;
101848b8605Smrg	boolean			has_txq_cube_array_z_comp;
102848b8605Smrg	boolean			uses_tex_buffers;
103848b8605Smrg	boolean                 gs_prim_id_input;
104b8e80941Smrg	boolean                 gs_tri_strip_adj_fix;
105b8e80941Smrg	uint8_t			ps_conservative_z;
106848b8605Smrg
107b8e80941Smrg	/* Size in bytes of a data item in the ring(s) (single vertex data).
108b8e80941Smrg	   Stages with only one ring items 123 will be set to 0. */
109b8e80941Smrg	unsigned		ring_item_sizes[4];
110848b8605Smrg
111848b8605Smrg	unsigned		indirect_files;
112848b8605Smrg	unsigned		max_arrays;
113848b8605Smrg	unsigned		num_arrays;
114848b8605Smrg	unsigned		vs_as_es;
115b8e80941Smrg	unsigned		vs_as_ls;
116b8e80941Smrg	unsigned		vs_as_gs_a;
117b8e80941Smrg	unsigned                tes_as_es;
118b8e80941Smrg	unsigned                tcs_prim_mode;
119b8e80941Smrg	unsigned                ps_prim_id_input;
120848b8605Smrg	struct r600_shader_array * arrays;
121b8e80941Smrg
122b8e80941Smrg	boolean			uses_doubles;
123b8e80941Smrg	boolean                 uses_atomics;
124b8e80941Smrg	boolean			uses_images;
125b8e80941Smrg	boolean			uses_helper_invocation;
126b8e80941Smrg	uint8_t                 atomic_base;
127b8e80941Smrg	uint8_t			rat_base;
128b8e80941Smrg	uint8_t                 image_size_const_offset;
129848b8605Smrg};
130848b8605Smrg
131b8e80941Smrgunion r600_shader_key {
132b8e80941Smrg	struct {
133b8e80941Smrg		unsigned	nr_cbufs:4;
134b8e80941Smrg		unsigned        first_atomic_counter:4;
135b8e80941Smrg		unsigned        image_size_const_offset:5;
136b8e80941Smrg		unsigned	color_two_side:1;
137b8e80941Smrg		unsigned	alpha_to_one:1;
138b8e80941Smrg	} ps;
139b8e80941Smrg	struct {
140b8e80941Smrg		unsigned	prim_id_out:8;
141b8e80941Smrg		unsigned        first_atomic_counter:4;
142b8e80941Smrg		unsigned	as_es:1; /* export shader */
143b8e80941Smrg		unsigned	as_ls:1; /* local shader */
144b8e80941Smrg		unsigned	as_gs_a:1;
145b8e80941Smrg	} vs;
146b8e80941Smrg	struct {
147b8e80941Smrg		unsigned        first_atomic_counter:4;
148b8e80941Smrg		unsigned	as_es:1;
149b8e80941Smrg	} tes;
150b8e80941Smrg	struct {
151b8e80941Smrg		unsigned        first_atomic_counter:4;
152b8e80941Smrg		unsigned	prim_mode:3;
153b8e80941Smrg	} tcs;
154b8e80941Smrg	struct {
155b8e80941Smrg		unsigned        first_atomic_counter:4;
156b8e80941Smrg		unsigned        tri_strip_adj_fix:1;
157b8e80941Smrg	} gs;
158848b8605Smrg};
159848b8605Smrg
160848b8605Smrgstruct r600_shader_array {
161848b8605Smrg	unsigned gpr_start;
162848b8605Smrg	unsigned gpr_count;
163848b8605Smrg	unsigned comp_mask;
164848b8605Smrg};
165848b8605Smrg
166848b8605Smrgstruct r600_pipe_shader {
167848b8605Smrg	struct r600_pipe_shader_selector *selector;
168848b8605Smrg	struct r600_pipe_shader	*next_variant;
169848b8605Smrg	/* for GS - corresponding copy shader (installed as VS) */
170848b8605Smrg	struct r600_pipe_shader *gs_copy_shader;
171848b8605Smrg	struct r600_shader	shader;
172848b8605Smrg	struct r600_command_buffer command_buffer; /* register writes */
173848b8605Smrg	struct r600_resource	*bo;
174848b8605Smrg	unsigned		sprite_coord_enable;
175848b8605Smrg	unsigned		flatshade;
176848b8605Smrg	unsigned		pa_cl_vs_out_cntl;
177848b8605Smrg	unsigned		nr_ps_color_outputs;
178b8e80941Smrg	unsigned                ps_color_export_mask;
179b8e80941Smrg
180b8e80941Smrg	union r600_shader_key	key;
181848b8605Smrg	unsigned		db_shader_control;
182848b8605Smrg	unsigned		ps_depth_export;
183b8e80941Smrg	unsigned		enabled_stream_buffers_mask;
184b8e80941Smrg	unsigned		scratch_space_needed; /* size of scratch space (if > 0) counted in vec4 */
185848b8605Smrg};
186848b8605Smrg
187b8e80941Smrg/* return the table index 0-5 for TGSI_INTERPOLATE_LINEAR/PERSPECTIVE and
188b8e80941Smrg TGSI_INTERPOLATE_LOC_CENTER/SAMPLE/COUNT. Other input values return -1. */
189b8e80941Smrgint eg_get_interpolator_index(unsigned interpolate, unsigned location);
190b8e80941Smrg
191b8e80941Smrgint r600_get_lds_unique_index(unsigned semantic_name, unsigned index);
192b8e80941Smrg
193b8e80941Smrg#ifdef __cplusplus
194b8e80941Smrg}  // extern "C"
195b8e80941Smrg#endif
196b8e80941Smrg
197b8e80941Smrg
198848b8605Smrg#endif
199