From 7ffef1794b156433112126b65ba8ce488617295d Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 9 May 2017 14:47:40 -0700 Subject: [PATCH] Sanitize swizzles --- src/intel/isl/isl_surface_state.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/intel/isl/isl_surface_state.c b/src/intel/isl/isl_surface_state.c index fa46469..dec575c 100644 --- a/src/intel/isl/isl_surface_state.c +++ b/src/intel/isl/isl_surface_state.c @@ -233,6 +233,27 @@ get_qpitch(const struct isl_surf *surf) } #endif /* GEN_GEN >= 8 */ +#if GEN_GEN >= 8 || GEN_IS_HASWELL +static inline enum isl_channel_select +fixup_swizzle(const struct isl_surf_fill_state_info *restrict info, + enum isl_channel_select scs) +{ + const struct isl_format_layout *fmtl = + isl_format_get_layout(info->view->format); + + switch (scs) { + case ISL_CHANNEL_SELECT_GREEN: + return fmtl->channels.g.bits ? scs : ISL_CHANNEL_SELECT_ZERO; + case ISL_CHANNEL_SELECT_BLUE: + return fmtl->channels.b.bits ? scs : ISL_CHANNEL_SELECT_ZERO; + case ISL_CHANNEL_SELECT_ALPHA: + return fmtl->channels.a.bits ? scs : ISL_CHANNEL_SELECT_ONE; + default: + return scs; + } +} +#endif + void isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state, const struct isl_surf_fill_state_info *restrict info) @@ -485,10 +506,11 @@ isl_genX(surf_fill_state_s)(const struct isl_device *dev, void *state, */ assert(info->view->swizzle.a == ISL_CHANNEL_SELECT_ALPHA); } - s.ShaderChannelSelectRed = info->view->swizzle.r; - s.ShaderChannelSelectGreen = info->view->swizzle.g; - s.ShaderChannelSelectBlue = info->view->swizzle.b; - s.ShaderChannelSelectAlpha = info->view->swizzle.a; + + s.ShaderChannelSelectRed = fixup_swizzle(info, info->view->swizzle.r); + s.ShaderChannelSelectGreen = fixup_swizzle(info, info->view->swizzle.g); + s.ShaderChannelSelectBlue = fixup_swizzle(info, info->view->swizzle.b); + s.ShaderChannelSelectAlpha = fixup_swizzle(info, info->view->swizzle.a); #endif s.SurfaceBaseAddress = info->address; -- 2.5.0.400.gff86faf