From b5a042a657fed45264406cbd0d67fa6217a410a1 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 7 Sep 2012 13:24:16 -0700 Subject: [PATCH] i965: Refactor texture swizzle generation into a helper. It's going to be reused in a second place soon. Reviewed-by: Eric Anholt Signed-off-by: Kenneth Graunke --- src/mesa/drivers/dri/i965/brw_state.h | 2 + src/mesa/drivers/dri/i965/brw_wm.c | 51 +---------------- .../drivers/dri/i965/brw_wm_surface_state.c | 56 +++++++++++++++++++ 3 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_state.h b/src/mesa/drivers/dri/i965/brw_state.h index 99fa088a90f..48dd4ba76bb 100644 --- a/src/mesa/drivers/dri/i965/brw_state.h +++ b/src/mesa/drivers/dri/i965/brw_state.h @@ -202,6 +202,8 @@ GLuint translate_tex_format(gl_format mesa_format, GLenum depth_mode, GLenum srgb_decode); +int brw_get_texture_swizzle(const struct gl_texture_object *t); + /* gen7_wm_surface_state.c */ void gen7_set_surface_tiling(struct gen7_surface_state *surf, uint32_t tiling); void gen7_set_surface_msaa(struct gen7_surface_state *surf, diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c index 995e8f3fa21..0f115259867 100644 --- a/src/mesa/drivers/dri/i965/brw_wm.c +++ b/src/mesa/drivers/dri/i965/brw_wm.c @@ -504,49 +504,8 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, const struct gl_texture_object *t = unit->_Current; const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id); - int swizzles[SWIZZLE_NIL + 1] = { - SWIZZLE_X, - SWIZZLE_Y, - SWIZZLE_Z, - SWIZZLE_W, - SWIZZLE_ZERO, - SWIZZLE_ONE, - SWIZZLE_NIL - }; - - if (img->_BaseFormat == GL_DEPTH_COMPONENT || - img->_BaseFormat == GL_DEPTH_STENCIL) { - /* We handle GL_DEPTH_TEXTURE_MODE here instead of as surface - * format overrides because shadow comparison always returns the - * result of the comparison in all channels anyway. - */ - switch (t->DepthMode) { - case GL_ALPHA: - swizzles[0] = SWIZZLE_ZERO; - swizzles[1] = SWIZZLE_ZERO; - swizzles[2] = SWIZZLE_ZERO; - swizzles[3] = SWIZZLE_X; - break; - case GL_LUMINANCE: - swizzles[0] = SWIZZLE_X; - swizzles[1] = SWIZZLE_X; - swizzles[2] = SWIZZLE_X; - swizzles[3] = SWIZZLE_ONE; - break; - case GL_INTENSITY: - swizzles[0] = SWIZZLE_X; - swizzles[1] = SWIZZLE_X; - swizzles[2] = SWIZZLE_X; - swizzles[3] = SWIZZLE_X; - break; - case GL_RED: - swizzles[0] = SWIZZLE_X; - swizzles[1] = SWIZZLE_ZERO; - swizzles[2] = SWIZZLE_ZERO; - swizzles[3] = SWIZZLE_ONE; - break; - } - } + + key->swizzles[s] = brw_get_texture_swizzle(t); if (img->InternalFormat == GL_YCBCR_MESA) { key->yuvtex_mask |= 1 << s; @@ -554,12 +513,6 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx, key->yuvtex_swap_mask |= 1 << s; } - key->swizzles[s] = - MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], - swizzles[GET_SWZ(t->_Swizzle, 1)], - swizzles[GET_SWZ(t->_Swizzle, 2)], - swizzles[GET_SWZ(t->_Swizzle, 3)]); - if (sampler->MinFilter != GL_NEAREST && sampler->MagFilter != GL_NEAREST) { if (sampler->WrapS == GL_CLAMP) diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c index 582e2399a15..abdcb8478ba 100644 --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c @@ -653,6 +653,62 @@ brw_get_surface_num_multisamples(unsigned num_samples) } +/** + * Compute the combination of DEPTH_TEXTURE_MODE and EXT_texture_swizzle + * swizzling. + */ +int +brw_get_texture_swizzle(const struct gl_texture_object *t) +{ + const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; + + int swizzles[SWIZZLE_NIL + 1] = { + SWIZZLE_X, + SWIZZLE_Y, + SWIZZLE_Z, + SWIZZLE_W, + SWIZZLE_ZERO, + SWIZZLE_ONE, + SWIZZLE_NIL + }; + + if (img->_BaseFormat == GL_DEPTH_COMPONENT || + img->_BaseFormat == GL_DEPTH_STENCIL) { + switch (t->DepthMode) { + case GL_ALPHA: + swizzles[0] = SWIZZLE_ZERO; + swizzles[1] = SWIZZLE_ZERO; + swizzles[2] = SWIZZLE_ZERO; + swizzles[3] = SWIZZLE_X; + break; + case GL_LUMINANCE: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_ONE; + break; + case GL_INTENSITY: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_X; + swizzles[2] = SWIZZLE_X; + swizzles[3] = SWIZZLE_X; + break; + case GL_RED: + swizzles[0] = SWIZZLE_X; + swizzles[1] = SWIZZLE_ZERO; + swizzles[2] = SWIZZLE_ZERO; + swizzles[3] = SWIZZLE_ONE; + break; + } + } + + return MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], + swizzles[GET_SWZ(t->_Swizzle, 1)], + swizzles[GET_SWZ(t->_Swizzle, 2)], + swizzles[GET_SWZ(t->_Swizzle, 3)]); +} + + static void brw_update_buffer_texture_surface(struct gl_context *ctx, unsigned unit, -- 2.30.2