[Mesa-dev] [PATCH 22/24] st/mesa: always set sampler swizzle according to the texture base format
Marek Olšák
maraeo at gmail.com
Mon Jun 12 18:18:53 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
Mainly don't (indirectly) call util_format_description here.
If the driver supports texture swizzling, this will always do the right
thing. If the driver doesn't support it, it doesn't matter.
---
src/mesa/state_tracker/st_sampler_view.c | 41 +++++++-------------------------
1 file changed, 9 insertions(+), 32 deletions(-)
diff --git a/src/mesa/state_tracker/st_sampler_view.c b/src/mesa/state_tracker/st_sampler_view.c
index 7a6993e..8c814ed 100644
--- a/src/mesa/state_tracker/st_sampler_view.c
+++ b/src/mesa/state_tracker/st_sampler_view.c
@@ -182,63 +182,41 @@ swizzle_swizzle(unsigned swizzle1, unsigned swizzle2)
* values.
*
* In the case of depth textures, the GL_DEPTH_MODE state determines the
* texture swizzle.
*
* This result must be composed with the user-specified swizzle to get
* the final swizzle.
*/
static unsigned
compute_texture_format_swizzle(GLenum baseFormat, GLenum depthMode,
- enum pipe_format actualFormat,
bool glsl130_or_later)
{
switch (baseFormat) {
case GL_RGBA:
return SWIZZLE_XYZW;
case GL_RGB:
- if (util_format_has_alpha(actualFormat))
- return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_ONE);
case GL_RG:
- if (util_format_get_nr_components(actualFormat) > 2)
- return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_ZERO, SWIZZLE_ONE);
case GL_RED:
- if (util_format_get_nr_components(actualFormat) > 1)
- return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
- SWIZZLE_ZERO, SWIZZLE_ONE);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_ZERO,
+ SWIZZLE_ZERO, SWIZZLE_ONE);
case GL_ALPHA:
- if (util_format_get_nr_components(actualFormat) > 1)
- return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
- SWIZZLE_ZERO, SWIZZLE_W);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_ZERO, SWIZZLE_ZERO,
+ SWIZZLE_ZERO, SWIZZLE_W);
case GL_LUMINANCE:
- if (util_format_get_nr_components(actualFormat) > 1)
- return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
case GL_LUMINANCE_ALPHA:
- if (util_format_get_nr_components(actualFormat) > 2)
- return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_W);
- else
- return SWIZZLE_XYZW;
+ return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_W);
case GL_INTENSITY:
- if (util_format_get_nr_components(actualFormat) > 1)
- return SWIZZLE_XXXX;
- else
- return SWIZZLE_XYZW;
+ return SWIZZLE_XXXX;
case GL_STENCIL_INDEX:
case GL_DEPTH_STENCIL:
case GL_DEPTH_COMPONENT:
/* Now examine the depth mode */
switch (depthMode) {
case GL_LUMINANCE:
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
case GL_INTENSITY:
return MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X);
case GL_ALPHA:
@@ -294,21 +272,20 @@ get_texture_format_swizzle(const struct st_context *st,
baseFormat == GL_STENCIL_INDEX)) {
const struct gl_texture_image *firstImage =
_mesa_base_tex_image(&stObj->base);
if (firstImage->InternalFormat != GL_DEPTH_COMPONENT &&
firstImage->InternalFormat != GL_DEPTH_STENCIL &&
firstImage->InternalFormat != GL_STENCIL_INDEX)
depth_mode = GL_RED;
}
tex_swizzle = compute_texture_format_swizzle(baseFormat,
depth_mode,
- stObj->pt->format,
glsl130_or_later);
/* Combine the texture format swizzle with user's swizzle */
return swizzle_swizzle(stObj->base._Swizzle, tex_swizzle);
}
/**
* Return TRUE if the texture's sampler view swizzle is not equal to
* the texture's swizzle.
--
2.7.4
More information about the mesa-dev
mailing list