panfrost/nir: Apply NIR style
$ astyle *.c *.h --style=linux -s3 Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
This commit is contained in:
@@ -38,9 +38,9 @@
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_blend_func(
|
||||
nir_builder *b,
|
||||
enum blend_func func,
|
||||
nir_ssa_def *src, nir_ssa_def *dst)
|
||||
nir_builder *b,
|
||||
enum blend_func func,
|
||||
nir_ssa_def *src, nir_ssa_def *dst)
|
||||
{
|
||||
switch (func) {
|
||||
case BLEND_FUNC_ADD:
|
||||
@@ -76,9 +76,9 @@ nir_blend_factored(enum blend_func func)
|
||||
/* Compute a src_alpha_saturate factor */
|
||||
static nir_ssa_def *
|
||||
nir_alpha_saturate(
|
||||
nir_builder *b,
|
||||
nir_ssa_def *src, nir_ssa_def *dst,
|
||||
unsigned chan)
|
||||
nir_builder *b,
|
||||
nir_ssa_def *src, nir_ssa_def *dst,
|
||||
unsigned chan)
|
||||
{
|
||||
nir_ssa_def *Asrc = nir_channel(b, src, 3);
|
||||
nir_ssa_def *Adst = nir_channel(b, dst, 3);
|
||||
@@ -92,10 +92,10 @@ nir_alpha_saturate(
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_blend_factor_value(
|
||||
nir_builder *b,
|
||||
nir_ssa_def *src, nir_ssa_def *dst, nir_ssa_def *bconst,
|
||||
unsigned chan,
|
||||
enum blend_factor factor)
|
||||
nir_builder *b,
|
||||
nir_ssa_def *src, nir_ssa_def *dst, nir_ssa_def *bconst,
|
||||
unsigned chan,
|
||||
enum blend_factor factor)
|
||||
{
|
||||
switch (factor) {
|
||||
case BLEND_FACTOR_ZERO:
|
||||
@@ -121,12 +121,12 @@ nir_blend_factor_value(
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_blend_factor(
|
||||
nir_builder *b,
|
||||
nir_ssa_def *raw_scalar,
|
||||
nir_ssa_def *src, nir_ssa_def *dst, nir_ssa_def *bconst,
|
||||
unsigned chan,
|
||||
enum blend_factor factor,
|
||||
bool inverted)
|
||||
nir_builder *b,
|
||||
nir_ssa_def *raw_scalar,
|
||||
nir_ssa_def *src, nir_ssa_def *dst, nir_ssa_def *bconst,
|
||||
unsigned chan,
|
||||
enum blend_factor factor,
|
||||
bool inverted)
|
||||
{
|
||||
nir_ssa_def *f =
|
||||
nir_blend_factor_value(b, src, dst, bconst, chan, factor);
|
||||
@@ -141,15 +141,15 @@ nir_blend_factor(
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_color_mask(
|
||||
nir_builder *b,
|
||||
unsigned mask,
|
||||
nir_ssa_def *src,
|
||||
nir_ssa_def *dst)
|
||||
nir_builder *b,
|
||||
unsigned mask,
|
||||
nir_ssa_def *src,
|
||||
nir_ssa_def *dst)
|
||||
{
|
||||
nir_ssa_def *masked[4];
|
||||
|
||||
for (unsigned c = 0; c < 4; ++c) {
|
||||
bool enab = (mask & (1 << c));
|
||||
bool enab = (mask & (1 << c));
|
||||
masked[c] = enab ? nir_channel(b, src, c) : nir_channel(b, dst, c);
|
||||
}
|
||||
|
||||
@@ -162,9 +162,9 @@ nir_color_mask(
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_blend(
|
||||
nir_builder *b,
|
||||
nir_lower_blend_options options,
|
||||
nir_ssa_def *src, nir_ssa_def *dst)
|
||||
nir_builder *b,
|
||||
nir_lower_blend_options options,
|
||||
nir_ssa_def *src, nir_ssa_def *dst)
|
||||
{
|
||||
/* Grab the blend constant ahead of time */
|
||||
nir_ssa_def *bconst = nir_f2f16(b, nir_load_blend_const_color_rgba(b));
|
||||
@@ -182,14 +182,14 @@ nir_blend(
|
||||
|
||||
if (nir_blend_factored(chan.func)) {
|
||||
psrc = nir_blend_factor(
|
||||
b, psrc,
|
||||
src, dst, bconst, c,
|
||||
chan.src_factor, chan.invert_src_factor);
|
||||
b, psrc,
|
||||
src, dst, bconst, c,
|
||||
chan.src_factor, chan.invert_src_factor);
|
||||
|
||||
pdst = nir_blend_factor(
|
||||
b, pdst,
|
||||
src, dst, bconst, c,
|
||||
chan.dst_factor, chan.invert_dst_factor);
|
||||
b, pdst,
|
||||
src, dst, bconst, c,
|
||||
chan.dst_factor, chan.invert_dst_factor);
|
||||
}
|
||||
|
||||
channels[c] = nir_blend_func(b, chan.func, psrc, pdst);
|
||||
@@ -260,7 +260,7 @@ nir_lower_blend(nir_shader *shader, nir_lower_blend_options options)
|
||||
/* Write out the final color instead of the input */
|
||||
nir_instr_rewrite_src(instr, &intr->src[1],
|
||||
nir_src_for_ssa(blended));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,13 +33,13 @@
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
enum blend_func func;
|
||||
enum blend_func func;
|
||||
|
||||
enum blend_factor src_factor;
|
||||
bool invert_src_factor;
|
||||
enum blend_factor src_factor;
|
||||
bool invert_src_factor;
|
||||
|
||||
enum blend_factor dst_factor;
|
||||
bool invert_dst_factor;
|
||||
enum blend_factor dst_factor;
|
||||
bool invert_dst_factor;
|
||||
} nir_lower_blend_channel;
|
||||
|
||||
typedef struct {
|
||||
|
@@ -56,7 +56,7 @@ nir_float_to_unorm8(nir_builder *b, nir_ssa_def *c_float)
|
||||
|
||||
/* Next, we type convert */
|
||||
nir_ssa_def *converted = nir_u2u8(b, nir_f2u16(b,
|
||||
nir_fround_even(b, scaled)));
|
||||
nir_fround_even(b, scaled)));
|
||||
|
||||
return converted;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ nir_float_to_unorm4(nir_builder *b, nir_ssa_def *c_float)
|
||||
|
||||
/* Next, we type convert to u16 */
|
||||
nir_ssa_def *converted = nir_f2u16(b,
|
||||
nir_fround_even(b, scaled));
|
||||
nir_fround_even(b, scaled));
|
||||
|
||||
/* In u16 land, we now need to pack */
|
||||
nir_ssa_def *cr = nir_channel(b, converted, 0);
|
||||
@@ -96,8 +96,8 @@ nir_float_to_unorm4(nir_builder *b, nir_ssa_def *c_float)
|
||||
|
||||
nir_ssa_def *pack =
|
||||
nir_ior(b,
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 4))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 8)), nir_ishl(b, ca, nir_imm_int(b, 12))));
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 4))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 8)), nir_ishl(b, ca, nir_imm_int(b, 12))));
|
||||
|
||||
return pack;
|
||||
}
|
||||
@@ -109,10 +109,10 @@ nir_float_to_rgb10a2(nir_builder *b, nir_ssa_def *c_float, bool normalize)
|
||||
|
||||
if (normalize) {
|
||||
nir_ssa_def *scaled = nir_fmul(b, nir_fsat(b, c_float),
|
||||
nir_imm_vec4(b, 1023.0, 1023.0, 1023.0, 3.0));
|
||||
nir_imm_vec4(b, 1023.0, 1023.0, 1023.0, 3.0));
|
||||
|
||||
converted = nir_f2u32(b,
|
||||
nir_fround_even(b, scaled));
|
||||
nir_fround_even(b, scaled));
|
||||
}
|
||||
|
||||
nir_ssa_def *cr = nir_channel(b, converted, 0);
|
||||
@@ -122,8 +122,8 @@ nir_float_to_rgb10a2(nir_builder *b, nir_ssa_def *c_float, bool normalize)
|
||||
|
||||
nir_ssa_def *pack =
|
||||
nir_ior(b,
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 10))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 20)), nir_ishl(b, ca, nir_imm_int(b, 30))));
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 10))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 20)), nir_ishl(b, ca, nir_imm_int(b, 30))));
|
||||
|
||||
return pack;
|
||||
}
|
||||
@@ -134,10 +134,10 @@ nir_float_to_rgb5a1(nir_builder *b, nir_ssa_def *c_float)
|
||||
nir_ssa_def *degraded = nir_f2f16(b, c_float);
|
||||
|
||||
nir_ssa_def *scaled = nir_fmul(b, nir_fsat(b, degraded),
|
||||
nir_imm_vec4_16(b, 31.0, 31.0, 31.0, 1.0));
|
||||
nir_imm_vec4_16(b, 31.0, 31.0, 31.0, 1.0));
|
||||
|
||||
nir_ssa_def *converted = nir_f2u16(b,
|
||||
nir_fround_even(b, scaled));
|
||||
nir_fround_even(b, scaled));
|
||||
|
||||
nir_ssa_def *cr = nir_channel(b, converted, 0);
|
||||
nir_ssa_def *cg = nir_channel(b, converted, 1);
|
||||
@@ -146,18 +146,18 @@ nir_float_to_rgb5a1(nir_builder *b, nir_ssa_def *c_float)
|
||||
|
||||
nir_ssa_def *pack =
|
||||
nir_ior(b,
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 5))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 10)), nir_ishl(b, ca, nir_imm_int(b, 15))));
|
||||
nir_ior(b, cr, nir_ishl(b, cg, nir_imm_int(b, 5))),
|
||||
nir_ior(b, nir_ishl(b, cb, nir_imm_int(b, 10)), nir_ishl(b, ca, nir_imm_int(b, 15))));
|
||||
|
||||
return pack;
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_shader_to_native(nir_builder *b,
|
||||
nir_ssa_def *c_shader,
|
||||
const struct util_format_description *desc,
|
||||
unsigned bits,
|
||||
bool homogenous_bits)
|
||||
nir_ssa_def *c_shader,
|
||||
const struct util_format_description *desc,
|
||||
unsigned bits,
|
||||
bool homogenous_bits)
|
||||
{
|
||||
bool float_or_pure_int =
|
||||
util_format_is_float(desc->format) ||
|
||||
@@ -173,40 +173,40 @@ nir_shader_to_native(nir_builder *b,
|
||||
|
||||
/* Special formats */
|
||||
switch (desc->format) {
|
||||
case PIPE_FORMAT_B4G4R4A4_UNORM:
|
||||
case PIPE_FORMAT_B4G4R4X4_UNORM:
|
||||
case PIPE_FORMAT_A4R4_UNORM:
|
||||
case PIPE_FORMAT_R4A4_UNORM:
|
||||
case PIPE_FORMAT_A4B4G4R4_UNORM:
|
||||
return nir_float_to_unorm4(b, c_shader);
|
||||
case PIPE_FORMAT_B4G4R4A4_UNORM:
|
||||
case PIPE_FORMAT_B4G4R4X4_UNORM:
|
||||
case PIPE_FORMAT_A4R4_UNORM:
|
||||
case PIPE_FORMAT_R4A4_UNORM:
|
||||
case PIPE_FORMAT_A4B4G4R4_UNORM:
|
||||
return nir_float_to_unorm4(b, c_shader);
|
||||
|
||||
case PIPE_FORMAT_R10G10B10A2_UNORM:
|
||||
case PIPE_FORMAT_B10G10R10A2_UNORM:
|
||||
case PIPE_FORMAT_R10G10B10X2_UNORM:
|
||||
case PIPE_FORMAT_B10G10R10X2_UNORM:
|
||||
return nir_float_to_rgb10a2(b, c_shader, true);
|
||||
case PIPE_FORMAT_R10G10B10A2_UNORM:
|
||||
case PIPE_FORMAT_B10G10R10A2_UNORM:
|
||||
case PIPE_FORMAT_R10G10B10X2_UNORM:
|
||||
case PIPE_FORMAT_B10G10R10X2_UNORM:
|
||||
return nir_float_to_rgb10a2(b, c_shader, true);
|
||||
|
||||
case PIPE_FORMAT_R10G10B10A2_UINT:
|
||||
return nir_float_to_rgb10a2(b, c_shader, false);
|
||||
case PIPE_FORMAT_R10G10B10A2_UINT:
|
||||
return nir_float_to_rgb10a2(b, c_shader, false);
|
||||
|
||||
case PIPE_FORMAT_B5G5R5A1_UNORM:
|
||||
return nir_float_to_rgb5a1(b, c_shader);
|
||||
case PIPE_FORMAT_B5G5R5A1_UNORM:
|
||||
return nir_float_to_rgb5a1(b, c_shader);
|
||||
|
||||
case PIPE_FORMAT_R11G11B10_FLOAT:
|
||||
return nir_format_pack_11f11f10f(b, c_shader);
|
||||
case PIPE_FORMAT_R11G11B10_FLOAT:
|
||||
return nir_format_pack_11f11f10f(b, c_shader);
|
||||
|
||||
default:
|
||||
printf("%s\n", desc->name);
|
||||
unreachable("Unknown format name");
|
||||
default:
|
||||
printf("%s\n", desc->name);
|
||||
unreachable("Unknown format name");
|
||||
}
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
nir_native_to_shader(nir_builder *b,
|
||||
nir_ssa_def *c_native,
|
||||
const struct util_format_description *desc,
|
||||
unsigned bits,
|
||||
bool homogenous_bits)
|
||||
nir_ssa_def *c_native,
|
||||
const struct util_format_description *desc,
|
||||
unsigned bits,
|
||||
bool homogenous_bits)
|
||||
{
|
||||
bool float_or_pure_int =
|
||||
util_format_is_float(desc->format) ||
|
||||
|
@@ -46,42 +46,42 @@ bool nir_undef_to_zero(nir_shader *shader);
|
||||
bool
|
||||
nir_undef_to_zero(nir_shader *shader)
|
||||
{
|
||||
bool progress = false;
|
||||
bool progress = false;
|
||||
|
||||
nir_foreach_function(function, shader) {
|
||||
if (!function->impl) continue;
|
||||
nir_foreach_function(function, shader) {
|
||||
if (!function->impl) continue;
|
||||
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, function->impl);
|
||||
nir_builder b;
|
||||
nir_builder_init(&b, function->impl);
|
||||
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_ssa_undef) continue;
|
||||
nir_foreach_block(block, function->impl) {
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_ssa_undef) continue;
|
||||
|
||||
nir_ssa_undef_instr *und = nir_instr_as_ssa_undef(instr);
|
||||
nir_ssa_undef_instr *und = nir_instr_as_ssa_undef(instr);
|
||||
|
||||
/* Get the required size */
|
||||
unsigned c = und->def.num_components;
|
||||
unsigned s = und->def.bit_size;
|
||||
/* Get the required size */
|
||||
unsigned c = und->def.num_components;
|
||||
unsigned s = und->def.bit_size;
|
||||
|
||||
nir_const_value v[NIR_MAX_VEC_COMPONENTS];
|
||||
memset(v, 0, sizeof(v));
|
||||
nir_const_value v[NIR_MAX_VEC_COMPONENTS];
|
||||
memset(v, 0, sizeof(v));
|
||||
|
||||
b.cursor = nir_before_instr(instr);
|
||||
nir_ssa_def *zero = nir_build_imm(&b, c, s, v);
|
||||
nir_src zerosrc = nir_src_for_ssa(zero);
|
||||
b.cursor = nir_before_instr(instr);
|
||||
nir_ssa_def *zero = nir_build_imm(&b, c, s, v);
|
||||
nir_src zerosrc = nir_src_for_ssa(zero);
|
||||
|
||||
nir_ssa_def_rewrite_uses(&und->def, zerosrc);
|
||||
nir_ssa_def_rewrite_uses(&und->def, zerosrc);
|
||||
|
||||
progress |= true;
|
||||
}
|
||||
}
|
||||
progress |= true;
|
||||
}
|
||||
}
|
||||
|
||||
nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);
|
||||
nir_metadata_preserve(function->impl, nir_metadata_block_index | nir_metadata_dominance);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return progress;
|
||||
return progress;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user