summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers
diff options
context:
space:
mode:
authorKenneth Graunke <[email protected]>2012-09-21 03:13:36 -0700
committerKenneth Graunke <[email protected]>2012-09-26 22:58:30 -0700
commit6d6aef79742ece3bb570ae44e6c13791aae15e01 (patch)
treebe2be5d9f04fa2fda8a8de8d1dc5be85a3977240 /src/mesa/drivers
parentb5a042a657fed45264406cbd0d67fa6217a410a1 (diff)
i965: Do texture swizzling in hardware on Haswell.
Haswell supports EXT_texture_swizzle and legacy DEPTH_TEXTURE_MODE swizzling by setting SURFACE_STATE entries. This means we don't have to bake the swizzle settings into the shader code by emitting MOV instructions, and thus don't have to recompile shaders whenever the swizzles change. Unfortunately, we can't handle GL_ALPHA this way: unlike all the others, which store the comparison result in the .r channel (and possibly others as well), GL_ALPHA puts it in the .a channel. The GLSL 1.30+ style functions which return a float always simply return the .r channel, which would be zero if we handled this as a surface override. In this case, fall back to doing it the old way. DEPTH_TEXTURE_MODE = GL_ALPHA isn't an interesting performance path anyway. Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm.c12
-rw-r--r--src/mesa/drivers/dri/i965/gen7_wm_surface_state.c45
2 files changed, 52 insertions, 5 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 0f115259867..f8eb54fce1d 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -491,6 +491,8 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
const struct gl_program *prog,
struct brw_sampler_prog_key_data *key)
{
+ struct intel_context *intel = intel_context(ctx);
+
for (int s = 0; s < MAX_SAMPLERS; s++) {
key->swizzles[s] = SWIZZLE_NOOP;
@@ -505,7 +507,15 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id);
- key->swizzles[s] = brw_get_texture_swizzle(t);
+ const bool alpha_depth = t->DepthMode == GL_ALPHA &&
+ (img->_BaseFormat == GL_DEPTH_COMPONENT ||
+ img->_BaseFormat == GL_DEPTH_STENCIL);
+
+ /* Haswell handles texture swizzling as surface format overrides
+ * (except for GL_ALPHA); all other platforms need MOVs in the shader.
+ */
+ if (!intel->is_haswell || alpha_depth)
+ key->swizzles[s] = brw_get_texture_swizzle(t);
if (img->InternalFormat == GL_YCBCR_MESA) {
key->yuvtex_mask |= 1 << s;
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index 97ae0e2f9a4..dd7b0d4cfe1 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -35,6 +35,32 @@
#include "brw_defines.h"
#include "brw_wm.h"
+/**
+ * Convert an swizzle enumeration (i.e. SWIZZLE_X) to one of the Gen7.5+
+ * "Shader Channel Select" enumerations (i.e. HSW_SCS_RED)
+ */
+static unsigned
+swizzle_to_scs(GLenum swizzle)
+{
+ switch (swizzle) {
+ case SWIZZLE_X:
+ return HSW_SCS_RED;
+ case SWIZZLE_Y:
+ return HSW_SCS_GREEN;
+ case SWIZZLE_Z:
+ return HSW_SCS_BLUE;
+ case SWIZZLE_W:
+ return HSW_SCS_ALPHA;
+ case SWIZZLE_ZERO:
+ return HSW_SCS_ZERO;
+ case SWIZZLE_ONE:
+ return HSW_SCS_ONE;
+ }
+
+ assert(!"Should not get here: invalid swizzle mode");
+ return HSW_SCS_ZERO;
+}
+
void
gen7_set_surface_tiling(struct gen7_surface_state *surf, uint32_t tiling)
{
@@ -343,10 +369,21 @@ gen7_update_texture_surface(struct gl_context *ctx,
*/
if (brw->intel.is_haswell) {
- surf->ss7.shader_channel_select_r = HSW_SCS_RED;
- surf->ss7.shader_channel_select_g = HSW_SCS_GREEN;
- surf->ss7.shader_channel_select_b = HSW_SCS_BLUE;
- surf->ss7.shader_channel_select_a = HSW_SCS_ALPHA;
+ /* Handling GL_ALPHA as a surface format override breaks 1.30+ style
+ * texturing functions that return a float, as our code generation always
+ * selects the .x channel (which would always be 0).
+ */
+ const bool alpha_depth = tObj->DepthMode == GL_ALPHA &&
+ (firstImage->_BaseFormat == GL_DEPTH_COMPONENT ||
+ firstImage->_BaseFormat == GL_DEPTH_STENCIL);
+
+ const int swizzle =
+ unlikely(alpha_depth) ? SWIZZLE_XYZW : brw_get_texture_swizzle(tObj);
+
+ surf->ss7.shader_channel_select_r = swizzle_to_scs(GET_SWZ(swizzle, 0));
+ surf->ss7.shader_channel_select_g = swizzle_to_scs(GET_SWZ(swizzle, 1));
+ surf->ss7.shader_channel_select_b = swizzle_to_scs(GET_SWZ(swizzle, 2));
+ surf->ss7.shader_channel_select_a = swizzle_to_scs(GET_SWZ(swizzle, 3));
}
/* Emit relocation to surface contents */