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:
/* 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);
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:
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);
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);
}
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));
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);
/* Write out the final color instead of the input */
nir_instr_rewrite_src(instr, &intr->src[1],
nir_src_for_ssa(blended));
-
+
}
}
/* 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;
}
/* 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);
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;
}
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);
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;
}
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);
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) ||
/* 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_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_B5G5R5A1_UNORM:
- return nir_float_to_rgb5a1(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");
+ 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_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_R11G11B10_FLOAT:
+ return nir_format_pack_11f11f10f(b, c_shader);
+
+ 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) ||
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;
}