nvc0: avoid crash on updating RASTERIZE_ENABLE state
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Mon, 11 Mar 2013 19:53:25 +0000 (20:53 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Tue, 12 Mar 2013 11:55:37 +0000 (12:55 +0100)
When doing a blit with the 3D engine, the rasterizer or zsa cso may
be NULL.

src/gallium/drivers/nvc0/nvc0_state_validate.c
src/gallium/drivers/nvc0/nvc0_surface.c

index 1f12de61e9fb960858d8afd5184efb559f0cdf34..28573b5119364c722fc23466ce9c168bb70fc39a 100644 (file)
@@ -451,10 +451,14 @@ nvc0_validate_derived_1(struct nvc0_context *nvc0)
    struct nouveau_pushbuf *push = nvc0->base.pushbuf;
    boolean rasterizer_discard;
 
-   rasterizer_discard = (!nvc0->fragprog || !nvc0->fragprog->hdr[18]) &&
-      !nvc0->zsa->pipe.depth.enabled && !nvc0->zsa->pipe.stencil[0].enabled;
-   rasterizer_discard = rasterizer_discard ||
-      nvc0->rast->pipe.rasterizer_discard;
+   if (nvc0->rast && nvc0->rast->pipe.rasterizer_discard) {
+      rasterizer_discard = TRUE;
+   } else {
+      boolean zs = nvc0->zsa &&
+         (nvc0->zsa->pipe.depth.enabled || nvc0->zsa->pipe.stencil[0].enabled);
+      rasterizer_discard = !zs &&
+         (!nvc0->fragprog || !nvc0->fragprog->hdr[18]);
+   }
 
    if (rasterizer_discard != nvc0->state.rasterizer_discard) {
       nvc0->state.rasterizer_discard = rasterizer_discard;
index 77330c52ac56f269d304cd137ba30d93ce475a1a..cd4e3a75dc1947d70907a6ac8f27c828d581bf2c 100644 (file)
@@ -472,6 +472,7 @@ struct nvc0_blitctx
    enum pipe_texture_target target;
    struct {
       struct pipe_framebuffer_state fb;
+      struct nvc0_rasterizer_stateobj *rast;
       struct nvc0_program *vp;
       struct nvc0_program *tcp;
       struct nvc0_program *tep;
@@ -483,6 +484,7 @@ struct nvc0_blitctx
       struct nv50_tsc_entry *sampler[2];
       uint32_t dirty;
    } saved;
+   struct nvc0_rasterizer_stateobj rast;
 };
 
 static void
@@ -701,12 +703,16 @@ nvc0_blitctx_pre_blit(struct nvc0_blitctx *ctx)
    ctx->saved.fb.cbufs[0] = nvc0->framebuffer.cbufs[0];
    ctx->saved.fb.zsbuf = nvc0->framebuffer.zsbuf;
 
+   ctx->saved.rast = nvc0->rast;
+
    ctx->saved.vp = nvc0->vertprog;
    ctx->saved.tcp = nvc0->tctlprog;
    ctx->saved.tep = nvc0->tevlprog;
    ctx->saved.gp = nvc0->gmtyprog;
    ctx->saved.fp = nvc0->fragprog;
 
+   nvc0->rast = &ctx->rast;
+
    nvc0->vertprog = &blitter->vp;
    nvc0->tctlprog = NULL;
    nvc0->tevlprog = NULL;
@@ -760,6 +766,8 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit)
    nvc0->framebuffer.cbufs[0] = blit->saved.fb.cbufs[0];
    nvc0->framebuffer.zsbuf = blit->saved.fb.zsbuf;
 
+   nvc0->rast = blit->saved.rast;
+
    nvc0->vertprog = blit->saved.vp;
    nvc0->tctlprog = blit->saved.tcp;
    nvc0->tevlprog = blit->saved.tep;
@@ -1182,6 +1190,8 @@ nvc0_blitctx_create(struct nvc0_context *nvc0)
 
    nvc0->blit->nvc0 = nvc0;
 
+   nvc0->blit->rast.pipe.gl_rasterization_rules = 1;
+
    return TRUE;
 }