nouveau: synchronize "scratch runout" destruction with the command stream
PATCH 1/1 nouveau: synchronize "scratch runout" destruction with the command stream
When nvc0_push_vbo calls nouveau_scratch_done it does not mean scratch buffers can be freed immediately. It means "when hardware advances to this place in the command stream the scratch buffers can be freed".
The bug existed for a very long time. Nobody noticed, because "scratch runout" code path is rarely executed.
Fixes "Serious Sam 3" on nve7/gk107.
--- src/gallium/drivers/nouveau/nouveau_buffer.c | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
src/gallium/drivers/nouveau/nouveau_buffer.c +28 -5
@@ -846,19 +846,42 @@ nouveau_scratch_bo_alloc(struct nouveau_context *nv, struct nouveau_bo **pbo, 4096, size, NULL, pbo); } +struct bos +{ +unsigned nr; +struct nouveau_bo **arr; +}; + +static void +unref_bos (void *d) +{ +struct bos *b = d; +int i; + +for (i =0 ; i < b->nr; ++i) +nouveau_bo_ref (NULL , &b->arr[i]); + +FREE (b->arr); +FREE (b); +} +void nouveau_scratch_runout_release (struct nouveau_context *nv) {if (!nv->scratch.nr_runout)return ; -do { - --nv->scratch.nr_runout; -nouveau_bo_ref (NULL , &nv->scratch.runout[nv->scratch.nr_runout]); - }while (nv->scratch.nr_runout); -FREE (nv->scratch.runout); +struct bos *b =MALLOC (sizeof (*b)); + b->arr = nv->scratch.runout; + b->nr = nv->scratch.nr_runout; + +struct nouveau_fence *fence =NULL ; +nouveau_fence_new (nv->screen, &fence, TRUE); +nouveau_fence_work (fence, unref_bos, b); + nv->scratch.end =0 ; nv->scratch.runout =NULL ; + nv->scratch.nr_runout =0 ; }/* Allocate an extra bo if we can't fit everything we need simultaneously.
Signature · 6 lines
2.1.0 _______________________________________________ Nouveau mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/nouveau
The big issue I have with this patch is that it's a little dirty to have the bos thing like that. I had a long comment about a way to mitigate that, but in the end, it may not be worth it... this scratch system is complex and it's insufficiently necessary to muck with it. Not a huge fan of creating a new fence either...
If you *are* interested in trying to fix it all up, moving all the scratch stuff off to the side and then attaching a fence to it (updated in the various kick methods) and then freeing when that fence is hit -- that seems like it'd be a bit cleaner. But not enough so that I'd ask or even recommend doing it.
Quoted 42 lines · Marcin Ślusarz
When
nvc0_push_vbocallsnouveau_scratch_doneit does not mean scratch buffers can be freed immediately. It means "when hardware advances to this place in the command stream the scratch buffers can be freed".The bug existed for a very long time. Nobody noticed, because "scratch runout" code path is rarely executed.
Fixes "Serious Sam 3" on nve7/gk107.
--- src/gallium/drivers/nouveau/nouveau_buffer.c | 33 +++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)src/gallium/drivers/nouveau/nouveau_buffer.c +19
-0@@ -846,19 +846,42 @@ nouveau_scratch_bo_alloc(struct nouveau_context *nv, struct nouveau_bo **pbo, 4096, size, NULL, pbo); } +struct bos +{ +unsigned nr; +struct nouveau_bo **arr; +}; + +static void +unref_bos (void *d) +{ +struct bos *b = d; +int i; + +for (i =0 ; i < b->nr; ++i) +nouveau_bo_ref (NULL , &b->arr[i]); + +FREE (b->arr); +FREE (b); +} +void nouveau_scratch_runout_release (struct nouveau_context *nv)
src/gallium/drivers/nouveau/nouveau_buffer.c nouveau_scratch_bo_alloc(struct nouveau_context *nv, struct nouveau_bo **pbo, · line 874
Quoted 10 lines
src/gallium/drivers/nouveau/nouveau_buffer.c +1
-5{if (!nv->scratch.nr_runout)return ; -do { - --nv->scratch.nr_runout; -nouveau_bo_ref (NULL , &nv->scratch.runout[nv->scratch.nr_runout]); - }while (nv->scratch.nr_runout); -FREE (nv->scratch.runout); +struct bos *b =MALLOC (sizeof (*b));
Let's not crash if this fails... I'd be totally fine with just leaking the bo's, or alternatively stalling until the fence is hit.
src/gallium/drivers/nouveau/nouveau_buffer.c nouveau_scratch_bo_alloc(struct nouveau_context *nv, struct nouveau_bo **pbo, · line 878
Quoted 4 lines
src/gallium/drivers/nouveau/nouveau_buffer.c +4
-0+ b->arr = nv->scratch.runout; + b->nr = nv->scratch.nr_runout; + +struct nouveau_fence *fence =NULL ;
Unnecessary (the = NULL bit).
Quoted 12 lines
src/gallium/drivers/nouveau/nouveau_buffer.c +4
-1+nouveau_fence_new (nv->screen, &fence, TRUE); +nouveau_fence_work (fence, unref_bos, b); + nv->scratch.end =0 ; nv->scratch.runout =NULL ; + nv->scratch.nr_runout =0 ; }/* Allocate an extra bo if we can't fit everything we need simultaneously. -- 2.1.0
Quoted 4 lines
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau