radeonsi: move param_offset out of shader->input[] and output[]
[mesa.git] / src / gallium / drivers / radeonsi / si_shader.h
1 /*
2 * Copyright 2012 Advanced Micro Devices, Inc.
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 * Authors:
24 * Tom Stellard <thomas.stellard@amd.com>
25 * Michel Dänzer <michel.daenzer@amd.com>
26 * Christian König <christian.koenig@amd.com>
27 */
28
29 #ifndef SI_SHADER_H
30 #define SI_SHADER_H
31
32 #include <llvm-c/Core.h> /* LLVMModuleRef */
33 #include "tgsi/tgsi_scan.h"
34 #include "si_state.h"
35
36 #define SI_SGPR_RW_BUFFERS 0 /* rings (& stream-out, VS only) */
37 #define SI_SGPR_CONST 2
38 #define SI_SGPR_SAMPLER 4
39 #define SI_SGPR_RESOURCE 6
40 #define SI_SGPR_VERTEX_BUFFER 8 /* VS only */
41 #define SI_SGPR_BASE_VERTEX 10 /* VS only */
42 #define SI_SGPR_START_INSTANCE 11 /* VS only */
43 #define SI_SGPR_ALPHA_REF 8 /* PS only */
44
45 #define SI_VS_NUM_USER_SGPR 12
46 #define SI_GS_NUM_USER_SGPR 8
47 #define SI_GSCOPY_NUM_USER_SGPR 4
48 #define SI_PS_NUM_USER_SGPR 9
49
50 /* LLVM function parameter indices */
51 #define SI_PARAM_RW_BUFFERS 0
52 #define SI_PARAM_CONST 1
53 #define SI_PARAM_SAMPLER 2
54 #define SI_PARAM_RESOURCE 3
55
56 /* VS only parameters */
57 #define SI_PARAM_VERTEX_BUFFER 4
58 #define SI_PARAM_BASE_VERTEX 5
59 #define SI_PARAM_START_INSTANCE 6
60 /* the other VS parameters are assigned dynamically */
61
62 /* ES only parameters */
63 #define SI_PARAM_ES2GS_OFFSET 7
64
65 /* GS only parameters */
66 #define SI_PARAM_GS2VS_OFFSET 4
67 #define SI_PARAM_GS_WAVE_ID 5
68 #define SI_PARAM_VTX0_OFFSET 6
69 #define SI_PARAM_VTX1_OFFSET 7
70 #define SI_PARAM_PRIMITIVE_ID 8
71 #define SI_PARAM_VTX2_OFFSET 9
72 #define SI_PARAM_VTX3_OFFSET 10
73 #define SI_PARAM_VTX4_OFFSET 11
74 #define SI_PARAM_VTX5_OFFSET 12
75 #define SI_PARAM_GS_INSTANCE_ID 13
76
77 /* PS only parameters */
78 #define SI_PARAM_ALPHA_REF 4
79 #define SI_PARAM_PRIM_MASK 5
80 #define SI_PARAM_PERSP_SAMPLE 6
81 #define SI_PARAM_PERSP_CENTER 7
82 #define SI_PARAM_PERSP_CENTROID 8
83 #define SI_PARAM_PERSP_PULL_MODEL 9
84 #define SI_PARAM_LINEAR_SAMPLE 10
85 #define SI_PARAM_LINEAR_CENTER 11
86 #define SI_PARAM_LINEAR_CENTROID 12
87 #define SI_PARAM_LINE_STIPPLE_TEX 13
88 #define SI_PARAM_POS_X_FLOAT 14
89 #define SI_PARAM_POS_Y_FLOAT 15
90 #define SI_PARAM_POS_Z_FLOAT 16
91 #define SI_PARAM_POS_W_FLOAT 17
92 #define SI_PARAM_FRONT_FACE 18
93 #define SI_PARAM_ANCILLARY 19
94 #define SI_PARAM_SAMPLE_COVERAGE 20
95 #define SI_PARAM_POS_FIXED_PT 21
96
97 #define SI_NUM_PARAMS (SI_PARAM_POS_FIXED_PT + 1)
98
99 struct si_shader_input {
100 unsigned name;
101 int sid;
102 unsigned param_offset;
103 unsigned index;
104 unsigned interpolate;
105 };
106
107 struct si_shader_output {
108 unsigned name;
109 int sid;
110 unsigned param_offset;
111 unsigned index;
112 };
113
114 struct si_shader;
115
116 struct si_shader_selector {
117 struct si_shader *current;
118
119 struct tgsi_token *tokens;
120 struct pipe_stream_output_info so;
121 struct tgsi_shader_info info;
122
123 unsigned num_shaders;
124
125 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
126 unsigned type;
127
128 unsigned gs_output_prim;
129 unsigned gs_max_out_vertices;
130 uint64_t gs_used_inputs; /* mask of "get_unique_index" bits */
131 };
132
133 union si_shader_key {
134 struct {
135 unsigned export_16bpc:8;
136 unsigned last_cbuf:3;
137 unsigned color_two_side:1;
138 unsigned alpha_func:3;
139 unsigned flatshade:1;
140 unsigned alpha_to_one:1;
141 } ps;
142 struct {
143 unsigned instance_divisors[SI_NUM_VERTEX_BUFFERS];
144 /* The mask of "get_unique_index" bits, needed for ES,
145 * it describes how the ES->GS ring buffer is laid out. */
146 uint64_t gs_used_inputs;
147 unsigned as_es:1;
148 } vs;
149 };
150
151 struct si_shader {
152 struct si_shader_selector *selector;
153 struct si_shader *next_variant;
154
155 struct si_shader *gs_copy_shader;
156 struct si_pm4_state *pm4;
157 struct r600_resource *bo;
158 struct r600_resource *scratch_bo;
159 unsigned num_sgprs;
160 unsigned num_vgprs;
161 unsigned lds_size;
162 unsigned spi_ps_input_ena;
163 unsigned scratch_bytes_per_wave;
164 unsigned spi_shader_col_format;
165 unsigned spi_shader_z_format;
166 unsigned db_shader_control;
167 unsigned cb_shader_mask;
168 union si_shader_key key;
169
170 unsigned ninput;
171 struct si_shader_input input[40];
172
173 unsigned noutput;
174 struct si_shader_output output[40];
175
176 unsigned nparam;
177 unsigned vs_output_param_offset[PIPE_MAX_SHADER_OUTPUTS];
178 unsigned ps_input_param_offset[PIPE_MAX_SHADER_INPUTS];
179
180 bool uses_instanceid;
181 bool vs_out_misc_write;
182 bool vs_out_point_size;
183 bool vs_out_edgeflag;
184 bool vs_out_layer;
185 unsigned nr_pos_exports;
186 unsigned clip_dist_write;
187 bool is_gs_copy_shader;
188 };
189
190 static inline struct si_shader* si_get_vs_state(struct si_context *sctx)
191 {
192 if (sctx->gs_shader)
193 return sctx->gs_shader->current->gs_copy_shader;
194 else
195 return sctx->vs_shader->current;
196 }
197
198 /* radeonsi_shader.c */
199 int si_shader_create(struct si_screen *sscreen, struct si_shader *shader);
200 int si_compile_llvm(struct si_screen *sscreen, struct si_shader *shader,
201 LLVMModuleRef mod);
202 void si_shader_destroy(struct pipe_context *ctx, struct si_shader *shader);
203 unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index);
204
205 #endif