aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/r600_shader.h
blob: 45ab88b58f562f62418adb3736e1c8e41c1443eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef R600_SHADER_H
#define R600_SHADER_H

#include "r600_compiler.h"
#include "radeon.h"

struct r600_state;

struct r600_shader_vfetch {
	struct r600_shader_vfetch	*next;
	struct r600_shader_vfetch	*prev;
	unsigned			cf_addr;
	unsigned			sel[4];
	unsigned			chan[4];
	unsigned			dsel[4];
};

struct r600_shader_operand {
	struct c_vector			*vector;
	unsigned			sel;
	unsigned			chan;
	unsigned			neg;
	unsigned			abs;
};

struct r600_shader_inst {
	unsigned			is_op3;
	unsigned			opcode;
	unsigned			inst;
	struct r600_shader_operand	src[3];
	struct r600_shader_operand	dst;
	unsigned			last;
};

struct r600_shader_alu {
	struct r600_shader_alu		*next;
	struct r600_shader_alu		*prev;
	unsigned			nalu;
	unsigned			nliteral;
	struct r600_shader_inst		alu[5];
	u32				literal[4];
};

struct r600_shader_node {
	struct r600_shader_node		*next;
	struct r600_shader_node		*prev;
	unsigned			cf_id;		/**< cf index (in dw) in byte code */
	unsigned			cf_addr;	/**< instructions index (in dw) in byte code */
	unsigned			nslot;		/**< number of slot (2 dw) needed by this node */
	unsigned			nfetch;
	struct c_node			*node;		/**< compiler node from which this node originate */
	struct r600_shader_vfetch	vfetch;		/**< list of vfetch instructions */
	struct r600_shader_alu		alu;		/**< list of alu instructions */
};

struct r600_shader_io {
	unsigned	name;
	unsigned	gpr;
	int		sid;
};

struct r600_shader {
	unsigned			stack_size;		/**< stack size needed by this shader */
	unsigned			ngpr;			/**< number of GPR needed by this shader */
	unsigned			nconstant;		/**< number of constants used by this shader */
	unsigned			nresource;		/**< number of resources used by this shader */
	unsigned			noutput;
	unsigned			ninput;
	unsigned			nvector;
	unsigned			ncf;			/**< total number of cf clauses */
	unsigned			nslot;			/**< total number of slots (2 dw) */
	unsigned			flat_shade;		/**< are we flat shading */
	struct r600_shader_node		nodes;			/**< list of node */
	struct r600_shader_node		*cur_node;		/**< current node (used during nodes list creation) */
	struct r600_shader_io		input[32];
	struct r600_shader_io		output[32];
	/* TODO replace GPR by some better register allocator */
	struct c_vector			**gpr;
	unsigned			ndw;			/**< bytes code size in dw */
	u32				*bcode;			/**< bytes code */
	enum pipe_format		resource_format[160];	/**< format of resource */
	struct c_shader			cshader;
};

void r600_shader_cleanup(struct r600_shader *rshader);
int r600_shader_register(struct r600_shader *rshader);
int r600_shader_node(struct r600_shader *shader);
void r600_shader_node_place(struct r600_shader *rshader);
int r600_shader_find_gpr(struct r600_shader *rshader, struct c_vector *v,
			unsigned swizzle, unsigned *sel, unsigned *chan);
int r600_shader_vfetch_bytecode(struct r600_shader *rshader,
				struct r600_shader_node *rnode,
				struct r600_shader_vfetch *vfetch,
				unsigned *cid);
int r600_shader_update(struct r600_shader *rshader,
			enum pipe_format *resource_format);
int r600_shader_legalize(struct r600_shader *rshader);

int r700_shader_translate(struct r600_shader *rshader);

int c_shader_from_tgsi(struct c_shader *shader, unsigned type,
			const struct tgsi_token *tokens);
int r600_shader_register(struct r600_shader *rshader);
int r600_shader_translate_rec(struct r600_shader *rshader, struct c_node *node);
int r700_shader_translate(struct r600_shader *rshader);
int r600_shader_insert_fetch(struct c_shader *shader);

#endif