Skip to content

intel/brw: Add builder helpers that allocate temporary destinations, allowing expression-tree construction

Kenneth Graunke requested to merge kwg/mesa:brw-builder into main

In many cases, we calculate an expression by generating a series of instructions. We'd either overwrite the same register repeatedly, or call vgrf(BRW_TYPE_X) repeatedly to allocate temporaries for each intermediate step. In many cases, we overwrote the same register simply because allocating and naming temporaries for each step was annoying.

This MR adds new builder helpers that automatically allocate a temporary destination for you. They use simple type inference:

  • Unary operations simply reuse the source type. (These helpers can't be used for conversions.)
  • Binary operations require the same base type, but return the larger of the two bit-sizes. For example, [D, W] -> D.
  • The size is always a single scalar (vec1) value. (If you need vec4's, allocate a temporary yourself.)

The helpers return the destination register, allowing us to write in an expression-tree style, chaining together builder operations to produce whole values. Sort of like nir_builder. We still optionally will write out the fs_inst pointer in case the caller wants to do things like set predicates or saturation.

This will help reduce the number of places where we overwrite the same temporary register multiple times, which is non-SSA visible. This would improve the visibility of partial-SSA passes in !28666 (merged).

fossil-db statistics are basically inconsequential except for Wolfenstein Youngblood which looks to be improved.

Merge request reports