165d717812218b82cf43e7bbb2829de68d8dc93e
[mesa.git] / src / gallium / drivers / r300 / r300_vs.h
1 /*
2 * Copyright 2009 Corbin Simpson <MostAwesomeDude@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 R300_VS_H
24 #define R300_VS_H
25
26 #include "tgsi/tgsi_parse.h"
27 #include "tgsi/tgsi_dump.h"
28
29 #include "r300_context.h"
30 #include "r300_debug.h"
31 #include "r300_reg.h"
32 #include "r300_screen.h"
33 #include "r300_shader_inlines.h"
34
35 /* XXX get these to r300_reg */
36 #define R300_PVS_DST_OPCODE(x) ((x) << 0)
37 # define R300_VE_DOT_PRODUCT 1
38 # define R300_VE_MULTIPLY 2
39 # define R300_VE_ADD 3
40 # define R300_VE_MAXIMUM 7
41 # define R300_VE_SET_LESS_THAN 10
42 #define R300_PVS_DST_MATH_INST (1 << 6)
43 # define R300_ME_RECIP_DX 6
44 #define R300_PVS_DST_MACRO_INST (1 << 7)
45 # define R300_PVS_MACRO_OP_2CLK_MADD 0
46 #define R300_PVS_DST_REG_TYPE(x) ((x) << 8)
47 # define R300_PVS_DST_REG_TEMPORARY 0
48 # define R300_PVS_DST_REG_A0 1
49 # define R300_PVS_DST_REG_OUT 2
50 # define R300_PVS_DST_REG_OUT_REPL_X 3
51 # define R300_PVS_DST_REG_ALT_TEMPORARY 4
52 # define R300_PVS_DST_REG_INPUT 5
53 #define R300_PVS_DST_OFFSET(x) ((x) << 13)
54 #define R300_PVS_DST_WE(x) ((x) << 20)
55 #define R300_PVS_DST_WE_XYZW (0xf << 20)
56
57 #define R300_PVS_SRC_REG_TYPE(x) ((x) << 0)
58 # define R300_PVS_SRC_REG_TEMPORARY 0
59 # define R300_PVS_SRC_REG_INPUT 1
60 # define R300_PVS_SRC_REG_CONSTANT 2
61 # define R300_PVS_SRC_REG_ALT_TEMPORARY 3
62 #define R300_PVS_SRC_OFFSET(x) ((x) << 5)
63 #define R300_PVS_SRC_SWIZZLE(x) ((x) << 13)
64 # define R300_PVS_SRC_SELECT_X 0
65 # define R300_PVS_SRC_SELECT_Y 1
66 # define R300_PVS_SRC_SELECT_Z 2
67 # define R300_PVS_SRC_SELECT_W 3
68 # define R300_PVS_SRC_SELECT_FORCE_0 4
69 # define R300_PVS_SRC_SELECT_FORCE_1 5
70 # define R300_PVS_SRC_SWIZZLE_XYZW \
71 ((R300_PVS_SRC_SELECT_X | (R300_PVS_SRC_SELECT_Y << 3) | \
72 (R300_PVS_SRC_SELECT_Z << 6) | (R300_PVS_SRC_SELECT_W << 9)) << 13)
73 # define R300_PVS_SRC_SWIZZLE_ZERO \
74 ((R300_PVS_SRC_SELECT_FORCE_0 | (R300_PVS_SRC_SELECT_FORCE_0 << 3) | \
75 (R300_PVS_SRC_SELECT_FORCE_0 << 6) | \
76 (R300_PVS_SRC_SELECT_FORCE_0 << 9)) << 13)
77 # define R300_PVS_SRC_SWIZZLE_ONE \
78 ((R300_PVS_SRC_SELECT_FORCE_1 | (R300_PVS_SRC_SELECT_FORCE_1 << 3) | \
79 (R300_PVS_SRC_SELECT_FORCE_1 << 6) | \
80 (R300_PVS_SRC_SELECT_FORCE_1 << 9)) << 13)
81 #define R300_PVS_MODIFIER_X (1 << 25)
82 #define R300_PVS_MODIFIER_Y (1 << 26)
83 #define R300_PVS_MODIFIER_Z (1 << 27)
84 #define R300_PVS_MODIFIER_W (1 << 28)
85 #define R300_PVS_NEGATE_XYZW \
86 (R300_PVS_MODIFIER_X | R300_PVS_MODIFIER_Y | \
87 R300_PVS_MODIFIER_Z | R300_PVS_MODIFIER_W)
88
89 /* Temporary struct used to hold assembly state while putting together
90 * fragment programs. */
91 struct r300_vs_asm {
92 /* Pipe context. */
93 struct r300_context* r300;
94 /* Number of colors. */
95 unsigned color_count;
96 /* Number of texcoords. */
97 unsigned tex_count;
98 /* Number of requested temporary registers. */
99 unsigned temp_count;
100 /* Offset for immediate constants. Neither R300 nor R500 can do four
101 * inline constants per source, so instead we copy immediates into the
102 * constant buffer. */
103 unsigned imm_offset;
104 /* Number of immediate constants. */
105 unsigned imm_count;
106 /* Number of colors to write. */
107 unsigned out_colors;
108 /* Number of texcoords to write. */
109 unsigned out_texcoords;
110 /* Whether to emit point size. */
111 boolean point_size;
112 /* Tab of declared outputs to OVM outputs. */
113 unsigned tab[16];
114 };
115
116 static struct r300_vertex_shader r300_passthrough_vertex_shader = {
117 /* XXX translate these back into normal instructions */
118 .instruction_count = 2,
119 .instructions[0].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
120 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
121 R300_PVS_DST_OFFSET(0) | R300_PVS_DST_WE_XYZW,
122 .instructions[0].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
123 R300_PVS_SRC_OFFSET(0) | R300_PVS_SRC_SWIZZLE_XYZW,
124 .instructions[0].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
125 .instructions[0].inst3 = 0x0,
126 .instructions[1].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
127 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
128 R300_PVS_DST_OFFSET(1) | R300_PVS_DST_WE_XYZW,
129 .instructions[1].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
130 R300_PVS_SRC_OFFSET(1) | R300_PVS_SRC_SWIZZLE_XYZW,
131 .instructions[1].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
132 .instructions[1].inst3 = 0x0,
133 };
134
135 static struct r300_vertex_shader r300_texture_vertex_shader = {
136 /* XXX translate these back into normal instructions */
137 .instruction_count = 2,
138 .instructions[0].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
139 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
140 R300_PVS_DST_OFFSET(0) | R300_PVS_DST_WE_XYZW,
141 .instructions[0].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
142 R300_PVS_SRC_OFFSET(0) | R300_PVS_SRC_SWIZZLE_XYZW,
143 .instructions[0].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
144 .instructions[0].inst3 = 0x0,
145 .instructions[1].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
146 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
147 R300_PVS_DST_OFFSET(1) | R300_PVS_DST_WE_XYZW,
148 .instructions[1].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
149 R300_PVS_SRC_OFFSET(1) | R300_PVS_SRC_SWIZZLE_XYZW,
150 .instructions[1].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
151 .instructions[1].inst3 = 0x0,
152 };
153
154 void r300_translate_vertex_shader(struct r300_context* r300,
155 struct r300_vertex_shader* vs);
156
157 #endif /* R300_VS_H */