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:
@@ -588,21 +588,4 @@ draw_clamp_viewport_idx(int idx)
|
|||||||
return ((PIPE_MAX_VIEWPORTS > idx && idx >= 0) ? idx : 0);
|
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 */
|
#endif /* DRAW_PRIVATE_H */
|
||||||
|
@@ -360,13 +360,9 @@ prim_restart_loop(struct draw_context *draw,
|
|||||||
struct pipe_draw_start_count_bias cur = *draw_info;
|
struct pipe_draw_start_count_bias cur = *draw_info;
|
||||||
cur.count = 0;
|
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++) {
|
for (unsigned j = 0; j < draw_info->count; j++) {
|
||||||
unsigned index = 0;
|
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) {
|
if (i < elt_max) {
|
||||||
switch (draw->pt.user.eltSize) {
|
switch (draw->pt.user.eltSize) {
|
||||||
case 1:
|
case 1:
|
||||||
|
@@ -33,9 +33,6 @@
|
|||||||
#define SEGMENT_SIZE 1024
|
#define SEGMENT_SIZE 1024
|
||||||
#define MAP_SIZE 256
|
#define MAP_SIZE 256
|
||||||
|
|
||||||
/* The largest possible index within an index buffer */
|
|
||||||
#define MAX_ELT_IDX 0xffffffff
|
|
||||||
|
|
||||||
struct vsplit_frontend {
|
struct vsplit_frontend {
|
||||||
struct draw_pt_front_end base;
|
struct draw_pt_front_end base;
|
||||||
struct draw_context *draw;
|
struct draw_context *draw;
|
||||||
@@ -116,7 +113,7 @@ vsplit_add_cache(struct vsplit_frontend *vsplit, unsigned fetch)
|
|||||||
static inline unsigned
|
static inline unsigned
|
||||||
vsplit_get_base_idx(unsigned start, unsigned fetch)
|
vsplit_get_base_idx(unsigned start, unsigned fetch)
|
||||||
{
|
{
|
||||||
return draw_overflow_uadd(start, fetch, MAX_ELT_IDX);
|
return util_clamped_uadd(start, fetch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -809,6 +809,20 @@ util_quantize_lod_bias(float lod)
|
|||||||
return roundf(lod * 256) / 256;
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user