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