mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 04:50:11 +01:00
nir: Pull some of intel's image load/store format conversion to nir_format.h
I needed the same functions for v3d. Note that the color value in the Intel lowering has already been cut down to image.chans num_components. v2: Drop the half float one, since it was a 1-liner after cleanup. Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
19c7cba2ab
commit
d3e046e76c
2 changed files with 40 additions and 18 deletions
|
|
@ -282,6 +282,44 @@ nir_format_srgb_to_linear(nir_builder *b, nir_ssa_def *c)
|
|||
linear, curved));
|
||||
}
|
||||
|
||||
/* Clamps a vector of uints so they don't extend beyond the given number of
|
||||
* bits per channel.
|
||||
*/
|
||||
static inline nir_ssa_def *
|
||||
nir_format_clamp_uint(nir_builder *b, nir_ssa_def *f, const unsigned *bits)
|
||||
{
|
||||
if (bits[0] == 32)
|
||||
return f;
|
||||
|
||||
nir_const_value max;
|
||||
for (unsigned i = 0; i < f->num_components; i++) {
|
||||
assert(bits[i] < 32);
|
||||
max.i32[i] = (1 << (bits[i] - 1)) - 1;
|
||||
}
|
||||
return nir_umin(b, f, nir_build_imm(b, f->num_components, 32, max));
|
||||
}
|
||||
|
||||
/* Clamps a vector of sints so they don't extend beyond the given number of
|
||||
* bits per channel.
|
||||
*/
|
||||
static inline nir_ssa_def *
|
||||
nir_format_clamp_sint(nir_builder *b, nir_ssa_def *f, const unsigned *bits)
|
||||
{
|
||||
if (bits[0] == 32)
|
||||
return f;
|
||||
|
||||
nir_const_value min, max;
|
||||
for (unsigned i = 0; i < f->num_components; i++) {
|
||||
assert(bits[i] < 32);
|
||||
max.i32[i] = (1 << (bits[i] - 1)) - 1;
|
||||
min.i32[i] = -(1 << (bits[i] - 1));
|
||||
}
|
||||
f = nir_imin(b, f, nir_build_imm(b, f->num_components, 32, max));
|
||||
f = nir_imax(b, f, nir_build_imm(b, f->num_components, 32, min));
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
static inline nir_ssa_def *
|
||||
nir_format_unpack_11f11f10f(nir_builder *b, nir_ssa_def *packed)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -555,27 +555,11 @@ convert_color_for_store(nir_builder *b, const struct gen_device_info *devinfo,
|
|||
break;
|
||||
|
||||
case ISL_UINT:
|
||||
if (image.bits[0] < 32) {
|
||||
nir_const_value max;
|
||||
for (unsigned i = 0; i < image.chans; i++) {
|
||||
assert(image.bits[i] < 32);
|
||||
max.u32[i] = (1u << image.bits[i]) - 1;
|
||||
}
|
||||
color = nir_umin(b, color, nir_build_imm(b, image.chans, 32, max));
|
||||
}
|
||||
color = nir_format_clamp_uint(b, color, image.bits);
|
||||
break;
|
||||
|
||||
case ISL_SINT:
|
||||
if (image.bits[0] < 32) {
|
||||
nir_const_value min, max;
|
||||
for (unsigned i = 0; i < image.chans; i++) {
|
||||
assert(image.bits[i] < 32);
|
||||
max.i32[i] = (1 << (image.bits[i] - 1)) - 1;
|
||||
min.i32[i] = -(1 << (image.bits[i] - 1));
|
||||
}
|
||||
color = nir_imin(b, color, nir_build_imm(b, image.chans, 32, max));
|
||||
color = nir_imax(b, color, nir_build_imm(b, image.chans, 32, min));
|
||||
}
|
||||
color = nir_format_clamp_sint(b, color, image.bits);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue