Re: [Mesa-dev] [PATCH] st/mesa: optionally apply texture swizzle to border color v2
Thanks for the update. Looks good to me FWIW. Jose - Original Message - From: Christoph Bumiller christoph.bumil...@speed.at This is the only sane solution for nv50 and nvc0 (really, trust me), but since on other hardware the border colour is tightly coupled with texture state they'd have to undo the swizzle, so I've added a cap. The dependency of update_sampler on the texture updates was introduced to avoid doing the apply_depthmode to the swizzle twice. v2: Moved swizzling helper to u_format.c, extended the CAP to provide more accurate information. --- src/gallium/auxiliary/util/u_format.c| 34 ++ src/gallium/auxiliary/util/u_format.h| 12 src/gallium/docs/source/cso/sampler.rst |6 ++- src/gallium/docs/source/screen.rst | 11 +++ src/gallium/drivers/freedreno/freedreno_screen.c |1 + src/gallium/drivers/i915/i915_screen.c |1 + src/gallium/drivers/llvmpipe/lp_screen.c |2 + src/gallium/drivers/nv30/nv30_screen.c |1 + src/gallium/drivers/nv50/nv50_screen.c |2 + src/gallium/drivers/nvc0/nvc0_screen.c |2 + src/gallium/drivers/r300/r300_screen.c |1 + src/gallium/drivers/r600/r600_pipe.c |3 ++ src/gallium/drivers/radeonsi/radeonsi_pipe.c |1 + src/gallium/drivers/softpipe/sp_screen.c |2 + src/gallium/drivers/svga/svga_screen.c |2 + src/gallium/include/pipe/p_defines.h |7 - src/mesa/state_tracker/st_atom.c |2 +- src/mesa/state_tracker/st_atom_sampler.c | 27 +++-- src/mesa/state_tracker/st_context.c |3 ++ src/mesa/state_tracker/st_context.h |1 + 20 files changed, 114 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 1845637..9bdc2ea 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -632,6 +632,40 @@ void util_format_compose_swizzles(const unsigned char swz1[4], } } +void util_format_apply_color_swizzle(union pipe_color_union *dst, + const union pipe_color_union *src, + const unsigned char swz[4], + const boolean is_integer) +{ + unsigned c; + + if (is_integer) { + for (c = 0; c 4; ++c) { + switch (swz[c]) { + case PIPE_SWIZZLE_RED: dst-ui[c] = src-ui[0]; break; + case PIPE_SWIZZLE_GREEN: dst-ui[c] = src-ui[1]; break; + case PIPE_SWIZZLE_BLUE: dst-ui[c] = src-ui[2]; break; + case PIPE_SWIZZLE_ALPHA: dst-ui[c] = src-ui[3]; break; + default: +dst-ui[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1 : 0; +break; + } + } + } else { + for (c = 0; c 4; ++c) { + switch (swz[c]) { + case PIPE_SWIZZLE_RED: dst-f[c] = src-f[0]; break; + case PIPE_SWIZZLE_GREEN: dst-f[c] = src-f[1]; break; + case PIPE_SWIZZLE_BLUE: dst-f[c] = src-f[2]; break; + case PIPE_SWIZZLE_ALPHA: dst-f[c] = src-f[3]; break; + default: +dst-f[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1.0f : 0.0f; +break; + } + } + } +} + void util_format_swizzle_4f(float *dst, const float *src, const unsigned char swz[4]) { diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index ed942fb..e4b9c36 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -33,6 +33,9 @@ #include pipe/p_format.h #include util/u_debug.h +union pipe_color_union; + + #ifdef __cplusplus extern C { #endif @@ -1117,6 +1120,15 @@ void util_format_compose_swizzles(const unsigned char swz1[4], const unsigned char swz2[4], unsigned char dst[4]); +/* Apply the swizzle provided in \param swz (which is one of PIPE_SWIZZLE_x) + * to \param src and store the result in \param dst. + * \param is_integer determines the value written for PIPE_SWIZZLE_ONE. + */ +void util_format_apply_color_swizzle(union pipe_color_union *dst, + const union pipe_color_union *src, + const unsigned char swz[4], + const boolean is_integer); + void util_format_swizzle_4f(float *dst, const float *src, const unsigned char swz[4]); diff --git a/src/gallium/docs/source/cso/sampler.rst b/src/gallium/docs/source/cso/sampler.rst index 26ffc18..9959793 100644 --- a/src/gallium/docs/source/cso/sampler.rst +++
[Mesa-dev] [PATCH] st/mesa: optionally apply texture swizzle to border color v2
From: Christoph Bumiller christoph.bumil...@speed.at This is the only sane solution for nv50 and nvc0 (really, trust me), but since on other hardware the border colour is tightly coupled with texture state they'd have to undo the swizzle, so I've added a cap. The dependency of update_sampler on the texture updates was introduced to avoid doing the apply_depthmode to the swizzle twice. v2: Moved swizzling helper to u_format.c, extended the CAP to provide more accurate information. --- src/gallium/auxiliary/util/u_format.c| 34 ++ src/gallium/auxiliary/util/u_format.h| 12 src/gallium/docs/source/cso/sampler.rst |6 ++- src/gallium/docs/source/screen.rst | 11 +++ src/gallium/drivers/freedreno/freedreno_screen.c |1 + src/gallium/drivers/i915/i915_screen.c |1 + src/gallium/drivers/llvmpipe/lp_screen.c |2 + src/gallium/drivers/nv30/nv30_screen.c |1 + src/gallium/drivers/nv50/nv50_screen.c |2 + src/gallium/drivers/nvc0/nvc0_screen.c |2 + src/gallium/drivers/r300/r300_screen.c |1 + src/gallium/drivers/r600/r600_pipe.c |3 ++ src/gallium/drivers/radeonsi/radeonsi_pipe.c |1 + src/gallium/drivers/softpipe/sp_screen.c |2 + src/gallium/drivers/svga/svga_screen.c |2 + src/gallium/include/pipe/p_defines.h |7 - src/mesa/state_tracker/st_atom.c |2 +- src/mesa/state_tracker/st_atom_sampler.c | 27 +++-- src/mesa/state_tracker/st_context.c |3 ++ src/mesa/state_tracker/st_context.h |1 + 20 files changed, 114 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c index 1845637..9bdc2ea 100644 --- a/src/gallium/auxiliary/util/u_format.c +++ b/src/gallium/auxiliary/util/u_format.c @@ -632,6 +632,40 @@ void util_format_compose_swizzles(const unsigned char swz1[4], } } +void util_format_apply_color_swizzle(union pipe_color_union *dst, + const union pipe_color_union *src, + const unsigned char swz[4], + const boolean is_integer) +{ + unsigned c; + + if (is_integer) { + for (c = 0; c 4; ++c) { + switch (swz[c]) { + case PIPE_SWIZZLE_RED: dst-ui[c] = src-ui[0]; break; + case PIPE_SWIZZLE_GREEN: dst-ui[c] = src-ui[1]; break; + case PIPE_SWIZZLE_BLUE: dst-ui[c] = src-ui[2]; break; + case PIPE_SWIZZLE_ALPHA: dst-ui[c] = src-ui[3]; break; + default: +dst-ui[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1 : 0; +break; + } + } + } else { + for (c = 0; c 4; ++c) { + switch (swz[c]) { + case PIPE_SWIZZLE_RED: dst-f[c] = src-f[0]; break; + case PIPE_SWIZZLE_GREEN: dst-f[c] = src-f[1]; break; + case PIPE_SWIZZLE_BLUE: dst-f[c] = src-f[2]; break; + case PIPE_SWIZZLE_ALPHA: dst-f[c] = src-f[3]; break; + default: +dst-f[c] = (swz[c] == PIPE_SWIZZLE_ONE) ? 1.0f : 0.0f; +break; + } + } + } +} + void util_format_swizzle_4f(float *dst, const float *src, const unsigned char swz[4]) { diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h index ed942fb..e4b9c36 100644 --- a/src/gallium/auxiliary/util/u_format.h +++ b/src/gallium/auxiliary/util/u_format.h @@ -33,6 +33,9 @@ #include pipe/p_format.h #include util/u_debug.h +union pipe_color_union; + + #ifdef __cplusplus extern C { #endif @@ -1117,6 +1120,15 @@ void util_format_compose_swizzles(const unsigned char swz1[4], const unsigned char swz2[4], unsigned char dst[4]); +/* Apply the swizzle provided in \param swz (which is one of PIPE_SWIZZLE_x) + * to \param src and store the result in \param dst. + * \param is_integer determines the value written for PIPE_SWIZZLE_ONE. + */ +void util_format_apply_color_swizzle(union pipe_color_union *dst, + const union pipe_color_union *src, + const unsigned char swz[4], + const boolean is_integer); + void util_format_swizzle_4f(float *dst, const float *src, const unsigned char swz[4]); diff --git a/src/gallium/docs/source/cso/sampler.rst b/src/gallium/docs/source/cso/sampler.rst index 26ffc18..9959793 100644 --- a/src/gallium/docs/source/cso/sampler.rst +++ b/src/gallium/docs/source/cso/sampler.rst @@ -101,7 +101,9 @@ max_lod border_color Color union used for texel coordinates that are outside the [0,width-1], [0, height-1] or [0, depth-1] ranges. Interpreted according to