13464ebd5Sriastradh/*
23464ebd5Sriastradh * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
33464ebd5Sriastradh *
43464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
53464ebd5Sriastradh * copy of this software and associated documentation files (the "Software"),
63464ebd5Sriastradh * to deal in the Software without restriction, including without limitation
73464ebd5Sriastradh * on the rights to use, copy, modify, merge, publish, distribute, sub
83464ebd5Sriastradh * license, and/or sell copies of the Software, and to permit persons to whom
93464ebd5Sriastradh * the Software is furnished to do so, subject to the following conditions:
103464ebd5Sriastradh *
113464ebd5Sriastradh * The above copyright notice and this permission notice (including the next
123464ebd5Sriastradh * paragraph) shall be included in all copies or substantial portions of the
133464ebd5Sriastradh * Software.
143464ebd5Sriastradh *
153464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
163464ebd5Sriastradh * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
173464ebd5Sriastradh * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
183464ebd5Sriastradh * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
193464ebd5Sriastradh * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
203464ebd5Sriastradh * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
213464ebd5Sriastradh * USE OR OTHER DEALINGS IN THE SOFTWARE.
223464ebd5Sriastradh */
233464ebd5Sriastradh#ifndef R600_SHADER_H
243464ebd5Sriastradh#define R600_SHADER_H
253464ebd5Sriastradh
263464ebd5Sriastradh#include "r600_asm.h"
273464ebd5Sriastradh
2801e04c3fSmrg
2901e04c3fSmrg#ifdef __cplusplus
3001e04c3fSmrgextern "C" {
3101e04c3fSmrg#endif
3201e04c3fSmrg
3301e04c3fSmrg/* Valid shader configurations:
3401e04c3fSmrg *
3501e04c3fSmrg * API shaders       VS | TCS | TES | GS |pass| PS
3601e04c3fSmrg * are compiled as:     |     |     |    |thru|
3701e04c3fSmrg *                      |     |     |    |    |
3801e04c3fSmrg * Only VS & PS:     VS | --  | --  | -- | -- | PS
3901e04c3fSmrg * With GS:          ES | --  | --  | GS | VS | PS
4001e04c3fSmrg * With Tessel.:     LS | HS  | VS  | -- | -- | PS
4101e04c3fSmrg * With both:        LS | HS  | ES  | GS | VS | PS
4201e04c3fSmrg */
4301e04c3fSmrg
443464ebd5Sriastradhstruct r600_shader_io {
453464ebd5Sriastradh	unsigned		name;
463464ebd5Sriastradh	unsigned		gpr;
473464ebd5Sriastradh	unsigned		done;
487ec681f3Smrg	unsigned		sid;
49af69d88dSmrg	int			spi_sid;
503464ebd5Sriastradh	unsigned		interpolate;
51af69d88dSmrg	unsigned		ij_index;
5201e04c3fSmrg	unsigned		interpolate_location; //  TGSI_INTERPOLATE_LOC_CENTER, CENTROID, SAMPLE
533464ebd5Sriastradh	unsigned		lds_pos; /* for evergreen */
54af69d88dSmrg	unsigned		back_color_input;
55af69d88dSmrg	unsigned		write_mask;
5601e04c3fSmrg	int			ring_offset;
577ec681f3Smrg	unsigned		uses_interpolate_at_centroid;
5801e04c3fSmrg};
5901e04c3fSmrg
6001e04c3fSmrgstruct r600_shader_atomic {
6101e04c3fSmrg	unsigned start, end;
6201e04c3fSmrg	unsigned buffer_id;
6301e04c3fSmrg	unsigned hw_idx;
6401e04c3fSmrg	unsigned array_id;
653464ebd5Sriastradh};
663464ebd5Sriastradh
673464ebd5Sriastradhstruct r600_shader {
683464ebd5Sriastradh	unsigned		processor_type;
69af69d88dSmrg	struct r600_bytecode		bc;
703464ebd5Sriastradh	unsigned		ninput;
713464ebd5Sriastradh	unsigned		noutput;
7201e04c3fSmrg	unsigned                nhwatomic;
733464ebd5Sriastradh	unsigned		nlds;
7401e04c3fSmrg	unsigned		nsys_inputs;
757ec681f3Smrg	struct r600_shader_io	input[PIPE_MAX_SHADER_INPUTS];
767ec681f3Smrg	struct r600_shader_io	output[PIPE_MAX_SHADER_OUTPUTS];
7701e04c3fSmrg	struct r600_shader_atomic atomics[8];
7801e04c3fSmrg	unsigned                nhwatomic_ranges;
793464ebd5Sriastradh	boolean			uses_kill;
803464ebd5Sriastradh	boolean			fs_write_all;
81af69d88dSmrg	boolean			two_side;
8201e04c3fSmrg	boolean			needs_scratch_space;
83af69d88dSmrg	/* Number of color outputs in the TGSI shader,
84af69d88dSmrg	 * sometimes it could be higher than nr_cbufs (bug?).
85af69d88dSmrg	 * Also with writes_all property on eg+ it will be set to max CB number */
86af69d88dSmrg	unsigned		nr_ps_max_color_exports;
87af69d88dSmrg	/* Real number of ps color exports compiled in the bytecode */
88af69d88dSmrg	unsigned		nr_ps_color_exports;
8901e04c3fSmrg	unsigned                ps_color_export_mask;
9001e04c3fSmrg	unsigned                ps_export_highest;
91af69d88dSmrg	/* bit n is set if the shader writes gl_ClipDistance[n] */
9201e04c3fSmrg	unsigned		cc_dist_mask;
93af69d88dSmrg	unsigned		clip_dist_write;
9401e04c3fSmrg	unsigned                cull_dist_write;
95af69d88dSmrg	boolean			vs_position_window_space;
96af69d88dSmrg	/* flag is set if the shader writes VS_OUT_MISC_VEC (e.g. for PSIZE) */
97af69d88dSmrg	boolean			vs_out_misc_write;
98af69d88dSmrg	boolean			vs_out_point_size;
99af69d88dSmrg	boolean			vs_out_layer;
100af69d88dSmrg	boolean			vs_out_viewport;
101af69d88dSmrg	boolean			vs_out_edgeflag;
102af69d88dSmrg	boolean			has_txq_cube_array_z_comp;
103af69d88dSmrg	boolean			uses_tex_buffers;
104af69d88dSmrg	boolean                 gs_prim_id_input;
10501e04c3fSmrg	boolean                 gs_tri_strip_adj_fix;
10601e04c3fSmrg	uint8_t			ps_conservative_z;
107af69d88dSmrg
10801e04c3fSmrg	/* Size in bytes of a data item in the ring(s) (single vertex data).
10901e04c3fSmrg	   Stages with only one ring items 123 will be set to 0. */
11001e04c3fSmrg	unsigned		ring_item_sizes[4];
111af69d88dSmrg
112af69d88dSmrg	unsigned		indirect_files;
113af69d88dSmrg	unsigned		max_arrays;
114af69d88dSmrg	unsigned		num_arrays;
115af69d88dSmrg	unsigned		vs_as_es;
11601e04c3fSmrg	unsigned		vs_as_ls;
11701e04c3fSmrg	unsigned		vs_as_gs_a;
11801e04c3fSmrg	unsigned                tes_as_es;
11901e04c3fSmrg	unsigned                tcs_prim_mode;
12001e04c3fSmrg	unsigned                ps_prim_id_input;
121af69d88dSmrg	struct r600_shader_array * arrays;
12201e04c3fSmrg
12301e04c3fSmrg	boolean			uses_doubles;
12401e04c3fSmrg	boolean                 uses_atomics;
12501e04c3fSmrg	boolean			uses_images;
12601e04c3fSmrg	boolean			uses_helper_invocation;
12701e04c3fSmrg	uint8_t                 atomic_base;
12801e04c3fSmrg	uint8_t			rat_base;
12901e04c3fSmrg	uint8_t                 image_size_const_offset;
130af69d88dSmrg};
131af69d88dSmrg
13201e04c3fSmrgunion r600_shader_key {
13301e04c3fSmrg	struct {
13401e04c3fSmrg		unsigned	nr_cbufs:4;
13501e04c3fSmrg		unsigned        first_atomic_counter:4;
13601e04c3fSmrg		unsigned        image_size_const_offset:5;
13701e04c3fSmrg		unsigned	color_two_side:1;
13801e04c3fSmrg		unsigned	alpha_to_one:1;
1397ec681f3Smrg		unsigned        apply_sample_id_mask:1;
1407ec681f3Smrg		unsigned        dual_source_blend:1;
14101e04c3fSmrg	} ps;
14201e04c3fSmrg	struct {
14301e04c3fSmrg		unsigned	prim_id_out:8;
14401e04c3fSmrg		unsigned        first_atomic_counter:4;
14501e04c3fSmrg		unsigned	as_es:1; /* export shader */
14601e04c3fSmrg		unsigned	as_ls:1; /* local shader */
14701e04c3fSmrg		unsigned	as_gs_a:1;
14801e04c3fSmrg	} vs;
14901e04c3fSmrg	struct {
15001e04c3fSmrg		unsigned        first_atomic_counter:4;
15101e04c3fSmrg		unsigned	as_es:1;
15201e04c3fSmrg	} tes;
15301e04c3fSmrg	struct {
15401e04c3fSmrg		unsigned        first_atomic_counter:4;
15501e04c3fSmrg		unsigned	prim_mode:3;
15601e04c3fSmrg	} tcs;
15701e04c3fSmrg	struct {
15801e04c3fSmrg		unsigned        first_atomic_counter:4;
15901e04c3fSmrg		unsigned        tri_strip_adj_fix:1;
16001e04c3fSmrg	} gs;
161af69d88dSmrg};
162af69d88dSmrg
163af69d88dSmrgstruct r600_shader_array {
164af69d88dSmrg	unsigned gpr_start;
165af69d88dSmrg	unsigned gpr_count;
166af69d88dSmrg	unsigned comp_mask;
167af69d88dSmrg};
168af69d88dSmrg
169af69d88dSmrgstruct r600_pipe_shader {
170af69d88dSmrg	struct r600_pipe_shader_selector *selector;
171af69d88dSmrg	struct r600_pipe_shader	*next_variant;
172af69d88dSmrg	/* for GS - corresponding copy shader (installed as VS) */
173af69d88dSmrg	struct r600_pipe_shader *gs_copy_shader;
174af69d88dSmrg	struct r600_shader	shader;
175af69d88dSmrg	struct r600_command_buffer command_buffer; /* register writes */
176af69d88dSmrg	struct r600_resource	*bo;
177af69d88dSmrg	unsigned		sprite_coord_enable;
178af69d88dSmrg	unsigned		flatshade;
179af69d88dSmrg	unsigned		pa_cl_vs_out_cntl;
180af69d88dSmrg	unsigned		nr_ps_color_outputs;
18101e04c3fSmrg	unsigned                ps_color_export_mask;
18201e04c3fSmrg
18301e04c3fSmrg	union r600_shader_key	key;
184af69d88dSmrg	unsigned		db_shader_control;
185af69d88dSmrg	unsigned		ps_depth_export;
18601e04c3fSmrg	unsigned		enabled_stream_buffers_mask;
18701e04c3fSmrg	unsigned		scratch_space_needed; /* size of scratch space (if > 0) counted in vec4 */
1883464ebd5Sriastradh};
1893464ebd5Sriastradh
19001e04c3fSmrg/* return the table index 0-5 for TGSI_INTERPOLATE_LINEAR/PERSPECTIVE and
19101e04c3fSmrg TGSI_INTERPOLATE_LOC_CENTER/SAMPLE/COUNT. Other input values return -1. */
19201e04c3fSmrgint eg_get_interpolator_index(unsigned interpolate, unsigned location);
19301e04c3fSmrg
19401e04c3fSmrgint r600_get_lds_unique_index(unsigned semantic_name, unsigned index);
19501e04c3fSmrg
1967ec681f3Smrgint generate_gs_copy_shader(struct r600_context *rctx,
1977ec681f3Smrg                            struct r600_pipe_shader *gs,
1987ec681f3Smrg                            struct pipe_stream_output_info *so);
1997ec681f3Smrg
20001e04c3fSmrg#ifdef __cplusplus
20101e04c3fSmrg}  // extern "C"
20201e04c3fSmrg#endif
20301e04c3fSmrg
20401e04c3fSmrg
2053464ebd5Sriastradh#endif
206