nir: const_index helpers

Direct access to intr->const_index[n], where different slots have
different meanings, is somewhat confusing.

Instead, let's put some extra info in nir_intrinsic_infos[] about which
slots map to what, and add some get/set helpers.  The helpers validate
that the field being accessed (base/writemask/etc) is applicable for the
intrinsic opc, for some extra safety.  And nir_print can use this to
dump out decoded const_index fields.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
Rob Clark
2016-01-13 18:43:14 -05:00
parent 8b0f6de73d
commit 1df3ecc1b8
4 changed files with 191 additions and 100 deletions

View File

@@ -768,7 +768,7 @@ typedef struct {
} nir_call_instr; } nir_call_instr;
#define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \ #define INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, \
num_variables, num_indices, flags) \ num_variables, num_indices, idx0, idx1, idx2, flags) \
nir_intrinsic_##name, nir_intrinsic_##name,
#define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name, #define LAST_INTRINSIC(name) nir_last_intrinsic = nir_intrinsic_##name,
@@ -781,6 +781,8 @@ typedef enum {
#undef INTRINSIC #undef INTRINSIC
#undef LAST_INTRINSIC #undef LAST_INTRINSIC
#define NIR_INTRINSIC_MAX_CONST_INDEX 3
/** Represents an intrinsic /** Represents an intrinsic
* *
* An intrinsic is an instruction type for handling things that are * An intrinsic is an instruction type for handling things that are
@@ -824,7 +826,7 @@ typedef struct {
*/ */
uint8_t num_components; uint8_t num_components;
int const_index[3]; int const_index[NIR_INTRINSIC_MAX_CONST_INDEX];
nir_deref_var *variables[2]; nir_deref_var *variables[2];
@@ -853,6 +855,39 @@ typedef enum {
NIR_INTRINSIC_CAN_REORDER = (1 << 1), NIR_INTRINSIC_CAN_REORDER = (1 << 1),
} nir_intrinsic_semantic_flag; } nir_intrinsic_semantic_flag;
/**
* \name NIR intrinsics const-index flag
*
* Indicates the usage of a const_index slot.
*
* \sa nir_intrinsic_info::index_map
*/
typedef enum {
/**
* Generally instructions that take a offset src argument, can encode
* a constant 'base' value which is added to the offset.
*/
NIR_INTRINSIC_BASE = 1,
/**
* For store instructions, a writemask for the store.
*/
NIR_INTRINSIC_WRMASK = 2,
/**
* The stream-id for GS emit_vertex/end_primitive intrinsics.
*/
NIR_INTRINSIC_STREAM_ID = 3,
/**
* The clip-plane id for load_user_clip_plane intrinsic.
*/
NIR_INTRINSIC_UCP_ID = 4,
NIR_INTRINSIC_NUM_INDEX_FLAGS,
} nir_intrinsic_index_flag;
#define NIR_INTRINSIC_MAX_INPUTS 4 #define NIR_INTRINSIC_MAX_INPUTS 4
typedef struct { typedef struct {
@@ -882,12 +917,37 @@ typedef struct {
/** the number of constant indices used by the intrinsic */ /** the number of constant indices used by the intrinsic */
unsigned num_indices; unsigned num_indices;
/** indicates the usage of intr->const_index[n] */
unsigned index_map[NIR_INTRINSIC_NUM_INDEX_FLAGS];
/** semantic flags for calls to this intrinsic */ /** semantic flags for calls to this intrinsic */
nir_intrinsic_semantic_flag flags; nir_intrinsic_semantic_flag flags;
} nir_intrinsic_info; } nir_intrinsic_info;
extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics]; extern const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics];
#define INTRINSIC_IDX_ACCESSORS(name, flag, type) \
static inline type \
nir_intrinsic_##name(nir_intrinsic_instr *instr) \
{ \
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \
assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
return instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1]; \
} \
static inline void \
nir_intrinsic_set_##name(nir_intrinsic_instr *instr, type val) \
{ \
const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic]; \
assert(info->index_map[NIR_INTRINSIC_##flag] > 0); \
instr->const_index[info->index_map[NIR_INTRINSIC_##flag] - 1] = val; \
}
INTRINSIC_IDX_ACCESSORS(write_mask, WRMASK, unsigned)
INTRINSIC_IDX_ACCESSORS(base, BASE, int)
INTRINSIC_IDX_ACCESSORS(stream_id, STREAM_ID, unsigned)
INTRINSIC_IDX_ACCESSORS(ucp_id, UCP_ID, unsigned)
/** /**
* \group texture information * \group texture information
* *

View File

@@ -30,7 +30,8 @@
#define OPCODE(name) nir_intrinsic_##name #define OPCODE(name) nir_intrinsic_##name
#define INTRINSIC(_name, _num_srcs, _src_components, _has_dest, \ #define INTRINSIC(_name, _num_srcs, _src_components, _has_dest, \
_dest_components, _num_variables, _num_indices, _flags) \ _dest_components, _num_variables, _num_indices, \
idx0, idx1, idx2, _flags) \
{ \ { \
.name = #_name, \ .name = #_name, \
.num_srcs = _num_srcs, \ .num_srcs = _num_srcs, \
@@ -39,9 +40,16 @@
.dest_components = _dest_components, \ .dest_components = _dest_components, \
.num_variables = _num_variables, \ .num_variables = _num_variables, \
.num_indices = _num_indices, \ .num_indices = _num_indices, \
.index_map = { \
[NIR_INTRINSIC_ ## idx0] = 1, \
[NIR_INTRINSIC_ ## idx1] = 2, \
[NIR_INTRINSIC_ ## idx2] = 3, \
}, \
.flags = _flags \ .flags = _flags \
}, },
#define NIR_INTRINSIC_xx 0
#define LAST_INTRINSIC(name) #define LAST_INTRINSIC(name)
const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = { const nir_intrinsic_info nir_intrinsic_infos[nir_num_intrinsics] = {

View File

@@ -30,7 +30,7 @@
* expands to a list of macros of the form: * expands to a list of macros of the form:
* *
* INTRINSIC(name, num_srcs, src_components, has_dest, dest_components, * INTRINSIC(name, num_srcs, src_components, has_dest, dest_components,
* num_variables, num_indices, flags) * num_variables, num_indices, idx0, idx1, idx2, flags)
* *
* Which should correspond one-to-one with the nir_intrinsic_info structure. It * Which should correspond one-to-one with the nir_intrinsic_info structure. It
* is included in both ir.h to create the nir_intrinsic enum (with members of * is included in both ir.h to create the nir_intrinsic enum (with members of
@@ -42,9 +42,9 @@
#define ARR(...) { __VA_ARGS__ } #define ARR(...) { __VA_ARGS__ }
INTRINSIC(load_var, 0, ARR(), true, 0, 1, 0, NIR_INTRINSIC_CAN_ELIMINATE) INTRINSIC(load_var, 0, ARR(), true, 0, 1, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, 0) INTRINSIC(store_var, 1, ARR(0), false, 0, 1, 1, WRMASK, xx, xx, 0)
INTRINSIC(copy_var, 0, ARR(), false, 0, 2, 0, 0) INTRINSIC(copy_var, 0, ARR(), false, 0, 2, 0, xx, xx, xx, 0)
/* /*
* Interpolation of input. The interp_var_at* intrinsics are similar to the * Interpolation of input. The interp_var_at* intrinsics are similar to the
@@ -54,25 +54,25 @@ INTRINSIC(copy_var, 0, ARR(), false, 0, 2, 0, 0)
* respectively. * respectively.
*/ */
INTRINSIC(interp_var_at_centroid, 0, ARR(0), true, 0, 1, 0, INTRINSIC(interp_var_at_centroid, 0, ARR(0), true, 0, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
INTRINSIC(interp_var_at_sample, 1, ARR(1), true, 0, 1, 0, INTRINSIC(interp_var_at_sample, 1, ARR(1), true, 0, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0, INTRINSIC(interp_var_at_offset, 1, ARR(2), true, 0, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* /*
* Ask the driver for the size of a given buffer. It takes the buffer index * Ask the driver for the size of a given buffer. It takes the buffer index
* as source. * as source.
*/ */
INTRINSIC(get_buffer_size, 1, ARR(1), true, 1, 0, 0, INTRINSIC(get_buffer_size, 1, ARR(1), true, 1, 0, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* /*
* a barrier is an intrinsic with no inputs/outputs but which can't be moved * a barrier is an intrinsic with no inputs/outputs but which can't be moved
* around/optimized in general * around/optimized in general
*/ */
#define BARRIER(name) INTRINSIC(name, 0, ARR(), false, 0, 0, 0, 0) #define BARRIER(name) INTRINSIC(name, 0, ARR(), false, 0, 0, 0, xx, xx, xx, 0)
BARRIER(barrier) BARRIER(barrier)
BARRIER(discard) BARRIER(discard)
@@ -89,7 +89,7 @@ BARRIER(memory_barrier)
* The latter can be used as code motion barrier, which is currently not * The latter can be used as code motion barrier, which is currently not
* feasible with NIR. * feasible with NIR.
*/ */
INTRINSIC(shader_clock, 0, ARR(), true, 1, 0, 0, NIR_INTRINSIC_CAN_ELIMINATE) INTRINSIC(shader_clock, 0, ARR(), true, 1, 0, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
/* /*
* Memory barrier with semantics analogous to the compute shader * Memory barrier with semantics analogous to the compute shader
@@ -103,7 +103,7 @@ BARRIER(memory_barrier_image)
BARRIER(memory_barrier_shared) BARRIER(memory_barrier_shared)
/** A conditional discard, with a single boolean source. */ /** A conditional discard, with a single boolean source. */
INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, 0) INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
/** /**
* Basic Geometry Shader intrinsics. * Basic Geometry Shader intrinsics.
@@ -113,8 +113,8 @@ INTRINSIC(discard_if, 1, ARR(1), false, 0, 0, 0, 0)
* *
* end_primitive implements GLSL's EndPrimitive() built-in. * end_primitive implements GLSL's EndPrimitive() built-in.
*/ */
INTRINSIC(emit_vertex, 0, ARR(), false, 0, 0, 1, 0) INTRINSIC(emit_vertex, 0, ARR(), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
INTRINSIC(end_primitive, 0, ARR(), false, 0, 0, 1, 0) INTRINSIC(end_primitive, 0, ARR(), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
/** /**
* Geometry Shader intrinsics with a vertex count. * Geometry Shader intrinsics with a vertex count.
@@ -125,9 +125,9 @@ INTRINSIC(end_primitive, 0, ARR(), false, 0, 0, 1, 0)
* These maintain a count of the number of vertices emitted, as an additional * These maintain a count of the number of vertices emitted, as an additional
* unsigned integer source. * unsigned integer source.
*/ */
INTRINSIC(emit_vertex_with_counter, 1, ARR(1), false, 0, 0, 1, 0) INTRINSIC(emit_vertex_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
INTRINSIC(end_primitive_with_counter, 1, ARR(1), false, 0, 0, 1, 0) INTRINSIC(end_primitive_with_counter, 1, ARR(1), false, 0, 0, 1, STREAM_ID, xx, xx, 0)
INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, 0) INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, xx, xx, xx, 0)
/* /*
* Atomic counters * Atomic counters
@@ -137,8 +137,8 @@ INTRINSIC(set_vertex_count, 1, ARR(1), false, 0, 0, 0, 0)
*/ */
#define ATOMIC(name, flags) \ #define ATOMIC(name, flags) \
INTRINSIC(atomic_counter_##name##_var, 0, ARR(), true, 1, 1, 0, flags) \ INTRINSIC(atomic_counter_##name##_var, 0, ARR(), true, 1, 1, 0, xx, xx, xx, flags) \
INTRINSIC(atomic_counter_##name, 1, ARR(1), true, 1, 0, 1, flags) INTRINSIC(atomic_counter_##name, 1, ARR(1), true, 1, 0, 1, BASE, xx, xx, flags)
ATOMIC(inc, 0) ATOMIC(inc, 0)
ATOMIC(dec, 0) ATOMIC(dec, 0)
@@ -159,20 +159,20 @@ ATOMIC(read, NIR_INTRINSIC_CAN_ELIMINATE)
* either one or two additional scalar arguments with the same meaning as in * either one or two additional scalar arguments with the same meaning as in
* the ARB_shader_image_load_store specification. * the ARB_shader_image_load_store specification.
*/ */
INTRINSIC(image_load, 2, ARR(4, 1), true, 4, 1, 0, INTRINSIC(image_load, 2, ARR(4, 1), true, 4, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE) NIR_INTRINSIC_CAN_ELIMINATE)
INTRINSIC(image_store, 3, ARR(4, 1, 4), false, 0, 1, 0, 0) INTRINSIC(image_store, 3, ARR(4, 1, 4), false, 0, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_add, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_add, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_min, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_min, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_max, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_max, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_and, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_and, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_or, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_or, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_xor, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_xor, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_exchange, 3, ARR(4, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_exchange, 3, ARR(4, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_atomic_comp_swap, 4, ARR(4, 1, 1, 1), true, 1, 1, 0, 0) INTRINSIC(image_atomic_comp_swap, 4, ARR(4, 1, 1, 1), true, 1, 1, 0, xx, xx, xx, 0)
INTRINSIC(image_size, 0, ARR(), true, 4, 1, 0, INTRINSIC(image_size, 0, ARR(), true, 4, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
INTRINSIC(image_samples, 0, ARR(), true, 1, 1, 0, INTRINSIC(image_samples, 0, ARR(), true, 1, 1, 0, xx, xx, xx,
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* /*
@@ -192,16 +192,16 @@ INTRINSIC(image_samples, 0, ARR(), true, 1, 1, 0,
* in ssbo_atomic_add, etc). * in ssbo_atomic_add, etc).
* 3: For CompSwap only: the second data parameter. * 3: For CompSwap only: the second data parameter.
*/ */
INTRINSIC(ssbo_atomic_add, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_add, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_imin, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_imin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_umin, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_umin, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_imax, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_imax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_umax, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_umax, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_and, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_and, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_or, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_or, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_xor, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_xor, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_exchange, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_exchange, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(ssbo_atomic_comp_swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(ssbo_atomic_comp_swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
/* /*
* CS shared variable atomic intrinsics * CS shared variable atomic intrinsics
@@ -219,42 +219,43 @@ INTRINSIC(ssbo_atomic_comp_swap, 4, ARR(1, 1, 1, 1), true, 1, 0, 0, 0)
* in shared_atomic_add, etc). * in shared_atomic_add, etc).
* 2: For CompSwap only: the second data parameter. * 2: For CompSwap only: the second data parameter.
*/ */
INTRINSIC(shared_atomic_add, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_add, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_imin, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_imin, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_umin, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_umin, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_imax, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_imax, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_umax, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_umax, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_and, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_and, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_or, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_or, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_xor, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_xor, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_exchange, 2, ARR(1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_exchange, 2, ARR(1, 1), true, 1, 0, 0, xx, xx, xx, 0)
INTRINSIC(shared_atomic_comp_swap, 3, ARR(1, 1, 1), true, 1, 0, 0, 0) INTRINSIC(shared_atomic_comp_swap, 3, ARR(1, 1, 1), true, 1, 0, 0, xx, xx, xx, 0)
#define SYSTEM_VALUE(name, components, num_indices) \ #define SYSTEM_VALUE(name, components, num_indices, idx0, idx1, idx2) \
INTRINSIC(load_##name, 0, ARR(), true, components, 0, num_indices, \ INTRINSIC(load_##name, 0, ARR(), true, components, 0, num_indices, \
idx0, idx1, idx2, \
NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
SYSTEM_VALUE(front_face, 1, 0) SYSTEM_VALUE(front_face, 1, 0, xx, xx, xx)
SYSTEM_VALUE(vertex_id, 1, 0) SYSTEM_VALUE(vertex_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(vertex_id_zero_base, 1, 0) SYSTEM_VALUE(vertex_id_zero_base, 1, 0, xx, xx, xx)
SYSTEM_VALUE(base_vertex, 1, 0) SYSTEM_VALUE(base_vertex, 1, 0, xx, xx, xx)
SYSTEM_VALUE(instance_id, 1, 0) SYSTEM_VALUE(instance_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(base_instance, 1, 0) SYSTEM_VALUE(base_instance, 1, 0, xx, xx, xx)
SYSTEM_VALUE(draw_id, 1, 0) SYSTEM_VALUE(draw_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(sample_id, 1, 0) SYSTEM_VALUE(sample_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(sample_pos, 2, 0) SYSTEM_VALUE(sample_pos, 2, 0, xx, xx, xx)
SYSTEM_VALUE(sample_mask_in, 1, 0) SYSTEM_VALUE(sample_mask_in, 1, 0, xx, xx, xx)
SYSTEM_VALUE(primitive_id, 1, 0) SYSTEM_VALUE(primitive_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(invocation_id, 1, 0) SYSTEM_VALUE(invocation_id, 1, 0, xx, xx, xx)
SYSTEM_VALUE(tess_coord, 3, 0) SYSTEM_VALUE(tess_coord, 3, 0, xx, xx, xx)
SYSTEM_VALUE(tess_level_outer, 4, 0) SYSTEM_VALUE(tess_level_outer, 4, 0, xx, xx, xx)
SYSTEM_VALUE(tess_level_inner, 2, 0) SYSTEM_VALUE(tess_level_inner, 2, 0, xx, xx, xx)
SYSTEM_VALUE(patch_vertices_in, 1, 0) SYSTEM_VALUE(patch_vertices_in, 1, 0, xx, xx, xx)
SYSTEM_VALUE(local_invocation_id, 3, 0) SYSTEM_VALUE(local_invocation_id, 3, 0, xx, xx, xx)
SYSTEM_VALUE(work_group_id, 3, 0) SYSTEM_VALUE(work_group_id, 3, 0, xx, xx, xx)
SYSTEM_VALUE(user_clip_plane, 4, 1) /* const_index[0] is user_clip_plane[idx] */ SYSTEM_VALUE(user_clip_plane, 4, 1, UCP_ID, xx, xx)
SYSTEM_VALUE(num_work_groups, 3, 0) SYSTEM_VALUE(num_work_groups, 3, 0, xx, xx, xx)
SYSTEM_VALUE(helper_invocation, 1, 0) SYSTEM_VALUE(helper_invocation, 1, 0, xx, xx, xx)
/* /*
* Load operations pull data from some piece of GPU memory. All load * Load operations pull data from some piece of GPU memory. All load
@@ -274,25 +275,25 @@ SYSTEM_VALUE(helper_invocation, 1, 0)
* offsets are always in bytes. * offsets are always in bytes.
*/ */
#define LOAD(name, srcs, indices, flags) \ #define LOAD(name, srcs, num_indices, idx0, idx1, idx2, flags) \
INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, indices, flags) INTRINSIC(load_##name, srcs, ARR(1, 1, 1, 1), true, 0, 0, num_indices, idx0, idx1, idx2, flags)
/* src[] = { offset }. const_index[] = { base } */ /* src[] = { offset }. const_index[] = { base } */
LOAD(uniform, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) LOAD(uniform, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* src[] = { buffer_index, offset }. No const_index */ /* src[] = { buffer_index, offset }. No const_index */
LOAD(ubo, 2, 0, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) LOAD(ubo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* src[] = { offset }. const_index[] = { base } */ /* src[] = { offset }. const_index[] = { base } */
LOAD(input, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) LOAD(input, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* src[] = { vertex, offset }. const_index[] = { base } */ /* src[] = { vertex, offset }. const_index[] = { base } */
LOAD(per_vertex_input, 2, 1, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER) LOAD(per_vertex_input, 2, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE | NIR_INTRINSIC_CAN_REORDER)
/* src[] = { buffer_index, offset }. No const_index */ /* src[] = { buffer_index, offset }. No const_index */
LOAD(ssbo, 2, 0, NIR_INTRINSIC_CAN_ELIMINATE) LOAD(ssbo, 2, 0, xx, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
/* src[] = { offset }. const_index[] = { base } */ /* src[] = { offset }. const_index[] = { base } */
LOAD(output, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE) LOAD(output, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
/* src[] = { vertex, offset }. const_index[] = { base } */ /* src[] = { vertex, offset }. const_index[] = { base } */
LOAD(per_vertex_output, 2, 1, NIR_INTRINSIC_CAN_ELIMINATE) LOAD(per_vertex_output, 2, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
/* src[] = { offset }. const_index[] = { base } */ /* src[] = { offset }. const_index[] = { base } */
LOAD(shared, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE) LOAD(shared, 1, 1, BASE, xx, xx, NIR_INTRINSIC_CAN_ELIMINATE)
/* /*
* Stores work the same way as loads, except now the first source is the value * Stores work the same way as loads, except now the first source is the value
@@ -301,16 +302,16 @@ LOAD(shared, 1, 1, NIR_INTRINSIC_CAN_ELIMINATE)
* const_index[0]. * const_index[0].
*/ */
#define STORE(name, srcs, indices, flags) \ #define STORE(name, srcs, num_indices, idx0, idx1, idx2, flags) \
INTRINSIC(store_##name, srcs, ARR(0, 1, 1, 1), false, 0, 0, indices, flags) INTRINSIC(store_##name, srcs, ARR(0, 1, 1, 1), false, 0, 0, num_indices, idx0, idx1, idx2, flags)
/* src[] = { value, offset }. const_index[] = { base, write_mask } */ /* src[] = { value, offset }. const_index[] = { base, write_mask } */
STORE(output, 2, 2, 0) STORE(output, 2, 2, BASE, WRMASK, xx, 0)
/* src[] = { value, vertex, offset }. const_index[] = { base, write_mask } */ /* src[] = { value, vertex, offset }. const_index[] = { base, write_mask } */
STORE(per_vertex_output, 3, 2, 0) STORE(per_vertex_output, 3, 2, BASE, WRMASK, xx, 0)
/* src[] = { value, block_index, offset }. const_index[] = { write_mask } */ /* src[] = { value, block_index, offset }. const_index[] = { write_mask } */
STORE(ssbo, 3, 1, 0) STORE(ssbo, 3, 1, WRMASK, xx, xx, 0)
/* src[] = { value, offset }. const_index[] = { base, write_mask } */ /* src[] = { value, offset }. const_index[] = { base, write_mask } */
STORE(shared, 2, 2, 0) STORE(shared, 2, 2, BASE, WRMASK, xx, 0)
LAST_INTRINSIC(store_shared) LAST_INTRINSIC(store_shared)

View File

@@ -444,15 +444,16 @@ print_deref(nir_deref_var *deref, print_state *state)
static void static void
print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state) print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
{ {
unsigned num_srcs = nir_intrinsic_infos[instr->intrinsic].num_srcs; const nir_intrinsic_info *info = &nir_intrinsic_infos[instr->intrinsic];
unsigned num_srcs = info->num_srcs;
FILE *fp = state->fp; FILE *fp = state->fp;
if (nir_intrinsic_infos[instr->intrinsic].has_dest) { if (info->has_dest) {
print_dest(&instr->dest, state); print_dest(&instr->dest, state);
fprintf(fp, " = "); fprintf(fp, " = ");
} }
fprintf(fp, "intrinsic %s (", nir_intrinsic_infos[instr->intrinsic].name); fprintf(fp, "intrinsic %s (", info->name);
for (unsigned i = 0; i < num_srcs; i++) { for (unsigned i = 0; i < num_srcs; i++) {
if (i != 0) if (i != 0)
@@ -463,9 +464,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
fprintf(fp, ") ("); fprintf(fp, ") (");
unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables; for (unsigned i = 0; i < info->num_variables; i++) {
for (unsigned i = 0; i < num_vars; i++) {
if (i != 0) if (i != 0)
fprintf(fp, ", "); fprintf(fp, ", ");
@@ -474,9 +473,7 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
fprintf(fp, ") ("); fprintf(fp, ") (");
unsigned num_indices = nir_intrinsic_infos[instr->intrinsic].num_indices; for (unsigned i = 0; i < info->num_indices; i++) {
for (unsigned i = 0; i < num_indices; i++) {
if (i != 0) if (i != 0)
fprintf(fp, ", "); fprintf(fp, ", ");
@@ -485,6 +482,31 @@ print_intrinsic_instr(nir_intrinsic_instr *instr, print_state *state)
fprintf(fp, ")"); fprintf(fp, ")");
static const char *index_name[NIR_INTRINSIC_NUM_INDEX_FLAGS] = {
[NIR_INTRINSIC_BASE] = "base",
[NIR_INTRINSIC_WRMASK] = "wrmask",
[NIR_INTRINSIC_STREAM_ID] = "stream-id",
[NIR_INTRINSIC_UCP_ID] = "ucp-id",
};
for (unsigned idx = 1; idx < NIR_INTRINSIC_NUM_INDEX_FLAGS; idx++) {
if (!info->index_map[idx])
continue;
fprintf(fp, " /*");
if (idx == NIR_INTRINSIC_WRMASK) {
/* special case wrmask to show it as a writemask.. */
unsigned wrmask = nir_intrinsic_write_mask(instr);
fprintf(fp, " wrmask=");
for (unsigned i = 0; i < 4; i++)
if ((wrmask >> i) & 1)
fprintf(fp, "%c", "xyzw"[i]);
} else {
unsigned off = info->index_map[idx] - 1;
assert(index_name[idx]); /* forgot to update index_name table? */
fprintf(fp, " %s=%d", index_name[idx], instr->const_index[off]);
}
fprintf(fp, " */");
}
if (!state->shader) if (!state->shader)
return; return;