Mesa (master): glsl: shader outputs cannot have initializers

2015-10-11 Thread Iago Toral Quiroga
Module: Mesa
Branch: master
Commit: f09c229cc6db838ae595fb57f5e6386a035bdf42
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f09c229cc6db838ae595fb57f5e6386a035bdf42

Author: Iago Toral Quiroga 
Date:   Wed Oct  7 09:21:36 2015 +0200

glsl: shader outputs cannot have initializers

GLSL Spec 4.20.8, 4.3 Storage Qualifiers:

"Initializers in global declarations may only be used in declarations of
 global variables with no storage qualifier, with a const qualifier or
 with a uniform qualifier."

We do this for input variables, but not for output variables. AMD and NVIDIA
proprietary drivers don't allow this either.

Reviewed-by: Samuel Iglesias Gonsálvez 
Reviewed-by: Matt Turner 

---

 src/glsl/ast_to_hir.cpp |6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 9511440..2aea5ae 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3201,6 +3201,12 @@ process_initializer(ir_variable *var, ast_declaration 
*decl,
   ? "attribute" : "varying");
}
 
+   if (var->data.mode == ir_var_shader_out && state->current_function == NULL) 
{
+  _mesa_glsl_error(&initializer_loc, state,
+   "cannot initialize %s shader output",
+   _mesa_shader_stage_to_string(state->stage));
+   }
+
/* If the initializer is an ast_aggregate_initializer, recursively store
 * type information from the LHS into it, so that its hir() function can do
 * type checking.

___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit


Mesa (master): i965: Fix unsafe pointer when dumping VS/FS IR

2015-10-11 Thread Iago Toral Quiroga
Module: Mesa
Branch: master
Commit: 8281a7c5333d9b78aabf9ce3e9cc7077ccca9413
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8281a7c5333d9b78aabf9ce3e9cc7077ccca9413

Author: Iago Toral Quiroga 
Date:   Fri Oct  9 07:57:19 2015 +0200

i965: Fix unsafe pointer when dumping VS/FS IR

For the VS and FS stages that use ARB_vertex_program or
ARB_fragment_program we don't have a shader program, however,
when debuging is enabled, we call brw_dump_ir like this:

brw_dump_ir("vertex", prog, &vs->base, &vp->program.Base);

where vs will be NULL (since prog is NULL).

As pointed out by Chris, this &vs->base is not really a dereference,
it simply computes a new address that just happens to be 0x0 because
the offset of base in brw_shader is 0. Then brw_dump_ir will see a
NULL pointer and not do anything. This is why this does not crash at
the moment. However, this does not look very safe (it would crash
for any location of base that is not the first in brw_shader), so
patch it to prevent a potential (even if unlikely) problem in the
future.

Reviewed-by: Topi Pohjolainen 

---

 src/mesa/drivers/dri/i965/brw_vs.c |2 +-
 src/mesa/drivers/dri/i965/brw_wm.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vs.c 
b/src/mesa/drivers/dri/i965/brw_vs.c
index 0dc2bdc..de9a867 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -205,7 +205,7 @@ brw_codegen_vs_prog(struct brw_context *brw,
}
 
if (unlikely(INTEL_DEBUG & DEBUG_VS))
-  brw_dump_ir("vertex", prog, &vs->base, &vp->program.Base);
+  brw_dump_ir("vertex", prog, vs ? &vs->base : NULL, &vp->program.Base);
 
int st_index = -1;
if (INTEL_DEBUG & DEBUG_SHADER_TIME)
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c 
b/src/mesa/drivers/dri/i965/brw_wm.c
index 4d5e7f6..65de543 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -222,7 +222,7 @@ brw_codegen_wm_prog(struct brw_context *brw,
}
 
if (unlikely(INTEL_DEBUG & DEBUG_WM))
-  brw_dump_ir("fragment", prog, &fs->base, &fp->program.Base);
+  brw_dump_ir("fragment", prog, fs ? &fs->base : NULL, &fp->program.Base);
 
int st_index8 = -1, st_index16 = -1;
if (INTEL_DEBUG & DEBUG_SHADER_TIME) {

___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit


Mesa (master): glsl: include variable name in error messages about initializers

2015-10-11 Thread Iago Toral Quiroga
Module: Mesa
Branch: master
Commit: 7a1143f29e477601f2b34b23d154edd5699352b1
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=7a1143f29e477601f2b34b23d154edd5699352b1

Author: Iago Toral Quiroga 
Date:   Wed Oct  7 09:28:43 2015 +0200

glsl: include variable name in error messages about initializers

Also fix style / wrong indentation along the way and make the messages
more uniform.

Reviewed-by: Samuel Iglesias Gonsálvez 
Reviewed-by: Matt Turner 

---

 src/glsl/ast_to_hir.cpp |   29 +
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 2aea5ae..fdded1e 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3170,7 +3170,8 @@ process_initializer(ir_variable *var, ast_declaration 
*decl,
 */
if (var->data.mode == ir_var_uniform) {
   state->check_version(120, 0, &initializer_loc,
-   "cannot initialize uniforms");
+   "cannot initialize uniform %s",
+   var->name);
}
 
/* Section 4.3.7 "Buffer Variables" of the GLSL 4.30 spec:
@@ -3178,8 +3179,9 @@ process_initializer(ir_variable *var, ast_declaration 
*decl,
 *"Buffer variables cannot have initializers."
 */
if (var->data.mode == ir_var_shader_storage) {
-  _mesa_glsl_error(& initializer_loc, state,
-   "SSBO variables cannot have initializers");
+  _mesa_glsl_error(&initializer_loc, state,
+   "cannot initialize buffer variable %s",
+   var->name);
}
 
/* From section 4.1.7 of the GLSL 4.40 spec:
@@ -3189,22 +3191,25 @@ process_initializer(ir_variable *var, ast_declaration 
*decl,
 * shader."
 */
if (var->type->contains_opaque()) {
-  _mesa_glsl_error(& initializer_loc, state,
-   "cannot initialize opaque variable");
+  _mesa_glsl_error(&initializer_loc, state,
+   "cannot initialize opaque variable %s",
+   var->name);
}
 
if ((var->data.mode == ir_var_shader_in) && (state->current_function == 
NULL)) {
-  _mesa_glsl_error(& initializer_loc, state,
-  "cannot initialize %s shader input / %s",
-  _mesa_shader_stage_to_string(state->stage),
-  (state->stage == MESA_SHADER_VERTEX)
-  ? "attribute" : "varying");
+  _mesa_glsl_error(&initializer_loc, state,
+   "cannot initialize %s shader input / %s %s",
+   _mesa_shader_stage_to_string(state->stage),
+   (state->stage == MESA_SHADER_VERTEX)
+   ? "attribute" : "varying",
+   var->name);
}
 
if (var->data.mode == ir_var_shader_out && state->current_function == NULL) 
{
   _mesa_glsl_error(&initializer_loc, state,
-   "cannot initialize %s shader output",
-   _mesa_shader_stage_to_string(state->stage));
+   "cannot initialize %s shader output %s",
+   _mesa_shader_stage_to_string(state->stage),
+   var->name);
}
 
/* If the initializer is an ast_aggregate_initializer, recursively store

___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit


Mesa (master): mesa/uniforms: fix get_uniform for doubles (v2)

2015-10-11 Thread Dave Airlie
Module: Mesa
Branch: master
Commit: bcfaab38858fdcfbd8ffeaf6b0e3da8a726f02e6
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=bcfaab38858fdcfbd8ffeaf6b0e3da8a726f02e6

Author: Dave Airlie 
Date:   Wed Sep 30 17:48:38 2015 +1000

mesa/uniforms: fix get_uniform for doubles (v2)

The initial glGetUniformdv support didn't cover all the
casting cases that are apparantly legal, and cts seems to
test for them.

I've updated the piglit test to cover these cases now.

v2: fix indentation - it's all broken in this file (Ilia)
fix src/dst index tracking in light of fp64 support (Ilia)

cc: "11.0" 
Reviewed-by: Ilia Mirkin 
Signed-off-by: Dave Airlie 

---

 src/mesa/main/uniform_query.cpp |   53 +++
 1 file changed, 37 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index d487297..083087d 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -318,19 +318,12 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
 
   return;
}
-   if ((uni->type->base_type == GLSL_TYPE_DOUBLE &&
-returnType != GLSL_TYPE_DOUBLE) ||
-   (uni->type->base_type != GLSL_TYPE_DOUBLE &&
-returnType == GLSL_TYPE_DOUBLE)) {
-_mesa_error( ctx, GL_INVALID_OPERATION,
-"glGetnUniform*vARB(incompatible uniform types)");
-   return;
-   }
 
{
   unsigned elements = (uni->type->is_sampler())
 ? 1 : uni->type->components();
   const int dmul = uni->type->base_type == GLSL_TYPE_DOUBLE ? 2 : 1;
+  const int rmul = returnType == GLSL_TYPE_DOUBLE ? 2 : 1;
 
   /* Calculate the source base address *BEFORE* modifying elements to
* account for the size of the user's buffer.
@@ -342,7 +335,7 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
  returnType == GLSL_TYPE_UINT || returnType == GLSL_TYPE_DOUBLE);
 
   /* doubles have a different size than the other 3 types */
-  unsigned bytes = sizeof(src[0]) * elements * dmul;
+  unsigned bytes = sizeof(src[0]) * elements * rmul;
   if (bufSize < 0 || bytes > (unsigned) bufSize) {
 _mesa_error( ctx, GL_INVALID_OPERATION,
 "glGetnUniform*vARB(out of bounds: bufSize is %d,"
@@ -366,32 +359,57 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
   } else {
 union gl_constant_value *const dst =
(union gl_constant_value *) paramsOut;
-
 /* This code could be optimized by putting the loop inside the switch
  * statements.  However, this is not expected to be
  * performance-critical code.
  */
 for (unsigned i = 0; i < elements; i++) {
+  int sidx = i * dmul;
+  int didx = i * rmul;
+
switch (returnType) {
case GLSL_TYPE_FLOAT:
   switch (uni->type->base_type) {
   case GLSL_TYPE_UINT:
- dst[i].f = (float) src[i].u;
+ dst[didx].f = (float) src[sidx].u;
  break;
   case GLSL_TYPE_INT:
   case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
- dst[i].f = (float) src[i].i;
+ dst[didx].f = (float) src[sidx].i;
  break;
   case GLSL_TYPE_BOOL:
- dst[i].f = src[i].i ? 1.0f : 0.0f;
+ dst[didx].f = src[sidx].i ? 1.0f : 0.0f;
+ break;
+  case GLSL_TYPE_DOUBLE:
+ dst[didx].f = *(double *)&src[sidx].f;
+ break;
+  default:
+ assert(!"Should not get here.");
+ break;
+  }
+  break;
+   case GLSL_TYPE_DOUBLE:
+  switch (uni->type->base_type) {
+  case GLSL_TYPE_UINT:
+ *(double *)&dst[didx].f = (double) src[sidx].u;
+ break;
+  case GLSL_TYPE_INT:
+  case GLSL_TYPE_SAMPLER:
+  case GLSL_TYPE_IMAGE:
+ *(double *)&dst[didx].f = (double) src[sidx].i;
+ break;
+  case GLSL_TYPE_BOOL:
+ *(double *)&dst[didx].f = src[sidx].i ? 1.0f : 0.0f;
+ break;
+  case GLSL_TYPE_FLOAT:
+ *(double *)&dst[didx].f = (double) src[sidx].f;
  break;
   default:
  assert(!"Should not get here.");
  break;
   }
   break;
-
case GLSL_TYPE_INT:
case GLSL_TYPE_UINT:
   switch (uni->type->base_type) {
@@ -413,10 +431,13 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, 
GLint location,
   *  a floating-point value is rounded to the
   *  nearest integer..."
   */
- dst[i].i = IROUND(

Mesa (master): ilo: improve Gen8 defines based on its PRMs

2015-10-11 Thread Chia-I Wu
Module: Mesa
Branch: master
Commit: c8083b1adc79073c0d6fc3bb87d6a18e41c779c4
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c8083b1adc79073c0d6fc3bb87d6a18e41c779c4

Author: Chia-I Wu 
Date:   Thu Oct  8 16:51:50 2015 +0800

ilo: improve Gen8 defines based on its PRMs

---

 src/gallium/drivers/ilo/core/ilo_state_cc.c|   12 +-
 src/gallium/drivers/ilo/core/ilo_state_raster.c|   14 +-
 src/gallium/drivers/ilo/core/ilo_state_sbe.c   |   12 +-
 src/gallium/drivers/ilo/core/ilo_state_surface.c   |4 -
 src/gallium/drivers/ilo/core/ilo_state_vf.c|8 +-
 src/gallium/drivers/ilo/genhw/gen_eu_message.xml.h |3 +
 src/gallium/drivers/ilo/genhw/gen_mi.xml.h |   96 ++-
 src/gallium/drivers/ilo/genhw/gen_regs.xml.h   |   17 +-
 src/gallium/drivers/ilo/genhw/gen_render.xml.h |   16 ++
 src/gallium/drivers/ilo/genhw/gen_render_3d.xml.h  |  278 +++-
 .../drivers/ilo/genhw/gen_render_dynamic.xml.h |   18 +-
 .../drivers/ilo/genhw/gen_render_media.xml.h   |6 +-
 .../drivers/ilo/genhw/gen_render_surface.xml.h |   36 ++-
 13 files changed, 399 insertions(+), 121 deletions(-)

Diff:   
http://cgit.freedesktop.org/mesa/mesa/diff/?id=c8083b1adc79073c0d6fc3bb87d6a18e41c779c4
___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit


Mesa (master): i965/vec4: Implement b2f and b2i using negation.

2015-10-11 Thread Matt Turner
Module: Mesa
Branch: master
Commit: 4642d53a03122e6d3214ed12cb327898917eb84e
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4642d53a03122e6d3214ed12cb327898917eb84e

Author: Matt Turner 
Date:   Fri Oct  9 12:27:04 2015 -0700

i965/vec4: Implement b2f and b2i using negation.

Curro added this in commit 3ee2daf23d (before the vec4/NIR backend was
added) but it was missed in the new NIR backend. Add it there as well.

instructions in affected programs: 1857 -> 1810 (-2.53%)
helped:15

Reviewed-by: Francisco Jerez 

---

 src/mesa/drivers/dri/i965/brw_vec4_nir.cpp |8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp 
b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
index 41bd80d..fdf767d 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
@@ -1237,14 +1237,8 @@ vec4_visitor::nir_emit_alu(nir_alu_instr *instr)
   break;
 
case nir_op_b2i:
-  emit(AND(dst, op[0], src_reg(1)));
-  break;
-
case nir_op_b2f:
-  op[0].type = BRW_REGISTER_TYPE_D;
-  dst.type = BRW_REGISTER_TYPE_D;
-  emit(AND(dst, op[0], src_reg(0x3f80u)));
-  dst.type = BRW_REGISTER_TYPE_F;
+  emit(MOV(dst, negate(op[0])));
   break;
 
case nir_op_f2b:

___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit


Mesa (master): nv50, nvc0: don't base decisions on available pushbuf space

2015-10-11 Thread Ilia Mirkin
Module: Mesa
Branch: master
Commit: 9fe458335ffd35366ef0f4b741aad0cdb3503783
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9fe458335ffd35366ef0f4b741aad0cdb3503783

Author: Ilia Mirkin 
Date:   Sat Oct 10 04:29:39 2015 -0400

nv50,nvc0: don't base decisions on available pushbuf space

We still have to push everything out, might as well kick earlier and
flip pushbufs when we know we'll need it. This resolves some issues with
the new policy of making sure that we always leave a bit of room at the
end for fences.

Signed-off-by: Ilia Mirkin 
Reviewed-by: Samuel Pitoiset 
Fixes: 47d11990b (nouveau: make sure there's always room to emit a fence)
Cc: mesa-sta...@lists.freedesktop.org

---

 .../drivers/nouveau/nv50/nv50_shader_state.c   |9 ++---
 src/gallium/drivers/nouveau/nv50/nv50_transfer.c   |   16 +++-
 src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c   |   20 +---
 3 files changed, 10 insertions(+), 35 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c 
b/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c
index fdde11f..941555f 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c
@@ -65,14 +65,9 @@ nv50_constbufs_validate(struct nv50_context *nv50)
PUSH_DATA (push, (b << 12) | (i << 8) | p | 1);
 }
 while (words) {
-   unsigned nr;
-
-   if (!PUSH_SPACE(push, 16))
-  break;
-   nr = PUSH_AVAIL(push);
-   assert(nr >= 16);
-   nr = MIN2(MIN2(nr - 3, words), NV04_PFIFO_MAX_PACKET_LEN);
+   unsigned nr = MIN2(words, NV04_PFIFO_MAX_PACKET_LEN);
 
+   PUSH_SPACE(push, nr + 3);
BEGIN_NV04(push, NV50_3D(CB_ADDR), 1);
PUSH_DATA (push, (start << 8) | b);
BEGIN_NI04(push, NV50_3D(CB_DATA(0)), nr);
diff --git a/src/gallium/drivers/nouveau/nv50/nv50_transfer.c 
b/src/gallium/drivers/nouveau/nv50/nv50_transfer.c
index be51407..9a3fd1e 100644
--- a/src/gallium/drivers/nouveau/nv50/nv50_transfer.c
+++ b/src/gallium/drivers/nouveau/nv50/nv50_transfer.c
@@ -187,14 +187,7 @@ nv50_sifc_linear_u8(struct nouveau_context *nv,
PUSH_DATA (push, 0);
 
while (count) {
-  unsigned nr;
-
-  if (!PUSH_SPACE(push, 16))
- break;
-  nr = PUSH_AVAIL(push);
-  assert(nr >= 16);
-  nr = MIN2(count, nr - 1);
-  nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN);
+  unsigned nr = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN);
 
   BEGIN_NI04(push, NV50_2D(SIFC_DATA), nr);
   PUSH_DATAp(push, src, nr);
@@ -395,12 +388,9 @@ nv50_cb_push(struct nouveau_context *nv,
nouveau_pushbuf_validate(push);
 
while (words) {
-  unsigned nr;
-
-  nr = PUSH_AVAIL(push);
-  nr = MIN2(nr - 7, words);
-  nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN - 1);
+  unsigned nr = MIN2(words, NV04_PFIFO_MAX_PACKET_LEN);
 
+  PUSH_SPACE(push, nr + 7);
   BEGIN_NV04(push, NV50_3D(CB_DEF_ADDRESS_HIGH), 3);
   PUSH_DATAh(push, bo->offset + base);
   PUSH_DATA (push, bo->offset + base);
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c 
b/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c
index aaec60a..d459dd6 100644
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c
@@ -188,14 +188,10 @@ nvc0_m2mf_push_linear(struct nouveau_context *nv,
nouveau_pushbuf_validate(push);
 
while (count) {
-  unsigned nr;
+  unsigned nr = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN);
 
-  if (!PUSH_SPACE(push, 16))
+  if (!PUSH_SPACE(push, nr + 9))
  break;
-  nr = PUSH_AVAIL(push);
-  assert(nr >= 16);
-  nr = MIN2(count, nr - 9);
-  nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN);
 
   BEGIN_NVC0(push, NVC0_M2MF(OFFSET_OUT_HIGH), 2);
   PUSH_DATAh(push, dst->offset + offset);
@@ -234,14 +230,10 @@ nve4_p2mf_push_linear(struct nouveau_context *nv,
nouveau_pushbuf_validate(push);
 
while (count) {
-  unsigned nr;
+  unsigned nr = MIN2(count, (NV04_PFIFO_MAX_PACKET_LEN - 1));
 
-  if (!PUSH_SPACE(push, 16))
+  if (!PUSH_SPACE(push, nr + 10))
  break;
-  nr = PUSH_AVAIL(push);
-  assert(nr >= 16);
-  nr = MIN2(count, nr - 8);
-  nr = MIN2(nr, (NV04_PFIFO_MAX_PACKET_LEN - 1));
 
   BEGIN_NVC0(push, NVE4_P2MF(UPLOAD_DST_ADDRESS_HIGH), 2);
   PUSH_DATAh(push, dst->offset + offset);
@@ -571,9 +563,7 @@ nvc0_cb_bo_push(struct nouveau_context *nv,
PUSH_DATA (push, bo->offset + base);
 
while (words) {
-  unsigned nr = PUSH_AVAIL(push);
-  nr = MIN2(nr, words);
-  nr = MIN2(nr, NV04_PFIFO_MAX_PACKET_LEN - 1);
+  unsigned nr = MIN2(words, NV04_PFIFO_MAX_PACKET_LEN - 1);
 
   PUSH_SPACE(push, nr + 2);
   PUSH_REFN (push, bo, NOUVEAU_BO_WR | domain);

___
m

Mesa (master): nouveau: avoid emitting new fences unnecessarily

2015-10-11 Thread Ilia Mirkin
Module: Mesa
Branch: master
Commit: 8053c9208f30964d89dc4e262fdf2148f0664696
URL:
http://cgit.freedesktop.org/mesa/mesa/commit/?id=8053c9208f30964d89dc4e262fdf2148f0664696

Author: Ilia Mirkin 
Date:   Sat Oct 10 01:56:09 2015 -0400

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.

Signed-off-by: Ilia Mirkin 
Reviewed-by: Samuel Pitoiset 
Fixes: 47d11990b (nouveau: make sure there's always room to emit a fence)
Cc: mesa-sta...@lists.freedesktop.org

---

 src/gallium/drivers/nouveau/nouveau_fence.c |   12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nouveau_fence.c 
b/src/gallium/drivers/nouveau/nouveau_fence.c
index ee4e08d..18b1592 100644
--- a/src/gallium/drivers/nouveau/nouveau_fence.c
+++ b/src/gallium/drivers/nouveau/nouveau_fence.c
@@ -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);
 

___
mesa-commit mailing list
mesa-commit@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-commit