mesa/src/asahi/lib/agx_nir_format_helpers.h
Alyssa Rosenzweig 75b858e904 asahi: Support more renderable formats
Fixes KHR-GLES3.copy_tex_image_conversions.forbidden.*

Arguably working around a mesa/st issue but more format support is good for
compatibility and performance anyway.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Janne Grunau <j@jannau.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22353>
2023-04-07 03:23:03 +00:00

32 lines
807 B
C

/*
* Copyright 2022 Alyssa Rosenzweig
* SPDX-License-Identifier: MIT
*/
#ifndef __AGX_NIR_FORMAT_HELPERS_H
#define __AGX_NIR_FORMAT_HELPERS_H
#include "util/format/u_formats.h"
#include "nir_builder.h"
#include "nir_format_convert.h"
static inline nir_ssa_def *
nir_sign_extend_if_sint(nir_builder *b, nir_ssa_def *x, enum pipe_format format)
{
if (!util_format_is_pure_sint(format))
return x;
const struct util_format_description *desc = util_format_description(format);
unsigned bits[4] = {0};
for (unsigned i = 0; i < desc->nr_channels; ++i) {
assert(desc->channel[i].type == UTIL_FORMAT_TYPE_SIGNED ||
desc->channel[i].type == UTIL_FORMAT_TYPE_VOID);
bits[i] = desc->channel[i].size;
}
return nir_format_sign_extend_ivec(b, x, bits);
}
#endif