if (util_format_has_depth(desc)) {
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)) {
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);
box->width, box->height, box->depth);
} else {
union pipe_color_union color;
- 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);
+ util_format_unpack_rgba(tex->format, color.ui, data, 1);
util_clear_color_texture(pipe, tex, tex->format, &color, level,
box->x, box->y, box->z,
uint8_t stencil = 0;
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)
- 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,
depth, stencil);
const unsigned nc = util_format_get_nr_components(ve->src_format);
struct nouveau_pushbuf *push = nv30->base.pushbuf;
struct nv04_resource *res = nv04_resource(vb->buffer.resource);
- const struct util_format_description *desc =
- util_format_description(ve->src_format);
const void *data;
float v[4];
data = nouveau_resource_map_offset(&nv30->base, res, vb->buffer_offset +
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) {
case 4:
if (util_format_has_depth(desc)) {
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)) {
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,
box->x, box->y, box->width, box->height, false);
assert(vb->is_user_buffer);
- if (desc->channel[0].pure_integer) {
- 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);
- }
+ util_format_unpack_rgba(ve->src_format, v, data, 1);
switch (nc) {
case 4:
PUSH_SPACE(push, 6);
BEGIN_NVC0(push, NVC0_3D(VTX_ATTR_DEFINE), 5);
dst = &push->cur[1];
+ util_format_unpack_rgba(ve->src_format, dst, src, 1);
if (desc->channel[0].pure_integer) {
if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
mode = VTX_ATTR(a, 4, SINT, 32);
- desc->unpack_rgba_sint(dst, 0, src, 0, 1, 1);
} else {
mode = VTX_ATTR(a, 4, UINT, 32);
- desc->unpack_rgba_uint(dst, 0, src, 0, 1, 1);
}
} else {
mode = VTX_ATTR(a, 4, FLOAT, 32);
- desc->unpack_rgba_float(dst, 0, src, 0, 1, 1);
}
push->cur[0] = mode;
push->cur += 5;
/* Depth is always present. */
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) {
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,
} else {
union pipe_color_union color;
- /* pipe_color_union requires the full vec4 representation. */
- 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);
+ util_format_unpack_rgba(tex->format, color.ui, data, 1);
if (screen->is_format_supported(screen, tex->format,
tex->target, 0, 0,
/* Depth is always present. */
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) {
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,
} else {
union pipe_color_union color;
- /* pipe_color_union requires the full vec4 representation. */
- 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);
+ util_format_unpack_rgba(tex->format, color.ui, data, 1);
if (screen->is_format_supported(screen, tex->format,
tex->target, 0, 0,
stencil = 0;
}
else {
- desc->unpack_z_float(&depth, 0, data, 0, 1, 1);
- desc->unpack_s_8uint(&stencil, 0, data, 0, 1, 1);
+ util_format_unpack_z_float(surface->format, &depth, data, 1);
+ util_format_unpack_s_8uint(surface->format, &stencil, data, 1);
}
if (util_format_has_depth(desc)) {
color.f[0] = color.f[1] = color.f[2] = color.f[3] = 0;
}
else {
- if (util_format_is_pure_sint(surface->format)) {
- /* 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);
- }
+ util_format_unpack_rgba(surface->format, color.ui, data, 1);
}
/* Setup render target view */
while (height--) {
if (tmp_z) {
- src_format_desc->unpack_z_float(tmp_z, 0, src_row, src_stride, width, 1);
- dst_format_desc->pack_z_float(dst_row, dst_stride, tmp_z, 0, width, 1);
+ util_format_unpack_z_float(src_format, tmp_z, src_row, width);
+ util_format_pack_z_float(dst_format, dst_row, tmp_z, width);
}
if (tmp_s) {
- src_format_desc->unpack_s_8uint(tmp_s, 0, src_row, src_stride, width, 1);
- dst_format_desc->pack_s_8uint(dst_row, dst_stride, tmp_s, 0, width, 1);
+ util_format_unpack_s_8uint(src_format, tmp_s, src_row, width);
+ util_format_pack_s_8uint(dst_format, dst_row, tmp_s, width);
}
dst_row += dst_step;
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.
*/