Merge commit 'origin/master' into drm-gem
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_program.h
1 /*
2 * Copyright (C) 2008 Nicolai Haehnle.
3 *
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 */
27
28 #ifndef __RADEON_PROGRAM_H_
29 #define __RADEON_PROGRAM_H_
30
31 #include "glheader.h"
32 #include "macros.h"
33 #include "enums.h"
34 #include "shader/program.h"
35 #include "shader/prog_instruction.h"
36
37
38 enum {
39 CLAUSE_MIXED = 0,
40 CLAUSE_ALU,
41 CLAUSE_TEX
42 };
43
44 enum {
45 PROGRAM_BUILTIN = PROGRAM_FILE_MAX /**< not a real register, but a special swizzle constant */
46 };
47
48 #define SWIZZLE_0000 MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO, SWIZZLE_ZERO)
49 #define SWIZZLE_1111 MAKE_SWIZZLE4(SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE, SWIZZLE_ONE)
50
51 /**
52 * A clause is simply a sequence of instructions that are executed
53 * in order.
54 */
55 struct radeon_clause {
56 /**
57 * Type of this clause, one of CLAUSE_XXX.
58 */
59 int Type : 2;
60
61 /**
62 * Pointer to an array of instructions.
63 * The array is terminated by an OPCODE_END instruction.
64 */
65 struct prog_instruction *Instructions;
66
67 /**
68 * Number of instructions in this clause.
69 */
70 int NumInstructions;
71
72 /**
73 * Space reserved for instructions in this clause.
74 */
75 int ReservedInstructions;
76 };
77
78 /**
79 * A compile object, holding the current intermediate state during compilation.
80 */
81 struct radeon_compiler {
82 struct gl_program *Source;
83 GLcontext* Ctx;
84
85 /**
86 * Number of clauses in this program.
87 */
88 int NumClauses;
89
90 /**
91 * Pointer to an array of NumClauses clauses.
92 */
93 struct radeon_clause *Clauses;
94
95 /**
96 * Number of registers in the PROGRAM_TEMPORARIES file.
97 */
98 int NumTemporaries;
99 };
100
101 void radeonCompilerInit(
102 struct radeon_compiler *compiler,
103 GLcontext *ctx,
104 struct gl_program *source);
105 void radeonCompilerCleanup(struct radeon_compiler *compiler);
106 int radeonCompilerAllocateTemporary(struct radeon_compiler *compiler);
107 void radeonCompilerDump(struct radeon_compiler *compiler);
108
109 struct radeon_clause *radeonCompilerInsertClause(
110 struct radeon_compiler *compiler,
111 int position,
112 int type);
113 void radeonCompilerEraseClauses(
114 struct radeon_compiler *compiler,
115 int start,
116 int end);
117
118 struct prog_instruction* radeonClauseInsertInstructions(
119 struct radeon_compiler *compiler,
120 struct radeon_clause *clause,
121 int position, int count);
122
123 /**
124 *
125 */
126 struct radeon_program_transform_context {
127 struct radeon_compiler *compiler;
128
129 /**
130 * Destination clause where new instructions must be written.
131 */
132 struct radeon_clause *dest;
133
134 /**
135 * Original clause that is currently being transformed.
136 */
137 struct radeon_clause *src;
138 };
139
140 /**
141 * A transformation that can be passed to \ref radeonClauseLinearTransform.
142 *
143 * The function will be called once for each instruction.
144 * It has to either emit the appropriate transformed code for the instruction
145 * and return GL_TRUE, or return GL_FALSE if it doesn't understand the
146 * instruction.
147 *
148 * The function gets passed the userData as last parameter.
149 */
150 struct radeon_program_transformation {
151 GLboolean (*function)(
152 struct radeon_program_transform_context*,
153 struct prog_instruction*,
154 void*);
155 void *userData;
156 };
157
158 void radeonClauseLocalTransform(
159 struct radeon_compiler *compiler,
160 struct radeon_clause *clause,
161 int num_transformations,
162 struct radeon_program_transformation* transformations);
163
164 #endif