nouveau: Unreference state/buffer objects on context/screen destruction.
authorYounes Manton <younes.m@gmail.com>
Mon, 28 Dec 2009 22:33:34 +0000 (17:33 -0500)
committerYounes Manton <younes.m@gmail.com>
Mon, 28 Dec 2009 22:59:01 +0000 (17:59 -0500)
- unreference state objects so that buffer objects are unreferenced and
eventually destroyed
- free channel at screen's destruction

Based on Krzysztof Smiechowicz's patch.

12 files changed:
src/gallium/drivers/nouveau/nouveau_screen.c
src/gallium/drivers/nv04/nv04_screen.c
src/gallium/drivers/nv10/nv10_screen.c
src/gallium/drivers/nv20/nv20_screen.c
src/gallium/drivers/nv30/nv30_context.c
src/gallium/drivers/nv30/nv30_fragprog.c
src/gallium/drivers/nv30/nv30_screen.c
src/gallium/drivers/nv40/nv40_context.c
src/gallium/drivers/nv40/nv40_fragprog.c
src/gallium/drivers/nv40/nv40_screen.c
src/gallium/drivers/nv50/nv50_context.c
src/gallium/drivers/nv50/nv50_screen.c

index e4cf91c005c4d5d9a9ba8ac8d936e097e7e65d10..0437af3725c152b92cab09f5727c020cbd340fc4 100644 (file)
@@ -31,7 +31,7 @@ nouveau_screen_bo_skel(struct pipe_screen *pscreen, struct nouveau_bo *bo,
                       unsigned alignment, unsigned usage, unsigned size)
 {
        struct pipe_buffer *pb;
-       
+
        pb = CALLOC(1, sizeof(struct pipe_buffer)+sizeof(struct nouveau_bo *));
        if (!pb) {
                nouveau_bo_ref(NULL, &bo);
@@ -239,5 +239,6 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
 void
 nouveau_screen_fini(struct nouveau_screen *screen)
 {
+       nouveau_channel_free(&screen->channel);
 }
 
index ee9b7d2e489712144f2eed17b113b7f0f80f7a54..7c5b6e8229ae1d8f3ad4b5bf5cdf1f64acc47726 100644 (file)
@@ -119,6 +119,8 @@ nv04_screen_destroy(struct pipe_screen *pscreen)
        nouveau_grobj_free(&screen->fahrenheit);
        nv04_surface_2d_takedown(&screen->eng2d);
 
+       nouveau_screen_fini(&screen->base);
+
        FREE(pscreen);
 }
 
index ee5901e743e54554a5d276439ccdc4a617878d47..6a39ddeaacb282d833d37b3ee668bea34b1f8daa 100644 (file)
@@ -115,6 +115,9 @@ nv10_screen_destroy(struct pipe_screen *pscreen)
 
        nouveau_notifier_free(&screen->sync);
        nouveau_grobj_free(&screen->celsius);
+       nv04_surface_2d_takedown(&screen->eng2d);
+
+       nouveau_screen_fini(&screen->base);
 
        FREE(pscreen);
 }
index 4eeacd1afd56661debacfc33078fab2fa32cde13..a0973f1ebdc3ce184796b5abf7833df97f29c5d8 100644 (file)
@@ -115,6 +115,9 @@ nv20_screen_destroy(struct pipe_screen *pscreen)
 
        nouveau_notifier_free(&screen->sync);
        nouveau_grobj_free(&screen->kelvin);
+       nv04_surface_2d_takedown(&screen->eng2d);
+
+       nouveau_screen_fini(&screen->base);
 
        FREE(pscreen);
 }
index 46a821a48b1f03b22e071120083e425d946918f8..38b39159f1950a964882b1c7a78a069a4ccef739 100644 (file)
@@ -25,6 +25,12 @@ static void
 nv30_destroy(struct pipe_context *pipe)
 {
        struct nv30_context *nv30 = nv30_context(pipe);
+       unsigned i;
+
+       for (i = 0; i < NV30_STATE_MAX; i++) {
+               if (nv30->state.hw[i])
+                       so_ref(NULL, &nv30->state.hw[i]);
+       }
 
        if (nv30->draw)
                draw_destroy(nv30->draw);
index dc4e583ce9dea37dca51aea5dbc34aeb6ab6e485..d1ff18e2dfb0b843013fce59bf4528f46cfcabc5 100644 (file)
@@ -886,6 +886,12 @@ void
 nv30_fragprog_destroy(struct nv30_context *nv30,
                      struct nv30_fragment_program *fp)
 {
+       if (fp->buffer)
+               pipe_buffer_reference(&fp->buffer, NULL);
+
+       if (fp->so)
+               so_ref(NULL, &fp->so);
+
        if (fp->insn_len)
                FREE(fp->insn);
 }
index 7cd36902eb489f04bf4a76de03cae8b29768c273..760467f73673db14a3e8f547935d422a0b536b79 100644 (file)
@@ -156,6 +156,12 @@ static void
 nv30_screen_destroy(struct pipe_screen *pscreen)
 {
        struct nv30_screen *screen = nv30_screen(pscreen);
+       unsigned i;
+
+       for (i = 0; i < NV30_STATE_MAX; i++) {
+               if (screen->state[i])
+                       so_ref(NULL, &screen->state[i]);
+       }
 
        nouveau_resource_free(&screen->vp_exec_heap);
        nouveau_resource_free(&screen->vp_data_heap);
@@ -163,6 +169,9 @@ nv30_screen_destroy(struct pipe_screen *pscreen)
        nouveau_notifier_free(&screen->query);
        nouveau_notifier_free(&screen->sync);
        nouveau_grobj_free(&screen->rankine);
+       nv04_surface_2d_takedown(&screen->eng2d);
+
+       nouveau_screen_fini(&screen->base);
 
        FREE(pscreen);
 }
index eb9cce4c786718b45708de45a47eb83e2d8538a3..d56c7a6b49cc81d83930a32eb69912849b80d76b 100644 (file)
@@ -25,6 +25,12 @@ static void
 nv40_destroy(struct pipe_context *pipe)
 {
        struct nv40_context *nv40 = nv40_context(pipe);
+       unsigned i;
+
+       for (i = 0; i < NV40_STATE_MAX; i++) {
+               if (nv40->state.hw[i])
+                       so_ref(NULL, &nv40->state.hw[i]);
+       }
 
        if (nv40->draw)
                draw_destroy(nv40->draw);
index 468d3509a987c77bdcb65bdc7519c3241fa56ff5..bb9c85cc434a6ce0383a5fdc68956355c7c35762 100644 (file)
@@ -149,7 +149,7 @@ emit_src(struct nv40_fpc *fpc, int pos, struct nv40_sreg src)
                                sizeof(uint32_t) * 4);
                }
 
-               sr |= (NV40_FP_REG_TYPE_CONST << NV40_FP_REG_TYPE_SHIFT);       
+               sr |= (NV40_FP_REG_TYPE_CONST << NV40_FP_REG_TYPE_SHIFT);
                break;
        case NV40SR_NONE:
                sr |= (NV40_FP_REG_TYPE_INPUT << NV40_FP_REG_TYPE_SHIFT);
@@ -768,7 +768,7 @@ nv40_fragprog_prepare(struct nv40_fpc *fpc)
                {
                        struct tgsi_full_immediate *imm;
                        float vals[4];
-                       
+
                        imm = &p.FullToken.FullImmediate;
                        assert(imm->Immediate.DataType == TGSI_IMM_FLOAT32);
                        assert(fpc->nr_imm < MAX_IMM);
@@ -852,7 +852,7 @@ nv40_fragprog_translate(struct nv40_context *nv40,
        fp->insn[fpc->inst_offset + 1] = 0x00000000;
        fp->insn[fpc->inst_offset + 2] = 0x00000000;
        fp->insn[fpc->inst_offset + 3] = 0x00000000;
-       
+
        fp->translated = TRUE;
 out_err:
        tgsi_parse_free(&parse);
@@ -933,7 +933,7 @@ nv40_fragprog_validate(struct nv40_context *nv40)
 update_constants:
        if (fp->nr_consts) {
                float *map;
-               
+
                map = pipe_buffer_map(pscreen, constbuf,
                                      PIPE_BUFFER_USAGE_CPU_READ);
                for (i = 0; i < fp->nr_consts; i++) {
@@ -964,6 +964,12 @@ void
 nv40_fragprog_destroy(struct nv40_context *nv40,
                      struct nv40_fragment_program *fp)
 {
+       if (fp->buffer)
+               pipe_buffer_reference(&fp->buffer, NULL);
+
+       if (fp->so)
+               so_ref(NULL, &fp->so);
+
        if (fp->insn_len)
                FREE(fp->insn);
 }
index bd13dfddd1c459b86f90d13a389762b9cd96e6f3..d01e71280510741c362f9b5c5a693aeb55113939 100644 (file)
@@ -140,6 +140,12 @@ static void
 nv40_screen_destroy(struct pipe_screen *pscreen)
 {
        struct nv40_screen *screen = nv40_screen(pscreen);
+       unsigned i;
+
+       for (i = 0; i < NV40_STATE_MAX; i++) {
+               if (screen->state[i])
+                       so_ref(NULL, &screen->state[i]);
+       }
 
        nouveau_resource_free(&screen->vp_exec_heap);
        nouveau_resource_free(&screen->vp_data_heap);
@@ -147,6 +153,7 @@ nv40_screen_destroy(struct pipe_screen *pscreen)
        nouveau_notifier_free(&screen->query);
        nouveau_notifier_free(&screen->sync);
        nouveau_grobj_free(&screen->curie);
+       nv04_surface_2d_takedown(&screen->eng2d);
 
        nouveau_screen_fini(&screen->base);
 
index d21b80eab8d476ea14679673d180bc5b76d7176e..5997456e4c9911f02374a66e811d9f982045f505 100644 (file)
@@ -43,6 +43,39 @@ nv50_destroy(struct pipe_context *pipe)
 {
        struct nv50_context *nv50 = nv50_context(pipe);
 
+        if (nv50->state.fb)
+               so_ref(NULL, &nv50->state.fb);
+       if (nv50->state.blend)
+               so_ref(NULL, &nv50->state.blend);
+       if (nv50->state.blend_colour)
+               so_ref(NULL, &nv50->state.blend_colour);
+       if (nv50->state.zsa)
+               so_ref(NULL, &nv50->state.zsa);
+       if (nv50->state.rast)
+               so_ref(NULL, &nv50->state.rast);
+       if (nv50->state.stipple)
+               so_ref(NULL, &nv50->state.stipple);
+       if (nv50->state.scissor)
+               so_ref(NULL, &nv50->state.scissor);
+       if (nv50->state.viewport)
+               so_ref(NULL, &nv50->state.viewport);
+       if (nv50->state.tsc_upload)
+               so_ref(NULL, &nv50->state.tsc_upload);
+       if (nv50->state.tic_upload)
+               so_ref(NULL, &nv50->state.tic_upload);
+       if (nv50->state.vertprog)
+               so_ref(NULL, &nv50->state.vertprog);
+       if (nv50->state.fragprog)
+               so_ref(NULL, &nv50->state.fragprog);
+       if (nv50->state.programs)
+               so_ref(NULL, &nv50->state.programs);
+       if (nv50->state.vtxfmt)
+               so_ref(NULL, &nv50->state.vtxfmt);
+       if (nv50->state.vtxbuf)
+               so_ref(NULL, &nv50->state.vtxbuf);
+       if (nv50->state.vtxattr)
+               so_ref(NULL, &nv50->state.vtxattr);
+
        draw_destroy(nv50->draw);
        FREE(nv50);
 }
index 15e4b6e5ca6884831b3058af0ae271dbbd5cd1a1..7e039ea82ecafe4df6c88723e9310bd21856130c 100644 (file)
@@ -165,6 +165,21 @@ static void
 nv50_screen_destroy(struct pipe_screen *pscreen)
 {
        struct nv50_screen *screen = nv50_screen(pscreen);
+       unsigned i;
+
+       for (i = 0; i < 2; i++) {
+               if (screen->constbuf_parm[i])
+                       nouveau_bo_ref(NULL, &screen->constbuf_parm[i]);
+       }
+
+       if (screen->constbuf_misc[0])
+               nouveau_bo_ref(NULL, &screen->constbuf_misc[0]);
+       if (screen->tic)
+               nouveau_bo_ref(NULL, &screen->tic);
+       if (screen->tsc)
+               nouveau_bo_ref(NULL, &screen->tsc);
+       if (screen->static_init)
+               so_ref(NULL, &screen->static_init);
 
        nouveau_notifier_free(&screen->sync);
        nouveau_grobj_free(&screen->tesla);