Move pf_get_component_bits() to u_format auxiliary module.

This commit is contained in:
Michal Krol 2009-12-03 11:58:36 +01:00
parent cceeab39ea
commit f5bd93fae2
10 changed files with 87 additions and 68 deletions

View file

@ -212,6 +212,50 @@ util_format_get_size(enum pipe_format format)
return bits / 8;
}
static INLINE uint
util_format_get_component_bits(enum pipe_format format,
enum util_format_colorspace colorspace,
uint component)
{
const struct util_format_description *desc = util_format_description(format);
enum util_format_colorspace desc_colorspace;
uint swizzle;
assert(format);
if (!format) {
return 0;
}
assert(component >= 4);
/* Treat RGB and SRGB as equivalent. */
if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
colorspace = UTIL_FORMAT_COLORSPACE_RGB;
}
if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) {
desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB;
} else {
desc_colorspace = desc->colorspace;
}
if (desc_colorspace != colorspace) {
return 0;
}
switch (desc->swizzle[component]) {
case UTIL_FORMAT_SWIZZLE_X:
return desc->channel[0].size;
case UTIL_FORMAT_SWIZZLE_Y:
return desc->channel[1].size;
case UTIL_FORMAT_SWIZZLE_Z:
return desc->channel[2].size;
case UTIL_FORMAT_SWIZZLE_W:
return desc->channel[3].size;
default:
return 0;
}
}
/*
* Format access functions.

View file

@ -35,6 +35,8 @@
#include "draw/draw_context.h"
#include "util/u_format.h"
/**
* XXX this might get moved someday
@ -88,8 +90,9 @@ llvmpipe_set_framebuffer_state(struct pipe_context *pipe,
if (lp->framebuffer.zsbuf) {
int depth_bits;
double mrd;
depth_bits = pf_get_component_bits(lp->framebuffer.zsbuf->format,
PIPE_FORMAT_COMP_Z);
depth_bits = util_format_get_component_bits(lp->framebuffer.zsbuf->format,
UTIL_FORMAT_COLORSPACE_ZS,
0);
if (depth_bits > 16) {
mrd = 0.0000001;
}

View file

@ -35,6 +35,8 @@
#include "draw/draw_context.h"
#include "util/u_format.h"
/**
* XXX this might get moved someday
@ -80,8 +82,9 @@ softpipe_set_framebuffer_state(struct pipe_context *pipe,
if (sp->framebuffer.zsbuf) {
int depth_bits;
double mrd;
depth_bits = pf_get_component_bits(sp->framebuffer.zsbuf->format,
PIPE_FORMAT_COMP_Z);
depth_bits = util_format_get_component_bits(sp->framebuffer.zsbuf->format,
UTIL_FORMAT_COLORSPACE_ZS,
0);
if (depth_bits > 16) {
mrd = 0.0000001;
}

View file

@ -394,33 +394,6 @@ enum pipe_format {
*/
extern const char *pf_name( enum pipe_format format );
/**
* Return bits for a particular component.
* \param comp component index, starting at 0
*/
static INLINE uint pf_get_component_bits( enum pipe_format format, uint comp )
{
uint size;
if (pf_swizzle_x(format) == comp) {
size = pf_size_x(format);
}
else if (pf_swizzle_y(format) == comp) {
size = pf_size_y(format);
}
else if (pf_swizzle_z(format) == comp) {
size = pf_size_z(format);
}
else if (pf_swizzle_w(format) == comp) {
size = pf_size_w(format);
}
else {
size = 0;
}
if (pf_layout( format ) == PIPE_FORMAT_LAYOUT_RGBAZS)
return size << pf_exp2( format );
return size << (pf_mixed_scale8( format ) * 3);
}
/**
* Describe accurately the pixel format.

View file

@ -57,7 +57,7 @@ create_texture(struct pipe_context *pipe, enum pipe_format format,
templ.depth0 = 1;
templ.last_level = 0;
if (pf_get_component_bits(format, PIPE_FORMAT_COMP_S)) {
if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_ZS, 1)) {
templ.tex_usage = PIPE_TEXTURE_USAGE_DEPTH_STENCIL;
} else {
templ.tex_usage = (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |

View file

@ -30,6 +30,7 @@
#include "main/context.h"
#include "pipe/p_format.h"
#include "pipe/p_screen.h"
#include "util/u_format.h"
#include "state_tracker/st_context.h"
#include "state_tracker/st_public.h"
@ -270,12 +271,12 @@ stw_framebuffer_allocate(
assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z ))
if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 0))
depthFormat = pfi->depth_stencil_format;
else
depthFormat = PIPE_FORMAT_NONE;
if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S ))
if(util_format_get_component_bits(pfi->depth_stencil_format, UTIL_FORMAT_COLORSPACE_ZS, 1))
stencilFormat = pfi->depth_stencil_format;
else
stencilFormat = PIPE_FORMAT_NONE;

View file

@ -32,6 +32,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
#include "util/u_format.h"
#include "util/u_debug.h"
#include "stw_icd.h"
@ -133,13 +134,13 @@ stw_pixelformat_add(
return;
assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red );
assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green );
assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue );
assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha );
assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 0) == color->bits.red);
assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 1) == color->bits.green);
assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 2) == color->bits.blue);
assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 3) == color->bits.alpha);
assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS );
assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth );
assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil );
assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 0) == depth->bits.depth);
assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 1) == depth->bits.stencil);
pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count];

View file

@ -648,7 +648,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y,
}
if(format != GL_DEPTH_STENCIL &&
pf_get_component_bits( strb->format, PIPE_FORMAT_COMP_Z ) != 0)
util_format_get_component_bits(strb->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
usage = PIPE_TRANSFER_READ_WRITE;
else
usage = PIPE_TRANSFER_WRITE;
@ -843,7 +843,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
&ctx->DefaultPacking, buffer);
if(pf_get_component_bits( rbDraw->format, PIPE_FORMAT_COMP_Z ) != 0)
if(util_format_get_component_bits(rbDraw->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0)
usage = PIPE_TRANSFER_READ_WRITE;
else
usage = PIPE_TRANSFER_WRITE;

View file

@ -42,28 +42,22 @@
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_screen.h"
#include "util/u_format.h"
#include "st_context.h"
#include "st_format.h"
static GLuint
format_bits(
pipe_format_rgbazs_t info,
GLuint comp )
{
return pf_get_component_bits( (enum pipe_format) info, comp );
}
static GLuint
format_max_bits(
pipe_format_rgbazs_t info )
{
GLuint size = format_bits( info, PIPE_FORMAT_COMP_R );
GLuint size = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0);
size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_G ) );
size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_B ) );
size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_A ) );
size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_Z ) );
size = MAX2( size, format_bits( info, PIPE_FORMAT_COMP_S ) );
size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1));
size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2));
size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3));
size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0));
size = MAX2(size, util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1));
return size;
}
@ -72,12 +66,12 @@ format_size(
pipe_format_rgbazs_t info )
{
return
format_bits( info, PIPE_FORMAT_COMP_R ) +
format_bits( info, PIPE_FORMAT_COMP_G ) +
format_bits( info, PIPE_FORMAT_COMP_B ) +
format_bits( info, PIPE_FORMAT_COMP_A ) +
format_bits( info, PIPE_FORMAT_COMP_Z ) +
format_bits( info, PIPE_FORMAT_COMP_S );
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0) +
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1) +
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2) +
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3) +
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0) +
util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1);
}
/*
@ -126,12 +120,12 @@ st_get_format_info(enum pipe_format format, struct pipe_format_info *pinfo)
}
/* Component bits */
pinfo->red_bits = format_bits( info, PIPE_FORMAT_COMP_R );
pinfo->green_bits = format_bits( info, PIPE_FORMAT_COMP_G );
pinfo->blue_bits = format_bits( info, PIPE_FORMAT_COMP_B );
pinfo->alpha_bits = format_bits( info, PIPE_FORMAT_COMP_A );
pinfo->depth_bits = format_bits( info, PIPE_FORMAT_COMP_Z );
pinfo->stencil_bits = format_bits( info, PIPE_FORMAT_COMP_S );
pinfo->red_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 0);
pinfo->green_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 1);
pinfo->blue_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 2);
pinfo->alpha_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_RGB, 3);
pinfo->depth_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 0);
pinfo->stencil_bits = util_format_get_component_bits((enum pipe_format)info, UTIL_FORMAT_COLORSPACE_ZS, 1);
pinfo->luminance_bits = 0;
pinfo->intensity_bits = 0;

View file

@ -406,7 +406,7 @@ st_bind_texture_surface(struct pipe_surface *ps, int target, int level,
}
/* map pipe format to base format for now */
if (pf_get_component_bits(format, PIPE_FORMAT_COMP_A) > 0)
if (util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
internalFormat = GL_RGBA;
else
internalFormat = GL_RGB;