summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/nv30/nv30_state_validate.c
blob: 99a98799a0c4feadca8680b76ba613edefa4934c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
/*
 * Copyright 2012 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 *
 */

#include "util/u_format.h"
#include "util/u_math.h"
#include "util/u_half.h"

#include "nouveau/nv_object.xml.h"
#include "nv30-40_3d.xml.h"
#include "nv30_context.h"
#include "nv30_format.h"

static void
nv30_validate_fb(struct nv30_context *nv30)
{
   struct pipe_screen *pscreen = &nv30->screen->base.base;
   struct pipe_framebuffer_state *fb = &nv30->framebuffer;
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct nouveau_object *eng3d = nv30->screen->eng3d;
   uint32_t rt_format;
   int h = fb->height;
   int w = fb->width;
   int x = 0;
   int y = 0;

   nv30->state.rt_enable = (NV30_3D_RT_ENABLE_COLOR0 << fb->nr_cbufs) - 1;
   if (nv30->state.rt_enable > 1)
      nv30->state.rt_enable |= NV30_3D_RT_ENABLE_MRT;

   rt_format = 0;
   if (fb->nr_cbufs > 0) {
      struct nv30_miptree *mt = nv30_miptree(fb->cbufs[0]->texture);
      rt_format |= nv30_format(pscreen, fb->cbufs[0]->format)->hw;
      rt_format |= mt->ms_mode;
      if (mt->swizzled)
         rt_format |= NV30_3D_RT_FORMAT_TYPE_SWIZZLED;
      else
         rt_format |= NV30_3D_RT_FORMAT_TYPE_LINEAR;
   } else {
      if (fb->zsbuf && util_format_get_blocksize(fb->zsbuf->format) > 2)
         rt_format |= NV30_3D_RT_FORMAT_COLOR_A8R8G8B8;
      else
         rt_format |= NV30_3D_RT_FORMAT_COLOR_R5G6B5;
   }

   if (fb->zsbuf) {
      rt_format |= nv30_format(pscreen, fb->zsbuf->format)->hw;
      if (nv30_miptree(fb->zsbuf->texture)->swizzled)
         rt_format |= NV30_3D_RT_FORMAT_TYPE_SWIZZLED;
      else
         rt_format |= NV30_3D_RT_FORMAT_TYPE_LINEAR;
   } else {
      if (fb->nr_cbufs && util_format_get_blocksize(fb->cbufs[0]->format) > 2)
         rt_format |= NV30_3D_RT_FORMAT_ZETA_Z24S8;
      else
         rt_format |= NV30_3D_RT_FORMAT_ZETA_Z16;
   }

   /* hardware rounds down render target offset to 64 bytes, but surfaces
    * with a size of 2x2 pixel (16bpp) or 1x1 pixel (32bpp) have an
    * unaligned start aaddress.  For these two important square formats
    * we can hack around this limitation by adjusting the viewport origin
    */
   if (nv30->state.rt_enable) {
      int off = nv30_surface(fb->cbufs[0])->offset & 63;
      if (off) {
         x += off / (util_format_get_blocksize(fb->cbufs[0]->format) * 2);
         w  = 16;
         h  = 2;
      }
   }

   if (rt_format & NV30_3D_RT_FORMAT_TYPE_SWIZZLED) {
      rt_format |= util_logbase2(w) << 16;
      rt_format |= util_logbase2(h) << 24;
   }

   if (!PUSH_SPACE(push, 64))
      return;
   PUSH_RESET(push, BUFCTX_FB);

   BEGIN_NV04(push, SUBC_3D(0x1da4), 1);
   PUSH_DATA (push, 0);
   BEGIN_NV04(push, NV30_3D(RT_HORIZ), 3);
   PUSH_DATA (push, w << 16);
   PUSH_DATA (push, h << 16);
   PUSH_DATA (push, rt_format);
   BEGIN_NV04(push, NV30_3D(VIEWPORT_HORIZ), 2);
   PUSH_DATA (push, w << 16);
   PUSH_DATA (push, h << 16);
   BEGIN_NV04(push, NV30_3D(VIEWPORT_TX_ORIGIN), 4);
   PUSH_DATA (push, (y << 16) | x);
   PUSH_DATA (push, 0);
   PUSH_DATA (push, ((w - 1) << 16) | 0);
   PUSH_DATA (push, ((h - 1) << 16) | 0);

   if ((nv30->state.rt_enable & NV30_3D_RT_ENABLE_COLOR0) || fb->zsbuf) {
      struct nv30_surface *rsf = nv30_surface(fb->cbufs[0]);
      struct nv30_surface *zsf = nv30_surface(fb->zsbuf);
      struct nouveau_bo *rbo, *zbo;

      if (!rsf)      rsf = zsf;
      else if (!zsf) zsf = rsf;
      rbo = nv30_miptree(rsf->base.texture)->base.bo;
      zbo = nv30_miptree(zsf->base.texture)->base.bo;

      if (eng3d->oclass >= NV40_3D_CLASS) {
         BEGIN_NV04(push, NV40_3D(ZETA_PITCH), 1);
         PUSH_DATA (push, zsf->pitch);
         BEGIN_NV04(push, NV40_3D(COLOR0_PITCH), 3);
         PUSH_DATA (push, rsf->pitch);
      } else {
         BEGIN_NV04(push, NV30_3D(COLOR0_PITCH), 3);
         PUSH_DATA (push, (zsf->pitch << 16) | rsf->pitch);
      }
      PUSH_MTHDl(push, NV30_3D(COLOR0_OFFSET), BUFCTX_FB, rbo, rsf->offset & ~63,
                       NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
      PUSH_MTHDl(push, NV30_3D(ZETA_OFFSET), BUFCTX_FB, zbo, zsf->offset & ~63,
                       NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
   }

   if (nv30->state.rt_enable & NV30_3D_RT_ENABLE_COLOR1) {
      struct nv30_surface *sf = nv30_surface(fb->cbufs[1]);
      struct nouveau_bo *bo = nv30_miptree(sf->base.texture)->base.bo;

      BEGIN_NV04(push, NV30_3D(COLOR1_OFFSET), 2);
      PUSH_MTHDl(push, NV30_3D(COLOR1_OFFSET), BUFCTX_FB, bo, sf->offset,
                       NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
      PUSH_DATA (push, sf->pitch);
   }

   if (nv30->state.rt_enable & NV40_3D_RT_ENABLE_COLOR2) {
      struct nv30_surface *sf = nv30_surface(fb->cbufs[2]);
      struct nouveau_bo *bo = nv30_miptree(sf->base.texture)->base.bo;

      BEGIN_NV04(push, NV40_3D(COLOR2_OFFSET), 1);
      PUSH_MTHDl(push, NV40_3D(COLOR2_OFFSET), BUFCTX_FB, bo, sf->offset,
                       NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
      BEGIN_NV04(push, NV40_3D(COLOR2_PITCH), 1);
      PUSH_DATA (push, sf->pitch);
   }

   if (nv30->state.rt_enable & NV40_3D_RT_ENABLE_COLOR3) {
      struct nv30_surface *sf = nv30_surface(fb->cbufs[3]);
      struct nouveau_bo *bo = nv30_miptree(sf->base.texture)->base.bo;

      BEGIN_NV04(push, NV40_3D(COLOR3_OFFSET), 1);
      PUSH_MTHDl(push, NV40_3D(COLOR3_OFFSET), BUFCTX_FB, bo, sf->offset,
                       NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
      BEGIN_NV04(push, NV40_3D(COLOR3_PITCH), 1);
      PUSH_DATA (push, sf->pitch);
   }
}

static void
nv30_validate_blend_colour(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   float *rgba = nv30->blend_colour.color;

   if (nv30->framebuffer.nr_cbufs) {
      switch (nv30->framebuffer.cbufs[0]->format) {
      case PIPE_FORMAT_R16G16B16A16_FLOAT:
      case PIPE_FORMAT_R32G32B32A32_FLOAT:
         BEGIN_NV04(push, NV30_3D(BLEND_COLOR), 1);
         PUSH_DATA (push, (util_float_to_half(rgba[0]) <<  0) |
                          (util_float_to_half(rgba[1]) << 16));
         BEGIN_NV04(push, SUBC_3D(0x037c), 1);
         PUSH_DATA (push, (util_float_to_half(rgba[2]) <<  0) |
                          (util_float_to_half(rgba[3]) << 16));
         break;
      default:
         break;
      }
   }

   BEGIN_NV04(push, NV30_3D(BLEND_COLOR), 1);
   PUSH_DATA (push, (float_to_ubyte(rgba[3]) << 24) |
                    (float_to_ubyte(rgba[0]) << 16) |
                    (float_to_ubyte(rgba[1]) <<  8) |
                    (float_to_ubyte(rgba[2]) <<  0));
}

static void
nv30_validate_stencil_ref(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;

   BEGIN_NV04(push, NV30_3D(STENCIL_FUNC_REF(0)), 1);
   PUSH_DATA (push, nv30->stencil_ref.ref_value[0]);
   BEGIN_NV04(push, NV30_3D(STENCIL_FUNC_REF(1)), 1);
   PUSH_DATA (push, nv30->stencil_ref.ref_value[1]);
}

static void
nv30_validate_stipple(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;

   BEGIN_NV04(push, NV30_3D(POLYGON_STIPPLE_PATTERN(0)), 32);
   PUSH_DATAp(push, nv30->stipple.stipple, 32);
}

static void
nv30_validate_scissor(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct pipe_scissor_state *s = &nv30->scissor;

   if (!(nv30->dirty & NV30_NEW_SCISSOR) &&
       nv30->rast->pipe.scissor != nv30->state.scissor_off)
      return;
   nv30->state.scissor_off = !nv30->rast->pipe.scissor;

   BEGIN_NV04(push, NV30_3D(SCISSOR_HORIZ), 2);
   if (nv30->rast->pipe.scissor) {
      PUSH_DATA (push, ((s->maxx - s->minx) << 16) | s->minx);
      PUSH_DATA (push, ((s->maxy - s->miny) << 16) | s->miny);
   } else {
      PUSH_DATA (push, 0x10000000);
      PUSH_DATA (push, 0x10000000);
   }
}

static void
nv30_validate_viewport(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct pipe_viewport_state *vp = &nv30->viewport;

   BEGIN_NV04(push, NV30_3D(VIEWPORT_TRANSLATE_X), 8);
   PUSH_DATAf(push, vp->translate[0]);
   PUSH_DATAf(push, vp->translate[1]);
   PUSH_DATAf(push, vp->translate[2]);
   PUSH_DATAf(push, vp->translate[3]);
   PUSH_DATAf(push, vp->scale[0]);
   PUSH_DATAf(push, vp->scale[1]);
   PUSH_DATAf(push, vp->scale[2]);
   PUSH_DATAf(push, vp->scale[3]);
   BEGIN_NV04(push, NV30_3D(DEPTH_RANGE_NEAR), 2);
   PUSH_DATAf(push, vp->translate[2] - fabsf(vp->scale[2]));
   PUSH_DATAf(push, vp->translate[2] + fabsf(vp->scale[2]));
}

static void
nv30_validate_clip(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   unsigned i;
   uint32_t clpd_enable = 0;

   for (i = 0; i < 6; i++) {
      if (nv30->rast->pipe.clip_plane_enable & (1 << i)) {
         if (nv30->dirty & NV30_NEW_CLIP) {
            BEGIN_NV04(push, NV30_3D(VP_UPLOAD_CONST_ID), 5);
            PUSH_DATA (push, i);
            PUSH_DATAp(push, nv30->clip.ucp[i], 4);
         }

         clpd_enable |= 1 << (1 + 4*i);
      }
   }

   BEGIN_NV04(push, NV30_3D(VP_CLIP_PLANES_ENABLE), 1);
   PUSH_DATA (push, clpd_enable);
}

static void
nv30_validate_blend(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;

   PUSH_SPACE(push, nv30->blend->size);
   PUSH_DATAp(push, nv30->blend->data, nv30->blend->size);
}

static void
nv30_validate_zsa(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;

   PUSH_SPACE(push, nv30->zsa->size);
   PUSH_DATAp(push, nv30->zsa->data, nv30->zsa->size);
}

static void
nv30_validate_rasterizer(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;

   PUSH_SPACE(push, nv30->rast->size);
   PUSH_DATAp(push, nv30->rast->data, nv30->rast->size);
}

static void
nv30_validate_multisample(struct nv30_context *nv30)
{
   struct pipe_rasterizer_state *rasterizer = &nv30->rast->pipe;
   struct pipe_blend_state *blend = &nv30->blend->pipe;
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   uint32_t ctrl = nv30->sample_mask << 16;

   if (blend->alpha_to_one)
      ctrl |= 0x00000100;
   if (blend->alpha_to_coverage)
      ctrl |= 0x00000010;
   if (rasterizer->multisample)
      ctrl |= 0x00000001;

   BEGIN_NV04(push, NV30_3D(MULTISAMPLE_CONTROL), 1);
   PUSH_DATA (push, ctrl);
}

static void
nv30_validate_fragment(struct nv30_context *nv30)
{
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct nv30_fragprog *fp = nv30->fragprog.program;

   BEGIN_NV04(push, NV30_3D(RT_ENABLE), 1);
   PUSH_DATA (push, nv30->state.rt_enable & ~fp->rt_enable);
   BEGIN_NV04(push, NV30_3D(COORD_CONVENTIONS), 1);
   PUSH_DATA (push, fp->coord_conventions | nv30->framebuffer.height);
}

static void
nv30_validate_point_coord(struct nv30_context *nv30)
{
   struct pipe_rasterizer_state *rasterizer = &nv30->rast->pipe;
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct nv30_fragprog *fp = nv30->fragprog.program;
   uint32_t hw = 0x00000000;

   if (rasterizer) {
      hw |= (nv30->rast->pipe.sprite_coord_enable & 0xff) << 8;
      if (fp)
         hw |= fp->point_sprite_control;

      if (rasterizer->sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT) {
         if (hw)
            nv30->draw_flags |= NV30_NEW_RASTERIZER;
      } else
      if (rasterizer->point_quad_rasterization) {
         hw |= NV30_3D_POINT_SPRITE_ENABLE;
      }
   }

   BEGIN_NV04(push, NV30_3D(POINT_SPRITE), 1);
   PUSH_DATA (push, hw);
}

struct state_validate {
   void (*func)(struct nv30_context *);
   uint32_t mask;
};

static struct state_validate hwtnl_validate_list[] = {
    { nv30_validate_fb,            NV30_NEW_FRAMEBUFFER },
    { nv30_validate_blend,         NV30_NEW_BLEND },
    { nv30_validate_zsa,           NV30_NEW_ZSA },
    { nv30_validate_rasterizer,    NV30_NEW_RASTERIZER },
    { nv30_validate_multisample,   NV30_NEW_SAMPLE_MASK | NV30_NEW_BLEND |
                                   NV30_NEW_RASTERIZER },
    { nv30_validate_blend_colour,  NV30_NEW_BLEND_COLOUR |
                                   NV30_NEW_FRAMEBUFFER },
    { nv30_validate_stencil_ref,   NV30_NEW_STENCIL_REF },
    { nv30_validate_stipple,       NV30_NEW_STIPPLE },
    { nv30_validate_scissor,       NV30_NEW_SCISSOR | NV30_NEW_RASTERIZER },
    { nv30_validate_viewport,      NV30_NEW_VIEWPORT },
    { nv30_validate_clip,          NV30_NEW_CLIP },
    { nv30_fragprog_validate,      NV30_NEW_FRAGPROG | NV30_NEW_FRAGCONST },
    { nv30_vertprog_validate,      NV30_NEW_VERTPROG | NV30_NEW_VERTCONST |
                                   NV30_NEW_FRAGPROG | NV30_NEW_RASTERIZER },
    { nv30_validate_fragment,      NV30_NEW_FRAMEBUFFER | NV30_NEW_FRAGPROG },
    { nv30_validate_point_coord,   NV30_NEW_RASTERIZER | NV30_NEW_FRAGPROG },
    { nv30_fragtex_validate,       NV30_NEW_FRAGTEX },
    { nv40_verttex_validate,       NV30_NEW_VERTTEX },
    { nv30_vbo_validate,           NV30_NEW_VERTEX | NV30_NEW_ARRAYS },
    {}
};

#define NV30_SWTNL_MASK (NV30_NEW_VIEWPORT |  \
                         NV30_NEW_CLIP |      \
                         NV30_NEW_VERTPROG |  \
                         NV30_NEW_VERTCONST | \
                         NV30_NEW_VERTTEX |   \
                         NV30_NEW_VERTEX |    \
                         NV30_NEW_ARRAYS)

static struct state_validate swtnl_validate_list[] = {
    { nv30_validate_fb,            NV30_NEW_FRAMEBUFFER },
    { nv30_validate_blend,         NV30_NEW_BLEND },
    { nv30_validate_zsa,           NV30_NEW_ZSA },
    { nv30_validate_rasterizer,    NV30_NEW_RASTERIZER },
    { nv30_validate_multisample,   NV30_NEW_SAMPLE_MASK | NV30_NEW_BLEND |
                                   NV30_NEW_RASTERIZER },
    { nv30_validate_blend_colour,  NV30_NEW_BLEND_COLOUR |
                                   NV30_NEW_FRAMEBUFFER },
    { nv30_validate_stencil_ref,   NV30_NEW_STENCIL_REF },
    { nv30_validate_stipple,       NV30_NEW_STIPPLE },
    { nv30_validate_scissor,       NV30_NEW_SCISSOR | NV30_NEW_RASTERIZER },
    { nv30_fragprog_validate,      NV30_NEW_FRAGPROG | NV30_NEW_FRAGCONST },
    { nv30_validate_fragment,      NV30_NEW_FRAMEBUFFER | NV30_NEW_FRAGPROG },
    { nv30_fragtex_validate,       NV30_NEW_FRAGTEX },
    {}
};

static void
nv30_state_context_switch(struct nv30_context *nv30)
{
   struct nv30_context *prev = nv30->screen->cur_ctx;

   if (prev)
      nv30->state = prev->state;
   nv30->dirty = NV30_NEW_ALL;

   if (!nv30->vertex)
      nv30->dirty &= ~(NV30_NEW_VERTEX | NV30_NEW_ARRAYS);

   if (!nv30->vertprog.program)
      nv30->dirty &= ~NV30_NEW_VERTPROG;
   if (!nv30->fragprog.program)
      nv30->dirty &= ~NV30_NEW_FRAGPROG;

   if (!nv30->blend)
      nv30->dirty &= ~NV30_NEW_BLEND;
   if (!nv30->rast)
      nv30->dirty &= ~NV30_NEW_RASTERIZER;
   if (!nv30->zsa)
      nv30->dirty &= ~NV30_NEW_ZSA;

   nv30->screen->cur_ctx = nv30;
   nv30->base.pushbuf->user_priv = &nv30->bufctx;
}

boolean
nv30_state_validate(struct nv30_context *nv30, boolean hwtnl)
{
   struct nouveau_screen *screen = &nv30->screen->base;
   struct nouveau_pushbuf *push = nv30->base.pushbuf;
   struct nouveau_bufctx *bctx = nv30->bufctx;
   struct nouveau_bufref *bref;
   struct state_validate *validate;

   if (nv30->screen->cur_ctx != nv30)
      nv30_state_context_switch(nv30);

   if (hwtnl) {
      nv30->draw_dirty |= nv30->dirty;
      if (nv30->draw_flags) {
         nv30->draw_flags &= ~nv30->dirty;
         if (!nv30->draw_flags)
            nv30->dirty |= NV30_SWTNL_MASK;
      }
   }

   if (!nv30->draw_flags)
      validate = hwtnl_validate_list;
   else
      validate = swtnl_validate_list;

   if (nv30->dirty) {
      while (validate->func) {
         if (nv30->dirty & validate->mask)
            validate->func(nv30);
         validate++;
      }

      nv30->dirty = 0;
   }

   nouveau_pushbuf_bufctx(push, bctx);
   if (nouveau_pushbuf_validate(push)) {
      nouveau_pushbuf_bufctx(push, NULL);
      return FALSE;
   }

   /*XXX*/
   BEGIN_NV04(push, NV30_3D(VTX_CACHE_INVALIDATE_1710), 1);
   PUSH_DATA (push, 0);
   if (nv30->screen->eng3d->oclass >= NV40_3D_CLASS) {
      BEGIN_NV04(push, NV40_3D(TEX_CACHE_CTL), 1);
      PUSH_DATA (push, 2);
      BEGIN_NV04(push, NV40_3D(TEX_CACHE_CTL), 1);
      PUSH_DATA (push, 1);
      BEGIN_NV04(push, NV30_3D(R1718), 1);
      PUSH_DATA (push, 0);
      BEGIN_NV04(push, NV30_3D(R1718), 1);
      PUSH_DATA (push, 0);
      BEGIN_NV04(push, NV30_3D(R1718), 1);
      PUSH_DATA (push, 0);
   }

   LIST_FOR_EACH_ENTRY(bref, &bctx->current, thead) {
      struct nv04_resource *res = bref->priv;
      if (res && res->mm) {
         nouveau_fence_ref(screen->fence.current, &res->fence);

         if (bref->flags & NOUVEAU_BO_RD)
            res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;

         if (bref->flags & NOUVEAU_BO_WR) {
            nouveau_fence_ref(screen->fence.current, &res->fence_wr);
            res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
         }
      }
   }

   return TRUE;
}

void
nv30_state_release(struct nv30_context *nv30)
{
   nouveau_pushbuf_bufctx(nv30->base.pushbuf, NULL);
}