Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / gallium / drivers / r300 / r300_state_tcl.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_STATE_TCL_H
24 #define R300_STATE_TCL_H
25
26 #include "tgsi/tgsi_parse.h"
27
28 #include "r300_context.h"
29 #include "r300_debug.h"
30 #include "r300_reg.h"
31 #include "r300_screen.h"
32
33 /* XXX get these to r300_reg */
34 #define R300_PVS_DST_OPCODE(x) ((x) << 0)
35 # define R300_VE_MULTIPLY 2
36 # define R300_VE_ADD 3
37 #define R300_PVS_DST_MACRO_INST (1 << 7)
38 # define R300_PVS_MACRO_OP_2CLK_MADD 0
39 #define R300_PVS_DST_REG_TYPE(x) ((x) << 8)
40 # define R300_PVS_DST_REG_TEMPORARY 0
41 # define R300_PVS_DST_REG_A0 1
42 # define R300_PVS_DST_REG_OUT 2
43 # define R300_PVS_DST_REG_OUT_REPL_X 3
44 # define R300_PVS_DST_REG_ALT_TEMPORARY 4
45 # define R300_PVS_DST_REG_INPUT 5
46 #define R300_PVS_DST_OFFSET(x) ((x) << 13)
47 #define R300_PVS_DST_WE(x) ((x) << 20)
48 #define R300_PVS_DST_WE_XYZW (0xf << 20)
49
50 #define R300_PVS_SRC_REG_TYPE(x) ((x) << 0)
51 # define R300_PVS_SRC_REG_TEMPORARY 0
52 # define R300_PVS_SRC_REG_INPUT 1
53 # define R300_PVS_SRC_REG_CONSTANT 2
54 # define R300_PVS_SRC_REG_ALT_TEMPORARY 3
55 #define R300_PVS_SRC_OFFSET(x) ((x) << 5)
56 #define R300_PVS_SRC_SWIZZLE(x) ((x) << 13)
57 # define R300_PVS_SRC_SELECT_X 0
58 # define R300_PVS_SRC_SELECT_Y 1
59 # define R300_PVS_SRC_SELECT_Z 2
60 # define R300_PVS_SRC_SELECT_W 3
61 # define R300_PVS_SRC_SELECT_FORCE_0 4
62 # define R300_PVS_SRC_SELECT_FORCE_1 5
63 # define R300_PVS_SRC_SWIZZLE_XYZW \
64 ((R300_PVS_SRC_SELECT_X | (R300_PVS_SRC_SELECT_Y << 3) | \
65 (R300_PVS_SRC_SELECT_Z << 6) | (R300_PVS_SRC_SELECT_W << 9)) << 13)
66 # define R300_PVS_SRC_SWIZZLE_ZERO \
67 ((R300_PVS_SRC_SELECT_FORCE_0 | (R300_PVS_SRC_SELECT_FORCE_0 << 3) | \
68 (R300_PVS_SRC_SELECT_FORCE_0 << 6) | \
69 (R300_PVS_SRC_SELECT_FORCE_0 << 9)) << 13)
70 # define R300_PVS_SRC_SWIZZLE_ONE \
71 ((R300_PVS_SRC_SELECT_FORCE_1 | (R300_PVS_SRC_SELECT_FORCE_1 << 3) | \
72 (R300_PVS_SRC_SELECT_FORCE_1 << 6) | \
73 (R300_PVS_SRC_SELECT_FORCE_1 << 9)) << 13)
74
75 static const struct tgsi_full_src_register r300_constant_zero = {
76 .SrcRegister.Extended = TRUE,
77 .SrcRegister.File = TGSI_FILE_NULL,
78 .SrcRegisterExtSwz.ExtSwizzleX = TGSI_EXTSWIZZLE_ZERO,
79 .SrcRegisterExtSwz.ExtSwizzleY = TGSI_EXTSWIZZLE_ZERO,
80 .SrcRegisterExtSwz.ExtSwizzleZ = TGSI_EXTSWIZZLE_ZERO,
81 .SrcRegisterExtSwz.ExtSwizzleW = TGSI_EXTSWIZZLE_ZERO,
82 };
83
84 /* Temporary struct used to hold assembly state while putting together
85 * fragment programs. */
86 struct r300_vs_asm {
87 /* Pipe context. */
88 struct r300_context* r300;
89 /* Number of colors. */
90 unsigned color_count;
91 /* Number of texcoords. */
92 unsigned tex_count;
93 /* Number of requested temporary registers. */
94 unsigned temp_count;
95 /* Offset for immediate constants. Neither R300 nor R500 can do four
96 * inline constants per source, so instead we copy immediates into the
97 * constant buffer. */
98 unsigned imm_offset;
99 /* Number of immediate constants. */
100 unsigned imm_count;
101 /* Offsets into vertex output memory. */
102 unsigned tab[16];
103 };
104
105 static struct r300_vertex_shader r300_passthrough_vertex_shader = {
106 /* XXX translate these back into normal instructions */
107 .instruction_count = 2,
108 .instructions[0].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
109 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
110 R300_PVS_DST_OFFSET(0) | R300_PVS_DST_WE_XYZW,
111 .instructions[0].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
112 R300_PVS_SRC_OFFSET(0) | R300_PVS_SRC_SWIZZLE_XYZW,
113 .instructions[0].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
114 .instructions[0].inst3 = 0x0,
115 .instructions[1].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
116 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
117 R300_PVS_DST_OFFSET(2) | R300_PVS_DST_WE_XYZW,
118 .instructions[1].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
119 R300_PVS_SRC_OFFSET(1) | R300_PVS_SRC_SWIZZLE_XYZW,
120 .instructions[1].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
121 .instructions[1].inst3 = 0x0,
122 };
123
124 static struct r300_vertex_shader r300_texture_vertex_shader = {
125 /* XXX translate these back into normal instructions */
126 .instruction_count = 2,
127 .instructions[0].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
128 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
129 R300_PVS_DST_OFFSET(0) | R300_PVS_DST_WE_XYZW,
130 .instructions[0].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
131 R300_PVS_SRC_OFFSET(0) | R300_PVS_SRC_SWIZZLE_XYZW,
132 .instructions[0].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
133 .instructions[0].inst3 = 0x0,
134 .instructions[1].inst0 = R300_PVS_DST_OPCODE(R300_VE_ADD) |
135 R300_PVS_DST_REG_TYPE(R300_PVS_DST_REG_OUT) |
136 R300_PVS_DST_OFFSET(6) | R300_PVS_DST_WE_XYZW,
137 .instructions[1].inst1 = R300_PVS_SRC_REG_TYPE(R300_PVS_SRC_REG_INPUT) |
138 R300_PVS_SRC_OFFSET(1) | R300_PVS_SRC_SWIZZLE_XYZW,
139 .instructions[1].inst2 = R300_PVS_SRC_SWIZZLE_ZERO,
140 .instructions[1].inst3 = 0x0,
141 };
142
143 void r300_translate_vertex_shader(struct r300_context* r300,
144 struct r300_vertex_shader* vs);
145
146 #endif /* R300_STATE_TCL_H */