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