Mesa (master): i965: Work around incorrect usage of glDrawRangeElements in UE4

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 9 15:34:33 UTC 2020


Module: Mesa
Branch: master
Commit: a751051248d445c3d726a3eab8fc999b0876364e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a751051248d445c3d726a3eab8fc999b0876364e

Author: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Date:   Mon May 25 19:07:08 2020 +0300

i965: Work around incorrect usage of glDrawRangeElements in UE4

Unreal Engine 4 has a bug in usage of glDrawRangeElements,
causing it to be called with a number of vertices in place
of "end" parameter (which specifies the maximum array index
contained in indices).

Since there is unknown amount of games affected and we
could not identify that a game is built with UE4 - we are
forced to make a blanket workaround, disregarding max_index
in range calculations. Fortunately all such calls look like:
  glDrawRangeElements(GL_TRIANGLES, 0, 3, 3, ...);
So we are able to narrow down this workaround.

This was uncovered after b684030c3a656ffdbc93581856034e0982db46fd
broke a bunch of UE4 games.

Cc: 20.1 <mesa-stable at lists.freedesktop.org>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2917
Signed-off-by: Danylo Piliaiev <danylo.piliaiev at globallogic.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5203>

---

 src/mesa/drivers/dri/i965/brw_draw_upload.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c
index ca51f88da15..cb307301abc 100644
--- a/src/mesa/drivers/dri/i965/brw_draw_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c
@@ -549,6 +549,26 @@ brw_prepare_vertices(struct brw_context *brw)
             start = vertex_range_start + stride * min_index;
             range = (stride * (max_index - min_index) +
                      vertex_size);
+
+            /**
+             * Unreal Engine 4 has a bug in usage of glDrawRangeElements,
+             * causing it to be called with a number of vertices in place
+             * of "end" parameter (which specifies the maximum array index
+             * contained in indices).
+             *
+             * Since there is unknown amount of games affected and we
+             * could not identify that a game is built with UE4 - we are
+             * forced to make a blanket workaround, disregarding max_index
+             * in range calculations. Fortunately all such calls look like:
+             *   glDrawRangeElements(GL_TRIANGLES, 0, 3, 3, ...);
+             * So we are able to narrow down this workaround.
+             *
+             * See: https://gitlab.freedesktop.org/mesa/mesa/-/issues/2917
+             */
+            if (unlikely(max_index == 3 && min_index == 0 &&
+                         brw->draw.derived_params.is_indexed_draw)) {
+                  range = intel_buffer->Base.Size - offset - start;
+            }
          }
       }
 



More information about the mesa-commit mailing list