<div dir="ltr">Thanks! I've pushed the first 13.<br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 22, 2018 at 6:06 PM Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Patches 1 through 13 are<br>
<br>
Reviewed-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><br>
<br>
The rest are going to take a bit more time and deep thought.<br>
<br>
On 10/22/2018 03:13 PM, Jason Ekstrand wrote:<br>
> This is something that Connor and I have talked about quite a bit over the<br>
> last couple of months. The core idea is to replace NIR's current 32-bit<br>
> 0/-1 D3D10-style booleans with a 1-bit data type. All in all, I think it<br>
> worked out pretty well though I really don't like the proliferation of<br>
> 32-bit comparison opcodes we now have kicking around for i965.<br>
> <br>
> Why? No hardware really has a 1-bit type, right? Well, sort of... AMD<br>
> actually uses 64-bit scalars for booleans with one bit per invocation.<br>
> However, most hardware such as Intel uses some other larger value for<br>
> booleans. The real benefit of 1-bit booleans and requiring a lowering pass<br>
> is that you can do somewhat custom lowering (like AMD wants) and your<br>
> lowering pass can always tell in an instant if a value is a boolean based<br>
> on the bit size. As can be seen in the last patch, this makes it really<br>
> easy to implement a bool -> float lowering pass for hardware that doesn't<br>
> have real integers where NIR's current booleans are actually rather<br>
> painful.<br>
> <br>
> On Intel, the situation is a bit more complicated. It's tempting to say<br>
> that we have 32-bit D3D10 booleans. However, they're not really D3D10<br>
> booleans on gen4-5 because the top 31 bits are undefined garbage and, while<br>
> iand, ior, ixor, and inot operations work, you have to iand with 1 at the<br>
> last minute to clear off all that garbage. Also, on all generations, a<br>
> comparison of two N-bit values results in an N-bit boolean, not a 32-bit<br>
> bool. This has caused the Igalia folks no end of trouble as they've been<br>
> working on native 8 and 16-bit support. If, instead, we have a 1-bit bool<br>
> with a lowering pass and we can lower to whatever we want, then we could<br>
> lower to a set of comparison opcodes that return the same bit-size as they<br>
> compare and it would match GEN hardware much better.<br>
> <br>
> But what about performance? Aren't there all sorts of neat tricks we can<br>
> do with D3D10 booleans like b & 1.0f for b2f? As it turns out, not really;<br>
> that's about the only one. There is some small advantage when optimizing<br>
> shaders that come from D3D if your native representation of booleans<br>
> matches that of D3D. However, penultimate patch in this series adds a few<br>
> small optimizations that get us to actually better than we were before.<br>
> With the entire series, shader-db on Kaby Lak looks like this:<br>
> <br>
> total instructions in shared programs: 15084098 -> 14988578 (-0.63%)<br>
> instructions in affected programs: 1321114 -> 1225594 (-7.23%)<br>
> helped: 2340<br>
> HURT: 23<br>
> <br>
> total cycles in shared programs: 369790134 -> 359798399 (-2.70%)<br>
> cycles in affected programs: 134085452 -> 124093717 (-7.45%)<br>
> helped: 2149<br>
> HURT: 720<br>
> <br>
> total loops in shared programs: 4393 -> 4393 (0.00%)<br>
> loops in affected programs: 0 -> 0<br>
> helped: 0<br>
> HURT: 0<br>
> <br>
> total spills in shared programs: 10158 -> 10051 (-1.05%)<br>
> spills in affected programs: 1429 -> 1322 (-7.49%)<br>
> helped: 8<br>
> HURT: 15<br>
> <br>
> total fills in shared programs: 22105 -> 21720 (-1.74%)<br>
> fills in affected programs: 2853 -> 2468 (-13.49%)<br>
> helped: 12<br>
> HURT: 15<br>
> <br>
> How about ease of use? Are they a pain to deal with? Yes, adding support<br>
> for 1-bit types was a bit awkward in a few places but most of it was<br>
> dealing with all the places where we have 32-bit booleans baked into<br>
> assumptions. Getting rid of that baking in solves the problem and also<br>
> makes the whole IR more future-proof.<br>
> <br>
> All in all, I'd say I'm pretty happy with it. However, I'd like other<br>
> people (particularly the AMD folks) to play with it a bit and verify that<br>
> it solves their problems as well. Also, I added a lowering pass and tried<br>
> to turn it on in everyone's driver but may not have put it in the right<br>
> spot. Please double-check my work. For those wishing to take a look, you<br>
> can also find the entire series on my gitlab here:<br>
> <br>
> <a href="https://gitlab.freedesktop.org/jekstrand/mesa/commits/review/nir-1-bit-bool" rel="noreferrer" target="_blank">https://gitlab.freedesktop.org/jekstrand/mesa/commits/review/nir-1-bit-bool</a><br>
> <br>
> Please review!<br>
> <br>
> --Jason<br>
> <br>
> Cc: Connor Abbott <<a href="mailto:cwabbott0@gmail.com" target="_blank">cwabbott0@gmail.com</a>><br>
> Cc: Timothy Arceri <<a href="mailto:tarceri@itsqueeze.com" target="_blank">tarceri@itsqueeze.com</a>><br>
> Cc: Eric Anholt <<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>><br>
> Cc: Rob Clark <<a href="mailto:robdclark@gmail.com" target="_blank">robdclark@gmail.com</a>><br>
> Cc: Karol Herbst <<a href="mailto:karolherbst@gmail.com" target="_blank">karolherbst@gmail.com</a>><br>
> Cc: Bas Nieuwenhuizen <<a href="mailto:bas@basnieuwenhuizen.nl" target="_blank">bas@basnieuwenhuizen.nl</a>><br>
> Cc: Alyssa Rosenzweig <<a href="mailto:alyssa@rosenzweig.io" target="_blank">alyssa@rosenzweig.io</a>><br>
> <br>
> <br>
> Jason Ekstrand (31):<br>
> nir/validate: Print when the validation failed<br>
> nir/constant_folding: Add an unreachable to a switch<br>
> nir/constant_folding: Use nir_src_as_bool for discard_if<br>
> nir/builder: Add a nir_imm_true/false helpers<br>
> nir/builder: Handle 16-bit floats in nir_imm_floatN_t<br>
> nir/search: Use nir_builder<br>
> nir/opt_if: Rework condition propagation<br>
> nir/system_values: Use the bit size from the load_deref<br>
> glsl/nir: Use i2b instead of ine for fixing UBO/SSBO booleans<br>
> nir/prog: Use nir_bany in kill handling<br>
> spirv: Use the right bit-size for spec constant ops<br>
> spirv: Initialize subgroup destinations with the destination type<br>
> intel/nir: Use the OPT macro for more passes<br>
> nir/algebraic: Disable b2f lowering and two optimizations<br>
> nir: Rename boolean-related opcodes to include 32 in the name<br>
> FIXUP: nir/builder: Generate 32-bit bool opcodes transparently<br>
> FIXUP: nir/algebraic: Remap boolean opcodes to the 32-bit variant<br>
> FIXUP: Use 32-bit opcodes in the NIR producers and optimizations<br>
> FIXUP: Use 32-bit opcodes in the NIR back-ends<br>
> nir/constant_expressions: Rework boolean handling<br>
> nir: Add support for 1-bit data types<br>
> nir: Add 1-bit boolean opcodes<br>
> nir: Add a bool to int32 lowering pass<br>
> glsl,spirv: Generate 1-bit booleans<br>
> FIXUP: Revert "Use 32-bit opcodes in the NIR producers and<br>
> optimizations"<br>
> FIXUP: Revert "nir/builder: Generate 32-bit bool opcodes<br>
> transparently"<br>
> FIXUP: nir/builder: Generate 1-bit booleans in nir_build_imm_bool<br>
> nir/algebraic: Optimize 1-bit booleans<br>
> nir/algebraic: Add back lower_b2f and a b2f optimization<br>
> nir/algebraic: Add some optimizations for D3D-style booleans<br>
> nir: Add a bool to float32 lowering pass<br>
> <br>
> src/amd/common/ac_nir_to_llvm.c | 30 +--<br>
> src/amd/vulkan/radv_shader.c | 6 +-<br>
> src/broadcom/compiler/nir_to_vir.c | 44 ++---<br>
> src/broadcom/compiler/vir.c | 2 +<br>
> src/compiler/Makefile.sources | 2 +<br>
> src/compiler/glsl/glsl_to_nir.cpp | 28 +--<br>
> src/compiler/nir/meson.build | 2 +<br>
> src/compiler/nir/nir.c | 15 +-<br>
> src/compiler/nir/nir.h | 36 ++--<br>
> src/compiler/nir/nir_algebraic.py | 22 ++-<br>
> src/compiler/nir/nir_builder.h | 51 ++++-<br>
> src/compiler/nir/nir_constant_expressions.py | 53 ++---<br>
> src/compiler/nir/nir_instr_set.c | 23 ++-<br>
> src/compiler/nir/nir_lower_alu_to_scalar.c | 4 +<br>
> src/compiler/nir/nir_lower_bool_to_float.c | 181 ++++++++++++++++++<br>
> src/compiler/nir/nir_lower_bool_to_int32.c | 162 ++++++++++++++++<br>
> src/compiler/nir/nir_lower_int64.c | 2 +-<br>
> .../nir/nir_lower_load_const_to_scalar.c | 3 +<br>
> src/compiler/nir/nir_lower_returns.c | 4 +-<br>
> src/compiler/nir/nir_lower_subgroups.c | 2 +-<br>
> src/compiler/nir/nir_lower_system_values.c | 1 +<br>
> src/compiler/nir/nir_opcodes.py | 31 ++-<br>
> src/compiler/nir/nir_opt_algebraic.py | 19 +-<br>
> src/compiler/nir/nir_opt_constant_folding.c | 18 +-<br>
> src/compiler/nir/nir_opt_if.c | 91 +++------<br>
> src/compiler/nir/nir_opt_intrinsics.c | 2 +-<br>
> src/compiler/nir/nir_opt_large_constants.c | 5 +<br>
> src/compiler/nir/nir_print.c | 3 +<br>
> src/compiler/nir/nir_search.c | 112 +++--------<br>
> src/compiler/nir/nir_search.h | 9 +-<br>
> src/compiler/nir/nir_validate.c | 16 +-<br>
> src/compiler/nir/tests/vars_tests.cpp | 38 ++--<br>
> src/compiler/nir_types.cpp | 2 +-<br>
> src/compiler/nir_types.h | 4 +-<br>
> src/compiler/spirv/spirv_to_nir.c | 23 ++-<br>
> src/compiler/spirv/vtn_alu.c | 4 +-<br>
> src/compiler/spirv/vtn_cfg.c | 10 +-<br>
> src/compiler/spirv/vtn_subgroup.c | 12 +-<br>
> src/gallium/auxiliary/nir/tgsi_to_nir.c | 20 +-<br>
> .../drivers/freedreno/ir3/ir3_compiler_nir.c | 31 +--<br>
> src/gallium/drivers/radeonsi/si_shader_nir.c | 2 +<br>
> src/gallium/drivers/vc4/vc4_program.c | 50 ++---<br>
> src/intel/compiler/brw_fs_nir.cpp | 80 ++++----<br>
> src/intel/compiler/brw_nir.c | 16 +-<br>
> .../brw_nir_analyze_boolean_resolves.c | 24 +--<br>
> .../compiler/brw_nir_lower_image_load_store.c | 2 +-<br>
> src/intel/compiler/brw_vec4_nir.cpp | 122 ++++++------<br>
> src/intel/vulkan/anv_pipeline.c | 2 +-<br>
> src/mesa/drivers/dri/i965/brw_program.c | 4 +-<br>
> src/mesa/main/glspirv.c | 2 +-<br>
> src/mesa/program/prog_to_nir.c | 2 +-<br>
> src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +-<br>
> 52 files changed, 934 insertions(+), 497 deletions(-)<br>
> create mode 100644 src/compiler/nir/nir_lower_bool_to_float.c<br>
> create mode 100644 src/compiler/nir/nir_lower_bool_to_int32.c<br>
> <br>
<br>
</blockquote></div>