util: Make helper functions for pack/unpacking pixel rows.

Almost all users of the unpack functions don't have strides to plug in
(and many are only doing one pixel!), and this will help simplify
them.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2744>
This commit is contained in:
Eric Anholt 2019-11-08 12:30:02 -08:00 committed by Marge Bot
parent 333c9d5bb0
commit c574cda3c6
11 changed files with 124 additions and 63 deletions

View file

@ -591,12 +591,12 @@ util_clear_texture(struct pipe_context *pipe,
if (util_format_has_depth(desc)) { if (util_format_has_depth(desc)) {
clear |= PIPE_CLEAR_DEPTH; clear |= PIPE_CLEAR_DEPTH;
desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(tex->format, &depth, data, 1);
} }
if (util_format_has_stencil(desc)) { if (util_format_has_stencil(desc)) {
clear |= PIPE_CLEAR_STENCIL; clear |= PIPE_CLEAR_STENCIL;
desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(tex->format, &stencil, data, 1);
} }
zstencil = util_pack64_z_stencil(tex->format, depth, stencil); zstencil = util_pack64_z_stencil(tex->format, depth, stencil);
@ -606,12 +606,7 @@ util_clear_texture(struct pipe_context *pipe,
box->width, box->height, box->depth); box->width, box->height, box->depth);
} else { } else {
union pipe_color_union color; union pipe_color_union color;
if (util_format_is_pure_uint(tex->format)) util_format_unpack_rgba(tex->format, color.ui, data, 1);
desc->unpack_rgba_uint(color.ui, 0, data, 0, 1, 1);
else if (util_format_is_pure_sint(tex->format))
desc->unpack_rgba_sint(color.i, 0, data, 0, 1, 1);
else
desc->unpack_rgba_float(color.f, 0, data, 0, 1, 1);
util_clear_color_texture(pipe, tex, tex->format, &color, level, util_clear_color_texture(pipe, tex, tex->format, &color, level,
box->x, box->y, box->z, box->x, box->y, box->z,

View file

@ -702,10 +702,10 @@ iris_clear_texture(struct pipe_context *ctx,
uint8_t stencil = 0; uint8_t stencil = 0;
if (fmt_desc->unpack_z_float) if (fmt_desc->unpack_z_float)
fmt_desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(p_res->format, &depth, data, 1);
if (fmt_desc->unpack_s_8uint) if (fmt_desc->unpack_s_8uint)
fmt_desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(p_res->format, &stencil, data, 1);
clear_depth_stencil(ice, p_res, level, box, true, true, true, clear_depth_stencil(ice, p_res, level, box, true, true, true,
depth, stencil); depth, stencil);

View file

@ -41,15 +41,13 @@ nv30_emit_vtxattr(struct nv30_context *nv30, struct pipe_vertex_buffer *vb,
const unsigned nc = util_format_get_nr_components(ve->src_format); const unsigned nc = util_format_get_nr_components(ve->src_format);
struct nouveau_pushbuf *push = nv30->base.pushbuf; struct nouveau_pushbuf *push = nv30->base.pushbuf;
struct nv04_resource *res = nv04_resource(vb->buffer.resource); struct nv04_resource *res = nv04_resource(vb->buffer.resource);
const struct util_format_description *desc =
util_format_description(ve->src_format);
const void *data; const void *data;
float v[4]; float v[4];
data = nouveau_resource_map_offset(&nv30->base, res, vb->buffer_offset + data = nouveau_resource_map_offset(&nv30->base, res, vb->buffer_offset +
ve->src_offset, NOUVEAU_BO_RD); ve->src_offset, NOUVEAU_BO_RD);
desc->unpack_rgba_float(v, 0, data, 0, 1, 1); util_format_unpack_rgba_float(ve->src_format, v, data, 1);
switch (nc) { switch (nc) {
case 4: case 4:

View file

@ -475,11 +475,11 @@ nv50_clear_texture(struct pipe_context *pipe,
if (util_format_has_depth(desc)) { if (util_format_has_depth(desc)) {
clear |= PIPE_CLEAR_DEPTH; clear |= PIPE_CLEAR_DEPTH;
desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(res->format, &depth, data, 1);
} }
if (util_format_has_stencil(desc)) { if (util_format_has_stencil(desc)) {
clear |= PIPE_CLEAR_STENCIL; clear |= PIPE_CLEAR_STENCIL;
desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(res->format, &stencil, data, 1);
} }
pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil, pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil,
box->x, box->y, box->width, box->height, false); box->x, box->y, box->width, box->height, false);

View file

@ -149,15 +149,7 @@ nv50_emit_vtxattr(struct nv50_context *nv50, struct pipe_vertex_buffer *vb,
assert(vb->is_user_buffer); assert(vb->is_user_buffer);
if (desc->channel[0].pure_integer) { util_format_unpack_rgba(ve->src_format, v, data, 1);
if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
desc->unpack_rgba_sint((int32_t *)v, 0, data, 0, 1, 1);
} else {
desc->unpack_rgba_uint((uint32_t *)v, 0, data, 0, 1, 1);
}
} else {
desc->unpack_rgba_float(v, 0, data, 0, 1, 1);
}
switch (nc) { switch (nc) {
case 4: case 4:

View file

@ -184,17 +184,15 @@ nvc0_set_constant_vertex_attrib(struct nvc0_context *nvc0, const unsigned a)
PUSH_SPACE(push, 6); PUSH_SPACE(push, 6);
BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 5); BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 5);
dst = &push->cur[1]; dst = &push->cur[1];
util_format_unpack_rgba(ve->src_format, dst, src, 1);
if (desc->channel[0].pure_integer) { if (desc->channel[0].pure_integer) {
if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) { if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
mode = VTX_ATTR(a, 4, SINT, 32); mode = VTX_ATTR(a, 4, SINT, 32);
desc->unpack_rgba_sint(dst, 0, src, 0, 1, 1);
} else { } else {
mode = VTX_ATTR(a, 4, UINT, 32); mode = VTX_ATTR(a, 4, UINT, 32);
desc->unpack_rgba_uint(dst, 0, src, 0, 1, 1);
} }
} else { } else {
mode = VTX_ATTR(a, 4, FLOAT, 32); mode = VTX_ATTR(a, 4, FLOAT, 32);
desc->unpack_rgba_float(dst, 0, src, 0, 1, 1);
} }
push->cur[0] = mode; push->cur[0] = mode;
push->cur += 5; push->cur += 5;

View file

@ -1635,11 +1635,11 @@ static void r600_clear_texture(struct pipe_context *pipe,
/* Depth is always present. */ /* Depth is always present. */
clear = PIPE_CLEAR_DEPTH; clear = PIPE_CLEAR_DEPTH;
desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(tex->format, &depth, data, 1);
if (rtex->surface.has_stencil) { if (rtex->surface.has_stencil) {
clear |= PIPE_CLEAR_STENCIL; clear |= PIPE_CLEAR_STENCIL;
desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(tex->format, &stencil, data, 1);
} }
pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil, pipe->clear_depth_stencil(pipe, sf, clear, depth, stencil,
@ -1648,13 +1648,7 @@ static void r600_clear_texture(struct pipe_context *pipe,
} else { } else {
union pipe_color_union color; union pipe_color_union color;
/* pipe_color_union requires the full vec4 representation. */ util_format_unpack_rgba(tex->format, color.ui, data, 1);
if (util_format_is_pure_uint(tex->format))
desc->unpack_rgba_uint(color.ui, 0, data, 0, 1, 1);
else if (util_format_is_pure_sint(tex->format))
desc->unpack_rgba_sint(color.i, 0, data, 0, 1, 1);
else
desc->unpack_rgba_float(color.f, 0, data, 0, 1, 1);
if (screen->is_format_supported(screen, tex->format, if (screen->is_format_supported(screen, tex->format,
tex->target, 0, 0, tex->target, 0, 0,

View file

@ -752,11 +752,12 @@ static void si_clear_texture(struct pipe_context *pipe,
/* Depth is always present. */ /* Depth is always present. */
clear = PIPE_CLEAR_DEPTH; clear = PIPE_CLEAR_DEPTH;
desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(tex->format, &depth, data, 1);
if (stex->surface.has_stencil) { if (stex->surface.has_stencil) {
clear |= PIPE_CLEAR_STENCIL; clear |= PIPE_CLEAR_STENCIL;
desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(tex->format,
&stencil, data, 1);
} }
si_clear_depth_stencil(pipe, sf, clear, depth, stencil, si_clear_depth_stencil(pipe, sf, clear, depth, stencil,
@ -765,13 +766,7 @@ static void si_clear_texture(struct pipe_context *pipe,
} else { } else {
union pipe_color_union color; union pipe_color_union color;
/* pipe_color_union requires the full vec4 representation. */ util_format_unpack_rgba(tex->format, color.ui, data, 1);
if (util_format_is_pure_uint(tex->format))
desc->unpack_rgba_uint(color.ui, 0, data, 0, 1, 1);
else if (util_format_is_pure_sint(tex->format))
desc->unpack_rgba_sint(color.i, 0, data, 0, 1, 1);
else
desc->unpack_rgba_float(color.f, 0, data, 0, 1, 1);
if (screen->is_format_supported(screen, tex->format, if (screen->is_format_supported(screen, tex->format,
tex->target, 0, 0, tex->target, 0, 0,

View file

@ -309,8 +309,8 @@ svga_clear_texture(struct pipe_context *pipe,
stencil = 0; stencil = 0;
} }
else { else {
desc->unpack_z_float(&depth, 0, data, 0, 1, 1); util_format_unpack_z_float(surface->format, &depth, data, 1);
desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1); util_format_unpack_s_8uint(surface->format, &stencil, data, 1);
} }
if (util_format_has_depth(desc)) { if (util_format_has_depth(desc)) {
@ -367,18 +367,7 @@ svga_clear_texture(struct pipe_context *pipe,
color.f[0] = color.f[1] = color.f[2] = color.f[3] = 0; color.f[0] = color.f[1] = color.f[2] = color.f[3] = 0;
} }
else { else {
if (util_format_is_pure_sint(surface->format)) { util_format_unpack_rgba(surface->format, color.ui, data, 1);
/* signed integer */
desc->unpack_rgba_sint(color.i, 0, data, 0, 1, 1);
}
else if (util_format_is_pure_uint(surface->format)) {
/* unsigned integer */
desc->unpack_rgba_uint(color.ui, 0, data, 0, 1, 1);
}
else {
/* floating point */
desc->unpack_rgba_float(color.f, 0, data, 0, 1, 1);
}
} }
/* Setup render target view */ /* Setup render target view */

View file

@ -717,13 +717,13 @@ util_format_translate(enum pipe_format dst_format,
while (height--) { while (height--) {
if (tmp_z) { if (tmp_z) {
src_format_desc->unpack_z_float(tmp_z, 0, src_row, src_stride, width, 1); util_format_unpack_z_float(src_format, tmp_z, src_row, width);
dst_format_desc->pack_z_float(dst_row, dst_stride, tmp_z, 0, width, 1); util_format_pack_z_float(dst_format, dst_row, tmp_z, width);
} }
if (tmp_s) { if (tmp_s) {
src_format_desc->unpack_s_8uint(tmp_s, 0, src_row, src_stride, width, 1); util_format_unpack_s_8uint(src_format, tmp_s, src_row, width);
dst_format_desc->pack_s_8uint(dst_row, dst_stride, tmp_s, 0, width, 1); util_format_pack_s_8uint(dst_format, dst_row, tmp_s, width);
} }
dst_row += dst_step; dst_row += dst_step;

View file

@ -1439,6 +1439,106 @@ util_format_is_unorm8(const struct util_format_description *desc)
return desc->is_unorm && desc->is_array && desc->channel[c].size == 8; return desc->is_unorm && desc->is_array && desc->channel[c].size == 8;
} }
static inline void
util_format_unpack_z_float(enum pipe_format format, float *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->unpack_z_float(dst, 0, (const uint8_t *)src, 0, w, 1);
}
static inline void
util_format_unpack_z_32unorm(enum pipe_format format, uint32_t *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->unpack_z_32unorm(dst, 0, (const uint8_t *)src, 0, w, 1);
}
static inline void
util_format_unpack_s_8uint(enum pipe_format format, uint8_t *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->unpack_s_8uint(dst, 0, (const uint8_t *)src, 0, w, 1);
}
static inline void
util_format_unpack_rgba_float(enum pipe_format format, float *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->unpack_rgba_float(dst, 0, (const uint8_t *)src, 0, w, 1);
}
/**
* Unpacks a row of color data to 32-bit RGBA, either integers for pure
* integer formats (sign-extended for signed data), or 32-bit floats.
*/
static inline void
util_format_unpack_rgba(enum pipe_format format, void *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
if (util_format_is_pure_uint(format))
desc->unpack_rgba_uint((uint32_t *)dst, 0, (const uint8_t *)src, 0, w, 1);
else if (util_format_is_pure_sint(format))
desc->unpack_rgba_sint((int32_t *)dst, 0, (const uint8_t *)src, 0, w, 1);
else
desc->unpack_rgba_float((float *)dst, 0, (const uint8_t *)src, 0, w, 1);
}
static inline void
util_format_pack_z_float(enum pipe_format format, void *dst,
const float *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->pack_z_float((uint8_t *)dst, 0, src, 0, w, 1);
}
static inline void
util_format_pack_z_32unorm(enum pipe_format format, void *dst,
const uint32_t *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->pack_z_32unorm((uint8_t *)dst, 0, src, 0, w, 1);
}
static inline void
util_format_pack_s_8uint(enum pipe_format format, void *dst,
const uint8_t *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
desc->pack_s_8uint((uint8_t *)dst, 0, src, 0, w, 1);
}
/**
* Packs a row of color data from 32-bit RGBA, either integers for pure
* integer formats, or 32-bit floats. Values are clamped to the packed
* representation's range.
*/
static inline void
util_format_pack_rgba(enum pipe_format format, void *dst,
const void *src, unsigned w)
{
const struct util_format_description *desc = util_format_description(format);
if (util_format_is_pure_uint(format))
desc->pack_rgba_uint((uint8_t *)dst, 0, (const uint32_t *)src, 0, w, 1);
else if (util_format_is_pure_sint(format))
desc->pack_rgba_sint((uint8_t *)dst, 0, (const int32_t *)src, 0, w, 1);
else
desc->pack_rgba_float((uint8_t *)dst, 0, (const float *)src, 0, w, 1);
}
/* /*
* Format access functions. * Format access functions.
*/ */