nir: Add read_invocation_cond_ir3 intrinsic
authorConnor Abbott <cwabbott0@gmail.com>
Mon, 14 Sep 2020 08:14:55 +0000 (10:14 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 8 Jul 2021 16:02:41 +0000 (16:02 +0000)
commitcc514bfa0e29a46498f88ffa4a9e6dd92b3e3d58
tree530a4672e393f9c40c8f5258ea521cd71de1efc7
parente4e79de2a420128190b28b39b87f6de39b1b7060
nir: Add read_invocation_cond_ir3 intrinsic

On qualcomm, we have shared registers similar to SGPR's on AMD. However,
there is no readlane or readfirstlane primitive. shared registers can
only be written to when just one lane is active. This means that we have
to lower readInvocation(val, id) to something like:

if (gl_SubgroupInvocation == id) {
    scalar_reg = val;
}

return scalar_reg;

However it's a bit difficult to actually get the value of
gl_SubgroupInvocation in the backend, because for compute it requires
some calculations and we don't have any CSE support in the backend. This
intrinsic lets us turn it into
"readInvocationCond(val, id == gl_SubgroupInvocation)" in NIR at which
point the backend code generation is a lot easier.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6752>
src/compiler/nir/nir.h
src/compiler/nir/nir_control_flow [new file with mode: 0644]
src/compiler/nir/nir_intrinsics.py
src/compiler/nir/nir_lower_subgroups.c