Skip to contentSkip to conversation

nouveau: avoid emitting new fences unnecessarily

PATCH In review Ilia Mirkin 3 participants 3 messages Oct 10, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nouveau: avoid emitting new fences unnecessarily

Right now we emit on every kick, but this is only necessary if something will ever be able to observe that the fence completed. If there are no refs, leave the fence alone and emit it another day.

This also happens to work around an issue for the kick handler -- a kick can be a result of e.g. nouveau_bo_wait or explicit kick, or it can be due to lack of space in the pushbuf. We want the emit to happen in the current batch, so we want there to always be enough space. However an explicit kick could take the reserved space for the implicitly-triggered kick's fence emission if it happened right after. With the new mechanism, hopefully there's no way to cause two fences to be emitted into the same reserved space.

Fixes 47d11990b (nouveau: make sure there's always room to emit a fence)
---
 src/gallium/drivers/nouveau/nouveau_fence.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
src/gallium/drivers/nouveau/nouveau_fence.c +9 -3
index ee4e08d..18b1592 100644
@@ -190,8 +190,10 @@ nouveau_fence_wait(struct nouveau_fence *fence)
    /* wtf, someone is waiting on a fence in flush_notify handler? */
    assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
 
-   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED)
+   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED) {
+      PUSH_SPACE(screen->pushbuf, 8);
       nouveau_fence_emit(fence);
+   }
 
    if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
       if (nouveau_pushbuf_kick(screen->pushbuf, screen->pushbuf->channel))
@@ -224,8 +226,12 @@ nouveau_fence_wait(struct nouveau_fence *fence)
 void
 nouveau_fence_next(struct nouveau_screen *screen)
 {
-   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING)
-      nouveau_fence_emit(screen->fence.current);
+   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING) {
+      if (screen->fence.current->ref > 1)
+         nouveau_fence_emit(screen->fence.current);
+      else
+         return;
+   }
 
    nouveau_fence_ref(NULL, &screen->fence.current);
 
Signature · 6 lines
2.4.9

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev
Reviewed-by on v1 1/1
#1 lore raw

Does this fix those texelFetch piglit tests ? Or is it the second patch ?

Anyway, this patch is :

Quoted 41 lines · Ilia Mirkin

Right now we emit on every kick, but this is only necessary if something will ever be able to observe that the fence completed. If there are no refs, leave the fence alone and emit it another day.

This also happens to work around an issue for the kick handler -- a kick can be a result of e.g. nouveau_bo_wait or explicit kick, or it can be due to lack of space in the pushbuf. We want the emit to happen in the current batch, so we want there to always be enough space. However an explicit kick could take the reserved space for the implicitly-triggered kick's fence emission if it happened right after. With the new mechanism, hopefully there's no way to cause two fences to be emitted into the same reserved space.

Fixes 47d11990b (nouveau: make sure there's always room to emit a fence)
---
  src/gallium/drivers/nouveau/nouveau_fence.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
src/gallium/drivers/nouveau/nouveau_fence.c +3 -2
index ee4e08d..18b1592 100644
@@ -190,8 +190,10 @@ nouveau_fence_wait(struct nouveau_fence *fence)
     /* wtf, someone is waiting on a fence in flush_notify handler? */
     assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
 
-   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED)
+   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED) {
+      PUSH_SPACE(screen->pushbuf, 8);
        nouveau_fence_emit(fence);
+   }
 
     if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
        if (nouveau_pushbuf_kick(screen->pushbuf, screen->pushbuf->channel))
@@ -224,8 +226,12 @@ nouveau_fence_wait(struct nouveau_fence *fence)
  void
  nouveau_fence_next(struct nouveau_screen *screen)
  {
-   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING)

src/gallium/drivers/nouveau/nouveau_fence.c nouveau_fence_wait(struct nouveau_fence *fence) · line 237

Quoted 10 lines
src/gallium/drivers/nouveau/nouveau_fence.c +6 -1
-      nouveau_fence_emit(screen->fence.current);
+   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING) {
+      if (screen->fence.current->ref > 1)
+         nouveau_fence_emit(screen->fence.current);
+      else
+         return;
+   }
 
     nouveau_fence_ref(NULL, &screen->fence.current);
 

_______________________________________________
mesa-dev mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 1 line · Samuel Pitoiset

Does this fix those texelFetch piglit tests ? Or is it the second patch ?

This patch "fixes" the initial texelFetch piglit failures. However it creates some fresh texelFetch piglit failures -- that test is interesting because it does a lot of draws with minimal state changes between them. Those ones are fixed by the second patch. But really these are all different problems, which interact with each other in frustrating ways.

Quoted 50 lines

Anyway, this patch is :

Quoted 43 lines · Ilia Mirkin

Right now we emit on every kick, but this is only necessary if something will ever be able to observe that the fence completed. If there are no refs, leave the fence alone and emit it another day.

This also happens to work around an issue for the kick handler -- a kick can be a result of e.g. nouveau_bo_wait or explicit kick, or it can be due to lack of space in the pushbuf. We want the emit to happen in the current batch, so we want there to always be enough space. However an explicit kick could take the reserved space for the implicitly-triggered kick's fence emission if it happened right after. With the new mechanism, hopefully there's no way to cause two fences to be emitted into the same reserved space.

Fixes 47d11990b (nouveau: make sure there's always room to emit a fence)
---
  src/gallium/drivers/nouveau/nouveau_fence.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
src/gallium/drivers/nouveau/nouveau_fence.c +3 -2
index ee4e08d..18b1592 100644
@@ -190,8 +190,10 @@ nouveau_fence_wait(struct nouveau_fence *fence)
     /* wtf, someone is waiting on a fence in flush_notify handler? */
     assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
  -   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED)
+   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED) {
+      PUSH_SPACE(screen->pushbuf, 8);
        nouveau_fence_emit(fence);
+   }
       if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
        if (nouveau_pushbuf_kick(screen->pushbuf,
 screen->pushbuf->channel))
@@ -224,8 +226,12 @@ nouveau_fence_wait(struct nouveau_fence *fence)
  void
  nouveau_fence_next(struct nouveau_screen *screen)
  {
-   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING)
-      nouveau_fence_emit(screen->fence.current);
Quoted 10 lines

src/gallium/drivers/nouveau/nouveau_fence.c nouveau_fence_wait(struct nouveau_fence *fence) · line 237

Quoted 8 lines
src/gallium/drivers/nouveau/nouveau_fence.c +6 -0
+   if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING) {
+      if (screen->fence.current->ref > 1)
+         nouveau_fence_emit(screen->fence.current);
+      else
+         return;
+   }
       nouveau_fence_ref(NULL, &screen->fence.current);
 

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau