[Mesa-dev] [PATCH] i965: Fix indirect parameters draw during conditional rendering on hsw+

2018-11-15 Thread Illia Iorin
Both extensions GL_ARB_indirect_parameters and GL_NV_conditional_render
use MI_PREDICATE for their work so when conditional rendering was enabled
GL_ARB_indirect_parameters incorrectly handled already present predicate
result and didn't restore it in the end.

Instead special code path for this case was added.

for each draw call mi_math is used to compute mi_predicate_result as:
( (draw index < draw count) && stored_mi_predicate_result )

After the loop mi_predicate is restored to the original value.

Also the amount of loadings to GPU registers was reduced by moving
loadings which were constant in respect to the draw loop outside of it.

Signed-off-by: Illia Iorin 
Signed-off-by: Danylo Piliaiev 
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=108759
---
I haven’t tested this patch on intel CI.
I going to test this patch when piglit test
is merged https://patchwork.freedesktop.org/patch/262127/

 src/mesa/drivers/dri/i965/brw_draw.c | 108 ++-
 1 file changed, 88 insertions(+), 20 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_draw.c 
b/src/mesa/drivers/dri/i965/brw_draw.c
index 8536c04010..98d9e9c553 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -1030,6 +1030,7 @@ brw_draw_prims(struct gl_context *ctx,
unsigned i;
struct brw_context *brw = brw_context(ctx);
int predicate_state = brw->predicate.state;
+   const struct gen_device_info *devinfo = >screen->devinfo;
struct brw_transform_feedback_object *xfb_obj =
   (struct brw_transform_feedback_object *) gl_xfb_obj;
 
@@ -1072,11 +1073,9 @@ brw_draw_prims(struct gl_context *ctx,
 * to it.
 */
 
-   for (i = 0; i < nr_prims; i++) {
-  /* Implementation of ARB_indirect_parameters via predicates */
-  if (brw->draw.draw_params_count_bo) {
- brw_emit_pipe_control_flush(brw, PIPE_CONTROL_FLUSH_ENABLE);
-
+   if (brw->draw.draw_params_count_bo) {
+  /* Preparing registers for ARB_indirect_parameters  */
+  if (brw->predicate.state != BRW_PREDICATE_STATE_USE_BIT) {
  /* Upload the current draw count from the draw parameters buffer to
   * MI_PREDICATE_SRC0.
   */
@@ -1085,25 +1084,94 @@ brw_draw_prims(struct gl_context *ctx,
brw->draw.draw_params_count_offset);
  /* Zero the top 32-bits of MI_PREDICATE_SRC0 */
  brw_load_register_imm32(brw, MI_PREDICATE_SRC0 + 4, 0);
- /* Upload the id of the current primitive to MI_PREDICATE_SRC1. */
- brw_load_register_imm64(brw, MI_PREDICATE_SRC1, prims[i].draw_id);
-
- BEGIN_BATCH(1);
- if (i == 0 && brw->predicate.state != BRW_PREDICATE_STATE_USE_BIT) {
-OUT_BATCH(GEN7_MI_PREDICATE | MI_PREDICATE_LOADOP_LOADINV |
-  MI_PREDICATE_COMBINEOP_SET |
-  MI_PREDICATE_COMPAREOP_SRCS_EQUAL);
- } else {
-OUT_BATCH(GEN7_MI_PREDICATE |
-  MI_PREDICATE_LOADOP_LOAD | MI_PREDICATE_COMBINEOP_XOR |
-  MI_PREDICATE_COMPAREOP_SRCS_EQUAL);
- }
+  } else if (devinfo->gen >= 8 || devinfo->is_haswell) {
+ /* Upload the current MI_PREDICATE_RESULT buffer to GPR0. */
+ brw_load_register_reg64(brw, MI_PREDICATE_RESULT, HSW_CS_GPR(0));
+ /* Upload the current draw count from the draw parameters buffer to
+  * GPR1.
+  */
+ brw_load_register_mem(brw, HSW_CS_GPR(1),
+   brw->draw.draw_params_count_bo,
+   brw->draw.draw_params_count_offset);
+
+ /* Zero the top 32-bits of GPR1 */
+ brw_load_register_imm32(brw, HSW_CS_GPR(1) + 4, 0);
+  } else {
+ /* TODO
+  * Implement slow code path  on pre hsw:
+  * read value from count buffer.
+  */
+ _mesa_warning(ctx, "Usage of GL_ARB_indirect_parameters " 
+"functions during GL_NV_conditional_render "
+"unsupported on pre hsw platform");
+ brw_finish_drawing(ctx);
+ brw->predicate.state = predicate_state;
+ return;
+  }
+   }
+
+   if (brw->draw.draw_params_count_bo &&
+   (brw->predicate.state == BRW_PREDICATE_STATE_USE_BIT) &&
+   (devinfo->gen >= 8 || devinfo->is_haswell)) {
+  for (i = 0; i < nr_prims; i++) {
+
+ static const uint32_t maths[] = {
+/* Compute (draw index < draw count).
+ * We do this by subtracting and storing the carry bit.
+ */ 
+MI_MATH_ALU2(LOAD, SRCA, R2),
+MI_MATH_ALU2(LOAD, SRCB, R1),
+MI_MATH_ALU0(SUB),
+MI_MATH_ALU2(STORE, R3, CF),
+/* Compute (subtracting result & MI_PREDICAT). */ 
+MI_MATH_ALU2(LOAD, SRCA, R3),
+MI_MATH_ALU2(LOAD, SRCB, 

[Mesa-dev] [PATCH] mesa: Fix pack_uint_Z_FLOAT32()

2018-10-11 Thread Illia Iorin
Fixed pack_uint_Z_FLOAT32 by casting row data to float instead uint.
Remove code duplicate function pack_uint_Z_FLOAT32_X24S8.
Edited case in "_mesa_get_pack_uint_z_func".
Now it looks like "_mesa_get_pack_float_z_func".
Remove _mesa_problem call, which was added for debuging this issue.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91433
Signed-off-by: Illia Iorin 
---
 src/mesa/main/format_pack.py | 21 +
 src/mesa/swrast/s_depth.c|  6 --
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 0b9e0d424d..9fa4f412d4 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -510,6 +510,10 @@ pack_float_Z_UNORM32(const GLfloat *src, void *dst)
*d = (GLuint) (*src * scale);
 }
 
+/**
+ ** Pack float to Z_FLOAT32 or Z_FLOAT32_X24S8.
+ **/
+
 static void
 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
 {
@@ -582,18 +586,12 @@ pack_uint_Z_UNORM32(const GLuint *src, void *dst)
*d = *src;
 }
 
-static void
-pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
-{
-   GLuint *d = ((GLuint *) dst);
-   const GLdouble scale = 1.0 / (GLdouble) 0x;
-   *d = (GLuint) (*src * scale);
-   assert(*d >= 0.0f);
-   assert(*d <= 1.0f);
-}
+/**
+ ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8.
+ **/
 
 static void
-pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
+pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
 {
GLfloat *d = ((GLfloat *) dst);
const GLdouble scale = 1.0 / (GLdouble) 0x;
@@ -617,9 +615,8 @@ _mesa_get_pack_uint_z_func(mesa_format format)
case MESA_FORMAT_Z_UNORM32:
   return pack_uint_Z_UNORM32;
case MESA_FORMAT_Z_FLOAT32:
-  return pack_uint_Z_FLOAT32;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-  return pack_uint_Z_FLOAT32_X24S8;
+  return pack_uint_Z_FLOAT32;
default:
   _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
   return NULL;
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 4b9640d319..de7f14a4fc 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -310,12 +310,6 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan 
*span)
   zBufferVals = zStart;
}
else {
-  if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_NORMALIZED) {
- _mesa_problem(ctx, "Incorrectly writing swrast's integer depth "
-   "values to %s depth buffer",
-   _mesa_get_format_name(rb->Format));
-  }
-
   /* copy Z buffer values into temp buffer (32-bit Z values) */
   zBufferTemp = malloc(count * sizeof(GLuint));
   if (!zBufferTemp)
-- 
2.17.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH v3] mesa/format_pack: Fix pack_uint_Z_FLOAT32()

2018-10-01 Thread Illia Iorin
Fixed pack_uint_Z_FLOAT32 by casting row data to float instead uint.
Remove code duplicate function pack_uint_Z_FLOAT32_X24S8.
Edited case in "_mesa_get_pack_uint_z_func".
Now it looks like "_mesa_get_pack_float_z_func".
v2: by Nanley Chery
-add coments
-remove _mesa_problem call, which was added for debuging this issue

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91433
Signed-off-by: Illia Iorin 
---
 src/mesa/main/format_pack.py | 21 +
 src/mesa/swrast/s_depth.c|  6 --
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 0b9e0d424d..9f97c09ccc 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -510,6 +510,10 @@ pack_float_Z_UNORM32(const GLfloat *src, void *dst)
*d = (GLuint) (*src * scale);
 }
 
+/**
+ ** Pack Z_FLOAT32 and Z_FLOAT32_X24S8 to float.
+ **/
+
 static void
 pack_float_Z_FLOAT32(const GLfloat *src, void *dst)
 {
@@ -582,18 +586,12 @@ pack_uint_Z_UNORM32(const GLuint *src, void *dst)
*d = *src;
 }
 
-static void
-pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
-{
-   GLuint *d = ((GLuint *) dst);
-   const GLdouble scale = 1.0 / (GLdouble) 0x;
-   *d = (GLuint) (*src * scale);
-   assert(*d >= 0.0f);
-   assert(*d <= 1.0f);
-}
+/**
+ ** Pack Z_FLOAT32 and Z_FLOAT32_X24S8 to uint.
+ **/
 
 static void
-pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
+pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
 {
GLfloat *d = ((GLfloat *) dst);
const GLdouble scale = 1.0 / (GLdouble) 0x;
@@ -617,9 +615,8 @@ _mesa_get_pack_uint_z_func(mesa_format format)
case MESA_FORMAT_Z_UNORM32:
   return pack_uint_Z_UNORM32;
case MESA_FORMAT_Z_FLOAT32:
-  return pack_uint_Z_FLOAT32;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-  return pack_uint_Z_FLOAT32_X24S8;
+  return pack_uint_Z_FLOAT32;
default:
   _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
   return NULL;
diff --git a/src/mesa/swrast/s_depth.c b/src/mesa/swrast/s_depth.c
index 4b9640d319..de7f14a4fc 100644
--- a/src/mesa/swrast/s_depth.c
+++ b/src/mesa/swrast/s_depth.c
@@ -310,12 +310,6 @@ _swrast_depth_test_span(struct gl_context *ctx, SWspan 
*span)
   zBufferVals = zStart;
}
else {
-  if (_mesa_get_format_datatype(rb->Format) != GL_UNSIGNED_NORMALIZED) {
- _mesa_problem(ctx, "Incorrectly writing swrast's integer depth "
-   "values to %s depth buffer",
-   _mesa_get_format_name(rb->Format));
-  }
-
   /* copy Z buffer values into temp buffer (32-bit Z values) */
   zBufferTemp = malloc(count * sizeof(GLuint));
   if (!zBufferTemp)
-- 
2.17.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa/format_pack: Fix pack_uint_Z_FLOAT32()

2018-09-13 Thread Illia Iorin
Fixed pack_uint_Z_FLOAT32 by casting row data to float instead uint.
Remove code duplicate function pack_uint_Z_FLOAT32_X24S8.
Edited case in "_mesa_get_pack_uint_z_func".
Now it looks like "_mesa_get_pack_float_z_func".

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91433
Signed-off-by: Illia Iorin 
---
 src/mesa/main/format_pack.py | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 0b9e0d424d..5cf49909b5 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -584,16 +584,6 @@ pack_uint_Z_UNORM32(const GLuint *src, void *dst)
 
 static void
 pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
-{
-   GLuint *d = ((GLuint *) dst);
-   const GLdouble scale = 1.0 / (GLdouble) 0x;
-   *d = (GLuint) (*src * scale);
-   assert(*d >= 0.0f);
-   assert(*d <= 1.0f);
-}
-
-static void
-pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
 {
GLfloat *d = ((GLfloat *) dst);
const GLdouble scale = 1.0 / (GLdouble) 0x;
@@ -617,9 +607,8 @@ _mesa_get_pack_uint_z_func(mesa_format format)
case MESA_FORMAT_Z_UNORM32:
   return pack_uint_Z_UNORM32;
case MESA_FORMAT_Z_FLOAT32:
-  return pack_uint_Z_FLOAT32;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-  return pack_uint_Z_FLOAT32_X24S8;
+  return pack_uint_Z_FLOAT32;
default:
   _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
   return NULL;

Previous version of patch was sent accidentally. This is correct one
-- 
2.17.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH] mesa/format_pack: Fix pack_uint_Z_FLOAT32()

2018-09-13 Thread Illia Iorin
Fixed pack_uint_Z_FLOAT32 by casting row data to float instead uint.
Remove code duplicate function pack_uint_Z_FLOAT32_X24S8.
Edited case in "_mesa_get_pack_uint_z_func".
Now it looks like "_mesa_get_pack_float_z_func".

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91433
Signed-off-by: Illia Iorin 
---
 src/mesa/main/format_pack.py | 13 +
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/src/mesa/main/format_pack.py b/src/mesa/main/format_pack.py
index 0b9e0d424d..a1774212c4 100644
--- a/src/mesa/main/format_pack.py
+++ b/src/mesa/main/format_pack.py
@@ -592,16 +592,6 @@ pack_uint_Z_FLOAT32(const GLuint *src, void *dst)
assert(*d <= 1.0f);
 }
 
-static void
-pack_uint_Z_FLOAT32_X24S8(const GLuint *src, void *dst)
-{
-   GLfloat *d = ((GLfloat *) dst);
-   const GLdouble scale = 1.0 / (GLdouble) 0x;
-   *d = (GLfloat) (*src * scale);
-   assert(*d >= 0.0f);
-   assert(*d <= 1.0f);
-}
-
 gl_pack_uint_z_func
 _mesa_get_pack_uint_z_func(mesa_format format)
 {
@@ -617,9 +607,8 @@ _mesa_get_pack_uint_z_func(mesa_format format)
case MESA_FORMAT_Z_UNORM32:
   return pack_uint_Z_UNORM32;
case MESA_FORMAT_Z_FLOAT32:
-  return pack_uint_Z_FLOAT32;
case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
-  return pack_uint_Z_FLOAT32_X24S8;
+  return pack_uint_Z_FLOAT32;
default:
   _mesa_problem(NULL, "unexpected format in _mesa_get_pack_uint_z_func()");
   return NULL;
-- 
2.17.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev