draw,util: Refactor draw_overflow_uadd into util.

So it can be used outside draw.  Also drop  the overflow_value parameter,
as it wasn't meaningfully useful.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19683>
This commit is contained in:
Jose Fonseca
2022-11-11 15:55:11 +00:00
committed by Marge Bot
parent cb904ceb80
commit f47253c5c7
4 changed files with 16 additions and 26 deletions

View File

@@ -588,21 +588,4 @@ draw_clamp_viewport_idx(int idx)
return ((PIPE_MAX_VIEWPORTS > idx && idx >= 0) ? idx : 0);
}
/**
* Adds two unsigned integers and if the addition
* overflows then it returns the value from
* the overflow_value variable.
*/
static inline unsigned
draw_overflow_uadd(unsigned a, unsigned b,
unsigned overflow_value)
{
unsigned res = a + b;
if (res < a) {
res = overflow_value;
}
return res;
}
#endif /* DRAW_PRIVATE_H */

View File

@@ -360,13 +360,9 @@ prim_restart_loop(struct draw_context *draw,
struct pipe_draw_start_count_bias cur = *draw_info;
cur.count = 0;
/* The largest index within a loop using the i variable as the index.
* Used for overflow detection */
const unsigned MAX_LOOP_IDX = 0xffffffff;
for (unsigned j = 0; j < draw_info->count; j++) {
unsigned index = 0;
unsigned i = draw_overflow_uadd(draw_info->start, j, MAX_LOOP_IDX);
unsigned i = util_clamped_uadd(draw_info->start, j);
if (i < elt_max) {
switch (draw->pt.user.eltSize) {
case 1:

View File

@@ -33,9 +33,6 @@
#define SEGMENT_SIZE 1024
#define MAP_SIZE 256
/* The largest possible index within an index buffer */
#define MAX_ELT_IDX 0xffffffff
struct vsplit_frontend {
struct draw_pt_front_end base;
struct draw_context *draw;
@@ -116,7 +113,7 @@ vsplit_add_cache(struct vsplit_frontend *vsplit, unsigned fetch)
static inline unsigned
vsplit_get_base_idx(unsigned start, unsigned fetch)
{
return draw_overflow_uadd(start, fetch, MAX_ELT_IDX);
return util_clamped_uadd(start, fetch);
}

View File

@@ -809,6 +809,20 @@ util_quantize_lod_bias(float lod)
return roundf(lod * 256) / 256;
}
/**
* Adds two unsigned integers and if the addition
* overflows then clamp it to ~0U.
*/
static inline unsigned
util_clamped_uadd(unsigned a, unsigned b)
{
unsigned res = a + b;
if (res < a) {
res = ~0U;
}
return res;
}
#ifdef __cplusplus
}
#endif