2 * Copyright 2008 Ben Skeggs
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include "nv50_context.h"
24 #include "nouveau/nouveau_stateobj.h"
27 nv50_state_validate_fb(struct nv50_context
*nv50
)
29 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
30 struct nouveau_stateobj
*so
= so_new(128, 18);
31 struct pipe_framebuffer_state
*fb
= &nv50
->framebuffer
;
32 unsigned i
, w
, h
, gw
= 0;
34 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
35 struct nouveau_bo
*bo
= nouveau_bo(nv50_surface_buffer(fb
->cbufs
[i
]));
38 w
= fb
->cbufs
[i
]->width
;
39 h
= fb
->cbufs
[i
]->height
;
42 assert(w
== fb
->cbufs
[i
]->width
);
43 assert(h
== fb
->cbufs
[i
]->height
);
46 so_method(so
, tesla
, NV50TCL_RT_HORIZ(i
), 2);
47 so_data (so
, fb
->cbufs
[i
]->width
);
48 so_data (so
, fb
->cbufs
[i
]->height
);
50 so_method(so
, tesla
, NV50TCL_RT_ADDRESS_HIGH(i
), 5);
51 so_reloc (so
, bo
, fb
->cbufs
[i
]->offset
, NOUVEAU_BO_VRAM
|
52 NOUVEAU_BO_HIGH
| NOUVEAU_BO_RDWR
, 0, 0);
53 so_reloc (so
, bo
, fb
->cbufs
[i
]->offset
, NOUVEAU_BO_VRAM
|
54 NOUVEAU_BO_LOW
| NOUVEAU_BO_RDWR
, 0, 0);
55 switch (fb
->cbufs
[i
]->format
) {
56 case PIPE_FORMAT_A8R8G8B8_UNORM
:
59 case PIPE_FORMAT_R5G6B5_UNORM
:
63 NOUVEAU_ERR("AIIII unknown format %s\n",
64 pf_name(fb
->cbufs
[i
]->format
));
68 so_data(so
, 0x00000000);
69 so_data(so
, 0x00000000);
71 so_method(so
, tesla
, 0x1224, 1);
76 struct nouveau_bo
*bo
= nouveau_bo(nv50_surface_buffer(fb
->zsbuf
));
80 h
= fb
->zsbuf
->height
;
83 assert(w
== fb
->zsbuf
->width
);
84 assert(h
== fb
->zsbuf
->height
);
87 so_method(so
, tesla
, NV50TCL_ZETA_ADDRESS_HIGH
, 5);
88 so_reloc (so
, bo
, fb
->zsbuf
->offset
, NOUVEAU_BO_VRAM
|
89 NOUVEAU_BO_HIGH
| NOUVEAU_BO_RDWR
, 0, 0);
90 so_reloc (so
, bo
, fb
->zsbuf
->offset
, NOUVEAU_BO_VRAM
|
91 NOUVEAU_BO_LOW
| NOUVEAU_BO_RDWR
, 0, 0);
92 switch (fb
->zsbuf
->format
) {
93 case PIPE_FORMAT_Z24S8_UNORM
:
96 case PIPE_FORMAT_Z16_UNORM
:
100 NOUVEAU_ERR("AIIII unknown format %s\n",
101 pf_name(fb
->zsbuf
->format
));
105 so_data(so
, 0x00000000);
106 so_data(so
, 0x00000000);
108 so_method(so
, tesla
, 0x1538, 1);
110 so_method(so
, tesla
, 0x1228, 3);
111 so_data (so
, fb
->zsbuf
->width
);
112 so_data (so
, fb
->zsbuf
->height
);
113 so_data (so
, 0x00010001);
116 so_method(so
, tesla
, NV50TCL_VIEWPORT_HORIZ
, 2);
117 so_data (so
, w
<< 16);
118 so_data (so
, h
<< 16);
119 so_method(so
, tesla
, 0x0e04, 2);
120 so_data (so
, w
<< 16);
121 so_data (so
, h
<< 16);
122 so_method(so
, tesla
, 0xdf8, 2);
126 so_ref(so
, &nv50
->state
.fb
);
131 nv50_state_emit(struct nv50_context
*nv50
)
133 struct nv50_screen
*screen
= nv50
->screen
;
134 struct nouveau_channel
*chan
= screen
->base
.channel
;
136 if (nv50
->pctx_id
!= screen
->cur_pctx
) {
137 nv50
->state
.dirty
|= 0xffffffff;
138 screen
->cur_pctx
= nv50
->pctx_id
;
141 if (nv50
->state
.dirty
& NV50_NEW_FRAMEBUFFER
)
142 so_emit(chan
, nv50
->state
.fb
);
143 if (nv50
->state
.dirty
& NV50_NEW_BLEND
)
144 so_emit(chan
, nv50
->state
.blend
);
145 if (nv50
->state
.dirty
& NV50_NEW_ZSA
)
146 so_emit(chan
, nv50
->state
.zsa
);
147 if (nv50
->state
.dirty
& NV50_NEW_VERTPROG
)
148 so_emit(chan
, nv50
->state
.vertprog
);
149 if (nv50
->state
.dirty
& NV50_NEW_FRAGPROG
)
150 so_emit(chan
, nv50
->state
.fragprog
);
151 if (nv50
->state
.dirty
& NV50_NEW_RASTERIZER
)
152 so_emit(chan
, nv50
->state
.rast
);
153 if (nv50
->state
.dirty
& NV50_NEW_BLEND_COLOUR
)
154 so_emit(chan
, nv50
->state
.blend_colour
);
155 if (nv50
->state
.dirty
& NV50_NEW_STIPPLE
)
156 so_emit(chan
, nv50
->state
.stipple
);
157 if (nv50
->state
.dirty
& NV50_NEW_SCISSOR
)
158 so_emit(chan
, nv50
->state
.scissor
);
159 if (nv50
->state
.dirty
& NV50_NEW_VIEWPORT
)
160 so_emit(chan
, nv50
->state
.viewport
);
161 if (nv50
->state
.dirty
& NV50_NEW_SAMPLER
)
162 so_emit(chan
, nv50
->state
.tsc_upload
);
163 if (nv50
->state
.dirty
& NV50_NEW_TEXTURE
)
164 so_emit(chan
, nv50
->state
.tic_upload
);
165 if (nv50
->state
.dirty
& NV50_NEW_ARRAYS
) {
166 so_emit(chan
, nv50
->state
.vtxfmt
);
167 so_emit(chan
, nv50
->state
.vtxbuf
);
169 nv50
->state
.dirty
= 0;
171 so_emit_reloc_markers(chan
, nv50
->state
.fb
);
172 so_emit_reloc_markers(chan
, nv50
->state
.vertprog
);
173 so_emit_reloc_markers(chan
, nv50
->state
.fragprog
);
174 so_emit_reloc_markers(chan
, nv50
->state
.vtxbuf
);
175 so_emit_reloc_markers(chan
, nv50
->screen
->static_init
);
179 nv50_state_validate(struct nv50_context
*nv50
)
181 struct nouveau_grobj
*tesla
= nv50
->screen
->tesla
;
182 struct nouveau_stateobj
*so
;
185 if (nv50
->dirty
& NV50_NEW_FRAMEBUFFER
)
186 nv50_state_validate_fb(nv50
);
188 if (nv50
->dirty
& NV50_NEW_BLEND
)
189 so_ref(nv50
->blend
->so
, &nv50
->state
.blend
);
191 if (nv50
->dirty
& NV50_NEW_ZSA
)
192 so_ref(nv50
->zsa
->so
, &nv50
->state
.zsa
);
194 if (nv50
->dirty
& (NV50_NEW_VERTPROG
| NV50_NEW_VERTPROG_CB
))
195 nv50_vertprog_validate(nv50
);
197 if (nv50
->dirty
& (NV50_NEW_FRAGPROG
| NV50_NEW_FRAGPROG_CB
))
198 nv50_fragprog_validate(nv50
);
200 if (nv50
->dirty
& NV50_NEW_RASTERIZER
)
201 so_ref(nv50
->rasterizer
->so
, &nv50
->state
.rast
);
203 if (nv50
->dirty
& NV50_NEW_BLEND_COLOUR
) {
205 so_method(so
, tesla
, NV50TCL_BLEND_COLOR(0), 4);
206 so_data (so
, fui(nv50
->blend_colour
.color
[0]));
207 so_data (so
, fui(nv50
->blend_colour
.color
[1]));
208 so_data (so
, fui(nv50
->blend_colour
.color
[2]));
209 so_data (so
, fui(nv50
->blend_colour
.color
[3]));
210 so_ref(so
, &nv50
->state
.blend_colour
);
214 if (nv50
->dirty
& NV50_NEW_STIPPLE
) {
216 so_method(so
, tesla
, NV50TCL_POLYGON_STIPPLE_PATTERN(0), 32);
217 for (i
= 0; i
< 32; i
++)
218 so_data(so
, nv50
->stipple
.stipple
[i
]);
219 so_ref(so
, &nv50
->state
.stipple
);
223 if (nv50
->dirty
& (NV50_NEW_SCISSOR
| NV50_NEW_RASTERIZER
)) {
224 struct pipe_rasterizer_state
*rast
= &nv50
->rasterizer
->pipe
;
225 struct pipe_scissor_state
*s
= &nv50
->scissor
;
227 if (nv50
->state
.scissor
&&
228 (rast
->scissor
== 0 && nv50
->state
.scissor_enabled
== 0))
229 goto scissor_uptodate
;
230 nv50
->state
.scissor_enabled
= rast
->scissor
;
233 so_method(so
, tesla
, 0x0ff4, 2);
234 if (nv50
->state
.scissor_enabled
) {
235 so_data(so
, ((s
->maxx
- s
->minx
) << 16) | s
->minx
);
236 so_data(so
, ((s
->maxy
- s
->miny
) << 16) | s
->miny
);
238 so_data(so
, (8192 << 16));
239 so_data(so
, (8192 << 16));
241 so_ref(so
, &nv50
->state
.scissor
);
243 nv50
->state
.dirty
|= NV50_NEW_SCISSOR
;
247 if (nv50
->dirty
& (NV50_NEW_VIEWPORT
| NV50_NEW_RASTERIZER
)) {
250 if (!nv50
->rasterizer
->pipe
.bypass_vs_clip_and_viewport
)
255 if (nv50
->state
.viewport
&&
256 (bypass
|| !(nv50
->dirty
& NV50_NEW_VIEWPORT
)) &&
257 nv50
->state
.viewport_bypass
== bypass
)
258 goto viewport_uptodate
;
259 nv50
->state
.viewport_bypass
= bypass
;
263 so_method(so
, tesla
, NV50TCL_VIEWPORT_UNK1(0), 3);
264 so_data (so
, fui(nv50
->viewport
.translate
[0]));
265 so_data (so
, fui(nv50
->viewport
.translate
[1]));
266 so_data (so
, fui(nv50
->viewport
.translate
[2]));
267 so_method(so
, tesla
, NV50TCL_VIEWPORT_UNK0(0), 3);
268 so_data (so
, fui(nv50
->viewport
.scale
[0]));
269 so_data (so
, fui(-nv50
->viewport
.scale
[1]));
270 so_data (so
, fui(nv50
->viewport
.scale
[2]));
271 so_method(so
, tesla
, 0x192c, 1);
273 so_method(so
, tesla
, 0x0f90, 1);
276 so_method(so
, tesla
, 0x192c, 1);
278 so_method(so
, tesla
, 0x0f90, 1);
282 so_ref(so
, &nv50
->state
.viewport
);
284 nv50
->state
.dirty
|= NV50_NEW_VIEWPORT
;
288 if (nv50
->dirty
& NV50_NEW_SAMPLER
) {
291 so
= so_new(nv50
->sampler_nr
* 8 + 3, 0);
292 so_method(so
, tesla
, 0x0f00, 1);
293 so_data (so
, NV50_CB_TSC
);
294 so_method(so
, tesla
, 0x40000f04, nv50
->sampler_nr
* 8);
295 for (i
= 0; i
< nv50
->sampler_nr
; i
++)
296 so_datap (so
, nv50
->sampler
[i
], 8);
297 so_ref(so
, &nv50
->state
.tsc_upload
);
301 if (nv50
->dirty
& NV50_NEW_TEXTURE
)
302 nv50_tex_validate(nv50
);
304 if (nv50
->dirty
& NV50_NEW_ARRAYS
)
305 nv50_vbo_validate(nv50
);
307 nv50
->state
.dirty
|= nv50
->dirty
;
309 nv50_state_emit(nv50
);