radeonsi: fix divide by zero in si_get_small_prim_cull_info()
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 13 Dec 2023 05:48:01 +0000 (16:48 +1100)
committerEric Engestrom <eric@engestrom.ch>
Sun, 17 Dec 2023 23:48:00 +0000 (23:48 +0000)
This fixes a crash on startup with the game
"Ty the Tasmanian Tiger 3"

Fixes: f8a0aa685275 ("radeonsi: fix view culling for wide lines")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26661>
(cherry picked from commit bed1b8b90d844d8bf36d3d1aa7c3f83e086d9cf6)

.pick_status.json
src/gallium/drivers/radeonsi/si_state_viewport.c

index 75d0378..3fa1905 100644 (file)
         "description": "radeonsi: fix divide by zero in si_get_small_prim_cull_info()",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "main_sha": null,
         "because_sha": "f8a0aa6852756d8f1593ef6627ddb1754ae967be",
         "notes": null
index c32584b..8260204 100644 (file)
@@ -33,8 +33,14 @@ static void si_get_small_prim_cull_info(struct si_context *sctx, struct si_small
       line_width = roundf(line_width);
    line_width = MAX2(line_width, 1);
 
-   info.clip_half_line_width[0] = line_width * 0.5 / fabs(info.scale[0]);
-   info.clip_half_line_width[1] = line_width * 0.5 / fabs(info.scale[1]);
+   float half_line_width = line_width * 0.5;
+   if (info.scale[0] == 0 || info.scale[1] == 0) {
+     info.clip_half_line_width[0] = 0;
+     info.clip_half_line_width[1] = 0;
+   } else {
+     info.clip_half_line_width[0] = half_line_width / fabs(info.scale[0]);
+     info.clip_half_line_width[1] = half_line_width / fabs(info.scale[1]);
+   }
 
    /* If the Y axis is inverted (OpenGL default framebuffer), reverse it.
     * This is because the viewport transformation inverts the clip space