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;
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;
#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)
{
*/
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 */