radeonsi: interpolate varyings at sample when full sample shading is enabled
[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
34 #define SI_SGPR_CONST 0
35 #define SI_SGPR_SAMPLER 2
36 #define SI_SGPR_RESOURCE 4
37 #define SI_SGPR_RW_BUFFERS 6 /* rings (& stream-out, VS only) */
38 #define SI_SGPR_VERTEX_BUFFER 8 /* VS only */
39 #define SI_SGPR_START_INSTANCE 10 /* VS only */
40 #define SI_SGPR_ALPHA_REF 8 /* PS only */
41
42 #define SI_VS_NUM_USER_SGPR 11
43 #define SI_GS_NUM_USER_SGPR 8
44 #define SI_PS_NUM_USER_SGPR 9
45
46 /* LLVM function parameter indices */
47 #define SI_PARAM_CONST 0
48 #define SI_PARAM_SAMPLER 1
49 #define SI_PARAM_RESOURCE 2
50 #define SI_PARAM_RW_BUFFERS 3
51
52 /* VS only parameters */
53 #define SI_PARAM_VERTEX_BUFFER 4
54 #define SI_PARAM_START_INSTANCE 5
55 /* the other VS parameters are assigned dynamically */
56
57 /* ES only parameters */
58 #define SI_PARAM_ES2GS_OFFSET 6
59
60 /* GS only parameters */
61 #define SI_PARAM_GS2VS_OFFSET 4
62 #define SI_PARAM_GS_WAVE_ID 5
63 #define SI_PARAM_VTX0_OFFSET 6
64 #define SI_PARAM_VTX1_OFFSET 7
65 #define SI_PARAM_PRIMITIVE_ID 8
66 #define SI_PARAM_VTX2_OFFSET 9
67 #define SI_PARAM_VTX3_OFFSET 10
68 #define SI_PARAM_VTX4_OFFSET 11
69 #define SI_PARAM_VTX5_OFFSET 12
70 #define SI_PARAM_GS_INSTANCE_ID 13
71
72 /* PS only parameters */
73 #define SI_PARAM_ALPHA_REF 4
74 #define SI_PARAM_PRIM_MASK 5
75 #define SI_PARAM_PERSP_SAMPLE 6
76 #define SI_PARAM_PERSP_CENTER 7
77 #define SI_PARAM_PERSP_CENTROID 8
78 #define SI_PARAM_PERSP_PULL_MODEL 9
79 #define SI_PARAM_LINEAR_SAMPLE 10
80 #define SI_PARAM_LINEAR_CENTER 11
81 #define SI_PARAM_LINEAR_CENTROID 12
82 #define SI_PARAM_LINE_STIPPLE_TEX 13
83 #define SI_PARAM_POS_X_FLOAT 14
84 #define SI_PARAM_POS_Y_FLOAT 15
85 #define SI_PARAM_POS_Z_FLOAT 16
86 #define SI_PARAM_POS_W_FLOAT 17
87 #define SI_PARAM_FRONT_FACE 18
88 #define SI_PARAM_ANCILLARY 19
89 #define SI_PARAM_SAMPLE_COVERAGE 20
90 #define SI_PARAM_POS_FIXED_PT 21
91
92 #define SI_NUM_PARAMS (SI_PARAM_POS_FIXED_PT + 1)
93
94 struct si_shader_input {
95 unsigned name;
96 int sid;
97 unsigned param_offset;
98 unsigned index;
99 unsigned interpolate;
100 bool centroid;
101 };
102
103 struct si_shader_output {
104 unsigned name;
105 int sid;
106 unsigned param_offset;
107 unsigned index;
108 unsigned usage;
109 };
110
111 struct si_pipe_shader;
112
113 struct si_pipe_shader_selector {
114 struct si_pipe_shader *current;
115
116 struct tgsi_token *tokens;
117 struct pipe_stream_output_info so;
118
119 unsigned num_shaders;
120
121 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
122 unsigned type;
123
124 /* 1 when the shader contains
125 * TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS, otherwise it's 0.
126 * Used to determine whether we need to include nr_cbufs in the key */
127 unsigned fs_write_all;
128 };
129
130 struct si_shader {
131 unsigned ninput;
132 struct si_shader_input input[40];
133
134 unsigned noutput;
135 struct si_shader_output output[40];
136
137 /* geometry shader properties */
138 unsigned gs_input_prim;
139 unsigned gs_output_prim;
140 unsigned gs_max_out_vertices;
141
142 unsigned nparam;
143 bool uses_kill;
144 bool uses_instanceid;
145 bool fs_write_all;
146 bool vs_out_misc_write;
147 bool vs_out_point_size;
148 bool vs_out_edgeflag;
149 bool vs_out_layer;
150 unsigned nr_pos_exports;
151 unsigned clip_dist_write;
152 };
153
154 union si_shader_key {
155 struct {
156 unsigned export_16bpc:8;
157 unsigned nr_cbufs:4;
158 unsigned color_two_side:1;
159 unsigned alpha_func:3;
160 unsigned flatshade:1;
161 unsigned interp_at_sample:1;
162 unsigned alpha_to_one:1;
163 } ps;
164 struct {
165 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
166 unsigned ucps_enabled:2;
167 unsigned as_es:1;
168 } vs;
169 };
170
171 struct si_pipe_shader {
172 struct si_pipe_shader_selector *selector;
173 struct si_pipe_shader *next_variant;
174 struct si_pipe_shader *gs_copy_shader;
175 struct si_shader shader;
176 struct si_pm4_state *pm4;
177 struct r600_resource *bo;
178 unsigned num_sgprs;
179 unsigned num_vgprs;
180 unsigned lds_size;
181 unsigned spi_ps_input_ena;
182 unsigned spi_shader_col_format;
183 unsigned spi_shader_z_format;
184 unsigned db_shader_control;
185 unsigned cb_shader_mask;
186 bool cb0_is_integer;
187 unsigned sprite_coord_enable;
188 union si_shader_key key;
189 };
190
191 static inline struct si_shader* si_get_vs_state(struct si_context *sctx)
192 {
193 if (sctx->gs_shader)
194 return &sctx->gs_shader->current->gs_copy_shader->shader;
195 else
196 return &sctx->vs_shader->current->shader;
197 }
198
199 /* radeonsi_shader.c */
200 int si_pipe_shader_create(struct pipe_context *ctx, struct si_pipe_shader *shader);
201 int si_pipe_shader_create(struct pipe_context *ctx, struct si_pipe_shader *shader);
202 int si_compile_llvm(struct si_context *sctx, struct si_pipe_shader *shader,
203 LLVMModuleRef mod);
204 void si_pipe_shader_destroy(struct pipe_context *ctx, struct si_pipe_shader *shader);
205
206 #endif