From c8c2c30f5d14ffe0eb23f9a8f44204f7fc7ac0d0 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Wed, 7 Jul 2021 01:51:20 -0700 Subject: [PATCH] intel/blorp: Add blorp_check_in_bounds() Signed-off-by: Jordan Justen Reviewed-by: Kenneth Graunke Reviewed-by: Jason Ekstrand Part-of: --- src/intel/blorp/blorp_nir_builder.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/intel/blorp/blorp_nir_builder.h b/src/intel/blorp/blorp_nir_builder.h index afcb9b44290..ea3a893ed8c 100644 --- a/src/intel/blorp/blorp_nir_builder.h +++ b/src/intel/blorp/blorp_nir_builder.h @@ -97,3 +97,24 @@ blorp_nir_mcs_is_clear_color(nir_builder *b, unreachable("Invalid sample count"); } } + +static inline nir_ssa_def * +blorp_check_in_bounds(nir_builder *b, + nir_ssa_def *bounds_rect, + nir_ssa_def *pos) +{ + nir_ssa_def *x0 = nir_channel(b, bounds_rect, 0); + nir_ssa_def *x1 = nir_channel(b, bounds_rect, 1); + nir_ssa_def *y0 = nir_channel(b, bounds_rect, 2); + nir_ssa_def *y1 = nir_channel(b, bounds_rect, 3); + + nir_ssa_def *c0 = nir_uge(b, nir_channel(b, pos, 0), x0); + nir_ssa_def *c1 = nir_ult(b, nir_channel(b, pos, 0), x1); + nir_ssa_def *c2 = nir_uge(b, nir_channel(b, pos, 1), y0); + nir_ssa_def *c3 = nir_ult(b, nir_channel(b, pos, 1), y1); + + nir_ssa_def *in_bounds = + nir_iand(b, nir_iand(b, c0, c1), nir_iand(b, c2, c3)); + + return in_bounds; +}