mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 07:28:11 +02:00
i965: Refactor texture swizzle generation into a helper.
It's going to be reused in a second place soon. Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
parent
ff947c6d65
commit
b5a042a657
3 changed files with 59 additions and 48 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue