From: Faith Ekstrand Date: Tue, 31 Jan 2023 02:12:02 +0000 (-0600) Subject: nil: Add an offset4d struct and some helpers X-Git-Tag: upstream/23.3.3~4123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28e73a72f648a6b0b487b6b4d5d2aa5dc1f999c4;p=platform%2Fupstream%2Fmesa.git nil: Add an offset4d struct and some helpers Part-of: --- diff --git a/src/nouveau/nil/nil_image.c b/src/nouveau/nil/nil_image.c index bdc517d..b5dee00 100644 --- a/src/nouveau/nil/nil_image.c +++ b/src/nouveau/nil/nil_image.c @@ -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) diff --git a/src/nouveau/nil/nil_image.h b/src/nouveau/nil/nil_image.h index cf92f05..0171b47 100644 --- a/src/nouveau/nil/nil_image.h +++ b/src/nouveau/nil/nil_image.h @@ -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