mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-02 23:09:05 +02:00
util: Add util_format_get_component_shift
Similar to util_format_get_component_bits, get the bit offset for a particular channel in a given format. Use this to calculate the shift/mask sets for formats when creating DRI configs, as a prelude to ripping out and replacing the hardcoded table. Signed-off-by: Daniel Stone <daniels@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27709>
This commit is contained in:
parent
b3d419ad24
commit
d3ed00f38a
2 changed files with 48 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue