r300: Remove GLcontext requirement from radeon_program_pair
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_program_pair.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_PAIR_H_
29 #define __RADEON_PROGRAM_PAIR_H_
30
31 #include "radeon_program.h"
32
33
34 /**
35 * Represents a paired instruction, as found in R300 and R500
36 * fragment programs.
37 */
38 struct radeon_pair_instruction_source {
39 GLuint Index:8;
40 GLuint Constant:1;
41 GLuint Used:1;
42 };
43
44 struct radeon_pair_instruction_rgb {
45 GLuint Opcode:8;
46 GLuint DestIndex:8;
47 GLuint WriteMask:3;
48 GLuint OutputWriteMask:3;
49 GLuint Saturate:1;
50
51 struct radeon_pair_instruction_source Src[3];
52
53 struct {
54 GLuint Source:2;
55 GLuint Swizzle:9;
56 GLuint Abs:1;
57 GLuint Negate:1;
58 } Arg[3];
59 };
60
61 struct radeon_pair_instruction_alpha {
62 GLuint Opcode:8;
63 GLuint DestIndex:8;
64 GLuint WriteMask:1;
65 GLuint OutputWriteMask:1;
66 GLuint DepthWriteMask:1;
67 GLuint Saturate:1;
68
69 struct radeon_pair_instruction_source Src[3];
70
71 struct {
72 GLuint Source:2;
73 GLuint Swizzle:3;
74 GLuint Abs:1;
75 GLuint Negate:1;
76 } Arg[3];
77 };
78
79 struct radeon_pair_instruction {
80 struct radeon_pair_instruction_rgb RGB;
81 struct radeon_pair_instruction_alpha Alpha;
82 };
83
84
85 enum {
86 RADEON_OPCODE_TEX = 0,
87 RADEON_OPCODE_TXB,
88 RADEON_OPCODE_TXP,
89 RADEON_OPCODE_KIL
90 };
91
92 struct radeon_pair_texture_instruction {
93 GLuint Opcode:2; /**< one of RADEON_OPCODE_xxx */
94
95 GLuint DestIndex:8;
96 GLuint WriteMask:4;
97
98 GLuint TexSrcUnit:5;
99 GLuint TexSrcTarget:3;
100
101 GLuint SrcIndex:8;
102 GLuint SrcSwizzle:12;
103 };
104
105
106 /**
107 *
108 */
109 struct radeon_pair_handler {
110 /**
111 * Fill in the proper hardware index for the given constant register.
112 *
113 * @return GL_FALSE on error.
114 */
115 GLboolean (*EmitConst)(void*, GLuint file, GLuint index, GLuint *hwindex);
116
117 /**
118 * Write a paired instruction to the hardware.
119 *
120 * @return GL_FALSE on error.
121 */
122 GLboolean (*EmitPaired)(void*, struct radeon_pair_instruction*);
123
124 /**
125 * Write a texture instruction to the hardware.
126 * Register indices have already been rewritten to the allocated
127 * hardware register numbers.
128 *
129 * @return GL_FALSE on error.
130 */
131 GLboolean (*EmitTex)(void*, struct radeon_pair_texture_instruction*);
132
133 /**
134 * Called before a block of contiguous, independent texture
135 * instructions is emitted.
136 */
137 GLboolean (*BeginTexBlock)(void*);
138
139 GLuint MaxHwTemps;
140 };
141
142 GLboolean radeonPairProgram(struct gl_program *program,
143 const struct radeon_pair_handler*, void *userdata);
144
145 void radeonPrintPairInstruction(struct radeon_pair_instruction *inst);
146
147 #endif /* __RADEON_PROGRAM_PAIR_H_ */