r300: Detangle fragment program compiler from driver-specific structure
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_compiler.h
1 /*
2 * Copyright 2009 Nicolai Hähnle <nhaehnle@gmail.com>
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 #ifndef RADEON_COMPILER_H
24 #define RADEON_COMPILER_H
25
26 #include "main/mtypes.h"
27 #include "shader/prog_instruction.h"
28
29 #define R300_PFS_MAX_ALU_INST 64
30 #define R300_PFS_MAX_TEX_INST 32
31 #define R300_PFS_MAX_TEX_INDIRECT 4
32 #define R300_PFS_NUM_TEMP_REGS 32
33 #define R300_PFS_NUM_CONST_REGS 32
34
35 #define R500_PFS_MAX_INST 512
36 #define R500_PFS_NUM_TEMP_REGS 128
37 #define R500_PFS_NUM_CONST_REGS 256
38
39
40 #define STATE_R300_WINDOW_DIMENSION (STATE_INTERNAL_DRIVER+0)
41 #define STATE_R300_TEXRECT_FACTOR (STATE_INTERNAL_DRIVER+1)
42
43
44 /**
45 * Stores state that influences the compilation of a fragment program.
46 */
47 struct r300_fragment_program_external_state {
48 struct {
49 /**
50 * If the sampler is used as a shadow sampler,
51 * this field is:
52 * 0 - GL_LUMINANCE
53 * 1 - GL_INTENSITY
54 * 2 - GL_ALPHA
55 * depending on the depth texture mode.
56 */
57 GLuint depth_texture_mode : 2;
58
59 /**
60 * If the sampler is used as a shadow sampler,
61 * this field is (texture_compare_func - GL_NEVER).
62 * [e.g. if compare function is GL_LEQUAL, this field is 3]
63 *
64 * Otherwise, this field is 0.
65 */
66 GLuint texture_compare_func : 3;
67 } unit[16];
68 };
69
70
71
72 struct r300_fragment_program_node {
73 int tex_offset; /**< first tex instruction */
74 int tex_end; /**< last tex instruction, relative to tex_offset */
75 int alu_offset; /**< first ALU instruction */
76 int alu_end; /**< last ALU instruction, relative to alu_offset */
77 int flags;
78 };
79
80 /**
81 * Stores an R300 fragment program in its compiled-to-hardware form.
82 */
83 struct r300_fragment_program_code {
84 struct {
85 int length; /**< total # of texture instructions used */
86 GLuint inst[R300_PFS_MAX_TEX_INST];
87 } tex;
88
89 struct {
90 int length; /**< total # of ALU instructions used */
91 struct {
92 GLuint inst0;
93 GLuint inst1;
94 GLuint inst2;
95 GLuint inst3;
96 } inst[R300_PFS_MAX_ALU_INST];
97 } alu;
98
99 struct r300_fragment_program_node node[4];
100 int cur_node;
101 int first_node_has_tex;
102
103 /**
104 * Remember which program register a given hardware constant
105 * belongs to.
106 */
107 struct prog_src_register constant[R300_PFS_NUM_CONST_REGS];
108 int const_nr;
109
110 int max_temp_idx;
111 };
112
113
114 struct r500_fragment_program_code {
115 struct {
116 GLuint inst0;
117 GLuint inst1;
118 GLuint inst2;
119 GLuint inst3;
120 GLuint inst4;
121 GLuint inst5;
122 } inst[R500_PFS_MAX_INST];
123
124 int inst_offset;
125 int inst_end;
126
127 /**
128 * Remember which program register a given hardware constant
129 * belongs to.
130 */
131 struct prog_src_register constant[R500_PFS_NUM_CONST_REGS];
132 int const_nr;
133
134 int max_temp_idx;
135 };
136
137 struct rX00_fragment_program_code {
138 union {
139 struct r300_fragment_program_code r300;
140 struct r500_fragment_program_code r500;
141 } code;
142
143 GLboolean writes_depth;
144
145 /* attribute that we are sending the WPOS in */
146 gl_frag_attrib wpos_attr;
147 /* attribute that we are sending the fog coordinate in */
148 gl_frag_attrib fog_attr;
149 };
150
151 struct r300_fragment_program_compiler {
152 GLcontext * ctx;
153 struct rX00_fragment_program_code *code;
154 struct gl_program *program;
155 struct r300_fragment_program_external_state state;
156 GLboolean is_r500;
157 GLboolean debug;
158 };
159
160 GLboolean r3xx_compile_fragment_program(struct r300_fragment_program_compiler* c);
161
162 #endif /* RADEON_COMPILER_H */