766059bd0564a0eb773bf336da636c4c5563f6c0
[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_VERTEX_BUFFER 6 /* VS only */
38 #define SI_SGPR_SO_BUFFER 8 /* VS only, stream-out */
39 #define SI_SGPR_START_INSTANCE 10 /* VS only */
40 #define SI_SGPR_ALPHA_REF 6 /* PS only */
41
42 #define SI_VS_NUM_USER_SGPR 11
43 #define SI_PS_NUM_USER_SGPR 7
44
45 /* LLVM function parameter indices */
46 #define SI_PARAM_CONST 0
47 #define SI_PARAM_SAMPLER 1
48 #define SI_PARAM_RESOURCE 2
49
50 /* VS only parameters */
51 #define SI_PARAM_VERTEX_BUFFER 3
52 #define SI_PARAM_SO_BUFFER 4
53 #define SI_PARAM_START_INSTANCE 5
54 /* the other VS parameters are assigned dynamically */
55
56 /* PS only parameters */
57 #define SI_PARAM_ALPHA_REF 3
58 #define SI_PARAM_PRIM_MASK 4
59 #define SI_PARAM_PERSP_SAMPLE 5
60 #define SI_PARAM_PERSP_CENTER 6
61 #define SI_PARAM_PERSP_CENTROID 7
62 #define SI_PARAM_PERSP_PULL_MODEL 8
63 #define SI_PARAM_LINEAR_SAMPLE 9
64 #define SI_PARAM_LINEAR_CENTER 10
65 #define SI_PARAM_LINEAR_CENTROID 11
66 #define SI_PARAM_LINE_STIPPLE_TEX 12
67 #define SI_PARAM_POS_X_FLOAT 13
68 #define SI_PARAM_POS_Y_FLOAT 14
69 #define SI_PARAM_POS_Z_FLOAT 15
70 #define SI_PARAM_POS_W_FLOAT 16
71 #define SI_PARAM_FRONT_FACE 17
72 #define SI_PARAM_ANCILLARY 18
73 #define SI_PARAM_SAMPLE_COVERAGE 19
74 #define SI_PARAM_POS_FIXED_PT 20
75
76 struct si_shader_io {
77 unsigned name;
78 int sid;
79 unsigned param_offset;
80 unsigned interpolate;
81 bool centroid;
82 };
83
84 struct si_pipe_shader;
85
86 struct si_pipe_shader_selector {
87 struct si_pipe_shader *current;
88
89 struct tgsi_token *tokens;
90 struct pipe_stream_output_info so;
91
92 unsigned num_shaders;
93
94 /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */
95 unsigned type;
96
97 /* 1 when the shader contains
98 * TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS, otherwise it's 0.
99 * Used to determine whether we need to include nr_cbufs in the key */
100 unsigned fs_write_all;
101 };
102
103 struct si_shader {
104 unsigned ninput;
105 struct si_shader_io input[40];
106
107 unsigned noutput;
108 struct si_shader_io output[40];
109
110 unsigned ninterp;
111 bool uses_kill;
112 bool uses_instanceid;
113 bool fs_write_all;
114 bool vs_out_misc_write;
115 bool vs_out_point_size;
116 bool vs_out_edgeflag;
117 bool vs_out_layer;
118 unsigned nr_pos_exports;
119 unsigned clip_dist_write;
120 };
121
122 union si_shader_key {
123 struct {
124 unsigned export_16bpc:8;
125 unsigned nr_cbufs:4;
126 unsigned color_two_side:1;
127 unsigned alpha_func:3;
128 unsigned flatshade:1;
129 unsigned alpha_to_one:1;
130 } ps;
131 struct {
132 unsigned instance_divisors[PIPE_MAX_ATTRIBS];
133 unsigned ucps_enabled:2;
134 } vs;
135 };
136
137 struct si_pipe_shader {
138 struct si_pipe_shader_selector *selector;
139 struct si_pipe_shader *next_variant;
140 struct si_shader shader;
141 struct si_pm4_state *pm4;
142 struct r600_resource *bo;
143 unsigned num_sgprs;
144 unsigned num_vgprs;
145 unsigned lds_size;
146 unsigned spi_ps_input_ena;
147 unsigned spi_shader_col_format;
148 unsigned cb_shader_mask;
149 bool cb0_is_integer;
150 unsigned sprite_coord_enable;
151 union si_shader_key key;
152 };
153
154 /* radeonsi_shader.c */
155 int si_pipe_shader_create(struct pipe_context *ctx, struct si_pipe_shader *shader);
156 int si_pipe_shader_create(struct pipe_context *ctx, struct si_pipe_shader *shader);
157 int si_compile_llvm(struct si_context *sctx, struct si_pipe_shader *shader,
158 LLVMModuleRef mod);
159 void si_pipe_shader_destroy(struct pipe_context *ctx, struct si_pipe_shader *shader);
160
161 #endif