gallium/util: use ui[4] instead of ui in union util_color
util_color often merely represents a collection of bytes, however it is inconvenient if those bytes can only be accessed as floats/doubles for int formats exceeding 32bits. (Note that since rgba8 formats use one uint, not 4 bytes, hence the byte and short member were left as is.)
This commit is contained in:
@@ -51,7 +51,7 @@
|
|||||||
union util_color {
|
union util_color {
|
||||||
ubyte ub;
|
ubyte ub;
|
||||||
ushort us;
|
ushort us;
|
||||||
uint ui;
|
uint ui[4];
|
||||||
ushort h[4]; /* half float */
|
ushort h[4]; /* half float */
|
||||||
float f[4];
|
float f[4];
|
||||||
double d[4];
|
double d[4];
|
||||||
@@ -67,32 +67,32 @@ util_pack_color_ub(ubyte r, ubyte g, ubyte b, ubyte a,
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case PIPE_FORMAT_ABGR8888_UNORM:
|
case PIPE_FORMAT_ABGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
|
uc->ui[0] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XBGR8888_UNORM:
|
case PIPE_FORMAT_XBGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
uc->ui[0] = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRA8888_UNORM:
|
case PIPE_FORMAT_BGRA8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
|
uc->ui[0] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRX8888_UNORM:
|
case PIPE_FORMAT_BGRX8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
|
uc->ui[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_ARGB8888_UNORM:
|
case PIPE_FORMAT_ARGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
|
uc->ui[0] = (b << 24) | (g << 16) | (r << 8) | a;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XRGB8888_UNORM:
|
case PIPE_FORMAT_XRGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
|
uc->ui[0] = (b << 24) | (g << 16) | (r << 8) | 0xff;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_B5G6R5_UNORM:
|
case PIPE_FORMAT_B5G6R5_UNORM:
|
||||||
@@ -168,7 +168,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case PIPE_FORMAT_ABGR8888_UNORM:
|
case PIPE_FORMAT_ABGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 24) & 0xff);
|
*r = (ubyte) ((p >> 24) & 0xff);
|
||||||
*g = (ubyte) ((p >> 16) & 0xff);
|
*g = (ubyte) ((p >> 16) & 0xff);
|
||||||
*b = (ubyte) ((p >> 8) & 0xff);
|
*b = (ubyte) ((p >> 8) & 0xff);
|
||||||
@@ -177,7 +177,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XBGR8888_UNORM:
|
case PIPE_FORMAT_XBGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 24) & 0xff);
|
*r = (ubyte) ((p >> 24) & 0xff);
|
||||||
*g = (ubyte) ((p >> 16) & 0xff);
|
*g = (ubyte) ((p >> 16) & 0xff);
|
||||||
*b = (ubyte) ((p >> 8) & 0xff);
|
*b = (ubyte) ((p >> 8) & 0xff);
|
||||||
@@ -186,7 +186,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRA8888_UNORM:
|
case PIPE_FORMAT_BGRA8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 16) & 0xff);
|
*r = (ubyte) ((p >> 16) & 0xff);
|
||||||
*g = (ubyte) ((p >> 8) & 0xff);
|
*g = (ubyte) ((p >> 8) & 0xff);
|
||||||
*b = (ubyte) ((p >> 0) & 0xff);
|
*b = (ubyte) ((p >> 0) & 0xff);
|
||||||
@@ -195,7 +195,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRX8888_UNORM:
|
case PIPE_FORMAT_BGRX8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 16) & 0xff);
|
*r = (ubyte) ((p >> 16) & 0xff);
|
||||||
*g = (ubyte) ((p >> 8) & 0xff);
|
*g = (ubyte) ((p >> 8) & 0xff);
|
||||||
*b = (ubyte) ((p >> 0) & 0xff);
|
*b = (ubyte) ((p >> 0) & 0xff);
|
||||||
@@ -204,7 +204,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_ARGB8888_UNORM:
|
case PIPE_FORMAT_ARGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 8) & 0xff);
|
*r = (ubyte) ((p >> 8) & 0xff);
|
||||||
*g = (ubyte) ((p >> 16) & 0xff);
|
*g = (ubyte) ((p >> 16) & 0xff);
|
||||||
*b = (ubyte) ((p >> 24) & 0xff);
|
*b = (ubyte) ((p >> 24) & 0xff);
|
||||||
@@ -213,7 +213,7 @@ util_unpack_color_ub(enum pipe_format format, union util_color *uc,
|
|||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XRGB8888_UNORM:
|
case PIPE_FORMAT_XRGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uint p = uc->ui;
|
uint p = uc->ui[0];
|
||||||
*r = (ubyte) ((p >> 8) & 0xff);
|
*r = (ubyte) ((p >> 8) & 0xff);
|
||||||
*g = (ubyte) ((p >> 16) & 0xff);
|
*g = (ubyte) ((p >> 16) & 0xff);
|
||||||
*b = (ubyte) ((p >> 24) & 0xff);
|
*b = (ubyte) ((p >> 24) & 0xff);
|
||||||
@@ -352,32 +352,32 @@ util_pack_color(const float rgba[4], enum pipe_format format, union util_color *
|
|||||||
switch (format) {
|
switch (format) {
|
||||||
case PIPE_FORMAT_ABGR8888_UNORM:
|
case PIPE_FORMAT_ABGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (r << 24) | (g << 16) | (b << 8) | a;
|
uc->ui[0] = (r << 24) | (g << 16) | (b << 8) | a;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XBGR8888_UNORM:
|
case PIPE_FORMAT_XBGR8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
uc->ui[0] = (r << 24) | (g << 16) | (b << 8) | 0xff;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRA8888_UNORM:
|
case PIPE_FORMAT_BGRA8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (a << 24) | (r << 16) | (g << 8) | b;
|
uc->ui[0] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_BGRX8888_UNORM:
|
case PIPE_FORMAT_BGRX8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (0xff << 24) | (r << 16) | (g << 8) | b;
|
uc->ui[0] = (0xff << 24) | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_ARGB8888_UNORM:
|
case PIPE_FORMAT_ARGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (b << 24) | (g << 16) | (r << 8) | a;
|
uc->ui[0] = (b << 24) | (g << 16) | (r << 8) | a;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_XRGB8888_UNORM:
|
case PIPE_FORMAT_XRGB8888_UNORM:
|
||||||
{
|
{
|
||||||
uc->ui = (b << 24) | (g << 16) | (r << 8) | 0xff;
|
uc->ui[0] = (b << 24) | (g << 16) | (r << 8) | 0xff;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case PIPE_FORMAT_B5G6R5_UNORM:
|
case PIPE_FORMAT_B5G6R5_UNORM:
|
||||||
|
@@ -196,7 +196,7 @@ util_fill_rect(ubyte * dst,
|
|||||||
for (i = 0; i < height; i++) {
|
for (i = 0; i < height; i++) {
|
||||||
uint32_t *row = (uint32_t *)dst;
|
uint32_t *row = (uint32_t *)dst;
|
||||||
for (j = 0; j < width; j++)
|
for (j = 0; j < width; j++)
|
||||||
*row++ = uc->ui;
|
*row++ = uc->ui[0];
|
||||||
dst += dst_stride;
|
dst += dst_stride;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -123,7 +123,7 @@ pack_rgba(enum pipe_format format, const float *rgba)
|
|||||||
{
|
{
|
||||||
union util_color uc;
|
union util_color uc;
|
||||||
util_pack_color(rgba, format, &uc);
|
util_pack_color(rgba, format, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -66,10 +66,10 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers,
|
|||||||
|
|
||||||
util_pack_color(color->f, cbuf->format, &u_color);
|
util_pack_color(color->f, cbuf->format, &u_color);
|
||||||
if (util_format_get_blocksize(cbuf_tex->b.b.format) == 4) {
|
if (util_format_get_blocksize(cbuf_tex->b.b.format) == 4) {
|
||||||
clear_color = u_color.ui;
|
clear_color = u_color.ui[0];
|
||||||
color_clear_bbp = 32;
|
color_clear_bbp = 32;
|
||||||
} else {
|
} else {
|
||||||
clear_color = (u_color.ui & 0xffff) | (u_color.ui << 16);
|
clear_color = (u_color.ui[0] & 0xffff) | (u_color.ui[0] << 16);
|
||||||
color_clear_bbp = 16;
|
color_clear_bbp = 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ i915_clear_emit(struct pipe_context *pipe, unsigned buffers,
|
|||||||
util_pack_color(color->f, cbuf->format, &u_color);
|
util_pack_color(color->f, cbuf->format, &u_color);
|
||||||
else
|
else
|
||||||
util_pack_color(color->f, PIPE_FORMAT_B8G8R8A8_UNORM, &u_color);
|
util_pack_color(color->f, PIPE_FORMAT_B8G8R8A8_UNORM, &u_color);
|
||||||
clear_color8888 = u_color.ui;
|
clear_color8888 = u_color.ui[0];
|
||||||
} else
|
} else
|
||||||
clear_color = clear_color8888 = 0;
|
clear_color = clear_color8888 = 0;
|
||||||
|
|
||||||
|
@@ -266,7 +266,7 @@ i915_clear_render_target_blitter(struct pipe_context *pipe,
|
|||||||
tex->buffer, offset,
|
tex->buffer, offset,
|
||||||
(short) dstx, (short) dsty,
|
(short) dstx, (short) dsty,
|
||||||
(short) width, (short) height,
|
(short) width, (short) height,
|
||||||
uc.ui );
|
uc.ui[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -739,7 +739,7 @@ ilo_blitter_blt_clear_rt(struct ilo_blitter *blitter,
|
|||||||
size = end - offset;
|
size = end - offset;
|
||||||
|
|
||||||
success = buf_clear_region(blitter, ilo_buffer(rt->texture),
|
success = buf_clear_region(blitter, ilo_buffer(rt->texture),
|
||||||
offset, size, packed.ui, mask, mask);
|
offset, size, packed.ui[0], mask, mask);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
struct pipe_box box;
|
struct pipe_box box;
|
||||||
@@ -748,7 +748,7 @@ ilo_blitter_blt_clear_rt(struct ilo_blitter *blitter,
|
|||||||
rt->u.tex.last_layer - rt->u.tex.first_layer + 1, &box);
|
rt->u.tex.last_layer - rt->u.tex.first_layer + 1, &box);
|
||||||
|
|
||||||
success = tex_clear_region(blitter, ilo_texture(rt->texture),
|
success = tex_clear_region(blitter, ilo_texture(rt->texture),
|
||||||
rt->u.tex.level, &box, packed.ui, mask, mask);
|
rt->u.tex.level, &box, packed.ui[0], mask, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@@ -37,7 +37,7 @@ pack_rgba(enum pipe_format format, const float *rgba)
|
|||||||
{
|
{
|
||||||
union util_color uc;
|
union util_color uc;
|
||||||
util_pack_color(rgba, format, &uc);
|
util_pack_color(rgba, format, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE uint32_t
|
static INLINE uint32_t
|
||||||
|
@@ -118,7 +118,7 @@ static uint32_t r300_depth_clear_cb_value(enum pipe_format format,
|
|||||||
util_pack_color(rgba, format, &uc);
|
util_pack_color(rgba, format, &uc);
|
||||||
|
|
||||||
if (util_format_get_blocksizebits(format) == 32)
|
if (util_format_get_blocksizebits(format) == 32)
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
else
|
else
|
||||||
return uc.us | (uc.us << 16);
|
return uc.us | (uc.us << 16);
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ static void r300_set_clear_color(struct r300_context *r300,
|
|||||||
r300->color_clear_value_gb = uc.h[0] | ((uint32_t)uc.h[1] << 16);
|
r300->color_clear_value_gb = uc.h[0] | ((uint32_t)uc.h[1] << 16);
|
||||||
r300->color_clear_value_ar = uc.h[2] | ((uint32_t)uc.h[3] << 16);
|
r300->color_clear_value_ar = uc.h[2] | ((uint32_t)uc.h[3] << 16);
|
||||||
} else {
|
} else {
|
||||||
r300->color_clear_value = uc.ui;
|
r300->color_clear_value = uc.ui[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -646,7 +646,7 @@ static void r300_set_blend_color(struct pipe_context* pipe,
|
|||||||
util_pack_color(c.color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
|
util_pack_color(c.color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
|
||||||
|
|
||||||
BEGIN_CB(state->cb, 2);
|
BEGIN_CB(state->cb, 2);
|
||||||
OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui);
|
OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui[0]);
|
||||||
END_CB;
|
END_CB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -699,24 +699,24 @@ static uint32_t r300_get_border_color(enum pipe_format format,
|
|||||||
/* The Y component is used for the border color. */
|
/* The Y component is used for the border color. */
|
||||||
border_swizzled[1] = border_swizzled[0] + 1.0f/32;
|
border_swizzled[1] = border_swizzled[0] + 1.0f/32;
|
||||||
util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
|
util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
case PIPE_FORMAT_RGTC2_SNORM:
|
case PIPE_FORMAT_RGTC2_SNORM:
|
||||||
case PIPE_FORMAT_LATC2_SNORM:
|
case PIPE_FORMAT_LATC2_SNORM:
|
||||||
util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc);
|
util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
case PIPE_FORMAT_RGTC2_UNORM:
|
case PIPE_FORMAT_RGTC2_UNORM:
|
||||||
case PIPE_FORMAT_LATC2_UNORM:
|
case PIPE_FORMAT_LATC2_UNORM:
|
||||||
util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
|
util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
case PIPE_FORMAT_DXT1_SRGB:
|
case PIPE_FORMAT_DXT1_SRGB:
|
||||||
case PIPE_FORMAT_DXT1_SRGBA:
|
case PIPE_FORMAT_DXT1_SRGBA:
|
||||||
case PIPE_FORMAT_DXT3_SRGBA:
|
case PIPE_FORMAT_DXT3_SRGBA:
|
||||||
case PIPE_FORMAT_DXT5_SRGBA:
|
case PIPE_FORMAT_DXT5_SRGBA:
|
||||||
util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_SRGB, &uc);
|
util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_SRGB, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
default:
|
default:
|
||||||
util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
|
util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,7 +789,7 @@ static uint32_t r300_get_border_color(enum pipe_format format,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return uc.ui;
|
return uc.ui[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void r300_merge_textures_and_samplers(struct r300_context* r300)
|
static void r300_merge_textures_and_samplers(struct r300_context* r300)
|
||||||
|
@@ -86,7 +86,7 @@ try_clear(struct svga_context *svga,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SVGA3D_ClearRect(svga->swc, flags, uc.ui, (float) depth, stencil,
|
ret = SVGA3D_ClearRect(svga->swc, flags, uc.ui[0], (float) depth, stencil,
|
||||||
rect.x, rect.y, rect.w, rect.h);
|
rect.x, rect.y, rect.w, rect.h);
|
||||||
if (ret != PIPE_OK)
|
if (ret != PIPE_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -121,7 +121,7 @@ load_color_map_texture(struct gl_context *ctx, struct pipe_resource *pt)
|
|||||||
rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize];
|
rgba[2] = ctx->PixelMaps.BtoB.Map[j * bSize / texSize];
|
||||||
rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize];
|
rgba[3] = ctx->PixelMaps.AtoA.Map[i * aSize / texSize];
|
||||||
util_pack_color(rgba, pt->format, &uc);
|
util_pack_color(rgba, pt->format, &uc);
|
||||||
*(dest + k) = uc.ui;
|
*(dest + k) = uc.ui[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user