summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Krol <[email protected]>2009-12-03 11:58:36 +0100
committerMichal Krol <[email protected]>2009-12-03 11:58:36 +0100
commitf5bd93fae2e4f46665eb1f09ca64cb39ff2b8a79 (patch)
tree2389d913bcd736d2d17a64189550b00ef68e1033
parentcceeab39ea541b1be1521114316d660a77769c2a (diff)
Move pf_get_component_bits() to u_format auxiliary module.
-rw-r--r--src/gallium/auxiliary/util/u_format.h44
-rw-r--r--src/gallium/drivers/llvmpipe/lp_state_surface.c7
-rw-r--r--src/gallium/drivers/softpipe/sp_state_surface.c7
-rw-r--r--src/gallium/include/pipe/p_format.h27
-rw-r--r--src/gallium/state_trackers/vega/vg_tracker.c2
-rw-r--r--src/gallium/state_trackers/wgl/stw_framebuffer.c5
-rw-r--r--src/gallium/state_trackers/wgl/stw_pixelformat.c13
-rw-r--r--src/mesa/state_tracker/st_cb_drawpixels.c4
-rw-r--r--src/mesa/state_tracker/st_format.c44
-rw-r--r--src/mesa/state_tracker/st_texture.c2
10 files changed, 87 insertions, 68 deletions
diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 3ac53840247..fa6dc1f55c0 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -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.
diff --git a/src/gallium/drivers/llvmpipe/lp_state_surface.c b/src/gallium/drivers/llvmpipe/lp_state_surface.c
index c06ce8b75c1..ba970cac985 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_surface.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_surface.c
@@ -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;
}
diff --git a/src/gallium/drivers/softpipe/sp_state_surface.c b/src/gallium/drivers/softpipe/sp_state_surface.c
index bc0e2011300..a518248bb18 100644
--- a/src/gallium/drivers/softpipe/sp_state_surface.c
+++ b/src/gallium/drivers/softpipe/sp_state_surface.c
@@ -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;
}
diff --git a/src/gallium/include/pipe/p_format.h b/src/gallium/include/pipe/p_format.h
index 5fd073c95fd..ec2961e8d7c 100644
--- a/src/gallium/include/pipe/p_format.h
+++ b/src/gallium/include/pipe/p_format.h
@@ -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.
diff --git a/src/gallium/state_trackers/vega/vg_tracker.c b/src/gallium/state_trackers/vega/vg_tracker.c
index e7b04a8e068..257feda671e 100644
--- a/src/gallium/state_trackers/vega/vg_tracker.c
+++ b/src/gallium/state_trackers/vega/vg_tracker.c
@@ -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 |
diff --git a/src/gallium/state_trackers/wgl/stw_framebuffer.c b/src/gallium/state_trackers/wgl/stw_framebuffer.c
index 8a3e11b6b40..5c3444777ab 100644
--- a/src/gallium/state_trackers/wgl/stw_framebuffer.c
+++ b/src/gallium/state_trackers/wgl/stw_framebuffer.c
@@ -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;
diff --git a/src/gallium/state_trackers/wgl/stw_pixelformat.c b/src/gallium/state_trackers/wgl/stw_pixelformat.c
index 7abe5d9f7fa..5ac833ced62 100644
--- a/src/gallium/state_trackers/wgl/stw_pixelformat.c
+++ b/src/gallium/state_trackers/wgl/stw_pixelformat.c
@@ -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];
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
index 0889cd6d2c2..496c1c4f3c6 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index 02f80057c29..c492d77530b 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -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;
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index bd6ee5d71c6..b1b515b28a6 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -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;