nil: Add an offset4d struct and some helpers

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>
This commit is contained in:
Faith Ekstrand 2023-01-30 20:12:02 -06:00 committed by Marge Bot
parent 256a1e4193
commit 28e73a72f6
2 changed files with 56 additions and 0 deletions

View file

@ -40,6 +40,28 @@ nil_extent4d_mul(struct nil_extent4d a, struct nil_extent4d b)
};
}
static struct nil_offset4d
nil_offset4d_div_round_down(struct nil_offset4d num, struct nil_extent4d denom)
{
return (struct nil_offset4d) {
.x = num.x / denom.w,
.y = num.y / denom.h,
.z = num.z / denom.d,
.a = num.a / denom.a,
};
}
static struct nil_offset4d
nil_offset4d_mul(struct nil_offset4d a, struct nil_extent4d b)
{
return (struct nil_offset4d) {
.x = a.x * b.w,
.y = a.y * b.h,
.z = a.z * b.d,
.a = a.a * b.a,
};
}
static struct nil_extent4d
nil_extent4d_align(struct nil_extent4d ext, struct nil_extent4d align)
{
@ -96,6 +118,17 @@ nil_extent4d_px_to_el(struct nil_extent4d extent_px,
return nil_extent4d_div_round_up(extent_sa, nil_el_extent_sa(format));
}
struct nil_offset4d
nil_offset4d_px_to_el(struct nil_offset4d offset_px,
enum pipe_format format,
enum nil_sample_layout sample_layout)
{
const struct nil_offset4d offset_sa =
nil_offset4d_mul(offset_px, nil_px_extent_sa(sample_layout));
return nil_offset4d_div_round_down(offset_sa, nil_el_extent_sa(format));
}
static struct nil_extent4d
nil_extent4d_el_to_B(struct nil_extent4d extent_el,
uint32_t B_per_el)

View file

@ -71,6 +71,29 @@ nil_extent4d_px_to_el(struct nil_extent4d extent_px,
enum pipe_format format,
enum nil_sample_layout sample_layout);
struct nil_offset4d {
uint32_t x;
uint32_t y;
uint32_t z;
uint32_t a;
};
static inline struct nil_offset4d
nil_offset4d(uint32_t x, uint32_t y, uint32_t z, uint32_t a)
{
struct nil_offset4d o;
o.x = x;
o.y = y;
o.z = z;
o.a = a;
return o;
}
struct nil_offset4d
nil_offset4d_px_to_el(struct nil_offset4d offset_px,
enum pipe_format format,
enum nil_sample_layout sample_layout);
#define NIL_GOB_WIDTH_B 64
#define NIL_GOB_HEIGHT(gob_height_8) ((gob_height_8) ? 8 : 4)
#define NIL_GOB_DEPTH 1