diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c index 0ad60ff1d87..729ededa024 100644 --- a/src/gallium/frontends/dri/dri_screen.c +++ b/src/gallium/frontends/dri/dri_screen.c @@ -286,6 +286,11 @@ driCreateConfigs(enum pipe_format format, for (i = 0; i < 4; i++) { color_bits[i] = util_format_get_component_bits(format, UTIL_FORMAT_COLORSPACE_RGB, i); + int f_shift = + util_format_get_component_shift(format, UTIL_FORMAT_COLORSPACE_RGB, i); + assert(f_shift == shifts[i] || (f_shift == 0 && shifts[i] == -1)); + uint32_t f_mask = ((1 << color_bits[i]) - 1) << f_shift; + assert(is_float || f_mask == masks[i]); } num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits * num_msaa_modes; diff --git a/src/util/format/u_format.h b/src/util/format/u_format.h index 8c42adf5b2d..4c64d414395 100644 --- a/src/util/format/u_format.h +++ b/src/util/format/u_format.h @@ -1000,6 +1000,49 @@ util_format_get_component_bits(enum pipe_format format, } } +static inline unsigned +util_format_get_component_shift(enum pipe_format format, + enum util_format_colorspace colorspace, + unsigned component) +{ + const struct util_format_description *desc = util_format_description(format); + enum util_format_colorspace desc_colorspace; + + assert(format); + if (!format) { + return 0; + } + + assert(component < 4); + + /* Treat RGB and SRGB as equivalent. */ + if (colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) { + desc_colorspace = UTIL_FORMAT_COLORSPACE_RGB; + } else { + desc_colorspace = desc->colorspace; + } + + if (desc_colorspace != colorspace) { + return 0; + } + + switch (desc->swizzle[component]) { + case PIPE_SWIZZLE_X: + return desc->channel[0].shift; + case PIPE_SWIZZLE_Y: + return desc->channel[1].shift; + case PIPE_SWIZZLE_Z: + return desc->channel[2].shift; + case PIPE_SWIZZLE_W: + return desc->channel[3].shift; + default: + return 0; + } +} + /** * Given a linear RGB colorspace format, return the corresponding SRGB * format, or PIPE_FORMAT_NONE if none.