nvc0: use tile flags in a way compatible with nouveau
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_shader_state.c
1 /*
2 * Copyright 2010 Christoph Bumiller
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "pipe/p_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/p_state.h"
26 #include "util/u_inlines.h"
27
28 #include "nvc0_context.h"
29
30 static boolean
31 nvc0_program_validate(struct nvc0_context *nvc0, struct nvc0_program *prog)
32 {
33 int ret;
34 unsigned size;
35
36 if (prog->translated)
37 return TRUE;
38
39 prog->translated = nvc0_program_translate(prog);
40 if (!prog->translated)
41 return FALSE;
42
43 size = align(prog->code_size + NVC0_SHADER_HEADER_SIZE, 0x100);
44
45 ret = nouveau_resource_alloc(nvc0->screen->text_heap, size, prog,
46 &prog->res);
47 if (ret)
48 return FALSE;
49
50 prog->code_base = prog->res->start;
51
52 nvc0_m2mf_push_linear(nvc0, nvc0->screen->text, NOUVEAU_BO_VRAM,
53 prog->code_base, NVC0_SHADER_HEADER_SIZE, prog->hdr);
54 nvc0_m2mf_push_linear(nvc0, nvc0->screen->text, NOUVEAU_BO_VRAM,
55 prog->code_base + NVC0_SHADER_HEADER_SIZE,
56 prog->code_size, prog->code);
57
58 BEGIN_RING(nvc0->screen->base.channel, RING_3D_(0x021c), 1);
59 OUT_RING (nvc0->screen->base.channel, 0x1111);
60
61 return TRUE;
62 }
63
64 void
65 nvc0_vertprog_validate(struct nvc0_context *nvc0)
66 {
67 struct nouveau_channel *chan = nvc0->screen->base.channel;
68 struct nvc0_program *vp = nvc0->vertprog;
69
70 if (!nvc0_program_validate(nvc0, vp))
71 return;
72
73 BEGIN_RING(chan, RING_3D(SP_SELECT(1)), 2);
74 OUT_RING (chan, 0x11);
75 OUT_RING (chan, vp->code_base);
76 BEGIN_RING(chan, RING_3D(SP_GPR_ALLOC(1)), 1);
77 OUT_RING (chan, vp->max_gpr);
78
79 // BEGIN_RING(chan, RING_3D_(0x163c), 1);
80 // OUT_RING (chan, 0);
81 // BEGIN_RING(chan, RING_3D_(0x2600), 1);
82 // OUT_RING (chan, 1);
83 }
84
85 void
86 nvc0_fragprog_validate(struct nvc0_context *nvc0)
87 {
88 struct nouveau_channel *chan = nvc0->screen->base.channel;
89 struct nvc0_program *fp = nvc0->fragprog;
90
91 if (!nvc0_program_validate(nvc0, fp))
92 return;
93
94 BEGIN_RING(chan, RING_3D(EARLY_FRAGMENT_TESTS), 1);
95 OUT_RING (chan, 0);
96 BEGIN_RING(chan, RING_3D(SP_SELECT(5)), 2);
97 OUT_RING (chan, 0x51);
98 OUT_RING (chan, fp->code_base);
99 BEGIN_RING(chan, RING_3D(SP_GPR_ALLOC(5)), 1);
100 OUT_RING (chan, fp->max_gpr);
101
102 BEGIN_RING(chan, RING_3D_(0x0360), 2);
103 OUT_RING (chan, 0x20164010);
104 OUT_RING (chan, 0x20);
105 BEGIN_RING(chan, RING_3D_(0x196c), 1);
106 OUT_RING (chan, fp->flags[0]);
107 }
108
109 void
110 nvc0_tctlprog_validate(struct nvc0_context *nvc0)
111 {
112 struct nouveau_channel *chan = nvc0->screen->base.channel;
113 struct nvc0_program *tp = nvc0->tctlprog;
114
115 if (!tp) {
116 BEGIN_RING(chan, RING_3D(SP_SELECT(2)), 1);
117 OUT_RING (chan, 0x20);
118 return;
119 }
120 if (!nvc0_program_validate(nvc0, tp))
121 return;
122
123 BEGIN_RING(chan, RING_3D(SP_SELECT(2)), 2);
124 OUT_RING (chan, 0x21);
125 OUT_RING (chan, tp->code_base);
126 BEGIN_RING(chan, RING_3D(SP_GPR_ALLOC(2)), 1);
127 OUT_RING (chan, tp->max_gpr);
128 }
129
130 void
131 nvc0_tevlprog_validate(struct nvc0_context *nvc0)
132 {
133 struct nouveau_channel *chan = nvc0->screen->base.channel;
134 struct nvc0_program *tp = nvc0->tevlprog;
135
136 if (!tp) {
137 BEGIN_RING(chan, RING_3D(TEP_SELECT), 1);
138 OUT_RING (chan, 0x30);
139 return;
140 }
141 if (!nvc0_program_validate(nvc0, tp))
142 return;
143
144 BEGIN_RING(chan, RING_3D(TEP_SELECT), 1);
145 OUT_RING (chan, 0x31);
146 BEGIN_RING(chan, RING_3D(SP_START_ID(3)), 1);
147 OUT_RING (chan, tp->code_base);
148 BEGIN_RING(chan, RING_3D(SP_GPR_ALLOC(3)), 1);
149 OUT_RING (chan, tp->max_gpr);
150 }
151
152 void
153 nvc0_gmtyprog_validate(struct nvc0_context *nvc0)
154 {
155 struct nouveau_channel *chan = nvc0->screen->base.channel;
156 struct nvc0_program *gp = nvc0->gmtyprog;
157
158 if (!gp) {
159 BEGIN_RING(chan, RING_3D(GP_SELECT), 1);
160 OUT_RING (chan, 0x40);
161 return;
162 }
163 if (!nvc0_program_validate(nvc0, gp))
164 return;
165
166 BEGIN_RING(chan, RING_3D(GP_SELECT), 1);
167 OUT_RING (chan, 0x41);
168 BEGIN_RING(chan, RING_3D(SP_START_ID(4)), 1);
169 OUT_RING (chan, gp->code_base);
170 BEGIN_RING(chan, RING_3D(SP_GPR_ALLOC(4)), 1);
171 OUT_RING (chan, gp->max_gpr);
172 }