nir_builder_instr_insert(build, ©->instr);
}
+/* Generic builder for system values. */
static inline nir_ssa_def *
nir_load_system_value(nir_builder *build, nir_intrinsic_op op, int index)
{
return &load->dest.ssa;
}
+/* Generate custom builders for system values. */
+#define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
+ num_variables, num_indices, idx0, idx1, idx2, flags)
+#define LAST_INTRINSIC(name)
+
+#define DEFINE_SYSTEM_VALUE(name) \
+ static inline nir_ssa_def * \
+ nir_load_##name(nir_builder *build) \
+ { \
+ return nir_load_system_value(build, nir_intrinsic_load_##name, 0); \
+ } \
+
+#include "nir_intrinsics.h"
+
static inline nir_ssa_def *
nir_load_barycentric(nir_builder *build, nir_intrinsic_op op,
unsigned interp_mode)
#define ARR(...) { __VA_ARGS__ }
-
INTRINSIC(load_var, 0, ARR(0), true, 0, 1, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, WRMASK, xx, xx, 0)
INTRINSIC(copy_var, 0, ARR(0), false, 0, 2, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_exchange, 2, ARR(1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
INTRINSIC(shared_atomic_comp_swap, 3, ARR(1, 1, 1), true, 1, 0, 1, BASE, xx, xx, 0)
+/* Used by nir_builder.h to generate loader helpers for the system values. */
+#ifndef DEFINE_SYSTEM_VALUE
+#define DEFINE_SYSTEM_VALUE(name)
+#endif
+
#define SYSTEM_VALUE(name, components, num_indices, idx0, idx1, idx2) \
+ DEFINE_SYSTEM_VALUE(name) \
INTRINSIC(load_##name, 0, ARR(0), true, components, 0, num_indices, \
idx0, idx1, idx2, \
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
LAST_INTRINSIC(store_shared)
+#undef DEFINE_SYSTEM_VALUE
#undef INTRINSIC
#undef LAST_INTRINSIC
local_size.u32[1] = b->shader->info.cs.local_size[1];
local_size.u32[2] = b->shader->info.cs.local_size[2];
- nir_ssa_def *group_id =
- nir_load_system_value(b, nir_intrinsic_load_work_group_id, 0);
- nir_ssa_def *local_id =
- nir_load_system_value(b, nir_intrinsic_load_local_invocation_id, 0);
+ nir_ssa_def *group_id = nir_load_work_group_id(b);
+ nir_ssa_def *local_id = nir_load_local_invocation_id(b);
sysval = nir_iadd(b, nir_imul(b, group_id,
nir_build_imm(b, 3, 32, local_size)),
* gl_WorkGroupSize.y + gl_LocalInvocationID.y *
* gl_WorkGroupSize.x + gl_LocalInvocationID.x"
*/
- nir_ssa_def *local_id =
- nir_load_system_value(b, nir_intrinsic_load_local_invocation_id, 0);
+ nir_ssa_def *local_id = nir_load_local_invocation_id(b);
nir_ssa_def *size_x = nir_imm_int(b, b->shader->info.cs.local_size[0]);
nir_ssa_def *size_y = nir_imm_int(b, b->shader->info.cs.local_size[1]);
case SYSTEM_VALUE_VERTEX_ID:
if (b->shader->options->vertex_id_zero_based) {
sysval = nir_iadd(b,
- nir_load_system_value(b, nir_intrinsic_load_vertex_id_zero_base, 0),
- nir_load_system_value(b, nir_intrinsic_load_base_vertex, 0));
+ nir_load_vertex_id_zero_base(b),
+ nir_load_base_vertex(b));
} else {
- sysval = nir_load_system_value(b, nir_intrinsic_load_vertex_id, 0);
+ sysval = nir_load_vertex_id(b);
}
break;
case SYSTEM_VALUE_INSTANCE_INDEX:
sysval = nir_iadd(b,
- nir_load_system_value(b, nir_intrinsic_load_instance_id, 0),
- nir_load_system_value(b, nir_intrinsic_load_base_instance, 0));
+ nir_load_instance_id(b),
+ nir_load_base_instance(b));
break;
default:
* bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
*/
b->cursor = nir_before_instr(&intr->instr);
- nir_ssa_def *face = nir_load_system_value(b,
- nir_intrinsic_load_front_face,
- 0);
+ nir_ssa_def *face = nir_load_front_face(b);
nir_ssa_def *front = load_input(b, state->colors[idx].front);
nir_ssa_def *back = load_input(b, state->colors[idx].back);
nir_ssa_def *color = nir_bcsel(b, face, front, back);
if (key->persample_msaa_dispatch) {
return nir_vec3(b, nir_channel(b, coord, 0), nir_channel(b, coord, 1),
- nir_load_system_value(b, nir_intrinsic_load_sample_id, 0));
+ nir_load_sample_id(b));
} else {
return nir_vec2(b, nir_channel(b, coord, 0), nir_channel(b, coord, 1));
}
* cs_thread_local_id + channel_num;
*/
nir_ssa_def *thread_local_id = read_thread_local_id(state);
- nir_ssa_def *channel =
- nir_load_system_value(b, nir_intrinsic_load_channel_num, 0);
+ nir_ssa_def *channel = nir_load_channel_num(b);
sysval = nir_iadd(b, channel, thread_local_id);
break;
}
*/
unsigned *size = nir->info.cs.local_size;
- nir_ssa_def *local_index =
- nir_load_system_value(b, nir_intrinsic_load_local_invocation_index, 0);
+ nir_ssa_def *local_index = nir_load_local_invocation_index(b);
nir_const_value uvec3;
uvec3.u32[0] = 1;