| 1 |
/* |
| 2 |
* Copyright (C) 2021 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "compiler/nir/nir_builder.h" |
| 7 |
#include "pan_nir.h" |
| 8 |
|
| 9 |
/* Lower gl_HelperInvocation to (gl_SampleMaskIn == 0), this depends on |
| 10 |
* architectural details but is more efficient than NIR's lowering. |
| 11 |
*/ |
| 12 |
static bool |
| 13 |
pan_lower_helper_invocation_instr(nir_builder *b, nir_intrinsic_instr *intr, |
| 14 |
void *data) |
| 15 |
{ |
| 16 |
if (intr->intrinsic != nir_intrinsic_load_helper_invocation) |
| 17 |
return false; |
| 18 |
|
| 19 |
b->cursor = nir_before_instr(&intr->instr); |
| 20 |
|
| 21 |
nir_def *mask = nir_load_sample_mask_in(b); |
| 22 |
nir_def_replace(&intr->def, nir_ieq_imm(b, mask, 0)); |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
bool |
| 27 |
pan_nir_lower_helper_invocation(nir_shader *shader) |
| 28 |
{ |
| 29 |
return nir_shader_intrinsics_pass(shader, pan_lower_helper_invocation_instr, |
| 30 |
nir_metadata_control_flow, NULL); |
| 31 |
} |