*/
#include "nir.h"
-#include "nir_builder.h"
-#include "nir_control_flow_private.h"
-#include "nir_worklist.h"
-#include "util/half_float.h"
-#include <limits.h>
#include <assert.h>
+#include <limits.h>
#include <math.h>
+#include "util/half_float.h"
#include "util/u_math.h"
#include "util/u_qsort.h"
+#include "nir_builder.h"
+#include "nir_control_flow_private.h"
+#include "nir_worklist.h"
#include "main/menums.h" /* BITFIELD64_MASK */
/* NOTE: if the instruction you are copying a src to is already added
* to the IR, use nir_instr_rewrite_src() instead.
*/
-void nir_src_copy(nir_src *dest, const nir_src *src, nir_instr *instr)
+void
+nir_src_copy(nir_src *dest, const nir_src *src, nir_instr *instr)
{
src_copy(dest, src, instr ? gc_get_context(instr) : NULL);
}
(memcmp(src->swizzle, trivial_swizzle, num_components) == 0);
}
-
static void
cf_init(nir_cf_node *node, nir_cf_node_type type)
{
return instr;
}
-static int8_t default_tg4_offsets[4][2] =
-{
+static int8_t default_tg4_offsets[4][2] = {
{ 0, 1 },
{ 1, 1 },
{ 1, 0 },
/* Now, move all of the other sources down */
for (unsigned i = src_idx + 1; i < tex->num_srcs; i++) {
- tex->src[i-1].src_type = tex->src[i].src_type;
- nir_instr_move_src(&tex->instr, &tex->src[i-1].src, &tex->src[i].src);
+ tex->src[i - 1].src_type = tex->src[i].src_type;
+ nir_instr_move_src(&tex->instr, &tex->src[i - 1].src, &tex->src[i].src);
}
tex->num_srcs--;
}
/* Inserting instructions after a jump is illegal. */
nir_instr *last = nir_block_last_instr(cursor.block);
assert(last == NULL || last->type != nir_instr_type_jump);
- (void) last;
+ (void)last;
instr->block = cursor.block;
add_defs_uses(instr);
static bool
remove_use_cb(nir_src *src, void *state)
{
- (void) state;
+ (void)state;
if (src_is_valid(src))
list_del(&src->use_link);
nir_foreach_src(instr, remove_use_cb, instr);
}
-void nir_instr_remove_v(nir_instr *instr)
+void
+nir_instr_remove_v(nir_instr *instr)
{
remove_defs_uses(instr);
exec_node_remove(&instr->node);
}
}
-void nir_instr_free(nir_instr *instr)
+void
+nir_instr_free(nir_instr *instr)
{
switch (instr->type) {
case nir_instr_type_tex:
}
}
-static bool nir_instr_free_and_dce_live_cb(nir_ssa_def *def, void *state)
+static bool
+nir_instr_free_and_dce_live_cb(nir_ssa_def *def, void *state)
{
bool *live = state;
}
}
-static bool nir_instr_free_and_dce_is_live(nir_instr *instr)
+static bool
+nir_instr_free_and_dce_is_live(nir_instr *instr)
{
/* Note: don't have to worry about jumps because they don't have dests to
* become unused.
case nir_instr_type_intrinsic:
case nir_instr_type_phi:
case nir_instr_type_parallel_copy: {
- struct foreach_ssa_def_state foreach_state = {cb, state};
+ struct foreach_ssa_def_state foreach_state = { cb, state };
return nir_foreach_dest(instr, nir_ssa_def_visitor, &foreach_state);
}
void
nir_ssa_dest_init(nir_instr *instr, nir_dest *dest,
- unsigned num_components, unsigned bit_size)
+ unsigned num_components, unsigned bit_size)
{
nir_ssa_def_init(instr, &dest->ssa, num_components, bit_size);
}
}
}
-nir_block *nir_cf_node_cf_tree_first(nir_cf_node *node)
+nir_block *
+nir_cf_node_cf_tree_first(nir_cf_node *node)
{
switch (node->type) {
case nir_cf_node_function: {
}
}
-nir_block *nir_cf_node_cf_tree_last(nir_cf_node *node)
+nir_block *
+nir_cf_node_cf_tree_last(nir_cf_node *node)
{
switch (node->type) {
case nir_cf_node_function: {
}
}
-nir_block *nir_cf_node_cf_tree_next(nir_cf_node *node)
+nir_block *
+nir_cf_node_cf_tree_next(nir_cf_node *node)
{
if (node->type == nir_cf_node_block)
return nir_block_cf_tree_next(nir_cf_node_as_block(node));
static int
compare_block_index(const void *p1, const void *p2)
{
- const nir_block *block1 = *((const nir_block **) p1);
- const nir_block *block2 = *((const nir_block **) p2);
+ const nir_block *block1 = *((const nir_block **)p1);
+ const nir_block *block2 = *((const nir_block **)p2);
- return (int) block1->index - (int) block2->index;
+ return (int)block1->index - (int)block2->index;
}
nir_block **
unsigned i = 0;
set_foreach(block->predecessors, entry)
- preds[i++] = (nir_block *) entry->key;
+ preds[i++] = (nir_block *)entry->key;
assert(i == block->predecessors->entries);
qsort(preds, block->predecessors->entries, sizeof(nir_block *),
static bool
index_ssa_def_cb(nir_ssa_def *def, void *state)
{
- unsigned *index = (unsigned *) state;
+ unsigned *index = (unsigned *)state;
def->index = (*index)++;
return true;
* Returns true if the shader supports quad-based implicit derivatives on
* texture sampling.
*/
-bool nir_shader_supports_implicit_lod(nir_shader *shader)
+bool
+nir_shader_supports_implicit_lod(nir_shader *shader)
{
return (shader->info.stage == MESA_SHADER_FRAGMENT ||
(shader->info.stage == MESA_SHADER_COMPUTE &&
atomic_op = nir_intrinsic_atomic_op(intrin);
switch (intrin->intrinsic) {
-#define CASE(op) \
- case nir_intrinsic_image_deref_##op: \
+#define CASE(op) \
+ case nir_intrinsic_image_deref_##op: \
intrin->intrinsic = bindless ? nir_intrinsic_bindless_image_##op \
- : nir_intrinsic_image_##op; \
+ : nir_intrinsic_image_##op; \
break;
- CASE(load)
- CASE(sparse_load)
- CASE(store)
- CASE(atomic)
- CASE(atomic_swap)
- CASE(size)
- CASE(samples)
- CASE(load_raw_intel)
- CASE(store_raw_intel)
- CASE(fragment_mask_load_amd)
+ CASE(load)
+ CASE(sparse_load)
+ CASE(store)
+ CASE(atomic)
+ CASE(atomic_swap)
+ CASE(size)
+ CASE(samples)
+ CASE(load_raw_intel)
+ CASE(store_raw_intel)
+ CASE(fragment_mask_load_amd)
#undef CASE
default:
unreachable("Unhanded image intrinsic");
}
}
-nir_binding nir_chase_binding(nir_src rsrc)
+nir_binding
+nir_chase_binding(nir_src rsrc)
{
- nir_binding res = {0};
+ nir_binding res = { 0 };
if (rsrc.ssa->parent_instr->type == nir_instr_type_deref) {
const struct glsl_type *type = glsl_without_array(nir_src_as_deref(rsrc)->type);
bool is_image = glsl_type_is_image(type) || glsl_type_is_sampler(type);
return res;
} else if (deref->deref_type == nir_deref_type_array && is_image) {
if (res.num_indices == ARRAY_SIZE(res.indices))
- return (nir_binding){0};
+ return (nir_binding){ 0 };
res.indices[res.num_indices++] = deref->arr.index;
}
if (alu && alu->op == nir_op_mov) {
for (unsigned i = 0; i < num_components; i++) {
if (alu->src[0].swizzle[i] != i)
- return (nir_binding){0};
+ return (nir_binding){ 0 };
}
rsrc = alu->src[0].src;
} else if (alu && nir_op_is_vec(alu->op)) {
for (unsigned i = 0; i < num_components; i++) {
if (alu->src[i].swizzle[0] != i || alu->src[i].src.ssa != alu->src[0].src.ssa)
- return (nir_binding){0};
+ return (nir_binding){ 0 };
}
rsrc = alu->src[0].src;
} else if (intrin && intrin->intrinsic == nir_intrinsic_read_first_invocation) {
nir_intrinsic_instr *intrin = nir_src_as_intrinsic(rsrc);
if (!intrin)
- return (nir_binding){0};
+ return (nir_binding){ 0 };
/* Intel resource, similar to load_vulkan_descriptor after it has been
* lowered.
if (intrin->intrinsic == nir_intrinsic_load_vulkan_descriptor) {
intrin = nir_src_as_intrinsic(intrin->src[0]);
if (!intrin)
- return (nir_binding){0};
+ return (nir_binding){ 0 };
}
if (intrin->intrinsic != nir_intrinsic_vulkan_resource_index)
- return (nir_binding){0};
+ return (nir_binding){ 0 };
assert(res.num_indices == 0);
res.success = true;
return res;
}
-nir_variable *nir_get_binding_variable(nir_shader *shader, nir_binding binding)
+nir_variable *
+nir_get_binding_variable(nir_shader *shader, nir_binding binding)
{
nir_variable *binding_var = NULL;
unsigned count = 0;
case GLSL_TYPE_FLOAT: return nir_type_float32;
case GLSL_TYPE_FLOAT16: return nir_type_float16;
case GLSL_TYPE_DOUBLE: return nir_type_float64;
- /* clang-format on */
+ /* clang-format on */
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_TEXTURE:
}
#define CASE_ALL_SIZES(op) \
- case op: \
- case op ## 8: \
- case op ## 16: \
- case op ## 32: \
+ case op: \
+ case op##8: \
+ case op##16: \
+ case op##32:
bool
nir_alu_instr_is_comparison(const nir_alu_instr *instr)
{
switch (instr->op) {
- CASE_ALL_SIZES(nir_op_flt)
- CASE_ALL_SIZES(nir_op_fge)
- CASE_ALL_SIZES(nir_op_feq)
- CASE_ALL_SIZES(nir_op_fneu)
- CASE_ALL_SIZES(nir_op_ilt)
- CASE_ALL_SIZES(nir_op_ult)
- CASE_ALL_SIZES(nir_op_ige)
- CASE_ALL_SIZES(nir_op_uge)
- CASE_ALL_SIZES(nir_op_ieq)
- CASE_ALL_SIZES(nir_op_ine)
- CASE_ALL_SIZES(nir_op_bitz)
- CASE_ALL_SIZES(nir_op_bitnz)
+ CASE_ALL_SIZES(nir_op_flt)
+ CASE_ALL_SIZES(nir_op_fge)
+ CASE_ALL_SIZES(nir_op_feq)
+ CASE_ALL_SIZES(nir_op_fneu)
+ CASE_ALL_SIZES(nir_op_ilt)
+ CASE_ALL_SIZES(nir_op_ult)
+ CASE_ALL_SIZES(nir_op_ige)
+ CASE_ALL_SIZES(nir_op_uge)
+ CASE_ALL_SIZES(nir_op_ieq)
+ CASE_ALL_SIZES(nir_op_ine)
+ CASE_ALL_SIZES(nir_op_bitz)
+ CASE_ALL_SIZES(nir_op_bitnz)
case nir_op_inot:
return true;
default:
assert(dst_info->index_map[i] > 0);
dst->const_index[dst_info->index_map[i] - 1] =
- src->const_index[src_info->index_map[i] - 1];
+ src->const_index[src_info->index_map[i] - 1];
}
}
-
bool
nir_tex_instr_need_sampler(const nir_tex_instr *instr)
{
case nir_texop_txs: {
unsigned ret;
switch (instr->sampler_dim) {
- case GLSL_SAMPLER_DIM_1D:
- case GLSL_SAMPLER_DIM_BUF:
- ret = 1;
- break;
- case GLSL_SAMPLER_DIM_2D:
- case GLSL_SAMPLER_DIM_CUBE:
- case GLSL_SAMPLER_DIM_MS:
- case GLSL_SAMPLER_DIM_RECT:
- case GLSL_SAMPLER_DIM_EXTERNAL:
- case GLSL_SAMPLER_DIM_SUBPASS:
- ret = 2;
- break;
- case GLSL_SAMPLER_DIM_3D:
- ret = 3;
- break;
- default:
- unreachable("not reached");
+ case GLSL_SAMPLER_DIM_1D:
+ case GLSL_SAMPLER_DIM_BUF:
+ ret = 1;
+ break;
+ case GLSL_SAMPLER_DIM_2D:
+ case GLSL_SAMPLER_DIM_CUBE:
+ case GLSL_SAMPLER_DIM_MS:
+ case GLSL_SAMPLER_DIM_RECT:
+ case GLSL_SAMPLER_DIM_EXTERNAL:
+ case GLSL_SAMPLER_DIM_SUBPASS:
+ ret = 2;
+ break;
+ case GLSL_SAMPLER_DIM_3D:
+ ret = 3;
+ break;
+ default:
+ unreachable("not reached");
}
if (instr->is_array)
ret++;
unsigned mask = 0;
if (nir_intrinsic_has_io_xfb(instr)) {
- unsigned wr_mask = nir_intrinsic_write_mask(instr) <<
- nir_intrinsic_component(instr);
+ unsigned wr_mask = nir_intrinsic_write_mask(instr) << nir_intrinsic_component(instr);
assert((wr_mask & ~0xf) == 0); /* only 4 components allowed */
unsigned iter_mask = wr_mask;
while (iter_mask) {
unsigned i = u_bit_scan(&iter_mask);
- nir_io_xfb xfb = i < 2 ? nir_intrinsic_io_xfb(instr) :
- nir_intrinsic_io_xfb2(instr);
+ nir_io_xfb xfb = i < 2 ? nir_intrinsic_io_xfb(instr) : nir_intrinsic_io_xfb2(instr);
if (xfb.out[i % 2].num_components)
mask |= BITFIELD_RANGE(i, xfb.out[i % 2].num_components) & wr_mask;
}
* This marks the output store instruction as not feeding fixed-function
* logic. If the instruction has no other use, it's removed.
*/
-void nir_remove_sysval_output(nir_intrinsic_instr *intr)
+void
+nir_remove_sysval_output(nir_intrinsic_instr *intr)
{
nir_io_semantics sem = nir_intrinsic_io_semantics(intr);
}
}
-void nir_remove_non_entrypoints(nir_shader *nir)
+void
+nir_remove_non_entrypoints(nir_shader *nir)
{
nir_foreach_function_safe(func, nir) {
if (!func->is_entrypoint)
#ifndef NIR_H
#define NIR_H
-#include "util/hash_table.h"
#include "compiler/glsl/list.h"
-#include "util/list.h"
-#include "util/log.h"
-#include "util/ralloc.h"
-#include "util/set.h"
+#include "compiler/nir_types.h"
+#include "compiler/shader_enums.h"
+#include "compiler/shader_info.h"
#include "util/bitscan.h"
#include "util/bitset.h"
#include "util/compiler.h"
#include "util/enum_operators.h"
+#include "util/format/u_format.h"
+#include "util/hash_table.h"
+#include "util/list.h"
+#include "util/log.h"
#include "util/macros.h"
+#include "util/ralloc.h"
+#include "util/set.h"
#include "util/u_printf.h"
-#include "util/format/u_format.h"
-#include "compiler/nir_types.h"
-#include "compiler/shader_enums.h"
-#include "compiler/shader_info.h"
#define XXH_INLINE_ALL
-#include "util/xxhash.h"
#include <stdio.h>
+#include "util/xxhash.h"
#ifndef NDEBUG
#include "util/u_debug.h"
extern bool nir_debug_print_shader[MESA_SHADER_KERNEL + 1];
#ifndef NDEBUG
-#define NIR_DEBUG(flag) unlikely(nir_debug & (NIR_DEBUG_ ## flag))
+#define NIR_DEBUG(flag) unlikely(nir_debug &(NIR_DEBUG_##flag))
#else
#define NIR_DEBUG(flag) false
#endif
#define NIR_DEBUG_PRINT_INTERNAL (1u << 21)
#define NIR_DEBUG_PRINT_PASS_FLAGS (1u << 22)
-#define NIR_DEBUG_PRINT (NIR_DEBUG_PRINT_VS | \
+#define NIR_DEBUG_PRINT (NIR_DEBUG_PRINT_VS | \
NIR_DEBUG_PRINT_TCS | \
NIR_DEBUG_PRINT_TES | \
- NIR_DEBUG_PRINT_GS | \
- NIR_DEBUG_PRINT_FS | \
- NIR_DEBUG_PRINT_CS | \
- NIR_DEBUG_PRINT_TS | \
- NIR_DEBUG_PRINT_MS | \
+ NIR_DEBUG_PRINT_GS | \
+ NIR_DEBUG_PRINT_FS | \
+ NIR_DEBUG_PRINT_CS | \
+ NIR_DEBUG_PRINT_TS | \
+ NIR_DEBUG_PRINT_MS | \
NIR_DEBUG_PRINT_RGS | \
NIR_DEBUG_PRINT_AHS | \
NIR_DEBUG_PRINT_CHS | \
NIR_DEBUG_PRINT_MHS | \
- NIR_DEBUG_PRINT_IS | \
+ NIR_DEBUG_PRINT_IS | \
NIR_DEBUG_PRINT_CBS | \
NIR_DEBUG_PRINT_KS)
-#define NIR_FALSE 0u
-#define NIR_TRUE (~0u)
+#define NIR_FALSE 0u
+#define NIR_TRUE (~0u)
#define NIR_MAX_VEC_COMPONENTS 16
#define NIR_MAX_MATRIX_COLUMNS 4
-#define NIR_STREAM_PACKED (1 << 8)
+#define NIR_STREAM_PACKED (1 << 8)
typedef uint16_t nir_component_mask_t;
static inline bool
nir_num_components_valid(unsigned num_components)
{
- return (num_components >= 1 &&
+ return (num_components >= 1 &&
num_components <= 5) ||
- num_components == 8 ||
- num_components == 16;
+ num_components == 8 ||
+ num_components == 16;
}
static inline nir_component_mask_t
* Note that you have to be a bit careful as the generated cast function
* destroys constness.
*/
-#define NIR_DEFINE_CAST(name, in_type, out_type, field, \
- type_field, type_value) \
-static inline out_type * \
-name(const in_type *parent) \
-{ \
- assert(parent && parent->type_field == type_value); \
- return exec_node_data(out_type, parent, field); \
-}
+#define NIR_DEFINE_CAST(name, in_type, out_type, field, \
+ type_field, type_value) \
+ static inline out_type * \
+ name(const in_type *parent) \
+ { \
+ assert(parent && parent->type_field == type_value); \
+ return exec_node_data(out_type, parent, field); \
+ }
struct nir_function;
struct nir_shader;
struct nir_builder;
struct nir_xfb_info;
-
/**
* Description of built-in state associated with a uniform
*
*/
typedef enum {
nir_rounding_mode_undef = 0,
- nir_rounding_mode_rtne = 1, /* round to nearest even */
- nir_rounding_mode_ru = 2, /* round up */
- nir_rounding_mode_rd = 3, /* round down */
- nir_rounding_mode_rtz = 4, /* round towards zero */
+ nir_rounding_mode_rtne = 1, /* round to nearest even */
+ nir_rounding_mode_ru = 2, /* round up */
+ nir_rounding_mode_rd = 3, /* round down */
+ nir_rounding_mode_rtz = 4, /* round towards zero */
} nir_rounding_mode;
/**
* Intel resource flags
*/
typedef enum {
- nir_resource_intel_bindless = 1u << 0,
- nir_resource_intel_pushable = 1u << 1,
- nir_resource_intel_sampler = 1u << 2,
- nir_resource_intel_non_uniform = 1u << 3,
+ nir_resource_intel_bindless = 1u << 0,
+ nir_resource_intel_pushable = 1u << 1,
+ nir_resource_intel_sampler = 1u << 2,
+ nir_resource_intel_non_uniform = 1u << 3,
} nir_resource_data_intel;
typedef union {
} nir_const_value;
#define nir_const_value_to_array(arr, c, components, m) \
-do { \
- for (unsigned i = 0; i < components; ++i) \
- arr[i] = c[i].m; \
-} while (false)
+ do { \
+ for (unsigned i = 0; i < components; ++i) \
+ arr[i] = c[i].m; \
+ } while (false)
static inline nir_const_value
nir_const_value_for_raw_uint(uint64_t x, unsigned bit_size)
* with a layout qualifier.
*/
typedef enum {
- nir_depth_layout_none, /**< No depth layout is specified. */
- nir_depth_layout_any,
- nir_depth_layout_greater,
- nir_depth_layout_less,
- nir_depth_layout_unchanged
+ nir_depth_layout_none, /**< No depth layout is specified. */
+ nir_depth_layout_any,
+ nir_depth_layout_greater,
+ nir_depth_layout_less,
+ nir_depth_layout_unchanged
} nir_depth_layout;
/**
*
* \sa nir_variable_mode
*/
- unsigned mode:16;
+ unsigned mode : 16;
/**
* Is the variable read-only?
* This is set for variables declared as \c const, shader inputs,
* and uniforms.
*/
- unsigned read_only:1;
- unsigned centroid:1;
- unsigned sample:1;
- unsigned patch:1;
- unsigned invariant:1;
+ unsigned read_only : 1;
+ unsigned centroid : 1;
+ unsigned sample : 1;
+ unsigned patch : 1;
+ unsigned invariant : 1;
/**
* Is the variable a ray query?
*/
- unsigned ray_query:1;
+ unsigned ray_query : 1;
- /**
+ /**
* Precision qualifier.
*
* In desktop GLSL we do not care about precision qualifiers at all, in
* have the same precision value and the checks we add in the compiler
* for this field will never break a desktop shader compile.
*/
- unsigned precision:2;
+ unsigned precision : 2;
/**
* Has this variable been statically assigned?
* still written after dead code removal, nor is it maintained in
* non-ast_to_hir.cpp (GLSL parsing) paths.
*/
- unsigned assigned:1;
+ unsigned assigned : 1;
/**
* Can this variable be coalesced with another?
* result in a load/store of the variable with an indirect offset which
* the backend may not be able to handle.
*/
- unsigned cannot_coalesce:1;
+ unsigned cannot_coalesce : 1;
/**
* When separate shader programs are enabled, only input/outputs between
* This is also used to make sure xfb varyings that are unused by the
* fragment shader are not removed.
*/
- unsigned always_active_io:1;
+ unsigned always_active_io : 1;
/**
* Interpolation mode for shader inputs / outputs
*
* \sa glsl_interp_mode
*/
- unsigned interpolation:3;
+ unsigned interpolation : 3;
/**
* If non-zero, then this variable may be packed along with other variables
* component of this variable is actually stored in component y of the
* location specified by \c location.
*/
- unsigned location_frac:2;
+ unsigned location_frac : 2;
/**
* If true, this variable represents an array of scalars that should
* be tightly packed. In other words, consecutive array elements
* should be stored one component apart, rather than one slot apart.
*/
- unsigned compact:1;
+ unsigned compact : 1;
/**
* Whether this is a fragment shader output implicitly initialized with
* the previous contents of the specified render target at the
* framebuffer location corresponding to this shader invocation.
*/
- unsigned fb_fetch_output:1;
+ unsigned fb_fetch_output : 1;
/**
* Non-zero if this variable is considered bindless as defined by
* ARB_bindless_texture.
*/
- unsigned bindless:1;
+ unsigned bindless : 1;
/**
* Was an explicit binding set in the shader?
*/
- unsigned explicit_binding:1;
+ unsigned explicit_binding : 1;
/**
* Was the location explicitly set in the shader?
* by the linker or by the API (e.g., calls to \c glBindAttribLocation have
* no effect).
*/
- unsigned explicit_location:1;
+ unsigned explicit_location : 1;
/**
* Is this varying used by transform feedback?
*
* This is used by the linker to decide if it's safe to pack the varying.
*/
- unsigned is_xfb:1;
+ unsigned is_xfb : 1;
/**
* Is this varying used only by transform feedback?
*
* This is used by the linker to decide if its safe to pack the varying.
*/
- unsigned is_xfb_only:1;
+ unsigned is_xfb_only : 1;
/**
* Was a transfer feedback buffer set in the shader?
*/
- unsigned explicit_xfb_buffer:1;
+ unsigned explicit_xfb_buffer : 1;
/**
* Was a transfer feedback stride set in the shader?
*/
- unsigned explicit_xfb_stride:1;
+ unsigned explicit_xfb_stride : 1;
/**
* Was an explicit offset set in the shader?
*/
- unsigned explicit_offset:1;
+ unsigned explicit_offset : 1;
/**
* Layout of the matrix. Uses glsl_matrix_layout values.
*/
- unsigned matrix_layout:2;
+ unsigned matrix_layout : 2;
/**
* Non-zero if this variable was created by lowering a named interface
* block.
*/
- unsigned from_named_ifc_block:1;
+ unsigned from_named_ifc_block : 1;
/**
* Non-zero if the variable must be a shader input. This is useful for
* constraints on function parameters.
*/
- unsigned must_be_shader_input:1;
+ unsigned must_be_shader_input : 1;
/**
* How the variable was declared. See nir_var_declaration_type.
* This is used to detect variables generated by the compiler, so should
* not be visible via the API.
*/
- unsigned how_declared:2;
+ unsigned how_declared : 2;
/**
* Is this variable per-view? If so, we know it must be an array with
* size corresponding to the number of views.
*/
- unsigned per_view:1;
+ unsigned per_view : 1;
/**
* Whether the variable is per-primitive.
* Can be use by Mesh Shader outputs and corresponding Fragment Shader inputs.
*/
- unsigned per_primitive:1;
+ unsigned per_primitive : 1;
/**
* Whether the variable is declared to indicate that a fragment shader
* input will not have interpolated values.
*/
- unsigned per_vertex:1;
+ unsigned per_vertex : 1;
/**
* \brief Layout qualifier for gl_FragDepth. See nir_depth_layout.
* This is not equal to \c ir_depth_layout_none if and only if this
* variable is \c gl_FragDepth and a layout qualifier is specified.
*/
- unsigned depth_layout:3;
+ unsigned depth_layout : 3;
/**
* Vertex stream output identifier.
* For packed outputs, NIR_STREAM_PACKED is set and bits [2*i+1,2*i]
* indicate the stream of the i-th component.
*/
- unsigned stream:9;
+ unsigned stream : 9;
/**
* See gl_access_qualifier.
* Access flags for memory variables (SSBO/global), image uniforms, and
* bindless images in uniforms/inputs/outputs.
*/
- unsigned access:9;
+ unsigned access : 9;
/**
* Descriptor set binding for sampler or UBO.
*/
- unsigned descriptor_set:5;
+ unsigned descriptor_set : 5;
/**
* output index for dual source blending.
/**
* Transform feedback buffer.
*/
- uint16_t buffer:2;
+ uint16_t buffer : 2;
/**
* Transform feedback stride.
*/
/*@{*/
uint16_t num_state_slots; /**< Number of state slots used */
- nir_state_slot *state_slots; /**< State descriptors. */
+ nir_state_slot *state_slots; /**< State descriptors. */
/*@}*/
/**
nir_foreach_variable_in_list_safe(var, &(shader)->variables)
#define nir_foreach_variable_with_modes(var, shader, modes) \
- nir_foreach_variable_in_shader(var, shader) \
+ nir_foreach_variable_in_shader(var, shader) \
if (_nir_shader_variable_has_mode(var, modes))
#define nir_foreach_variable_with_modes_safe(var, shader, modes) \
- nir_foreach_variable_in_shader_safe(var, shader) \
+ nir_foreach_variable_in_shader_safe(var, shader) \
if (_nir_shader_variable_has_mode(var, modes))
#define nir_foreach_shader_in_variable(var, shader) \
#define nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
list_for_each_entry_safe(nir_src, src, &(reg_or_ssa_def)->uses, use_link)
-#define nir_foreach_use(src, reg_or_ssa_def) \
+#define nir_foreach_use(src, reg_or_ssa_def) \
nir_foreach_use_including_if(src, reg_or_ssa_def) \
if (!src->is_if)
-#define nir_foreach_use_safe(src, reg_or_ssa_def) \
+#define nir_foreach_use_safe(src, reg_or_ssa_def) \
nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
if (!src->is_if)
-#define nir_foreach_if_use(src, reg_or_ssa_def) \
+#define nir_foreach_if_use(src, reg_or_ssa_def) \
nir_foreach_use_including_if(src, reg_or_ssa_def) \
if (src->is_if)
-#define nir_foreach_if_use_safe(src, reg_or_ssa_def) \
+#define nir_foreach_if_use_safe(src, reg_or_ssa_def) \
nir_foreach_use_including_if_safe(src, reg_or_ssa_def) \
if (src->is_if)
} nir_alu_type;
/* clang-format on */
-#define NIR_ALU_TYPE_SIZE_MASK 0x79
+#define NIR_ALU_TYPE_SIZE_MASK 0x79
#define NIR_ALU_TYPE_BASE_TYPE_MASK 0x86
static inline unsigned
static inline bool
nir_is_float_control_signed_zero_inf_nan_preserve(unsigned execution_mode, unsigned bit_size)
{
- return (16 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP16) ||
- (32 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP32) ||
- (64 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP64);
+ return (16 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP16) ||
+ (32 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP32) ||
+ (64 == bit_size && execution_mode & FLOAT_CONTROLS_SIGNED_ZERO_INF_NAN_PRESERVE_FP64);
}
static inline bool
nir_is_denorm_flush_to_zero(unsigned execution_mode, unsigned bit_size)
{
- return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP16) ||
- (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32) ||
- (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP64);
+ return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP16) ||
+ (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP32) ||
+ (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP64);
}
static inline bool
nir_is_denorm_preserve(unsigned execution_mode, unsigned bit_size)
{
- return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP16) ||
- (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP32) ||
- (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP64);
+ return (16 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP16) ||
+ (32 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP32) ||
+ (64 == bit_size && execution_mode & FLOAT_CONTROLS_DENORM_PRESERVE_FP64);
}
static inline bool
nir_is_rounding_mode_rtne(unsigned execution_mode, unsigned bit_size)
{
- return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
- (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
- (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
+ return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
+ (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
+ (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
}
static inline bool
nir_is_rounding_mode_rtz(unsigned execution_mode, unsigned bit_size)
{
- return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
- (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
- (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
+ return (16 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
+ (32 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
+ (64 == bit_size && execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
}
static inline bool
nir_has_any_rounding_mode_rtz(unsigned execution_mode)
{
- return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
- (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
- (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
+ return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP16) ||
+ (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP32) ||
+ (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTZ_FP64);
}
static inline bool
nir_has_any_rounding_mode_rtne(unsigned execution_mode)
{
- return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
- (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
- (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
+ return (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP16) ||
+ (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP32) ||
+ (execution_mode & FLOAT_CONTROLS_ROUNDING_MODE_RTE_FP64);
}
static inline nir_rounding_mode
* it must ensure that the resulting value is bit-for-bit identical to the
* original.
*/
- bool exact:1;
+ bool exact : 1;
/**
* Indicates that this instruction doese not cause signed integer wrapping
* to occur, in the form of overflow or underflow.
*/
- bool no_signed_wrap:1;
+ bool no_signed_wrap : 1;
/**
* Indicates that this instruction does not cause unsigned integer wrapping
* to occur, in the form of overflow or underflow.
*/
- bool no_unsigned_wrap:1;
+ bool no_unsigned_wrap : 1;
/** Destination */
nir_alu_dest dest;
typedef enum {
/* Memory ordering. */
- NIR_MEMORY_ACQUIRE = 1 << 0,
- NIR_MEMORY_RELEASE = 1 << 1,
- NIR_MEMORY_ACQ_REL = NIR_MEMORY_ACQUIRE | NIR_MEMORY_RELEASE,
+ NIR_MEMORY_ACQUIRE = 1 << 0,
+ NIR_MEMORY_RELEASE = 1 << 1,
+ NIR_MEMORY_ACQ_REL = NIR_MEMORY_ACQUIRE | NIR_MEMORY_RELEASE,
/* Memory visibility operations. */
NIR_MEMORY_MAKE_AVAILABLE = 1 << 2,
- NIR_MEMORY_MAKE_VISIBLE = 1 << 3,
+ NIR_MEMORY_MAKE_VISIBLE = 1 << 3,
} nir_memory_semantics;
/**
#define NIR_ALIGN_MUL_MAX 0x40000000
typedef struct nir_io_semantics {
- unsigned location:7; /* gl_vert_attrib, gl_varying_slot, or gl_frag_result */
- unsigned num_slots:6; /* max 32, may be pessimistic with const indexing */
- unsigned dual_source_blend_index:1;
- unsigned fb_fetch_output:1; /* for GL_KHR_blend_equation_advanced */
- unsigned gs_streams:8; /* xxyyzzww: 2-bit stream index for each component */
- unsigned medium_precision:1; /* GLSL mediump qualifier */
- unsigned per_view:1;
- unsigned high_16bits:1; /* whether accessing low or high half of the slot */
- unsigned invariant:1; /* The variable has the invariant flag set */
+ unsigned location : 7; /* gl_vert_attrib, gl_varying_slot, or gl_frag_result */
+ unsigned num_slots : 6; /* max 32, may be pessimistic with const indexing */
+ unsigned dual_source_blend_index : 1;
+ unsigned fb_fetch_output : 1; /* for GL_KHR_blend_equation_advanced */
+ unsigned gs_streams : 8; /* xxyyzzww: 2-bit stream index for each component */
+ unsigned medium_precision : 1; /* GLSL mediump qualifier */
+ unsigned per_view : 1;
+ unsigned high_16bits : 1; /* whether accessing low or high half of the slot */
+ unsigned invariant : 1; /* The variable has the invariant flag set */
/* CLIP_DISTn, LAYER, VIEWPORT, and TESS_LEVEL_* have up to 3 uses:
* - an output consumed by the next stage
* - a system value output affecting fixed-func hardware, e.g. the clipper
* The following fields disable the first two. Transform feedback is disabled
* by transform feedback info.
*/
- unsigned no_varying:1; /* whether this output isn't consumed by the next stage */
- unsigned no_sysval_output:1; /* whether this system value output has no
- effect due to current pipeline states */
- unsigned _pad:3;
+ unsigned no_varying : 1; /* whether this output isn't consumed by the next stage */
+ unsigned no_sysval_output : 1; /* whether this system value output has no
+ effect due to current pipeline states */
+ unsigned _pad : 3;
} nir_io_semantics;
/* Transform feedback info for 2 outputs. nir_intrinsic_store_output contains
/* start_component is equal to the index of out[]; add 2 for io_xfb2 */
/* start_component is not relative to nir_intrinsic_component */
/* get the stream index from nir_io_semantics */
- uint8_t num_components:4; /* max 4; if this is 0, xfb is disabled */
- uint8_t buffer:4; /* buffer index, max 3 */
- uint8_t offset; /* transform feedback buffer offset in dwords,
- max (1K - 4) bytes */
+ uint8_t num_components : 4; /* max 4; if this is 0, xfb is disabled */
+ uint8_t buffer : 4; /* buffer index, max 3 */
+ uint8_t offset; /* transform feedback buffer offset in dwords,
+ max (1K - 4) bytes */
} out[2];
} nir_io_xfb;
/** Texture instruction opcode */
typedef enum {
- nir_texop_tex, /**< Regular texture look-up */
- nir_texop_txb, /**< Texture look-up with LOD bias */
- nir_texop_txl, /**< Texture look-up with explicit LOD */
- nir_texop_txd, /**< Texture look-up with partial derivatives */
- nir_texop_txf, /**< Texel fetch with explicit LOD */
- nir_texop_txf_ms, /**< Multisample texture fetch */
- nir_texop_txf_ms_fb, /**< Multisample texture fetch from framebuffer */
- nir_texop_txf_ms_mcs_intel, /**< Multisample compression value fetch */
- nir_texop_txs, /**< Texture size */
- nir_texop_lod, /**< Texture lod query */
- nir_texop_tg4, /**< Texture gather */
- nir_texop_query_levels, /**< Texture levels query */
- nir_texop_texture_samples, /**< Texture samples query */
- nir_texop_samples_identical, /**< Query whether all samples are definitely
- * identical.
- */
- nir_texop_tex_prefetch, /**< Regular texture look-up, eligible for pre-dispatch */
+ nir_texop_tex, /**< Regular texture look-up */
+ nir_texop_txb, /**< Texture look-up with LOD bias */
+ nir_texop_txl, /**< Texture look-up with explicit LOD */
+ nir_texop_txd, /**< Texture look-up with partial derivatives */
+ nir_texop_txf, /**< Texel fetch with explicit LOD */
+ nir_texop_txf_ms, /**< Multisample texture fetch */
+ nir_texop_txf_ms_fb, /**< Multisample texture fetch from framebuffer */
+ nir_texop_txf_ms_mcs_intel, /**< Multisample compression value fetch */
+ nir_texop_txs, /**< Texture size */
+ nir_texop_lod, /**< Texture lod query */
+ nir_texop_tg4, /**< Texture gather */
+ nir_texop_query_levels, /**< Texture levels query */
+ nir_texop_texture_samples, /**< Texture samples query */
+ nir_texop_samples_identical, /**< Query whether all samples are definitely
+ * identical.
+ */
+ nir_texop_tex_prefetch, /**< Regular texture look-up, eligible for pre-dispatch */
nir_texop_fragment_fetch_amd, /**< Multisample fragment color texture fetch */
nir_texop_fragment_mask_fetch_amd, /**< Multisample fragment mask texture fetch */
- nir_texop_descriptor_amd, /**< Returns a buffer or image descriptor. */
- nir_texop_sampler_descriptor_amd, /**< Returns a sampler descriptor. */
- nir_texop_lod_bias_agx, /**< Returns the sampler's LOD bias */
+ nir_texop_descriptor_amd, /**< Returns a buffer or image descriptor. */
+ nir_texop_sampler_descriptor_amd, /**< Returns a sampler descriptor. */
+ nir_texop_lod_bias_agx, /**< Returns the sampler's LOD bias */
} nir_texop;
/** Represents a texture instruction */
{
for (unsigned i = 0; i < instr->num_srcs; i++)
if (instr->src[i].src_type == type)
- return (int) i;
+ return (int)i;
return -1;
}
nir_parallel_copy_instr, instr,
type, nir_instr_type_parallel_copy)
+#define NIR_DEFINE_SRC_AS_CONST(type, suffix) \
+ static inline type \
+ nir_src_comp_as_##suffix(nir_src src, unsigned comp) \
+ { \
+ assert(nir_src_is_const(src)); \
+ nir_load_const_instr *load = \
+ nir_instr_as_load_const(src.ssa->parent_instr); \
+ assert(comp < load->def.num_components); \
+ return nir_const_value_as_##suffix(load->value[comp], \
+ load->def.bit_size); \
+ } \
+ \
+ static inline type \
+ nir_src_as_##suffix(nir_src src) \
+ { \
+ assert(nir_src_num_components(src) == 1); \
+ return nir_src_comp_as_##suffix(src, 0); \
+ }
-#define NIR_DEFINE_SRC_AS_CONST(type, suffix) \
-static inline type \
-nir_src_comp_as_##suffix(nir_src src, unsigned comp) \
-{ \
- assert(nir_src_is_const(src)); \
- nir_load_const_instr *load = \
- nir_instr_as_load_const(src.ssa->parent_instr); \
- assert(comp < load->def.num_components); \
- return nir_const_value_as_##suffix(load->value[comp], \
- load->def.bit_size); \
-} \
- \
-static inline type \
-nir_src_as_##suffix(nir_src src) \
-{ \
- assert(nir_src_num_components(src) == 1); \
- return nir_src_comp_as_##suffix(src, 0); \
-}
-
-NIR_DEFINE_SRC_AS_CONST(int64_t, int)
-NIR_DEFINE_SRC_AS_CONST(uint64_t, uint)
-NIR_DEFINE_SRC_AS_CONST(bool, bool)
-NIR_DEFINE_SRC_AS_CONST(double, float)
+NIR_DEFINE_SRC_AS_CONST(int64_t, int)
+NIR_DEFINE_SRC_AS_CONST(uint64_t, uint)
+NIR_DEFINE_SRC_AS_CONST(bool, bool)
+NIR_DEFINE_SRC_AS_CONST(double, float)
#undef NIR_DEFINE_SRC_AS_CONST
-
typedef struct {
nir_ssa_def *def;
unsigned comp;
return load->value[s.comp];
}
-#define NIR_DEFINE_SCALAR_AS_CONST(type, suffix) \
-static inline type \
-nir_ssa_scalar_as_##suffix(nir_ssa_scalar s) \
-{ \
- return nir_const_value_as_##suffix( \
- nir_ssa_scalar_as_const_value(s), s.def->bit_size); \
-}
+#define NIR_DEFINE_SCALAR_AS_CONST(type, suffix) \
+ static inline type \
+ nir_ssa_scalar_as_##suffix(nir_ssa_scalar s) \
+ { \
+ return nir_const_value_as_##suffix( \
+ nir_ssa_scalar_as_const_value(s), s.def->bit_size); \
+ }
-NIR_DEFINE_SCALAR_AS_CONST(int64_t, int)
-NIR_DEFINE_SCALAR_AS_CONST(uint64_t, uint)
-NIR_DEFINE_SCALAR_AS_CONST(bool, bool)
-NIR_DEFINE_SCALAR_AS_CONST(double, float)
+NIR_DEFINE_SCALAR_AS_CONST(int64_t, int)
+NIR_DEFINE_SCALAR_AS_CONST(uint64_t, uint)
+NIR_DEFINE_SCALAR_AS_CONST(bool, bool)
+NIR_DEFINE_SCALAR_AS_CONST(double, float)
#undef NIR_DEFINE_SCALAR_AS_CONST
nir_binding nir_chase_binding(nir_src rsrc);
nir_variable *nir_get_binding_variable(struct nir_shader *shader, nir_binding binding);
-
/*
* Control flow
*
nir_instr *instr = nir_block_last_instr(block);
return instr->type == nir_instr_type_jump &&
- nir_instr_as_jump(instr)->type == nir_jump_break;
+ nir_instr_as_jump(instr)->type == nir_jump_break;
}
#define nir_foreach_instr(instr, block) \
return NULL;
}
-#define nir_foreach_phi(instr, block) \
- for (nir_phi_instr *instr = nir_first_phi_in_block(block); instr != NULL; \
+#define nir_foreach_phi(instr, block) \
+ for (nir_phi_instr *instr = nir_first_phi_in_block(block); instr != NULL; \
instr = nir_next_phi(instr))
-#define nir_foreach_phi_safe(instr, block) \
- for (nir_phi_instr *instr = nir_first_phi_in_block(block), \
- *__next = instr ? nir_next_phi(instr) : NULL; \
- instr != NULL; \
+#define nir_foreach_phi_safe(instr, block) \
+ for (nir_phi_instr *instr = nir_first_phi_in_block(block), \
+ *__next = instr ? nir_next_phi(instr) : NULL; \
+ instr != NULL; \
instr = __next, __next = instr ? nir_next_phi(instr) : NULL)
static inline nir_phi_instr *
typedef struct {
nir_cf_node cf_node;
- struct exec_list body; /** < list of nir_cf_node */
+ struct exec_list body; /** < list of nir_cf_node */
struct exec_list continue_list; /** < (optional) list of nir_cf_node */
nir_loop_info *info;
ATTRIBUTE_RETURNS_NONNULL static inline nir_block *
nir_start_block(nir_function_impl *impl)
{
- return (nir_block *) impl->body.head_sentinel.next;
+ return (nir_block *)impl->body.head_sentinel.next;
}
ATTRIBUTE_RETURNS_NONNULL static inline nir_block *
nir_impl_last_block(nir_function_impl *impl)
{
- return (nir_block *) impl->body.tail_sentinel.prev;
+ return (nir_block *)impl->body.tail_sentinel.prev;
}
static inline nir_cf_node *
} nir_divergence_options;
typedef enum {
- nir_pack_varying_interp_mode_none = (1 << 0),
- nir_pack_varying_interp_mode_smooth = (1 << 1),
- nir_pack_varying_interp_mode_flat = (1 << 2),
+ nir_pack_varying_interp_mode_none = (1 << 0),
+ nir_pack_varying_interp_mode_smooth = (1 << 1),
+ nir_pack_varying_interp_mode_flat = (1 << 2),
nir_pack_varying_interp_mode_noperspective = (1 << 3),
- nir_pack_varying_interp_loc_sample = (1 << 16),
- nir_pack_varying_interp_loc_centroid = (1 << 17),
- nir_pack_varying_interp_loc_center = (1 << 18),
+ nir_pack_varying_interp_loc_sample = (1 << 16),
+ nir_pack_varying_interp_loc_centroid = (1 << 17),
+ nir_pack_varying_interp_loc_center = (1 << 18),
} nir_pack_varying_options;
/** An instruction filtering callback
*/
bool use_interpolated_input_intrinsics;
-
/**
* Whether nir_lower_io() will lower interpolateAt functions to
* load_interpolated_input intrinsics.
return NULL;
}
-#define nir_foreach_function_with_impl(it, impl_it, shader) \
- for (nir_function *it =nir_foreach_function_with_impl_first(shader); \
- it != NULL; \
- it = NULL) \
- \
- for (nir_function_impl *impl_it = it->impl; \
- impl_it != NULL; \
+#define nir_foreach_function_with_impl(it, impl_it, shader) \
+ for (nir_function *it = nir_foreach_function_with_impl_first(shader); \
+ it != NULL; \
+ it = NULL) \
+ \
+ for (nir_function_impl *impl_it = it->impl; \
+ impl_it != NULL; \
impl_it = nir_foreach_function_with_impl_next(&it))
/* Equivalent to
nir_const_value *nir_src_as_const_value(nir_src src);
-#define NIR_SRC_AS_(name, c_type, type_enum, cast_macro) \
-static inline c_type * \
-nir_src_as_ ## name (nir_src src) \
-{ \
- return src.ssa->parent_instr->type == type_enum \
- ? cast_macro(src.ssa->parent_instr) : NULL; \
-}
+#define NIR_SRC_AS_(name, c_type, type_enum, cast_macro) \
+ static inline c_type * \
+ nir_src_as_##name(nir_src src) \
+ { \
+ return src.ssa->parent_instr->type == type_enum \
+ ? cast_macro(src.ssa->parent_instr) \
+ : NULL; \
+ }
NIR_SRC_AS_(alu_instr, nir_alu_instr, nir_instr_type_alu, nir_instr_as_alu)
NIR_SRC_AS_(intrinsic, nir_intrinsic_instr,
return list_is_empty(&ssa->uses);
}
-
/** Returns the next block, disregarding structure
*
* The ordering is deterministic but has no guarantees beyond that. In
nir_block *nir_block_unstructured_next(nir_block *block);
nir_block *nir_unstructured_start_block(nir_function_impl *impl);
-#define nir_foreach_block_unstructured(block, impl) \
+#define nir_foreach_block_unstructured(block, impl) \
for (nir_block *block = nir_unstructured_start_block(impl); block != NULL; \
block = nir_block_unstructured_next(block))
-#define nir_foreach_block_unstructured_safe(block, impl) \
+#define nir_foreach_block_unstructured_safe(block, impl) \
for (nir_block *block = nir_unstructured_start_block(impl), \
- *next = nir_block_unstructured_next(block); \
- block != NULL; \
+ *next = nir_block_unstructured_next(block); \
+ block != NULL; \
block = next, next = nir_block_unstructured_next(block))
/*
/* Macros for loops that visit blocks in source-code order */
-#define nir_foreach_block(block, impl) \
+#define nir_foreach_block(block, impl) \
for (nir_block *block = nir_start_block(impl); block != NULL; \
block = nir_block_cf_tree_next(block))
-#define nir_foreach_block_safe(block, impl) \
- for (nir_block *block = nir_start_block(impl), \
- *next = nir_block_cf_tree_next(block); \
- block != NULL; \
+#define nir_foreach_block_safe(block, impl) \
+ for (nir_block *block = nir_start_block(impl), \
+ *next = nir_block_cf_tree_next(block); \
+ block != NULL; \
block = next, next = nir_block_cf_tree_next(block))
-#define nir_foreach_block_reverse(block, impl) \
+#define nir_foreach_block_reverse(block, impl) \
for (nir_block *block = nir_impl_last_block(impl); block != NULL; \
block = nir_block_cf_tree_prev(block))
-#define nir_foreach_block_reverse_safe(block, impl) \
- for (nir_block *block = nir_impl_last_block(impl), \
- *prev = nir_block_cf_tree_prev(block); \
- block != NULL; \
+#define nir_foreach_block_reverse_safe(block, impl) \
+ for (nir_block *block = nir_impl_last_block(impl), \
+ *prev = nir_block_cf_tree_prev(block); \
+ block != NULL; \
block = prev, prev = nir_block_cf_tree_prev(block))
-#define nir_foreach_block_in_cf_node(block, node) \
+#define nir_foreach_block_in_cf_node(block, node) \
for (nir_block *block = nir_cf_node_cf_tree_first(node); \
- block != nir_cf_node_cf_tree_next(node); \
+ block != nir_cf_node_cf_tree_next(node); \
block = nir_block_cf_tree_next(block))
/* If the following CF node is an if, this function returns that if.
void nir_print_instr(const nir_instr *instr, FILE *fp);
void nir_print_deref(const nir_deref_instr *deref, FILE *fp);
void nir_log_shader_annotated_tagged(enum mesa_log_level level, const char *tag, nir_shader *shader, struct hash_table *annotations);
-#define nir_log_shadere(s) nir_log_shader_annotated_tagged(MESA_LOG_ERROR, (MESA_LOG_TAG), (s), NULL)
-#define nir_log_shaderw(s) nir_log_shader_annotated_tagged(MESA_LOG_WARN, (MESA_LOG_TAG), (s), NULL)
-#define nir_log_shaderi(s) nir_log_shader_annotated_tagged(MESA_LOG_INFO, (MESA_LOG_TAG), (s), NULL)
+#define nir_log_shadere(s) nir_log_shader_annotated_tagged(MESA_LOG_ERROR, (MESA_LOG_TAG), (s), NULL)
+#define nir_log_shaderw(s) nir_log_shader_annotated_tagged(MESA_LOG_WARN, (MESA_LOG_TAG), (s), NULL)
+#define nir_log_shaderi(s) nir_log_shader_annotated_tagged(MESA_LOG_INFO, (MESA_LOG_TAG), (s), NULL)
#define nir_log_shader_annotated(s, annotations) nir_log_shader_annotated_tagged(MESA_LOG_ERROR, (MESA_LOG_TAG), (s), annotations)
char *nir_shader_as_str(nir_shader *nir, void *mem_ctx);
return unlikely(nir_debug_print_shader[shader->info.stage]);
}
#else
-static inline void nir_validate_shader(nir_shader *shader, const char *when) { (void) shader; (void)when; }
-static inline void nir_validate_ssa_dominance(nir_shader *shader, const char *when) { (void) shader; (void)when; }
-static inline void nir_metadata_set_validation_flag(nir_shader *shader) { (void) shader; }
-static inline void nir_metadata_check_validation_flag(nir_shader *shader) { (void) shader; }
-static inline bool should_skip_nir(UNUSED const char *pass_name) { return false; }
-static inline bool should_print_nir(UNUSED nir_shader *shader) { return false; }
+static inline void
+nir_validate_shader(nir_shader *shader, const char *when)
+{
+ (void)shader;
+ (void)when;
+}
+static inline void
+nir_validate_ssa_dominance(nir_shader *shader, const char *when)
+{
+ (void)shader;
+ (void)when;
+}
+static inline void
+nir_metadata_set_validation_flag(nir_shader *shader)
+{
+ (void)shader;
+}
+static inline void
+nir_metadata_check_validation_flag(nir_shader *shader)
+{
+ (void)shader;
+}
+static inline bool
+should_skip_nir(UNUSED const char *pass_name)
+{
+ return false;
+}
+static inline bool
+should_print_nir(UNUSED nir_shader *shader)
+{
+ return false;
+}
#endif /* NDEBUG */
-#define _PASS(pass, nir, do_pass) do { \
- if (should_skip_nir(#pass)) { \
- printf("skipping %s\n", #pass); \
- break; \
- } \
- do_pass \
- if (NIR_DEBUG(CLONE)) { \
- nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
- nir_shader_replace(nir, clone); \
- } \
- if (NIR_DEBUG(SERIALIZE)) { \
- nir_shader_serialize_deserialize(nir); \
- } \
-} while (0)
-
-#define NIR_PASS(progress, nir, pass, ...) _PASS(pass, nir, { \
- nir_metadata_set_validation_flag(nir); \
- if (should_print_nir(nir)) \
- printf("%s\n", #pass); \
- if (pass(nir, ##__VA_ARGS__)) { \
- nir_validate_shader(nir, "after " #pass " in " __FILE__); \
- UNUSED bool _; \
- progress = true; \
- if (should_print_nir(nir)) \
- nir_print_shader(nir, stdout); \
- nir_metadata_check_validation_flag(nir); \
- } \
+#define _PASS(pass, nir, do_pass) \
+ do { \
+ if (should_skip_nir(#pass)) { \
+ printf("skipping %s\n", #pass); \
+ break; \
+ } \
+ do_pass if (NIR_DEBUG(CLONE)) \
+ { \
+ nir_shader *clone = nir_shader_clone(ralloc_parent(nir), nir); \
+ nir_shader_replace(nir, clone); \
+ } \
+ if (NIR_DEBUG(SERIALIZE)) { \
+ nir_shader_serialize_deserialize(nir); \
+ } \
+ } while (0)
+
+#define NIR_PASS(progress, nir, pass, ...) _PASS(pass, nir, { \
+ nir_metadata_set_validation_flag(nir); \
+ if (should_print_nir(nir)) \
+ printf("%s\n", #pass); \
+ if (pass(nir, ##__VA_ARGS__)) { \
+ nir_validate_shader(nir, "after " #pass " in " __FILE__); \
+ UNUSED bool _; \
+ progress = true; \
+ if (should_print_nir(nir)) \
+ nir_print_shader(nir, stdout); \
+ nir_metadata_check_validation_flag(nir); \
+ } \
})
-#define NIR_PASS_V(nir, pass, ...) _PASS(pass, nir, { \
- if (should_print_nir(nir)) \
- printf("%s\n", #pass); \
- pass(nir, ##__VA_ARGS__); \
- nir_validate_shader(nir, "after " #pass " in " __FILE__); \
- if (should_print_nir(nir)) \
- nir_print_shader(nir, stdout); \
+#define NIR_PASS_V(nir, pass, ...) _PASS(pass, nir, { \
+ if (should_print_nir(nir)) \
+ printf("%s\n", #pass); \
+ pass(nir, ##__VA_ARGS__); \
+ nir_validate_shader(nir, "after " #pass " in " __FILE__); \
+ if (should_print_nir(nir)) \
+ nir_print_shader(nir, stdout); \
})
#define NIR_SKIP(name) should_skip_nir(#name)
bool nir_lower_global_vars_to_local(nir_shader *shader);
typedef enum {
- nir_lower_direct_array_deref_of_vec_load = (1 << 0),
- nir_lower_indirect_array_deref_of_vec_load = (1 << 1),
- nir_lower_direct_array_deref_of_vec_store = (1 << 2),
- nir_lower_indirect_array_deref_of_vec_store = (1 << 3),
+ nir_lower_direct_array_deref_of_vec_load = (1 << 0),
+ nir_lower_indirect_array_deref_of_vec_load = (1 << 1),
+ nir_lower_direct_array_deref_of_vec_store = (1 << 2),
+ nir_lower_indirect_array_deref_of_vec_store = (1 << 3),
} nir_lower_array_deref_of_vec_options;
bool nir_lower_array_deref_of_vec(nir_shader *shader, nir_variable_mode modes,
* An address format which is a 64-bit value, where the high 32 bits
* are a buffer index, and the low 32 bits are an offset.
*/
- nir_address_format_32bit_index_offset_pack64,
+ nir_address_format_32bit_index_offset_pack64,
/**
* An address format which is comprised of a vec3 where the first two
/**
* An address format which is a simple 32-bit offset cast to 64-bit.
*/
- nir_address_format_32bit_offset_as_64bit,
+ nir_address_format_32bit_offset_as_64bit,
/**
* An address format representing a purely logical addressing model. In
nir_ssa_def *nir_build_addr_isub(struct nir_builder *b, nir_ssa_def *addr0, nir_ssa_def *addr1,
nir_address_format addr_format);
-nir_ssa_def * nir_explicit_io_address_from_deref(struct nir_builder *b,
- nir_deref_instr *deref,
- nir_ssa_def *base_addr,
- nir_address_format addr_format);
+nir_ssa_def *nir_explicit_io_address_from_deref(struct nir_builder *b,
+ nir_deref_instr *deref,
+ nir_ssa_def *base_addr,
+ nir_address_format addr_format);
bool nir_get_explicit_deref_align(nir_deref_instr *deref,
bool default_to_type_align,
bool lower_shared;
} nir_lower_robust_access_options;
-
bool nir_lower_robust_access(nir_shader *s,
const nir_lower_robust_access_options *opts);
bool nir_lower_io_to_scalar_early(nir_shader *shader, nir_variable_mode mask);
bool nir_lower_io_to_vector(nir_shader *shader, nir_variable_mode mask);
bool nir_vectorize_tess_levels(nir_shader *shader);
-nir_shader * nir_create_passthrough_tcs_impl(const nir_shader_compiler_options *options,
- unsigned *locations, unsigned num_locations,
- uint8_t patch_vertices);
-nir_shader * nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
- const nir_shader *vs, uint8_t patch_vertices);
-nir_shader * nir_create_passthrough_gs(const nir_shader_compiler_options *options,
- const nir_shader *prev_stage,
- enum mesa_prim primitive_type,
- bool emulate_edgeflags,
- bool force_line_strip_out);
+nir_shader *nir_create_passthrough_tcs_impl(const nir_shader_compiler_options *options,
+ unsigned *locations, unsigned num_locations,
+ uint8_t patch_vertices);
+nir_shader *nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
+ const nir_shader *vs, uint8_t patch_vertices);
+nir_shader *nir_create_passthrough_gs(const nir_shader_compiler_options *options,
+ const nir_shader *prev_stage,
+ enum mesa_prim primitive_type,
+ bool emulate_edgeflags,
+ bool force_line_strip_out);
bool nir_lower_fragcolor(nir_shader *shader, unsigned max_cbufs);
bool nir_lower_fragcoord_wtrans(nir_shader *shader);
uint8_t subgroup_size;
uint8_t ballot_bit_size;
uint8_t ballot_components;
- bool lower_to_scalar:1;
- bool lower_vote_trivial:1;
- bool lower_vote_eq:1;
- bool lower_subgroup_masks:1;
- bool lower_relative_shuffle:1;
- bool lower_shuffle_to_32bit:1;
- bool lower_shuffle_to_swizzle_amd:1;
- bool lower_shuffle:1;
- bool lower_quad:1;
- bool lower_quad_broadcast_dynamic:1;
- bool lower_quad_broadcast_dynamic_to_const:1;
- bool lower_elect:1;
- bool lower_read_invocation_to_cond:1;
- bool lower_rotate_to_shuffle:1;
- bool lower_ballot_bit_count_to_mbcnt_amd:1;
+ bool lower_to_scalar : 1;
+ bool lower_vote_trivial : 1;
+ bool lower_vote_eq : 1;
+ bool lower_subgroup_masks : 1;
+ bool lower_relative_shuffle : 1;
+ bool lower_shuffle_to_32bit : 1;
+ bool lower_shuffle_to_swizzle_amd : 1;
+ bool lower_shuffle : 1;
+ bool lower_quad : 1;
+ bool lower_quad_broadcast_dynamic : 1;
+ bool lower_quad_broadcast_dynamic_to_const : 1;
+ bool lower_elect : 1;
+ bool lower_read_invocation_to_cond : 1;
+ bool lower_rotate_to_shuffle : 1;
+ bool lower_ballot_bit_count_to_mbcnt_amd : 1;
} nir_lower_subgroups_options;
bool nir_lower_subgroups(nir_shader *shader,
nir_build_lowered_load_helper_invocation(struct nir_builder *b);
typedef struct nir_lower_compute_system_values_options {
- bool has_base_global_invocation_id:1;
- bool has_base_workgroup_id:1;
- bool shuffle_local_ids_for_quad_derivatives:1;
- bool lower_local_invocation_index:1;
- bool lower_cs_local_id_to_index:1;
- bool lower_workgroup_id_to_index:1;
+ bool has_base_global_invocation_id : 1;
+ bool has_base_workgroup_id : 1;
+ bool shuffle_local_ids_for_quad_derivatives : 1;
+ bool lower_local_invocation_index : 1;
+ bool lower_cs_local_id_to_index : 1;
+ bool lower_workgroup_id_to_index : 1;
/* At shader execution time, check if WorkGroupId should be 1D
* and compute it quickly. Fall back to slow computation if not.
*/
- bool shortcut_1d_workgroup_id:1;
+ bool shortcut_1d_workgroup_id : 1;
uint16_t num_workgroups[3]; /* Compile-time-known dispatch sizes, or 0 if unknown. */
} nir_lower_compute_system_values_options;
const nir_lower_compute_system_values_options *options);
struct nir_lower_sysvals_to_varyings_options {
- bool frag_coord:1;
- bool front_face:1;
- bool point_coord:1;
+ bool frag_coord : 1;
+ bool front_face : 1;
+ bool point_coord : 1;
};
bool
bool nir_lower_tex(nir_shader *shader,
const nir_lower_tex_options *options);
-
typedef struct nir_lower_tex_shadow_swizzle {
- unsigned swizzle_r:3;
- unsigned swizzle_g:3;
- unsigned swizzle_b:3;
- unsigned swizzle_a:3;
+ unsigned swizzle_r : 3;
+ unsigned swizzle_g : 3;
+ unsigned swizzle_b : 3;
+ unsigned swizzle_a : 3;
} nir_lower_tex_shadow_swizzle;
bool
*/
bool lower_to_fragment_mask_load_amd;
- /**
- * Lower image_samples to a constant in case the driver doesn't support multisampled
- * images.
- */
- bool lower_image_samples_to_one;
+ /**
+ * Lower image_samples to a constant in case the driver doesn't support multisampled
+ * images.
+ */
+ bool lower_image_samples_to_one;
} nir_lower_image_options;
bool nir_lower_image(nir_shader *nir,
bool nir_lower_readonly_images_to_tex(nir_shader *shader, bool per_variable);
enum nir_lower_non_uniform_access_type {
- nir_lower_non_uniform_ubo_access = (1 << 0),
- nir_lower_non_uniform_ssbo_access = (1 << 1),
+ nir_lower_non_uniform_ubo_access = (1 << 0),
+ nir_lower_non_uniform_ssbo_access = (1 << 1),
nir_lower_non_uniform_texture_access = (1 << 2),
- nir_lower_non_uniform_image_access = (1 << 3),
- nir_lower_non_uniform_get_ssbo_size = (1 << 4),
+ nir_lower_non_uniform_image_access = (1 << 3),
+ nir_lower_non_uniform_get_ssbo_size = (1 << 4),
};
/* Given the nir_src used for the resource, return the channels which might be non-uniform. */
typedef struct nir_lower_wpos_ytransform_options {
gl_state_index16 state_tokens[STATE_LENGTH];
- bool fs_coord_origin_upper_left :1;
- bool fs_coord_origin_lower_left :1;
- bool fs_coord_pixel_center_integer :1;
- bool fs_coord_pixel_center_half_integer :1;
+ bool fs_coord_origin_upper_left : 1;
+ bool fs_coord_origin_lower_left : 1;
+ bool fs_coord_pixel_center_integer : 1;
+ bool fs_coord_pixel_center_half_integer : 1;
} nir_lower_wpos_ytransform_options;
bool nir_lower_wpos_ytransform(nir_shader *shader,
gl_state_index16 bias_state_tokens[STATE_LENGTH];
unsigned drawpix_sampler;
unsigned pixelmap_sampler;
- bool pixel_maps :1;
- bool scale_and_bias :1;
+ bool pixel_maps : 1;
+ bool scale_and_bias : 1;
} nir_lower_drawpixels_options;
void nir_lower_drawpixels(nir_shader *shader,
typedef enum {
nir_lower_interpolation_at_sample = (1 << 1),
nir_lower_interpolation_at_offset = (1 << 2),
- nir_lower_interpolation_centroid = (1 << 3),
- nir_lower_interpolation_pixel = (1 << 4),
- nir_lower_interpolation_sample = (1 << 5),
+ nir_lower_interpolation_centroid = (1 << 3),
+ nir_lower_interpolation_pixel = (1 << 4),
+ nir_lower_interpolation_sample = (1 << 5),
} nir_lower_interpolation_options;
bool nir_lower_interpolation(nir_shader *shader,
bool nir_opt_loop_unroll(nir_shader *shader);
typedef enum {
- nir_move_const_undef = (1 << 0),
- nir_move_load_ubo = (1 << 1),
- nir_move_load_input = (1 << 2),
- nir_move_comparisons = (1 << 3),
- nir_move_copies = (1 << 4),
- nir_move_load_ssbo = (1 << 5),
- nir_move_load_uniform = (1 << 6),
+ nir_move_const_undef = (1 << 0),
+ nir_move_load_ubo = (1 << 1),
+ nir_move_load_input = (1 << 2),
+ nir_move_comparisons = (1 << 3),
+ nir_move_copies = (1 << 4),
+ nir_move_load_ssbo = (1 << 5),
+ nir_move_load_uniform = (1 << 6),
} nir_move_options;
bool nir_can_move_instr(nir_instr *instr, nir_move_options options);
static inline unsigned
nir_variable_count_slots(const nir_variable *var, const struct glsl_type *type)
{
- return var->data.compact ?
- DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4) :
- glsl_count_attribute_slots(type, false);
+ return var->data.compact ? DIV_ROUND_UP(var->data.location_frac + glsl_get_length(type), 4) : glsl_count_attribute_slots(type, false);
}
/* See default_ub_config in nir_range_analysis.c for documentation. */
return NULL;
}
-#define nir_foreach_reg_decl(reg, impl) \
- for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl); \
+#define nir_foreach_reg_decl(reg, impl) \
+ for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl); \
reg; reg = nir_next_decl_reg(reg, NULL))
-#define nir_foreach_reg_decl_safe(reg, impl) \
- for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl), \
- *next_ = nir_next_decl_reg(reg, NULL); \
+#define nir_foreach_reg_decl_safe(reg, impl) \
+ for (nir_intrinsic_instr *reg = nir_next_decl_reg(NULL, impl), \
+ *next_ = nir_next_decl_reg(reg, NULL); \
reg; reg = next_, next_ = nir_next_decl_reg(next_, NULL))
static inline bool
intr->intrinsic == nir_intrinsic_store_reg_indirect;
}
-#define nir_foreach_reg_load(load, reg) \
- assert(reg->intrinsic == nir_intrinsic_decl_reg); \
- \
- nir_foreach_use(load, ®->dest.ssa) \
+#define nir_foreach_reg_load(load, reg) \
+ assert(reg->intrinsic == nir_intrinsic_decl_reg); \
+ \
+ nir_foreach_use(load, ®->dest.ssa) \
if (nir_is_load_reg(nir_instr_as_intrinsic(load->parent_instr)))
-#define nir_foreach_reg_store(store, reg) \
- assert(reg->intrinsic == nir_intrinsic_decl_reg); \
- \
- nir_foreach_use(store, ®->dest.ssa) \
+#define nir_foreach_reg_store(store, reg) \
+ assert(reg->intrinsic == nir_intrinsic_decl_reg); \
+ \
+ nir_foreach_use(store, ®->dest.ssa) \
if (nir_is_store_reg(nir_instr_as_intrinsic(store->parent_instr)))
static inline nir_intrinsic_instr *
#include "nir_builder.h"
nir_builder MUST_CHECK PRINTFLIKE(3, 4)
-nir_builder_init_simple_shader(gl_shader_stage stage,
- const nir_shader_compiler_options *options,
- const char *name, ...)
+ nir_builder_init_simple_shader(gl_shader_stage stage,
+ const nir_shader_compiler_options *options,
+ const char *name, ...)
{
nir_builder b;
bit_size = src_bit_size;
} else {
assert(src_bit_size ==
- nir_alu_type_get_type_size(op_info->input_types[i]));
+ nir_alu_type_get_type_size(op_info->input_types[i]));
}
}
}
nir_ssa_def *
nir_build_alu2(nir_builder *build, nir_op op, nir_ssa_def *src0,
- nir_ssa_def *src1)
+ nir_ssa_def *src1)
{
nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
if (!instr)
nir_ssa_def *
nir_build_alu3(nir_builder *build, nir_op op, nir_ssa_def *src0,
- nir_ssa_def *src1, nir_ssa_def *src2)
+ nir_ssa_def *src1, nir_ssa_def *src2)
{
nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
if (!instr)
nir_ssa_def *
nir_build_alu4(nir_builder *build, nir_op op, nir_ssa_def *src0,
- nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)
+ nir_ssa_def *src1, nir_ssa_def *src2, nir_ssa_def *src3)
{
nir_alu_instr *instr = nir_alu_instr_create(build->shader, op);
if (!instr)
case nir_tex_src_coord:
tex->coord_components = nir_src_num_components(extra_srcs[i].src);
assert(tex->coord_components == tex->is_array +
- glsl_get_sampler_dim_coordinate_components(tex->sampler_dim));
+ glsl_get_sampler_dim_coordinate_components(tex->sampler_dim));
break;
case nir_tex_src_lod:
nir_alu_type_get_type_size(src_type) == src->bit_size);
const nir_alu_type dst_base =
- (nir_alu_type) nir_alu_type_get_base_type(dest_type);
+ (nir_alu_type)nir_alu_type_get_base_type(dest_type);
const nir_alu_type src_base =
- (nir_alu_type) nir_alu_type_get_base_type(src_type);
+ (nir_alu_type)nir_alu_type_get_base_type(src_type);
/* b2b uses the regular type conversion path, but i2b and f2b are
* implemented as src != 0.
if (src_base == nir_type_float) {
switch (dst_bit_size) {
- case 1: opcode = nir_op_fneu; break;
- case 8: opcode = nir_op_fneu8; break;
- case 16: opcode = nir_op_fneu16; break;
- case 32: opcode = nir_op_fneu32; break;
- default: unreachable("Invalid Boolean size.");
+ case 1:
+ opcode = nir_op_fneu;
+ break;
+ case 8:
+ opcode = nir_op_fneu8;
+ break;
+ case 16:
+ opcode = nir_op_fneu16;
+ break;
+ case 32:
+ opcode = nir_op_fneu32;
+ break;
+ default:
+ unreachable("Invalid Boolean size.");
}
} else {
assert(src_base == nir_type_int || src_base == nir_type_uint);
switch (dst_bit_size) {
- case 1: opcode = nir_op_ine; break;
- case 8: opcode = nir_op_ine8; break;
- case 16: opcode = nir_op_ine16; break;
- case 32: opcode = nir_op_ine32; break;
- default: unreachable("Invalid Boolean size.");
+ case 1:
+ opcode = nir_op_ine;
+ break;
+ case 8:
+ opcode = nir_op_ine8;
+ break;
+ case 16:
+ opcode = nir_op_ine16;
+ break;
+ case 32:
+ opcode = nir_op_ine32;
+ break;
+ default:
+ unreachable("Invalid Boolean size.");
}
}
nir_imm_zero(b, src->num_components, src->bit_size),
NULL, NULL);
} else {
- src_type = (nir_alu_type) (src_type | src->bit_size);
+ src_type = (nir_alu_type)(src_type | src->bit_size);
nir_op opcode =
nir_type_conversion_op(src_type, dest_type, rnd);
#ifndef NIR_BUILDER_H
#define NIR_BUILDER_H
-#include "nir_control_flow.h"
#include "util/bitscan.h"
#include "util/half_float.h"
+#include "nir_control_flow.h"
#ifdef __cplusplus
extern "C" {
}
nir_builder MUST_CHECK PRINTFLIKE(3, 4)
-nir_builder_init_simple_shader(gl_shader_stage stage,
- const nir_shader_compiler_options *options,
- const char *name, ...);
+ nir_builder_init_simple_shader(gl_shader_stage stage,
+ const nir_shader_compiler_options *options,
+ const char *name, ...);
typedef bool (*nir_instr_pass_cb)(struct nir_builder *, nir_instr *, void *);
static inline nir_ssa_def *
nir_convert_to_bit_size(nir_builder *b,
- nir_ssa_def *src,
- nir_alu_type type,
- unsigned bit_size)
+ nir_ssa_def *src,
+ nir_alu_type type,
+ unsigned bit_size)
{
- return nir_type_convert(b, src, type, (nir_alu_type) (type | bit_size),
+ return nir_type_convert(b, src, type, (nir_alu_type)(type | bit_size),
nir_rounding_mode_undef);
}
nir_b2iN(nir_builder *b, nir_ssa_def *src, uint32_t bit_size)
{
return nir_type_convert(b, src, nir_type_bool,
- (nir_alu_type) (nir_type_int | bit_size),
+ (nir_alu_type)(nir_type_int | bit_size),
nir_rounding_mode_undef);
}
nir_b2fN(nir_builder *b, nir_ssa_def *src, uint32_t bit_size)
{
return nir_type_convert(b, src, nir_type_bool,
- (nir_alu_type) (nir_type_float | bit_size),
+ (nir_alu_type)(nir_type_float | bit_size),
nir_rounding_mode_undef);
}
nir_i2fN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_int,
- (nir_alu_type) (nir_type_float | bit_size),
+ (nir_alu_type)(nir_type_float | bit_size),
nir_rounding_mode_undef);
}
nir_u2fN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_uint,
- (nir_alu_type) (nir_type_float | bit_size),
+ (nir_alu_type)(nir_type_float | bit_size),
nir_rounding_mode_undef);
}
nir_f2uN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_float,
- (nir_alu_type) (nir_type_uint | bit_size),
+ (nir_alu_type)(nir_type_uint | bit_size),
nir_rounding_mode_undef);
}
nir_f2iN(nir_builder *b, nir_ssa_def *src, unsigned bit_size)
{
return nir_type_convert(b, src, nir_type_float,
- (nir_alu_type) (nir_type_int | bit_size),
+ (nir_alu_type)(nir_type_int | bit_size),
nir_rounding_mode_undef);
}
{
assert(src0->num_components == src1->num_components);
switch (src0->num_components) {
- case 1: return nir_fmul(build, src0, src1);
- case 2: return nir_fdot2(build, src0, src1);
- case 3: return nir_fdot3(build, src0, src1);
- case 4: return nir_fdot4(build, src0, src1);
- case 5: return nir_fdot5(build, src0, src1);
- case 8: return nir_fdot8(build, src0, src1);
- case 16: return nir_fdot16(build, src0, src1);
+ case 1:
+ return nir_fmul(build, src0, src1);
+ case 2:
+ return nir_fdot2(build, src0, src1);
+ case 3:
+ return nir_fdot3(build, src0, src1);
+ case 4:
+ return nir_fdot4(build, src0, src1);
+ case 5:
+ return nir_fdot5(build, src0, src1);
+ case 8:
+ return nir_fdot8(build, src0, src1);
+ case 16:
+ return nir_fdot16(build, src0, src1);
default:
unreachable("bad component size");
}
nir_ball_iequal(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1)
{
switch (src0->num_components) {
- case 1: return nir_ieq(b, src0, src1);
- case 2: return nir_ball_iequal2(b, src0, src1);
- case 3: return nir_ball_iequal3(b, src0, src1);
- case 4: return nir_ball_iequal4(b, src0, src1);
- case 5: return nir_ball_iequal5(b, src0, src1);
- case 8: return nir_ball_iequal8(b, src0, src1);
- case 16: return nir_ball_iequal16(b, src0, src1);
+ case 1:
+ return nir_ieq(b, src0, src1);
+ case 2:
+ return nir_ball_iequal2(b, src0, src1);
+ case 3:
+ return nir_ball_iequal3(b, src0, src1);
+ case 4:
+ return nir_ball_iequal4(b, src0, src1);
+ case 5:
+ return nir_ball_iequal5(b, src0, src1);
+ case 8:
+ return nir_ball_iequal8(b, src0, src1);
+ case 16:
+ return nir_ball_iequal16(b, src0, src1);
default:
unreachable("bad component size");
}
nir_bany_inequal(nir_builder *b, nir_ssa_def *src0, nir_ssa_def *src1)
{
switch (src0->num_components) {
- case 1: return nir_ine(b, src0, src1);
- case 2: return nir_bany_inequal2(b, src0, src1);
- case 3: return nir_bany_inequal3(b, src0, src1);
- case 4: return nir_bany_inequal4(b, src0, src1);
- case 5: return nir_bany_inequal5(b, src0, src1);
- case 8: return nir_bany_inequal8(b, src0, src1);
- case 16: return nir_bany_inequal16(b, src0, src1);
+ case 1:
+ return nir_ine(b, src0, src1);
+ case 2:
+ return nir_bany_inequal2(b, src0, src1);
+ case 3:
+ return nir_bany_inequal3(b, src0, src1);
+ case 4:
+ return nir_bany_inequal4(b, src0, src1);
+ case 5:
+ return nir_bany_inequal5(b, src0, src1);
+ case 8:
+ return nir_bany_inequal8(b, src0, src1);
+ case 16:
+ return nir_bany_inequal16(b, src0, src1);
default:
unreachable("bad component size");
}
assert(scalar->num_components == 1);
assert(num_components <= NIR_MAX_VEC_COMPONENTS);
- nir_ssa_def *copies[NIR_MAX_VEC_COMPONENTS] = {NULL};
+ nir_ssa_def *copies[NIR_MAX_VEC_COMPONENTS] = { NULL };
for (unsigned i = 0; i < num_components; ++i)
copies[i] = scalar;
if (y == 0) {
return x;
} else {
- assert (y < x->bit_size);
+ assert(y < x->bit_size);
return nir_ishl(build, x, nir_imm_int(build, y));
}
}
return nir_fadd_imm(build, nir_fmul_imm(build, src0, src1), src2);
else
return nir_ffma(build, src0, nir_imm_floatN_t(build, src1, src0->bit_size),
- nir_imm_floatN_t(build, src2, src0->bit_size));
+ nir_imm_floatN_t(build, src2, src0->bit_size));
}
static inline nir_ssa_def *
switch (dest_bit_size) {
case 64:
switch (src->bit_size) {
- case 32: return nir_pack_64_2x32(b, src);
- case 16: return nir_pack_64_4x16(b, src);
- default: break;
+ case 32:
+ return nir_pack_64_2x32(b, src);
+ case 16:
+ return nir_pack_64_4x16(b, src);
+ default:
+ break;
}
break;
switch (src->bit_size) {
case 64:
switch (dest_bit_size) {
- case 32: return nir_unpack_64_2x32(b, src);
- case 16: return nir_unpack_64_4x16(b, src);
- default: break;
+ case 32:
+ return nir_unpack_64_2x32(b, src);
+ case 16:
+ return nir_unpack_64_4x16(b, src);
+ default:
+ break;
}
break;
const unsigned bit = first_bit + (i * common_bit_size);
while (bit >= src_end_bit) {
src_idx++;
- assert(src_idx < (int) num_srcs);
+ assert(src_idx < (int)num_srcs);
src_start_bit = src_end_bit;
src_end_bit += srcs[src_idx]->bit_size *
srcs[src_idx]->num_components;
rel_bit / src_bit_size);
if (srcs[src_idx]->bit_size > common_bit_size) {
nir_ssa_def *unpacked = nir_unpack_bits(b, comp, common_bit_size);
- comp = nir_channel(b, unpacked, (rel_bit % src_bit_size) /
- common_bit_size);
+ comp = nir_channel(b, unpacked, (rel_bit % src_bit_size) / common_bit_size);
}
common_comps[i] = comp;
}
if (leader->deref_type == nir_deref_type_array) {
nir_ssa_def *index = nir_i2iN(b, leader->arr.index.ssa,
- parent->dest.ssa.bit_size);
+ parent->dest.ssa.bit_size);
return nir_build_deref_array(b, parent, index);
} else {
return nir_build_deref_array_wildcard(b, parent);
nir_copy_deref(nir_builder *build, nir_deref_instr *dest, nir_deref_instr *src)
{
nir_copy_deref_with_access(build, dest, src,
- (enum gl_access_qualifier) 0,
- (enum gl_access_qualifier) 0);
+ (enum gl_access_qualifier)0,
+ (enum gl_access_qualifier)0);
}
static inline void
nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)
{
nir_copy_deref(build, nir_build_deref_var(build, dest),
- nir_build_deref_var(build, src));
+ nir_build_deref_var(build, src));
}
static inline nir_ssa_def *
store->src[0] = nir_src_for_ssa(value);
store->src[1] = nir_src_for_ssa(addr);
nir_intrinsic_set_write_mask(store,
- write_mask & BITFIELD_MASK(value->num_components));
+ write_mask & BITFIELD_MASK(value->num_components));
nir_intrinsic_set_align(store, align, 0);
nir_builder_instr_insert(build, &store->instr);
}
nir_tex_deref(nir_builder *b, nir_deref_instr *t, nir_deref_instr *s,
nir_ssa_def *coord)
{
- nir_tex_src srcs[] = {nir_tex_src_for_ssa(nir_tex_src_coord, coord)};
+ nir_tex_src srcs[] = { nir_tex_src_for_ssa(nir_tex_src_coord, coord) };
return nir_build_tex_deref_instr(b, nir_texop_tex, t, s,
ARRAY_SIZE(srcs), srcs);
nir_samples_identical_deref(nir_builder *b, nir_deref_instr *t,
nir_ssa_def *coord)
{
- nir_tex_src srcs[] = {nir_tex_src_for_ssa(nir_tex_src_coord, coord)};
+ nir_tex_src srcs[] = { nir_tex_src_for_ssa(nir_tex_src_coord, coord) };
return nir_build_tex_deref_instr(b, nir_texop_samples_identical, t, NULL,
ARRAY_SIZE(srcs), srcs);
nir_mask(nir_builder *b, nir_ssa_def *bits, unsigned dst_bit_size)
{
return nir_ushr(b, nir_imm_intN_t(b, -1, dst_bit_size),
- nir_isub_imm(b, dst_bit_size, nir_u2u32(b, bits)));
+ nir_isub_imm(b, dst_bit_size, nir_u2u32(b, bits)));
}
static inline nir_ssa_def *
#include "nir.h"
#include "nir_builtin_builder.h"
-nir_ssa_def*
+nir_ssa_def *
nir_cross3(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
{
unsigned yzx[3] = { 1, 2, 0 };
unsigned zxy[3] = { 2, 0, 1 };
return nir_ffma(b, nir_swizzle(b, x, yzx, 3),
- nir_swizzle(b, y, zxy, 3),
- nir_fneg(b, nir_fmul(b, nir_swizzle(b, x, zxy, 3),
- nir_swizzle(b, y, yzx, 3))));
+ nir_swizzle(b, y, zxy, 3),
+ nir_fneg(b, nir_fmul(b, nir_swizzle(b, x, zxy, 3),
+ nir_swizzle(b, y, yzx, 3))));
}
-nir_ssa_def*
+nir_ssa_def *
nir_cross4(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
{
nir_ssa_def *cross = nir_cross3(b, x, y);
return nir_vec4(b,
- nir_channel(b, cross, 0),
- nir_channel(b, cross, 1),
- nir_channel(b, cross, 2),
- nir_imm_intN_t(b, 0, cross->bit_size));
+ nir_channel(b, cross, 0),
+ nir_channel(b, cross, 1),
+ nir_channel(b, cross, 2),
+ nir_imm_intN_t(b, 0, cross->bit_size));
}
-nir_ssa_def*
+nir_ssa_def *
nir_fast_length(nir_builder *b, nir_ssa_def *vec)
{
return nir_fsqrt(b, nir_fdot(b, vec, vec));
}
-nir_ssa_def*
+nir_ssa_def *
nir_nextafter(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
{
nir_ssa_def *zero = nir_imm_intN_t(b, 0, x->bit_size);
return nir_nan_check2(b, x, y, nir_bcsel(b, condeq, x, res));
}
-nir_ssa_def*
+nir_ssa_def *
nir_normalize(nir_builder *b, nir_ssa_def *vec)
{
if (vec->num_components == 1)
return nir_bcsel(b, nir_feq(b, maxc, f0), vec, res);
}
-nir_ssa_def*
+nir_ssa_def *
nir_smoothstep(nir_builder *b, nir_ssa_def *edge0, nir_ssa_def *edge1, nir_ssa_def *x)
{
nir_ssa_def *f2 = nir_imm_floatN_t(b, 2.0, x->bit_size);
/* t = clamp((x - edge0) / (edge1 - edge0), 0, 1) */
nir_ssa_def *t =
nir_fsat(b, nir_fdiv(b, nir_fsub(b, x, edge0),
- nir_fsub(b, edge1, edge0)));
+ nir_fsub(b, edge1, edge0)));
/* result = t * t * (3 - 2 * t) */
return nir_fmul(b, t, nir_fmul(b, t, nir_a_minus_bc(b, f3, f2, t)));
}
-nir_ssa_def*
+nir_ssa_def *
nir_upsample(nir_builder *b, nir_ssa_def *hi, nir_ssa_def *lo)
{
assert(lo->num_components == hi->num_components);
* \ 1.0 / y_over_x otherwise
*/
nir_ssa_def *x = nir_fdiv(b, nir_fmin(b, abs_y_over_x, one),
- nir_fmax(b, abs_y_over_x, one));
+ nir_fmax(b, abs_y_over_x, one));
/*
* approximate atan by evaluating polynomial:
* x^5 * 0.1938924977115610 - x^7 * 0.1173503194786851 +
* x^9 * 0.0536813784310406 - x^11 * 0.0121323213173444
*/
- nir_ssa_def *x_2 = nir_fmul(b, x, x);
- nir_ssa_def *x_3 = nir_fmul(b, x_2, x);
- nir_ssa_def *x_5 = nir_fmul(b, x_3, x_2);
- nir_ssa_def *x_7 = nir_fmul(b, x_5, x_2);
- nir_ssa_def *x_9 = nir_fmul(b, x_7, x_2);
+ nir_ssa_def *x_2 = nir_fmul(b, x, x);
+ nir_ssa_def *x_3 = nir_fmul(b, x_2, x);
+ nir_ssa_def *x_5 = nir_fmul(b, x_3, x_2);
+ nir_ssa_def *x_7 = nir_fmul(b, x_5, x_2);
+ nir_ssa_def *x_9 = nir_fmul(b, x_7, x_2);
nir_ssa_def *x_11 = nir_fmul(b, x_9, x_2);
nir_ssa_def *polynomial_terms[] = {
- nir_fmul_imm(b, x, 0.9999793128310355f),
- nir_fmul_imm(b, x_3, -0.3326756418091246f),
- nir_fmul_imm(b, x_5, 0.1938924977115610f),
- nir_fmul_imm(b, x_7, -0.1173503194786851f),
- nir_fmul_imm(b, x_9, 0.0536813784310406f),
+ nir_fmul_imm(b, x, 0.9999793128310355f),
+ nir_fmul_imm(b, x_3, -0.3326756418091246f),
+ nir_fmul_imm(b, x_5, 0.1938924977115610f),
+ nir_fmul_imm(b, x_7, -0.1173503194786851f),
+ nir_fmul_imm(b, x_9, 0.0536813784310406f),
nir_fmul_imm(b, x_11, -0.0121323213173444f),
};
* Definitions for functions in the C file come first.
*/
-nir_ssa_def* nir_cross3(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
-nir_ssa_def* nir_cross4(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
-nir_ssa_def* nir_fast_length(nir_builder *b, nir_ssa_def *vec);
-nir_ssa_def* nir_nextafter(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
-nir_ssa_def* nir_normalize(nir_builder *b, nir_ssa_def *vec);
-nir_ssa_def* nir_smoothstep(nir_builder *b, nir_ssa_def *edge0,
+nir_ssa_def *nir_cross3(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
+nir_ssa_def *nir_cross4(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
+nir_ssa_def *nir_fast_length(nir_builder *b, nir_ssa_def *vec);
+nir_ssa_def *nir_nextafter(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y);
+nir_ssa_def *nir_normalize(nir_builder *b, nir_ssa_def *vec);
+nir_ssa_def *nir_smoothstep(nir_builder *b, nir_ssa_def *edge0,
nir_ssa_def *edge1, nir_ssa_def *x);
-nir_ssa_def* nir_upsample(nir_builder *b, nir_ssa_def *hi, nir_ssa_def *lo);
-nir_ssa_def* nir_atan(nir_builder *b, nir_ssa_def *y_over_x);
-nir_ssa_def* nir_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x);
+nir_ssa_def *nir_upsample(nir_builder *b, nir_ssa_def *hi, nir_ssa_def *lo);
+nir_ssa_def *nir_atan(nir_builder *b, nir_ssa_def *y_over_x);
+nir_ssa_def *nir_atan2(nir_builder *b, nir_ssa_def *y, nir_ssa_def *x);
nir_ssa_def *
nir_get_texture_lod(nir_builder *b, nir_tex_instr *tex);
return nir_fast_length(b, nir_fsub(b, x, y));
}
-static inline nir_ssa_def*
+static inline nir_ssa_def *
nir_fast_normalize(nir_builder *b, nir_ssa_def *vec)
{
return nir_fdiv(b, vec, nir_fast_length(b, vec));
}
-static inline nir_ssa_def*
+static inline nir_ssa_def *
nir_fmad(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y, nir_ssa_def *z)
{
return nir_fadd(b, nir_fmul(b, x, y), z);
}
-static inline nir_ssa_def*
+static inline nir_ssa_def *
nir_maxmag(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
{
nir_ssa_def *xabs = nir_fabs(b, x);
return nir_bcsel(b, condy, y, nir_bcsel(b, condx, x, nir_fmax(b, x, y)));
}
-static inline nir_ssa_def*
+static inline nir_ssa_def *
nir_minmag(nir_builder *b, nir_ssa_def *x, nir_ssa_def *y)
{
nir_ssa_def *xabs = nir_fabs(b, x);
return nir_bcsel(b, condy, y, nir_bcsel(b, condx, x, nir_fmin(b, x, y)));
}
-static inline nir_ssa_def*
+static inline nir_ssa_def *
nir_nan(nir_builder *b, nir_ssa_def *x)
{
nir_ssa_def *nan = nir_imm_floatN_t(b, NAN, x->bit_size);
nfxn->num_params = fxn->num_params;
if (fxn->num_params) {
- nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
- memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
+ nfxn->params = ralloc_array(state->ns, nir_parameter, fxn->num_params);
+ memcpy(nfxn->params, fxn->params, sizeof(nir_parameter) * fxn->num_params);
}
nfxn->is_entrypoint = fxn->is_entrypoint;
nfxn->is_preamble = fxn->is_preamble;
unlink_block_successors(block);
link_blocks(block, loop_header_block, NULL);
}
-
}
/**
exec_node_insert_node_before(&block->cf_node.node, &new_block->cf_node.node);
set_foreach(block->predecessors, entry) {
- nir_block *pred = (nir_block *) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
replace_successor(pred, block, new_block);
}
nir_block *header = nir_loop_first_block(loop);
nir_block *preheader = nir_block_cf_tree_prev(header);
set_foreach(header->predecessors, entry) {
- nir_block *pred = (nir_block *) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
if (pred != preheader)
replace_successor(pred, header, cont);
}
nir_block *header = nir_loop_first_block(loop);
nir_block *cont = nir_loop_first_continue_block(loop);
set_foreach(cont->predecessors, entry) {
- nir_block *pred = (nir_block*) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
replace_successor(pred, cont, header);
}
block_remove_pred(header, cont);
exec_list_append(&before->instr_list, &after->instr_list);
exec_node_remove(&after->cf_node.node);
- return last_before_instr ? nir_after_instr(last_before_instr) :
- nir_before_block(before);
+ return last_before_instr ? nir_after_instr(last_before_instr) : nir_before_block(before);
}
}
nir_cf_node_insert(nir_after_cf_list(list), node);
}
-
/** Control flow motion.
*
* These functions let you take a part of a control flow list (basically
#include "nir_control_flow.h"
-
/* Internal control-flow modification functions used when inserting/removing
* instructions.
*/
switch (round) {
case nir_rounding_mode_ru: {
/* If lower-precision conversion results in a lower value, push it
- * up one ULP. */
+ * up one ULP. */
nir_ssa_def *lower_prec =
nir_build_alu(b, low_conv, src, NULL, NULL, NULL);
nir_ssa_def *roundtrip =
}
case nir_rounding_mode_rd: {
/* If lower-precision conversion results in a higher value, push it
- * down one ULP. */
+ * down one ULP. */
nir_ssa_def *lower_prec =
nir_build_alu(b, low_conv, src, NULL, NULL, NULL);
nir_ssa_def *roundtrip =
}
case nir_rounding_mode_rtz:
return nir_bcsel(b, nir_flt_imm(b, src, 1),
- nir_round_float_to_float(b, src, dest_bit_size,
- nir_rounding_mode_ru),
- nir_round_float_to_float(b, src, dest_bit_size,
- nir_rounding_mode_rd));
+ nir_round_float_to_float(b, src, dest_bit_size,
+ nir_rounding_mode_ru),
+ nir_round_float_to_float(b, src, dest_bit_size,
+ nir_rounding_mode_rd));
case nir_rounding_mode_rtne:
case nir_rounding_mode_undef:
break;
case 64:
mantissa_bits = 52;
break;
- default: unreachable("Unsupported bit size");
+ default:
+ unreachable("Unsupported bit size");
}
if (src->bit_size < mantissa_bits)
switch (round) {
case nir_rounding_mode_rtz:
return nir_bcsel(b, sign, nir_ineg(b, positive_rounded),
- positive_rounded);
+ positive_rounded);
break;
case nir_rounding_mode_ru:
return nir_bcsel(b, sign,
break;
case nir_rounding_mode_ru:
return nir_bcsel(b, nir_ieq(b, src, truncated),
- src, nir_uadd_sat(b, truncated, adjust));
+ src, nir_uadd_sat(b, truncated, adjust));
case nir_rounding_mode_rtne:
case nir_rounding_mode_undef:
break;
break;
}
case nir_type_uint: {
- uint64_t uhigh = dest_bit_size == 64 ?
- ~0ull : (1ull << dest_bit_size) - 1;
+ uint64_t uhigh = dest_bit_size == 64 ? ~0ull : (1ull << dest_bit_size) - 1;
if (src_base_type != nir_type_float) {
*low = nir_imm_intN_t(b, 0, src_bit_size);
if (src_base_type == nir_type_uint || src_bit_size > dest_bit_size)
break;
}
case nir_type_uint: {
- uint64_t src_uhigh = src_bit_size == 64 ?
- ~0ull : (1ull << src_bit_size) - 1;
+ uint64_t src_uhigh = src_bit_size == 64 ? ~0ull : (1ull << src_bit_size) - 1;
if (src_uhigh > fhigh)
*high = nir_imm_intN_t(b, fhigh, src_bit_size);
break;
/**
* Clamp the value into the widest representatble range of the
* destination type with cmp + bcsel.
- *
+ *
* val/val_type: The variables used for bcsel
* src/src_type: The variables used for comparison
* dest_type: The type which determines the range used for comparison
/* Try to simplify the conversion if we can */
clamp = clamp &&
- !nir_alu_type_range_contains_type_range(dest_type, src_type);
+ !nir_alu_type_range_contains_type_range(dest_type, src_type);
round = nir_simplify_conversion_rounding(src_type, dest_type, round);
/* For float -> int/uint conversions, we might not be able to represent
* do the comparison in float range, but the bcsel in the destination range.
*/
bool clamp_after_conversion = clamp &&
- src_base_type == nir_type_float &&
- dest_base_type != nir_type_float;
+ src_base_type == nir_type_float &&
+ dest_base_type != nir_type_float;
/*
* If we don't care about rounding and clamping, we can just use NIR's
if (!clamp && round == nir_rounding_mode_undef) {
trivial_convert = true;
} else if (!clamp && src_type == nir_type_float32 &&
- dest_type == nir_type_float16 &&
- (round == nir_rounding_mode_rtne ||
- round == nir_rounding_mode_rtz)) {
+ dest_type == nir_type_float16 &&
+ (round == nir_rounding_mode_rtne ||
+ round == nir_rounding_mode_rtz)) {
trivial_convert = true;
} else {
trivial_convert = false;
* IN THE SOFTWARE.
*/
-#include "nir.h"
-#include "nir_builder.h"
#include "nir_deref.h"
#include "util/hash_table.h"
+#include "nir.h"
+#include "nir_builder.h"
static bool
is_trivial_deref_cast(nir_deref_instr *cast)
for (; instr; instr = nir_deref_instr_parent(instr)) {
if (instr->deref_type == nir_deref_type_array &&
nir_src_is_const(instr->arr.index) &&
- nir_src_as_uint(instr->arr.index) >=
- glsl_get_length(nir_deref_instr_parent(instr)->type))
+ nir_src_as_uint(instr->arr.index) >=
+ glsl_get_length(nir_deref_instr_parent(instr)->type))
return true;
}
case nir_deref_type_array:
offset += nir_src_as_uint((*p)->arr.index) *
type_get_array_stride((*p)->type, size_align);
- break;
+ break;
case nir_deref_type_struct: {
/* p starts at path[1], so this is safe */
nir_deref_instr *parent = *(p - 1);
offset += struct_type_get_field_offset(parent->type, size_align,
(*p)->strct.index);
- break;
+ break;
}
case nir_deref_type_cast:
/* A cast doesn't contribute to the offset */
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
{
nir_shader_instructions_pass(shader, nir_fixup_deref_modes_instr,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_instr_index, NULL);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_instr_index,
+ NULL);
}
static bool
return result;
}
-nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref)
+nir_deref_path *
+nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref)
{
if (!deref->_path) {
deref->_path = ralloc(mem_ctx, nir_deref_path);
return deref->_path;
}
-nir_deref_compare_result nir_compare_derefs_and_paths(void *mem_ctx,
- nir_deref_and_path *a,
- nir_deref_and_path *b)
+nir_deref_compare_result
+nir_compare_derefs_and_paths(void *mem_ctx,
+ nir_deref_and_path *a,
+ nir_deref_and_path *b)
{
if (a->instr == b->instr) /* nir_compare_derefs has a fast path if a == b */
return nir_compare_derefs(a->instr, b->instr);
bool trivial_array_cast = is_trivial_array_deref_cast(cast);
-
nir_foreach_use_including_if_safe(use_src, &cast->dest.ssa) {
assert(!use_src->is_if && "there cannot be if-uses");
parent->deref_type != nir_deref_type_ptr_as_array)
return false;
-
deref->arr.in_bounds &= parent->arr.in_bounds;
nir_ssa_def *new_idx = nir_iadd(b, parent->arr.index.ssa,
- deref->arr.index.ssa);
+ deref->arr.index.ssa);
deref->deref_type = parent->deref_type;
nir_instr_rewrite_src(&deref->instr, &deref->parent, parent->parent);
if (num_components == data->num_components)
return data;
- unsigned swiz[NIR_MAX_VEC_COMPONENTS] = { 0, };
+ unsigned swiz[NIR_MAX_VEC_COMPONENTS] = {
+ 0,
+ };
for (unsigned i = 0; i < MIN2(num_components, data->num_components); i++)
swiz[i] = i;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_deref_path *nir_get_deref_path(void *mem_ctx, nir_deref_and_path *deref);
typedef enum {
- nir_derefs_do_not_alias = 0,
- nir_derefs_equal_bit = (1 << 0),
- nir_derefs_may_alias_bit = (1 << 1),
+ nir_derefs_do_not_alias = 0,
+ nir_derefs_equal_bit = (1 << 0),
+ nir_derefs_may_alias_bit = (1 << 1),
nir_derefs_a_contains_b_bit = (1 << 2),
nir_derefs_b_contains_a_bit = (1 << 3),
} nir_deref_compare_result;
}
static bool
-nir_variable_mode_is_uniform(nir_variable_mode mode) {
+nir_variable_mode_is_uniform(nir_variable_mode mode)
+{
switch (mode) {
case nir_var_uniform:
case nir_var_mem_ubo:
if (phi->dest.ssa.divergent)
return false;
- nir_ssa_def* same = NULL;
+ nir_ssa_def *same = NULL;
nir_foreach_phi_src(src, phi) {
/* if any source value is divergent, the resulting value is divergent */
if (src->src.ssa->divergent) {
visit_cf_list(&nir_shader_get_entrypoint(shader)->body, &state);
}
-bool nir_update_instr_divergence(nir_shader *shader, nir_instr *instr)
+bool
+nir_update_instr_divergence(nir_shader *shader, nir_instr *instr)
{
nir_foreach_ssa_def(instr, set_ssa_def_not_divergent, NULL);
return true;
}
-
bool
nir_has_divergent_loop(nir_shader *shader)
{
{
nir_block *new_idom = NULL;
set_foreach(block->predecessors, entry) {
- nir_block *pred = (nir_block *) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
if (pred->imm_dom) {
if (new_idom)
{
if (block->predecessors->entries > 1) {
set_foreach(block->predecessors, entry) {
- nir_block *runner = (nir_block *) entry->key;
+ nir_block *runner = (nir_block *)entry->key;
/* Skip unreachable predecessors */
if (runner->imm_dom == NULL)
*/
static void
-calc_dom_children(nir_function_impl* impl)
+calc_dom_children(nir_function_impl *impl)
{
void *mem_ctx = ralloc_parent(impl);
nir_foreach_block_unstructured(block, impl) {
if (block->imm_dom) {
- block->imm_dom->dom_children[block->imm_dom->num_dom_children++]
- = block;
+ block->imm_dom->dom_children[block->imm_dom->num_dom_children++] = block;
}
}
}
nir_metadata_require(impl, nir_metadata_block_index);
-
nir_foreach_block_unstructured(block, impl) {
init_block(block, impl);
}
nir_foreach_block_unstructured(block, impl) {
fprintf(fp, "DF(%u) = {", block->index);
set_foreach(block->dom_frontier, entry) {
- nir_block *df = (nir_block *) entry->key;
+ nir_block *df = (nir_block *)entry->key;
fprintf(fp, "%u, ", df->index);
}
fprintf(fp, "}\n");
nir_ssa_def *comps[4];
for (unsigned i = 0; i < src->num_components; i++) {
unsigned shift = src->bit_size - bits[i];
- comps[i] = nir_ishr_imm(b, nir_ishl_imm(b,
- nir_channel(b, src, i),
- shift),
- shift);
+ comps[i] = nir_ishr_imm(b, nir_ishl_imm(b, nir_channel(b, src, i), shift),
+ shift);
}
return nir_vec(b, comps, src->num_components);
}
-
static inline nir_ssa_def *
nir_format_unpack_int(nir_builder *b, nir_ssa_def *packed,
const unsigned *bits, unsigned num_components,
nir_ssa_def *packed = nir_imm_int(b, 0);
unsigned offset = 0;
for (unsigned i = 0; i < num_components; i++) {
- packed = nir_ior(b, packed, nir_shift_imm(b, nir_channel(b, color, i),
- offset));
+ packed = nir_ior(b, packed, nir_shift_imm(b, nir_channel(b, color, i), offset));
offset += bits[i];
}
assert(offset <= packed->bit_size);
DIV_ROUND_UP(src->num_components * src_bits, dst_bits);
assert(dst_components <= 4);
- nir_ssa_def *dst_chan[4] = {0};
+ nir_ssa_def *dst_chan[4] = { 0 };
if (dst_bits > src_bits) {
unsigned shift = 0;
unsigned dst_idx = 0;
for (unsigned i = 0; i < src->num_components; i++) {
nir_ssa_def *shifted = nir_ishl_imm(b, nir_channel(b, src, i),
- shift);
+ shift);
if (shift == 0) {
dst_chan[dst_idx] = shifted;
} else {
_nir_format_norm_factor(b, bits, s->num_components, true);
return nir_fmax(b, nir_fdiv(b, nir_i2f32(b, s), factor),
- nir_imm_float(b, -1.0f));
+ nir_imm_float(b, -1.0f));
}
static inline nir_ssa_def *
{
nir_ssa_def *linear = nir_fmul_imm(b, c, 12.92f);
nir_ssa_def *curved =
- nir_fadd_imm(b, nir_fmul_imm(b, nir_fpow(b, c, nir_imm_float(b, 1.0 / 2.4)),
- 1.055f),
- -0.055f);
+ nir_fadd_imm(b, nir_fmul_imm(b, nir_fpow(b, c, nir_imm_float(b, 1.0 / 2.4)), 1.055f),
+ -0.055f);
return nir_fsat(b, nir_bcsel(b, nir_flt_imm(b, c, 0.0031308f),
- linear, curved));
+ linear, curved));
}
static inline nir_ssa_def *
{
nir_ssa_def *linear = nir_fdiv_imm(b, c, 12.92f);
nir_ssa_def *curved =
- nir_fpow(b, nir_fmul_imm(b, nir_fadd_imm(b, c, 0.055f),
- 1.0 / 1.055f),
- nir_imm_float(b, 2.4f));
+ nir_fpow(b, nir_fmul_imm(b, nir_fadd_imm(b, c, 0.055f), 1.0 / 1.055f),
+ nir_imm_float(b, 2.4f));
return nir_fsat(b, nir_bcsel(b, nir_fle_imm(b, c, 0.04045f),
- linear, curved));
+ linear, curved));
}
/* Clamps a vector of uints so they don't extend beyond the given number of
nir_ssa_def *undef = nir_ssa_undef(b, 1, color->bit_size);
nir_ssa_def *p1 = nir_pack_half_2x16_split(b, nir_channel(b, clamped, 0),
- nir_channel(b, clamped, 1));
+ nir_channel(b, clamped, 1));
nir_ssa_def *p2 = nir_pack_half_2x16_split(b, nir_channel(b, clamped, 2),
- undef);
+ undef);
/* A 10 or 11-bit float has the same exponent as a 16-bit float but with
* fewer mantissa bits and no sign bit. All we have to do is throw away
/* Get rid of negatives and NaN */
clamped = nir_bcsel(b, nir_ugt_imm(b, color, 0x7f800000),
- nir_imm_float(b, 0), clamped);
+ nir_imm_float(b, 0), clamped);
/* maxrgb.u = MAX3(rc.u, gc.u, bc.u); */
nir_ssa_def *maxu = nir_umax(b, nir_channel(b, clamped, 0),
- nir_umax(b, nir_channel(b, clamped, 1),
- nir_channel(b, clamped, 2)));
+ nir_umax(b, nir_channel(b, clamped, 1),
+ nir_channel(b, clamped, 2)));
/* maxrgb.u += maxrgb.u & (1 << (23-9)); */
maxu = nir_iadd(b, maxu, nir_iand_imm(b, maxu, 1 << 14));
* 1 + RGB9E5_EXP_BIAS - 127;
*/
nir_ssa_def *exp_shared =
- nir_iadd_imm(b, nir_umax(b, nir_ushr_imm(b, maxu, 23),
- nir_imm_int(b, -RGB9E5_EXP_BIAS - 1 + 127)),
- 1 + RGB9E5_EXP_BIAS - 127);
+ nir_iadd_imm(b, nir_umax(b, nir_ushr_imm(b, maxu, 23), nir_imm_int(b, -RGB9E5_EXP_BIAS - 1 + 127)),
+ 1 + RGB9E5_EXP_BIAS - 127);
/* revdenom_biasedexp = 127 - (exp_shared - RGB9E5_EXP_BIAS -
* RGB9E5_MANTISSA_BITS) + 1;
*/
nir_ssa_def *revdenom_biasedexp =
- nir_isub_imm(b, 127 + RGB9E5_EXP_BIAS +
- RGB9E5_MANTISSA_BITS + 1,
- exp_shared);
+ nir_isub_imm(b, 127 + RGB9E5_EXP_BIAS + RGB9E5_MANTISSA_BITS + 1,
+ exp_shared);
/* revdenom.u = revdenom_biasedexp << 23; */
nir_ssa_def *revdenom =
* bm = (bm & 1) + (bm >> 1);
*/
mantissa = nir_iadd(b, nir_iand_imm(b, mantissa, 1),
- nir_ushr_imm(b, mantissa, 1));
+ nir_ushr_imm(b, mantissa, 1));
nir_ssa_def *packed = nir_channel(b, mantissa, 0);
packed = nir_mask_shift_or(b, packed, nir_channel(b, mantissa, 1), ~0, 9);
if (a->parent_instr->type == nir_instr_type_ssa_undef) {
/* SSA undefs always dominate */
return true;
- } if (def_after(a, b)) {
+ }
+ if (def_after(a, b)) {
return false;
} else if (a->parent_instr->block == b->parent_instr->block) {
return def_after(b, a);
}
}
-
/* The following data structure, which I have named merge_set is a way of
* representing a set registers of non-interfering registers. This is
* based on the concept of a "dominance forest" presented in "Fast Copy
static void
aggressive_coalesce_parallel_copy(nir_parallel_copy_instr *pcopy,
- struct from_ssa_state *state)
+ struct from_ssa_state *state)
{
nir_foreach_parallel_copy_entry(entry, pcopy) {
assert(!entry->src_is_reg);
*/
nir_ssa_def *load = NULL;
if (b->cursor.option == nir_cursor_before_instr) {
- nir_instr *prev = nir_instr_prev(b->cursor.instr);
-
- if (prev != NULL && prev->type == nir_instr_type_intrinsic) {
- nir_intrinsic_instr *intr = nir_instr_as_intrinsic(prev);
- if (intr->intrinsic == nir_intrinsic_load_reg &&
- intr->src[0].ssa == reg &&
- nir_intrinsic_base(intr) == 0)
- load = &intr->dest.ssa;
- }
+ nir_instr *prev = nir_instr_prev(b->cursor.instr);
+
+ if (prev != NULL && prev->type == nir_instr_type_intrinsic) {
+ nir_intrinsic_instr *intr = nir_instr_as_intrinsic(prev);
+ if (intr->intrinsic == nir_intrinsic_load_reg &&
+ intr->src[0].ssa == reg &&
+ nir_intrinsic_base(intr) == 0)
+ load = &intr->dest.ssa;
+ }
}
if (load == NULL)
}
set_reg_divergent(reg, copy_value_is_divergent(values[b]));
- values[num_vals] = (struct copy_value) {
+ values[num_vals] = (struct copy_value){
.is_reg = true,
.ssa = reg,
};
/* Mark metadata as dirty before we ask for liveness analysis */
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
nir_metadata_require(impl, nir_metadata_instr_index |
- nir_metadata_live_ssa_defs |
- nir_metadata_dominance);
-
+ nir_metadata_live_ssa_defs |
+ nir_metadata_dominance);
nir_foreach_block(block, impl) {
coalesce_phi_nodes_block(block, &state);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
/* Clean up dead instructions and the hash tables */
nir_instr_free_list(&state.dead_instrs);
return progress;
}
-
static void
place_phi_read(nir_builder *b, nir_ssa_def *reg,
nir_ssa_def *def, nir_block *block, struct set *visited_blocks)
{
- /* Search already visited blocks to avoid back edges in tree */
- if (_mesa_set_search(visited_blocks, block) == NULL) {
+ /* Search already visited blocks to avoid back edges in tree */
+ if (_mesa_set_search(visited_blocks, block) == NULL) {
/* Try to go up the single-successor tree */
bool all_single_successors = true;
set_foreach(block->predecessors, entry) {
* IN THE SOFTWARE.
*/
+#include "main/menums.h"
#include "nir.h"
#include "nir_deref.h"
-#include "main/menums.h"
#include "util/set.h"
nir_ssa_scalar s = nir_ssa_scalar_resolved(src->ssa, 0);
return s.def->parent_instr->type == nir_instr_type_intrinsic &&
nir_instr_as_intrinsic(s.def->parent_instr)->intrinsic ==
- nir_intrinsic_load_invocation_id;
+ nir_intrinsic_load_invocation_id;
}
static bool
nir_ssa_scalar s = nir_ssa_scalar_resolved(src->ssa, 0);
return s.def->parent_instr->type == nir_instr_type_intrinsic &&
nir_instr_as_intrinsic(s.def->parent_instr)->intrinsic ==
- nir_intrinsic_load_local_invocation_index;
+ nir_intrinsic_load_local_invocation_index;
}
static void
return;
bitfield = BITFIELD64_BIT(idx - VARYING_SLOT_PATCH0);
- }
- else {
+ } else {
/* Varyings might still have temp locations so abort */
if (idx >= VARYING_SLOT_MAX)
return;
return 0;
}
assert(deref->deref_type == nir_deref_type_array);
- return nir_src_is_const(deref->arr.index) ?
- (nir_src_as_uint(deref->arr.index) + var->data.location_frac) / 4u :
- (unsigned)-1;
+ return nir_src_is_const(deref->arr.index) ? (nir_src_as_uint(deref->arr.index) + var->data.location_frac) / 4u : (unsigned)-1;
}
unsigned offset = 0;
case nir_intrinsic_interp_deref_at_vertex:
case nir_intrinsic_load_deref:
case nir_intrinsic_store_deref:
- case nir_intrinsic_copy_deref:{
+ case nir_intrinsic_copy_deref: {
nir_deref_instr *deref = nir_src_as_deref(instr->src[0]);
if (nir_deref_mode_is_one_of(deref, nir_var_shader_in |
- nir_var_shader_out)) {
+ nir_var_shader_out)) {
nir_variable *var = nir_deref_instr_get_variable(deref);
bool is_output_read = false;
if (var->data.mode == nir_var_shader_out &&
case nir_intrinsic_load_color0:
case nir_intrinsic_load_color1:
shader->info.inputs_read |=
- BITFIELD64_BIT(VARYING_SLOT_COL0 <<
- (instr->intrinsic == nir_intrinsic_load_color1));
+ BITFIELD64_BIT(VARYING_SLOT_COL0 << (instr->intrinsic == nir_intrinsic_load_color1));
FALLTHROUGH;
case nir_intrinsic_load_subgroup_size:
case nir_intrinsic_load_subgroup_invocation:
* IN THE SOFTWARE.
*/
-#include "nir.h"
#include "util/bitset.h"
+#include "nir.h"
static void
set_type(unsigned idx, nir_alu_type type, BITSET_WORD *float_types,
xfb->buffers[buffer].varying_count++;
}
-
static nir_xfb_info *
nir_xfb_info_create(void *mem_ctx, uint16_t output_count)
{
* that contains an array.
*/
bool is_array_block = var->interface_type != NULL &&
- glsl_type_is_array(var->type) &&
- glsl_without_array(var->type) == var->interface_type;
+ glsl_type_is_array(var->type) &&
+ glsl_without_array(var->type) == var->interface_type;
if (var->data.explicit_offset && !is_array_block) {
unsigned offset = var->data.offset;
#ifndef NDEBUG
/* Finally, do a sanity check */
- unsigned max_offset[NIR_MAX_XFB_BUFFERS] = {0};
+ unsigned max_offset[NIR_MAX_XFB_BUFFERS] = { 0 };
for (unsigned i = 0; i < xfb->output_count; i++) {
assert(xfb->outputs[i].offset >= max_offset[xfb->outputs[i].buffer]);
assert(xfb->outputs[i].component_mask != 0);
nir_gather_xfb_info_from_intrinsics(nir_shader *nir)
{
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
- uint8_t buffer_to_stream[MAX_XFB_BUFFERS] = {0};
+ uint8_t buffer_to_stream[MAX_XFB_BUFFERS] = { 0 };
uint8_t buffer_mask = 0;
uint8_t stream_mask = 0;
/* Gather xfb outputs. */
- struct util_dynarray array = {0};
+ struct util_dynarray array = { 0 };
nir_foreach_block(block, impl) {
nir_foreach_instr(instr, block) {
while (wr_mask) {
unsigned i = u_bit_scan(&wr_mask);
unsigned index = nir_intrinsic_component(intr) + i;
- nir_io_xfb xfb = index < 2 ? nir_intrinsic_io_xfb(intr) :
- nir_intrinsic_io_xfb2(intr);
+ nir_io_xfb xfb = index < 2 ? nir_intrinsic_io_xfb(intr) : nir_intrinsic_io_xfb2(intr);
if (xfb.out[index % 2].num_components) {
nir_io_semantics sem = nir_intrinsic_io_semantics(intr);
j < count &&
cur->buffer == outputs[j].buffer &&
cur->location == outputs[j].location &&
- cur->high_16bits == outputs[j].high_16bits; j++) {
+ cur->high_16bits == outputs[j].high_16bits;
+ j++) {
if (outputs[j].component_mask &&
outputs[j].offset - outputs[j].component_offset * 4 ==
- cur->offset - cur->component_offset * 4) {
+ cur->offset - cur->component_offset * 4) {
unsigned merged_offset = MIN2(cur->component_offset,
outputs[j].component_offset);
/* component_mask is relative to 0, not component_offset */
return NULL;
}
-struct check_sources_state
-{
+struct check_sources_state {
nir_block *block;
uint32_t first_index;
};
* instructions.
*/
if (last && is_pseudo_inst(last) && is_grouped_load(instr))
- counter++;
+ counter++;
/* Set each instruction's index within the block. */
instr->index = counter;
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
const char *name = nir_intrinsic_infos[intr->intrinsic].name;
-
if (intr->intrinsic == nir_intrinsic_discard ||
intr->intrinsic == nir_intrinsic_discard_if ||
intr->intrinsic == nir_intrinsic_terminate ||
return false;
}
-struct indirection_state
-{
+struct indirection_state {
nir_block *block;
unsigned indirections;
};
unsigned max_distance)
{
int max_indirection = -1;
- unsigned num_inst_per_level[256] = {0};
+ unsigned num_inst_per_level[256] = { 0 };
/* UINT32_MAX means the instruction has not been visited. Once
* an instruction has been visited and its indirection level has been
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_loop_analysis);
}
}
{
assert(num_streams);
- int vtxcnt_arr[4] = {-1, -1, -1, -1};
- int prmcnt_arr[4] = {-1, -1, -1, -1};
- bool cnt_found[4] = {false, false, false, false};
+ int vtxcnt_arr[4] = { -1, -1, -1, -1 };
+ int prmcnt_arr[4] = { -1, -1, -1, -1 };
+ bool cnt_found[4] = { false, false, false, false };
nir_foreach_function_impl(impl, shader) {
/* set_vertex_and_primitive_count intrinsics only appear in predecessors of the
* end block. So we don't need to walk all of them.
*/
set_foreach(impl->end_block->predecessors, entry) {
- nir_block *block = (nir_block *) entry->key;
+ nir_block *block = (nir_block *)entry->key;
nir_foreach_instr_reverse(instr, block) {
nir_intrinsic_instr *intrin = as_set_vertex_and_primitive_count(instr);
#include "nir_control_flow.h"
#include "nir_vla.h"
-static bool function_ends_in_jump(nir_function_impl *impl)
+static bool
+function_ends_in_jump(nir_function_impl *impl)
{
nir_block *last_block = nir_impl_last_block(impl);
return nir_block_ends_in_jump(last_block);
}
-void nir_inline_function_impl(struct nir_builder *b,
- const nir_function_impl *impl,
- nir_ssa_def **params,
- struct hash_table *shader_var_remap)
+void
+nir_inline_function_impl(struct nir_builder *b,
+ const nir_function_impl *impl,
+ nir_ssa_def **params,
+ struct hash_table *shader_var_remap)
{
nir_function_impl *copy = nir_function_impl_clone(b->shader, impl);
if (!nir_collect_src_uniforms(&alu_src->src, alu_src->swizzle[j],
uni_offsets, num_offsets,
max_num_bo, max_offset))
- return false;
+ return false;
}
}
}
/* Allow induction variable which means a loop terminator. */
if (info) {
- nir_ssa_scalar cond_scalar = {cond->ssa, 0};
+ nir_ssa_scalar cond_scalar = { cond->ssa, 0 };
/* Limit terminator condition to loop unroll support case which is a simple
* comparison (ie. "i < count" is supported, but "i + 1 < count" is not).
* found component load with constant load.
*/
uint32_t max_offset = offset + num_components;
- nir_ssa_def *components[NIR_MAX_VEC_COMPONENTS] = {0};
+ nir_ssa_def *components[NIR_MAX_VEC_COMPONENTS] = { 0 };
bool found = false;
b.cursor = nir_before_instr(&intr->instr);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
}
}
*/
#include "nir_instr_set.h"
-#include "nir_vla.h"
#include "util/half_float.h"
+#include "nir_vla.h"
/* This function determines if uses of an instruction can safely be rewritten
* to use another identical instruction instead. Note that this function must
return false;
}
-
#define HASH(hash, data) XXH32(&(data), sizeof(data), hash)
static uint32_t
nir_alu_instr *alu = nir_src_as_alu_instr(s);
return alu != NULL && (alu->op == nir_op_fneg || alu->op == nir_op_ineg)
- ? alu : NULL;
+ ? alu
+ : NULL;
}
bool
return true;
}
- uint8_t alu1_swizzle[NIR_MAX_VEC_COMPONENTS] = {0};
+ uint8_t alu1_swizzle[NIR_MAX_VEC_COMPONENTS] = { 0 };
nir_src alu1_actual_src;
nir_alu_instr *neg1 = get_neg_instr(alu1->src[src1].src);
alu1_swizzle[i] = i;
}
- uint8_t alu2_swizzle[NIR_MAX_VEC_COMPONENTS] = {0};
+ uint8_t alu2_swizzle[NIR_MAX_VEC_COMPONENTS] = { 0 };
nir_src alu2_actual_src;
nir_alu_instr *neg2 = get_neg_instr(alu2->src[src2].src);
tex1->is_shadow != tex2->is_shadow ||
tex1->is_new_style_shadow != tex2->is_new_style_shadow ||
tex1->component != tex2->component ||
- tex1->texture_index != tex2->texture_index ||
- tex1->sampler_index != tex2->sampler_index ||
- tex1->backend_flags != tex2->backend_flags) {
+ tex1->texture_index != tex2->texture_index ||
+ tex1->sampler_index != tex2->sampler_index ||
+ tex1->backend_flags != tex2->backend_flags) {
return false;
}
return false;
if (info->has_dest && intrinsic1->dest.ssa.num_components !=
- intrinsic2->dest.ssa.num_components)
+ intrinsic2->dest.ssa.num_components)
return false;
if (info->has_dest && intrinsic1->dest.ssa.bit_size !=
- intrinsic2->dest.ssa.bit_size)
+ intrinsic2->dest.ssa.bit_size)
return false;
for (unsigned i = 0; i < info->num_srcs; i++) {
bool
nir_instr_set_add_or_rewrite(struct set *instr_set, nir_instr *instr,
- bool (*cond_function) (const nir_instr *a,
- const nir_instr *b))
+ bool (*cond_function)(const nir_instr *a,
+ const nir_instr *b))
{
if (!instr_can_rewrite(instr))
return false;
struct set_entry *e = _mesa_set_search_or_add(instr_set, instr, NULL);
- nir_instr *match = (nir_instr *) e->key;
+ nir_instr *match = (nir_instr *)e->key;
if (match == instr)
return false;
if (entry)
_mesa_set_remove(instr_set, entry);
}
-
* SPDX-License-Identifier: MIT
*/
+#include "nir_legacy.h"
#include "nir.h"
#include "nir_builder.h"
-#include "nir_legacy.h"
bool
nir_legacy_float_mod_folds(nir_alu_instr *mod)
if (load) {
bool indirect = (load->intrinsic == nir_intrinsic_load_reg_indirect);
- return (nir_legacy_alu_src) {
+ return (nir_legacy_alu_src){
.src.is_ssa = false,
.src.reg = {
.handle = load->src[0].ssa,
.base_offset = nir_intrinsic_base(load),
- .indirect = indirect ? load->src[1].ssa : NULL
- },
+ .indirect = indirect ? load->src[1].ssa : NULL },
.fabs = nir_intrinsic_legacy_fabs(load),
.fneg = nir_intrinsic_legacy_fneg(load),
};
} else {
- return (nir_legacy_alu_src) {
+ return (nir_legacy_alu_src){
.src.is_ssa = true,
.src.ssa = src->ssa,
};
if (store) {
bool indirect = (store->intrinsic == nir_intrinsic_store_reg_indirect);
- return (nir_legacy_alu_dest) {
+ return (nir_legacy_alu_dest){
.dest.is_ssa = false,
.dest.reg = {
.handle = store->src[1].ssa,
.base_offset = nir_intrinsic_base(store),
- .indirect = indirect ? store->src[2].ssa : NULL
- },
+ .indirect = indirect ? store->src[2].ssa : NULL },
.fsat = nir_intrinsic_legacy_fsat(store),
.write_mask = nir_intrinsic_write_mask(store),
};
} else {
- return (nir_legacy_alu_dest) {
+ return (nir_legacy_alu_dest){
.dest.is_ssa = true,
.dest.ssa = &dest->ssa,
.write_mask = nir_component_mask(dest->ssa.num_components),
/* Try SSA fsat. No users support 64-bit modifiers. */
if (chase_fsat(&def)) {
- return (nir_legacy_alu_dest) {
+ return (nir_legacy_alu_dest){
.dest.is_ssa = true,
.dest.ssa = def,
.fsat = true,
* chase registers recursively, allowing registers to be trivialized easier.
*/
if (nir_shader_instructions_pass(s, fuse_mods_with_registers,
- nir_metadata_block_index |
- nir_metadata_dominance, &fuse_fabs)) {
+ nir_metadata_block_index |
+ nir_metadata_dominance,
+ &fuse_fabs)) {
/* If we made progress, we likely left dead loads. Clean them up. */
NIR_PASS_V(s, nir_opt_dce);
}
* IN THE SOFTWARE.
*/
+#include "util/hash_table.h"
+#include "util/set.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/set.h"
-#include "util/hash_table.h"
/* This file contains various little helpers for doing simple linking in
* NIR. Eventually, we'll probably want a full-blown varying packing
if (var->data.location < 0)
return 0;
- unsigned location = var->data.patch ?
- var->data.location - VARYING_SLOT_PATCH0 : var->data.location;
+ unsigned location = var->data.patch ? var->data.location - VARYING_SLOT_PATCH0 : var->data.location;
assert(var->data.mode == nir_var_shader_in ||
var->data.mode == nir_var_shader_out);
if (!(other_stage & get_variable_io_mask(var, shader->info.stage))) {
/* This one is invalid, make it a global variable instead */
if (shader->info.stage == MESA_SHADER_MESH &&
- (shader->info.outputs_read & BITFIELD64_BIT(var->data.location)))
+ (shader->info.outputs_read & BITFIELD64_BIT(var->data.location)))
var->data.mode = nir_var_mem_shared;
else
var->data.mode = nir_var_shader_temp;
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
nir_fixup_deref_modes(shader);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
patches_read);
progress = nir_remove_unused_io_vars(consumer, nir_var_shader_in, written,
- patches_written) || progress;
+ patches_written) ||
+ progress;
return progress;
}
return INTERP_MODE_NONE;
}
-#define INTERPOLATE_LOC_SAMPLE 0
+#define INTERPOLATE_LOC_SAMPLE 0
#define INTERPOLATE_LOC_CENTROID 1
-#define INTERPOLATE_LOC_CENTER 2
+#define INTERPOLATE_LOC_CENTER 2
static uint8_t
get_interp_loc(nir_variable *var)
return glsl_type_is_scalar(type) && glsl_type_is_32bit(type);
}
-struct assigned_comps
-{
+struct assigned_comps {
uint8_t comps;
uint8_t interp_type;
uint8_t interp_loc;
unsigned location = var->data.location - VARYING_SLOT_VAR0;
unsigned elements =
- glsl_type_is_vector_or_scalar(glsl_without_array(type)) ?
- glsl_get_vector_elements(glsl_without_array(type)) : 4;
+ glsl_type_is_vector_or_scalar(glsl_without_array(type)) ? glsl_get_vector_elements(glsl_without_array(type)) : 4;
bool dual_slot = glsl_type_is_dual_slot(glsl_without_array(type));
unsigned slots = glsl_count_attribute_slots(type, false);
}
}
-struct varying_loc
-{
+struct varying_loc {
uint8_t component;
uint32_t location;
};
unsigned loc_offset = var->data.patch ? VARYING_SLOT_PATCH0 : 0;
slots_used[var->data.patch ? 1 : 0] |= slots_used_mask &
- BITFIELD64_RANGE(var->data.location - loc_offset, num_slots);
+ BITFIELD64_RANGE(var->data.location - loc_offset, num_slots);
}
static void
struct varying_loc (*remap)[4],
uint64_t *slots_used, uint64_t *out_slots_read,
uint32_t *p_slots_used, uint32_t *p_out_slots_read)
- {
+{
const gl_shader_stage stage = shader->info.stage;
- uint64_t out_slots_read_tmp[2] = {0};
- uint64_t slots_used_tmp[2] = {0};
+ uint64_t out_slots_read_tmp[2] = { 0 };
+ uint64_t slots_used_tmp[2] = { 0 };
/* We don't touch builtins so just copy the bitmask */
slots_used_tmp[0] = *slots_used & BITFIELD64_RANGE(0, VARYING_SLOT_VAR0);
static int
cmp_varying_component(const void *comp1_v, const void *comp2_v)
{
- struct varying_component *comp1 = (struct varying_component *) comp1_v;
- struct varying_component *comp2 = (struct varying_component *) comp2_v;
+ struct varying_component *comp1 = (struct varying_component *)comp1_v;
+ struct varying_component *comp2 = (struct varying_component *)comp2_v;
/* We want patches to be order at the end of the array */
if (comp1->is_patch != comp2->is_patch)
unsigned *varying_comp_info_size,
bool default_to_smooth_interp)
{
- unsigned store_varying_info_idx[MAX_VARYINGS_INCL_PATCH][4] = {{0}};
+ unsigned store_varying_info_idx[MAX_VARYINGS_INCL_PATCH][4] = { { 0 } };
unsigned num_of_comps_to_pack = 0;
/* Count the number of varying that can be packed and create a mapping
continue;
struct varying_component *vc_info =
- &(*varying_comp_info)[var_info_idx-1];
+ &(*varying_comp_info)[var_info_idx - 1];
if (!vc_info->initialised) {
const struct glsl_type *type = in_var->type;
vc_info->is_patch = in_var->data.patch;
vc_info->is_per_primitive = in_var->data.per_primitive;
vc_info->is_mediump = !producer->options->linker_ignore_precision &&
- (in_var->data.precision == GLSL_PRECISION_MEDIUM ||
- in_var->data.precision == GLSL_PRECISION_LOW);
+ (in_var->data.precision == GLSL_PRECISION_MEDIUM ||
+ in_var->data.precision == GLSL_PRECISION_LOW);
vc_info->is_intra_stage_only = false;
vc_info->initialised = true;
}
}
struct varying_component *vc_info =
- &(*varying_comp_info)[var_info_idx-1];
+ &(*varying_comp_info)[var_info_idx - 1];
if (!vc_info->initialised) {
const struct glsl_type *type = out_var->type;
vc_info->is_patch = out_var->data.patch;
vc_info->is_per_primitive = out_var->data.per_primitive;
vc_info->is_mediump = !producer->options->linker_ignore_precision &&
- (out_var->data.precision == GLSL_PRECISION_MEDIUM ||
- out_var->data.precision == GLSL_PRECISION_LOW);
+ (out_var->data.precision == GLSL_PRECISION_MEDIUM ||
+ out_var->data.precision == GLSL_PRECISION_LOW);
vc_info->is_intra_stage_only = true;
vc_info->initialised = true;
}
}
}
- for (unsigned i = 0; i < *varying_comp_info_size; i++ ) {
+ for (unsigned i = 0; i < *varying_comp_info_size; i++) {
struct varying_component *vc_info = &(*varying_comp_info)[i];
if (!vc_info->initialised) {
/* Something went wrong, the shader interfaces didn't match, so
}
static void
-assign_remap_locations(struct varying_loc (*remap)[4],
- struct assigned_comps *assigned_comps,
- struct varying_component *info,
- unsigned *cursor, unsigned *comp,
- unsigned max_location,
- nir_pack_varying_options options)
+ assign_remap_locations(struct varying_loc (*remap)[4],
+ struct assigned_comps *assigned_comps,
+ struct varying_component *info,
+ unsigned *cursor, unsigned *comp,
+ unsigned max_location,
+ nir_pack_varying_options options)
{
unsigned tmp_cursor = *cursor;
unsigned tmp_comp = *comp;
struct assigned_comps *assigned_comps,
bool default_to_smooth_interp)
{
- struct varying_loc remap[MAX_VARYINGS_INCL_PATCH][4] = {{{0}, {0}}};
+ struct varying_loc remap[MAX_VARYINGS_INCL_PATCH][4] = { { { 0 }, { 0 } } };
struct varying_component *varying_comp_info;
unsigned varying_comp_info_size;
unsigned comp = 0;
/* Set the remap array based on the sorted components */
- for (unsigned i = 0; i < varying_comp_info_size; i++ ) {
+ for (unsigned i = 0; i < varying_comp_info_size; i++) {
struct varying_component *info = &varying_comp_info[i];
assert(info->is_patch || cursor < MAX_VARYING);
assert(producer->info.stage != MESA_SHADER_FRAGMENT);
assert(consumer->info.stage != MESA_SHADER_VERTEX);
- struct assigned_comps assigned_comps[MAX_VARYINGS_INCL_PATCH] = {{0}};
+ struct assigned_comps assigned_comps[MAX_VARYINGS_INCL_PATCH] = { { 0 } };
get_unmoveable_components_masks(producer, nir_var_shader_out,
assigned_comps,
static bool
replace_duplicate_input(nir_shader *shader, nir_variable *input_var,
- nir_intrinsic_instr *dup_store_intr)
+ nir_intrinsic_instr *dup_store_intr)
{
assert(input_var);
clone_deref_instr(nir_builder *b, nir_variable *var, nir_deref_instr *deref)
{
if (deref->deref_type == nir_deref_type_var)
- return nir_build_deref_var(b, var);
+ return nir_build_deref_var(b, var);
nir_deref_instr *parent_deref = nir_deref_instr_parent(deref);
nir_deref_instr *parent = clone_deref_instr(b, var, parent_deref);
/* Add a vector to scalar move if uniform is a vector. */
if (uni_def->num_components > 1) {
- nir_alu_src src = {0};
+ nir_alu_src src = { 0 };
src.src = nir_src_for_ssa(uni_def);
src.swizzle[0] = scalar->comp;
uni_def = nir_mov_alu(&b, src, 1);
continue;
nir_variable *consumer_var = find_consumer_variable(consumer,
- producer_var);
+ producer_var);
/* Skip if the variable will be eliminated */
if (!consumer_var)
struct hash_entry *entry = _mesa_hash_table_search(varying_values, ssa);
if (entry) {
progress |= replace_duplicate_input(consumer,
- (nir_variable *) entry->data,
+ (nir_variable *)entry->data,
intr);
} else {
nir_variable *in_var = get_matching_input_var(consumer, out_var);
{
unsigned location = 0;
unsigned assigned_locations[VARYING_SLOT_TESS_MAX];
- uint64_t processed_locs[2] = {0};
+ uint64_t processed_locs[2] = { 0 };
struct exec_list io_vars;
sort_varyings(shader, mode, &io_vars);
*/
#include "nir.h"
-#include "nir_worklist.h"
#include "nir_vla.h"
+#include "nir_worklist.h"
/*
* Basic liveness analysis. This works only in SSA form.
BITSET_WORD *live = void_live;
if (nir_src_is_undef(*src))
- return true; /* undefined variables are never live */
+ return true; /* undefined variables are never live */
BITSET_SET(live, src->ssa->index);
/* Number the instructions so we can do cheap interference tests using the
* instruction index.
*/
- nir_metadata_require(impl, nir_metadata_instr_index);
+ nir_metadata_require(impl, nir_metadata_instr_index);
nir_block_worklist_init(&state.worklist, impl->num_blocks, NULL);
init_liveness_block(block, &state);
}
-
/* We're now ready to work through the worklist and update the liveness
* sets of each of the blocks. By the time we get to this point, every
* block in the function implementation has been pushed onto the
* IN THE SOFTWARE.
*/
-#include "nir.h"
-#include "nir_constant_expressions.h"
#include "nir_loop_analyze.h"
#include "util/bitset.h"
+#include "nir.h"
+#include "nir_constant_expressions.h"
typedef enum {
undefined,
unsigned cost = 1;
if (nir_op_is_selection(alu->op)) {
- nir_ssa_scalar cond_scalar = {alu->src[0].src.ssa, 0};
+ nir_ssa_scalar cond_scalar = { alu->src[0].src.ssa, 0 };
if (nir_is_terminator_condition_with_two_inputs(cond_scalar)) {
nir_instr *sel_cond = alu->src[0].src.ssa->parent_instr;
nir_alu_instr *sel_alu = nir_instr_as_alu(sel_cond);
if ((nir_src_is_const(sel_alu->src[0].src) &&
get_loop_var(rhs.def, state)->type == basic_induction) ||
(nir_src_is_const(sel_alu->src[1].src) &&
- get_loop_var(lhs.def, state)->type == basic_induction) ) {
+ get_loop_var(lhs.def, state)->type == basic_induction)) {
/* Also if the selects condition is only used by the select then
* remove that alu instructons cost from the cost total also.
*/
return cost;
bool is_fp64 = nir_dest_bit_size(alu->dest.dest) == 64 &&
- nir_alu_type_get_base_type(info->output_type) == nir_type_float;
+ nir_alu_type_get_base_type(info->output_type) == nir_type_float;
for (unsigned i = 0; i < info->num_inputs; i++) {
if (nir_src_bit_size(alu->src[i].src) == 64 &&
nir_alu_type_get_base_type(info->input_types[i]) == nir_type_float)
init_loop_block(nir_block *block, loop_info_state *state,
bool in_if_branch, bool in_nested_loop)
{
- init_loop_state init_state = {.in_if_branch = in_if_branch,
- .in_nested_loop = in_nested_loop,
- .state = state };
+ init_loop_state init_state = { .in_if_branch = in_if_branch,
+ .in_nested_loop = in_nested_loop,
+ .state = state };
nir_foreach_instr(instr, block) {
nir_foreach_ssa_def(instr, init_loop_def, &init_state);
nir_alu_instr *alu = nir_instr_as_alu(instr);
for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
if (!is_only_uniform_src(&alu->src[i].src))
- return false;
+ return false;
}
return true;
}
/* Is one of the operands const or uniform, and the other the phi.
* The phi source can't be swizzled in any way.
*/
- if (alu->src[1-i].src.ssa == &phi->dest.ssa &&
+ if (alu->src[1 - i].src.ssa == &phi->dest.ssa &&
alu_src_has_identity_swizzle(alu, 1 - i)) {
if (is_only_uniform_src(&alu->src[i].src))
var->update_src = alu->src + i;
if (var->type == basic_induction) {
nir_loop_induction_variable *ivar =
&info->induction_vars[info->num_induction_vars++];
- ivar->def = var->def;
- ivar->init_src = var->init_src;
- ivar->update_src = var->update_src;
+ ivar->def = var->def;
+ ivar->init_src = var->init_src;
+ ivar->update_src = var->update_src;
}
}
/* don't overflow */
if (array_size) {
if ((array_size == state->loop->info->max_trip_count) &&
nir_deref_mode_must_be(deref, nir_var_shader_in |
- nir_var_shader_out |
- nir_var_shader_temp |
- nir_var_function_temp))
+ nir_var_shader_out |
+ nir_var_shader_temp |
+ nir_var_function_temp))
return true;
if (nir_deref_mode_must_be(deref, state->indirect_mask))
nir_tex_instr_src_index(tex_instr,
nir_tex_src_sampler_deref);
-
if (sampler_idx >= 0) {
nir_deref_instr *deref =
nir_instr_as_deref(tex_instr->src[sampler_idx].src.ssa->parent_instr);
}
}
-
if (instr->type != nir_instr_type_intrinsic)
continue;
list_inithead(&state->process_list);
if (loop->info)
- ralloc_free(loop->info);
+ ralloc_free(loop->info);
loop->info = rzalloc(loop, nir_loop_info);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
}
return nir_shader_instructions_pass(shader, lower_alu_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
}
#define LOWER_REDUCTION(name, chan, merge) \
- case name##2: \
- case name##3: \
- case name##4: \
- case name##8: \
- case name##16: \
- return lower_reduction(alu, chan, merge, b, true); \
+ case name##2: \
+ case name##3: \
+ case name##4: \
+ case name##8: \
+ case name##16: \
+ return lower_reduction(alu, chan, merge, b, true);
switch (alu->op) {
case nir_op_vec16:
nir_ssa_def *src_vec2 = nir_ssa_for_alu_src(b, alu, 0);
return nir_pack_half_2x16_split(b, nir_channel(b, src_vec2, 0),
- nir_channel(b, src_vec2, 1));
+ nir_channel(b, src_vec2, 1));
}
case nir_op_unpack_unorm_4x8:
nir_ssa_def *packed = nir_ssa_for_alu_src(b, alu, 0);
if (alu->op == nir_op_unpack_half_2x16_flush_to_zero) {
- return nir_vec2(b,
- nir_unpack_half_2x16_split_x_flush_to_zero(b,
- packed),
- nir_unpack_half_2x16_split_y_flush_to_zero(b,
- packed));
+ return nir_vec2(b,
+ nir_unpack_half_2x16_split_x_flush_to_zero(b,
+ packed),
+ nir_unpack_half_2x16_split_y_flush_to_zero(b,
+ packed));
} else {
- return nir_vec2(b,
- nir_unpack_half_2x16_split_x(b, packed),
- nir_unpack_half_2x16_split_y(b, packed));
+ return nir_vec2(b,
+ nir_unpack_half_2x16_split_x(b, packed),
+ nir_unpack_half_2x16_split_y(b, packed));
}
}
b->shader->options->lower_pack_unorm_2x16);
nir_ssa_def *word = nir_extract_u16(b, nir_ssa_for_alu_src(b, alu, 0),
- nir_imm_int(b, 0));
- return nir_ior(b, nir_ishl(b, nir_channel(b, word, 1),
- nir_imm_int(b, 16)),
- nir_channel(b, word, 0));
+ nir_imm_int(b, 0));
+ return nir_ior(b, nir_ishl(b, nir_channel(b, word, 1), nir_imm_int(b, 16)),
+ nir_channel(b, word, 0));
}
case nir_op_pack_uvec4_to_uint: {
b->shader->options->lower_pack_unorm_4x8);
nir_ssa_def *byte = nir_extract_u8(b, nir_ssa_for_alu_src(b, alu, 0),
- nir_imm_int(b, 0));
- return nir_ior(b, nir_ior(b, nir_ishl(b, nir_channel(b, byte, 3),
- nir_imm_int(b, 24)),
- nir_ishl(b, nir_channel(b, byte, 2),
- nir_imm_int(b, 16))),
- nir_ior(b, nir_ishl(b, nir_channel(b, byte, 1),
- nir_imm_int(b, 8)),
- nir_channel(b, byte, 0)));
+ nir_imm_int(b, 0));
+ return nir_ior(b, nir_ior(b, nir_ishl(b, nir_channel(b, byte, 3), nir_imm_int(b, 24)), nir_ishl(b, nir_channel(b, byte, 2), nir_imm_int(b, 16))),
+ nir_ior(b, nir_ishl(b, nir_channel(b, byte, 1), nir_imm_int(b, 8)),
+ nir_channel(b, byte, 0)));
}
case nir_op_fdph: {
for (unsigned i = 0; i < 3; i++) {
int dest = reverse_order ? 3 - i : i;
sum[dest] = nir_fmul(b, nir_channel(b, src0_vec, i),
- nir_channel(b, src1_vec, i));
+ nir_channel(b, src1_vec, i));
}
sum[reverse_order ? 0 : 3] = nir_channel(b, src1_vec, 3);
nir_ssa_def *src_vec4 = nir_ssa_for_alu_src(b, alu, 0);
nir_ssa_def *xy = nir_pack_32_2x16_split(b, nir_channel(b, src_vec4, 0),
- nir_channel(b, src_vec4, 1));
+ nir_channel(b, src_vec4, 1));
nir_ssa_def *zw = nir_pack_32_2x16_split(b, nir_channel(b, src_vec4, 2),
- nir_channel(b, src_vec4, 3));
+ nir_channel(b, src_vec4, 3));
return nir_pack_64_2x32_split(b, xy, zw);
}
return nir_lower_alu_width(shader, cb ? scalar_cb : NULL, &data);
}
-
{
switch (intr->intrinsic) {
case nir_intrinsic_load_ubo:
- //# src[] = { buffer_index, offset }.
+ // # src[] = { buffer_index, offset }.
if (large_ubo(state, intr->src[0]))
lower_large_src(&intr->src[1], state);
return;
case nir_intrinsic_load_ssbo:
- //# src[] = { buffer_index, offset }.
+ // # src[] = { buffer_index, offset }.
if (large_ssbo(state, intr->src[0]))
lower_large_src(&intr->src[1], state);
return;
case nir_intrinsic_store_ssbo:
- //# src[] = { value, block_index, offset }
+ // # src[] = { value, block_index, offset }
if (large_ssbo(state, intr->src[1]))
lower_large_src(&intr->src[2], state);
return;
/* Figure out which UBOs or SSBOs are large enough to be
* disqualified from imul24:
*/
- nir_foreach_variable_in_shader (var, shader) {
+ nir_foreach_variable_in_shader(var, shader) {
if (var->data.mode == nir_var_mem_ubo) {
if (is_large(&state, var)) {
state.has_large_ubo = true;
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
-
+ nir_metadata_dominance);
}
return state.progress;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
static nir_deref_instr *
deref_offset_var(nir_builder *b, unsigned binding, unsigned offset_align_state)
{
- gl_state_index16 tokens[STATE_LENGTH] = {offset_align_state, binding};
+ gl_state_index16 tokens[STATE_LENGTH] = { offset_align_state, binding };
nir_variable *var = nir_find_state_variable(b->shader, tokens);
if (!var) {
var = nir_state_variable_create(b->shader, glsl_uint_type(), "offset", tokens);
offset_load = nir_load_deref(b, deref_offset);
}
nir_intrinsic_instr *new_instr =
- nir_intrinsic_instr_create(b->shader, op);
+ nir_intrinsic_instr_create(b->shader, op);
if (nir_intrinsic_has_atomic_op(new_instr))
nir_intrinsic_set_atomic_op(new_instr, atomic_op);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
if (progress) {
ssbo->data.binding + 1);
struct glsl_struct_field field = {
- .type = type,
- .name = "counters",
- .location = -1,
+ .type = type,
+ .name = "counters",
+ .location = -1,
};
ssbo->interface_type =
- glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
- false, "counters");
+ glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
+ false, "counters");
replaced |= (1 << var->data.binding);
}
return progress;
}
-
* the original bit-size.
*/
-static nir_ssa_def *convert_to_bit_size(nir_builder *bld, nir_ssa_def *src,
- nir_alu_type type, unsigned bit_size)
+static nir_ssa_def *
+convert_to_bit_size(nir_builder *bld, nir_ssa_def *src,
+ nir_alu_type type, unsigned bit_size)
{
assert(src->bit_size < bit_size);
lowered_dst = nir_build_alu_src_arr(bld, op, srcs);
}
-
/* Convert result back to the original bit-size */
if (nir_alu_type_get_type_size(nir_op_infos[op].output_type) == 0 &&
dst_bit_size != bit_size) {
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
{
return nir_shader_instructions_pass(shader, lower_64bit_phi_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
nir_builder_instr_insert(b, &tex->instr);
/* kill if tex != 0.0.. take .x or .w channel according to format: */
- cond = nir_fneu_imm(b, nir_channel(b, &tex->dest.ssa,
- options->swizzle_xxxx ? 0 : 3),
+ cond = nir_fneu_imm(b, nir_channel(b, &tex->dest.ssa, options->swizzle_xxxx ? 0 : 3),
0.0);
nir_discard_if(b, cond);
lower_bitmap(impl->function->shader, &b, options);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
void
* fixed-function blending in part or in full.
*/
+#include "nir_lower_blend.h"
#include "compiler/nir/nir.h"
#include "compiler/nir/nir_builder.h"
#include "compiler/nir/nir_format_convert.h"
#include "util/blend.h"
-#include "nir_lower_blend.h"
struct ctx {
const nir_lower_blend_options *options;
nir_fsat_signed(nir_builder *b, nir_ssa_def *x)
{
return nir_fclamp(b, x, nir_imm_floatN_t(b, -1.0, x->bit_size),
- nir_imm_floatN_t(b, +1.0, x->bit_size));
+ nir_imm_floatN_t(b, +1.0, x->bit_size));
}
static nir_ssa_def *
default:
unreachable("invalid blend factor");
}
-
}
static bool
nir_ssa_def *dst)
{
return nir_vec4(b,
- nir_channel(b, (mask & (1 << 0)) ? src : dst, 0),
- nir_channel(b, (mask & (1 << 1)) ? src : dst, 1),
- nir_channel(b, (mask & (1 << 2)) ? src : dst, 2),
- nir_channel(b, (mask & (1 << 3)) ? src : dst, 3));
+ nir_channel(b, (mask & (1 << 0)) ? src : dst, 0),
+ nir_channel(b, (mask & (1 << 1)) ? src : dst, 1),
+ nir_channel(b, (mask & (1 << 2)) ? src : dst, 2),
+ nir_channel(b, (mask & (1 << 3)) ? src : dst, 3));
}
static nir_ssa_def *
unsigned bits[4];
for (int i = 0; i < 4; ++i)
- bits[i] = format_desc->channel[i].size;
+ bits[i] = format_desc->channel[i].size;
if (util_format_is_unorm(format)) {
src = nir_format_float_to_unorm(b, src, bits);
nir_ssa_def *one = nir_imm_floatN_t(b, 1.0, dst->bit_size);
dst = nir_vec4(b,
- channel_exists(desc, 0) ? nir_channel(b, dst, 0) : zero,
- channel_exists(desc, 1) ? nir_channel(b, dst, 1) : zero,
- channel_exists(desc, 2) ? nir_channel(b, dst, 2) : zero,
- channel_exists(desc, 3) ? nir_channel(b, dst, 3) : one);
+ channel_exists(desc, 0) ? nir_channel(b, dst, 0) : zero,
+ channel_exists(desc, 1) ? nir_channel(b, dst, 1) : zero,
+ channel_exists(desc, 2) ? nir_channel(b, dst, 2) : zero,
+ channel_exists(desc, 3) ? nir_channel(b, dst, 3) : one);
/* We blend per channel and recombine later */
nir_ssa_def *channels[4];
if (nir_blend_factored(chan.func)) {
psrc = nir_blend_factor(
- b, psrc,
- src, src1, dst, bconst, c,
- chan.src_factor, format);
+ b, psrc,
+ src, src1, dst, bconst, c,
+ chan.src_factor, format);
pdst = nir_blend_factor(
- b, pdst,
- src, src1, dst, bconst, c,
- chan.dst_factor, format);
+ b, pdst,
+ src, src1, dst, bconst, c,
+ chan.dst_factor, format);
}
channels[c] = nir_blend_func(b, chan.func, psrc, pdst);
/* Grow or shrink the store destination as needed */
store->num_components = num_components;
nir_intrinsic_set_write_mask(store, nir_intrinsic_write_mask(store) &
- nir_component_mask(num_components));
+ nir_component_mask(num_components));
/* Write out the final color instead of the input */
nir_instr_rewrite_src_ssa(instr, &store->src[0], blended);
{
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
- struct ctx ctx = {.options = options};
+ struct ctx ctx = { .options = options };
nir_shader_instructions_pass(shader, consume_dual_stores,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
ctx.src1);
nir_shader_instructions_pass(shader, nir_lower_blend_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&ctx);
}
#define NIR_BLEND_H
#include "compiler/nir/nir.h"
-#include "util/format/u_formats.h"
#include "util/blend.h"
+#include "util/format/u_formats.h"
/* These structs encapsulates the blend state such that it can be lowered
* cleanly
get_bool_convert_opcode(uint32_t dst_bit_size)
{
switch (dst_bit_size) {
- case 32: return nir_op_i2i32;
- case 16: return nir_op_i2i16;
- case 8: return nir_op_i2i8;
+ case 32:
+ return nir_op_i2i32;
+ case 16:
+ return nir_op_i2i16;
+ case 8:
+ return nir_op_i2i8;
default:
unreachable("invalid boolean bit-size");
}
break;
case nir_op_flt:
- opcode = bit_size == 8 ? nir_op_flt8 :
- bit_size == 16 ? nir_op_flt16 : nir_op_flt32;
+ opcode = bit_size == 8 ? nir_op_flt8 : bit_size == 16 ? nir_op_flt16
+ : nir_op_flt32;
break;
case nir_op_fge:
- opcode = bit_size == 8 ? nir_op_fge8 :
- bit_size == 16 ? nir_op_fge16 : nir_op_fge32;
+ opcode = bit_size == 8 ? nir_op_fge8 : bit_size == 16 ? nir_op_fge16
+ : nir_op_fge32;
break;
case nir_op_feq:
- opcode = bit_size == 8 ? nir_op_feq8 :
- bit_size == 16 ? nir_op_feq16 : nir_op_feq32;
+ opcode = bit_size == 8 ? nir_op_feq8 : bit_size == 16 ? nir_op_feq16
+ : nir_op_feq32;
break;
case nir_op_fneu:
- opcode = bit_size == 8 ? nir_op_fneu8 :
- bit_size == 16 ? nir_op_fneu16 : nir_op_fneu32;
+ opcode = bit_size == 8 ? nir_op_fneu8 : bit_size == 16 ? nir_op_fneu16
+ : nir_op_fneu32;
break;
case nir_op_ilt:
- opcode = bit_size == 8 ? nir_op_ilt8 :
- bit_size == 16 ? nir_op_ilt16 : nir_op_ilt32;
+ opcode = bit_size == 8 ? nir_op_ilt8 : bit_size == 16 ? nir_op_ilt16
+ : nir_op_ilt32;
break;
case nir_op_ige:
- opcode = bit_size == 8 ? nir_op_ige8 :
- bit_size == 16 ? nir_op_ige16 : nir_op_ige32;
+ opcode = bit_size == 8 ? nir_op_ige8 : bit_size == 16 ? nir_op_ige16
+ : nir_op_ige32;
break;
case nir_op_ieq:
- opcode = bit_size == 8 ? nir_op_ieq8 :
- bit_size == 16 ? nir_op_ieq16 : nir_op_ieq32;
+ opcode = bit_size == 8 ? nir_op_ieq8 : bit_size == 16 ? nir_op_ieq16
+ : nir_op_ieq32;
break;
case nir_op_ine:
- opcode = bit_size == 8 ? nir_op_ine8 :
- bit_size == 16 ? nir_op_ine16 : nir_op_ine32;
+ opcode = bit_size == 8 ? nir_op_ine8 : bit_size == 16 ? nir_op_ine16
+ : nir_op_ine32;
break;
case nir_op_ult:
- opcode = bit_size == 8 ? nir_op_ult8 :
- bit_size == 16 ? nir_op_ult16 : nir_op_ult32;
+ opcode = bit_size == 8 ? nir_op_ult8 : bit_size == 16 ? nir_op_ult16
+ : nir_op_ult32;
break;
case nir_op_uge:
- opcode = bit_size == 8 ? nir_op_uge8 :
- bit_size == 16 ? nir_op_uge16 : nir_op_uge32;
+ opcode = bit_size == 8 ? nir_op_uge8 : bit_size == 16 ? nir_op_uge16
+ : nir_op_uge32;
break;
case nir_op_ball_fequal2:
- opcode = bit_size == 8 ? nir_op_b8all_fequal2 :
- bit_size == 16 ? nir_op_b16all_fequal2 :
- nir_op_b32all_fequal2;
+ opcode = bit_size == 8 ? nir_op_b8all_fequal2 : bit_size == 16 ? nir_op_b16all_fequal2
+ : nir_op_b32all_fequal2;
break;
case nir_op_ball_fequal3:
- opcode = bit_size == 8 ? nir_op_b8all_fequal3 :
- bit_size == 16 ? nir_op_b16all_fequal3 :
- nir_op_b32all_fequal3;
+ opcode = bit_size == 8 ? nir_op_b8all_fequal3 : bit_size == 16 ? nir_op_b16all_fequal3
+ : nir_op_b32all_fequal3;
break;
case nir_op_ball_fequal4:
- opcode = bit_size == 8 ? nir_op_b8all_fequal4 :
- bit_size == 16 ? nir_op_b16all_fequal4 :
- nir_op_b32all_fequal4;
+ opcode = bit_size == 8 ? nir_op_b8all_fequal4 : bit_size == 16 ? nir_op_b16all_fequal4
+ : nir_op_b32all_fequal4;
break;
case nir_op_bany_fnequal2:
- opcode = bit_size == 8 ? nir_op_b8any_fnequal2 :
- bit_size == 16 ? nir_op_b16any_fnequal2 :
- nir_op_b32any_fnequal2;
+ opcode = bit_size == 8 ? nir_op_b8any_fnequal2 : bit_size == 16 ? nir_op_b16any_fnequal2
+ : nir_op_b32any_fnequal2;
break;
case nir_op_bany_fnequal3:
- opcode = bit_size == 8 ? nir_op_b8any_fnequal3 :
- bit_size == 16 ? nir_op_b16any_fnequal3 :
- nir_op_b32any_fnequal3;
+ opcode = bit_size == 8 ? nir_op_b8any_fnequal3 : bit_size == 16 ? nir_op_b16any_fnequal3
+ : nir_op_b32any_fnequal3;
break;
case nir_op_bany_fnequal4:
- opcode = bit_size == 8 ? nir_op_b8any_fnequal4 :
- bit_size == 16 ? nir_op_b16any_fnequal4 :
- nir_op_b32any_fnequal4;
+ opcode = bit_size == 8 ? nir_op_b8any_fnequal4 : bit_size == 16 ? nir_op_b16any_fnequal4
+ : nir_op_b32any_fnequal4;
break;
case nir_op_ball_iequal2:
- opcode = bit_size == 8 ? nir_op_b8all_iequal2 :
- bit_size == 16 ? nir_op_b16all_iequal2 :
- nir_op_b32all_iequal2;
+ opcode = bit_size == 8 ? nir_op_b8all_iequal2 : bit_size == 16 ? nir_op_b16all_iequal2
+ : nir_op_b32all_iequal2;
break;
case nir_op_ball_iequal3:
- opcode = bit_size == 8 ? nir_op_b8all_iequal3 :
- bit_size == 16 ? nir_op_b16all_iequal3 :
- nir_op_b32all_iequal3;
+ opcode = bit_size == 8 ? nir_op_b8all_iequal3 : bit_size == 16 ? nir_op_b16all_iequal3
+ : nir_op_b32all_iequal3;
break;
case nir_op_ball_iequal4:
- opcode = bit_size == 8 ? nir_op_b8all_iequal4 :
- bit_size == 16 ? nir_op_b16all_iequal4 :
- nir_op_b32all_iequal4;
+ opcode = bit_size == 8 ? nir_op_b8all_iequal4 : bit_size == 16 ? nir_op_b16all_iequal4
+ : nir_op_b32all_iequal4;
break;
case nir_op_bany_inequal2:
- opcode = bit_size == 8 ? nir_op_b8any_inequal2 :
- bit_size == 16 ? nir_op_b16any_inequal2 :
- nir_op_b32any_inequal2;
+ opcode = bit_size == 8 ? nir_op_b8any_inequal2 : bit_size == 16 ? nir_op_b16any_inequal2
+ : nir_op_b32any_inequal2;
break;
case nir_op_bany_inequal3:
- opcode = bit_size == 8 ? nir_op_b8any_inequal3 :
- bit_size == 16 ? nir_op_b16any_inequal3 :
- nir_op_b32any_inequal3;
+ opcode = bit_size == 8 ? nir_op_b8any_inequal3 : bit_size == 16 ? nir_op_b16any_inequal3
+ : nir_op_b32any_inequal3;
break;
case nir_op_bany_inequal4:
- opcode = bit_size == 8 ? nir_op_b8any_inequal4 :
- bit_size == 16 ? nir_op_b16any_inequal4 :
- nir_op_b32any_inequal4;
+ opcode = bit_size == 8 ? nir_op_b8any_inequal4 : bit_size == 16 ? nir_op_b16any_inequal4
+ : nir_op_b32any_inequal4;
break;
case nir_op_bcsel:
- opcode = bit_size == 8 ? nir_op_b8csel :
- bit_size == 16 ? nir_op_b16csel : nir_op_b32csel;
+ opcode = bit_size == 8 ? nir_op_b8csel : bit_size == 16 ? nir_op_b16csel
+ : nir_op_b32csel;
/* The destination of the selection may have a different bit-size from
* the bcsel condition.
{
return nir_shader_instructions_pass(shader, nir_lower_bool_to_bitsize_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
/* These we expect to have booleans but the opcode doesn't change */
break;
- case nir_op_b2f32: alu->op = nir_op_mov; break;
- case nir_op_b2i32: alu->op = nir_op_mov; break;
- case nir_op_b2b1: alu->op = nir_op_mov; break;
-
- case nir_op_flt: alu->op = nir_op_slt; break;
- case nir_op_fge: alu->op = nir_op_sge; break;
- case nir_op_feq: alu->op = nir_op_seq; break;
- case nir_op_fneu: alu->op = nir_op_sne; break;
- case nir_op_ilt: alu->op = nir_op_slt; break;
- case nir_op_ige: alu->op = nir_op_sge; break;
- case nir_op_ieq: alu->op = nir_op_seq; break;
- case nir_op_ine: alu->op = nir_op_sne; break;
- case nir_op_ult: alu->op = nir_op_slt; break;
- case nir_op_uge: alu->op = nir_op_sge; break;
-
- case nir_op_ball_fequal2: alu->op = nir_op_fall_equal2; break;
- case nir_op_ball_fequal3: alu->op = nir_op_fall_equal3; break;
- case nir_op_ball_fequal4: alu->op = nir_op_fall_equal4; break;
- case nir_op_bany_fnequal2: alu->op = nir_op_fany_nequal2; break;
- case nir_op_bany_fnequal3: alu->op = nir_op_fany_nequal3; break;
- case nir_op_bany_fnequal4: alu->op = nir_op_fany_nequal4; break;
- case nir_op_ball_iequal2: alu->op = nir_op_fall_equal2; break;
- case nir_op_ball_iequal3: alu->op = nir_op_fall_equal3; break;
- case nir_op_ball_iequal4: alu->op = nir_op_fall_equal4; break;
- case nir_op_bany_inequal2: alu->op = nir_op_fany_nequal2; break;
- case nir_op_bany_inequal3: alu->op = nir_op_fany_nequal3; break;
- case nir_op_bany_inequal4: alu->op = nir_op_fany_nequal4; break;
+ case nir_op_b2f32:
+ alu->op = nir_op_mov;
+ break;
+ case nir_op_b2i32:
+ alu->op = nir_op_mov;
+ break;
+ case nir_op_b2b1:
+ alu->op = nir_op_mov;
+ break;
+
+ case nir_op_flt:
+ alu->op = nir_op_slt;
+ break;
+ case nir_op_fge:
+ alu->op = nir_op_sge;
+ break;
+ case nir_op_feq:
+ alu->op = nir_op_seq;
+ break;
+ case nir_op_fneu:
+ alu->op = nir_op_sne;
+ break;
+ case nir_op_ilt:
+ alu->op = nir_op_slt;
+ break;
+ case nir_op_ige:
+ alu->op = nir_op_sge;
+ break;
+ case nir_op_ieq:
+ alu->op = nir_op_seq;
+ break;
+ case nir_op_ine:
+ alu->op = nir_op_sne;
+ break;
+ case nir_op_ult:
+ alu->op = nir_op_slt;
+ break;
+ case nir_op_uge:
+ alu->op = nir_op_sge;
+ break;
+
+ case nir_op_ball_fequal2:
+ alu->op = nir_op_fall_equal2;
+ break;
+ case nir_op_ball_fequal3:
+ alu->op = nir_op_fall_equal3;
+ break;
+ case nir_op_ball_fequal4:
+ alu->op = nir_op_fall_equal4;
+ break;
+ case nir_op_bany_fnequal2:
+ alu->op = nir_op_fany_nequal2;
+ break;
+ case nir_op_bany_fnequal3:
+ alu->op = nir_op_fany_nequal3;
+ break;
+ case nir_op_bany_fnequal4:
+ alu->op = nir_op_fany_nequal4;
+ break;
+ case nir_op_ball_iequal2:
+ alu->op = nir_op_fall_equal2;
+ break;
+ case nir_op_ball_iequal3:
+ alu->op = nir_op_fall_equal3;
+ break;
+ case nir_op_ball_iequal4:
+ alu->op = nir_op_fall_equal4;
+ break;
+ case nir_op_bany_inequal2:
+ alu->op = nir_op_fany_nequal2;
+ break;
+ case nir_op_bany_inequal3:
+ alu->op = nir_op_fany_nequal3;
+ break;
+ case nir_op_bany_inequal4:
+ alu->op = nir_op_fany_nequal4;
+ break;
case nir_op_bcsel:
if (has_fcsel_gt)
break;
- case nir_op_iand: alu->op = nir_op_fmul; break;
- case nir_op_ixor: alu->op = nir_op_sne; break;
- case nir_op_ior: alu->op = nir_op_fmax; break;
+ case nir_op_iand:
+ alu->op = nir_op_fmul;
+ break;
+ case nir_op_ixor:
+ alu->op = nir_op_sne;
+ break;
+ case nir_op_ior:
+ alu->op = nir_op_fmax;
+ break;
case nir_op_inot:
rep = nir_seq(b, nir_ssa_for_alu_src(b, alu, 0),
- nir_imm_float(b, 0));
+ nir_imm_float(b, 0));
break;
default:
return nir_shader_instructions_pass(shader, nir_lower_bool_to_float_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&data);
}
alu->op = nir_op_mov;
break;
- case nir_op_flt: alu->op = nir_op_flt32; break;
- case nir_op_fge: alu->op = nir_op_fge32; break;
- case nir_op_feq: alu->op = nir_op_feq32; break;
- case nir_op_fneu: alu->op = nir_op_fneu32; break;
- case nir_op_ilt: alu->op = nir_op_ilt32; break;
- case nir_op_ige: alu->op = nir_op_ige32; break;
- case nir_op_ieq: alu->op = nir_op_ieq32; break;
- case nir_op_ine: alu->op = nir_op_ine32; break;
- case nir_op_ult: alu->op = nir_op_ult32; break;
- case nir_op_uge: alu->op = nir_op_uge32; break;
-
- case nir_op_ball_fequal2: alu->op = nir_op_b32all_fequal2; break;
- case nir_op_ball_fequal3: alu->op = nir_op_b32all_fequal3; break;
- case nir_op_ball_fequal4: alu->op = nir_op_b32all_fequal4; break;
- case nir_op_bany_fnequal2: alu->op = nir_op_b32any_fnequal2; break;
- case nir_op_bany_fnequal3: alu->op = nir_op_b32any_fnequal3; break;
- case nir_op_bany_fnequal4: alu->op = nir_op_b32any_fnequal4; break;
- case nir_op_ball_iequal2: alu->op = nir_op_b32all_iequal2; break;
- case nir_op_ball_iequal3: alu->op = nir_op_b32all_iequal3; break;
- case nir_op_ball_iequal4: alu->op = nir_op_b32all_iequal4; break;
- case nir_op_bany_inequal2: alu->op = nir_op_b32any_inequal2; break;
- case nir_op_bany_inequal3: alu->op = nir_op_b32any_inequal3; break;
- case nir_op_bany_inequal4: alu->op = nir_op_b32any_inequal4; break;
-
- case nir_op_bcsel: alu->op = nir_op_b32csel; break;
-
- case nir_op_fisfinite: alu->op = nir_op_fisfinite32; break;
+ case nir_op_flt:
+ alu->op = nir_op_flt32;
+ break;
+ case nir_op_fge:
+ alu->op = nir_op_fge32;
+ break;
+ case nir_op_feq:
+ alu->op = nir_op_feq32;
+ break;
+ case nir_op_fneu:
+ alu->op = nir_op_fneu32;
+ break;
+ case nir_op_ilt:
+ alu->op = nir_op_ilt32;
+ break;
+ case nir_op_ige:
+ alu->op = nir_op_ige32;
+ break;
+ case nir_op_ieq:
+ alu->op = nir_op_ieq32;
+ break;
+ case nir_op_ine:
+ alu->op = nir_op_ine32;
+ break;
+ case nir_op_ult:
+ alu->op = nir_op_ult32;
+ break;
+ case nir_op_uge:
+ alu->op = nir_op_uge32;
+ break;
+
+ case nir_op_ball_fequal2:
+ alu->op = nir_op_b32all_fequal2;
+ break;
+ case nir_op_ball_fequal3:
+ alu->op = nir_op_b32all_fequal3;
+ break;
+ case nir_op_ball_fequal4:
+ alu->op = nir_op_b32all_fequal4;
+ break;
+ case nir_op_bany_fnequal2:
+ alu->op = nir_op_b32any_fnequal2;
+ break;
+ case nir_op_bany_fnequal3:
+ alu->op = nir_op_b32any_fnequal3;
+ break;
+ case nir_op_bany_fnequal4:
+ alu->op = nir_op_b32any_fnequal4;
+ break;
+ case nir_op_ball_iequal2:
+ alu->op = nir_op_b32all_iequal2;
+ break;
+ case nir_op_ball_iequal3:
+ alu->op = nir_op_b32all_iequal3;
+ break;
+ case nir_op_ball_iequal4:
+ alu->op = nir_op_b32all_iequal4;
+ break;
+ case nir_op_bany_inequal2:
+ alu->op = nir_op_b32any_inequal2;
+ break;
+ case nir_op_bany_inequal3:
+ alu->op = nir_op_b32any_inequal3;
+ break;
+ case nir_op_bany_inequal4:
+ alu->op = nir_op_b32any_inequal4;
+ break;
+
+ case nir_op_bcsel:
+ alu->op = nir_op_b32csel;
+ break;
+
+ case nir_op_fisfinite:
+ alu->op = nir_op_fisfinite32;
+ break;
default:
assert(alu->dest.dest.ssa.bit_size > 1);
progress |=
nir_shader_instructions_pass(shader, nir_lower_bool_to_int32_instr,
nir_metadata_block_index |
- nir_metadata_dominance, NULL);
+ nir_metadata_dominance,
+ NULL);
return progress;
}
nir_shader_instructions_pass(nir, nir_dedup_inline_samplers_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&inline_samplers);
/* If we found any inline samplers in the instructions pass, they'll now be
b.cursor = nir_instr_remove(&deref->instr);
nir_ssa_def *loc =
nir_imm_intN_t(&b, deref->var->data.driver_location,
- deref->dest.ssa.bit_size);
+ deref->dest.ssa.bit_size);
nir_ssa_def_rewrite_uses(&deref->dest.ssa, loc);
progress = true;
break;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* SOFTWARE.
*/
-
#include "nir.h"
#include "nir_builder.h"
{
return nir_shader_instructions_pass(shader, lower_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
shader);
}
* and only once).
*/
-
static nir_variable *
create_clipdist_var(nir_shader *shader,
bool output, gl_varying_slot slot, unsigned array_size)
if (b->shader->options->use_interpolated_input_intrinsics) {
/* TODO: use sample when per-sample shading? */
nir_ssa_def *barycentric = nir_load_barycentric(
- b, nir_intrinsic_load_barycentric_pixel, INTERP_MODE_NONE);
+ b, nir_intrinsic_load_barycentric_pixel, INTERP_MODE_NONE);
load = nir_load_interpolated_input(
- b, 4, 32, barycentric, nir_imm_int(b, location_offset),
- .base = in->data.driver_location,
- .dest_type = nir_type_float32,
- .io_semantics = semantics);
+ b, 4, 32, barycentric, nir_imm_int(b, location_offset),
+ .base = in->data.driver_location,
+ .dest_type = nir_type_float32,
+ .io_semantics = semantics);
} else {
load = nir_load_input(b, 4, 32, nir_imm_int(b, location_offset),
return nir_load_user_clip_plane(b, plane);
}
-
static void
lower_clip_outputs(nir_builder *b, nir_variable *position,
nir_variable *clipvertex, nir_variable **out,
static bool
fs_has_clip_dist_input_var(nir_shader *shader, nir_variable **io_vars,
- unsigned *ucp_enables)
+ unsigned *ucp_enables)
{
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
nir_foreach_shader_in_variable(var, shader) {
nir_lower_clip_fs(nir_shader *shader, unsigned ucp_enables,
bool use_clipdist_array)
{
- nir_variable *in[2] = {0};
+ nir_variable *in[2] = { 0 };
if (!ucp_enables)
return false;
if (progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_loop_analysis);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
- *
+ *
* Authors:
* Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
*/
#include "nir.h"
#include "nir_builder.h"
-
/**
* This pass uses the enabled clip planes from the rasterizer state to rewrite
* vertex shader store operations and store a 0 to the corresponding gl_ClipDistance[n]
out = nir_deref_instr_get_variable(deref);
if ((out->data.location != VARYING_SLOT_CLIP_DIST0 &&
out->data.location != VARYING_SLOT_CLIP_DIST1) ||
- out->data.mode != nir_var_shader_out)
+ out->data.mode != nir_var_shader_out)
return false;
b->cursor = nir_after_instr(&instr->instr);
components[i] = nir_ssa_undef(b, 1, 32);
}
nir_store_deref(b, deref, nir_vec(b, components, instr->num_components), wrmask);
- } else if (nir_src_is_const(deref->arr.index)) {
+ } else if (nir_src_is_const(deref->arr.index)) {
/* storing using a constant index */
plane = nir_src_as_uint(deref->arr.index);
/* no need to make changes if the clip plane is enabled */
return nir_shader_instructions_pass(shader, lower_clip_plane_store,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&clip_plane_enable);
}
nir_shader_instructions_pass(shader, lower_pos_write,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
assert(*p);
nir_constant *ret = top_level_init;
- for ( ; *p; p++) {
+ for (; *p; p++) {
if ((*p)->deref_type == nir_deref_type_array) {
assert(nir_src_is_const((*p)->arr.index));
*/
nir_instr *src_instr = const_src->ssa->parent_instr;
assert(src_instr->type == nir_instr_type_load_const);
- nir_load_const_instr* load = nir_instr_as_load_const(src_instr);
+ nir_load_const_instr *load = nir_instr_as_load_const(src_instr);
for (unsigned i = 0; i < load->def.num_components; i++) {
if (!(writemask & (1 << i)))
struct var_info *var_infos = ralloc_array(NULL, struct var_info, num_locals);
nir_foreach_function_temp_variable(var, impl) {
- var_infos[var->index] = (struct var_info) {
+ var_infos[var->index] = (struct var_info){
.var = var,
.is_constant = true,
.found_read = false,
b.cursor = nir_before_instr(instr);
- nir_variable *uni = (nir_variable *) entry->data;
+ nir_variable *uni = (nir_variable *)entry->data;
nir_deref_instr *new_deref_instr = nir_build_deref_var(&b, uni);
nir_deref_path path;
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
ralloc_free(var_infos);
_mesa_hash_table_destroy(const_array_vars, NULL);
*
*/
-
#include "nir.h"
#include "nir_builder.h"
#include "nir_control_flow.h"
unsigned num_continue = 0;
nir_block *single_predecessor = NULL;
set_foreach(cont->predecessors, entry) {
- nir_block *pred = (nir_block*) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
/* If the continue block has no predecessors, it is unreachable. */
if (pred->predecessors->entries == 0)
continue;
return true;
}
-
static bool
visit_cf_list(nir_builder *b, struct exec_list *list, bool *repair_ssa)
{
return progress;
}
-
if (lowered_instr) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-#include "nir.h"
#include "compiler/nir/nir_builder.h"
+#include "nir.h"
static bool
lower_discard_if_instr(nir_builder *b, nir_instr *instr_, void *cb_data)
return nir_is_helper_invocation(b, 1);
}
-
static bool
nir_lower_load_helper_to_is_helper(nir_builder *b, nir_instr *instr, void *data)
{
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
- nir_ssa_def *is_helper = *(nir_ssa_def**) data;
+ nir_ssa_def *is_helper = *(nir_ssa_def **)data;
switch (intrin->intrinsic) {
case nir_intrinsic_demote:
case nir_intrinsic_demote_if:
/* insert is_helper at last top level occasion */
if (is_helper == NULL) {
is_helper = insert_is_helper(b, instr);
- *(nir_ssa_def**)data = is_helper;
+ *(nir_ssa_def **)data = is_helper;
return true;
} else {
return false;
progress = nir_shader_instructions_pass(shader,
nir_lower_discard_to_demote_instr,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_instr_index,
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_instr_index,
NULL);
shader->info.fs.uses_demote = true;
} else if (!shader->info.fs.needs_quad_helper_invocations &&
progress = nir_shader_instructions_pass(shader,
nir_lower_demote_to_discard_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
shader->info.fs.uses_demote = false;
} else if (shader->info.fs.uses_demote &&
progress = nir_shader_instructions_pass(shader,
nir_lower_load_helper_to_is_helper,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&is_helper);
BITSET_CLEAR(shader->info.system_values_read,
nir_system_value_from_intrinsic(nir_intrinsic_load_helper_invocation));
#include "nir.h"
#include "nir_builder.h"
-#include <math.h>
#include <float.h>
+#include <math.h>
/*
* Lowers some unsupported double operations, using only:
* denorms properly. Note that this doesn't preserve positive/negative
* zeros, but GLSL doesn't require it.
*/
- res = nir_bcsel(b, nir_ior(b, nir_ile_imm(b, exp, 0),
- nir_feq_imm(b, nir_fabs(b, src), INFINITY)),
+ res = nir_bcsel(b, nir_ior(b, nir_ile_imm(b, exp, 0), nir_feq_imm(b, nir_fabs(b, src), INFINITY)),
nir_imm_double(b, 0.0f), res);
/* If the original input was 0, generate the correctly-signed infinity */
res, get_signed_inf(b, src));
return res;
-
}
static nir_ssa_def *
nir_imm_double(b, 0.0),
src);
}
- res = nir_bcsel(b, nir_ior(b, nir_feq_imm(b, src_flushed, 0.0),
- nir_feq_imm(b, src, INFINITY)),
- src_flushed, res);
+ res = nir_bcsel(b, nir_ior(b, nir_feq_imm(b, src_flushed, 0.0), nir_feq_imm(b, src, INFINITY)),
+ src_flushed, res);
} else {
res = fix_inv_result(b, res, src, new_exp);
}
nir_ssa_def *src_lo = nir_unpack_64_2x32_split_x(b, src);
nir_ssa_def *src_hi = nir_unpack_64_2x32_split_y(b, src);
- return
- nir_bcsel(b,
- nir_ilt_imm(b, unbiased_exp, 0),
- nir_imm_double(b, 0.0),
- nir_bcsel(b, nir_ige_imm(b, unbiased_exp, 53),
- src,
- nir_pack_64_2x32_split(b,
- nir_iand(b, mask_lo, src_lo),
- nir_iand(b, mask_hi, src_hi))));
+ return nir_bcsel(b,
+ nir_ilt_imm(b, unbiased_exp, 0),
+ nir_imm_double(b, 0.0),
+ nir_bcsel(b, nir_ige_imm(b, unbiased_exp, 53),
+ src,
+ nir_pack_64_2x32_split(b,
+ nir_iand(b, mask_lo, src_lo),
+ nir_iand(b, mask_hi, src_hi))));
}
static nir_ssa_def *
return nir_bcsel(b, nir_flt(b, nir_fabs(b, src), two52),
nir_pack_64_2x32_split(b, nir_unpack_64_2x32_split_x(b, res),
- nir_ior(b, nir_unpack_64_2x32_split_y(b, res), sign)), src);
+ nir_ior(b, nir_unpack_64_2x32_split_y(b, res), sign)),
+ src);
}
static nir_ssa_def *
if (instr->src[0].src.ssa->bit_size == 64) {
name = "__int64_to_fp64";
mangled_name = "__int64_to_fp64(i641;";
- }
- else {
+ } else {
name = "__int_to_fp64";
mangled_name = "__int_to_fp64(i1;";
}
if (instr->src[0].src.ssa->bit_size == 64) {
name = "__uint64_to_fp64";
mangled_name = "__uint64_to_fp64(u641;";
- }
- else {
+ } else {
name = "__uint_to_fp64";
mangled_name = "__uint_to_fp64(u1;";
}
assert(func);
}
- nir_ssa_def *params[4] = { NULL, };
+ nir_ssa_def *params[4] = {
+ NULL,
+ };
nir_variable *ret_tmp =
nir_local_variable_create(b->impl, return_type, "return_tmp");
nir_lower_doubles_op_to_options_mask(nir_op opcode)
{
switch (opcode) {
- case nir_op_frcp: return nir_lower_drcp;
- case nir_op_fsqrt: return nir_lower_dsqrt;
- case nir_op_frsq: return nir_lower_drsq;
- case nir_op_ftrunc: return nir_lower_dtrunc;
- case nir_op_ffloor: return nir_lower_dfloor;
- case nir_op_fceil: return nir_lower_dceil;
- case nir_op_ffract: return nir_lower_dfract;
- case nir_op_fround_even: return nir_lower_dround_even;
- case nir_op_fmod: return nir_lower_dmod;
- case nir_op_fsub: return nir_lower_dsub;
- case nir_op_fdiv: return nir_lower_ddiv;
- default: return 0;
+ case nir_op_frcp:
+ return nir_lower_drcp;
+ case nir_op_fsqrt:
+ return nir_lower_dsqrt;
+ case nir_op_frsq:
+ return nir_lower_drsq;
+ case nir_op_ftrunc:
+ return nir_lower_dtrunc;
+ case nir_op_ffloor:
+ return nir_lower_dfloor;
+ case nir_op_fceil:
+ return nir_lower_dceil;
+ case nir_op_ffract:
+ return nir_lower_dfract;
+ case nir_op_fround_even:
+ return nir_lower_dround_even;
+ case nir_op_fmod:
+ return nir_lower_dmod;
+ case nir_op_fsub:
+ return nir_lower_dsub;
+ case nir_op_fdiv:
+ return nir_lower_ddiv;
+ default:
+ return 0;
}
}
nir_opt_deref_impl(impl);
} else if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
typedef struct {
const nir_lower_drawpixels_options *options;
- nir_shader *shader;
+ nir_shader *shader;
nir_variable *texcoord, *texcoord_const, *scale, *bias, *tex, *pixelmap;
} lower_drawpixels_state;
nir_shader_instructions_pass(shader, lower_drawpixels_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
return nir_shader_instructions_pass(shader, nir_lower_fb_read_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
* SOFTWARE.
*/
-
#include "nir.h"
#include "nir_builder.h"
* IN THE SOFTWARE.
*/
#include <math.h>
+#include "util/u_vector.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/u_vector.h"
/**
* Lower flrp instructions.
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
/**
return nir_iadd(b, value, nir_iand(b, guard, nir_ior(b, sticky, value)));
case nir_rounding_mode_ru:
sign = nir_ushr_imm(b, sign, 31);
- return nir_iadd(b, value, nir_iand(b, nir_inot(b, sign),
- nir_ior(b, guard, sticky)));
+ return nir_iadd(b, value, nir_iand(b, nir_inot(b, sign), nir_ior(b, guard, sticky)));
case nir_rounding_mode_rd:
sign = nir_ushr_imm(b, sign, 31);
- return nir_iadd(b, value, nir_iand(b, sign,
- nir_ior(b, guard, sticky)));
+ return nir_iadd(b, value, nir_iand(b, sign, nir_ior(b, guard, sticky)));
default:
return value;
}
/* NaN or INF. For rtne, overflow also becomes INF, so combine the comparisons */
nir_push_if(b, nir_ige(b, abs, mode == nir_rounding_mode_rtne ? f16max : f32infinity));
nir_ssa_def *inf_nanfp16 = nir_bcsel(b,
- nir_ilt(b, f32infinity, abs),
- nir_imm_int(b, 0x7E00),
- nir_imm_int(b, 0x7C00));
+ nir_ilt(b, f32infinity, abs),
+ nir_imm_int(b, 0x7E00),
+ nir_imm_int(b, 0x7C00));
nir_push_else(b, NULL);
nir_ssa_def *overflowed_fp16 = NULL;
/* Negative becomes inf, positive becomes max float */
overflowed_fp16 = nir_bcsel(b, nir_i2b(b, sign), nir_imm_int(b, 0x7C00), nir_imm_int(b, 0x7BFF));
break;
- default: unreachable("Should've been handled already");
+ default:
+ unreachable("Should've been handled already");
}
nir_push_else(b, NULL);
}
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
- *
+ *
* Authors:
* Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
*/
nir_ssa_def *frag_color = instr->src[1].ssa;
ralloc_free(out->name);
- const char *name = out->data.index == 0 ? "gl_FragData[0]" :
- "gl_SecondaryFragDataEXT[0]";
- const char *name_tmpl = out->data.index == 0 ? "gl_FragData[%u]" :
- "gl_SecondaryFragDataEXT[%u]";
+ const char *name = out->data.index == 0 ? "gl_FragData[0]" : "gl_SecondaryFragDataEXT[0]";
+ const char *name_tmpl = out->data.index == 0 ? "gl_FragData[%u]" : "gl_SecondaryFragDataEXT[%u]";
out->name = ralloc_strdup(out, name);
char name[28];
snprintf(name, sizeof(name), name_tmpl, i);
nir_variable *out_color = nir_variable_create(b->shader, nir_var_shader_out,
- out->type, name);
+ out->type, name);
out_color->data.location = FRAG_RESULT_DATA0 + i;
out_color->data.driver_location = b->shader->num_outputs++;
out_color->data.index = out->data.index;
return false;
return nir_shader_instructions_pass(shader, lower_fragcolor_instr,
- nir_metadata_block_index | nir_metadata_dominance, &max_draw_buffers);
+ nir_metadata_block_index | nir_metadata_dominance, &max_draw_buffers);
}
lower_fragcoord_wtrans_filter,
lower_fragcoord_wtrans_impl,
NULL);
-
}
* exponent must be a 32-bit integer.
*/
exponent = nir_i2i32(b, nir_iadd(b, nir_ushr(b, abs_x, exponent_shift),
- nir_bcsel(b, is_not_zero, exponent_bias, zero)));
+ nir_bcsel(b, is_not_zero, exponent_bias, zero)));
break;
}
case 32: {
nir_ssa_def *exponent_bias = nir_imm_int(b, -126);
exponent = nir_iadd(b, nir_ushr(b, abs_x, exponent_shift),
- nir_bcsel(b, is_not_zero, exponent_bias, zero));
+ nir_bcsel(b, is_not_zero, exponent_bias, zero));
break;
}
case 64: {
nir_ssa_def *abs_upper_x = nir_unpack_64_2x32_split_y(b, abs_x);
exponent = nir_iadd(b, nir_ushr(b, abs_upper_x, exponent_shift),
- nir_bcsel(b, is_not_zero, exponent_bias, zero32));
+ nir_bcsel(b, is_not_zero, exponent_bias, zero32));
break;
}
default:
{
return nir_shader_instructions_pass(shader, lower_frexp_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
struct hash_table *var_func_table)
{
nir_foreach_instr(instr, block) {
- if (instr->type == nir_instr_type_deref) {
+ if (instr->type == nir_instr_type_deref) {
nir_deref_instr *deref = nir_instr_as_deref(instr);
if (deref->deref_type == nir_deref_type_var)
register_var_use(deref->var, impl, var_func_table);
var->data.mode = nir_var_function_temp;
exec_list_push_tail(&impl->locals, &var->node);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
progress = true;
}
}
}
fork = fork->paths[i].fork;
break;
- }
- else {
+ } else {
nir_ssa_def *ssa_def = condition.ssa;
assert(ssa_def->bit_size == 1);
assert(ssa_def->num_components == 1);
{
if (_mesa_set_search(routing->regular.reachable, target)) {
set_path_vars(b, routing->regular.fork, target);
- }
- else if (_mesa_set_search(routing->brk.reachable, target)) {
+ } else if (_mesa_set_search(routing->brk.reachable, target)) {
set_path_vars(b, routing->brk.fork, target);
nir_jump(b, nir_jump_break);
- }
- else if (_mesa_set_search(routing->cont.reachable, target)) {
+ } else if (_mesa_set_search(routing->cont.reachable, target)) {
set_path_vars(b, routing->cont.fork, target);
nir_jump(b, nir_jump_continue);
- }
- else {
- assert(!target->successors[0]); /* target is endblock */
+ } else {
+ assert(!target->successors[0]); /* target is endblock */
nir_jump(b, nir_jump_return);
}
}
nir_ssa_def *ret;
if (fork->is_var) {
ret = nir_load_var(b, fork->path_var);
- }
- else
+ } else
ret = fork->path_ssa;
return ret;
}
assert(routing->cont.reachable == routing->regular.reachable);
nir_pop_loop(b, NULL);
if (routing->brk.fork && routing->brk.fork->paths[1].reachable ==
- routing_backup->cont.reachable) {
+ routing_backup->cont.reachable) {
assert(!(routing->brk.fork->is_var &&
strcmp(routing->brk.fork->path_var->name, "path_continue")));
nir_push_if_src(b, nir_src_for_ssa(
- fork_condition(b, routing->brk.fork)));
+ fork_condition(b, routing->brk.fork)));
nir_jump(b, nir_jump_continue);
nir_pop_if(b, NULL);
routing->brk = routing->brk.fork->paths[0];
}
if (routing->brk.fork && routing->brk.fork->paths[1].reachable ==
- routing_backup->brk.reachable) {
+ routing_backup->brk.reachable) {
assert(!(routing->brk.fork->is_var &&
strcmp(routing->brk.fork->path_var->name, "path_break")));
nir_push_if_src(b, nir_src_for_ssa(
- fork_condition(b, routing->brk.fork)));
+ fork_condition(b, routing->brk.fork)));
nir_jump(b, nir_jump_break);
nir_pop_if(b, NULL);
routing->brk = routing->brk.fork->paths[0];
_mesa_set_add(remaining, block->dom_children[i]);
}
-
if (NIR_LOWER_GOTO_IFS_DEBUG) {
printf("inside_outside(%u):\n", block->index);
printf(" loop_heads = ");
while (remaining->entries && progress) {
progress = false;
set_foreach(remaining, child_entry) {
- nir_block *dom_child = (nir_block *) child_entry->key;
+ nir_block *dom_child = (nir_block *)child_entry->key;
bool can_jump_back = false;
set_foreach(dom_child->dom_frontier, entry) {
if (entry->key == dom_child)
/* Recurse for each remaining */
set_foreach(remaining, entry) {
- inside_outside((nir_block *) entry->key, loop_heads, outside, reach,
+ inside_outside((nir_block *)entry->key, loop_heads, outside, reach,
brk_reachable, mem_ctx);
}
struct set *brk_reachable, void *mem_ctx)
{
nir_block *candidate = (nir_block *)
- _mesa_set_next_entry(remaining, NULL)->key;
+ _mesa_set_next_entry(remaining, NULL)
+ ->key;
struct set *old_candidates = _mesa_pointer_set_create(mem_ctx);
while (candidate) {
_mesa_set_add(old_candidates, candidate);
candidate = NULL;
set_foreach(remaining, entry) {
- nir_block *remaining_block = (nir_block *) entry->key;
+ nir_block *remaining_block = (nir_block *)entry->key;
if (!_mesa_set_search(curr_level->blocks, remaining_block) &&
_mesa_set_intersects(remaining_block->dom_frontier,
curr_level->blocks)) {
curr_level->reach = _mesa_pointer_set_create(curr_level);
set_foreach(curr_level->blocks, entry) {
_mesa_set_remove_key(remaining, entry->key);
- inside_outside((nir_block *) entry->key, loop_heads, remaining,
+ inside_outside((nir_block *)entry->key, loop_heads, remaining,
curr_level->reach, brk_reachable, mem_ctx);
}
_mesa_set_destroy(loop_heads, NULL);
while (remaining->entries) {
_mesa_set_clear(remaining_frontier, NULL);
set_foreach(remaining, entry) {
- nir_block *remain_block = (nir_block *) entry->key;
+ nir_block *remain_block = (nir_block *)entry->key;
set_foreach(remain_block->dom_frontier, frontier_entry) {
- nir_block *frontier = (nir_block *) frontier_entry->key;
+ nir_block *frontier = (nir_block *)frontier_entry->key;
if (frontier != remain_block) {
_mesa_set_add(remaining_frontier, frontier);
}
struct strct_lvl *curr_level = rzalloc(mem_ctx, struct strct_lvl);
curr_level->blocks = _mesa_pointer_set_create(curr_level);
set_foreach(remaining, entry) {
- nir_block *candidate = (nir_block *) entry->key;
+ nir_block *candidate = (nir_block *)entry->key;
if (!_mesa_set_search(remaining_frontier, candidate)) {
_mesa_set_add(curr_level->blocks, candidate);
_mesa_set_remove_key(remaining, candidate);
}
set_foreach(curr_level->blocks, blocks_entry) {
- nir_block *level_block = (nir_block *) blocks_entry->key;
+ nir_block *level_block = (nir_block *)blocks_entry->key;
if (prev_frontier == NULL) {
prev_frontier =
_mesa_set_clone(level_block->dom_frontier, curr_level);
if (level->skip_start) {
assert(routing->regular.fork);
assert(!(routing->regular.fork->is_var && strcmp(
- routing->regular.fork->path_var->name, "path_conditional")));
+ routing->regular.fork->path_var->name, "path_conditional")));
nir_push_if_src(b, nir_src_for_ssa(
- fork_condition(b, routing->regular.fork)));
+ fork_condition(b, routing->regular.fork)));
routing->regular = routing->regular.fork->paths[1];
}
struct path in_path = routing->regular;
nir_cf_list cf_list;
nir_cf_extract(&cf_list, nir_before_cf_list(&impl->body),
- nir_after_cf_list(&impl->body));
+ nir_after_cf_list(&impl->body));
/* From this point on, it's structured */
impl->structured = true;
nir_block *start_block = nir_cf_node_as_block(start_node);
struct routes *routing = rzalloc(mem_ctx, struct routes);
- *routing = (struct routes) {
+ *routing = (struct routes){
.regular.reachable = end_set,
.brk.reachable = empty_set,
.cont.reachable = empty_set,
* but before any jump instructions (return).
*/
set_foreach(end_block->predecessors, entry) {
- nir_block *pred = (nir_block *) entry->key;
+ nir_block *pred = (nir_block *)entry->key;
b->cursor = nir_after_block_before_jump(pred);
for (unsigned stream = 0; stream < NIR_MAX_XFB_STREAMS; ++stream) {
/* Inactive stream: vertex count is 0, primitive count is 0 or undef. */
vtx_cnt = nir_imm_int(b, 0);
prim_cnt = state->count_prims || state->is_points
- ? nir_imm_int(b, 0)
- : nir_ssa_undef(b, 1, 32);
+ ? nir_imm_int(b, 0)
+ : nir_ssa_undef(b, 1, 32);
} else {
if (state->overwrite_incomplete)
overwrite_incomplete_primitives(state, stream);
a_block_needs_set_vertex_and_primitive_count(nir_block *end_block, bool per_stream)
{
set_foreach(end_block->predecessors, entry) {
- nir_block *pred = (nir_block *) entry->key;
-
+ nir_block *pred = (nir_block *)entry->key;
for (unsigned stream = 0; stream < NIR_MAX_XFB_STREAMS; ++stream) {
/* When it's not per-stream, we only need to write one variable. */
static nir_ssa_def *
convert_instr_small(nir_builder *b, nir_op op,
- nir_ssa_def *numer, nir_ssa_def *denom,
- const nir_lower_idiv_options *options)
+ nir_ssa_def *numer, nir_ssa_def *denom,
+ const nir_lower_idiv_options *options)
{
unsigned sz = numer->bit_size;
nir_alu_type int_type = nir_op_infos[op].output_type | sz;
if (op == nir_op_imod) {
nir_ssa_def *zero = nir_imm_zero(b, 1, sz);
nir_ssa_def *diff_sign =
- nir_ine(b, nir_ige(b, numer, zero), nir_ige(b, denom, zero));
+ nir_ine(b, nir_ige(b, numer, zero), nir_ige(b, denom, zero));
nir_ssa_def *adjust = nir_iand(b, diff_sign, nir_ine(b, res, zero));
res = nir_iadd(b, res, nir_bcsel(b, adjust, denom, zero));
nir_lower_idiv(nir_shader *shader, const nir_lower_idiv_options *options)
{
return nir_shader_lower_instructions(shader,
- inst_is_idiv,
- lower_idiv,
- (void *)options);
+ inst_is_idiv,
+ lower_idiv,
+ (void *)options);
}
{
return nir_shader_instructions_pass(nir, lower_image_instr,
nir_metadata_block_index |
- nir_metadata_dominance, (void*)options);
+ nir_metadata_dominance,
+ (void *)options);
}
nir_intrinsic_op address_op;
bool swap;
-#define CASE(storage) \
- case nir_intrinsic_##storage##_atomic: \
- case nir_intrinsic_##storage##_atomic_swap: \
- address_op = nir_intrinsic_##storage##_texel_address; \
- swap = intr->intrinsic == nir_intrinsic_##storage##_atomic_swap; \
+#define CASE(storage) \
+ case nir_intrinsic_##storage##_atomic: \
+ case nir_intrinsic_##storage##_atomic_swap: \
+ address_op = nir_intrinsic_##storage##_texel_address; \
+ swap = intr->intrinsic == nir_intrinsic_##storage##_atomic_swap; \
break;
switch (intr->intrinsic) {
{
return nir_shader_instructions_pass(shader, lower,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
nir_ssa_def *unscaled_frag_coord = nir_load_frag_coord_unscaled_ir3(b);
if (deref->deref_type == nir_deref_type_array) {
nir_ssa_def *unscaled =
- nir_i2b(b, nir_iand(b, nir_ishr(b,
- nir_imm_int(b, options->unscaled_input_attachment_ir3 >> base),
- deref->arr.index.ssa),
- nir_imm_int(b, 1)));
+ nir_i2b(b, nir_iand(b, nir_ishr(b, nir_imm_int(b, options->unscaled_input_attachment_ir3 >> base), deref->arr.index.ssa),
+ nir_imm_int(b, 1)));
frag_coord = nir_bcsel(b, unscaled, unscaled_frag_coord, frag_coord);
} else {
assert(deref->deref_type == nir_deref_type_var);
return nir_load_layer_id(b);
}
- gl_varying_slot slot = options->use_view_id_for_layer ?
- VARYING_SLOT_VIEW_INDEX : VARYING_SLOT_LAYER;
+ gl_varying_slot slot = options->use_view_id_for_layer ? VARYING_SLOT_VIEW_INDEX : VARYING_SLOT_LAYER;
nir_variable *layer_id = nir_get_variable_with_location(b->shader, nir_var_shader_in,
slot, glsl_int_type());
layer_id->data.interpolation = INTERP_MODE_FLAT;
nir_ssa_def *layer = load_layer_id(b, options);
nir_ssa_def *coord = nir_vec3(b, nir_channel(b, frag_coord, 0),
- nir_channel(b, frag_coord, 1), layer);
+ nir_channel(b, frag_coord, 1), layer);
tex->coord_components = 3;
return nir_shader_instructions_pass(shader, lower_input_attachments_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
(void *)options);
}
#include "nir.h"
#include "nir_builder.h"
-#define COND_LOWER_OP(b, name, ...) \
- (b->shader->options->lower_int64_options & \
- nir_lower_int64_op_to_options_mask(nir_op_##name)) ? \
- lower_##name##64(b, __VA_ARGS__) : nir_##name(b, __VA_ARGS__)
-
-#define COND_LOWER_CMP(b, name, ...) \
- (b->shader->options->lower_int64_options & \
- nir_lower_int64_op_to_options_mask(nir_op_##name)) ? \
- lower_int64_compare(b, nir_op_##name, __VA_ARGS__) : \
- nir_##name(b, __VA_ARGS__)
-
-#define COND_LOWER_CAST(b, name, ...) \
- (b->shader->options->lower_int64_options & \
- nir_lower_int64_op_to_options_mask(nir_op_##name)) ? \
- lower_##name(b, __VA_ARGS__) : \
- nir_##name(b, __VA_ARGS__)
+#define COND_LOWER_OP(b, name, ...) \
+ (b->shader->options->lower_int64_options & \
+ nir_lower_int64_op_to_options_mask(nir_op_##name)) \
+ ? lower_##name##64(b, __VA_ARGS__) \
+ : nir_##name(b, __VA_ARGS__)
+
+#define COND_LOWER_CMP(b, name, ...) \
+ (b->shader->options->lower_int64_options & \
+ nir_lower_int64_op_to_options_mask(nir_op_##name)) \
+ ? lower_int64_compare(b, nir_op_##name, __VA_ARGS__) \
+ : nir_##name(b, __VA_ARGS__)
+
+#define COND_LOWER_CAST(b, name, ...) \
+ (b->shader->options->lower_int64_options & \
+ nir_lower_int64_op_to_options_mask(nir_op_##name)) \
+ ? lower_##name(b, __VA_ARGS__) \
+ : nir_##name(b, __VA_ARGS__)
static nir_ssa_def *
lower_b2i64(nir_builder *b, nir_ssa_def *x)
return nir_i2i16(b, nir_unpack_64_2x32_split_x(b, x));
}
-
static nir_ssa_def *
lower_i2i32(nir_builder *b, nir_ssa_def *x)
{
nir_ssa_def *y_hi = nir_unpack_64_2x32_split_y(b, y);
return nir_pack_64_2x32_split(b, nir_bcsel(b, cond, x_lo, y_lo),
- nir_bcsel(b, cond, x_hi, y_hi));
+ nir_bcsel(b, cond, x_hi, y_hi));
}
static nir_ssa_def *
nir_ssa_def *y_hi = nir_unpack_64_2x32_split_y(b, y);
return nir_pack_64_2x32_split(b, nir_iand(b, x_lo, y_lo),
- nir_iand(b, x_hi, y_hi));
+ nir_iand(b, x_hi, y_hi));
}
static nir_ssa_def *
nir_ssa_def *y_hi = nir_unpack_64_2x32_split_y(b, y);
return nir_pack_64_2x32_split(b, nir_ior(b, x_lo, y_lo),
- nir_ior(b, x_hi, y_hi));
+ nir_ior(b, x_hi, y_hi));
}
static nir_ssa_def *
nir_ssa_def *y_hi = nir_unpack_64_2x32_split_y(b, y);
return nir_pack_64_2x32_split(b, nir_ixor(b, x_lo, y_lo),
- nir_ixor(b, x_hi, y_hi));
+ nir_ixor(b, x_hi, y_hi));
}
static nir_ssa_def *
nir_ssa_def *res_if_lt_32 =
nir_pack_64_2x32_split(b, lo_shifted,
- nir_ior(b, hi_shifted, lo_shifted_hi));
+ nir_ior(b, hi_shifted, lo_shifted_hi));
nir_ssa_def *res_if_ge_32 =
nir_pack_64_2x32_split(b, nir_imm_int(b, 0),
- nir_ishl(b, x_lo, reverse_count));
+ nir_ishl(b, x_lo, reverse_count));
return nir_bcsel(b, nir_ieq_imm(b, y, 0), x,
nir_bcsel(b, nir_uge_imm(b, y, 32),
- res_if_ge_32, res_if_lt_32));
+ res_if_ge_32, res_if_lt_32));
}
static nir_ssa_def *
nir_ssa_def *res_if_lt_32 =
nir_pack_64_2x32_split(b, nir_ior(b, lo_shifted, hi_shifted_lo),
- hi_shifted);
+ hi_shifted);
nir_ssa_def *res_if_ge_32 =
nir_pack_64_2x32_split(b, nir_ishr(b, x_hi, reverse_count),
- nir_ishr_imm(b, x_hi, 31));
+ nir_ishr_imm(b, x_hi, 31));
return nir_bcsel(b, nir_ieq_imm(b, y, 0), x,
nir_bcsel(b, nir_uge_imm(b, y, 32),
- res_if_ge_32, res_if_lt_32));
+ res_if_ge_32, res_if_lt_32));
}
static nir_ssa_def *
nir_ssa_def *res_if_lt_32 =
nir_pack_64_2x32_split(b, nir_ior(b, lo_shifted, hi_shifted_lo),
- hi_shifted);
+ hi_shifted);
nir_ssa_def *res_if_ge_32 =
nir_pack_64_2x32_split(b, nir_ushr(b, x_hi, reverse_count),
- nir_imm_int(b, 0));
+ nir_imm_int(b, 0));
return nir_bcsel(b, nir_ieq_imm(b, y, 0), x,
nir_bcsel(b, nir_uge_imm(b, y, 32),
- res_if_ge_32, res_if_lt_32));
+ res_if_ge_32, res_if_lt_32));
}
static nir_ssa_def *
return nir_ior(b, nir_ine(b, x_hi, y_hi), nir_ine(b, x_lo, y_lo));
case nir_op_ult:
return nir_ior(b, nir_ult(b, x_hi, y_hi),
- nir_iand(b, nir_ieq(b, x_hi, y_hi),
- nir_ult(b, x_lo, y_lo)));
+ nir_iand(b, nir_ieq(b, x_hi, y_hi),
+ nir_ult(b, x_lo, y_lo)));
case nir_op_ilt:
return nir_ior(b, nir_ilt(b, x_hi, y_hi),
- nir_iand(b, nir_ieq(b, x_hi, y_hi),
- nir_ult(b, x_lo, y_lo)));
+ nir_iand(b, nir_ieq(b, x_hi, y_hi),
+ nir_ult(b, x_lo, y_lo)));
break;
case nir_op_uge:
/* Lower as !(x < y) in the hopes of better CSE */
nir_ssa_def *mul_lo = nir_umul_2x32_64(b, x_lo, y_lo);
nir_ssa_def *res_hi = nir_iadd(b, nir_unpack_64_2x32_split_y(b, mul_lo),
- nir_iadd(b, nir_imul(b, x_lo, y_hi),
- nir_imul(b, x_hi, y_lo)));
+ nir_iadd(b, nir_imul(b, x_lo, y_hi),
+ nir_imul(b, x_hi, y_lo)));
return nir_pack_64_2x32_split(b, nir_unpack_64_2x32_split_x(b, mul_lo),
res_hi);
y32[2] = y32[3] = nir_imm_int(b, 0);
}
- nir_ssa_def *res[8] = { NULL, };
+ nir_ssa_def *res[8] = {
+ NULL,
+ };
/* Yes, the following generates a pile of code. However, we throw res[0]
* and res[1] away in the end and, if we're in the umul case, four of our
nir_ssa_def *new_n_hi = nir_isub(b, n_hi, d_shift);
nir_ssa_def *new_q_hi = nir_ior_imm(b, q_hi, 1ull << i);
nir_ssa_def *cond = nir_iand(b, need_high_div,
- nir_uge(b, n_hi, d_shift));
+ nir_uge(b, n_hi, d_shift));
if (i != 0) {
/* log2_d_lo is always <= 31, so we don't need to bother with it
* in the last iteration.
*/
cond = nir_iand(b, cond,
- nir_ile_imm(b, log2_d_lo, 31 - i));
+ nir_ile_imm(b, log2_d_lo, 31 - i));
}
n_hi = nir_bcsel(b, cond, new_n_hi, n_hi);
q_hi = nir_bcsel(b, cond, new_q_hi, q_hi);
* in the last iteration.
*/
cond = nir_iand(b, cond,
- nir_ile_imm(b, log2_denom, 31 - i));
+ nir_ile_imm(b, log2_denom, 31 - i));
}
n = nir_bcsel(b, cond, new_n, n);
q_lo = nir_bcsel(b, cond, new_q_lo, q_lo);
nir_ssa_def *d_hi = nir_unpack_64_2x32_split_y(b, d);
nir_ssa_def *negate = nir_ine(b, nir_ilt_imm(b, n_hi, 0),
- nir_ilt_imm(b, d_hi, 0));
+ nir_ilt_imm(b, d_hi, 0));
nir_ssa_def *q, *r;
lower_udiv64_mod64(b, nir_iabs(b, n), nir_iabs(b, d), &q, &r);
return nir_bcsel(b, negate, nir_ineg(b, q), q);
nir_ssa_def *rem = nir_bcsel(b, n_is_neg, nir_ineg(b, r), r);
return nir_bcsel(b, nir_ieq_imm(b, r, 0), nir_imm_int64(b, 0),
- nir_bcsel(b, nir_ieq(b, n_is_neg, d_is_neg), rem,
- nir_iadd(b, rem, d)));
+ nir_bcsel(b, nir_ieq(b, n_is_neg, d_is_neg), rem,
+ nir_iadd(b, rem, d)));
}
static nir_ssa_def *
nir_ssa_def *extract32;
if (chunk < num_chunks_in_32) {
extract32 = nir_build_alu(b, op, nir_unpack_64_2x32_split_x(b, x),
- nir_imm_int(b, chunk),
- NULL, NULL);
+ nir_imm_int(b, chunk),
+ NULL, NULL);
} else {
extract32 = nir_build_alu(b, op, nir_unpack_64_2x32_split_y(b, x),
- nir_imm_int(b, chunk - num_chunks_in_32),
- NULL, NULL);
+ nir_imm_int(b, chunk - num_chunks_in_32),
+ NULL, NULL);
}
if (op == nir_op_extract_i8 || op == nir_op_extract_i16)
nir_ssa_def *discard =
nir_imax(b, nir_iadd_imm(b, exp, -significand_bits),
- nir_imm_int(b, 0));
+ nir_imm_int(b, 0));
nir_ssa_def *significand = COND_LOWER_OP(b, ushr, x, discard);
if (significand_bits < 32)
significand = COND_LOWER_CAST(b, u2u32, significand);
nir_ssa_def *halfway = nir_iand(b, COND_LOWER_CMP(b, ieq, rem, half),
nir_ine_imm(b, discard, 0));
nir_ssa_def *is_odd = COND_LOWER_CMP(b, ine, nir_imm_int64(b, 0),
- COND_LOWER_OP(b, iand, x, lsb_mask));
+ COND_LOWER_OP(b, iand, x, lsb_mask));
nir_ssa_def *round_up = nir_ior(b, COND_LOWER_CMP(b, ilt, half, rem),
nir_iand(b, halfway, is_odd));
if (significand_bits >= 32)
lower_vote_ieq(nir_builder *b, nir_ssa_def *x)
{
return nir_iand(b, build_vote_ieq(b, nir_unpack_64_2x32_split_x(b, x)),
- build_vote_ieq(b, nir_unpack_64_2x32_split_y(b, x)));
+ build_vote_ieq(b, nir_unpack_64_2x32_split_y(b, x)));
}
static nir_ssa_def *
lower_scan_iadd64(nir_builder *b, const nir_intrinsic_instr *intrin)
{
unsigned cluster_size =
- intrin->intrinsic == nir_intrinsic_reduce ?
- nir_intrinsic_cluster_size(intrin) : 0;
+ intrin->intrinsic == nir_intrinsic_reduce ? nir_intrinsic_cluster_size(intrin) : 0;
/* Split it into three chunks of no more than 24 bits each. With 8 bits
* of headroom, we're guaranteed that there will never be overflow in the
nir_u2u32(b, nir_iand_imm(b, x, 0xffffff));
nir_ssa_def *x_mid =
nir_u2u32(b, nir_iand_imm(b, nir_ushr_imm(b, x, 24),
- 0xffffff));
+ 0xffffff));
nir_ssa_def *x_hi =
nir_u2u32(b, nir_ushr_imm(b, x, 48));
nir_ssa_def *scan_low =
build_scan_intrinsic(b, intrin->intrinsic, nir_op_iadd,
- cluster_size, x_low);
+ cluster_size, x_low);
nir_ssa_def *scan_mid =
build_scan_intrinsic(b, intrin->intrinsic, nir_op_iadd,
- cluster_size, x_mid);
+ cluster_size, x_mid);
nir_ssa_def *scan_hi =
build_scan_intrinsic(b, intrin->intrinsic, nir_op_iadd,
- cluster_size, x_hi);
+ cluster_size, x_hi);
scan_low = nir_u2u64(b, scan_low);
scan_mid = nir_ishl_imm(b, nir_u2u64(b, scan_mid), 24);
/* These we expect to have integers but the opcode doesn't change */
break;
- case nir_op_b2i32: alu->op = nir_op_b2f32; break;
- case nir_op_i2f32: alu->op = nir_op_mov; break;
- case nir_op_u2f32: alu->op = nir_op_mov; break;
+ case nir_op_b2i32:
+ alu->op = nir_op_b2f32;
+ break;
+ case nir_op_i2f32:
+ alu->op = nir_op_mov;
+ break;
+ case nir_op_u2f32:
+ alu->op = nir_op_mov;
+ break;
case nir_op_f2i32: {
alu->op = nir_op_ftrunc;
break;
}
- case nir_op_f2u32: alu->op = nir_op_ffloor; break;
+ case nir_op_f2u32:
+ alu->op = nir_op_ffloor;
+ break;
- case nir_op_ilt: alu->op = nir_op_flt; break;
- case nir_op_ige: alu->op = nir_op_fge; break;
- case nir_op_ieq: alu->op = nir_op_feq; break;
- case nir_op_ine: alu->op = nir_op_fneu; break;
- case nir_op_ult: alu->op = nir_op_flt; break;
- case nir_op_uge: alu->op = nir_op_fge; break;
+ case nir_op_ilt:
+ alu->op = nir_op_flt;
+ break;
+ case nir_op_ige:
+ alu->op = nir_op_fge;
+ break;
+ case nir_op_ieq:
+ alu->op = nir_op_feq;
+ break;
+ case nir_op_ine:
+ alu->op = nir_op_fneu;
+ break;
+ case nir_op_ult:
+ alu->op = nir_op_flt;
+ break;
+ case nir_op_uge:
+ alu->op = nir_op_fge;
+ break;
- case nir_op_iadd: alu->op = nir_op_fadd; break;
- case nir_op_isub: alu->op = nir_op_fsub; break;
- case nir_op_imul: alu->op = nir_op_fmul; break;
+ case nir_op_iadd:
+ alu->op = nir_op_fadd;
+ break;
+ case nir_op_isub:
+ alu->op = nir_op_fsub;
+ break;
+ case nir_op_imul:
+ alu->op = nir_op_fmul;
+ break;
case nir_op_idiv: {
nir_ssa_def *x = nir_ssa_for_alu_src(b, alu, 0);
break;
}
- case nir_op_iabs: alu->op = nir_op_fabs; break;
- case nir_op_ineg: alu->op = nir_op_fneg; break;
- case nir_op_imax: alu->op = nir_op_fmax; break;
- case nir_op_imin: alu->op = nir_op_fmin; break;
- case nir_op_umax: alu->op = nir_op_fmax; break;
- case nir_op_umin: alu->op = nir_op_fmin; break;
+ case nir_op_iabs:
+ alu->op = nir_op_fabs;
+ break;
+ case nir_op_ineg:
+ alu->op = nir_op_fneg;
+ break;
+ case nir_op_imax:
+ alu->op = nir_op_fmax;
+ break;
+ case nir_op_imin:
+ alu->op = nir_op_fmin;
+ break;
+ case nir_op_umax:
+ alu->op = nir_op_fmax;
+ break;
+ case nir_op_umin:
+ alu->op = nir_op_fmin;
+ break;
- case nir_op_ball_iequal2: alu->op = nir_op_ball_fequal2; break;
- case nir_op_ball_iequal3: alu->op = nir_op_ball_fequal3; break;
- case nir_op_ball_iequal4: alu->op = nir_op_ball_fequal4; break;
- case nir_op_bany_inequal2: alu->op = nir_op_bany_fnequal2; break;
- case nir_op_bany_inequal3: alu->op = nir_op_bany_fnequal3; break;
- case nir_op_bany_inequal4: alu->op = nir_op_bany_fnequal4; break;
+ case nir_op_ball_iequal2:
+ alu->op = nir_op_ball_fequal2;
+ break;
+ case nir_op_ball_iequal3:
+ alu->op = nir_op_ball_fequal3;
+ break;
+ case nir_op_ball_iequal4:
+ alu->op = nir_op_ball_fequal4;
+ break;
+ case nir_op_bany_inequal2:
+ alu->op = nir_op_bany_fnequal2;
+ break;
+ case nir_op_bany_inequal3:
+ alu->op = nir_op_bany_fnequal3;
+ break;
+ case nir_op_bany_inequal4:
+ alu->op = nir_op_bany_fnequal4;
+ break;
- case nir_op_i32csel_gt: alu->op = nir_op_fcsel_gt; break;
- case nir_op_i32csel_ge: alu->op = nir_op_fcsel_ge; break;
+ case nir_op_i32csel_gt:
+ alu->op = nir_op_fcsel_gt;
+ break;
+ case nir_op_i32csel_ge:
+ alu->op = nir_op_fcsel_ge;
+ break;
default:
assert(nir_alu_type_get_base_type(info->output_type) != nir_type_int &&
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_lower_interpolation_instr(nir_builder *b, nir_instr *instr, void *cb_data)
{
nir_lower_interpolation_options options =
- *(nir_lower_interpolation_options *)cb_data;
+ *(nir_lower_interpolation_options *)cb_data;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_ssa_def *val;
val = nir_ffma(b, nir_channel(b, bary, 1),
- nir_channel(b, iid, 1),
- nir_channel(b, iid, 0));
+ nir_channel(b, iid, 1),
+ nir_channel(b, iid, 0));
val = nir_ffma(b, nir_channel(b, bary, 0),
- nir_channel(b, iid, 2),
- val);
+ nir_channel(b, iid, 2),
+ val);
comps[i] = val;
}
{
return nir_shader_instructions_pass(shader, nir_lower_interpolation_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&options);
}
ssbo_atomic_for_deref(nir_intrinsic_op deref_op)
{
switch (deref_op) {
- case nir_intrinsic_deref_atomic: return nir_intrinsic_ssbo_atomic;
- case nir_intrinsic_deref_atomic_swap: return nir_intrinsic_ssbo_atomic_swap;
+ case nir_intrinsic_deref_atomic:
+ return nir_intrinsic_ssbo_atomic;
+ case nir_intrinsic_deref_atomic_swap:
+ return nir_intrinsic_ssbo_atomic_swap;
default:
unreachable("Invalid SSBO atomic");
}
shared_atomic_for_deref(nir_intrinsic_op deref_op)
{
switch (deref_op) {
- case nir_intrinsic_deref_atomic: return nir_intrinsic_shared_atomic;
- case nir_intrinsic_deref_atomic_swap: return nir_intrinsic_shared_atomic_swap;
+ case nir_intrinsic_deref_atomic:
+ return nir_intrinsic_shared_atomic;
+ case nir_intrinsic_deref_atomic_swap:
+ return nir_intrinsic_shared_atomic_swap;
default:
unreachable("Invalid shared atomic");
}
return false;
}
-static unsigned get_number_of_slots(struct lower_io_state *state,
- const nir_variable *var)
+static unsigned
+get_number_of_slots(struct lower_io_state *state,
+ const nir_variable *var)
{
const struct glsl_type *type = var->type;
op = nir_intrinsic_load_interpolated_input;
}
} else {
- op = array_index ? nir_intrinsic_load_per_vertex_input :
- nir_intrinsic_load_input;
+ op = array_index ? nir_intrinsic_load_per_vertex_input : nir_intrinsic_load_input;
}
break;
case nir_var_shader_out:
- op = !array_index ? nir_intrinsic_load_output :
- var->data.per_primitive ? nir_intrinsic_load_per_primitive_output :
- nir_intrinsic_load_per_vertex_output;
+ op = !array_index ? nir_intrinsic_load_output : var->data.per_primitive ? nir_intrinsic_load_per_primitive_output
+ : nir_intrinsic_load_per_vertex_output;
break;
case nir_var_uniform:
op = nir_intrinsic_load_uniform;
nir_intrinsic_set_dest_type(load, dest_type);
if (load->intrinsic != nir_intrinsic_load_uniform) {
- nir_io_semantics semantics = {0};
+ nir_io_semantics semantics = { 0 };
semantics.location = var->data.location;
semantics.num_slots = get_number_of_slots(state, var);
semantics.fb_fetch_output = var->data.fb_fetch_output;
assert(var->data.mode == nir_var_shader_out);
nir_intrinsic_op op =
- !array_index ? nir_intrinsic_store_output :
- var->data.per_primitive ? nir_intrinsic_store_per_primitive_output :
- nir_intrinsic_store_per_vertex_output;
+ !array_index ? nir_intrinsic_store_output : var->data.per_primitive ? nir_intrinsic_store_per_primitive_output
+ : nir_intrinsic_store_per_vertex_output;
nir_intrinsic_instr *store =
nir_intrinsic_instr_create(state->builder.shader, op);
}
}
- nir_io_semantics semantics = {0};
+ nir_io_semantics semantics = { 0 };
semantics.location = var->data.location;
semantics.num_slots = get_number_of_slots(state, var);
semantics.dual_source_blend_index = var->data.index;
nir_builder_instr_insert(b, &bary_setup->instr);
- nir_io_semantics semantics = {0};
+ nir_io_semantics semantics = { 0 };
semantics.location = var->data.location;
semantics.num_slots = get_number_of_slots(state, var);
semantics.medium_precision =
var->data.mode == nir_var_shader_out ||
var->data.bindless;
- if (nir_deref_instr_is_known_out_of_bounds(deref)) {
- /* Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:
- *
- * In the subsections described above for array, vector, matrix and
- * structure accesses, any out-of-bounds access produced undefined
- * behavior....
- * Out-of-bounds reads return undefined values, which
- * include values from other variables of the active program or zero.
- * Out-of-bounds writes may be discarded or overwrite
- * other variables of the active program.
- *
- * GL_KHR_robustness and GL_ARB_robustness encourage us to return zero
- * for reads.
- *
- * Otherwise get_io_offset would return out-of-bound offset which may
- * result in out-of-bound loading/storing of inputs/outputs,
- * that could cause issues in drivers down the line.
- */
+ if (nir_deref_instr_is_known_out_of_bounds(deref)) {
+ /* Section 5.11 (Out-of-Bounds Accesses) of the GLSL 4.60 spec says:
+ *
+ * In the subsections described above for array, vector, matrix and
+ * structure accesses, any out-of-bounds access produced undefined
+ * behavior....
+ * Out-of-bounds reads return undefined values, which
+ * include values from other variables of the active program or zero.
+ * Out-of-bounds writes may be discarded or overwrite
+ * other variables of the active program.
+ *
+ * GL_KHR_robustness and GL_ARB_robustness encourage us to return zero
+ * for reads.
+ *
+ * Otherwise get_io_offset would return out-of-bound offset which may
+ * result in out-of-bound loading/storing of inputs/outputs,
+ * that could cause issues in drivers down the line.
+ */
if (intrin->intrinsic != nir_intrinsic_store_deref) {
nir_ssa_def *zero =
nir_imm_zero(b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size);
+ intrin->dest.ssa.bit_size);
nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
- zero);
+ zero);
}
nir_instr_remove(&intrin->instr);
case nir_var_mem_global:
return nir_iadd_imm(b, nir_load_global_base_ptr(b, num_comps, bit_size),
- var->data.driver_location);
+ var->data.driver_location);
default:
unreachable("Unsupported variable mode");
case nir_var_mem_global:
return nir_ior(b, nir_ieq_imm(b, mode_enum, 0x0),
- nir_ieq_imm(b, mode_enum, 0x3));
+ nir_ieq_imm(b, mode_enum, 0x3));
default:
unreachable("Invalid mode check intrinsic");
nir_address_format_bit_size(nir_address_format addr_format)
{
switch (addr_format) {
- case nir_address_format_32bit_global: return 32;
- case nir_address_format_2x32bit_global: return 32;
- case nir_address_format_64bit_global: return 64;
- case nir_address_format_64bit_global_32bit_offset: return 32;
- case nir_address_format_64bit_bounded_global: return 32;
- case nir_address_format_32bit_index_offset: return 32;
- case nir_address_format_32bit_index_offset_pack64: return 64;
- case nir_address_format_vec2_index_32bit_offset: return 32;
- case nir_address_format_62bit_generic: return 64;
- case nir_address_format_32bit_offset: return 32;
- case nir_address_format_32bit_offset_as_64bit: return 64;
- case nir_address_format_logical: return 32;
+ case nir_address_format_32bit_global:
+ return 32;
+ case nir_address_format_2x32bit_global:
+ return 32;
+ case nir_address_format_64bit_global:
+ return 64;
+ case nir_address_format_64bit_global_32bit_offset:
+ return 32;
+ case nir_address_format_64bit_bounded_global:
+ return 32;
+ case nir_address_format_32bit_index_offset:
+ return 32;
+ case nir_address_format_32bit_index_offset_pack64:
+ return 64;
+ case nir_address_format_vec2_index_32bit_offset:
+ return 32;
+ case nir_address_format_62bit_generic:
+ return 64;
+ case nir_address_format_32bit_offset:
+ return 32;
+ case nir_address_format_32bit_offset_as_64bit:
+ return 64;
+ case nir_address_format_logical:
+ return 32;
}
unreachable("Invalid address format");
}
nir_address_format_num_components(nir_address_format addr_format)
{
switch (addr_format) {
- case nir_address_format_32bit_global: return 1;
- case nir_address_format_2x32bit_global: return 2;
- case nir_address_format_64bit_global: return 1;
- case nir_address_format_64bit_global_32bit_offset: return 4;
- case nir_address_format_64bit_bounded_global: return 4;
- case nir_address_format_32bit_index_offset: return 2;
- case nir_address_format_32bit_index_offset_pack64: return 1;
- case nir_address_format_vec2_index_32bit_offset: return 3;
- case nir_address_format_62bit_generic: return 1;
- case nir_address_format_32bit_offset: return 1;
- case nir_address_format_32bit_offset_as_64bit: return 1;
- case nir_address_format_logical: return 1;
+ case nir_address_format_32bit_global:
+ return 1;
+ case nir_address_format_2x32bit_global:
+ return 2;
+ case nir_address_format_64bit_global:
+ return 1;
+ case nir_address_format_64bit_global_32bit_offset:
+ return 4;
+ case nir_address_format_64bit_bounded_global:
+ return 4;
+ case nir_address_format_32bit_index_offset:
+ return 2;
+ case nir_address_format_32bit_index_offset_pack64:
+ return 1;
+ case nir_address_format_vec2_index_32bit_offset:
+ return 3;
+ case nir_address_format_62bit_generic:
+ return 1;
+ case nir_address_format_32bit_offset:
+ return 1;
+ case nir_address_format_32bit_offset_as_64bit:
+ return 1;
+ case nir_address_format_logical:
+ return 1;
}
unreachable("Invalid address format");
}
case nir_address_format_vec2_index_32bit_offset:
assert(addr->num_components == 3);
return nir_trim_vector(b, addr, 2);
- default: unreachable("Invalid address format");
+ default:
+ unreachable("Invalid address format");
}
}
case nir_address_format_64bit_bounded_global:
assert(addr->num_components == 4);
return nir_iadd(b, nir_pack_64_2x32(b, nir_trim_vector(b, addr, 2)),
- nir_u2u64(b, nir_channel(b, addr, 3)));
+ nir_u2u64(b, nir_channel(b, addr, 3)));
case nir_address_format_32bit_index_offset:
case nir_address_format_32bit_index_offset_pack64:
assert(addr->num_components == 4);
assert(size > 0);
return nir_ult(b, nir_iadd_imm(b, nir_channel(b, addr, 3), size - 1),
- nir_channel(b, addr, 2));
+ nir_channel(b, addr, 2));
}
static void
nir_pop_if(b, NULL);
return nir_if_phi(b, &atomic->dest.ssa,
- nir_ssa_undef(b, 1, atomic->dest.ssa.bit_size));
+ nir_ssa_undef(b, 1, atomic->dest.ssa.bit_size));
} else {
nir_builder_instr_insert(b, &atomic->instr);
return &atomic->dest.ssa;
case nir_intrinsic_load_deref: {
nir_ssa_def *value;
if (vec_stride > scalar_size) {
- nir_ssa_def *comps[NIR_MAX_VEC_COMPONENTS] = { NULL, };
+ nir_ssa_def *comps[NIR_MAX_VEC_COMPONENTS] = {
+ NULL,
+ };
for (unsigned i = 0; i < intrin->num_components; i++) {
unsigned comp_offset = i * vec_stride;
nir_ssa_def *comp_addr = nir_build_addr_iadd_imm(b, addr, addr_format,
offset = addr_to_offset(b, addr, addr_format);
nir_ssa_def *index = addr_to_index(b, addr, addr_format);
unsigned access = nir_intrinsic_access(intrin);
- size = nir_get_ssbo_size(b, index, .access=access);
+ size = nir_get_ssbo_size(b, index, .access = access);
break;
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_loop_analysis);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_address_format_null_value(nir_address_format addr_format)
{
const static nir_const_value null_values[][NIR_MAX_VEC_COMPONENTS] = {
- [nir_address_format_32bit_global] = {{0}},
- [nir_address_format_2x32bit_global] = {{0}},
- [nir_address_format_64bit_global] = {{0}},
- [nir_address_format_64bit_global_32bit_offset] = {{0}},
- [nir_address_format_64bit_bounded_global] = {{0}},
- [nir_address_format_32bit_index_offset] = {{.u32 = ~0}, {.u32 = ~0}},
- [nir_address_format_32bit_index_offset_pack64] = {{.u64 = ~0ull}},
- [nir_address_format_vec2_index_32bit_offset] = {{.u32 = ~0}, {.u32 = ~0}, {.u32 = ~0}},
- [nir_address_format_32bit_offset] = {{.u32 = ~0}},
- [nir_address_format_32bit_offset_as_64bit] = {{.u64 = ~0ull}},
- [nir_address_format_62bit_generic] = {{.u64 = 0}},
- [nir_address_format_logical] = {{.u32 = ~0}},
+ [nir_address_format_32bit_global] = { { 0 } },
+ [nir_address_format_2x32bit_global] = { { 0 } },
+ [nir_address_format_64bit_global] = { { 0 } },
+ [nir_address_format_64bit_global_32bit_offset] = { { 0 } },
+ [nir_address_format_64bit_bounded_global] = { { 0 } },
+ [nir_address_format_32bit_index_offset] = { { .u32 = ~0 }, { .u32 = ~0 } },
+ [nir_address_format_32bit_index_offset_pack64] = { { .u64 = ~0ull } },
+ [nir_address_format_vec2_index_32bit_offset] = { { .u32 = ~0 }, { .u32 = ~0 }, { .u32 = ~0 } },
+ [nir_address_format_32bit_offset] = { { .u32 = ~0 } },
+ [nir_address_format_32bit_offset_as_64bit] = { { .u64 = ~0ull } },
+ [nir_address_format_62bit_generic] = { { .u64 = 0 } },
+ [nir_address_format_logical] = { { .u32 = ~0 } },
};
assert(addr_format < ARRAY_SIZE(null_values));
case nir_address_format_64bit_global_32bit_offset:
return nir_ball_iequal(b, nir_channels(b, addr0, 0xb),
- nir_channels(b, addr1, 0xb));
+ nir_channels(b, addr1, 0xb));
case nir_address_format_32bit_offset_as_64bit:
assert(addr0->num_components == 1 && addr1->num_components == 1);
case nir_address_format_2x32bit_global:
return nir_isub(b, addr_to_global(b, addr0, addr_format),
- addr_to_global(b, addr1, addr_format));
+ addr_to_global(b, addr1, addr_format));
case nir_address_format_32bit_offset_as_64bit:
assert(addr0->num_components == 1);
case nir_address_format_64bit_global_32bit_offset:
case nir_address_format_64bit_bounded_global:
return nir_isub(b, addr_to_global(b, addr0, addr_format),
- addr_to_global(b, addr1, addr_format));
+ addr_to_global(b, addr1, addr_format));
case nir_address_format_32bit_index_offset:
assert(addr0->num_components == 2);
intrin->intrinsic == nir_intrinsic_store_per_primitive_output;
}
-static bool is_dual_slot(nir_intrinsic_instr *intrin)
+static bool
+is_dual_slot(nir_intrinsic_instr *intrin)
{
if (intrin->intrinsic == nir_intrinsic_store_output ||
intrin->intrinsic == nir_intrinsic_store_per_vertex_output ||
nir_builder b = nir_builder_create(impl);
- nir_foreach_block (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_intrinsic)
continue;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
for (unsigned i = 0; i < NIR_MAX_XFB_BUFFERS; i++)
nir->info.xfb_stride[i] = nir->xfb_info->buffers[i].stride / 4;
- nir_foreach_block (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_intrinsic)
continue;
continue;
nir_io_semantics sem = nir_intrinsic_io_semantics(intr);
- unsigned writemask = nir_intrinsic_write_mask(intr) <<
- nir_intrinsic_component(intr);
+ unsigned writemask = nir_intrinsic_write_mask(intr) << nir_intrinsic_component(intr);
nir_io_xfb xfb[2];
memset(xfb, 0, sizeof(xfb));
*/
NIR_PASS_V(nir, nir_recompute_io_bases,
(nir->info.stage != MESA_SHADER_VERTEX ||
- renumber_vs_inputs ? nir_var_shader_in : 0) |
- nir_var_shader_out);
+ renumber_vs_inputs
+ ? nir_var_shader_in
+ : 0) |
+ nir_var_shader_out);
/* nir_io_add_const_offset_to_base needs actual constants. */
NIR_PASS_V(nir, nir_opt_constant_folding);
- NIR_PASS_V(nir, nir_io_add_const_offset_to_base, nir_var_shader_in |
- nir_var_shader_out);
+ NIR_PASS_V(nir, nir_io_add_const_offset_to_base, nir_var_shader_in | nir_var_shader_out);
/* Lower and remove dead derefs and variables to clean up the IR. */
NIR_PASS_V(nir, nir_lower_vars_to_ssa);
*xfb_offset += index * glsl_get_component_slots((*p)->type) * 4;
- unsigned num_elements = glsl_type_is_array((*p)->type) ?
- glsl_get_aoa_size((*p)->type) : 1;
+ unsigned num_elements = glsl_type_is_array((*p)->type) ? glsl_get_aoa_size((*p)->type) : 1;
- num_elements *= glsl_type_is_matrix(glsl_without_array((*p)->type)) ?
- glsl_get_matrix_columns(glsl_without_array((*p)->type)) : 1;
+ num_elements *= glsl_type_is_matrix(glsl_without_array((*p)->type)) ? glsl_get_matrix_columns(glsl_without_array((*p)->type)) : 1;
*element_index += num_elements * index;
} else if ((*p)->deref_type == nir_deref_type_struct) {
type = glsl_get_array_element(type);
}
- unsigned num_elements = glsl_type_is_array(type) ?
- glsl_get_aoa_size(type) : 1;
+ unsigned num_elements = glsl_type_is_array(type) ? glsl_get_aoa_size(type) : 1;
- num_elements *= glsl_type_is_matrix(glsl_without_array(type)) ?
- glsl_get_matrix_columns(glsl_without_array(type)) : 1;
+ num_elements *= glsl_type_is_matrix(glsl_without_array(type)) ? glsl_get_matrix_columns(glsl_without_array(type)) : 1;
- elements = (nir_variable **) calloc(num_elements, sizeof(nir_variable *));
+ elements = (nir_variable **)calloc(num_elements, sizeof(nir_variable *));
_mesa_hash_table_insert(ht, var, elements);
} else {
- elements = (nir_variable **) entry->data;
+ elements = (nir_variable **)entry->data;
}
return elements;
nir_variable *element = elements[elements_index];
if (!element) {
- element = nir_variable_clone(var, b->shader);
- element->data.location = var->data.location + io_offset;
+ element = nir_variable_clone(var, b->shader);
+ element->data.location = var->data.location + io_offset;
- if (var->data.explicit_offset)
- element->data.offset = var->data.offset + xfb_offset;
+ if (var->data.explicit_offset)
+ element->data.offset = var->data.offset + xfb_offset;
- const struct glsl_type *type = glsl_without_array(element->type);
+ const struct glsl_type *type = glsl_without_array(element->type);
- /* This pass also splits matrices so we need give them a new type. */
- if (glsl_type_is_matrix(type))
- type = glsl_get_column_type(type);
+ /* This pass also splits matrices so we need give them a new type. */
+ if (glsl_type_is_matrix(type))
+ type = glsl_get_column_type(type);
- if (nir_is_arrayed_io(var, b->shader->info.stage)) {
- type = glsl_array_type(type, glsl_get_length(element->type),
- glsl_get_explicit_stride(element->type));
- }
+ if (nir_is_arrayed_io(var, b->shader->info.stage)) {
+ type = glsl_array_type(type, glsl_get_length(element->type),
+ glsl_get_explicit_stride(element->type));
+ }
- element->type = type;
- elements[elements_index] = element;
+ element->type = type;
+ elements[elements_index] = element;
- nir_shader_add_variable(b->shader, element);
+ nir_shader_add_variable(b->shader, element);
}
nir_deref_instr *element_deref = nir_build_deref_var(b, element);
nir_deref_path_finish(&path);
}
}
-}
+ }
}
static void
*
* TODO: Add support for struct splitting.
*/
- if ((!glsl_type_is_array(type) && !glsl_type_is_matrix(type))||
+ if ((!glsl_type_is_array(type) && !glsl_type_is_matrix(type)) ||
glsl_type_is_struct_or_ifc(glsl_without_array(type)))
continue;
struct hash_table *split_inputs = _mesa_pointer_hash_table_create(NULL);
struct hash_table *split_outputs = _mesa_pointer_hash_table_create(NULL);
- BITSET_DECLARE(indirects, 4 * VARYING_SLOT_TESS_MAX) = {0};
+ BITSET_DECLARE(indirects, 4 * VARYING_SLOT_TESS_MAX) = { 0 };
lower_io_arrays_to_elements(shader, nir_var_shader_out,
indirects, split_outputs, true);
/* Remove old input from the shaders inputs list */
hash_table_foreach(split_inputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
/* Remove old output from the shaders outputs list */
hash_table_foreach(split_outputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
struct hash_table *split_inputs = _mesa_pointer_hash_table_create(NULL);
struct hash_table *split_outputs = _mesa_pointer_hash_table_create(NULL);
- BITSET_DECLARE(indirects, 4 * VARYING_SLOT_TESS_MAX) = {0};
+ BITSET_DECLARE(indirects, 4 * VARYING_SLOT_TESS_MAX) = { 0 };
create_indirects_mask(producer, indirects, nir_var_shader_out);
create_indirects_mask(consumer, indirects, nir_var_shader_in);
/* Remove old input from the shaders inputs list */
hash_table_foreach(split_inputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
/* Remove old output from the shaders outputs list */
hash_table_foreach(split_outputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
nir_intrinsic_set_align_offset(chan_intr,
(nir_intrinsic_align_offset(intr) +
- i * (intr->dest.ssa.bit_size / 8)) % nir_intrinsic_align_mul(intr));
+ i * (intr->dest.ssa.bit_size / 8)) %
+ nir_intrinsic_align_mul(intr));
nir_intrinsic_set_align_mul(chan_intr, nir_intrinsic_align_mul(intr));
if (nir_intrinsic_has_access(intr))
nir_intrinsic_set_access(chan_intr, nir_intrinsic_access(intr));
unsigned component = nir_intrinsic_component(chan_intr);
for (unsigned c = 0; c <= component; c++) {
- nir_io_xfb xfb = c < 2 ? nir_intrinsic_io_xfb(intr) :
- nir_intrinsic_io_xfb2(intr);
+ nir_io_xfb xfb = c < 2 ? nir_intrinsic_io_xfb(intr) : nir_intrinsic_io_xfb2(intr);
if (component < c + xfb.out[c % 2].num_components) {
nir_io_xfb scalar_xfb;
memset(&scalar_xfb, 0, sizeof(scalar_xfb));
- scalar_xfb.out[component % 2].num_components = is_64bit ? 2 : 1;
+ scalar_xfb.out[component % 2].num_components = is_64bit ? 2 : 1;
scalar_xfb.out[component % 2].buffer = xfb.out[c % 2].buffer;
scalar_xfb.out[component % 2].offset = xfb.out[c % 2].offset +
component - c;
nir_intrinsic_set_write_mask(chan_intr, 0x1);
nir_intrinsic_set_align_offset(chan_intr,
(nir_intrinsic_align_offset(intr) +
- i * (value->bit_size / 8)) % nir_intrinsic_align_mul(intr));
+ i * (value->bit_size / 8)) %
+ nir_intrinsic_align_mul(intr));
nir_intrinsic_set_align_mul(chan_intr, nir_intrinsic_align_mul(intr));
if (nir_intrinsic_has_access(intr))
nir_intrinsic_set_access(chan_intr, nir_intrinsic_access(intr));
if ((intr->intrinsic == nir_intrinsic_load_output ||
intr->intrinsic == nir_intrinsic_load_per_vertex_output) &&
- (state->mask & nir_var_shader_out) &&
- (!state->filter || state->filter(instr, state->filter_data))) {
+ (state->mask & nir_var_shader_out) &&
+ (!state->filter || state->filter(instr, state->filter_data))) {
lower_load_input_to_scalar(b, intr);
return true;
}
return nir_shader_instructions_pass(shader,
nir_lower_io_to_scalar_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
nir_variable **chan_vars;
struct hash_entry *entry = _mesa_hash_table_search(ht, var);
if (!entry) {
- chan_vars = (nir_variable **) calloc(4, sizeof(nir_variable *));
+ chan_vars = (nir_variable **)calloc(4, sizeof(nir_variable *));
_mesa_hash_table_insert(ht, var, chan_vars);
} else {
- chan_vars = (nir_variable **) entry->data;
+ chan_vars = (nir_variable **)entry->data;
}
return chan_vars;
nir_variable *chan_var = chan_vars[var->data.location_frac + i];
if (!chan_vars[var->data.location_frac + i]) {
chan_var = nir_variable_clone(var, b->shader);
- chan_var->data.location_frac = var->data.location_frac + i;
+ chan_var->data.location_frac = var->data.location_frac + i;
chan_var->type = glsl_channel_type(chan_var->type);
chan_vars[var->data.location_frac + i] = chan_var;
nir_variable *chan_var = chan_vars[var->data.location_frac + i];
if (!chan_vars[var->data.location_frac + i]) {
chan_var = nir_variable_clone(var, b->shader);
- chan_var->data.location_frac = var->data.location_frac + i;
+ chan_var->data.location_frac = var->data.location_frac + i;
chan_var->type = glsl_channel_type(chan_var->type);
chan_vars[var->data.location_frac + i] = chan_var;
bool progress = nir_shader_instructions_pass(shader,
nir_lower_io_to_scalar_early_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
/* Remove old input from the shaders inputs list */
hash_table_foreach(state.split_inputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
/* Remove old output from the shaders outputs list */
hash_table_foreach(state.split_outputs, entry) {
- nir_variable *var = (nir_variable *) entry->key;
+ nir_variable *var = (nir_variable *)entry->key;
exec_node_remove(&var->node);
free(entry->data);
continue;
nir_intrinsic_instr *interp = nir_instr_as_intrinsic(instr);
-
+
if (interp->intrinsic == nir_intrinsic_interp_deref_at_centroid ||
interp->intrinsic == nir_intrinsic_interp_deref_at_sample ||
interp->intrinsic == nir_intrinsic_interp_deref_at_offset ||
emit_output_copies_impl(&state, impl);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
exec_list_append(&shader->variables, &state.old_inputs);
* IN THE SOFTWARE.
*/
+#include "util/u_dynarray.h"
#include "nir.h"
#include "nir_builder.h"
#include "nir_deref.h"
-#include "util/u_dynarray.h"
/** @file nir_lower_io_to_vector.c
*
/* FRAG_RESULT_MAX+1 instead of just FRAG_RESULT_MAX because of how this pass
* handles dual source blending */
-#define MAX_SLOTS MAX2(VARYING_SLOT_TESS_MAX, FRAG_RESULT_MAX+1)
+#define MAX_SLOTS MAX2(VARYING_SLOT_TESS_MAX, FRAG_RESULT_MAX + 1)
static unsigned
get_slot(const nir_variable *var)
bool flat_vars[MAX_SLOTS],
struct util_dynarray *demote_vars)
{
- nir_variable *old_vars[MAX_SLOTS][4] = {{0}};
+ nir_variable *old_vars[MAX_SLOTS][4] = { { 0 } };
bool has_io_var = false;
nir_foreach_variable_with_modes(var, shader, mode) {
return base;
case nir_deref_type_array: {
nir_ssa_def *index = nir_i2iN(b, deref->arr.index.ssa,
- deref->dest.ssa.bit_size);
+ deref->dest.ssa.bit_size);
if (nir_deref_instr_parent(deref)->deref_type == nir_deref_type_var &&
per_vertex)
bool vs_in = shader->info.stage == MESA_SHADER_VERTEX &&
new_var->data.mode == nir_var_shader_in;
return nir_build_deref_array(b, deref,
- build_array_index(b, leader, nir_imm_int(b, base), vs_in, per_vertex));
+ build_array_index(b, leader, nir_imm_int(b, base), vs_in, per_vertex));
}
ASSERTED static bool
util_dynarray_init(&demote_vars, NULL);
nir_shader *shader = impl->function->shader;
- nir_variable *new_inputs[MAX_SLOTS][4] = {{0}};
- nir_variable *new_outputs[MAX_SLOTS][4] = {{0}};
- bool flat_inputs[MAX_SLOTS] = {0};
- bool flat_outputs[MAX_SLOTS] = {0};
+ nir_variable *new_inputs[MAX_SLOTS][4] = { { 0 } };
+ nir_variable *new_outputs[MAX_SLOTS][4] = { { 0 } };
+ bool flat_inputs[MAX_SLOTS] = { 0 };
+ bool flat_outputs[MAX_SLOTS] = { 0 };
if (modes & nir_var_shader_in) {
/* Vertex shaders support overlapping inputs. We don't do those */
const unsigned loc = get_slot(old_var);
const unsigned old_frac = old_var->data.location_frac;
- nir_variable *new_var = old_var->data.mode == nir_var_shader_in ?
- new_inputs[loc][old_frac] :
- new_outputs[loc][old_frac];
- bool flat = old_var->data.mode == nir_var_shader_in ?
- flat_inputs[loc] : flat_outputs[loc];
+ nir_variable *new_var = old_var->data.mode == nir_var_shader_in ? new_inputs[loc][old_frac] : new_outputs[loc][old_frac];
+ bool flat = old_var->data.mode == nir_var_shader_in ? flat_inputs[loc] : flat_outputs[loc];
if (!new_var)
break;
if (new_frac + c >= old_frac &&
(old_wrmask & 1 << (new_frac + c - old_frac))) {
comps[c] = nir_get_ssa_scalar(old_value,
- new_frac + c - old_frac);
+ new_frac + c - old_frac);
} else {
comps[c] = nir_get_ssa_scalar(nir_ssa_undef(&b, old_value->num_components,
- old_value->bit_size), 0);
+ old_value->bit_size),
+ 0);
}
}
nir_ssa_def *new_value = nir_vec_scalars(&b, comps, intrin->num_components);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
return progress;
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
- nir_deref_instr *is_helper_deref = (nir_deref_instr*) data;
+ nir_deref_instr *is_helper_deref = (nir_deref_instr *)data;
switch (intrin->intrinsic) {
case nir_intrinsic_demote: {
nir_builder b = nir_builder_at(nir_before_cf_list(&entrypoint->body));
nir_variable *is_helper = nir_local_variable_create(entrypoint,
- glsl_bool_type(),
- "gl_IsHelperInvocationEXT");
+ glsl_bool_type(),
+ "gl_IsHelperInvocationEXT");
- nir_ssa_def *started_as_helper = shader->options->lower_helper_invocation ?
- nir_build_lowered_load_helper_invocation(&b) :
- nir_load_helper_invocation(&b, 1);
+ nir_ssa_def *started_as_helper = shader->options->lower_helper_invocation ? nir_build_lowered_load_helper_invocation(&b) : nir_load_helper_invocation(&b, 1);
nir_deref_instr *is_helper_deref = nir_build_deref_var(&b, is_helper);
nir_store_deref(&b, is_helper_deref, started_as_helper, 1);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* handle this case we just convert it to a direct reference.
*/
if (nir_intrinsic_num_array_elems(decl) == 0)
- return (struct reg_location){.reg = reg};
+ return (struct reg_location){ .reg = reg };
nir_ssa_def *indirect = NULL;
unsigned base_offset = 0;
.write_mask = write_mask);
} else {
nir_build_store_reg(b, val, loc.reg, .base = loc.base_offset,
- .write_mask = write_mask);
+ .write_mask = write_mask);
}
nir_instr_remove(&intrin->instr);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
_mesa_hash_table_destroy(state.regs_table, NULL);
BITSET_ZERO(outputs);
/* Gather the bitmasks of used locations. */
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_variable_mode mode;
nir_intrinsic_instr *intr = get_io_intrinsic(instr, modes, &mode);
if (!intr)
/* Renumber bases. */
bool changed = false;
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_variable_mode mode;
nir_intrinsic_instr *intr = get_io_intrinsic(instr, modes, &mode);
if (!intr)
if (changed) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_builder b = nir_builder_create(impl);
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_variable_mode mode;
nir_intrinsic_instr *intr = get_io_intrinsic(instr, modes, &mode);
if (!intr)
mode == nir_var_shader_out);
if (is_varying && sem.location <= VARYING_SLOT_VAR31 &&
- !(varying_mask & BITFIELD64_BIT(sem.location))) {
+ !(varying_mask & BITFIELD64_BIT(sem.location))) {
continue; /* can't lower */
}
if (changed) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
assert(impl);
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_variable_mode mode;
nir_intrinsic_instr *intr = get_io_intrinsic(instr, modes, &mode);
if (!intr)
/* Only accept generic varyings. */
if (sem.location < VARYING_SLOT_VAR0 ||
sem.location > VARYING_SLOT_VAR31)
- continue;
+ continue;
}
sem.medium_precision = 1;
if (changed) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
assert(impl);
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_variable_mode mode;
nir_intrinsic_instr *intr = get_io_intrinsic(instr, modes, &mode);
if (!intr)
if (changed) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_builder b = nir_builder_create(impl);
- nir_foreach_block_safe (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block_safe(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_tex)
continue;
switch (bit_size) {
case 16:
- convert = is_sint ? nir_i2i16 :
- is_uint ? nir_u2u16 : nir_f2f16;
+ convert = is_sint ? nir_i2i16 : is_uint ? nir_u2u16
+ : nir_f2f16;
break;
case 32:
- convert = is_sint ? nir_i2i32 :
- is_uint ? nir_u2u32 : nir_f2f32;
+ convert = is_sint ? nir_i2i32 : is_uint ? nir_u2u32
+ : nir_f2f32;
break;
default:
assert(!"unexpected bit size");
if (changed) {
nir_metadata_preserve(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
const_is_u16(nir_ssa_scalar scalar)
{
uint64_t value = nir_ssa_scalar_as_uint(scalar);
- return value == (uint16_t) value;
+ return value == (uint16_t)value;
}
static bool
const_is_i16(nir_ssa_scalar scalar)
{
int64_t value = nir_ssa_scalar_as_int(scalar);
- return value == (int16_t) value;
+ return value == (int16_t)value;
}
static bool
return true;
}
-
static bool
fold_16bit_tex_srcs(nir_builder *b, nir_tex_instr *tex,
struct nir_fold_tex_srcs_options *options)
return progress;
}
-bool nir_fold_16bit_tex_image(nir_shader *nir,
- struct nir_fold_16bit_tex_image_options *options)
+bool
+nir_fold_16bit_tex_image(nir_shader *nir,
+ struct nir_fold_16bit_tex_image_options *options)
{
return nir_shader_instructions_pass(nir,
fold_16bit_tex_image,
* IN THE SOFTWARE.
*/
-#include "nir_builder.h"
-#include "util/u_math.h"
#include "util/bitscan.h"
+#include "util/u_math.h"
+#include "nir_builder.h"
static nir_intrinsic_instr *
dup_mem_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin,
rev_shifted = nir_vec(b, comps, load->dest.ssa.num_components);
shifted = nir_bcsel(b, nir_ieq_imm(b, shift, 0), &load->dest.ssa,
- nir_ior(b, shifted, rev_shifted));
+ nir_ior(b, shifted, rev_shifted));
}
unsigned chunk_bit_size = MIN2(8 << (ffs(chunk_bytes) - 1), bit_size);
static bool
lower_mem_store(nir_builder *b, nir_intrinsic_instr *intrin,
- nir_lower_mem_access_bit_sizes_cb mem_access_size_align_cb,
- const void *cb_data, bool allow_unaligned_stores_as_atomics)
+ nir_lower_mem_access_bit_sizes_cb mem_access_size_align_cb,
+ const void *cb_data, bool allow_unaligned_stores_as_atomics)
{
nir_ssa_def *value = intrin->src[0].ssa;
uint64_t align_mask = requested.align - 1;
nir_ssa_def *chunk_offset = nir_iadd_imm(b, offset, chunk_start);
- nir_ssa_def *pad = chunk_align < 4 ?
- nir_iand_imm(b, chunk_offset, align_mask) :
- nir_imm_intN_t(b, 0, chunk_offset->bit_size);
+ nir_ssa_def *pad = chunk_align < 4 ? nir_iand_imm(b, chunk_offset, align_mask) : nir_imm_intN_t(b, 0, chunk_offset->bit_size);
chunk_offset = nir_iand_imm(b, chunk_offset, ~align_mask);
unsigned max_pad = chunk_align < requested.align ? requested.align - chunk_align : 0;
switch (intrin->intrinsic) {
case nir_intrinsic_store_ssbo:
nir_ssbo_atomic(b, 32, intrin->src[1].ssa, chunk_offset, iand_mask,
- .atomic_op = nir_atomic_op_iand,
- .access = nir_intrinsic_access(intrin));
+ .atomic_op = nir_atomic_op_iand,
+ .access = nir_intrinsic_access(intrin));
nir_ssbo_atomic(b, 32, intrin->src[1].ssa, chunk_offset, data,
- .atomic_op = nir_atomic_op_ior,
- .access = nir_intrinsic_access(intrin));
+ .atomic_op = nir_atomic_op_ior,
+ .access = nir_intrinsic_access(intrin));
break;
case nir_intrinsic_store_global:
nir_global_atomic(b, 32, chunk_offset, iand_mask,
- .atomic_op = nir_atomic_op_iand);
+ .atomic_op = nir_atomic_op_iand);
nir_global_atomic(b, 32, chunk_offset, data,
- .atomic_op = nir_atomic_op_ior);
+ .atomic_op = nir_atomic_op_ior);
break;
case nir_intrinsic_store_shared:
nir_shared_atomic(b, 32, chunk_offset, iand_mask,
- .atomic_op = nir_atomic_op_iand,
- .base = nir_intrinsic_base(intrin));
+ .atomic_op = nir_atomic_op_iand,
+ .base = nir_intrinsic_base(intrin));
nir_shared_atomic(b, 32, chunk_offset, data,
- .atomic_op = nir_atomic_op_ior,
- .base = nir_intrinsic_base(intrin));
+ .atomic_op = nir_atomic_op_ior,
+ .base = nir_intrinsic_base(intrin));
break;
default:
unreachable("Unsupported unaligned store");
dup_mem_intrinsic(b, intrin, chunk_offset,
align_mul, chunk_align_offset, packed,
requested.num_components, requested.bit_size);
-
}
BITSET_CLEAR_RANGE(mask, chunk_start, (chunk_start + chunk_bytes - 1));
}
{
return nir_shader_instructions_pass(shader, lower_mem_access_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
(void *)options);
}
copy_type_for_byte_size(unsigned size)
{
switch (size) {
- case 1: return glsl_vector_type(GLSL_TYPE_UINT8, 1);
- case 2: return glsl_vector_type(GLSL_TYPE_UINT16, 1);
- case 4: return glsl_vector_type(GLSL_TYPE_UINT, 1);
- case 8: return glsl_vector_type(GLSL_TYPE_UINT, 2);
- case 16: return glsl_vector_type(GLSL_TYPE_UINT, 4);
+ case 1:
+ return glsl_vector_type(GLSL_TYPE_UINT8, 1);
+ case 2:
+ return glsl_vector_type(GLSL_TYPE_UINT16, 1);
+ case 4:
+ return glsl_vector_type(GLSL_TYPE_UINT, 1);
+ case 8:
+ return glsl_vector_type(GLSL_TYPE_UINT, 2);
+ case 16:
+ return glsl_vector_type(GLSL_TYPE_UINT, 4);
default:
unreachable("Unsupported size");
}
glsl_uint8_t_type(), 1);
nir_variable *i = nir_local_variable_create(impl,
- glsl_uintN_t_type(size->bit_size), NULL);
+ glsl_uintN_t_type(size->bit_size), NULL);
nir_store_var(&b, i, nir_imm_intN_t(&b, 0, size->bit_size), ~0);
nir_push_loop(&b);
{
nir_ssa_def *value =
memcpy_load_deref_elem(&b, copy_src, index);
memcpy_store_deref_elem(&b, copy_dst, index, value);
- nir_store_var(&b, i, nir_iadd_imm(&b, index, 1), ~0);
+ nir_store_var(&b, i, nir_iadd_imm(&b, index, 1), ~0);
}
nir_pop_loop(&b, NULL);
}
nir_metadata_preserve(impl, nir_metadata_none);
} else if (found_const_memcpy) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* IN THE SOFTWARE.
*/
-#include "nir_control_flow.h"
#include "nir_builder.h"
+#include "nir_control_flow.h"
/**
* This file implements an optimization for multiview. Some GPU's have a
* original shader body.
*/
- nir_loop* loop = nir_push_loop(&b);
+ nir_loop *loop = nir_push_loop(&b);
nir_ssa_def *loop_index = nir_load_deref(&b, loop_index_deref);
nir_ssa_def *cmp = nir_ige_imm(&b, loop_index, view_count);
nir_metadata_preserve(entrypoint, nir_metadata_none);
return true;
}
-
lower_pack_64_from_32(nir_builder *b, nir_ssa_def *src)
{
return nir_pack_64_2x32_split(b, nir_channel(b, src, 0),
- nir_channel(b, src, 1));
+ nir_channel(b, src, 1));
}
static nir_ssa_def *
lower_unpack_64_to_32(nir_builder *b, nir_ssa_def *src)
{
return nir_vec2(b, nir_unpack_64_2x32_split_x(b, src),
- nir_unpack_64_2x32_split_y(b, src));
+ nir_unpack_64_2x32_split_y(b, src));
}
static nir_ssa_def *
lower_pack_32_from_16(nir_builder *b, nir_ssa_def *src)
{
return nir_pack_32_2x16_split(b, nir_channel(b, src, 0),
- nir_channel(b, src, 1));
+ nir_channel(b, src, 1));
}
static nir_ssa_def *
lower_unpack_32_to_16(nir_builder *b, nir_ssa_def *src)
{
return nir_vec2(b, nir_unpack_32_2x16_split_x(b, src),
- nir_unpack_32_2x16_split_y(b, src));
+ nir_unpack_32_2x16_split_y(b, src));
}
static nir_ssa_def *
lower_pack_64_from_16(nir_builder *b, nir_ssa_def *src)
{
nir_ssa_def *xy = nir_pack_32_2x16_split(b, nir_channel(b, src, 0),
- nir_channel(b, src, 1));
+ nir_channel(b, src, 1));
nir_ssa_def *zw = nir_pack_32_2x16_split(b, nir_channel(b, src, 2),
- nir_channel(b, src, 3));
+ nir_channel(b, src, 3));
return nir_pack_64_2x32_split(b, xy, zw);
}
nir_ssa_def *zw = nir_unpack_64_2x32_split_y(b, src);
return nir_vec4(b, nir_unpack_32_2x16_split_x(b, xy),
- nir_unpack_32_2x16_split_y(b, xy),
- nir_unpack_32_2x16_split_x(b, zw),
- nir_unpack_32_2x16_split_y(b, zw));
+ nir_unpack_32_2x16_split_y(b, xy),
+ nir_unpack_32_2x16_split_x(b, zw),
+ nir_unpack_32_2x16_split_y(b, zw));
}
static nir_ssa_def *
lower_pack_32_from_8(nir_builder *b, nir_ssa_def *src)
{
return nir_pack_32_4x8_split(b, nir_channel(b, src, 0),
- nir_channel(b, src, 1),
- nir_channel(b, src, 2),
- nir_channel(b, src, 3));
+ nir_channel(b, src, 1),
+ nir_channel(b, src, 2),
+ nir_channel(b, src, 3));
}
static bool
if (instr->type != nir_instr_type_alu)
return false;
- nir_alu_instr *alu_instr = (nir_alu_instr *) instr;
+ nir_alu_instr *alu_instr = (nir_alu_instr *)instr;
if (alu_instr->op != nir_op_pack_64_2x32 &&
alu_instr->op != nir_op_unpack_64_2x32 &&
nir_lower_pack(nir_shader *shader)
{
return nir_shader_instructions_pass(shader, lower_pack_instr,
- nir_metadata_block_index | nir_metadata_dominance, NULL);
+ nir_metadata_block_index | nir_metadata_dominance, NULL);
}
util_bitcount64(shader->info.outputs_written));
/* Load an edge flag. */
- nir_io_semantics load_sem = {0};
+ nir_io_semantics load_sem = { 0 };
load_sem.location = VERT_ATTRIB_EDGEFLAG;
load_sem.num_slots = 1;
.io_semantics = load_sem);
/* Store an edge flag. */
- nir_io_semantics semantics = {0};
+ nir_io_semantics semantics = { 0 };
semantics.location = VARYING_SLOT_EDGE;
semantics.num_slots = 1;
.write_mask = 0x1);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return;
}
nir_store_var(&b, out, def, 0xf);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
-void nir_lower_passthrough_edgeflags(nir_shader *shader)
+void
+nir_lower_passthrough_edgeflags(nir_shader *shader)
{
assert(shader->info.stage == MESA_SHADER_VERTEX);
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
}
*/
nir_deref_instr *deref = nir_src_as_deref(src_intrin->src[0]);
return !nir_deref_mode_may_be(deref, nir_var_function_temp |
- nir_var_shader_temp);
+ nir_var_shader_temp);
}
case nir_intrinsic_interp_deref_at_centroid:
break;
}
}
- FALLTHROUGH;
+ FALLTHROUGH;
default:
/* We can't scalarize this type of instruction */
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
nir_instr_free_list(&state.dead_instrs);
typedef struct {
const gl_state_index16 *pntc_state_tokens;
- nir_shader *shader;
- nir_builder b;
- nir_variable *pntc_transform;
+ nir_shader *shader;
+ nir_builder b;
+ nir_variable *pntc_transform;
} lower_pntc_ytransform_state;
static nir_ssa_def *
var->data.location == VARYING_SLOT_PNTC) ||
(var->data.mode == nir_var_system_value &&
var->data.location == SYSTEM_VALUE_POINT_COORD)) {
- lower_load_pointcoord(state, intr);
+ lower_load_pointcoord(state, intr);
}
}
}
nir_lower_pntc_ytransform(nir_shader *shader,
const gl_state_index16 pntc_state_tokens[][STATE_LENGTH])
{
- if (!shader->options->lower_wpos_pntc)
- return false;
+ if (!shader->options->lower_wpos_pntc)
+ return false;
lower_pntc_ytransform_state state = {
.pntc_state_tokens = *pntc_state_tokens,
lower_pntc_ytransform_block(&state, block);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
return state.pntc_transform != NULL;
assert(min > 0.0f || max > 0.0f);
assert(min <= 0.0f || max <= 0.0f || min <= max);
- float minmax[] = {min, max};
+ float minmax[] = { min, max };
return nir_shader_instructions_pass(s, lower_point_size_instr,
nir_metadata_block_index |
- nir_metadata_dominance, minmax);
+ nir_metadata_dominance,
+ minmax);
}
VARYING_SLOT_PSIZ, glsl_float_type());
}
-
if (!out) {
b.cursor = nir_before_cf_list(&impl->body);
nir_ssa_def *load = nir_load_var(&b, in);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return true;
}
nir_ssa_def *point_size = nir_frcp(b, nir_fddx(b, nir_channel(b, coord, 0)));
/* radius = point_size * 0.5 */
- nir_ssa_def *radius = nir_fmul_imm(b, point_size, 0.5);;
+ nir_ssa_def *radius = nir_fmul_imm(b, point_size, 0.5);
+ ;
/**
* Compute the distance of point from centre
assert(shader->info.stage == MESA_SHADER_FRAGMENT);
return nir_shader_instructions_pass(shader, lower_point_smooth,
nir_metadata_loop_analysis |
- nir_metadata_block_index |
- nir_metadata_dominance, NULL);
+ nir_metadata_block_index |
+ nir_metadata_dominance,
+ NULL);
}
/* coverage = (coverage) / SI_NUM_SMOOTH_AA_SAMPLES */
coverage = nir_bit_count(b, coverage);
coverage = nir_u2f32(b, coverage);
- coverage = nir_fmul_imm(b, coverage, 1.0 / *num_smooth_aa_sample);
+ coverage = nir_fmul_imm(b, coverage, 1.0 / *num_smooth_aa_sample);
/* Write out the fragment color*vec4(1, 1, 1, alpha) */
nir_ssa_def *one = nir_imm_float(b, 1.0f);
/* Check if we're still in-bounds */
const unsigned default_buffer_size = 1024 * 1024;
- unsigned buffer_size = (options && options->max_buffer_size) ?
- options->max_buffer_size : default_buffer_size;
+ unsigned buffer_size = (options && options->max_buffer_size) ? options->max_buffer_size : default_buffer_size;
int max_valid_offset =
buffer_size - args_size - fmt_str_id_size - counter_size;
nir_push_if(b, nir_ilt_imm(b, offset, max_valid_offset));
unsigned field_offset = glsl_get_struct_field_offset(args->type, i);
nir_ssa_def *arg_offset =
- nir_i2iN(b, nir_iadd_imm(b, offset,
- fmt_str_id_size + field_offset),
- ptr_bit_size);
+ nir_i2iN(b, nir_iadd_imm(b, offset, fmt_str_id_size + field_offset),
+ ptr_bit_size);
nir_deref_instr *dst_arg_deref =
nir_build_deref_array(b, buffer, arg_offset);
dst_arg_deref = nir_build_deref_cast(b, &dst_arg_deref->dest.ssa,
struct readonly_image_lower_options options = { per_variable };
return nir_shader_instructions_pass(shader, lower_readonly_image_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&options);
}
}
nir_metadata_require(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
nir_index_ssa_defs(impl);
void *dead_ctx = ralloc_context(NULL);
ralloc_free(dead_ctx);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return true;
}
*/
nir_cf_list list;
nir_cf_extract(&list, nir_after_cf_node(&if_stmt->cf_node),
- nir_after_cf_list(state->cf_list));
+ nir_after_cf_list(state->cf_list));
assert(!exec_list_is_empty(&list.list));
nir_cf_reinsert(&list, nir_before_cf_list(&if_stmt->else_list));
}
/* This block is unreachable. Delete it and everything after it. */
nir_cf_list list;
nir_cf_extract(&list, nir_before_cf_node(&block->cf_node),
- nir_after_cf_list(state->cf_list));
+ nir_after_cf_list(state->cf_list));
if (exec_list_is_empty(&list.list)) {
/* There's nothing here, which also means there's nothing in this
nir_iadd_imm(b, instr->src[offset_src].ssa, access_size - 1);
nir_ssa_def *offset =
nir_bcsel(b, nir_uge(b, max_access_offset, size), nir_imm_int(b, 0),
- instr->src[offset_src].ssa);
+ instr->src[offset_src].ssa);
/* Rewrite offset */
nir_instr_rewrite_src_ssa(&instr->instr, &instr->src[offset_src], offset);
if (has_dest) {
zero = nir_imm_zero(b, instr->dest.ssa.num_components,
- instr->dest.ssa.bit_size);
+ instr->dest.ssa.bit_size);
}
nir_push_if(b, valid);
nir_lower_robust_access(nir_shader *s,
const nir_lower_robust_access_options *opts)
{
- return nir_shader_instructions_pass(s, lower, nir_metadata_block_index |
- nir_metadata_dominance,
- (void*)opts);
+ return nir_shader_instructions_pass(s, lower, nir_metadata_block_index | nir_metadata_dominance,
+ (void *)opts);
}
nir_instr_rewrite_src(&instr->instr, &src->src,
nir_src_for_ssa(index));
- src->src_type = is_sampler ?
- nir_tex_src_sampler_offset :
- nir_tex_src_texture_offset;
+ src->src_type = is_sampler ? nir_tex_src_sampler_offset : nir_tex_src_texture_offset;
} else {
nir_tex_instr_remove_src(instr, src_idx);
}
{
return nir_shader_instructions_pass(shader, lower_sampler,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
nir_ssa_def *offset =
nir_iadd_imm(b, nir_build_deref_offset(b, deref, size_align),
- var->data.location);
+ var->data.location);
unsigned align, UNUSED size;
size_align(deref->type, &size, &align);
if (intrin->intrinsic == nir_intrinsic_load_deref) {
unsigned bit_size = intrin->dest.ssa.bit_size;
nir_ssa_def *value = nir_load_scratch(
- b, intrin->num_components, bit_size == 1 ? 32 : bit_size, offset, .align_mul=align);
+ b, intrin->num_components, bit_size == 1 ? 32 : bit_size, offset, .align_mul = align);
if (bit_size == 1)
value = nir_b2b1(b, value);
if (value->bit_size == 1)
value = nir_b2b32(b, value);
- nir_store_scratch(b, value, offset, .align_mul=align,
- .write_mask=nir_intrinsic_write_mask(intrin));
+ nir_store_scratch(b, value, offset, .align_mul = align,
+ .write_mask = nir_intrinsic_write_mask(intrin));
}
nir_instr_remove(&intrin->instr);
nir_deref_instr_remove_if_unused(deref);
}
-static bool only_used_for_load_store(nir_deref_instr *deref)
+static bool
+only_used_for_load_store(nir_deref_instr *deref)
{
nir_foreach_use(src, &deref->dest.ssa) {
if (!src->parent_instr)
return false;
if (src->parent_instr->type == nir_instr_type_deref) {
- if (!only_used_for_load_store(nir_instr_as_deref(src->parent_instr)))
+ if (!only_used_for_load_store(nir_instr_as_deref(src->parent_instr)))
return false;
} else if (src->parent_instr->type != nir_instr_type_intrinsic) {
return false;
}
set_foreach(set, entry) {
- nir_variable* var = (void*)entry->key;
+ nir_variable *var = (void *)entry->key;
/* Remove it from its list */
exec_node_remove(&var->node);
if (impl_progress) {
progress = true;
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* IN THE SOFTWARE.
*/
+#include "util/u_dynarray.h"
+#include "util/u_math.h"
#include "nir.h"
#include "nir_builder.h"
#include "nir_phi_builder.h"
-#include "util/u_dynarray.h"
-#include "util/u_math.h"
static bool
move_system_values_to_top(nir_shader *shader)
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
static struct sized_bitset
bitset_create(void *mem_ctx, unsigned size)
{
- return (struct sized_bitset) {
+ return (struct sized_bitset){
.set = rzalloc_array(mem_ctx, BITSET_WORD, BITSET_WORDS(size)),
.size = size,
};
static int
compare_instr_indexes(const void *_inst1, const void *_inst2)
{
- const nir_instr * const *inst1 = _inst1;
- const nir_instr * const *inst2 = _inst2;
+ const nir_instr *const *inst1 = _inst1;
+ const nir_instr *const *inst2 = _inst2;
return (*inst1)->index - (*inst2)->index;
}
return true;
- fail:
+fail:
util_dynarray_clear(buf);
ralloc_free(mem_ctx);
return false;
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
nir_metadata_require(impl, nir_metadata_live_ssa_defs |
- nir_metadata_dominance |
- nir_metadata_block_index |
- nir_metadata_instr_index);
+ nir_metadata_dominance |
+ nir_metadata_block_index |
+ nir_metadata_instr_index);
void *mem_ctx = ralloc_context(shader);
switch (call->intrinsic) {
case nir_intrinsic_trace_ray: {
nir_rt_trace_ray(b, call->src[0].ssa, call->src[1].ssa,
- call->src[2].ssa, call->src[3].ssa,
- call->src[4].ssa, call->src[5].ssa,
- call->src[6].ssa, call->src[7].ssa,
- call->src[8].ssa, call->src[9].ssa,
- call->src[10].ssa,
- .call_idx = call_idx, .stack_size = offset);
+ call->src[2].ssa, call->src[3].ssa,
+ call->src[4].ssa, call->src[5].ssa,
+ call->src[6].ssa, call->src[7].ssa,
+ call->src[8].ssa, call->src[9].ssa,
+ call->src[10].ssa,
+ .call_idx = call_idx, .stack_size = offset);
break;
}
ralloc_free(mem_ctx);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
static nir_instr *
case nir_cursor_after_instr:
return cursor.instr->type == nir_instr_type_jump;
case nir_cursor_after_block:
- return nir_block_ends_in_jump(cursor.block);;
+ return nir_block_ends_in_jump(cursor.block);
+ ;
}
unreachable("Invalid cursor option");
}
* copy the stuff after resume_node.
*/
nir_cf_extract(&cf_list, nir_after_cf_node(resume_node),
- nir_after_cf_list(child_list));
+ nir_after_cf_list(child_list));
} else {
/* The loop contains its own cursor and still has useful stuff in it.
* We want to move everything after and including the loop to before
*/
assert(resume_node->type == nir_cf_node_loop);
nir_cf_extract(&cf_list, nir_before_cf_node(resume_node),
- nir_after_cf_list(child_list));
+ nir_after_cf_list(child_list));
}
} else {
/* If we found the resume instruction in one of our blocks, grab
* place it before the cursor instr.
*/
nir_cf_extract(&cf_list, nir_after_instr(resume_instr),
- nir_after_cf_list(child_list));
+ nir_after_cf_list(child_list));
}
/* If the resume instruction is in the first block of the child_list,
*/
nir_cf_list cf_list;
nir_cf_extract(&cf_list, nir_after_instr(&resume->instr),
- nir_after_block(block));
+ nir_after_block(block));
nir_cf_delete(&cf_list);
b.cursor = nir_instr_remove(&resume->instr);
nir_jump(&b, nir_jump_halt);
return nir_shader_instructions_pass(shader,
lower_stack_instr_to_scratch,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
return nir_shader_instructions_pass(shader,
opt_remove_respills_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
if (read_mask == 0)
continue;
- unsigned swiz_map[NIR_MAX_VEC_COMPONENTS] = { 0, };
+ unsigned swiz_map[NIR_MAX_VEC_COMPONENTS] = {
+ 0,
+ };
unsigned swiz_count = 0;
u_foreach_bit(idx, read_mask)
swiz_map[idx] = swiz_count++;
}
nir_metadata_preserve(impl,
- progress ?
- (nir_metadata_dominance |
- nir_metadata_block_index |
- nir_metadata_loop_analysis) :
- nir_metadata_all);
+ progress ? (nir_metadata_dominance |
+ nir_metadata_block_index |
+ nir_metadata_loop_analysis)
+ : nir_metadata_all);
_mesa_hash_table_u64_destroy(value_id_to_mask);
/* By ascending value_id */
if (item1->bit_size == item2->bit_size)
- return (int) item1->value - (int) item2->value;
+ return (int)item1->value - (int)item2->value;
/* By descending size */
- return (int) item2->bit_size - (int) item1->bit_size;
+ return (int)item2->bit_size - (int)item1->bit_size;
}
static bool
};
util_dynarray_append(&ops, struct scratch_item, item);
- _mesa_hash_table_u64_insert(value_id_to_item, value_id, (void *)(uintptr_t)true);
+ _mesa_hash_table_u64_insert(value_id_to_item, value_id, (void *)(uintptr_t) true);
}
}
sizeof(struct scratch_item),
sort_scratch_item_by_size_and_value_id);
-
/* Reorder things on the stack */
_mesa_hash_table_u64_clear(value_id_to_item);
nir_foreach_function_impl(impl, shader) {
nir_metadata_require(impl, nir_metadata_dominance |
- nir_metadata_block_index);
+ nir_metadata_block_index);
bool func_progress = false;
nir_foreach_block_safe(block, impl) {
nir_metadata_preserve(impl,
func_progress ? (nir_metadata_block_index |
nir_metadata_dominance |
- nir_metadata_loop_analysis) :
- nir_metadata_all);
+ nir_metadata_loop_analysis)
+ : nir_metadata_all);
progress |= func_progress;
}
b->cursor = nir_before_instr(instr);
if (intrin->intrinsic == nir_intrinsic_load_stack) {
- nir_ssa_def *components[NIR_MAX_VEC_COMPONENTS] = { 0, };
+ nir_ssa_def *components[NIR_MAX_VEC_COMPONENTS] = {
+ 0,
+ };
for (unsigned c = 0; c < intrin->dest.ssa.num_components; c++) {
components[c] = nir_load_stack(b, 1, intrin->dest.ssa.bit_size,
.base = nir_intrinsic_base(intrin) +
return nir_shader_instructions_pass(shader,
split_stack_components_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
struct stack_op_vectorizer_state {
- nir_should_vectorize_mem_func driver_callback;
- void *driver_data;
+ nir_should_vectorize_mem_func driver_callback;
+ void *driver_data;
};
static bool
nir_rematerialize_derefs_in_use_blocks_impl(impl);
if (progress)
- NIR_PASS(_, shader, nir_opt_dead_cf);
+ NIR_PASS(_, shader, nir_opt_dead_cf);
}
/* Save the start point of the call stack in scratch */
struct stack_op_vectorizer_state vectorizer_state = {
.driver_callback = options->vectorizer_callback,
- .driver_data = options->vectorizer_data,
+ .driver_data = options->vectorizer_data,
};
nir_load_store_vectorize_options vect_opts = {
.modes = nir_var_shader_temp,
case nir_intrinsic_load_barycentric_at_sample:
b->cursor = nir_before_instr(instr);
lowered = nir_load_barycentric(b, nir_intrinsic_load_barycentric_pixel,
- nir_intrinsic_interp_mode(intrin));
+ nir_intrinsic_interp_mode(intrin));
if (nir_intrinsic_interp_mode(intrin) == INTERP_MODE_NOPERSPECTIVE) {
BITSET_SET(b->shader->info.system_values_read,
return nir_shader_instructions_pass(shader, lower_single_sampled_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
- NULL) || progress;
+ nir_metadata_dominance,
+ NULL) ||
+ progress;
}
static inline nir_ssa_def *
nir_load_ssbo_prop(nir_builder *b, nir_intrinsic_op op,
- nir_src *idx, unsigned bitsize)
+ nir_src *idx, unsigned bitsize)
{
nir_intrinsic_instr *load = nir_intrinsic_instr_create(b->shader, op);
load->num_components = 1;
nir_ssa_def *address =
nir_iadd(b,
- nir_ssbo_prop(b, load_ssbo_address, &index, 64),
- nir_u2u64(b, offset));
+ nir_ssbo_prop(b, load_ssbo_address, &index, 64),
+ nir_u2u64(b, offset));
/* Create the replacement intrinsic */
nir_foreach_block(block, impl) {
nir_foreach_instr_safe(instr, block) {
- if (!should_lower_ssbo_instr(instr)) continue;
+ if (!should_lower_ssbo_instr(instr))
+ continue;
progress = true;
b.cursor = nir_before_instr(instr);
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
nir_ssa_def *replace = lower_ssbo_instr(&b, intr);
- if (replace) {
+ if (replace) {
nir_ssa_def_rewrite_uses(&intr->dest.ssa,
- replace);
+ replace);
}
nir_instr_remove(instr);
* IN THE SOFTWARE.
*/
+#include "util/u_math.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/u_math.h"
/**
* \file nir_opt_intrinsics.c
assert(intrin->dest.ssa.num_components > 1);
nir_ssa_def *value = nir_ssa_for_src(b, intrin->src[0],
- intrin->num_components);
+ intrin->num_components);
nir_ssa_def *reads[NIR_MAX_VEC_COMPONENTS];
for (unsigned i = 0; i < intrin->num_components; i++) {
break;
case nir_intrinsic_quad_broadcast:
index = nir_ior(b, nir_iand_imm(b, index, ~0x3),
- intrin->src[1].ssa);
+ intrin->src[1].ssa);
break;
case nir_intrinsic_quad_swap_horizontal:
/* For Quad operations, subgroups are divided into quads where
const unsigned cluster_size = nir_intrinsic_cluster_size(intrin);
nir_ssa_def *rotation_group_mask =
- cluster_size > 0 ? nir_imm_int(b, (int)(cluster_size - 1)) :
- nir_iadd_imm(b, nir_load_subgroup_size(b), -1);
+ cluster_size > 0 ? nir_imm_int(b, (int)(cluster_size - 1)) : nir_iadd_imm(b, nir_load_subgroup_size(b), -1);
index = nir_iand(b, nir_iadd(b, local_id, delta),
- rotation_group_mask);
+ rotation_group_mask);
if (cluster_size > 0) {
index = nir_iadd(b, index,
nir_iand(b, local_id, nir_inot(b, rotation_group_mask)));
static const struct glsl_type *
glsl_type_for_ssa(nir_ssa_def *def)
{
- const struct glsl_type *comp_type = def->bit_size == 1 ? glsl_bool_type() :
- glsl_uintN_t_type(def->bit_size);
+ const struct glsl_type *comp_type = def->bit_size == 1 ? glsl_bool_type() : glsl_uintN_t_type(def->bit_size);
return glsl_replace_vector_type(comp_type, def->num_components);
}
nir_variable *result =
nir_local_variable_create(b->impl, glsl_type_for_ssa(val), "result");
- nir_loop *loop = nir_push_loop(b); {
+ nir_loop *loop = nir_push_loop(b);
+ {
nir_ssa_def *first_id = nir_read_first_invocation(b, subgroup_id);
nir_ssa_def *first_val = nir_read_first_invocation(b, val);
nir_ssa_def *first_result =
nir_read_invocation(b, val, nir_read_first_invocation(b, id));
- nir_if *nif = nir_push_if(b, nir_ieq(b, id, first_id)); {
+ nir_if *nif = nir_push_if(b, nir_ieq(b, id, first_id));
+ {
nir_store_var(b, result, first_val, BITFIELD_MASK(val->num_components));
- } nir_pop_if(b, nif);
+ }
+ nir_pop_if(b, nif);
- nir_if *nif2 = nir_push_if(b, nir_elect(b, 1)); {
- nir_if *nif3 = nir_push_if(b, nir_ult(b, subgroup_id, id)); {
+ nir_if *nif2 = nir_push_if(b, nir_elect(b, 1));
+ {
+ nir_if *nif3 = nir_push_if(b, nir_ult(b, subgroup_id, id));
+ {
nir_store_var(b, result, first_result, BITFIELD_MASK(val->num_components));
- } nir_pop_if(b, nif3);
+ }
+ nir_pop_if(b, nif3);
nir_jump(b, nir_jump_break);
- } nir_pop_if(b, nif2);
- } nir_pop_loop(b, loop);
+ }
+ nir_pop_if(b, nif2);
+ }
+ nir_pop_loop(b, loop);
return nir_load_var(b, result);
}
/* First compute the result assuming one ballot component. */
nir_ssa_def *result =
nir_ushr(b, nir_imm_intN_t(b, ~0ull, options->ballot_bit_size),
- nir_isub_imm(b, options->ballot_bit_size,
- subgroup_size));
+ nir_isub_imm(b, options->ballot_bit_size,
+ subgroup_size));
/* Since the subgroup size and ballot bitsize are both powers of two, there
* are two possible cases to consider:
* in all cases. The other components will also get the correct value in
* case (1) if we just use the rule in case (2), so we'll get the correct
* result if we just follow (2) and then replace the first component with
- * "result".
- */
+ * "result".
+ */
nir_const_value min_idx[4];
for (unsigned i = 0; i < options->ballot_components; i++)
min_idx[i] = nir_const_value_for_int(i * options->ballot_bit_size, 32);
break;
case nir_intrinsic_load_subgroup_ge_mask:
val = nir_iand(b, build_subgroup_ge_mask(b, options),
- build_subgroup_mask(b, options));
+ build_subgroup_mask(b, options));
break;
case nir_intrinsic_load_subgroup_gt_mask:
val = nir_iand(b, build_subgroup_gt_mask(b, options),
- build_subgroup_mask(b, options));
+ build_subgroup_mask(b, options));
break;
case nir_intrinsic_load_subgroup_le_mask:
val = nir_inot(b, build_subgroup_gt_mask(b, options));
*
*/
+#include "util/set.h"
+#include "util/u_math.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/u_math.h"
-#include "util/set.h"
struct lower_sysval_state {
const nir_lower_compute_system_values_options *options;
return nir_u2uN(b, &intrin->dest.ssa, bit_size);
}
-static nir_ssa_def*
+static nir_ssa_def *
build_global_group_size(nir_builder *b, unsigned bit_size)
{
nir_ssa_def *group_size = nir_load_workgroup_size(b);
nir_ssa_def *num_workgroups = nir_load_num_workgroups(b, bit_size);
return nir_imul(b, nir_u2uN(b, group_size, bit_size),
- num_workgroups);
+ num_workgroups);
}
static bool
case nir_intrinsic_load_vertex_id:
if (b->shader->options->vertex_id_zero_based) {
return nir_iadd(b, nir_load_vertex_id_zero_base(b),
- nir_load_first_vertex(b));
+ nir_load_first_vertex(b));
} else {
return NULL;
}
*/
if (b->shader->options->lower_base_vertex) {
return nir_iand(b, nir_load_is_indexed_draw(b),
- nir_load_first_vertex(b));
+ nir_load_first_vertex(b));
} else {
return NULL;
}
nir_ssa_def *index = nir_ssa_for_src(b, arr_deref->arr.index, 1);
nir_ssa_def *sysval = (deref->var->data.location ==
SYSTEM_VALUE_TESS_LEVEL_INNER)
- ? nir_load_tess_level_inner(b)
- : nir_load_tess_level_outer(b);
+ ? nir_load_tess_level_inner(b)
+ : nir_load_tess_level_outer(b);
return nir_vector_extract(b, sysval, index);
}
switch (var->data.location) {
case SYSTEM_VALUE_INSTANCE_INDEX:
return nir_iadd(b, nir_load_instance_id(b),
- nir_load_base_instance(b));
+ nir_load_base_instance(b));
case SYSTEM_VALUE_SUBGROUP_EQ_MASK:
case SYSTEM_VALUE_SUBGROUP_GE_MASK:
case SYSTEM_VALUE_MESH_VIEW_INDICES:
return nir_load_mesh_view_indices(b, intrin->dest.ssa.num_components,
- bit_size, column, .base = 0,
- .range = intrin->dest.ssa.num_components * bit_size / 8);
+ bit_size, column, .base = 0,
+ .range = intrin->dest.ssa.num_components * bit_size / 8);
default:
break;
}
}
-
static nir_ssa_def *
lower_id_to_index(nir_builder *b, nir_ssa_def *index, nir_ssa_def *size,
unsigned bit_size)
*/
nir_ssa_def *val = try_lower_id_to_index_1d(b, local_index,
- b->shader->info.workgroup_size);
+ b->shader->info.workgroup_size);
if (val)
return val;
}
if (!b->shader->info.workgroup_size_variable && is_zero) {
nir_ssa_scalar defs[3];
for (unsigned i = 0; i < 3; i++) {
- defs[i] = is_zero & (1 << i) ? nir_get_ssa_scalar(nir_imm_zero(b, 1, 32), 0) :
- nir_get_ssa_scalar(&intrin->dest.ssa, i);
+ defs[i] = is_zero & (1 << i) ? nir_get_ssa_scalar(nir_imm_zero(b, 1, 32), 0) : nir_get_ssa_scalar(&intrin->dest.ssa, i);
}
return nir_vec_scalars(b, defs, 3);
}
*/
nir_ssa_def *index;
index = nir_imul(b, nir_channel(b, local_id, 2),
- nir_imul(b, size_x, size_y));
+ nir_imul(b, size_x, size_y));
index = nir_iadd(b, index,
- nir_imul(b, nir_channel(b, local_id, 1), size_x));
+ nir_imul(b, nir_channel(b, local_id, 1), size_x));
index = nir_iadd(b, index, nir_channel(b, local_id, 0));
return nir_u2uN(b, index, bit_size);
} else {
nir_ssa_def *group_id = nir_load_workgroup_id(b, bit_size);
nir_ssa_def *local_id = nir_load_local_invocation_id(b);
- return nir_iadd(b, nir_imul(b, group_id,
- nir_u2uN(b, group_size, bit_size)),
- nir_u2uN(b, local_id, bit_size));
+ return nir_iadd(b, nir_imul(b, group_id, nir_u2uN(b, group_size, bit_size)),
+ nir_u2uN(b, local_id, bit_size));
} else {
return NULL;
}
case nir_intrinsic_load_global_invocation_id: {
if (options && options->has_base_global_invocation_id)
return nir_iadd(b, nir_load_global_invocation_id_zero_base(b, bit_size),
- nir_load_base_global_invocation_id(b, bit_size));
+ nir_load_base_global_invocation_id(b, bit_size));
else if ((options && options->has_base_workgroup_id) ||
!b->shader->options->has_cs_global_id)
return nir_load_global_invocation_id_zero_base(b, bit_size);
/* index = id.x + ((id.y + (id.z * size.y)) * size.x) */
nir_ssa_def *index;
index = nir_imul(b, nir_channel(b, global_id, 2),
- nir_channel(b, global_size, 1));
+ nir_channel(b, global_size, 1));
index = nir_iadd(b, nir_channel(b, global_id, 1), index);
index = nir_imul(b, nir_channel(b, global_size, 0), index);
index = nir_iadd(b, nir_channel(b, global_id, 0), index);
case nir_intrinsic_load_workgroup_id: {
if (options && options->has_base_workgroup_id)
return nir_iadd(b, nir_u2uN(b, nir_load_workgroup_id_zero_base(b), bit_size),
- nir_load_base_workgroup_id(b, bit_size));
+ nir_load_base_workgroup_id(b, bit_size));
else if (options && options->lower_workgroup_id_to_index) {
nir_ssa_def *wg_idx = nir_load_workgroup_index(b);
nir_ssa_def *val =
- try_lower_id_to_index_1d(b, wg_idx, options->num_workgroups);
+ try_lower_id_to_index_1d(b, wg_idx, options->num_workgroups);
if (val)
return val;
}
return NULL;
-
}
case nir_intrinsic_load_num_workgroups: {
nir_shader_lower_instructions(shader,
lower_compute_system_value_filter,
lower_compute_system_value_instr,
- (void*)&state);
+ (void *)&state);
ralloc_free(state.lower_once_list);
/* Update this so as not to lower it again. */
nir_foreach_variable_with_modes(var, shader, nir_var_system_value) {
switch (var->data.location) {
-#define SYSVAL_TO_VARYING(opt, sysval, varying) \
- case SYSTEM_VALUE_ ## sysval: \
- if (options->opt) { \
- var->data.mode = nir_var_shader_in; \
- var->data.location = VARYING_SLOT_ ## varying; \
- progress = true; \
- } \
- break
+#define SYSVAL_TO_VARYING(opt, sysval, varying) \
+ case SYSTEM_VALUE_##sysval: \
+ if (options->opt) { \
+ var->data.mode = nir_var_shader_in; \
+ var->data.location = VARYING_SLOT_##varying; \
+ progress = true; \
+ } \
+ break
- SYSVAL_TO_VARYING(frag_coord, FRAG_COORD, POS);
- SYSVAL_TO_VARYING(point_coord, POINT_COORD, PNTC);
- SYSVAL_TO_VARYING(front_face, FRONT_FACE, FACE);
+ SYSVAL_TO_VARYING(frag_coord, FRAG_COORD, POS);
+ SYSVAL_TO_VARYING(point_coord, POINT_COORD, PNTC);
+ SYSVAL_TO_VARYING(front_face, FRONT_FACE, FACE);
#undef SYSVAL_TO_VARYING
*
*/
+#include "util/u_math.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/u_math.h"
typedef struct {
uint32_t task_count_shared_addr;
if (instr->type != nir_instr_type_intrinsic)
return false;
- lower_task_nv_state *s = (lower_task_nv_state *) state;
+ lower_task_nv_state *s = (lower_task_nv_state *)state;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
nir_store_shared(b, zero, zero, .base = s->task_count_shared_addr);
nir_barrier(b,
- .execution_scope = SCOPE_WORKGROUP,
- .memory_scope = SCOPE_WORKGROUP,
- .memory_semantics = NIR_MEMORY_RELEASE,
- .memory_modes = nir_var_mem_shared);
+ .execution_scope = SCOPE_WORKGROUP,
+ .memory_scope = SCOPE_WORKGROUP,
+ .memory_semantics = NIR_MEMORY_RELEASE,
+ .memory_modes = nir_var_mem_shared);
/* At the end of the shader, read the task count from shared memory
* and emit launch_mesh_workgroups.
b->cursor = nir_after_cf_list(&b->impl->body);
nir_barrier(b,
- .execution_scope = SCOPE_WORKGROUP,
- .memory_scope = SCOPE_WORKGROUP,
- .memory_semantics = NIR_MEMORY_ACQUIRE,
- .memory_modes = nir_var_mem_shared);
+ .execution_scope = SCOPE_WORKGROUP,
+ .memory_scope = SCOPE_WORKGROUP,
+ .memory_semantics = NIR_MEMORY_ACQUIRE,
+ .memory_modes = nir_var_mem_shared);
nir_ssa_def *task_count =
nir_load_shared(b, 1, 32, zero, .base = s->task_count_shared_addr);
* have the same number of sources and same indices.
*/
unsigned base = nir_intrinsic_base(intrin);
- nir_atomic_op atom_op = nir_intrinsic_has_atomic_op(intrin) ?
- nir_intrinsic_atomic_op(intrin) : 0;
+ nir_atomic_op atom_op = nir_intrinsic_has_atomic_op(intrin) ? nir_intrinsic_atomic_op(intrin) : 0;
intrin->intrinsic = shared_opcode_for_task_payload(intrin->intrinsic);
nir_intrinsic_set_base(intrin, base + s->payload_shared_addr);
const unsigned vec4_copies_per_invocation = whole_wg_vec4_copies / invocations;
const unsigned remaining_vec4_copies = whole_wg_vec4_copies % invocations;
const unsigned remaining_dwords =
- DIV_ROUND_UP(payload_size
- - vec4size * vec4_copies_per_invocation * invocations
- - vec4size * remaining_vec4_copies,
- 4);
+ DIV_ROUND_UP(payload_size - vec4size * vec4_copies_per_invocation * invocations - vec4size * remaining_vec4_copies,
+ 4);
const unsigned base_shared_addr = s->payload_shared_addr + payload_addr;
nir_ssa_def *invocation_index = nir_load_local_invocation_index(b);
* This is necessary because we placed the payload in shared memory.
*/
nir_barrier(b, .execution_scope = SCOPE_WORKGROUP,
- .memory_scope = SCOPE_WORKGROUP,
- .memory_semantics = NIR_MEMORY_ACQ_REL,
- .memory_modes = nir_var_mem_shared);
+ .memory_scope = SCOPE_WORKGROUP,
+ .memory_semantics = NIR_MEMORY_ACQ_REL,
+ .memory_modes = nir_var_mem_shared);
/* Payload_size is a size of user-accessible payload, but on some
* hardware (e.g. Intel) payload has a private header, which we have
if (instr->type != nir_instr_type_intrinsic)
return false;
- lower_task_state *s = (lower_task_state *) state;
+ lower_task_state *s = (lower_task_state *)state;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
- case nir_intrinsic_task_payload_atomic:
- case nir_intrinsic_task_payload_atomic_swap:
- if (atomics)
- return true;
- break;
- case nir_intrinsic_load_task_payload:
- if (small_types && nir_dest_bit_size(intrin->dest) < 32)
- return true;
- break;
- case nir_intrinsic_store_task_payload:
- if (small_types && nir_src_bit_size(intrin->src[0]) < 32)
- return true;
- break;
- default:
- break;
+ case nir_intrinsic_task_payload_atomic:
+ case nir_intrinsic_task_payload_atomic_swap:
+ if (atomics)
+ return true;
+ break;
+ case nir_intrinsic_load_task_payload:
+ if (small_types && nir_dest_bit_size(intrin->dest) < 32)
+ return true;
+ break;
+ case nir_intrinsic_store_task_payload:
+ if (small_types && nir_src_bit_size(intrin->src[0]) < 32)
+ return true;
+ break;
+ default:
+ break;
}
}
}
{
return nir_shader_instructions_pass(shader, lower_tess_coord_z,
nir_metadata_block_index |
- nir_metadata_dominance, &triangles);
+ nir_metadata_dominance,
+ &triangles);
}
} nir_const_value_3_4;
static const nir_const_value_3_4 bt601_limited_range_csc_coeffs = { {
- { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
- { { .f32 = 0.0f }, { .f32 = -0.39176229f }, { .f32 = 2.01723214f } },
- { { .f32 = 1.59602678f }, { .f32 = -0.81296764f }, { .f32 = 0.0f } },
+ { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
+ { { .f32 = 0.0f }, { .f32 = -0.39176229f }, { .f32 = 2.01723214f } },
+ { { .f32 = 1.59602678f }, { .f32 = -0.81296764f }, { .f32 = 0.0f } },
} };
static const nir_const_value_3_4 bt601_full_range_csc_coeffs = { {
- { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
- { { .f32 = 0.0f }, { .f32 = -0.34413629f }, { .f32 = 1.772f } },
- { { .f32 = 1.402f }, { .f32 = -0.71413629f }, { .f32 = 0.0f } },
+ { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
+ { { .f32 = 0.0f }, { .f32 = -0.34413629f }, { .f32 = 1.772f } },
+ { { .f32 = 1.402f }, { .f32 = -0.71413629f }, { .f32 = 0.0f } },
} };
static const nir_const_value_3_4 bt709_limited_range_csc_coeffs = { {
- { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
- { { .f32 = 0.0f }, { .f32 = -0.21324861f }, { .f32 = 2.11240179f } },
- { { .f32 = 1.79274107f }, { .f32 = -0.53290933f }, { .f32 = 0.0f } },
+ { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
+ { { .f32 = 0.0f }, { .f32 = -0.21324861f }, { .f32 = 2.11240179f } },
+ { { .f32 = 1.79274107f }, { .f32 = -0.53290933f }, { .f32 = 0.0f } },
} };
static const nir_const_value_3_4 bt709_full_range_csc_coeffs = { {
- { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
- { { .f32 = 0.0f }, { .f32 = -0.18732427f }, { .f32 = 1.8556f } },
- { { .f32 = 1.5748f }, { .f32 = -0.46812427f }, { .f32 = 0.0f } },
+ { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
+ { { .f32 = 0.0f }, { .f32 = -0.18732427f }, { .f32 = 1.8556f } },
+ { { .f32 = 1.5748f }, { .f32 = -0.46812427f }, { .f32 = 0.0f } },
} };
static const nir_const_value_3_4 bt2020_limited_range_csc_coeffs = { {
- { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
- { { .f32 = 0.0f }, { .f32 = -0.18732610f }, { .f32 = 2.14177232f } },
- { { .f32 = 1.67878795f }, { .f32 = -0.65046843f }, { .f32 = 0.0f } },
+ { { .f32 = 1.16438356f }, { .f32 = 1.16438356f }, { .f32 = 1.16438356f } },
+ { { .f32 = 0.0f }, { .f32 = -0.18732610f }, { .f32 = 2.14177232f } },
+ { { .f32 = 1.67878795f }, { .f32 = -0.65046843f }, { .f32 = 0.0f } },
} };
static const nir_const_value_3_4 bt2020_full_range_csc_coeffs = { {
- { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
- { { .f32 = 0.0f }, { .f32 = -0.16455313f }, { .f32 = 1.88140000f } },
- { { .f32 = 1.4747f }, { .f32 = -0.57139187f }, { .f32 = 0.0f } },
+ { { .f32 = 1.0f }, { .f32 = 1.0f }, { .f32 = 1.0f } },
+ { { .f32 = 0.0f }, { .f32 = -0.16455313f }, { .f32 = 1.88140000f } },
+ { { .f32 = 1.4747f }, { .f32 = -0.57139187f }, { .f32 = 0.0f } },
} };
static const float bt601_limited_range_csc_offsets[3] = {
/* The offset is not applied to the array index */
if (tex->coord_components == 2) {
offset_coord = nir_vec2(b, nir_channel(b, offset_coord, 0),
- nir_channel(b, coord, 1));
+ nir_channel(b, coord, 1));
} else if (tex->coord_components == 3) {
offset_coord = nir_vec3(b, nir_channel(b, offset_coord, 0),
- nir_channel(b, offset_coord, 1),
- nir_channel(b, coord, 2));
+ nir_channel(b, offset_coord, 1),
+ nir_channel(b, coord, 2));
} else {
unreachable("Invalid number of components");
}
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
-
- nir_ssa_def *y = sample_plane(b, tex, 0, options);
- nir_ssa_def *uxvx = sample_plane(b, tex, 1, options);
-
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, y, 1),
- nir_channel(b, uxvx, 0),
- nir_channel(b, uxvx, 2),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ b->cursor = nir_after_instr(&tex->instr);
+
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *uxvx = sample_plane(b, tex, 1, options);
+
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, uxvx, 0),
+ nir_channel(b, uxvx, 2),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
-
- nir_ssa_def *y = sample_plane(b, tex, 0, options);
- nir_ssa_def *vxux = sample_plane(b, tex, 1, options);
-
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, y, 1),
- nir_channel(b, vxux, 2),
- nir_channel(b, vxux, 0),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ b->cursor = nir_after_instr(&tex->instr);
+
+ nir_ssa_def *y = sample_plane(b, tex, 0, options);
+ nir_ssa_def *vxux = sample_plane(b, tex, 1, options);
+
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y, 1),
+ nir_channel(b, vxux, 2),
+ nir_channel(b, vxux, 0),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *ayuv = sample_plane(b, tex, 0, options);
+ nir_ssa_def *ayuv = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, ayuv, 2),
- nir_channel(b, ayuv, 1),
- nir_channel(b, ayuv, 0),
- nir_channel(b, ayuv, 3),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, ayuv, 2),
+ nir_channel(b, ayuv, 1),
+ nir_channel(b, ayuv, 0),
+ nir_channel(b, ayuv, 3),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *y41x = sample_plane(b, tex, 0, options);
+ nir_ssa_def *y41x = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, y41x, 1),
- nir_channel(b, y41x, 0),
- nir_channel(b, y41x, 2),
- nir_channel(b, y41x, 3),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, y41x, 1),
+ nir_channel(b, y41x, 0),
+ nir_channel(b, y41x, 2),
+ nir_channel(b, y41x, 3),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *xyuv = sample_plane(b, tex, 0, options);
+ nir_ssa_def *xyuv = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, xyuv, 2),
- nir_channel(b, xyuv, 1),
- nir_channel(b, xyuv, 0),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, xyuv, 2),
+ nir_channel(b, xyuv, 1),
+ nir_channel(b, xyuv, 0),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
+ nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, yuv, 0),
- nir_channel(b, yuv, 1),
- nir_channel(b, yuv, 2),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, yuv, 0),
+ nir_channel(b, yuv, 1),
+ nir_channel(b, yuv, 2),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
+ nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, yuv, 1),
- nir_channel(b, yuv, 2),
- nir_channel(b, yuv, 0),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, yuv, 1),
+ nir_channel(b, yuv, 2),
+ nir_channel(b, yuv, 0),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
static void
const nir_lower_tex_options *options,
unsigned texture_index)
{
- b->cursor = nir_after_instr(&tex->instr);
+ b->cursor = nir_after_instr(&tex->instr);
- nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
+ nir_ssa_def *yuv = sample_plane(b, tex, 0, options);
- convert_yuv_to_rgb(b, tex,
- nir_channel(b, yuv, 2),
- nir_channel(b, yuv, 1),
- nir_channel(b, yuv, 0),
- nir_imm_float(b, 1.0f),
- options,
- texture_index);
+ convert_yuv_to_rgb(b, tex,
+ nir_channel(b, yuv, 2),
+ nir_channel(b, yuv, 1),
+ nir_channel(b, yuv, 0),
+ nir_imm_float(b, 1.0f),
+ options,
+ texture_index);
}
/*
nir_ssa_def *size =
nir_channels(b, nir_i2f32(b, nir_get_texture_size(b, tex)),
- component_mask);
+ component_mask);
/* Scale the gradients by width and height. Effectively, the incoming
* gradients are s'(x,y), t'(x,y), and r'(x,y) from equation 3.19 in the
return false;
case nir_lower_tex_packing_16: {
- static const unsigned bits[4] = {16, 16, 16, 16};
+ static const unsigned bits[4] = { 16, 16, 16, 16 };
switch (nir_alu_type_get_base_type(tex->dest_type)) {
case nir_type_float:
}
nir_ssa_def *offset = nir_imm_ivec2(b, tex->tg4_offsets[i][0],
- tex->tg4_offsets[i][1]);
+ tex->tg4_offsets[i][1]);
nir_tex_src src = nir_tex_src_for_ssa(nir_tex_src_offset, offset);
tex_copy->src[tex_copy->num_srcs - 1] = src;
assert(tex->dest.ssa.num_components == 3);
nir_ssa_def *size = &tex->dest.ssa;
size = nir_vec3(b, nir_channel(b, size, 1),
- nir_channel(b, size, 1),
- nir_idiv(b, nir_channel(b, size, 2),
- nir_imm_int(b, 6)));
+ nir_channel(b, size, 1),
+ nir_idiv(b, nir_channel(b, size, 2),
+ nir_imm_int(b, 6)));
nir_ssa_def_rewrite_uses_after(&tex->dest.ssa, size, size->parent_instr);
}
/* Replace the raw LOD by -FLT_MAX if the sum is 0 for all coordinates. */
nir_ssa_def *adjusted_lod =
nir_bcsel(b, is_zero, nir_imm_float(b, -FLT_MAX),
- nir_channel(b, &tex->dest.ssa, 1));
+ nir_channel(b, &tex->dest.ssa, 1));
nir_ssa_def *def =
nir_vec2(b, nir_channel(b, &tex->dest.ssa, 0), adjusted_lod);
/* ignore saturate for txf ops: these don't use samplers and can't GL_CLAMP */
if (nir_tex_instr_need_sampler(tex)) {
if ((1 << tex->sampler_index) & options->saturate_r)
- sat_mask |= (1 << 2); /* .z */
+ sat_mask |= (1 << 2); /* .z */
if ((1 << tex->sampler_index) & options->saturate_t)
- sat_mask |= (1 << 1); /* .y */
+ sat_mask |= (1 << 1); /* .y */
if ((1 << tex->sampler_index) & options->saturate_s)
- sat_mask |= (1 << 0); /* .x */
+ sat_mask |= (1 << 0); /* .x */
}
if (options->lower_index_to_offset)
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return progress;
}
strip_shadow(const struct glsl_type *type)
{
const struct glsl_type *new_type =
- glsl_sampler_type(
- glsl_get_sampler_dim(type),
- false, glsl_sampler_type_is_array(type),
- GLSL_TYPE_FLOAT);
+ glsl_sampler_type(
+ glsl_get_sampler_dim(type),
+ false, glsl_sampler_type_is_array(type),
+ GLSL_TYPE_FLOAT);
return new_type;
}
-
static const struct glsl_type *
strip_shadow_with_array(const struct glsl_type *type)
{
if (proj_index >= 0)
cmp = nir_fmul(b, cmp, nir_frcp(b, tex->src[proj_index].src.ssa));
- nir_ssa_def * result =
- nir_compare_func(b,
- sampler_binding < state->n_states ?
- state->compare_func[sampler_binding] : COMPARE_FUNC_ALWAYS,
- cmp, tex_r);
+ nir_ssa_def *result =
+ nir_compare_func(b,
+ sampler_binding < state->n_states ? state->compare_func[sampler_binding] : COMPARE_FUNC_ALWAYS,
+ cmp, tex_r);
result = nir_b2f32(b, result);
nir_ssa_def *one = nir_imm_float(b, 1.0);
nir_ssa_def *zero = nir_imm_float(b, 0.0);
- nir_ssa_def *lookup[6] = {result, NULL, NULL, NULL, zero, one};
+ nir_ssa_def *lookup[6] = { result, NULL, NULL, NULL, zero, one };
nir_ssa_def *r[4] = { result, result, result, result };
if (sampler_binding < state->n_states) {
enum compare_func *compare_func,
nir_lower_tex_shadow_swizzle *tex_swizzles)
{
- sampler_state state = {n_states, compare_func, tex_swizzles};
+ sampler_state state = { n_states, compare_func, tex_swizzles };
bool result =
- nir_shader_lower_instructions(s,
- nir_lower_tex_shadow_filter,
- nir_lower_tex_shadow_impl,
- &state);
+ nir_shader_lower_instructions(s,
+ nir_lower_tex_shadow_filter,
+ nir_lower_tex_shadow_impl,
+ &state);
return result;
}
if (yinvert)
y = nir_fsub_imm(&b, 1.0, y);
new_coord = nir_vec4(&b, nir_channel(&b, new_coord, 0),
- y,
- zero, one);
+ y,
+ zero, one);
nir_foreach_block(block, impl) {
nir_foreach_instr_safe(instr, block) {
nir_ssa_def *index = get_io_index(&b, deref);
nir_ssa_def *mask =
nir_ishl(&b, nir_imm_int(&b, 1),
- nir_iadd_imm(&b, index, base));
+ nir_iadd_imm(&b, index, base));
nir_ssa_def *cond = nir_test_mask(&b, mask, coord_replace);
nir_ssa_def *result = nir_bcsel(&b, cond, new_coord,
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
}
void
assert(s->info.stage == MESA_SHADER_FRAGMENT);
assert(coord_replace != 0);
- uint64_t replace_mask = (((uint64_t) coord_replace) << VARYING_SLOT_TEX0);
+ uint64_t replace_mask = (((uint64_t)coord_replace) << VARYING_SLOT_TEX0);
/* If no relevant texcoords are read, there's nothing to do */
if (!(s->info.inputs_read & replace_mask))
return;
/* Otherwise, we're going to replace these texcoord reads with a PNTC read */
- s->info.inputs_read &= ~(((uint64_t) coord_replace) << VARYING_SLOT_TEX0);
+ s->info.inputs_read &= ~(((uint64_t)coord_replace) << VARYING_SLOT_TEX0);
if (!point_coord_is_sysval)
s->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_PNTC);
nir_shader_instructions_pass(s, pass,
- nir_metadata_block_index | nir_metadata_dominance,
- &(struct opts) {
- .coord_replace = coord_replace,
- .point_coord_is_sysval = point_coord_is_sysval,
- });
+ nir_metadata_block_index | nir_metadata_dominance,
+ &(struct opts){
+ .coord_replace = coord_replace,
+ .point_coord_is_sysval = point_coord_is_sysval,
+ });
}
#include "nir.h"
#include "nir_builder.h"
-#define MAX_COLORS 2 /* VARYING_SLOT_COL0/COL1 */
+#define MAX_COLORS 2 /* VARYING_SLOT_COL0/COL1 */
typedef struct {
- nir_builder b;
- nir_shader *shader;
+ nir_builder b;
+ nir_shader *shader;
bool face_sysval;
struct {
- nir_variable *front; /* COLn */
- nir_variable *back; /* BFCn */
+ nir_variable *front; /* COLn */
+ nir_variable *back; /* BFCn */
} colors[MAX_COLORS];
int colors_count;
} lower_2side_state;
-
/* Lowering pass for fragment shaders to emulated two-sided-color. For
* each COLOR input, a corresponding BCOLOR input is created, and bcsel
* instruction used to select front or back color based on FACE.
slot = VARYING_SLOT_BFC1;
state->colors[i].back = create_input(
- state->shader, slot,
- state->colors[i].front->data.interpolation);
+ state->shader, slot,
+ state->colors[i].front->data.interpolation);
}
return 0;
return false;
/* replace load_input(COLn) with
- * bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
- */
+ * bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
+ */
b->cursor = nir_before_instr(&intr->instr);
/* gl_FrontFace is a boolean but the intrinsic constructor creates
- * 32-bit value by default.
- */
+ * 32-bit value by default.
+ */
nir_ssa_def *face;
if (state->face_sysval)
face = nir_load_front_face(b, 1);
nir_ssa_def *front, *back;
if (intr->intrinsic == nir_intrinsic_load_deref) {
front = nir_load_var(b, state->colors[idx].front);
- back = nir_load_var(b, state->colors[idx].back);
+ back = nir_load_var(b, state->colors[idx].back);
} else {
front = load_input(b, state->colors[idx].front);
- back = load_input(b, state->colors[idx].back);
+ back = load_input(b, state->colors[idx].back);
}
nir_ssa_def *color = nir_bcsel(b, face, front, back);
return nir_shader_instructions_pass(shader,
nir_lower_two_sided_color_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
unsigned num_components = intr->num_components;
bool aligned_mul = (align_mul == 16 &&
- align_offset + chan_size_bytes * num_components <= 16);
+ align_offset + chan_size_bytes * num_components <= 16);
if (!aligned_mul)
num_components = chans_per_vec4;
nir_component_mask_t high_channels =
low_channels << (8 / chan_size_bytes);
result = nir_bcsel(b, nir_test_mask(b, byte_offset, 8),
- nir_channels(b, result, high_channels),
- nir_channels(b, result, low_channels));
+ nir_channels(b, result, high_channels),
+ nir_channels(b, result, low_channels));
} else {
/* General fallback case: Per-result-channel bcsel-based extraction
* from two separate vec4 loads.
nir_ssa_undef_instr *und = nir_instr_as_ssa_undef(instr);
b->cursor = nir_instr_remove(&und->instr);
nir_ssa_def *zero = nir_imm_zero(b, und->def.num_components,
- und->def.bit_size);
+ und->def.bit_size);
nir_ssa_def_rewrite_uses(&und->def, zero);
return true;
}
{
return nir_shader_instructions_pass(shader, lower_undef_instr_to_zero,
nir_metadata_block_index |
- nir_metadata_dominance, NULL);
+ nir_metadata_dominance,
+ NULL);
}
*/
assert(!state->dword_packed);
load_result = nir_load_ubo_vec4(b, intr->num_components, intr->dest.ssa.bit_size,
- ubo_idx, uniform_offset, .base=nir_intrinsic_base(intr));
+ ubo_idx, uniform_offset, .base = nir_intrinsic_base(intr));
} else {
/* For PIPE_CAP_PACKED_UNIFORMS, the uniforms are packed with the
* base/offset in dword units instead of vec4 units.
*/
int multiplier = state->dword_packed ? 4 : 16;
load_result = nir_load_ubo(b, intr->num_components, intr->dest.ssa.bit_size,
- ubo_idx,
- nir_iadd_imm(b, nir_imul_imm(b, uniform_offset, multiplier),
- nir_intrinsic_base(intr) * multiplier));
+ ubo_idx,
+ nir_iadd_imm(b, nir_imul_imm(b, uniform_offset, multiplier),
+ nir_intrinsic_base(intr) * multiplier));
nir_intrinsic_instr *load = nir_instr_as_intrinsic(load_result->parent_instr);
/* If it's const, set the alignment to our known constant offset. If
if (nir_src_is_const(intr->src[0])) {
nir_intrinsic_set_align(load, NIR_ALIGN_MUL_MAX,
(nir_src_as_uint(intr->src[0]) +
- nir_intrinsic_base(intr) * multiplier) %
- NIR_ALIGN_MUL_MAX);
+ nir_intrinsic_base(intr) * multiplier) %
+ NIR_ALIGN_MUL_MAX);
} else {
- nir_intrinsic_set_align(load, MAX2(multiplier,
- intr->dest.ssa.bit_size / 8), 0);
+ nir_intrinsic_set_align(load, MAX2(multiplier, intr->dest.ssa.bit_size / 8), 0);
}
nir_intrinsic_set_range_base(load, nir_intrinsic_base(intr) * multiplier);
progress = nir_shader_instructions_pass(shader,
nir_lower_uniforms_to_ubo_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
if (progress) {
.location = -1,
};
ubo->interface_type =
- glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
- false, "__ubo0_interface");
+ glsl_interface_type(&field, 1, GLSL_INTERFACE_PACKING_STD430,
+ false, "__ubo0_interface");
}
}
* IN THE SOFTWARE.
*/
+#include "compiler/nir_types.h"
#include "nir.h"
#include "nir_builder.h"
#include "nir_deref.h"
-#include "compiler/nir_types.h"
/*
* Lowers all copy intrinsics to sequences of load/store intrinsics.
b->cursor = nir_before_instr(©->instr);
emit_deref_copy_load_store(b, dst_path.path[0], &dst_path.path[1],
- src_path.path[0], &src_path.path[1],
- nir_intrinsic_dst_access(copy),
- nir_intrinsic_src_access(copy));
+ src_path.path[0], &src_path.path[1],
+ nir_intrinsic_dst_access(copy),
+ nir_intrinsic_src_access(copy));
nir_deref_path_finish(&dst_path);
nir_deref_path_finish(&src_path);
return nir_shader_instructions_pass(shader,
lower_var_copies_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
progress = true;
var->pointer_initializer = NULL;
}
-
}
return progress;
if (impl_progress) {
progress = true;
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_pop_if(&b, NULL);
nir_store_shared(&b, nir_imm_zero(&b, chunk_comps, 32), offset,
- .align_mul=chunk_size,
- .write_mask=((1 << chunk_comps) - 1));
+ .align_mul = chunk_size,
+ .write_mask = ((1 << chunk_comps) - 1));
nir_ssa_def *new_offset = nir_iadd_imm(&b, offset, chunk_size * local_count);
nir_store_var(&b, it, new_offset, 0x1);
#include "nir_phi_builder.h"
#include "nir_vla.h"
-
struct deref_node {
struct deref_node *parent;
const struct glsl_type *type;
/* \sa foreach_deref_node_match */
static void
foreach_deref_node_worker(struct deref_node *node, nir_deref_instr **path,
- void (* cb)(struct deref_node *node,
- struct lower_variables_state *state),
+ void (*cb)(struct deref_node *node,
+ struct lower_variables_state *state),
struct lower_variables_state *state)
{
if (*path == NULL) {
*/
static void
foreach_deref_node_match(nir_deref_path *path,
- void (* cb)(struct deref_node *node,
- struct lower_variables_state *state),
+ void (*cb)(struct deref_node *node,
+ struct lower_variables_state *state),
struct lower_variables_state *state)
{
assert(path->path[0]->deref_type == nir_deref_type_var);
nir_phi_builder_finish(state.phi_builder);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
ralloc_free(state.dead_ctx);
static bool
lower_vec3_to_vec4_instr(nir_builder *b, nir_instr *instr, void *data)
{
- nir_variable_mode modes = *((nir_variable_mode*) data);
+ nir_variable_mode modes = *((nir_variable_mode *)data);
switch (instr->type) {
case nir_instr_type_deref: {
nir_deref_instr *dst = nir_src_as_deref(intrin->src[0]);
nir_deref_instr *src = nir_src_as_deref(intrin->src[0]);
/* If we convert once side of a copy and not the other, that
- * would be very bad.
- */
+ * would be very bad.
+ */
if (nir_deref_mode_may_be(dst, modes) ||
nir_deref_mode_may_be(src, modes)) {
- assert(nir_deref_mode_must_be(dst, modes));
- assert(nir_deref_mode_must_be(src, modes));
+ assert(nir_deref_mode_must_be(dst, modes));
+ assert(nir_deref_mode_must_be(src, modes));
}
break;
}
progress |= nir_shader_instructions_pass(shader,
lower_vec3_to_vec4_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&modes);
return progress;
unsigned num_components = nir_dest_num_components(vec->dest.dest);
assert(num_components == nir_op_infos[vec->op].num_inputs);
unsigned write_mask = 0;
- unsigned swiz[NIR_MAX_VEC_COMPONENTS] = {0};
+ unsigned swiz[NIR_MAX_VEC_COMPONENTS] = { 0 };
for (unsigned i = start_idx; i < num_components; i++) {
if (vec->src[i].src.ssa == src) {
nir_rewrite_uses_to_load_reg(b, &vec->dest.dest.ssa, reg);
} else {
/* Otherwise, we replace with a swizzle */
- unsigned swiz[NIR_MAX_VEC_COMPONENTS] = {0};
+ unsigned swiz[NIR_MAX_VEC_COMPONENTS] = { 0 };
for (unsigned i = 0; i < num_components; ++i) {
swiz[i] = vec->src[i].swizzle[0];
return nir_shader_instructions_pass(shader, lower,
nir_metadata_block_index |
- nir_metadata_dominance, &data);
+ nir_metadata_dominance,
+ &data);
}
bool
nir_lower_viewport_transform(nir_shader *shader)
{
- assert((shader->info.stage == MESA_SHADER_VERTEX)
- || (shader->info.stage == MESA_SHADER_GEOMETRY)
- || (shader->info.stage == MESA_SHADER_TESS_EVAL));
+ assert((shader->info.stage == MESA_SHADER_VERTEX) || (shader->info.stage == MESA_SHADER_GEOMETRY) || (shader->info.stage == MESA_SHADER_TESS_EVAL));
return nir_shader_instructions_pass(shader,
lower_viewport_transform_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
* IN THE SOFTWARE.
*/
+#include "program/prog_instruction.h"
#include "nir.h"
#include "nir_builder.h"
-#include "program/prog_instruction.h"
/**
* This pass adds <0.5, 0.5> to all uses of gl_FragCoord.
return nir_shader_instructions_pass(shader,
lower_wpos_center_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
typedef struct {
const nir_lower_wpos_ytransform_options *options;
- nir_shader *shader;
- nir_builder b;
+ nir_shader *shader;
+ nir_builder b;
nir_variable *transform;
} lower_wpos_ytransform_state;
*/
if (invert) {
/* wpos_temp.y = wpos_input * wpostrans.xxxx + wpostrans.yyyy */
- wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1),
- nir_channel(b, wpostrans, 0)),
- nir_channel(b, wpostrans, 1));
+ wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1), nir_channel(b, wpostrans, 0)),
+ nir_channel(b, wpostrans, 1));
} else {
/* wpos_temp.y = wpos_input * wpostrans.zzzz + wpostrans.wwww */
- wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1),
- nir_channel(b, wpostrans, 2)),
- nir_channel(b, wpostrans, 3));
+ wpos_temp_y = nir_fadd(b, nir_fmul(b, nir_channel(b, wpos_temp, 1), nir_channel(b, wpostrans, 2)),
+ nir_channel(b, wpostrans, 3));
}
wpos_temp = nir_vec4(b,
offset = nir_ssa_for_src(b, intr->src[offset_src], 2);
flip_y = nir_fmul(b, nir_channel(b, offset, 1),
- nir_channel(b, get_transform(state), 0));
+ nir_channel(b, get_transform(state), 0));
nir_instr_rewrite_src(&intr->instr, &intr->src[offset_src],
nir_src_for_ssa(nir_vec2(b, nir_channel(b, offset, 0),
- flip_y)));
+ flip_y)));
}
-
static void
lower_load_sample_pos(lower_wpos_ytransform_state *state,
nir_intrinsic_instr *intr)
nir_ssa_def *neg_scale = nir_channel(b, get_transform(state), 2);
/* Either y or 1-y for scale equal to 1 or -1 respectively. */
nir_ssa_def *flipped_y =
- nir_fadd(b, nir_fmax(b, neg_scale, nir_imm_float(b, 0.0)),
- nir_fmul(b, nir_channel(b, pos, 1), scale));
+ nir_fadd(b, nir_fmax(b, neg_scale, nir_imm_float(b, 0.0)),
+ nir_fmul(b, nir_channel(b, pos, 1), scale));
nir_ssa_def *flipped_pos = nir_vec2(b, nir_channel(b, pos, 0), flipped_y);
nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, flipped_pos,
return nir_shader_instructions_pass(shader,
lower_wpos_ytransform_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
b->cursor = nir_before_instr(&intr->instr);
- assert(!info->has_dest); /* expecting only store intrinsics */
+ assert(!info->has_dest); /* expecting only store intrinsics */
- unsigned num_srcs = info->num_srcs;
- unsigned value_idx = value_src(intr->intrinsic);
+ unsigned num_srcs = info->num_srcs;
+ unsigned value_idx = value_src(intr->intrinsic);
unsigned offset_idx = offset_src(intr->intrinsic);
- unsigned num_comp = nir_intrinsic_src_components(intr, value_idx);
+ unsigned num_comp = nir_intrinsic_src_components(intr, value_idx);
unsigned wrmask = nir_intrinsic_write_mask(intr);
while (wrmask) {
unsigned first_component = ffs(wrmask) - 1;
unsigned length = ffs(~(wrmask >> first_component)) - 1;
- nir_ssa_def *value = nir_ssa_for_src(b, intr->src[value_idx], num_comp);
+ nir_ssa_def *value = nir_ssa_for_src(b, intr->src[value_idx], num_comp);
nir_ssa_def *offset = nir_ssa_for_src(b, intr->src[offset_idx], 1);
/* swizzle out the consecutive components that we'll store
/* and create the replacement intrinsic: */
nir_intrinsic_instr *new_intr =
- nir_intrinsic_instr_create(b->shader, intr->intrinsic);
+ nir_intrinsic_instr_create(b->shader, intr->intrinsic);
nir_intrinsic_copy_const_indices(new_intr, intr);
nir_intrinsic_set_write_mask(new_intr, BITFIELD_MASK(length));
unsigned offset_adj = offset_units * first_component;
if (nir_intrinsic_has_base(intr)) {
nir_intrinsic_set_base(new_intr,
- nir_intrinsic_base(intr) + offset_adj);
+ nir_intrinsic_base(intr) + offset_adj);
} else {
offset = nir_iadd(b, offset,
- nir_imm_intN_t(b, offset_adj, offset->bit_size));
+ nir_imm_intN_t(b, offset_adj, offset->bit_size));
}
new_intr->num_components = length;
return nir_shader_instructions_pass(shader,
nir_lower_wrmasks_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
}
assert(util_is_power_of_two_nonzero(div));
switch (val.def->parent_instr->type) {
- case nir_instr_type_load_const: {
- nir_load_const_instr *load =
- nir_instr_as_load_const(val.def->parent_instr);
- nir_alu_type base_type = nir_alu_type_get_base_type(val_type);
-
- if (base_type == nir_type_uint) {
- assert(val.comp < load->def.num_components);
- uint64_t ival = nir_const_value_as_uint(load->value[val.comp],
- load->def.bit_size);
- *mod = ival % div;
- return true;
- } else if (base_type == nir_type_int) {
- assert(val.comp < load->def.num_components);
- int64_t ival = nir_const_value_as_int(load->value[val.comp],
- load->def.bit_size);
+ case nir_instr_type_load_const: {
+ nir_load_const_instr *load =
+ nir_instr_as_load_const(val.def->parent_instr);
+ nir_alu_type base_type = nir_alu_type_get_base_type(val_type);
+
+ if (base_type == nir_type_uint) {
+ assert(val.comp < load->def.num_components);
+ uint64_t ival = nir_const_value_as_uint(load->value[val.comp],
+ load->def.bit_size);
+ *mod = ival % div;
+ return true;
+ } else if (base_type == nir_type_int) {
+ assert(val.comp < load->def.num_components);
+ int64_t ival = nir_const_value_as_int(load->value[val.comp],
+ load->def.bit_size);
+
+ /* whole analysis collapses the moment we allow negative values */
+ if (ival < 0)
+ return false;
+
+ *mod = ((uint64_t)ival) % div;
+ return true;
+ }
+
+ break;
+ }
+
+ case nir_instr_type_alu: {
+ nir_alu_instr *alu = nir_instr_as_alu(val.def->parent_instr);
+
+ if (alu->dest.dest.ssa.num_components != 1)
+ return false;
+
+ switch (alu->op) {
+ case nir_op_ishr: {
+ if (nir_src_is_const(alu->src[1].src)) {
+ assert(alu->src[1].src.ssa->num_components == 1);
+ uint64_t shift = nir_src_as_uint(alu->src[1].src);
+
+ if (util_last_bit(div) + shift > 32)
+ break;
- /* whole analysis collapses the moment we allow negative values */
- if (ival < 0)
+ nir_alu_type type0 = nir_alu_src_type(alu, 0);
+ if (!nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div << shift, mod))
return false;
- *mod = ((uint64_t)ival) % div;
+ *mod >>= shift;
return true;
}
-
break;
}
- case nir_instr_type_alu: {
- nir_alu_instr *alu = nir_instr_as_alu(val.def->parent_instr);
-
- if (alu->dest.dest.ssa.num_components != 1)
+ case nir_op_iadd: {
+ unsigned mod0;
+ nir_alu_type type0 = nir_alu_src_type(alu, 0);
+ if (!nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div, &mod0))
return false;
- switch (alu->op) {
- case nir_op_ishr: {
- if (nir_src_is_const(alu->src[1].src)) {
- assert(alu->src[1].src.ssa->num_components == 1);
- uint64_t shift = nir_src_as_uint(alu->src[1].src);
-
- if (util_last_bit(div) + shift > 32)
- break;
-
- nir_alu_type type0 = nir_alu_src_type(alu, 0);
- if (!nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div << shift, mod))
- return false;
-
- *mod >>= shift;
- return true;
- }
- break;
- }
+ unsigned mod1;
+ nir_alu_type type1 = nir_alu_src_type(alu, 1);
+ if (!nir_mod_analysis(nir_alu_arg(alu, 1, val.comp), type1, div, &mod1))
+ return false;
- case nir_op_iadd: {
- unsigned mod0;
- nir_alu_type type0 = nir_alu_src_type(alu, 0);
- if (!nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div, &mod0))
- return false;
+ *mod = (mod0 + mod1) % div;
+ return true;
+ }
- unsigned mod1;
- nir_alu_type type1 = nir_alu_src_type(alu, 1);
- if (!nir_mod_analysis(nir_alu_arg(alu, 1, val.comp), type1, div, &mod1))
- return false;
+ case nir_op_ishl: {
+ if (nir_src_is_const(alu->src[1].src)) {
+ assert(alu->src[1].src.ssa->num_components == 1);
+ uint64_t shift = nir_src_as_uint(alu->src[1].src);
- *mod = (mod0 + mod1) % div;
+ if ((div >> shift) == 0) {
+ *mod = 0;
return true;
}
+ nir_alu_type type0 = nir_alu_src_type(alu, 0);
+ return nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div >> shift, mod);
+ }
+ break;
+ }
- case nir_op_ishl: {
- if (nir_src_is_const(alu->src[1].src)) {
- assert(alu->src[1].src.ssa->num_components == 1);
- uint64_t shift = nir_src_as_uint(alu->src[1].src);
-
- if ((div >> shift) == 0) {
- *mod = 0;
- return true;
- }
- nir_alu_type type0 = nir_alu_src_type(alu, 0);
- return nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div >> shift, mod);
- }
- break;
- }
-
- case nir_op_imul_32x16: /* multiply 32-bits with low 16-bits */
- case nir_op_imul: {
- unsigned mod0;
- nir_alu_type type0 = nir_alu_src_type(alu, 0);
- bool s1 = nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div, &mod0);
-
- if (s1 && (mod0 == 0)) {
- *mod = 0;
- return true;
- }
+ case nir_op_imul_32x16: /* multiply 32-bits with low 16-bits */
+ case nir_op_imul: {
+ unsigned mod0;
+ nir_alu_type type0 = nir_alu_src_type(alu, 0);
+ bool s1 = nir_mod_analysis(nir_alu_arg(alu, 0, val.comp), type0, div, &mod0);
- /* if divider is larger than 2nd source max (interpreted) value
- * then modulo of multiplication is unknown
- */
- if (alu->op == nir_op_imul_32x16 && div > (1u << 16))
- return false;
+ if (s1 && (mod0 == 0)) {
+ *mod = 0;
+ return true;
+ }
- unsigned mod1;
- nir_alu_type type1 = nir_alu_src_type(alu, 1);
- bool s2 = nir_mod_analysis(nir_alu_arg(alu, 1, val.comp), type1, div, &mod1);
+ /* if divider is larger than 2nd source max (interpreted) value
+ * then modulo of multiplication is unknown
+ */
+ if (alu->op == nir_op_imul_32x16 && div > (1u << 16))
+ return false;
- if (s2 && (mod1 == 0)) {
- *mod = 0;
- return true;
- }
+ unsigned mod1;
+ nir_alu_type type1 = nir_alu_src_type(alu, 1);
+ bool s2 = nir_mod_analysis(nir_alu_arg(alu, 1, val.comp), type1, div, &mod1);
- if (!s1 || !s2)
- return false;
+ if (s2 && (mod1 == 0)) {
+ *mod = 0;
+ return true;
+ }
- *mod = (mod0 * mod1) % div;
- return true;
- }
+ if (!s1 || !s2)
+ return false;
- default:
- break;
- }
- break;
+ *mod = (mod0 * mod1) % div;
+ return true;
}
default:
break;
+ }
+ break;
+ }
+
+ default:
+ break;
}
return false;
if (use->parent_instr->type != nir_instr_type_alu)
continue;
-
nir_alu_instr *use_alu = nir_instr_as_alu(use->parent_instr);
/* Figure out which source we're actually looking at */
}
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return progress;
}
{
return nir_shader_instructions_pass(shader, normalize_cubemap_coords,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
}
if ((var->data.mode == nir_var_uniform ||
- var->data.mode == nir_var_image) && read)
+ var->data.mode == nir_var_image) &&
+ read)
_mesa_set_add(state->vars_read, var);
if ((var->data.mode == nir_var_uniform ||
- var->data.mode == nir_var_image) && write)
+ var->data.mode == nir_var_image) &&
+ write)
_mesa_set_add(state->vars_written, var);
break;
if (progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_loop_analysis);
}
-
return progress;
}
state.images_read |= state.buffers_read;
}
- nir_foreach_variable_with_modes(var, shader, nir_var_uniform |
- nir_var_mem_ubo |
- nir_var_mem_ssbo |
- nir_var_image)
+ nir_foreach_variable_with_modes(var, shader, nir_var_uniform | nir_var_mem_ubo | nir_var_mem_ssbo | nir_var_image)
var_progress |= process_variable(&state, var);
nir_foreach_function_impl(impl, shader) {
if (var_progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs |
+ nir_metadata_loop_analysis);
}
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_builder b;
bool progress;
-
/* Allocator and freelist to reuse structs between functions. */
void *lin_ctx;
struct list_head freelist;
static void
combine_stores(struct combine_stores_state *state,
- struct combined_store *combo)
+ struct combined_store *combo)
{
assert(combo->latest);
assert(combo->latest->intrinsic == nir_intrinsic_store_deref);
/* Build a new vec, to be used as source for the combined store. As it
* gets build, remove previous stores that are not needed anymore.
*/
- nir_ssa_scalar comps[NIR_MAX_VEC_COMPONENTS] = {0};
+ nir_ssa_scalar comps[NIR_MAX_VEC_COMPONENTS] = { 0 };
unsigned num_components = glsl_get_vector_elements(combo->dst->type);
unsigned bit_size = combo->latest->src[1].ssa->bit_size;
for (unsigned i = 0; i < num_components; i++) {
static void
combine_stores_with_deref(struct combine_stores_state *state,
- nir_deref_instr *deref)
+ nir_deref_instr *deref)
{
if (!nir_deref_mode_may_be(deref, state->modes))
return;
static void
combine_stores_with_modes(struct combine_stores_state *state,
- nir_variable_mode modes)
+ nir_variable_mode modes)
{
if ((state->modes & modes) == 0)
return;
nir_instr_remove(&prev_store->instr);
} else {
assert(glsl_type_is_vector(
- nir_src_as_deref(prev_store->src[0])->type));
+ nir_src_as_deref(prev_store->src[0])->type));
nir_component_mask_t prev_mask = nir_intrinsic_write_mask(prev_store);
nir_intrinsic_set_write_mask(prev_store, prev_mask & ~(1 << i));
}
nir_foreach_instr_safe(instr, block) {
if (instr->type == nir_instr_type_call) {
combine_stores_with_modes(state, nir_var_shader_out |
- nir_var_shader_temp |
- nir_var_function_temp |
- nir_var_mem_ssbo |
- nir_var_mem_shared |
- nir_var_mem_global);
+ nir_var_shader_temp |
+ nir_var_function_temp |
+ nir_var_mem_ssbo |
+ nir_var_mem_shared |
+ nir_var_mem_global);
continue;
}
case nir_intrinsic_report_ray_intersection:
combine_stores_with_modes(state, nir_var_mem_ssbo |
- nir_var_mem_global |
- nir_var_shader_call_data |
- nir_var_ray_hit_attrib);
+ nir_var_mem_global |
+ nir_var_shader_call_data |
+ nir_var_ray_hit_attrib);
break;
case nir_intrinsic_ignore_ray_intersection:
case nir_intrinsic_terminate_ray:
combine_stores_with_modes(state, nir_var_mem_ssbo |
- nir_var_mem_global |
- nir_var_shader_call_data);
+ nir_var_mem_global |
+ nir_var_shader_call_data);
break;
case nir_intrinsic_load_deref: {
if (state->progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
{
void *mem_ctx = ralloc_context(NULL);
struct combine_stores_state state = {
- .modes = modes,
+ .modes = modes,
.lin_ctx = linear_zalloc_parent(mem_ctx, 0),
};
* IN THE SOFTWARE.
*/
+#include "util/u_vector.h"
+#include "nir_builder.h"
#include "nir_instr_set.h"
#include "nir_search_helpers.h"
-#include "nir_builder.h"
-#include "util/u_vector.h"
/* Partial redundancy elimination of compares
*
{
struct block_instructions *n;
- while ((n = (struct block_instructions *) exec_list_pop_head(&bq->blocks)) != NULL) {
+ while ((n = (struct block_instructions *)exec_list_pop_head(&bq->blocks)) != NULL) {
u_vector_finish(&n->instructions);
free(n);
}
- while ((n = (struct block_instructions *) exec_list_pop_head(&bq->reusable_blocks)) != NULL) {
+ while ((n = (struct block_instructions *)exec_list_pop_head(&bq->reusable_blocks)) != NULL) {
free(n);
}
}
push_block(struct block_queue *bq)
{
struct block_instructions *bi =
- (struct block_instructions *) exec_list_pop_head(&bq->reusable_blocks);
+ (struct block_instructions *)exec_list_pop_head(&bq->reusable_blocks);
if (bi == NULL) {
bi = calloc(1, sizeof(struct block_instructions));
nir_ssa_def *const b = nir_ssa_for_alu_src(bld, orig_cmp, 1);
nir_ssa_def *const fadd = zero_on_left
- ? nir_fadd(bld, b, nir_fneg(bld, a))
- : nir_fadd(bld, a, nir_fneg(bld, b));
+ ? nir_fadd(bld, b, nir_fneg(bld, a))
+ : nir_fadd(bld, a, nir_fneg(bld, b));
nir_ssa_def *const zero =
nir_imm_floatN_t(bld, 0.0, orig_add->dest.dest.ssa.bit_size);
nir_ssa_def *const cmp = zero_on_left
- ? nir_build_alu(bld, orig_cmp->op, zero, fadd, NULL, NULL)
- : nir_build_alu(bld, orig_cmp->op, fadd, zero, NULL, NULL);
+ ? nir_build_alu(bld, orig_cmp->op, zero, fadd, NULL, NULL)
+ : nir_build_alu(bld, orig_cmp->op, fadd, zero, NULL, NULL);
/* Generating extra moves of the results is the easy way to make sure the
* writemasks match the original instructions. Later optimization passes
if (alu->dest.dest.ssa.num_components != 1)
continue;
- static const uint8_t swizzle[NIR_MAX_VEC_COMPONENTS] = {0};
+ static const uint8_t swizzle[NIR_MAX_VEC_COMPONENTS] = { 0 };
switch (alu->op) {
case nir_op_fadd: {
* instructions that dominate it.
*/
struct block_instructions *b =
- (struct block_instructions *) exec_list_get_head_raw(&bq->blocks);
+ (struct block_instructions *)exec_list_get_head_raw(&bq->blocks);
while (b->node.next != NULL) {
nir_alu_instr **a;
bool rewrote_compare = false;
- u_vector_foreach(a, &b->instructions) {
+ u_vector_foreach(a, &b->instructions)
+ {
nir_alu_instr *const cmp = *a;
if (cmp == NULL)
break;
}
- b = (struct block_instructions *) b->node.next;
+ b = (struct block_instructions *)b->node.next;
}
break;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* IN THE SOFTWARE.
*/
+#include <math.h>
#include "nir.h"
#include "nir_builder.h"
#include "nir_constant_expressions.h"
#include "nir_deref.h"
-#include <math.h>
/*
* Implements SSA-based constant folding.
if (src_instr->type != nir_instr_type_load_const)
return false;
- nir_load_const_instr* load_const = nir_instr_as_load_const(src_instr);
+ nir_load_const_instr *load_const = nir_instr_as_load_const(src_instr);
for (unsigned j = 0; j < nir_ssa_alu_instr_src_components(alu, i);
j++) {
b->cursor = nir_before_instr(&alu->instr);
nir_ssa_def *imm = nir_build_imm(b, alu->dest.dest.ssa.num_components,
- alu->dest.dest.ssa.bit_size,
- dest);
+ alu->dest.dest.ssa.bit_size,
+ dest);
nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, imm);
nir_instr_remove(&alu->instr);
nir_instr_free(&alu->instr);
uint64_t idx = nir_src_as_uint(p->arr.index);
if (c->num_elements > 0) {
- assert(glsl_type_is_array(path.path[i-1]->type));
+ assert(glsl_type_is_array(path.path[i - 1]->type));
if (idx >= c->num_elements)
goto fail;
c = c->elements[idx];
} else {
- assert(glsl_type_is_vector(path.path[i-1]->type));
+ assert(glsl_type_is_vector(path.path[i - 1]->type));
assert(glsl_type_is_scalar(p->type));
if (idx >= NIR_MAX_VEC_COMPONENTS)
goto fail;
}
case nir_deref_type_struct:
- assert(glsl_type_is_struct(path.path[i-1]->type));
+ assert(glsl_type_is_struct(path.path[i - 1]->type));
assert(v == NULL && c->num_elements > 0);
if (p->strct.index >= c->num_elements)
goto fail;
if (v) {
b->cursor = nir_before_instr(&intrin->instr);
nir_ssa_def *val = nir_build_imm(b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size, v);
+ intrin->dest.ssa.bit_size, v);
nir_ssa_def_rewrite_uses(&intrin->dest.ssa, val);
nir_instr_remove(&intrin->instr);
return true;
nir_ssa_def *val;
if (offset >= range) {
val = nir_ssa_undef(b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size);
+ intrin->dest.ssa.bit_size);
} else {
nir_const_value imm[NIR_MAX_VEC_COMPONENTS];
memset(imm, 0, sizeof(imm));
- uint8_t *data = (uint8_t*)b->shader->constant_data + base;
+ uint8_t *data = (uint8_t *)b->shader->constant_data + base;
for (unsigned i = 0; i < intrin->num_components; i++) {
unsigned bytes = intrin->dest.ssa.bit_size / 8;
bytes = MIN2(bytes, range - offset);
offset += bytes;
}
val = nir_build_imm(b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size, imm);
+ intrin->dest.ssa.bit_size, imm);
}
nir_ssa_def_rewrite_uses(&intrin->dest.ssa, val);
nir_instr_remove(&intrin->instr);
bool progress = nir_shader_instructions_pass(shader, try_fold_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
/* This doesn't free the constant data if there are no constant loads because
/* Destination in all of store_deref, copy_deref and the atomics is src[0]. */
nir_deref_instr *dst = nir_src_as_deref(intrin->src[0]);
- uintptr_t mask = intrin->intrinsic == nir_intrinsic_store_deref ?
- nir_intrinsic_write_mask(intrin) : (1 << glsl_get_vector_elements(dst->type)) - 1;
+ uintptr_t mask = intrin->intrinsic == nir_intrinsic_store_deref ? nir_intrinsic_write_mask(intrin) : (1 << glsl_get_vector_elements(dst->type)) - 1;
struct hash_entry *ht_entry = _mesa_hash_table_search(written->derefs, dst);
if (ht_entry)
_mesa_hash_table_search_pre_hashed(written->derefs, new_entry->hash,
new_entry->key);
if (old_entry) {
- nir_component_mask_t merged = (uintptr_t) new_entry->data |
- (uintptr_t) old_entry->data;
- old_entry->data = (void *) ((uintptr_t) merged);
+ nir_component_mask_t merged = (uintptr_t)new_entry->data |
+ (uintptr_t)old_entry->data;
+ old_entry->data = (void *)((uintptr_t)merged);
} else {
_mesa_hash_table_insert_pre_hashed(written->derefs, new_entry->hash,
new_entry->key, new_entry->data);
struct copies_dynarray *copies_array;
if (copies_owns_ht_entry(copies, ht_entry)) {
/* The array already exists so just return it */
- copies_array = (struct copies_dynarray *) ht_entry->data;
+ copies_array = (struct copies_dynarray *)ht_entry->data;
} else {
/* Clone the array and set the data value for future access */
copies_array = get_copies_dynarray(state);
return copies_array;
}
-
static struct copy_entry *
copy_entry_create(struct copy_prop_var_state *state,
struct copies *copies, nir_deref_and_path *deref)
deref->_path->path[0]->var->data.mode == nir_var_mem_shared) {
hash_table_foreach(copies->ht, ht_entry) {
- nir_variable *var = (nir_variable *) ht_entry->key;
+ nir_variable *var = (nir_variable *)ht_entry->key;
if (deref->_path->path[0]->deref_type == nir_deref_type_var &&
var->data.mode != deref->_path->path[0]->var->data.mode)
continue;
static void
apply_barrier_for_modes_to_dynarr(struct util_dynarray *copies_array,
- nir_variable_mode modes)
+ nir_variable_mode modes)
{
util_dynarray_foreach_reverse(copies_array, struct copy_entry, iter) {
if (nir_deref_mode_may_be(iter->dst.instr, modes) ||
assert(entry->src.ssa.component[index] <
entry->src.ssa.def[index]->num_components);
nir_ssa_def *def = nir_channel(b, entry->src.ssa.def[index],
- entry->src.ssa.component[index]);
+ entry->src.ssa.component[index]);
- *value = (struct value) {
+ *value = (struct value){
.is_ssa = true,
{
- .ssa = {
- .def = { def },
- .component = { 0 },
- },
+ .ssa = {
+ .def = { def },
+ .component = { 0 },
+ },
}
};
}
}
- hash_table_foreach (written->derefs, entry) {
+ hash_table_foreach(written->derefs, entry) {
nir_deref_instr *deref_written = (nir_deref_instr *)entry->key;
- nir_deref_and_path deref = {deref_written, NULL};
+ nir_deref_and_path deref = { deref_written, NULL };
kill_aliases(state, copies, &deref, (uintptr_t)entry->data);
}
}
{
hash_table_foreach(copies->ht, ht_entry) {
struct util_dynarray *copies_array =
- &((struct copies_dynarray *) ht_entry->data)->arr;
+ &((struct copies_dynarray *)ht_entry->data)->arr;
util_dynarray_foreach(copies_array, struct copy_entry, iter)
print_copy_entry(iter);
dump_instr(instr);
if (instr->type == nir_instr_type_call) {
- if (debug) dump_instr(instr);
- apply_barrier_for_modes(state, copies, nir_var_shader_out |
- nir_var_shader_temp |
- nir_var_function_temp |
- nir_var_mem_ssbo |
- nir_var_mem_shared |
- nir_var_mem_global);
- if (debug) dump_copy_entries(copies);
+ if (debug)
+ dump_instr(instr);
+ apply_barrier_for_modes(state, copies, nir_var_shader_out | nir_var_shader_temp | nir_var_function_temp | nir_var_mem_ssbo | nir_var_mem_shared | nir_var_mem_global);
+ if (debug)
+ dump_copy_entries(copies);
continue;
}
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
case nir_intrinsic_barrier:
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
if (nir_intrinsic_memory_semantics(intrin) & NIR_MEMORY_ACQUIRE)
apply_barrier_for_modes(state, copies, nir_intrinsic_memory_modes(intrin));
case nir_intrinsic_emit_vertex:
case nir_intrinsic_emit_vertex_with_counter:
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
apply_barrier_for_modes(state, copies, nir_var_shader_out);
break;
case nir_intrinsic_report_ray_intersection:
- apply_barrier_for_modes(state, copies, nir_var_mem_ssbo |
- nir_var_mem_global |
- nir_var_shader_call_data |
- nir_var_ray_hit_attrib);
+ apply_barrier_for_modes(state, copies, nir_var_mem_ssbo | nir_var_mem_global | nir_var_shader_call_data | nir_var_ray_hit_attrib);
break;
case nir_intrinsic_ignore_ray_intersection:
case nir_intrinsic_terminate_ray:
- apply_barrier_for_modes(state, copies, nir_var_mem_ssbo |
- nir_var_mem_global |
- nir_var_shader_call_data);
+ apply_barrier_for_modes(state, copies, nir_var_mem_ssbo | nir_var_mem_global | nir_var_shader_call_data);
break;
case nir_intrinsic_load_deref: {
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
if (nir_intrinsic_access(intrin) & ACCESS_VOLATILE)
break;
- nir_deref_and_path src = {nir_src_as_deref(intrin->src[0]), NULL};
+ nir_deref_and_path src = { nir_src_as_deref(intrin->src[0]), NULL };
/* If this is a load from a read-only mode, then all this pass would
* do is combine redundant loads and CSE should be more efficient for
struct copy_entry *src_entry =
lookup_entry_for_deref(state, copies, &src,
nir_derefs_a_contains_b_bit, &src_entry_equal);
- struct value value = {0};
+ struct value value = { 0 };
if (try_load_from_entry(state, src_entry, b, intrin, &src, &value)) {
if (value.is_ssa) {
/* lookup_load has already ensured that we get a single SSA
}
case nir_intrinsic_store_deref: {
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
- nir_deref_and_path dst = {nir_src_as_deref(intrin->src[0]), NULL};
+ nir_deref_and_path dst = { nir_src_as_deref(intrin->src[0]), NULL };
assert(glsl_type_is_vector_or_scalar(dst.instr->type));
/* Direct array_derefs of vectors operate on the vectors (the parent
nir_instr_remove(instr);
state->progress = true;
} else {
- struct value value = {0};
+ struct value value = { 0 };
value_set_ssa_components(&value, intrin->src[1].ssa,
intrin->num_components);
unsigned wrmask = nir_intrinsic_write_mask(intrin);
}
case nir_intrinsic_copy_deref: {
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
- nir_deref_and_path dst = {nir_src_as_deref(intrin->src[0]), NULL};
- nir_deref_and_path src = {nir_src_as_deref(intrin->src[1]), NULL};
+ nir_deref_and_path dst = { nir_src_as_deref(intrin->src[0]), NULL };
+ nir_deref_and_path src = { nir_src_as_deref(intrin->src[1]), NULL };
/* The copy_deref intrinsic doesn't keep track of num_components, so
* get it ourselves.
state->progress = true;
} else {
- value = (struct value) {
+ value = (struct value){
.is_ssa = false,
{ .deref = src },
};
case nir_intrinsic_execute_callable:
case nir_intrinsic_rt_trace_ray:
case nir_intrinsic_rt_execute_callable: {
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
nir_deref_and_path payload = {
- nir_src_as_deref(*nir_get_shader_call_payload_src(intrin)), NULL};
+ nir_src_as_deref(*nir_get_shader_call_payload_src(intrin)), NULL
+ };
nir_component_mask_t full_mask = (1 << glsl_get_vector_elements(payload.instr->type)) - 1;
kill_aliases(state, copies, &payload, full_mask);
break;
case nir_intrinsic_memcpy_deref:
case nir_intrinsic_deref_atomic:
case nir_intrinsic_deref_atomic_swap:
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
- nir_deref_and_path dst = {nir_src_as_deref(intrin->src[0]), NULL};
+ nir_deref_and_path dst = { nir_src_as_deref(intrin->src[0]), NULL };
unsigned num_components = glsl_get_vector_elements(dst.instr->type);
unsigned full_mask = (1 << num_components) - 1;
kill_aliases(state, copies, &dst, full_mask);
break;
case nir_intrinsic_store_deref_block_intel: {
- if (debug) dump_instr(instr);
+ if (debug)
+ dump_instr(instr);
/* Invalidate the whole variable (or cast) and anything that alias
* with it.
*/
- nir_deref_and_path dst = {nir_src_as_deref(intrin->src[0]), NULL};
+ nir_deref_and_path dst = { nir_src_as_deref(intrin->src[0]), NULL };
while (nir_deref_instr_parent(dst.instr))
dst.instr = nir_deref_instr_parent(dst.instr);
assert(dst.instr->deref_type == nir_deref_type_var ||
continue; /* To skip the debug below. */
}
- if (debug) dump_copy_entries(copies);
+ if (debug)
+ dump_copy_entries(copies);
}
}
if (state.progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
return progress;
}
-
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
if (instr->type == nir_instr_type_intrinsic) {
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (!(nir_intrinsic_infos[intrin->intrinsic].flags &
- NIR_INTRINSIC_CAN_ELIMINATE))
+ NIR_INTRINSIC_CAN_ELIMINATE))
return false;
switch (intrin->intrinsic) {
if (intrin->intrinsic == nir_intrinsic_load_deref) {
nir_deref_instr *deref = nir_src_as_deref(intrin->src[0]);
if (!nir_deref_mode_may_be(deref, nir_var_mem_ssbo |
- nir_var_mem_shared |
- nir_var_mem_global |
- nir_var_shader_out))
+ nir_var_mem_shared |
+ nir_var_mem_global |
+ nir_var_shader_out))
break;
}
if (nir_intrinsic_access(intrin) & ACCESS_CAN_REORDER)
nir_block *next = nir_cf_node_as_block(nir_cf_node_next(cur));
if (next->predecessors->entries == 0 &&
(!exec_list_is_empty(&next->instr_list) ||
- !exec_node_is_tail_sentinel(next->cf_node.node.next))) {
+ !exec_node_is_tail_sentinel(next->cf_node.node.next))) {
remove_after_cf_node(cur);
return true;
}
nir_foreach_instr_safe(instr, block) {
if (instr->type == nir_instr_type_call) {
clear_unused_for_modes(&unused_writes, nir_var_shader_out |
- nir_var_shader_temp |
- nir_var_function_temp |
- nir_var_mem_ssbo |
- nir_var_mem_shared |
- nir_var_mem_global);
+ nir_var_shader_temp |
+ nir_var_function_temp |
+ nir_var_mem_ssbo |
+ nir_var_mem_shared |
+ nir_var_mem_global);
continue;
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
struct match_node *node = rzalloc_size(state->dead_ctx,
sizeof(struct match_node) +
- num_children * sizeof(struct match_node *));
+ num_children * sizeof(struct match_node *));
node->num_children = num_children;
node->src_wildcard_idx = -1;
node->first_src_read = UINT32_MAX;
nir_deref_path *deref_path, int arr_idx,
nir_deref_instr *dst)
{
- for (int i = 0; ; i++) {
+ for (int i = 0;; i++) {
nir_deref_instr *b = base_path->path[i];
nir_deref_instr *d = deref_path->path[i];
/* They have to be the same length */
/* This can happen if one is a deref_array and the other a wildcard */
if (b->deref_type != d->deref_type)
- return false;;
+ return false;
+ ;
switch (b->deref_type) {
case nir_deref_type_var:
const_b_idx && b_idx == 0 &&
const_d_idx && d_idx == arr_idx &&
glsl_get_length(nir_deref_instr_parent(b)->type) ==
- glsl_get_length(nir_deref_instr_parent(dst)->type)) {
+ glsl_get_length(nir_deref_instr_parent(dst)->type)) {
*path_array_idx = i;
continue;
}
if (src_node->last_overwritten <= dst_node->first_src_read) {
nir_copy_deref(b, build_wildcard_deref(b, &dst_path, idx),
- build_wildcard_deref(b, &dst_node->first_src_path,
- dst_node->src_wildcard_idx));
+ build_wildcard_deref(b, &dst_node->first_src_path,
+ dst_node->src_wildcard_idx));
foreach_aliasing_node(&dst_path, clobber, state);
return true;
}
continue;
}
-reset:
+ reset:
dst_node->next_array_idx = 0;
dst_node->src_wildcard_idx = -1;
dst_node->last_successful_write = 0;
*/
if (src_deref &&
!nir_deref_mode_must_be(src_deref, nir_var_function_temp |
- nir_var_read_only_modes)) {
+ nir_var_read_only_modes)) {
src_deref = NULL;
}
nir_deref_instr_has_indirect(dst_deref) ||
!glsl_type_is_vector_or_scalar(src_deref->type) ||
glsl_get_bare_type(src_deref->type) !=
- glsl_get_bare_type(dst_deref->type))) {
+ glsl_get_bare_type(dst_deref->type))) {
src_deref = NULL;
}
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_instr_remove(&store_intrin->instr);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_loop_analysis |
- nir_metadata_instr_index);
+ nir_metadata_dominance |
+ nir_metadata_loop_analysis |
+ nir_metadata_instr_index);
progress = true;
}
/* Flags used in the instr->pass_flags field for various instruction states */
enum {
- GCM_INSTR_PINNED = (1 << 0),
+ GCM_INSTR_PINNED = (1 << 0),
GCM_INSTR_SCHEDULE_EARLIER_ONLY = (1 << 1),
- GCM_INSTR_SCHEDULED_EARLY = (1 << 2),
- GCM_INSTR_SCHEDULED_LATE = (1 << 3),
- GCM_INSTR_PLACED = (1 << 4),
+ GCM_INSTR_SCHEDULED_EARLY = (1 << 2),
+ GCM_INSTR_SCHEDULED_LATE = (1 << 3),
+ GCM_INSTR_PLACED = (1 << 4),
};
struct gcm_state {
struct gcm_state *state = void_state;
nir_instr *instr = state->instr;
-
gcm_schedule_early_instr(src->ssa->parent_instr, void_state);
/* While the index isn't a proper dominance depth, it does have the
}
static bool
-set_block_to_if_block(struct gcm_state *state, nir_instr *instr,
+set_block_to_if_block(struct gcm_state *state, nir_instr *instr,
nir_block *block)
{
if (instr->type == nir_instr_type_load_const)
continue;
if (state->blocks[block->index].if_depth >=
- state->blocks[best->index].if_depth &&
+ state->blocks[best->index].if_depth &&
set_block_to_if_block(state, instr, block)) {
- /* If we are pushing the instruction into an if we want it to be
- * in the earliest block not the latest to avoid creating register
- * pressure issues. So we don't break unless we come across the
- * block the instruction was originally in.
- */
- best = block;
- block_set = true;
- if (block == instr->block)
- break;
+ /* If we are pushing the instruction into an if we want it to be
+ * in the earliest block not the latest to avoid creating register
+ * pressure issues. So we don't break unless we come across the
+ * block the instruction was originally in.
+ */
+ best = block;
+ block_set = true;
+ if (block == instr->block)
+ break;
} else if (block == instr->block) {
/* If we couldn't push the instruction later just put is back where it
* was previously.
opt_gcm_impl(nir_shader *shader, nir_function_impl *impl, bool value_number)
{
nir_metadata_require(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
nir_metadata_require(impl, nir_metadata_loop_analysis,
shader->options->force_indirect_unrolling,
shader->options->force_indirect_unrolling_sampler);
ralloc_free(state.instr_infos);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_loop_analysis);
+ nir_metadata_dominance |
+ nir_metadata_loop_analysis);
return state.progress;
}
* IN THE SOFTWARE.
*/
-#include "nir.h"
-#include "nir_builder.h"
#include "util/fast_idiv_by_const.h"
#include "util/u_math.h"
+#include "nir.h"
+#include "nir_builder.h"
static nir_ssa_def *
build_udiv(nir_builder *b, nir_ssa_def *n, uint64_t d)
alu->op != nir_op_irem)
return false;
-
if (alu->dest.dest.ssa.bit_size < *min_bit_size)
return false;
{
return nir_shader_instructions_pass(shader, nir_opt_idiv_const_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&min_bit_size);
}
* IN THE SOFTWARE.
*/
-#include "nir.h"
#include "nir/nir_builder.h"
+#include "nir.h"
#include "nir_constant_expressions.h"
#include "nir_control_flow.h"
#include "nir_loop_analyze.h"
* Gets the single block that jumps back to the loop header. Already assumes
* there is exactly one such block.
*/
-static nir_block*
+static nir_block *
find_continue_block(nir_loop *loop)
{
nir_block *header_block = nir_loop_first_block(loop);
set_foreach(header_block->predecessors, pred_entry) {
if (pred_entry->key != prev_block)
- return (nir_block*)pred_entry->key;
+ return (nir_block *)pred_entry->key;
}
unreachable("Continue block not found!");
*entry_val = false;
*continue_val = false;
- nir_foreach_phi_src(src, phi) {
- if (!nir_src_is_const(src->src))
+ nir_foreach_phi_src(src, phi) {
+ if (!nir_src_is_const(src->src))
return false;
- if (src->pred != entry_block) {
- *continue_val = nir_src_as_bool(src->src);
- } else {
- *entry_val = nir_src_as_bool(src->src);
- }
- }
+ if (src->pred != entry_block) {
+ *continue_val = nir_src_as_bool(src->src);
+ } else {
+ *entry_val = nir_src_as_bool(src->src);
+ }
+ }
- return true;
+ return true;
}
/**
nir_cf_list header, tmp;
nir_cf_extract(&header, nir_before_block(header_block),
- nir_after_block(header_block));
+ nir_after_block(header_block));
nir_cf_list_clone(&tmp, &header, &loop->cf_node, NULL);
nir_cf_reinsert(&tmp, nir_before_cf_node(&loop->cf_node));
nir_cf_extract(&tmp, nir_before_cf_list(entry_list),
- nir_after_cf_list(entry_list));
+ nir_after_cf_list(entry_list));
nir_cf_reinsert(&tmp, nir_before_cf_node(&loop->cf_node));
nir_cf_reinsert(&header,
cf_node.node));
nir_cf_extract(&tmp, nir_before_cf_list(continue_list),
- nir_after_cf_list(continue_list));
+ nir_after_cf_list(continue_list));
/* Get continue block again as the previous reinsert might have removed the
* block. Also, if both the continue list and the continue block ends in
nir_phi_instr *const phi = nir_phi_instr_create(b->shader);
nir_phi_instr_add_src(phi, prev_block,
nir_phi_get_src_from_block(nir_instr_as_phi(bcsel->src[entry_src].src.ssa->parent_instr),
- prev_block)->src);
+ prev_block)
+ ->src);
nir_phi_instr_add_src(phi, continue_block,
nir_phi_get_src_from_block(nir_instr_as_phi(bcsel->src[continue_src].src.ssa->parent_instr),
- continue_block)->src);
+ continue_block)
+ ->src);
nir_ssa_dest_init(&phi->instr, &phi->dest,
nir_dest_num_components(bcsel->dest.dest),
nir_instr *instr = nir_block_last_instr(block);
return instr->type == nir_instr_type_jump &&
- nir_instr_as_jump(instr)->type == nir_jump_continue;
+ nir_instr_as_jump(instr)->type == nir_jump_continue;
}
/**
/* Move the last block of the loop inside the last if-statement */
nir_cf_list tmp;
nir_cf_extract(&tmp, nir_after_cf_node(if_node),
- nir_after_block(last_block));
+ nir_after_block(last_block));
if (then_ends_in_continue)
nir_cf_reinsert(&tmp, nir_after_cf_list(&nif->else_list));
else
/* Finally, move the else block to the then block. */
nir_cf_list tmp;
nir_cf_extract(&tmp, nir_before_cf_list(&nif->else_list),
- nir_after_cf_list(&nif->else_list));
+ nir_after_cf_list(&nif->else_list));
nir_cf_reinsert(&tmp, nir_before_cf_list(&nif->then_list));
return true;
continue;
enum opt_bool {
- T, F, UNKNOWN
- } then_val = UNKNOWN, else_val = UNKNOWN;
+ T,
+ F,
+ UNKNOWN
+ } then_val = UNKNOWN,
+ else_val = UNKNOWN;
nir_foreach_phi_src(src, phi) {
assert(src->pred == then_block || src->pred == else_block);
nir_instr_remove_v(jump);
nir_instr_insert(nir_after_block(after_if), jump);
return true;
- }
+ }
/* Single break: If there's a break after the branch and the non-breaking
* side of the if falls through to it, then hoist that code after up into
nir_cf_node *first = nir_cf_node_next(&nif->cf_node);
nir_cf_node *last = first;
while (!nir_cf_node_is_last(last)) {
- if (contains_other_jump (last, NULL))
+ if (contains_other_jump(last, NULL))
return false;
last = nir_cf_node_next(last);
}
nir_cf_list tmp;
nir_cf_extract(&tmp, nir_before_cf_node(first),
- nir_after_block_before_jump(nir_cf_node_as_block(last)));
+ nir_after_block_before_jump(nir_cf_node_as_block(last)));
if (then_break)
nir_cf_reinsert(&tmp, nir_after_block(last_else));
else
/* If the continue from block is empty then return as there is nothing to
* move.
*/
- nir_block *first_continue_from_blk = continue_from_then ?
- nir_if_first_then_block(nif) :
- nir_if_first_else_block(nif);
+ nir_block *first_continue_from_blk = continue_from_then ? nir_if_first_then_block(nif) : nir_if_first_else_block(nif);
if (is_block_empty(first_continue_from_blk))
return false;
/* Finally, move the continue from branch after the if-statement. */
nir_cf_list tmp;
nir_cf_extract(&tmp, nir_before_block(first_continue_from_blk),
- nir_after_block(continue_from_blk));
+ nir_after_block(continue_from_blk));
nir_cf_reinsert(&tmp, nir_after_cf_node(&nif->cf_node));
return true;
alu->dest.dest.ssa.num_components,
alu->dest.dest.ssa.bit_size);
-
for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
nalu->src[i].src = nir_src_for_ssa(src_defs[i]);
memcpy(nalu->src[i].swizzle, alu->src[i].swizzle,
nir_builder_instr_insert(b, &nalu->instr);
- return &nalu->dest.dest.ssa;;
+ return &nalu->dest.dest.ssa;
+ ;
}
/*
if (!evaluate_if_condition(nif, b->cursor, &bool_value))
return false;
- nir_ssa_def *def[NIR_MAX_VEC_COMPONENTS] = {0};
+ nir_ssa_def *def[NIR_MAX_VEC_COMPONENTS] = { 0 };
for (unsigned i = 0; i < nir_op_infos[alu->op].num_inputs; i++) {
if (alu->src[i].src.ssa == use_src->ssa) {
def[i] = nir_imm_bool(b, bool_value);
nir_alu_instr *alu = nir_instr_as_alu(src->parent_instr);
switch (alu->op) {
- case nir_op_ior:
- case nir_op_iand:
- case nir_op_inot:
- case nir_op_b2i32:
- return true;
- case nir_op_bcsel:
- return src == &alu->src[0].src;
- default:
- return false;
+ case nir_op_ior:
+ case nir_op_iand:
+ case nir_op_inot:
+ case nir_op_b2i32:
+ return true;
+ case nir_op_bcsel:
+ return src == &alu->src[0].src;
+ default:
+ return false;
}
}
* use(b)
* if (c == (d=load_const))
* use(d)
-*/
+ */
static bool
opt_if_rewrite_uniform_uses(nir_builder *b, nir_if *nif, nir_ssa_scalar cond, bool accept_ine)
{
(intrin->intrinsic != nir_intrinsic_reduce || nir_intrinsic_cluster_size(intrin)))
continue;
- nir_ssa_scalar intrin_src = {intrin->src[0].ssa, src_uni.comp};
+ nir_ssa_scalar intrin_src = { intrin->src[0].ssa, src_uni.comp };
nir_ssa_scalar resolved_intrin_src = nir_ssa_scalar_resolved(intrin_src.def, intrin_src.comp);
if (resolved_intrin_src.comp != src_div.comp || resolved_intrin_src.def != src_div.def)
nir_builder b = nir_builder_create(impl);
nir_metadata_require(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
progress = opt_if_safe_cf_list(&b, &impl->body);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
bool preserve = true;
alu->op == nir_op_ine) {
/* Check for 0 in either operand. */
nir_const_value *const_val =
- nir_src_as_const_value(alu->src[0].src);
+ nir_src_as_const_value(alu->src[0].src);
if (!const_val)
const_val = nir_src_as_const_value(alu->src[1].src);
if (!const_val || const_val->i32 != 0)
if (opt_intrinsics_impl(impl, shader->options)) {
progress = true;
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
struct var_info *var_infos = ralloc_array(NULL, struct var_info, num_locals);
nir_foreach_function_temp_variable(var, impl) {
- var_infos[var->index] = (struct var_info) {
+ var_infos[var->index] = (struct var_info){
.var = var,
.is_constant = true,
.found_read = false,
ralloc_free(var_infos);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
return true;
}
* Handling these cases probably wouldn't provide much benefit though.
*
* This probably doesn't handle big-endian GPUs correctly.
-*/
+ */
+#include "util/u_dynarray.h"
#include "nir.h"
-#include "nir_deref.h"
#include "nir_builder.h"
+#include "nir_deref.h"
#include "nir_worklist.h"
-#include "util/u_dynarray.h"
#include <stdlib.h>
bool is_atomic;
/* Indices into nir_intrinsic::src[] or -1 if not applicable. */
int resource_src; /* resource (e.g. from vulkan_resource_index) */
- int base_src; /* offset which it loads/stores from */
- int deref_src; /* deref which is loads/stores from */
- int value_src; /* the data it is storing */
+ int base_src; /* offset which it loads/stores from */
+ int deref_src; /* deref which is loads/stores from */
+ int value_src; /* the data it is storing */
};
static const struct intrinsic_info *
-get_info(nir_intrinsic_op op) {
+get_info(nir_intrinsic_op op)
+{
switch (op) {
-#define INFO(mode, op, atomic, res, base, deref, val) \
-case nir_intrinsic_##op: {\
- static const struct intrinsic_info op##_info = {mode, nir_intrinsic_##op, atomic, res, base, deref, val};\
- return &op##_info;\
-}
-#define LOAD(mode, op, res, base, deref) INFO(mode, load_##op, false, res, base, deref, -1)
+#define INFO(mode, op, atomic, res, base, deref, val) \
+ case nir_intrinsic_##op: { \
+ static const struct intrinsic_info op##_info = { mode, nir_intrinsic_##op, atomic, res, base, deref, val }; \
+ return &op##_info; \
+ }
+#define LOAD(mode, op, res, base, deref) INFO(mode, load_##op, false, res, base, deref, -1)
#define STORE(mode, op, res, base, deref, val) INFO(mode, store_##op, false, res, base, deref, val)
-#define ATOMIC(mode, type, res, base, deref, val) \
+#define ATOMIC(mode, type, res, base, deref, val) \
INFO(mode, type##_atomic, true, res, base, deref, val) \
- INFO(mode, type##_atomic_swap, true, res, base, deref, val) \
-
- LOAD(nir_var_mem_push_const, push_constant, -1, 0, -1)
- LOAD(nir_var_mem_ubo, ubo, 0, 1, -1)
- LOAD(nir_var_mem_ssbo, ssbo, 0, 1, -1)
- STORE(nir_var_mem_ssbo, ssbo, 1, 2, -1, 0)
- LOAD(0, deref, -1, -1, 0)
- STORE(0, deref, -1, -1, 0, 1)
- LOAD(nir_var_mem_shared, shared, -1, 0, -1)
- STORE(nir_var_mem_shared, shared, -1, 1, -1, 0)
- LOAD(nir_var_mem_global, global, -1, 0, -1)
- STORE(nir_var_mem_global, global, -1, 1, -1, 0)
- LOAD(nir_var_mem_global, global_constant, -1, 0, -1)
- LOAD(nir_var_mem_task_payload, task_payload, -1, 0, -1)
- STORE(nir_var_mem_task_payload, task_payload, -1, 1, -1, 0)
- ATOMIC(nir_var_mem_ssbo, ssbo, 0, 1, -1, 2)
- ATOMIC(0, deref, -1, -1, 0, 1)
- ATOMIC(nir_var_mem_shared, shared, -1, 0, -1, 1)
- ATOMIC(nir_var_mem_global, global, -1, 0, -1, 1)
- ATOMIC(nir_var_mem_task_payload, task_payload, -1, 0, -1, 1)
- LOAD(nir_var_shader_temp, stack, -1, -1, -1)
- STORE(nir_var_shader_temp, stack, -1, -1, -1, 0)
- LOAD(nir_var_mem_ubo, ubo_uniform_block_intel, 0, 1, -1)
- LOAD(nir_var_mem_ssbo, ssbo_uniform_block_intel, 0, 1, -1)
- LOAD(nir_var_mem_shared, shared_uniform_block_intel, -1, 0, -1)
- LOAD(nir_var_mem_global, global_constant_uniform_block_intel, -1, 0, -1)
+ INFO(mode, type##_atomic_swap, true, res, base, deref, val)
+
+ LOAD(nir_var_mem_push_const, push_constant, -1, 0, -1)
+ LOAD(nir_var_mem_ubo, ubo, 0, 1, -1)
+ LOAD(nir_var_mem_ssbo, ssbo, 0, 1, -1)
+ STORE(nir_var_mem_ssbo, ssbo, 1, 2, -1, 0)
+ LOAD(0, deref, -1, -1, 0)
+ STORE(0, deref, -1, -1, 0, 1)
+ LOAD(nir_var_mem_shared, shared, -1, 0, -1)
+ STORE(nir_var_mem_shared, shared, -1, 1, -1, 0)
+ LOAD(nir_var_mem_global, global, -1, 0, -1)
+ STORE(nir_var_mem_global, global, -1, 1, -1, 0)
+ LOAD(nir_var_mem_global, global_constant, -1, 0, -1)
+ LOAD(nir_var_mem_task_payload, task_payload, -1, 0, -1)
+ STORE(nir_var_mem_task_payload, task_payload, -1, 1, -1, 0)
+ ATOMIC(nir_var_mem_ssbo, ssbo, 0, 1, -1, 2)
+ ATOMIC(0, deref, -1, -1, 0, 1)
+ ATOMIC(nir_var_mem_shared, shared, -1, 0, -1, 1)
+ ATOMIC(nir_var_mem_global, global, -1, 0, -1, 1)
+ ATOMIC(nir_var_mem_task_payload, task_payload, -1, 0, -1, 1)
+ LOAD(nir_var_shader_temp, stack, -1, -1, -1)
+ STORE(nir_var_shader_temp, stack, -1, -1, -1, 0)
+ LOAD(nir_var_mem_ubo, ubo_uniform_block_intel, 0, 1, -1)
+ LOAD(nir_var_mem_ssbo, ssbo_uniform_block_intel, 0, 1, -1)
+ LOAD(nir_var_mem_shared, shared_uniform_block_intel, -1, 0, -1)
+ LOAD(nir_var_mem_global, global_constant_uniform_block_intel, -1, 0, -1)
default:
break;
#undef ATOMIC
struct hash_table *stores[nir_num_variable_modes];
};
-static uint32_t hash_entry_key(const void *key_)
+static uint32_t
+hash_entry_key(const void *key_)
{
/* this is careful to not include pointers in the hash calculation so that
* the order of the hash table walk is deterministic */
- struct entry_key *key = (struct entry_key*)key_;
+ struct entry_key *key = (struct entry_key *)key_;
uint32_t hash = 0;
if (key->resource)
return hash;
}
-static bool entry_key_equals(const void *a_, const void *b_)
+static bool
+entry_key_equals(const void *a_, const void *b_)
{
- struct entry_key *a = (struct entry_key*)a_;
- struct entry_key *b = (struct entry_key*)b_;
+ struct entry_key *a = (struct entry_key *)a_;
+ struct entry_key *b = (struct entry_key *)b_;
if (a->var != b->var || a->resource != b->resource)
return false;
return true;
}
-static void delete_entry_dynarray(struct hash_entry *entry)
+static void
+delete_entry_dynarray(struct hash_entry *entry)
{
struct util_dynarray *arr = (struct util_dynarray *)entry->data;
ralloc_free(arr);
}
-static int sort_entries(const void *a_, const void *b_)
+static int
+sort_entries(const void *a_, const void *b_)
{
- struct entry *a = *(struct entry*const*)a_;
- struct entry *b = *(struct entry*const*)b_;
+ struct entry *a = *(struct entry *const *)a_;
+ struct entry *b = *(struct entry *const *)b_;
if (a->offset_signed > b->offset_signed)
return 1;
static unsigned
get_bit_size(struct entry *entry)
{
- unsigned size = entry->is_store ?
- entry->intrin->src[entry->info->value_src].ssa->bit_size :
- entry->intrin->dest.ssa.bit_size;
+ unsigned size = entry->is_store ? entry->intrin->src[entry->info->value_src].ssa->bit_size : entry->intrin->dest.ssa.bit_size;
return size == 1 ? 32u : size;
}
}
unsigned offset_def_count = 0;
- struct entry_key* key = ralloc(mem_ctx, struct entry_key);
+ struct entry_key *key = ralloc(mem_ctx, struct entry_key);
key->resource = NULL;
key->var = NULL;
*offset_base = 0;
nir_ssa_def *index = deref->arr.index.ssa;
uint32_t stride = nir_deref_instr_array_stride(deref);
- nir_ssa_scalar base = {.def=index, .comp=0};
+ nir_ssa_scalar base = { .def = index, .comp = 0 };
uint64_t offset = 0, base_mul = 1;
parse_offset(&base, &base_mul, &offset);
offset = util_mask_sign_extend(offset, index->bit_size);
nir_ssa_scalar src1 = nir_ssa_scalar_chase_alu_src(base, 1);
unsigned amount = parse_entry_key_from_offset(key, size, left - 1, src0, base_mul, offset);
amount += parse_entry_key_from_offset(key, size + amount, left - amount, src1, base_mul, offset);
- return amount;
- }
+ return amount;
}
+ }
return add_to_entry_key(key->offset_defs, key->offset_defs_mul, size, base, base_mul);
}
key->offset_defs = offset_defs;
key->offset_defs_mul = offset_defs_mul;
- nir_ssa_scalar scalar = {.def=base, .comp=0};
+ nir_ssa_scalar scalar = { .def = base, .comp = 0 };
key->offset_def_count = parse_entry_key_from_offset(key, 0, 32, scalar, base_mul, offset);
key->offset_defs = ralloc_array(mem_ctx, nir_ssa_scalar, key->offset_def_count);
entry->key = create_entry_key_from_deref(entry, ctx, &path, &entry->offset);
nir_deref_path_finish(&path);
} else {
- nir_ssa_def *base = entry->info->base_src >= 0 ?
- intrin->src[entry->info->base_src].ssa : NULL;
+ nir_ssa_def *base = entry->info->base_src >= 0 ? intrin->src[entry->info->base_src].ssa : NULL;
uint64_t offset = 0;
if (nir_intrinsic_has_base(intrin))
offset += nir_intrinsic_base(intrin);
cast_deref(nir_builder *b, unsigned num_components, unsigned bit_size, nir_deref_instr *deref)
{
if (glsl_get_components(deref->type) == num_components &&
- type_scalar_size_bytes(deref->type)*8u == bit_size)
+ type_scalar_size_bytes(deref->type) * 8u == bit_size)
return deref;
enum glsl_base_type types[] = {
- GLSL_TYPE_UINT8, GLSL_TYPE_UINT16, GLSL_TYPE_UINT, GLSL_TYPE_UINT64};
+ GLSL_TYPE_UINT8, GLSL_TYPE_UINT16, GLSL_TYPE_UINT, GLSL_TYPE_UINT64
+ };
enum glsl_base_type base = types[ffs(bit_size / 8u) - 1u];
const struct glsl_type *type = glsl_vector_type(base, num_components);
return true;
}
-static nir_deref_instr *subtract_deref(nir_builder *b, nir_deref_instr *deref, int64_t offset)
+static nir_deref_instr *
+subtract_deref(nir_builder *b, nir_deref_instr *deref, int64_t offset)
{
/* avoid adding another deref to the path */
if (deref->deref_type == nir_deref_type_ptr_as_array &&
b, parent, nir_src_as_int(deref->arr.index) - offset / stride);
}
-
deref = nir_build_deref_cast(b, &deref->dest.ssa, deref->modes,
glsl_scalar_type(GLSL_TYPE_UINT8), 1);
return nir_build_deref_ptr_as_array(
if (a_res.num_indices != b_res.num_indices ||
a_res.desc_set != b_res.desc_set ||
a_res.binding != b_res.binding)
- different_bindings = true;
+ different_bindings = true;
for (unsigned i = 0; i < a_res.num_indices; i++) {
if (nir_src_is_const(a_res.indices[i]) && nir_src_is_const(b_res.indices[i]) &&
nir_src_as_uint(a_res.indices[i]) != nir_src_as_uint(b_res.indices[i]))
- different_bindings = true;
+ different_bindings = true;
}
if (different_bindings) {
if (glsl_type_is_vector(type)) {
unsigned explicit_stride = glsl_get_explicit_stride(type);
return explicit_stride != 0 && explicit_stride !=
- type_scalar_size_bytes(glsl_get_array_element(type));
+ type_scalar_size_bytes(glsl_get_array_element(type));
} else {
return false;
}
nir_ssa_def *low_val = low->intrin->src[low->info->value_src].ssa;
nir_ssa_def *high_val = high->intrin->src[high->info->value_src].ssa;
nir_ssa_def *val = nir_vec2(&b, nir_bitcast_vector(&b, low_val, low_size * 8u),
- nir_bitcast_vector(&b, high_val, low_size * 8u));
- nir_store_shared2_amd(&b, val, offset, .offset1=diff/stride, .st64=st64);
+ nir_bitcast_vector(&b, high_val, low_size * 8u));
+ nir_store_shared2_amd(&b, val, offset, .offset1 = diff / stride, .st64 = st64);
} else {
- nir_ssa_def *new_def = nir_load_shared2_amd(&b, low_size * 8u, offset, .offset1=diff/stride,
- .st64=st64);
+ nir_ssa_def *new_def = nir_load_shared2_amd(&b, low_size * 8u, offset, .offset1 = diff / stride,
+ .st64 = st64);
nir_ssa_def_rewrite_uses(&low->intrin->dest.ssa,
nir_bitcast_vector(&b, nir_channel(&b, new_def, 0), low_bit_size));
nir_ssa_def_rewrite_uses(&high->intrin->dest.ssa,
continue;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
- const struct intrinsic_info *info = get_info(intrin->intrinsic);
+ const struct intrinsic_info *info = get_info(intrin->intrinsic);
if (!info)
continue;
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
}
ralloc_free(ctx);
#include "nir_control_flow.h"
#include "nir_loop_analyze.h"
-
/* This limit is chosen fairly arbitrarily. GLSL IR max iteration is 32
* instructions. (Multiply counting nodes and magic number 5.) But there is
* no 1:1 mapping between GLSL IR and NIR so 25 was picked because it seemed
nir_cf_list_clone_and_reinsert(&lcssa_list, loop->cf_node.parent,
cursor, remap_table);
- start_cursor = terminator->continue_from_then ?
- nir_before_block(nir_if_first_else_block(if_stmt)) :
- nir_before_block(nir_if_first_then_block(if_stmt));
+ start_cursor = terminator->continue_from_then ? nir_before_block(nir_if_first_else_block(if_stmt)) : nir_before_block(nir_if_first_then_block(if_stmt));
/* Reinsert the cloned vars back where they came from */
nir_cf_reinsert(&lcssa_list, start_cursor);
nir_cf_reinsert(&loop_body,
nir_after_block(terminator->continue_from_block));
- loop_end = terminator->continue_from_then ?
- nir_after_block(nir_if_last_then_block(terminator->nif)) :
- nir_after_block(nir_if_last_else_block(terminator->nif));
+ loop_end = terminator->continue_from_then ? nir_after_block(nir_if_last_then_block(terminator->nif)) : nir_after_block(nir_if_last_else_block(terminator->nif));
}
} else {
loop_prepare_for_unroll(loop);
* the trip count any iteration over the loop will be an out of bounds
* access of the array.
*/
- unsigned length = glsl_type_is_vector(parent->type) ?
- glsl_get_vector_elements(parent->type) :
- glsl_get_length(parent->type);
+ unsigned length = glsl_type_is_vector(parent->type) ? glsl_get_vector_elements(parent->type) : glsl_get_length(parent->type);
return length <= trip_count;
}
nir_loop_terminator *terminator =
list_first_entry(&loop->info->loop_terminator_list,
- nir_loop_terminator, loop_terminator_link);
+ nir_loop_terminator, loop_terminator_link);
assert(nir_is_trivial_loop_if(terminator->nif, terminator->break_block));
* We trust that nir_opt_if() does its job well enough to
* remove all instructions from the continue block when possible.
*/
- nir_block *first_continue_from_blk = t->continue_from_then ?
- nir_if_first_then_block(t->nif) :
- nir_if_first_else_block(t->nif);
+ nir_block *first_continue_from_blk = t->continue_from_then ? nir_if_first_then_block(t->nif) : nir_if_first_else_block(t->nif);
if (!(nir_cf_node_is_last(&first_continue_from_blk->cf_node) &&
exec_list_is_empty(&first_continue_from_blk->instr_list)))
list_first_entry(&loop->info->loop_terminator_list,
nir_loop_terminator, loop_terminator_link);
-
if (terminator->nif == loop->info->limiting_terminator->nif) {
limiting_term_second = false;
terminator =
{
bool progress = false;
nir_metadata_require(impl, nir_metadata_loop_analysis, indirect_mask,
- (int) force_unroll_sampler_indirect);
+ (int)force_unroll_sampler_indirect);
nir_metadata_require(impl, nir_metadata_block_index);
bool has_nested_loop = false;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
nir_opt_move_block(nir_block *block, nir_move_options options)
{
bool progress = false;
- nir_instr *last_instr = nir_block_ends_in_jump(block) ?
- nir_block_last_instr(block) : NULL;
+ nir_instr *last_instr = nir_block_ends_in_jump(block) ? nir_block_last_instr(block) : NULL;
const nir_if *iff = nir_block_get_following_if(block);
const nir_instr *if_cond_instr = iff ? iff->condition.parent_instr : NULL;
* If multiple instructions have the same user,
* the original order is kept.
*/
- unsigned index = 1;
+ unsigned index = 1;
nir_foreach_instr_reverse_safe(instr, block) {
instr->index = index++;
if (impl_progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
progress = true;
} else {
nir_metadata_preserve(impl, nir_metadata_all);
nir_foreach_function_impl(impl, shader) {
if (opt_move_discards_to_top_impl(impl)) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
progress = true;
}
}
case nir_instr_type_tex: {
nir_tex_instr *tex = nir_instr_as_tex(instr);
if ((types & nir_lower_non_uniform_texture_access) &&
- has_non_uniform_tex_access(tex))
+ has_non_uniform_tex_access(tex))
return true;
break;
}
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (is_ubo_intrinsic(intrin)) {
if ((types & nir_lower_non_uniform_ubo_access) &&
- has_non_uniform_access_intrin(intrin))
+ has_non_uniform_access_intrin(intrin))
return true;
} else if (is_ssbo_intrinsic(intrin)) {
if ((types & nir_lower_non_uniform_ssbo_access) &&
- has_non_uniform_access_intrin(intrin))
+ has_non_uniform_access_intrin(intrin))
return true;
} else if (is_image_intrinsic(intrin)) {
if ((types & nir_lower_non_uniform_image_access) &&
- has_non_uniform_access_intrin(intrin))
+ has_non_uniform_access_intrin(intrin))
return true;
} else if (intrin->intrinsic == nir_intrinsic_get_ssbo_size) {
if ((types & nir_lower_non_uniform_get_ssbo_size) &&
return val;
nir_ssa_scalar src[2] = {
- {alu->src[0].src.ssa, alu->src[0].swizzle[val.comp]},
- {alu->src[1].src.ssa, alu->src[1].swizzle[val.comp]},
+ { alu->src[0].src.ssa, alu->src[0].swizzle[val.comp] },
+ { alu->src[1].src.ssa, alu->src[1].swizzle[val.comp] },
};
/* Make sure that we aren't taking out an addition that could trigger
b->cursor = nir_before_instr(&alu->instr);
nir_ssa_def *r =
- nir_iadd(b, nir_channel(b, src[0].def, src[0].comp),
- nir_channel(b, src[1].def, src[1].comp));
+ nir_iadd(b, nir_channel(b, src[0].def, src[0].comp),
+ nir_channel(b, src[1].def, src[1].comp));
return nir_get_ssa_scalar(r, 0);
}
if (!nir_src_is_const(*off_src)) {
uint32_t add_offset = 0;
- nir_ssa_scalar val = {.def = off_src->ssa, .comp = 0};
+ nir_ssa_scalar val = { .def = off_src->ssa, .comp = 0 };
val = try_extract_const_addition(b, val, state, &add_offset, max - off_const);
if (add_offset == 0)
return false;
static bool
try_fold_shared2(nir_builder *b,
- nir_intrinsic_instr *intrin,
- opt_offsets_state *state,
- unsigned offset_src_idx)
+ nir_intrinsic_instr *intrin,
+ opt_offsets_state *state,
+ unsigned offset_src_idx)
{
- unsigned comp_size = (intrin->intrinsic == nir_intrinsic_load_shared2_amd ?
- intrin->dest.ssa.bit_size : intrin->src[0].ssa->bit_size) / 8;
+ unsigned comp_size = (intrin->intrinsic == nir_intrinsic_load_shared2_amd ? intrin->dest.ssa.bit_size : intrin->src[0].ssa->bit_size) / 8;
unsigned stride = (nir_intrinsic_st64(intrin) ? 64 : 1) * comp_size;
unsigned offset0 = nir_intrinsic_offset0(intrin) * stride;
unsigned offset1 = nir_intrinsic_offset1(intrin) * stride;
if (instr->type != nir_instr_type_intrinsic)
return false;
- opt_offsets_state *state = (opt_offsets_state *) s;
+ opt_offsets_state *state = (opt_offsets_state *)s;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
switch (intrin->intrinsic) {
bool p = nir_shader_instructions_pass(shader, process_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
&state);
if (state.range_ht)
_mesa_hash_table_destroy(state.range_ht, NULL);
-
return p;
}
* IN THE SOFTWARE.
*/
-#include "nir.h"
#include "nir/nir_builder.h"
+#include "nir.h"
#include "nir_control_flow.h"
#include "nir_search_helpers.h"
nir_phi_src *else_src =
nir_phi_get_src_from_block(phi, nir_if_first_else_block(if_stmt));
- nir_foreach_use (src, &phi->dest.ssa) {
+ nir_foreach_use(src, &phi->dest.ssa) {
assert(src->parent_instr->type == nir_instr_type_phi);
nir_phi_src *phi_src =
nir_phi_get_src_from_block(nir_instr_as_phi(src->parent_instr),
/* move the whole inner if before the parent if */
nir_cf_list tmp;
nir_cf_extract(&tmp, nir_before_block(first),
- nir_after_block(last));
+ nir_after_block(last));
nir_cf_reinsert(&tmp, nir_before_cf_node(&parent_if->cf_node));
/* The now empty parent if will be cleaned up by other passes */
concrete_conversion(nir_op op)
{
switch (op) {
- case nir_op_i2imp: return nir_op_i2i16;
- case nir_op_i2fmp: return nir_op_i2f16;
- case nir_op_u2fmp: return nir_op_u2f16;
- case nir_op_f2fmp: return nir_op_f2f16;
- case nir_op_f2imp: return nir_op_f2i16;
- case nir_op_f2ump: return nir_op_f2u16;
- default: return op;
+ case nir_op_i2imp:
+ return nir_op_i2i16;
+ case nir_op_i2fmp:
+ return nir_op_i2f16;
+ case nir_op_u2fmp:
+ return nir_op_u2f16;
+ case nir_op_f2fmp:
+ return nir_op_f2f16;
+ case nir_op_f2imp:
+ return nir_op_f2i16;
+ case nir_op_f2ump:
+ return nir_op_f2u16;
+ default:
+ return op;
}
}
/* Are the only uses of the phi conversion instructions, and
* are they all the same conversion?
*/
- nir_foreach_use_including_if (use, &phi->dest.ssa) {
+ nir_foreach_use_including_if(use, &phi->dest.ssa) {
/* an if use means the phi is used directly in a conditional, ie.
* without a conversion
*/
nir_alu_type_get_type_size(nir_op_infos[op].output_type));
/* Push the conversion into the new phi sources: */
- nir_foreach_phi_src (src, phi) {
+ nir_foreach_phi_src(src, phi) {
/* insert new conversion instr in block of original phi src: */
b->cursor = nir_after_instr_and_phis(src->src.ssa->parent_instr);
nir_ssa_def *old_src = src->src.ssa;
* directly use the new phi, skipping the conversion out of the orig
* phi
*/
- nir_foreach_use (use, &phi->dest.ssa) {
+ nir_foreach_use(use, &phi->dest.ssa) {
/* We've previously established that all the uses were alu
* conversion ops. Turn them into movs instead.
*/
break;
case nir_type_float:
if (lc->value[i].f32 != _mesa_half_to_float(
- _mesa_float_to_half(lc->value[i].f32)))
+ _mesa_float_to_half(lc->value[i].f32)))
return false;
break;
default:
bool has_load_const = false;
*bit_size = 0;
- nir_foreach_phi_src (src, phi) {
+ nir_foreach_phi_src(src, phi) {
nir_instr *instr = src->src.ssa->parent_instr;
if (instr->type == nir_instr_type_load_const) {
has_load_const = true;
* loss of precision), then we could insert a narrowing->widening
* sequence to make the rest of the transformation possible:
*/
- nir_foreach_phi_src (src, phi) {
+ nir_foreach_phi_src(src, phi) {
nir_instr *instr = src->src.ssa->parent_instr;
if (instr->type != nir_instr_type_load_const)
continue;
phi->dest.ssa.num_components, bit_size);
/* Remove the widening conversions from the phi sources: */
- nir_foreach_phi_src (src, phi) {
+ nir_foreach_phi_src(src, phi) {
nir_instr *instr = src->src.ssa->parent_instr;
nir_ssa_def *new_src;
nir_foreach_function_impl(impl, shader) {
nir_builder b = nir_builder_create(impl);
- nir_foreach_block (block, impl) {
- nir_foreach_phi_safe (phi, block)
+ nir_foreach_block(block, impl) {
+ nir_foreach_phi_safe(phi, block)
progress |= lower_phi(&b, phi);
}
if (progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
return progress;
}
-
* in case backends want to insert their own code.
*/
-
nir_function_impl *
nir_shader_get_preamble(nir_shader *shader)
{
case nir_intrinsic_load_ssbo:
case nir_intrinsic_load_ssbo_ir3:
return (nir_intrinsic_access(instr) & ACCESS_CAN_REORDER) &&
- can_move_srcs(&instr->instr, ctx);
+ can_move_srcs(&instr->instr, ctx);
default:
return false;
ctx.states = calloc(impl->ssa_alloc, sizeof(*ctx.states));
/* Step 1: Calculate can_move */
- nir_foreach_block (block, impl) {
- nir_foreach_instr (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr(instr, block) {
nir_ssa_def *def = nir_instr_ssa_def(instr);
if (!def)
continue;
* program because it has a non-can_move user, including recursively.
*/
unsigned num_candidates = 0;
- nir_foreach_block_reverse (block, impl) {
- nir_foreach_instr_reverse (instr, block) {
+ nir_foreach_block_reverse(block, impl) {
+ nir_foreach_instr_reverse(instr, block) {
nir_ssa_def *def = nir_instr_ssa_def(instr);
if (!def)
continue;
bool is_candidate = !avoid_instr(instr, options);
state->candidate = false;
state->must_stay = false;
- nir_foreach_use (use, def) {
+ nir_foreach_use(use, def) {
nir_ssa_def *use_def = nir_instr_ssa_def(use->parent_instr);
if (!use_def || !ctx.states[use_def->index].can_move ||
ctx.states[use_def->index].must_stay) {
}
}
- nir_foreach_if_use (use, def) {
+ nir_foreach_if_use(use, def) {
if (is_candidate)
state->candidate = true;
else
*
* While we're here, also collect an array of candidates.
*/
- nir_foreach_block (block, impl) {
- nir_foreach_instr (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr(instr, block) {
nir_ssa_def *def = nir_instr_ssa_def(instr);
if (!def)
continue;
ctx.def = def;
nir_foreach_src(instr, update_src_value, &ctx);
-
+
/* If this instruction is a candidate, its value shouldn't be
* propagated so we skip dividing it.
*
if (state->candidate) {
state->benefit = state->value -
- options->rewrite_cost_cb(def, options->cb_data);
+ options->rewrite_cost_cb(def, options->cb_data);
if (state->benefit > 0) {
options->def_size(def, &state->size, &state->align);
*/
if (((*size) + total_size) > options->preamble_storage_size) {
- qsort(candidates, num_candidates, sizeof(*candidates), candidate_sort);
+ qsort(candidates, num_candidates, sizeof(*candidates), candidate_sort);
}
unsigned offset = *size;
nir_builder preamble_builder = nir_builder_at(nir_before_cf_list(&preamble->body));
nir_builder *b = &preamble_builder;
- nir_foreach_block (block, impl) {
- nir_foreach_instr (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr(instr, block) {
nir_ssa_def *def = nir_instr_ssa_def(instr);
if (!def)
continue;
nir_builder builder = nir_builder_create(impl);
b = &builder;
- nir_foreach_block (block, impl) {
- nir_foreach_instr_safe (instr, block) {
+ nir_foreach_block(block, impl) {
+ nir_foreach_instr_safe(instr, block) {
nir_ssa_def *def = nir_instr_ssa_def(instr);
if (!def)
continue;
nir_load_preamble(b, def->num_components, def->bit_size,
.base = state->offset);
-
nir_ssa_def_rewrite_uses(def, new_def);
nir_instr_free_and_dce(instr);
}
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
ralloc_free(remap_table);
free(ctx.states);
#include "nir_builder.h"
#include "util/hash_table.h"
-#include "util/set.h"
#include "util/macros.h"
+#include "util/set.h"
#include "util/u_dynarray.h"
/** @file nir_opt_ray_queries.c
nir_shader_instructions_pass(shader,
nir_replace_unread_queries_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
read_queries);
/* Update the number of queries if some have been removed. */
/**
* Merge ray queries that are not used in parallel to reduce scratch memory:
- *
+ *
* 1. Store all the ray queries we will consider into an array for
* convenient access. Ignore arrays since it would be really complex
* to handle and will be rare in praxis.
*
* 1. rq_initialize can be inside some form of controlflow which can result
* in incorrect ranges and invalid merging.
- *
+ *
* SOLUTION: Discard the entire ray query when encountering an
* instruction that is not dominated by the rq_initialize
* of the range.
- *
+ *
* 2. With loops, we can underestimate the range because the state may
* have to be preserved for multiple iterations.
- *
+ *
* SOLUTION: Track parent loops.
- *
+ *
* 4. Try to rewrite the variables. For that, we iterate over every ray query
* and try to move its ranges to the preceding ray queries.
*/
nir_intrinsic_instr *intrinsic = nir_instr_as_intrinsic(instr);
if (intrinsic->intrinsic == nir_intrinsic_rq_initialize)
- (*(uint32_t *) data)++;
+ (*(uint32_t *)data)++;
return false;
}
nir_metadata_require(func->impl, nir_metadata_instr_index | nir_metadata_dominance);
- nir_variable **ray_queries = ralloc_array(mem_ctx, nir_variable*, ray_query_count);
+ nir_variable **ray_queries = ralloc_array(mem_ctx, nir_variable *, ray_query_count);
ray_query_count = 0;
nir_foreach_variable_in_shader(var, shader) {
if (!var->data.ray_query || glsl_type_is_array(var->type))
continue;
-
+
ray_queries[ray_query_count] = var;
ray_query_count++;
}
nir_foreach_function_temp_variable(var, func->impl) {
if (!var->data.ray_query || glsl_type_is_array(var->type))
continue;
-
+
ray_queries[ray_query_count] = var;
ray_query_count++;
}
struct hash_entry *index_entry =
_mesa_hash_table_search(range_indices, ray_query_deref->var);
struct rq_range *range = ranges + (uintptr_t)index_entry->data;
-
+
if (intrinsic->intrinsic != nir_intrinsic_rq_initialize) {
/* If the initialize instruction does not dominate every other
* instruction in the range, we have to reject the enire query
* since we can not be certain about the ranges:
- *
+ *
* rayQuery rq;
* if (i == 0)
* init(rq);
bool progress = nir_shader_instructions_pass(shader,
nir_opt_reassociate_bfi_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
return progress;
}
-
* IN THE SOFTWARE.
*/
-#include "nir.h"
#include "nir/nir_builder.h"
+#include "nir.h"
#include "nir_constant_expressions.h"
#include "nir_control_flow.h"
#include "nir_loop_analyze.h"
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
*/
if (src->src.ssa == &phi->dest.ssa)
continue;
-
+
if (def == NULL) {
- def = src->src.ssa;
+ def = src->src.ssa;
mov = get_parent_mov(def);
} else if (nir_src_is_undef(src->src) &&
nir_block_dominates(def->parent_instr->block, src->pred)) {
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
return progress;
}
-
if (progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* elimination.
*/
+#include "util/u_math.h"
#include "nir.h"
#include "nir_builder.h"
-#include "util/u_math.h"
/*
* Round up a vector size to a vector size that's valid in NIR. At present, NIR
nir_foreach_use(use_src, def) {
/* all uses must be ALU instructions */
assert(use_src->parent_instr->type == nir_instr_type_alu);
- nir_alu_src *alu_src = (nir_alu_src*)use_src;
+ nir_alu_src *alu_src = (nir_alu_src *)use_src;
/* reswizzle ALU sources */
for (unsigned i = 0; i < NIR_MAX_VEC_COMPONENTS; i++)
return false;
switch (instr->op) {
- /* don't use nir_op_is_vec() as not all vector sizes are supported. */
- case nir_op_vec4:
- case nir_op_vec3:
- case nir_op_vec2:
- return opt_shrink_vector(b, instr);
- default:
- if (nir_op_infos[instr->op].output_size != 0)
- return false;
- break;
+ /* don't use nir_op_is_vec() as not all vector sizes are supported. */
+ case nir_op_vec4:
+ case nir_op_vec3:
+ case nir_op_vec2:
+ return opt_shrink_vector(b, instr);
+ default:
+ if (nir_op_infos[instr->op].output_size != 0)
+ return false;
+ break;
}
/* don't remove any channels if used by non-ALU */
if (def->num_components > 4)
return false;
-
/* Check the uses. */
nir_component_mask_t mask = 0;
nir_foreach_use(src, def) {
if (progress) {
nir_metadata_preserve(impl,
nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
#include "nir.h"
-
/*
* A simple pass that moves some instructions into the least common
* anscestor of consuming instructions.
{
for (; node != NULL; node = node->parent) {
if (node->type == nir_cf_node_loop)
- return (nir_loop*)node;
+ return (nir_loop *)node;
}
return NULL;
}
if (next && next->type == nir_cf_node_loop) {
nir_loop *following_loop = nir_cf_node_as_loop(next);
if (loop_contains_block(following_loop, use_block)) {
- use_block = cur_block;
- continue;
+ use_block = cur_block;
+ continue;
}
}
}
instr->type != nir_instr_type_intrinsic ||
can_sink_out_of_loop(nir_instr_as_intrinsic(instr));
nir_block *use_block =
- get_preferred_block(def, sink_out_of_loops);
+ get_preferred_block(def, sink_out_of_loops);
if (!use_block || use_block == instr->block)
continue;
case nir_intrinsic_store_shared:
case nir_intrinsic_store_global:
case nir_intrinsic_store_scratch:
- arg_index = 0;
+ arg_index = 0;
break;
default:
return false;
return nir_shader_instructions_pass(shader,
nir_opt_undef_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
atomic_op_to_alu(nir_atomic_op op)
{
switch (op) {
- case nir_atomic_op_iadd: return nir_op_iadd;
- case nir_atomic_op_imin: return nir_op_imin;
- case nir_atomic_op_umin: return nir_op_umin;
- case nir_atomic_op_imax: return nir_op_imax;
- case nir_atomic_op_umax: return nir_op_umax;
- case nir_atomic_op_iand: return nir_op_iand;
- case nir_atomic_op_ior: return nir_op_ior;
- case nir_atomic_op_ixor: return nir_op_ixor;
- case nir_atomic_op_fadd: return nir_op_fadd;
- case nir_atomic_op_fmin: return nir_op_fmin;
- case nir_atomic_op_fmax: return nir_op_fmax;
+ case nir_atomic_op_iadd:
+ return nir_op_iadd;
+ case nir_atomic_op_imin:
+ return nir_op_imin;
+ case nir_atomic_op_umin:
+ return nir_op_umin;
+ case nir_atomic_op_imax:
+ return nir_op_imax;
+ case nir_atomic_op_umax:
+ return nir_op_umax;
+ case nir_atomic_op_iand:
+ return nir_op_iand;
+ case nir_atomic_op_ior:
+ return nir_op_ior;
+ case nir_atomic_op_ixor:
+ return nir_op_ixor;
+ case nir_atomic_op_fadd:
+ return nir_op_fadd;
+ case nir_atomic_op_fmin:
+ return nir_op_fmin;
+ case nir_atomic_op_fmax:
+ return nir_op_fmax;
/* We don't handle exchanges or wraps */
case nir_atomic_op_xchg:
if (!within_then)
continue;
- nir_ssa_scalar cond = {nir_cf_node_as_if(cf)->condition.ssa, 0};
+ nir_ssa_scalar cond = { nir_cf_node_as_if(cf)->condition.ssa, 0 };
dims |= match_invocation_comparison(cond);
}
}
unsigned dims_needed = 0;
for (unsigned i = 0; i < 3; i++)
dims_needed |= (shader->info.workgroup_size_variable ||
- shader->info.workgroup_size[i] > 1) << i;
+ shader->info.workgroup_size[i] > 1)
+ << i;
if ((dims & dims_needed) == dims_needed)
return true;
}
nir_ssa_def **reduce, nir_ssa_def **scan)
{
if (scan) {
- *scan = nir_exclusive_scan(b, data, .reduction_op=op);
+ *scan = nir_exclusive_scan(b, data, .reduction_op = op);
if (reduce) {
nir_ssa_def *last_lane = nir_last_invocation(b);
nir_ssa_def *res = nir_build_alu(b, op, *scan, data, NULL, NULL);
*reduce = nir_read_invocation(b, res, last_lane);
}
} else {
- *reduce = nir_reduce(b, data, .reduction_op=op);
+ *reduce = nir_reduce(b, data, .reduction_op = op);
}
}
* The max vectorization width must be a power of 2.
*/
+#include "util/u_dynarray.h"
#include "nir.h"
-#include "nir_vla.h"
#include "nir_builder.h"
-#include "util/u_dynarray.h"
+#include "nir_vla.h"
#define HASH(hash, data) XXH32(&data, sizeof(data), hash)
static uint32_t
hash_instr(const void *data)
{
- const nir_instr *instr = (nir_instr *) data;
+ const nir_instr *instr = (nir_instr *)data;
assert(instr->type == nir_instr_type_alu);
nir_alu_instr *alu = nir_instr_as_alu(instr);
static bool
instrs_equal(const void *data1, const void *data2)
{
- const nir_instr *instr1 = (nir_instr *) data1;
- const nir_instr *instr2 = (nir_instr *) data2;
+ const nir_instr *instr1 = (nir_instr *)data1;
+ const nir_instr *instr2 = (nir_instr *)data2;
assert(instr1->type == nir_instr_type_alu);
assert(instr2->type == nir_instr_type_alu);
unsigned bit_size = alu1->src[i].src.ssa->bit_size;
for (unsigned j = 0; j < total_components; j++) {
- value[j].u64 = j < alu1_components ?
- c1[alu1->src[i].swizzle[j]].u64 :
- c2[alu2->src[i].swizzle[j - alu1_components]].u64;
+ value[j].u64 = j < alu1_components ? c1[alu1->src[i].swizzle[j]].u64 : c2[alu2->src[i].swizzle[j - alu1_components]].u64;
}
nir_ssa_def *def = nir_build_imm(&b, total_components, bit_size, value);
struct set_entry *entry = _mesa_set_search(instr_set, instr);
if (entry) {
- nir_instr *old_instr = (nir_instr *) entry->key;
+ nir_instr *old_instr = (nir_instr *)entry->key;
_mesa_set_remove(instr_set, entry);
nir_instr *new_instr = instr_try_combine(instr_set, old_instr, instr);
if (new_instr) {
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* SOFTWARE.
*/
+#include "util/u_memory.h"
#include "nir.h"
-#include "nir_xfb_info.h"
#include "nir_builder.h"
-#include "util/u_memory.h"
+#include "nir_xfb_info.h"
static unsigned int
gs_in_prim_for_topology(enum mesa_prim prim)
nir_shader *nir = b.shader;
nir->info.gs.input_primitive = gs_in_prim_for_topology(primitive_type);
- nir->info.gs.output_primitive = (force_line_strip_out || emulate_edgeflags) ?
- MESA_PRIM_LINE_STRIP : original_our_prim;
+ nir->info.gs.output_primitive = (force_line_strip_out || emulate_edgeflags) ? MESA_PRIM_LINE_STRIP : original_our_prim;
nir->info.gs.vertices_in = vertices_out;
nir->info.gs.vertices_out = needs_closing ? vertices_out + 1 : vertices_out;
nir->info.gs.invocations = 1;
nir_store_var(&b, out_inner, inner, 0x3);
nir_variable *in_outer =
- nir_create_variable_with_location(b.shader, nir_var_system_value,
+ nir_create_variable_with_location(b.shader, nir_var_system_value,
SYSTEM_VALUE_TESS_LEVEL_OUTER_DEFAULT, glsl_vec4_type());
nir_variable *out_outer =
continue;
nir_variable *in = nir_create_variable_with_location(b.shader, nir_var_shader_in,
- semantic, type);
+ semantic, type);
nir_variable *out = nir_create_variable_with_location(b.shader, nir_var_shader_out,
semantic, type);
return b.shader;
}
-
nir_shader *
nir_create_passthrough_tcs(const nir_shader_compiler_options *options,
const nir_shader *vs, uint8_t patch_vertices)
unsigned locations[MAX_VARYING];
unsigned num_outputs = 0;
- nir_foreach_shader_out_variable (var, vs) {
+ nir_foreach_shader_out_variable(var, vs) {
assert(num_outputs < ARRAY_SIZE(locations));
locations[num_outputs++] = var->data.location;
}
* _mesa_hash_pointer drops the two least significant bits, but that's where
* most of our data likely is. Shift by 2 and add 1 to make everything happy.
*/
-#define INDEX_TO_KEY(x) ((void *)(uintptr_t) ((x << 2) + 1))
+#define INDEX_TO_KEY(x) ((void *)(uintptr_t)((x << 2) + 1))
struct nir_phi_builder *
nir_phi_builder_create(nir_function_impl *impl)
while (w_start != w_end) {
nir_block *cur = pb->W[w_start++];
set_foreach(cur->dom_frontier, dom_entry) {
- nir_block *next = (nir_block *) dom_entry->key;
+ nir_block *next = (nir_block *)dom_entry->key;
/* If there's more than one return statement, then the end block
* can be a join point for some definitions. However, there are
* phi node created by the case above or one passed to us through
* nir_phi_builder_value_set_block_def().
*/
- def = (struct nir_ssa_def *) he->data;
+ def = (struct nir_ssa_def *)he->data;
}
/* Walk the chain and stash the def in all of the applicable blocks. We do
*
*/
-#include "nir.h"
+#include <inttypes.h> /* for PRIx64 macro */
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "compiler/shader_enums.h"
#include "util/half_float.h"
#include "util/memstream.h"
#include "util/mesa-sha1.h"
#include "vulkan/vulkan_core.h"
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <inttypes.h> /* for PRIx64 macro */
+#include "nir.h"
static void
print_indentation(unsigned levels, FILE *fp)
static const char *sizes[] = { "x??", " ", "x2 ", "x3 ", "x4 ",
"x5 ", "x??", "x??", "x8 ",
"x??", "x??", "x??", "x??",
- "x??", "x??", "x??", "x16"};
+ "x??", "x??", "x??", "x16" };
static const char *
divergence_status(print_state *state, bool divergent)
{
FILE *fp = state->fp;
- const unsigned ssa_padding = state->max_dest_index ?
- count_digits(state->max_dest_index) - count_digits(def->index) : 0;
+ const unsigned ssa_padding = state->max_dest_index ? count_digits(state->max_dest_index) - count_digits(def->index) : 0;
const unsigned padding = (def->bit_size == 1) + 1 + ssa_padding;
print_hex_padded_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
{
switch (bit_size) {
- case 64: fprintf(fp, "0x%016" PRIx64, value->u64); break;
- case 32: fprintf(fp, "0x%08x", value->u32); break;
- case 16: fprintf(fp, "0x%04x", value->u16); break;
- case 8: fprintf(fp, "0x%02x", value->u8); break;
+ case 64:
+ fprintf(fp, "0x%016" PRIx64, value->u64);
+ break;
+ case 32:
+ fprintf(fp, "0x%08x", value->u32);
+ break;
+ case 16:
+ fprintf(fp, "0x%04x", value->u16);
+ break;
+ case 8:
+ fprintf(fp, "0x%02x", value->u8);
+ break;
default:
unreachable("unhandled bit size");
}
print_hex_terse_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
{
switch (bit_size) {
- case 64: fprintf(fp, "0x%" PRIx64, value->u64); break;
- case 32: fprintf(fp, "0x%x", value->u32); break;
- case 16: fprintf(fp, "0x%x", value->u16); break;
- case 8: fprintf(fp, "0x%x", value->u8); break;
+ case 64:
+ fprintf(fp, "0x%" PRIx64, value->u64);
+ break;
+ case 32:
+ fprintf(fp, "0x%x", value->u32);
+ break;
+ case 16:
+ fprintf(fp, "0x%x", value->u16);
+ break;
+ case 8:
+ fprintf(fp, "0x%x", value->u8);
+ break;
default:
unreachable("unhandled bit size");
}
print_float_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
{
switch (bit_size) {
- case 64: fprintf(fp, "%f", value->f64); break;
- case 32: fprintf(fp, "%f", value->f32); break;
- case 16: fprintf(fp, "%f", _mesa_half_to_float(value->u16)); break;
+ case 64:
+ fprintf(fp, "%f", value->f64);
+ break;
+ case 32:
+ fprintf(fp, "%f", value->f32);
+ break;
+ case 16:
+ fprintf(fp, "%f", _mesa_half_to_float(value->u16));
+ break;
default:
unreachable("unhandled bit size");
}
print_int_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
{
switch (bit_size) {
- case 64: fprintf(fp, "%+" PRIi64, value->i64); break;
- case 32: fprintf(fp, "%+d", value->i32); break;
- case 16: fprintf(fp, "%+d", value->i16); break;
- case 8: fprintf(fp, "%+d", value->i8); break;
+ case 64:
+ fprintf(fp, "%+" PRIi64, value->i64);
+ break;
+ case 32:
+ fprintf(fp, "%+d", value->i32);
+ break;
+ case 16:
+ fprintf(fp, "%+d", value->i16);
+ break;
+ case 8:
+ fprintf(fp, "%+d", value->i8);
+ break;
default:
unreachable("unhandled bit size");
}
print_uint_const_value(const nir_const_value *value, unsigned bit_size, FILE *fp)
{
switch (bit_size) {
- case 64: fprintf(fp, "%" PRIu64, value->u64); break;
- case 32: fprintf(fp, "%u", value->u32); break;
- case 16: fprintf(fp, "%u", value->u16); break;
- case 8: fprintf(fp, "%u", value->u8); break;
+ case 64:
+ fprintf(fp, "%" PRIu64, value->u64);
+ break;
+ case 32:
+ fprintf(fp, "%u", value->u32);
+ break;
+ case 16:
+ fprintf(fp, "%u", value->u16);
+ break;
+ case 8:
+ fprintf(fp, "%u", value->u8);
+ break;
default:
unreachable("unhandled bit size");
}
}
}
} else {
- #define PRINT_VALUES(F) \
- do { \
- for (unsigned i = 0; i < num_components; i++) { \
- if (i != 0) \
- fprintf(fp, ", "); \
- F(&instr->value[i], bit_size, fp); \
- } \
- } while (0)
-
- #define SEPARATOR() \
- if (num_components > 1) \
- fprintf(fp, ") = ("); \
- else \
- fprintf(fp, " = ")
+#define PRINT_VALUES(F) \
+ do { \
+ for (unsigned i = 0; i < num_components; i++) { \
+ if (i != 0) \
+ fprintf(fp, ", "); \
+ F(&instr->value[i], bit_size, fp); \
+ } \
+ } while (0)
+
+#define SEPARATOR() \
+ if (num_components > 1) \
+ fprintf(fp, ") = ("); \
+ else \
+ fprintf(fp, " = ")
bool needs_float = bit_size > 8;
bool needs_signed = false;
const nir_const_value *v = &instr->value[i];
switch (bit_size) {
case 64:
- needs_signed |= v->i64 < 0;
+ needs_signed |= v->i64 < 0;
needs_decimal |= v->u64 >= 10;
break;
case 32:
- needs_signed |= v->i32 < 0;
+ needs_signed |= v->i32 < 0;
needs_decimal |= v->u32 >= 10;
break;
case 16:
- needs_signed |= v->i16 < 0;
+ needs_signed |= v->i16 < 0;
needs_decimal |= v->u16 >= 10;
break;
case 8:
- needs_signed |= v->i8 < 0;
+ needs_signed |= v->i8 < 0;
needs_decimal |= v->u8 >= 10;
break;
default:
get_constant_sampler_addressing_mode(enum cl_sampler_addressing_mode mode)
{
switch (mode) {
- case SAMPLER_ADDRESSING_MODE_NONE: return "none";
- case SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE: return "clamp_to_edge";
- case SAMPLER_ADDRESSING_MODE_CLAMP: return "clamp";
- case SAMPLER_ADDRESSING_MODE_REPEAT: return "repeat";
- case SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED: return "repeat_mirrored";
- default: unreachable("Invalid addressing mode");
+ case SAMPLER_ADDRESSING_MODE_NONE:
+ return "none";
+ case SAMPLER_ADDRESSING_MODE_CLAMP_TO_EDGE:
+ return "clamp_to_edge";
+ case SAMPLER_ADDRESSING_MODE_CLAMP:
+ return "clamp";
+ case SAMPLER_ADDRESSING_MODE_REPEAT:
+ return "repeat";
+ case SAMPLER_ADDRESSING_MODE_REPEAT_MIRRORED:
+ return "repeat_mirrored";
+ default:
+ unreachable("Invalid addressing mode");
}
}
get_constant_sampler_filter_mode(enum cl_sampler_filter_mode mode)
{
switch (mode) {
- case SAMPLER_FILTER_MODE_NEAREST: return "nearest";
- case SAMPLER_FILTER_MODE_LINEAR: return "linear";
- default: unreachable("Invalid filter mode");
+ case SAMPLER_FILTER_MODE_NEAREST:
+ return "nearest";
+ case SAMPLER_FILTER_MODE_LINEAR:
+ return "linear";
+ default:
+ unreachable("Invalid filter mode");
}
}
assert(cols == 1);
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "%s", c->values[i].b ? "true" : "false");
}
break;
assert(cols == 1);
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "0x%02x", c->values[i].u8);
}
break;
assert(cols == 1);
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "0x%04x", c->values[i].u16);
}
break;
assert(cols == 1);
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "0x%08x", c->values[i].u32);
}
break;
case GLSL_TYPE_DOUBLE:
if (cols > 1) {
for (i = 0; i < cols; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
print_constant(c->elements[i], glsl_get_column_type(type), state);
}
} else {
switch (glsl_get_base_type(type)) {
case GLSL_TYPE_FLOAT16:
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "%f", _mesa_half_to_float(c->values[i].u16));
}
break;
case GLSL_TYPE_FLOAT:
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "%f", c->values[i].f32);
}
break;
case GLSL_TYPE_DOUBLE:
for (i = 0; i < rows; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "%f", c->values[i].f64);
}
break;
assert(cols == 1);
for (i = 0; i < cols; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "0x%08" PRIx64, c->values[i].u64);
}
break;
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_INTERFACE:
for (i = 0; i < c->num_elements; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "{ ");
print_constant(c->elements[i], glsl_get_struct_field(type, i), state);
fprintf(fp, " }");
case GLSL_TYPE_ARRAY:
for (i = 0; i < c->num_elements; i++) {
- if (i > 0) fprintf(fp, ", ");
+ if (i > 0)
+ fprintf(fp, ", ");
fprintf(fp, "{ ");
print_constant(c->elements[i], glsl_get_array_element(type), state);
fprintf(fp, " }");
const char *const ronly = (access & ACCESS_NON_WRITEABLE) ? "readonly " : "";
const char *const wonly = (access & ACCESS_NON_READABLE) ? "writeonly " : "";
const char *const reorder = (access & ACCESS_CAN_REORDER) ? "reorderable " : "";
- const char *const non_temporal = (access & ACCESS_NON_TEMPORAL) ?
- "non-temporal" : "";
- const char *const include_helpers = (access & ACCESS_INCLUDE_HELPERS) ?
- "include-helpers " : "";
+ const char *const non_temporal = (access & ACCESS_NON_TEMPORAL) ? "non-temporal" : "";
+ const char *const include_helpers = (access & ACCESS_INCLUDE_HELPERS) ? "include-helpers " : "";
fprintf(fp, "%s%s%s%s%s%s%s%s", coher, volat, restr, ronly, wonly, reorder,
non_temporal, include_helpers);
unsigned int num_components =
glsl_get_components(glsl_without_array(var->type));
const char *components = NULL;
- char components_local[18] = {'.' /* the rest is 0-filled */};
+ char components_local[18] = { '.' /* the rest is 0-filled */ };
switch (var->data.mode) {
case nir_var_shader_in:
case nir_var_shader_out:
case nir_deref_type_array:
case nir_deref_type_ptr_as_array: {
if (nir_src_is_const(instr->arr.index)) {
- fprintf(fp, "[%"PRId64"]", nir_src_as_int(instr->arr.index));
+ fprintf(fp, "[%" PRId64 "]", nir_src_as_int(instr->arr.index));
} else {
fprintf(fp, "[");
print_src(&instr->arr.index, state, nir_type_invalid);
while (modes) {
int m = u_bit_scan(&modes);
fprintf(fp, "%s%s", get_variable_mode_str(1 << m, true),
- modes ? "|" : "");
+ modes ? "|" : "");
}
fprintf(fp, " %s)", glsl_get_type_name(instr->type));
vulkan_descriptor_type_name(VkDescriptorType type)
{
switch (type) {
- case VK_DESCRIPTOR_TYPE_SAMPLER: return "sampler";
- case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: return "texture+sampler";
- case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: return "texture";
- case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: return "image";
- case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: return "texture-buffer";
- case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: return "image-buffer";
- case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: return "UBO";
- case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: return "SSBO";
- case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: return "UBO";
- case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: return "SSBO";
- case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: return "input-att";
- case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK: return "inline-UBO";
- case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR: return "accel-struct";
- default: return "unknown";
+ case VK_DESCRIPTOR_TYPE_SAMPLER:
+ return "sampler";
+ case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
+ return "texture+sampler";
+ case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
+ return "texture";
+ case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
+ return "image";
+ case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
+ return "texture-buffer";
+ case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
+ return "image-buffer";
+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
+ return "UBO";
+ case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
+ return "SSBO";
+ case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
+ return "UBO";
+ case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
+ return "SSBO";
+ case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
+ return "input-att";
+ case VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
+ return "inline-UBO";
+ case VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
+ return "accel-struct";
+ default:
+ return "unknown";
}
}
const char *name;
switch (nir_alu_type_get_base_type(type)) {
- case nir_type_int: name = "int"; break;
- case nir_type_uint: name = "uint"; break;
- case nir_type_bool: name = "bool"; break;
- case nir_type_float: name = "float"; break;
- default: name = "invalid";
+ case nir_type_int:
+ name = "int";
+ break;
+ case nir_type_uint:
+ name = "uint";
+ break;
+ case nir_type_bool:
+ name = "bool";
+ break;
+ case nir_type_float:
+ name = "float";
+ break;
+ default:
+ name = "invalid";
}
if (size)
fprintf(fp, "%s%u", name, size);
fprintf(fp, "atomic_op=");
switch (atomic_op) {
- case nir_atomic_op_iadd: fprintf(fp, "iadd"); break;
- case nir_atomic_op_imin: fprintf(fp, "imin"); break;
- case nir_atomic_op_umin: fprintf(fp, "umin"); break;
- case nir_atomic_op_imax: fprintf(fp, "imax"); break;
- case nir_atomic_op_umax: fprintf(fp, "umax"); break;
- case nir_atomic_op_iand: fprintf(fp, "iand"); break;
- case nir_atomic_op_ior: fprintf(fp, "ior"); break;
- case nir_atomic_op_ixor: fprintf(fp, "ixor"); break;
- case nir_atomic_op_xchg: fprintf(fp, "xchg"); break;
- case nir_atomic_op_fadd: fprintf(fp, "fadd"); break;
- case nir_atomic_op_fmin: fprintf(fp, "fmin"); break;
- case nir_atomic_op_fmax: fprintf(fp, "fmax"); break;
- case nir_atomic_op_cmpxchg: fprintf(fp, "cmpxchg"); break;
- case nir_atomic_op_fcmpxchg: fprintf(fp, "fcmpxchg"); break;
- case nir_atomic_op_inc_wrap: fprintf(fp, "inc_wrap"); break;
- case nir_atomic_op_dec_wrap: fprintf(fp, "dec_wrap"); break;
+ case nir_atomic_op_iadd:
+ fprintf(fp, "iadd");
+ break;
+ case nir_atomic_op_imin:
+ fprintf(fp, "imin");
+ break;
+ case nir_atomic_op_umin:
+ fprintf(fp, "umin");
+ break;
+ case nir_atomic_op_imax:
+ fprintf(fp, "imax");
+ break;
+ case nir_atomic_op_umax:
+ fprintf(fp, "umax");
+ break;
+ case nir_atomic_op_iand:
+ fprintf(fp, "iand");
+ break;
+ case nir_atomic_op_ior:
+ fprintf(fp, "ior");
+ break;
+ case nir_atomic_op_ixor:
+ fprintf(fp, "ixor");
+ break;
+ case nir_atomic_op_xchg:
+ fprintf(fp, "xchg");
+ break;
+ case nir_atomic_op_fadd:
+ fprintf(fp, "fadd");
+ break;
+ case nir_atomic_op_fmin:
+ fprintf(fp, "fmin");
+ break;
+ case nir_atomic_op_fmax:
+ fprintf(fp, "fmax");
+ break;
+ case nir_atomic_op_cmpxchg:
+ fprintf(fp, "cmpxchg");
+ break;
+ case nir_atomic_op_fcmpxchg:
+ fprintf(fp, "fcmpxchg");
+ break;
+ case nir_atomic_op_inc_wrap:
+ fprintf(fp, "inc_wrap");
+ break;
+ case nir_atomic_op_dec_wrap:
+ fprintf(fp, "dec_wrap");
+ break;
}
break;
}
fprintf(fp, "%d", (mask >> (i * 2) & 3));
} else if (instr->intrinsic == nir_intrinsic_masked_swizzle_amd) {
fprintf(fp, "((id & %d) | %d) ^ %d", mask & 0x1F,
- (mask >> 5) & 0x1F,
- (mask >> 10) & 0x1F);
+ (mask >> 5) & 0x1F,
+ (mask >> 10) & 0x1F);
} else {
fprintf(fp, "%d", mask);
}
nir_memory_semantics semantics = nir_intrinsic_memory_semantics(instr);
fprintf(fp, "mem_semantics=");
switch (semantics & (NIR_MEMORY_ACQUIRE | NIR_MEMORY_RELEASE)) {
- case 0: fprintf(fp, "NONE"); break;
- case NIR_MEMORY_ACQUIRE: fprintf(fp, "ACQ"); break;
- case NIR_MEMORY_RELEASE: fprintf(fp, "REL"); break;
- default: fprintf(fp, "ACQ|REL"); break;
+ case 0:
+ fprintf(fp, "NONE");
+ break;
+ case NIR_MEMORY_ACQUIRE:
+ fprintf(fp, "ACQ");
+ break;
+ case NIR_MEMORY_RELEASE:
+ fprintf(fp, "REL");
+ break;
+ default:
+ fprintf(fp, "ACQ|REL");
+ break;
}
- if (semantics & (NIR_MEMORY_MAKE_AVAILABLE)) fprintf(fp, "|AVAILABLE");
- if (semantics & (NIR_MEMORY_MAKE_VISIBLE)) fprintf(fp, "|VISIBLE");
+ if (semantics & (NIR_MEMORY_MAKE_AVAILABLE))
+ fprintf(fp, "|AVAILABLE");
+ if (semantics & (NIR_MEMORY_MAKE_VISIBLE))
+ fprintf(fp, "|VISIBLE");
break;
}
fprintf(fp, " no_sysval_output");
if (state->shader &&
- state->shader->info.stage == MESA_SHADER_GEOMETRY &&
- (instr->intrinsic == nir_intrinsic_store_output ||
- instr->intrinsic == nir_intrinsic_store_per_primitive_output ||
- instr->intrinsic == nir_intrinsic_store_per_vertex_output)) {
+ state->shader->info.stage == MESA_SHADER_GEOMETRY &&
+ (instr->intrinsic == nir_intrinsic_store_output ||
+ instr->intrinsic == nir_intrinsic_store_per_primitive_output ||
+ instr->intrinsic == nir_intrinsic_store_per_vertex_output)) {
unsigned gs_streams = io.gs_streams;
fprintf(fp, " gs_streams(");
for (unsigned i = 0; i < 4; i++) {
bool first = true;
for (unsigned i = 0; i < 2; i++) {
unsigned start_comp = (idx == NIR_INTRINSIC_IO_XFB ? 0 : 2) + i;
- nir_io_xfb xfb = start_comp < 2 ? nir_intrinsic_io_xfb(instr) :
- nir_intrinsic_io_xfb2(instr);
+ nir_io_xfb xfb = start_comp < 2 ? nir_intrinsic_io_xfb(instr) : nir_intrinsic_io_xfb2(instr);
if (!xfb.out[i].num_components)
continue;
case NIR_INTRINSIC_ROUNDING_MODE: {
fprintf(fp, "rounding_mode=");
switch (nir_intrinsic_rounding_mode(instr)) {
- case nir_rounding_mode_undef: fprintf(fp, "undef"); break;
- case nir_rounding_mode_rtne: fprintf(fp, "rtne"); break;
- case nir_rounding_mode_ru: fprintf(fp, "ru"); break;
- case nir_rounding_mode_rd: fprintf(fp, "rd"); break;
- case nir_rounding_mode_rtz: fprintf(fp, "rtz"); break;
- default: fprintf(fp, "unknown"); break;
+ case nir_rounding_mode_undef:
+ fprintf(fp, "undef");
+ break;
+ case nir_rounding_mode_rtne:
+ fprintf(fp, "rtne");
+ break;
+ case nir_rounding_mode_ru:
+ fprintf(fp, "ru");
+ break;
+ case nir_rounding_mode_rd:
+ fprintf(fp, "rd");
+ break;
+ case nir_rounding_mode_rtz:
+ fprintf(fp, "rtz");
+ break;
+ default:
+ fprintf(fp, "unknown");
+ break;
}
break;
}
case NIR_INTRINSIC_RAY_QUERY_VALUE: {
fprintf(fp, "ray_query_value=");
switch (nir_intrinsic_ray_query_value(instr)) {
-#define VAL(_name) case nir_ray_query_value_##_name: fprintf(fp, #_name); break
- VAL(intersection_type);
- VAL(intersection_t);
- VAL(intersection_instance_custom_index);
- VAL(intersection_instance_id);
- VAL(intersection_instance_sbt_index);
- VAL(intersection_geometry_index);
- VAL(intersection_primitive_index);
- VAL(intersection_barycentrics);
- VAL(intersection_front_face);
- VAL(intersection_object_ray_direction);
- VAL(intersection_object_ray_origin);
- VAL(intersection_object_to_world);
- VAL(intersection_world_to_object);
- VAL(intersection_candidate_aabb_opaque);
- VAL(tmin);
- VAL(flags);
- VAL(world_ray_direction);
- VAL(world_ray_origin);
+#define VAL(_name) \
+ case nir_ray_query_value_##_name: \
+ fprintf(fp, #_name); \
+ break
+ VAL(intersection_type);
+ VAL(intersection_t);
+ VAL(intersection_instance_custom_index);
+ VAL(intersection_instance_id);
+ VAL(intersection_instance_sbt_index);
+ VAL(intersection_geometry_index);
+ VAL(intersection_primitive_index);
+ VAL(intersection_barycentrics);
+ VAL(intersection_front_face);
+ VAL(intersection_object_ray_direction);
+ VAL(intersection_object_ray_origin);
+ VAL(intersection_object_to_world);
+ VAL(intersection_world_to_object);
+ VAL(intersection_candidate_aabb_opaque);
+ VAL(tmin);
+ VAL(flags);
+ VAL(world_ray_direction);
+ VAL(world_ray_origin);
#undef VAL
- default: fprintf(fp, "unknown"); break;
+ default:
+ fprintf(fp, "unknown");
+ break;
}
break;
}
while (modes) {
nir_resource_data_intel i = 1u << u_bit_scan(&modes);
switch (i) {
- case nir_resource_intel_bindless: fprintf(fp, "bindless"); break;
- case nir_resource_intel_pushable: fprintf(fp, "pushable"); break;
- case nir_resource_intel_sampler: fprintf(fp, "sampler"); break;
+ case nir_resource_intel_bindless:
+ fprintf(fp, "bindless");
+ break;
+ case nir_resource_intel_pushable:
+ fprintf(fp, "pushable");
+ break;
+ case nir_resource_intel_sampler:
+ fprintf(fp, "sampler");
+ break;
case nir_resource_intel_non_uniform:
- fprintf(fp, "non-uniform"); break;
- default: fprintf(fp, "unknown"); break;
+ fprintf(fp, "non-uniform");
+ break;
+ default:
+ fprintf(fp, "unknown");
+ break;
}
fprintf(fp, "%s", modes ? "|" : "");
}
nir_foreach_variable_with_modes(var, state->shader, var_mode) {
if ((var->data.driver_location == nir_intrinsic_base(instr)) &&
(instr->intrinsic == nir_intrinsic_load_uniform ||
- (nir_intrinsic_component(instr) >= var->data.location_frac &&
+ (nir_intrinsic_component(instr) >= var->data.location_frac &&
nir_intrinsic_component(instr) <
- (var->data.location_frac + glsl_get_components(var->type)))) &&
- var->name) {
+ (var->data.location_frac + glsl_get_components(var->type)))) &&
+ var->name) {
fprintf(fp, " // %s", var->name);
break;
}
print_src(&instr->src[i].src, state, nir_tex_instr_src_type(instr, i));
fprintf(fp, " ");
- switch(instr->src[i].src_type) {
+ switch (instr->src[i].src_type) {
case nir_tex_src_backend1:
fprintf(fp, "(backend1)");
break;
}
static void
-print_ssa_undef_instr(nir_ssa_undef_instr* instr, print_state *state)
+print_ssa_undef_instr(nir_ssa_undef_instr *instr, print_state *state)
{
FILE *fp = state->fp;
print_ssa_def(&instr->def, state);
}
const unsigned block_length = 7 + count_digits(block->index) + 1;
- const unsigned pred_padding = block_length < state->padding_for_no_dest ?
- state->padding_for_no_dest - block_length : 0;
+ const unsigned pred_padding = block_length < state->padding_for_no_dest ? state->padding_for_no_dest - block_length : 0;
fprintf(fp, "%*s// preds: ", pred_padding, "");
print_block_preds(block, state);
static const char *
primitive_name(unsigned primitive)
{
-#define PRIM(X) case MESA_PRIM_ ## X : return #X
+#define PRIM(X) \
+ case MESA_PRIM_##X: \
+ return #X
switch (primitive) {
- PRIM(POINTS);
- PRIM(LINES);
- PRIM(LINE_LOOP);
- PRIM(LINE_STRIP);
- PRIM(TRIANGLES);
- PRIM(TRIANGLE_STRIP);
- PRIM(TRIANGLE_FAN);
- PRIM(QUADS);
- PRIM(QUAD_STRIP);
- PRIM(POLYGON);
+ PRIM(POINTS);
+ PRIM(LINES);
+ PRIM(LINE_LOOP);
+ PRIM(LINE_STRIP);
+ PRIM(TRIANGLES);
+ PRIM(TRIANGLE_STRIP);
+ PRIM(TRIANGLE_FAN);
+ PRIM(QUADS);
+ PRIM(QUAD_STRIP);
+ PRIM(POLYGON);
default:
return "UNKNOWN";
}
print_nz_x64(FILE *fp, const char *label, uint64_t value)
{
if (value) {
- char acc[256] = {0};
+ char acc[256] = { 0 };
char buf[32];
int start = 0;
int count = 0;
info->xfb_stride[2],
info->xfb_stride[3]);
- bool has_inlinable_uniform_dw_offsets = info->inlinable_uniform_dw_offsets[0]
- || info->inlinable_uniform_dw_offsets[1]
- || info->inlinable_uniform_dw_offsets[2]
- || info->inlinable_uniform_dw_offsets[3];
+ bool has_inlinable_uniform_dw_offsets = info->inlinable_uniform_dw_offsets[0] || info->inlinable_uniform_dw_offsets[1] || info->inlinable_uniform_dw_offsets[2] || info->inlinable_uniform_dw_offsets[3];
if (has_inlinable_uniform_dw_offsets)
fprintf(fp, "inlinable_uniform_dw_offsets: {%u, %u, %u, %u}\n",
info->inlinable_uniform_dw_offsets[0],
break;
case MESA_SHADER_COMPUTE:
- if (info->cs.workgroup_size_hint[0]
- || info->cs.workgroup_size_hint[1]
- || info->cs.workgroup_size_hint[2])
+ if (info->cs.workgroup_size_hint[0] || info->cs.workgroup_size_hint[1] || info->cs.workgroup_size_hint[2])
fprintf(fp, "workgroup_size_hint: {%u, %u, %u}\n",
info->cs.workgroup_size_hint[0],
info->cs.workgroup_size_hint[1],
print_deref_link(deref, true, &state);
}
-void nir_log_shader_annotated_tagged(enum mesa_log_level level, const char *tag,
- nir_shader *shader, struct hash_table *annotations)
+void
+nir_log_shader_annotated_tagged(enum mesa_log_level level, const char *tag,
+ nir_shader *shader, struct hash_table *annotations)
{
char *str = nir_shader_as_str_annotated(shader, annotations, NULL);
_mesa_log_multiline(level, tag, str);
}
static bool
-var_is_invariant(nir_variable *var, struct set * invariants)
+var_is_invariant(nir_variable *var, struct set *invariants)
{
/* Because we pass the result of nir_intrinsic_get_var directly to this
* function, it's possible for var to be NULL if, for instance, there's a
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
-#include <math.h>
-#include <float.h>
-#include "nir.h"
#include "nir_range_analysis.h"
+#include <float.h>
+#include <math.h>
#include "util/hash_table.h"
-#include "util/u_math.h"
#include "util/u_dynarray.h"
+#include "util/u_math.h"
#include "c99_alloca.h"
+#include "nir.h"
/**
* Analyzes a sequence of operations to determine some aspects of the range of
{
while (state->query_stack.size) {
struct analysis_query *cur =
- (struct analysis_query *)((char*)util_dynarray_end(&state->query_stack) - state->query_size);
+ (struct analysis_query *)((char *)util_dynarray_end(&state->query_stack) - state->query_size);
uint32_t *result = util_dynarray_element(&state->result_stack, uint32_t, cur->result_index);
uintptr_t key = state->get_key(cur);
* them by testing pushed_queries.
*/
if (cur->pushed_queries == 0 && key &&
- (he = _mesa_hash_table_search(state->range_ht, (void*)key))) {
+ (he = _mesa_hash_table_search(state->range_ht, (void *)key))) {
*result = (uintptr_t)he->data;
state->query_stack.size -= state->query_size;
continue;
}
- uint32_t *src = (uint32_t*)util_dynarray_end(&state->result_stack) - cur->pushed_queries;
+ uint32_t *src = (uint32_t *)util_dynarray_end(&state->result_stack) - cur->pushed_queries;
state->result_stack.size -= sizeof(uint32_t) * cur->pushed_queries;
uint32_t prev_num_queries = state->query_stack.size;
}
if (key)
- _mesa_hash_table_insert(state->range_ht, (void*)key, (void*)(uintptr_t)*result);
+ _mesa_hash_table_insert(state->range_ht, (void *)key, (void *)(uintptr_t)*result);
state->query_stack.size -= state->query_size;
}
unpack_data(uint32_t v)
{
return (struct ssa_result_range){
- .range = v & 0xff,
+ .range = v & 0xff,
.is_integral = (v & 0x00100) != 0,
- .is_finite = (v & 0x00200) != 0,
+ .is_finite = (v & 0x00200) != 0,
.is_a_number = (v & 0x00400) != 0
};
}
*/
#define _______ unknown
-
#if defined(__clang__)
- /* clang wants _Pragma("unroll X") */
- #define pragma_unroll_5 _Pragma("unroll 5")
- #define pragma_unroll_7 _Pragma("unroll 7")
+/* clang wants _Pragma("unroll X") */
+#define pragma_unroll_5 _Pragma("unroll 5")
+#define pragma_unroll_7 _Pragma("unroll 7")
/* gcc wants _Pragma("GCC unroll X") */
#elif defined(__GNUC__)
- #if __GNUC__ >= 8
- #define pragma_unroll_5 _Pragma("GCC unroll 5")
- #define pragma_unroll_7 _Pragma("GCC unroll 7")
- #else
- #pragma GCC optimize ("unroll-loops")
- #define pragma_unroll_5
- #define pragma_unroll_7
- #endif
+#if __GNUC__ >= 8
+#define pragma_unroll_5 _Pragma("GCC unroll 5")
+#define pragma_unroll_7 _Pragma("GCC unroll 7")
#else
- /* MSVC doesn't have C99's _Pragma() */
- #define pragma_unroll_5
- #define pragma_unroll_7
+#pragma GCC optimize("unroll-loops")
+#define pragma_unroll_5
+#define pragma_unroll_7
+#endif
+#else
+/* MSVC doesn't have C99's _Pragma() */
+#define pragma_unroll_5
+#define pragma_unroll_7
#endif
-
#ifndef NDEBUG
-#define ASSERT_TABLE_IS_COMMUTATIVE(t) \
- do { \
- static bool first = true; \
- if (first) { \
- first = false; \
- pragma_unroll_7 \
- for (unsigned r = 0; r < ARRAY_SIZE(t); r++) { \
- pragma_unroll_7 \
- for (unsigned c = 0; c < ARRAY_SIZE(t[0]); c++) \
- assert(t[r][c] == t[c][r]); \
- } \
- } \
+#define ASSERT_TABLE_IS_COMMUTATIVE(t) \
+ do { \
+ static bool first = true; \
+ if (first) { \
+ first = false; \
+ pragma_unroll_7 for (unsigned r = 0; r < ARRAY_SIZE(t); r++) \
+ { \
+ pragma_unroll_7 for (unsigned c = 0; c < ARRAY_SIZE(t[0]); c++) \
+ assert(t[r][c] == t[c][r]); \
+ } \
+ } \
} while (false)
-#define ASSERT_TABLE_IS_DIAGONAL(t) \
- do { \
- static bool first = true; \
- if (first) { \
- first = false; \
- pragma_unroll_7 \
- for (unsigned r = 0; r < ARRAY_SIZE(t); r++) \
- assert(t[r][r] == r); \
- } \
+#define ASSERT_TABLE_IS_DIAGONAL(t) \
+ do { \
+ static bool first = true; \
+ if (first) { \
+ first = false; \
+ pragma_unroll_7 for (unsigned r = 0; r < ARRAY_SIZE(t); r++) \
+ assert(t[r][r] == r); \
+ } \
} while (false)
#else
/* Verify that the 'unknown' entry in each row (or column) of the table is the
* union of all the other values in the row (or column).
*/
-#define ASSERT_UNION_OF_OTHERS_MATCHES_UNKNOWN_2_SOURCE(t) \
- do { \
- static bool first = true; \
- if (first) { \
- first = false; \
- pragma_unroll_7 \
- for (unsigned i = 0; i < last_range; i++) { \
- enum ssa_ranges col_range = t[i][unknown + 1]; \
- enum ssa_ranges row_range = t[unknown + 1][i]; \
- \
- pragma_unroll_5 \
- for (unsigned j = unknown + 2; j < last_range; j++) { \
- col_range = union_ranges(col_range, t[i][j]); \
- row_range = union_ranges(row_range, t[j][i]); \
- } \
- \
- assert(col_range == t[i][unknown]); \
- assert(row_range == t[unknown][i]); \
- } \
- } \
+#define ASSERT_UNION_OF_OTHERS_MATCHES_UNKNOWN_2_SOURCE(t) \
+ do { \
+ static bool first = true; \
+ if (first) { \
+ first = false; \
+ pragma_unroll_7 for (unsigned i = 0; i < last_range; i++) \
+ { \
+ enum ssa_ranges col_range = t[i][unknown + 1]; \
+ enum ssa_ranges row_range = t[unknown + 1][i]; \
+ \
+ pragma_unroll_5 for (unsigned j = unknown + 2; j < last_range; j++) \
+ { \
+ col_range = union_ranges(col_range, t[i][j]); \
+ row_range = union_ranges(row_range, t[j][i]); \
+ } \
+ \
+ assert(col_range == t[i][unknown]); \
+ assert(row_range == t[unknown][i]); \
+ } \
+ } \
} while (false)
/* For most operations, the union of ranges for a strict inequality and
* Does not apply to selection-like opcodes (bcsel, fmin, fmax, etc.).
*/
#define ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_1_SOURCE(t) \
- do { \
- assert(union_ranges(t[lt_zero], t[eq_zero]) == t[le_zero]); \
- assert(union_ranges(t[gt_zero], t[eq_zero]) == t[ge_zero]); \
+ do { \
+ assert(union_ranges(t[lt_zero], t[eq_zero]) == t[le_zero]); \
+ assert(union_ranges(t[gt_zero], t[eq_zero]) == t[ge_zero]); \
} while (false)
-#define ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_2_SOURCE(t) \
- do { \
- static bool first = true; \
- if (first) { \
- first = false; \
- pragma_unroll_7 \
- for (unsigned i = 0; i < last_range; i++) { \
+#define ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_2_SOURCE(t) \
+ do { \
+ static bool first = true; \
+ if (first) { \
+ first = false; \
+ pragma_unroll_7 for (unsigned i = 0; i < last_range; i++) \
+ { \
assert(union_ranges(t[i][lt_zero], t[i][eq_zero]) == t[i][le_zero]); \
assert(union_ranges(t[i][gt_zero], t[i][eq_zero]) == t[i][ge_zero]); \
assert(union_ranges(t[lt_zero][i], t[eq_zero][i]) == t[le_zero][i]); \
assert(union_ranges(t[gt_zero][i], t[eq_zero][i]) == t[ge_zero][i]); \
- } \
- } \
+ } \
+ } \
} while (false)
/* Several other unordered tuples span the range of "everything." Each should
* possibilities, so the union of all the unions of disjoint ranges is
* equivalent to the union of "others."
*/
-#define ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_1_SOURCE(t) \
- do { \
- assert(union_ranges(t[lt_zero], t[ge_zero]) == t[unknown]); \
- assert(union_ranges(t[le_zero], t[gt_zero]) == t[unknown]); \
- assert(union_ranges(t[eq_zero], t[ne_zero]) == t[unknown]); \
+#define ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_1_SOURCE(t) \
+ do { \
+ assert(union_ranges(t[lt_zero], t[ge_zero]) == t[unknown]); \
+ assert(union_ranges(t[le_zero], t[gt_zero]) == t[unknown]); \
+ assert(union_ranges(t[eq_zero], t[ne_zero]) == t[unknown]); \
} while (false)
-#define ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_2_SOURCE(t) \
- do { \
- static bool first = true; \
- if (first) { \
- first = false; \
- pragma_unroll_7 \
- for (unsigned i = 0; i < last_range; i++) { \
- assert(union_ranges(t[i][lt_zero], t[i][ge_zero]) == \
- t[i][unknown]); \
- assert(union_ranges(t[i][le_zero], t[i][gt_zero]) == \
- t[i][unknown]); \
- assert(union_ranges(t[i][eq_zero], t[i][ne_zero]) == \
- t[i][unknown]); \
- \
- assert(union_ranges(t[lt_zero][i], t[ge_zero][i]) == \
- t[unknown][i]); \
- assert(union_ranges(t[le_zero][i], t[gt_zero][i]) == \
- t[unknown][i]); \
- assert(union_ranges(t[eq_zero][i], t[ne_zero][i]) == \
- t[unknown][i]); \
- } \
- } \
+#define ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_2_SOURCE(t) \
+ do { \
+ static bool first = true; \
+ if (first) { \
+ first = false; \
+ pragma_unroll_7 for (unsigned i = 0; i < last_range; i++) \
+ { \
+ assert(union_ranges(t[i][lt_zero], t[i][ge_zero]) == \
+ t[i][unknown]); \
+ assert(union_ranges(t[i][le_zero], t[i][gt_zero]) == \
+ t[i][unknown]); \
+ assert(union_ranges(t[i][eq_zero], t[i][ne_zero]) == \
+ t[i][unknown]); \
+ \
+ assert(union_ranges(t[lt_zero][i], t[ge_zero][i]) == \
+ t[unknown][i]); \
+ assert(union_ranges(t[le_zero][i], t[gt_zero][i]) == \
+ t[unknown][i]); \
+ assert(union_ranges(t[eq_zero][i], t[ne_zero][i]) == \
+ t[unknown][i]); \
+ } \
+ } \
} while (false)
#else
* As a result, the number of bits does not need to be encoded here.
*/
switch (nir_alu_type_get_base_type(fp_q->use_type)) {
- case nir_type_int: type_encoding = 0; break;
- case nir_type_uint: type_encoding = 1; break;
- case nir_type_bool: type_encoding = 2; break;
- case nir_type_float: type_encoding = 3; break;
- default: unreachable("Invalid base type.");
+ case nir_type_int:
+ type_encoding = 0;
+ break;
+ case nir_type_uint:
+ type_encoding = 1;
+ break;
+ case nir_type_bool:
+ type_encoding = 2;
+ break;
+ case nir_type_float:
+ type_encoding = 3;
+ break;
+ default:
+ unreachable("Invalid base type.");
}
return ptr | type_encoding;
}
if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_alu) {
- *result = pack_data((struct ssa_result_range){unknown, false, false, false});
+ *result = pack_data((struct ssa_result_range){ unknown, false, false, false });
return;
}
const struct nir_alu_instr *const alu =
- nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);
+ nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);
/* Bail if the type of the instruction generating the value does not match
* the type the value will be interpreted as. int/uint/bool can be
if (use_base_type != src_base_type &&
(use_base_type == nir_type_float ||
src_base_type == nir_type_float)) {
- *result = pack_data((struct ssa_result_range){unknown, false, false, false});
+ *result = pack_data((struct ssa_result_range){ unknown, false, false, false });
return;
}
}
}
}
- struct ssa_result_range r = {unknown, false, false, false};
+ struct ssa_result_range r = { unknown, false, false, false };
/* ge_zero: ge_zero + ge_zero
*
ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_2_SOURCE(fmul_table);
static const enum ssa_ranges fneg_table[last_range + 1] = {
- /* unknown lt_zero le_zero gt_zero ge_zero ne_zero eq_zero */
+ /* unknown lt_zero le_zero gt_zero ge_zero ne_zero eq_zero */
_______, gt_zero, ge_zero, lt_zero, le_zero, ne_zero, eq_zero
};
ASSERT_UNION_OF_DISJOINT_MATCHES_UNKNOWN_1_SOURCE(fneg_table);
ASSERT_UNION_OF_EQ_AND_STRICT_INEQ_MATCHES_NONSTRICT_1_SOURCE(fneg_table);
-
switch (alu->op) {
case nir_op_b2f32:
case nir_op_b2i32:
* 1.401298464324817e-45. The latter is subnormal, but it is finite and
* a number.
*/
- r = (struct ssa_result_range){ge_zero, alu->op == nir_op_b2f32, true, true};
+ r = (struct ssa_result_range){ ge_zero, alu->op == nir_op_b2f32, true, true };
break;
case nir_op_bcsel: {
* operands is finite, then the result cannot be NaN.
*/
r.is_a_number = left.is_a_number && right.is_a_number &&
- (left.is_finite || right.is_finite);
+ (left.is_finite || right.is_finite);
break;
}
* parameters, the result will flush to zero.
*/
static const enum ssa_ranges table[last_range + 1] = {
- /* unknown lt_zero le_zero gt_zero ge_zero ne_zero eq_zero */
+ /* unknown lt_zero le_zero gt_zero ge_zero ne_zero eq_zero */
ge_zero, ge_zero, ge_zero, gt_zero, gt_zero, ge_zero, gt_zero
};
* the other cannot be zero, then the result must be a number.
*/
r.is_a_number = (left.is_a_number && right.is_a_number) &&
- ((left.is_finite && right.is_finite) ||
- (!is_not_zero(left.range) && right.is_finite) ||
- (left.is_finite && !is_not_zero(right.range)));
+ ((left.is_finite && right.is_finite) ||
+ (!is_not_zero(left.range) && right.is_finite) ||
+ (left.is_finite && !is_not_zero(right.range)));
} else {
/* nir_op_fmulz: unlike nir_op_fmul, 0 * ±Inf is a number. */
r.is_a_number = left.is_a_number && right.is_a_number;
case nir_op_fsqrt:
case nir_op_frsq:
- r = (struct ssa_result_range){ge_zero, false, false, false};
+ r = (struct ssa_result_range){ ge_zero, false, false, false };
break;
case nir_op_ffloor: {
case nir_op_ult:
case nir_op_uge:
/* Boolean results are 0 or -1. */
- r = (struct ssa_result_range){le_zero, false, true, false};
+ r = (struct ssa_result_range){ le_zero, false, true, false };
break;
case nir_op_fdot2:
* Inf-Inf in the dot-product, the result must also be a number.
*/
if (nir_alu_srcs_equal(alu, alu, 0, 1)) {
- r = (struct ssa_result_range){ge_zero, false, left.is_a_number, false };
+ r = (struct ssa_result_range){ ge_zero, false, left.is_a_number, false };
} else if (nir_alu_srcs_negative_equal(alu, alu, 0, 1)) {
- r = (struct ssa_result_range){le_zero, false, left.is_a_number, false };
+ r = (struct ssa_result_range){ le_zero, false, left.is_a_number, false };
} else {
- r = (struct ssa_result_range){unknown, false, false, false};
+ r = (struct ssa_result_range){ unknown, false, false, false };
}
break;
}
}
default:
- r = (struct ssa_result_range){unknown, false, false, false};
+ r = (struct ssa_result_range){ unknown, false, false, false };
break;
}
r.is_integral = true;
/* Just like isfinite(), the is_finite flag implies the value is a number. */
- assert((int) r.is_finite <= (int) r.is_a_number);
+ assert((int)r.is_finite <= (int)r.is_a_number);
*result = pack_data(r);
}
return unpack_data(perform_analysis(&state));
}
-static uint32_t bitmask(uint32_t size) {
+static uint32_t
+bitmask(uint32_t size)
+{
return size >= 32 ? 0xffffffffu : ((uint32_t)1 << size) - 1u;
}
-static uint64_t mul_clamp(uint32_t a, uint32_t b)
+static uint64_t
+mul_clamp(uint32_t a, uint32_t b)
{
if (a != 0 && (a * b) / a != b)
return (uint64_t)UINT32_MAX + 1;
nir_foreach_phi_src(src, phi) {
num_sources_left--;
unsigned added = search_phi_bcsel(nir_get_ssa_scalar(src->src.ssa, scalar.comp),
- buf + total_added, buf_size - num_sources_left, visited);
+ buf + total_added, buf_size - num_sources_left, visited);
assert(added <= buf_size);
buf_size -= added;
total_added += added;
* unbounded. On some hardware max_workgroup_count[1] and
* max_workgroup_count[2] may be smaller.
*/
- .max_workgroup_count = {UINT32_MAX, UINT32_MAX, UINT32_MAX},
+ .max_workgroup_count = { UINT32_MAX, UINT32_MAX, UINT32_MAX },
/* max_workgroup_size is the local invocation maximum. This is generally
* small the OpenGL 4.2 minimum maximum is 1024.
*/
- .max_workgroup_size = {UINT16_MAX, UINT16_MAX, UINT16_MAX},
+ .max_workgroup_size = { UINT16_MAX, UINT16_MAX, UINT16_MAX },
.vertex_attrib_max = {
- UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX,
- UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX,
- UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX,
- UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
+ UINT32_MAX,
},
};
/* keys can't be 0, so we have to add 1 to the index */
unsigned shift_amount = ffs(NIR_MAX_VEC_COMPONENTS) - 1;
return nir_ssa_scalar_is_const(scalar)
- ? 0
- : ((uintptr_t)(scalar.def->index + 1) << shift_amount) | scalar.comp;
+ ? 0
+ : ((uintptr_t)(scalar.def->index + 1) << shift_amount) | scalar.comp;
}
static void
} else {
*result = (shader->info.workgroup_size[0] *
shader->info.workgroup_size[1] *
- shader->info.workgroup_size[2]) - 1u;
+ shader->info.workgroup_size[2]) -
+ 1u;
}
break;
case nir_intrinsic_load_local_invocation_id:
case nir_intrinsic_load_global_invocation_id:
if (shader->info.workgroup_size_variable) {
*result = mul_clamp(config->max_workgroup_size[q.scalar.comp],
- config->max_workgroup_count[q.scalar.comp]) - 1u;
+ config->max_workgroup_count[q.scalar.comp]) -
+ 1u;
} else {
*result = (shader->info.workgroup_size[q.scalar.comp] *
- config->max_workgroup_count[q.scalar.comp]) - 1u;
+ config->max_workgroup_count[q.scalar.comp]) -
+ 1u;
}
break;
case nir_intrinsic_load_invocation_id:
if (shader->info.stage == MESA_SHADER_TESS_CTRL)
*result = shader->info.tess.tcs_vertices_out
- ? (shader->info.tess.tcs_vertices_out - 1)
- : 511; /* Generous maximum output patch size of 512 */
+ ? (shader->info.tess.tcs_vertices_out - 1)
+ : 511; /* Generous maximum output patch size of 512 */
break;
case nir_intrinsic_load_subgroup_invocation:
case nir_intrinsic_first_invocation:
if (format == PIPE_FORMAT_NONE)
break;
- const struct util_format_description* desc = util_format_description(format);
+ const struct util_format_description *desc = util_format_description(format);
if (desc->channel[q.scalar.comp].type != UTIL_FORMAT_TYPE_UNSIGNED)
break;
nir_ssa_scalar src1_scalar = nir_ssa_scalar_chase_alu_src(q.scalar, 1);
if (nir_ssa_scalar_is_const(src1_scalar))
*result = nir_ssa_scalar_as_uint(src1_scalar)
- ? src[0] / nir_ssa_scalar_as_uint(src1_scalar) : 0;
+ ? src[0] / nir_ssa_scalar_as_uint(src1_scalar)
+ : 0;
else
*result = src[0];
break;
if (!prev || prev->type == nir_cf_node_block) {
/* Resolve cycles by inserting max into range_ht. */
uint32_t max = bitmask(q.scalar.def->bit_size);
- _mesa_hash_table_insert(state->range_ht, (void*)get_uub_key(&q.head), (void*)(uintptr_t)max);
+ _mesa_hash_table_insert(state->range_ht, (void *)get_uub_key(&q.head), (void *)(uintptr_t)max);
struct set *visited = _mesa_pointer_set_create(NULL);
nir_ssa_scalar *defs = alloca(sizeof(nir_ssa_scalar) * 64);
uint32_t
nir_unsigned_upper_bound(nir_shader *shader, struct hash_table *range_ht,
nir_ssa_scalar scalar,
- const nir_unsigned_upper_bound_config *config) {
+ const nir_unsigned_upper_bound_config *config)
+{
if (!config)
config = &default_ub_config;
if (modes & ~nir_var_function_temp) {
progress = remove_dead_vars(&shader->variables, modes,
- live, opts) || progress;
+ live, opts) ||
+ progress;
}
if (modes & nir_var_function_temp) {
if (progress) {
remove_dead_var_writes(shader);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
strip_shadow(const struct glsl_type *type)
{
const struct glsl_type *new_type =
- glsl_sampler_type(
- glsl_get_sampler_dim(type),
- false, glsl_sampler_type_is_array(type),
- GLSL_TYPE_FLOAT);
+ glsl_sampler_type(
+ glsl_get_sampler_dim(type),
+ false, glsl_sampler_type_is_array(type),
+ GLSL_TYPE_FLOAT);
return new_type;
}
-
static inline const struct glsl_type *
strip_shadow_with_array(const struct glsl_type *type)
{
return false;
nir_variable *sampler = data;
- nir_deref_instr *deref = nir_instr_as_deref (instr);
+ nir_deref_instr *deref = nir_instr_as_deref(instr);
if (deref->var == sampler) {
deref->type = sampler->type;
return true;
state.progress = false;
nir_metadata_require(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
nir_foreach_block(block, impl) {
nir_foreach_instr_safe(instr, block) {
if (state.progress)
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
if (state.phi_builder) {
nir_phi_builder_finish(state.phi_builder);
nir_ssa_def *final_a =
nir_bcsel(b, big, scaled_down_a,
- (nir_bcsel(b, small, scaled_up_a, orig_a)));
+ (nir_bcsel(b, small, scaled_up_a, orig_a)));
nir_ssa_def *final_b =
nir_bcsel(b, big, scaled_down_b,
- (nir_bcsel(b, small, scaled_up_b, orig_b)));
+ (nir_bcsel(b, small, scaled_up_b, orig_b)));
nir_ssa_def *new_div = nir_fdiv(b, final_a, final_b);
nir_ssa_def_rewrite_uses(&alu->dest.dest.ssa, new_div);
{
return nir_shader_instructions_pass(shader, nir_scale_fdiv_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
/* When walking the instructions in reverse, we use this flag to swap
* before/after in add_dep().
*/
-enum direction { F, R };
+enum direction { F,
+ R };
struct nir_schedule_class_dep {
int klass;
dag_add_edge(&after->dag, &before->dag, 0);
}
-
static void
add_read_dep(nir_deps_state *state,
nir_schedule_node *before,
}
n->max_delay = MAX2(n->max_delay, max_delay + n->delay);
- }
+}
static void
nir_schedule_block(nir_schedule_scoreboard *scoreboard, nir_block *block)
set_foreach(remaining_uses, instr_entry) {
if (!any_uses) {
fprintf(stderr, "Tracked uses remain after scheduling. "
- "Affected instructions: \n");
+ "Affected instructions: \n");
any_uses = true;
}
nir_print_instr(instr_entry->key, stderr);
* true then a dependency should be added and dep is filled in to describe
* it.
*/
- bool (* intrinsic_cb)(nir_intrinsic_instr *intr,
- nir_schedule_dependency *dep,
- void *user_data);
+ bool (*intrinsic_cb)(nir_intrinsic_instr *intr,
+ nir_schedule_dependency *dep,
+ void *user_data);
/* Data to pass to the intrinsic callback */
void *intrinsic_cb_data;
/* Callback used to specify instruction delays */
- unsigned (* instr_delay_cb)(nir_instr *instr, void *user_data);
+ unsigned (*instr_delay_cb)(nir_instr *instr, void *user_data);
/* Data to pass to the instruction delay callback */
void *instr_delay_cb_data;
* IN THE SOFTWARE.
*/
-#include <inttypes.h>
#include "nir_search.h"
+#include <inttypes.h>
+#include "util/half_float.h"
#include "nir_builder.h"
#include "nir_worklist.h"
-#include "util/half_float.h"
/* This should be the same as nir_search_max_comm_ops in nir_algebraic.py. */
#define NIR_SEARCH_MAX_COMM_OPS 8
nir_algebraic_automaton(nir_instr *instr, struct util_dynarray *states,
const struct per_op_table *pass_op_table);
-static const uint8_t identity_swizzle[NIR_MAX_VEC_COMPONENTS] =
-{
- 0, 1, 2, 3,
- 4, 5, 6, 7,
- 8, 9, 10, 11,
- 12, 13, 14, 15,
+static const uint8_t identity_swizzle[NIR_MAX_VEC_COMPONENTS] = {
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8,
+ 9,
+ 10,
+ 11,
+ 12,
+ 13,
+ 14,
+ 15,
};
/**
if (sop <= nir_last_opcode)
return nop == sop;
-#define MATCH_FCONV_CASE(op) \
- case nir_search_op_##op: \
+#define MATCH_FCONV_CASE(op) \
+ case nir_search_op_##op: \
return nop == nir_op_##op##16 || \
nop == nir_op_##op##32 || \
nop == nir_op_##op##64;
-#define MATCH_ICONV_CASE(op) \
- case nir_search_op_##op: \
- return nop == nir_op_##op##8 || \
+#define MATCH_ICONV_CASE(op) \
+ case nir_search_op_##op: \
+ return nop == nir_op_##op##8 || \
nop == nir_op_##op##16 || \
nop == nir_op_##op##32 || \
nop == nir_op_##op##64;
switch (sop) {
- MATCH_FCONV_CASE(i2f)
- MATCH_FCONV_CASE(u2f)
- MATCH_FCONV_CASE(f2f)
- MATCH_ICONV_CASE(f2u)
- MATCH_ICONV_CASE(f2i)
- MATCH_ICONV_CASE(u2u)
- MATCH_ICONV_CASE(i2i)
- MATCH_FCONV_CASE(b2f)
- MATCH_ICONV_CASE(b2i)
+ MATCH_FCONV_CASE(i2f)
+ MATCH_FCONV_CASE(u2f)
+ MATCH_FCONV_CASE(f2f)
+ MATCH_ICONV_CASE(f2u)
+ MATCH_ICONV_CASE(f2i)
+ MATCH_ICONV_CASE(u2u)
+ MATCH_ICONV_CASE(i2i)
+ MATCH_FCONV_CASE(b2f)
+ MATCH_ICONV_CASE(b2i)
default:
unreachable("Invalid nir_search_op");
}
nir_search_op_for_nir_op(nir_op nop)
{
#define MATCH_FCONV_CASE(op) \
- case nir_op_##op##16: \
- case nir_op_##op##32: \
- case nir_op_##op##64: \
+ case nir_op_##op##16: \
+ case nir_op_##op##32: \
+ case nir_op_##op##64: \
return nir_search_op_##op;
#define MATCH_ICONV_CASE(op) \
- case nir_op_##op##8: \
- case nir_op_##op##16: \
- case nir_op_##op##32: \
- case nir_op_##op##64: \
+ case nir_op_##op##8: \
+ case nir_op_##op##16: \
+ case nir_op_##op##32: \
+ case nir_op_##op##64: \
return nir_search_op_##op;
-
switch (nop) {
- MATCH_FCONV_CASE(i2f)
- MATCH_FCONV_CASE(u2f)
- MATCH_FCONV_CASE(f2f)
- MATCH_ICONV_CASE(f2u)
- MATCH_ICONV_CASE(f2i)
- MATCH_ICONV_CASE(u2u)
- MATCH_ICONV_CASE(i2i)
- MATCH_FCONV_CASE(b2f)
- MATCH_ICONV_CASE(b2i)
+ MATCH_FCONV_CASE(i2f)
+ MATCH_FCONV_CASE(u2f)
+ MATCH_FCONV_CASE(f2f)
+ MATCH_ICONV_CASE(f2u)
+ MATCH_ICONV_CASE(f2i)
+ MATCH_ICONV_CASE(u2u)
+ MATCH_ICONV_CASE(i2i)
+ MATCH_FCONV_CASE(b2f)
+ MATCH_ICONV_CASE(b2i)
default:
return nop;
}
if (sop <= nir_last_opcode)
return sop;
-#define RET_FCONV_CASE(op) \
- case nir_search_op_##op: \
- switch (bit_size) { \
- case 16: return nir_op_##op##16; \
- case 32: return nir_op_##op##32; \
- case 64: return nir_op_##op##64; \
- default: unreachable("Invalid bit size"); \
+#define RET_FCONV_CASE(op) \
+ case nir_search_op_##op: \
+ switch (bit_size) { \
+ case 16: \
+ return nir_op_##op##16; \
+ case 32: \
+ return nir_op_##op##32; \
+ case 64: \
+ return nir_op_##op##64; \
+ default: \
+ unreachable("Invalid bit size"); \
}
-#define RET_ICONV_CASE(op) \
- case nir_search_op_##op: \
- switch (bit_size) { \
- case 8: return nir_op_##op##8; \
- case 16: return nir_op_##op##16; \
- case 32: return nir_op_##op##32; \
- case 64: return nir_op_##op##64; \
- default: unreachable("Invalid bit size"); \
+#define RET_ICONV_CASE(op) \
+ case nir_search_op_##op: \
+ switch (bit_size) { \
+ case 8: \
+ return nir_op_##op##8; \
+ case 16: \
+ return nir_op_##op##16; \
+ case 32: \
+ return nir_op_##op##32; \
+ case 64: \
+ return nir_op_##op##64; \
+ default: \
+ unreachable("Invalid bit size"); \
}
switch (sop) {
- RET_FCONV_CASE(i2f)
- RET_FCONV_CASE(u2f)
- RET_FCONV_CASE(f2f)
- RET_ICONV_CASE(f2u)
- RET_ICONV_CASE(f2i)
- RET_ICONV_CASE(u2u)
- RET_ICONV_CASE(i2i)
- RET_FCONV_CASE(b2f)
- RET_ICONV_CASE(b2i)
+ RET_FCONV_CASE(i2f)
+ RET_FCONV_CASE(u2f)
+ RET_FCONV_CASE(f2f)
+ RET_ICONV_CASE(f2u)
+ RET_ICONV_CASE(f2i)
+ RET_ICONV_CASE(u2u)
+ RET_ICONV_CASE(i2i)
+ RET_FCONV_CASE(b2f)
+ RET_ICONV_CASE(b2i)
default:
unreachable("Invalid nir_search_op");
}
*/
unsigned comm_op_flip =
(expr->comm_expr_idx >= 0 &&
- expr->comm_expr_idx < NIR_SEARCH_MAX_COMM_OPS) ?
- ((state->comm_op_direction >> expr->comm_expr_idx) & 1) : 0;
+ expr->comm_expr_idx < NIR_SEARCH_MAX_COMM_OPS)
+ ? ((state->comm_op_direction >> expr->comm_expr_idx) & 1)
+ : 0;
bool matched = true;
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; i++) {
}
}
-UNUSED static void dump_value(const nir_algebraic_table *table, const nir_search_value *val)
+UNUSED static void
+dump_value(const nir_algebraic_table *table, const nir_search_value *val)
{
switch (val->type) {
case nir_search_value_constant: {
fprintf(stderr, "%f", sconst->data.d);
break;
case nir_type_int:
- fprintf(stderr, "%"PRId64, sconst->data.i);
+ fprintf(stderr, "%" PRId64, sconst->data.i);
break;
case nir_type_uint:
- fprintf(stderr, "0x%"PRIx64, sconst->data.u);
+ fprintf(stderr, "0x%" PRIx64, sconst->data.u);
break;
case nir_type_bool:
fprintf(stderr, "%s", sconst->data.u != 0 ? "True" : "False");
if (expr->inexact)
fprintf(stderr, "~");
switch (expr->opcode) {
-#define CASE(n) \
- case nir_search_op_##n: fprintf(stderr, #n); break;
- CASE(b2f)
- CASE(b2i)
- CASE(i2i)
- CASE(f2i)
- CASE(i2f)
+#define CASE(n) \
+ case nir_search_op_##n: \
+ fprintf(stderr, #n); \
+ break;
+ CASE(b2f)
+ CASE(b2i)
+ CASE(i2i)
+ CASE(f2i)
+ CASE(i2f)
#undef CASE
default:
fprintf(stderr, "%s", nir_op_infos[expr->opcode].name);
* state 0 is the default state, which means we don't have to visit
* anything other than constants and ALU instructions.
*/
- struct util_dynarray states = {0};
+ struct util_dynarray states = { 0 };
if (!util_dynarray_resize(&states, uint16_t, impl->ssa_alloc)) {
nir_metadata_preserve(impl, nir_metadata_all);
return false;
if (progress) {
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
#ifndef _NIR_SEARCH_
#define _NIR_SEARCH_
+#include "util/u_dynarray.h"
#include "nir.h"
#include "nir_worklist.h"
-#include "util/u_dynarray.h"
#define NIR_SEARCH_MAX_VARIABLES 16
};
struct transform {
- uint16_t search; /* Index in table->values[] for the search expression. */
+ uint16_t search; /* Index in table->values[] for the search expression. */
uint16_t replace; /* Index in table->values[] for the replace value. */
unsigned condition_offset;
};
#ifndef _NIR_SEARCH_HELPERS_
#define _NIR_SEARCH_HELPERS_
-#include "nir.h"
+#include <math.h>
#include "util/bitscan.h"
+#include "nir.h"
#include "nir_range_analysis.h"
-#include <math.h>
static inline bool
is_pos_power_of_two(UNUSED struct hash_table *ht, const nir_alu_instr *instr,
return true;
}
-#define MULTIPLE(test) \
-static inline bool \
-is_unsigned_multiple_of_ ## test(UNUSED struct hash_table *ht, \
- const nir_alu_instr *instr, \
- unsigned src, unsigned num_components, \
- const uint8_t *swizzle) \
-{ \
- /* only constant srcs: */ \
- if (!nir_src_is_const(instr->src[src].src)) \
- return false; \
- \
- for (unsigned i = 0; i < num_components; i++) { \
- uint64_t val = nir_src_comp_as_uint(instr->src[src].src, swizzle[i]); \
- if (val % test != 0) \
- return false; \
- } \
- \
- return true; \
-}
+#define MULTIPLE(test) \
+ static inline bool \
+ is_unsigned_multiple_of_##test(UNUSED struct hash_table *ht, \
+ const nir_alu_instr *instr, \
+ unsigned src, unsigned num_components, \
+ const uint8_t *swizzle) \
+ { \
+ /* only constant srcs: */ \
+ if (!nir_src_is_const(instr->src[src].src)) \
+ return false; \
+ \
+ for (unsigned i = 0; i < num_components; i++) { \
+ uint64_t val = nir_src_comp_as_uint(instr->src[src].src, swizzle[i]); \
+ if (val % test != 0) \
+ return false; \
+ } \
+ \
+ return true; \
+ }
MULTIPLE(2)
MULTIPLE(4)
const nir_alu_instr *const user_alu = nir_instr_as_alu(user_instr);
assert(instr != user_alu);
- unsigned index = (nir_alu_src*)container_of(src, nir_alu_src, src) - user_alu->src;
+ unsigned index = (nir_alu_src *)container_of(src, nir_alu_src, src) - user_alu->src;
nir_alu_type type = nir_op_infos[user_alu->op].input_types[index];
if (nir_alu_type_get_base_type(type) != nir_type_float)
return false;
unsigned half_bit_size = nir_src_bit_size(instr->src[src].src) / 2;
uint64_t high_bits = u_bit_consecutive64(half_bit_size, half_bit_size);
if ((nir_src_comp_as_uint(instr->src[src].src,
- swizzle[i]) & high_bits) != 0) {
+ swizzle[i]) &
+ high_bits) != 0) {
return false;
}
}
unsigned half_bit_size = nir_src_bit_size(instr->src[src].src) / 2;
uint64_t high_bits = u_bit_consecutive64(half_bit_size, half_bit_size);
if ((nir_src_comp_as_uint(instr->src[src].src,
- swizzle[i]) & high_bits) != high_bits) {
+ swizzle[i]) &
+ high_bits) != high_bits) {
return false;
}
}
(v.range == lt_zero || v.range == gt_zero || v.range == ne_zero);
}
-
-#define RELATION(r) \
-static inline bool \
-is_ ## r (struct hash_table *ht, const nir_alu_instr *instr, \
- unsigned src, UNUSED unsigned num_components, \
- UNUSED const uint8_t *swizzle) \
-{ \
- const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \
- return v.range == r; \
-} \
- \
-static inline bool \
-is_a_number_ ## r (struct hash_table *ht, const nir_alu_instr *instr, \
- unsigned src, UNUSED unsigned num_components, \
- UNUSED const uint8_t *swizzle) \
-{ \
- const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \
- return v.is_a_number && v.range == r; \
-}
+#define RELATION(r) \
+ static inline bool \
+ is_##r(struct hash_table *ht, const nir_alu_instr *instr, \
+ unsigned src, UNUSED unsigned num_components, \
+ UNUSED const uint8_t *swizzle) \
+ { \
+ const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \
+ return v.range == r; \
+ } \
+ \
+ static inline bool \
+ is_a_number_##r(struct hash_table *ht, const nir_alu_instr *instr, \
+ unsigned src, UNUSED unsigned num_components, \
+ UNUSED const uint8_t *swizzle) \
+ { \
+ const struct ssa_result_range v = nir_analyze_range(ht, instr, src); \
+ return v.is_a_number && v.range == r; \
+ }
RELATION(lt_zero)
RELATION(le_zero)
(v.range == ge_zero || v.range == gt_zero || v.range == eq_zero);
}
-
static inline bool
is_not_positive(struct hash_table *ht, const nir_alu_instr *instr, unsigned src,
UNUSED unsigned num_components, UNUSED const uint8_t *swizzle)
*/
#include "nir_serialize.h"
-#include "nir_control_flow.h"
-#include "nir_xfb_info.h"
#include "util/u_dynarray.h"
#include "util/u_math.h"
+#include "nir_control_flow.h"
+#include "nir_xfb_info.h"
#define NIR_SERIALIZE_FUNC_HAS_IMPL ((void *)(intptr_t)1)
-#define MAX_OBJECT_IDS (1 << 20)
+#define MAX_OBJECT_IDS (1 << 20)
typedef struct {
size_t blob_offset;
{
uint32_t index = ctx->next_idx++;
assert(index != MAX_OBJECT_IDS);
- _mesa_hash_table_insert(ctx->remap_table, obj, (void *)(uintptr_t) index);
+ _mesa_hash_table_insert(ctx->remap_table, obj, (void *)(uintptr_t)index);
}
static uint32_t
{
struct hash_entry *entry = _mesa_hash_table_search(ctx->remap_table, obj);
assert(entry);
- return (uint32_t)(uintptr_t) entry->data;
+ return (uint32_t)(uintptr_t)entry->data;
}
static void
return 0;
}
-#define NUM_COMPONENTS_IS_SEPARATE_7 7
+#define NUM_COMPONENTS_IS_SEPARATE_7 7
static uint8_t
encode_num_components_in_3bits(uint8_t num_components)
union packed_var {
uint32_t u32;
struct {
- unsigned has_name:1;
- unsigned has_constant_initializer:1;
- unsigned has_pointer_initializer:1;
- unsigned has_interface_type:1;
- unsigned num_state_slots:7;
- unsigned data_encoding:2;
- unsigned type_same_as_last:1;
- unsigned interface_type_same_as_last:1;
- unsigned ray_query:1;
- unsigned num_members:16;
+ unsigned has_name : 1;
+ unsigned has_constant_initializer : 1;
+ unsigned has_pointer_initializer : 1;
+ unsigned has_interface_type : 1;
+ unsigned num_state_slots : 7;
+ unsigned data_encoding : 2;
+ unsigned type_same_as_last : 1;
+ unsigned interface_type_same_as_last : 1;
+ unsigned ray_query : 1;
+ unsigned num_members : 16;
} u;
};
union packed_var_data_diff {
uint32_t u32;
struct {
- int location:13;
- int location_frac:3;
- int driver_location:16;
+ int location : 13;
+ int location_frac : 3;
+ int driver_location : 16;
} u;
};
blob_write_uint32(ctx->blob,
write_lookup_object(ctx, var->pointer_initializer));
if (var->num_members > 0) {
- blob_write_bytes(ctx->blob, (uint8_t *) var->members,
+ blob_write_bytes(ctx->blob, (uint8_t *)var->members,
var->num_members * sizeof(*var->members));
}
}
else if (flags.u.data_encoding == var_encode_function_temp)
var->data.mode = nir_var_function_temp;
else if (flags.u.data_encoding == var_encode_full) {
- blob_copy_bytes(ctx->blob, (uint8_t *) &var->data, sizeof(var->data));
+ blob_copy_bytes(ctx->blob, (uint8_t *)&var->data, sizeof(var->data));
ctx->last_var_data = var->data;
} else { /* var_encode_location_diff */
union packed_var_data_diff diff;
if (var->num_members > 0) {
var->members = ralloc_array(var, struct nir_variable_data,
var->num_members);
- blob_copy_bytes(ctx->blob, (uint8_t *) var->members,
+ blob_copy_bytes(ctx->blob, (uint8_t *)var->members,
var->num_members * sizeof(*var->members));
}
union packed_src {
uint32_t u32;
struct {
- unsigned _pad:2; /* <-- Header */
- unsigned object_idx:20;
- unsigned _footer:10; /* <-- Footer */
+ unsigned _pad : 2; /* <-- Header */
+ unsigned object_idx : 20;
+ unsigned _footer : 10; /* <-- Footer */
} any;
struct {
- unsigned _header:22; /* <-- Header */
- unsigned _pad:2; /* <-- Footer */
- unsigned swizzle_x:2;
- unsigned swizzle_y:2;
- unsigned swizzle_z:2;
- unsigned swizzle_w:2;
+ unsigned _header : 22; /* <-- Header */
+ unsigned _pad : 2; /* <-- Footer */
+ unsigned swizzle_x : 2;
+ unsigned swizzle_y : 2;
+ unsigned swizzle_z : 2;
+ unsigned swizzle_w : 2;
} alu;
struct {
- unsigned _header:22; /* <-- Header */
- unsigned src_type:5; /* <-- Footer */
- unsigned _pad:5;
+ unsigned _header : 22; /* <-- Header */
+ unsigned src_type : 5; /* <-- Footer */
+ unsigned _pad : 5;
} tex;
};
static void
write_src(write_ctx *ctx, const nir_src *src)
{
- union packed_src header = {0};
+ union packed_src header = { 0 };
write_src_full(ctx, src, header);
}
union packed_dest {
uint8_t u8;
struct {
- uint8_t _pad:1;
- uint8_t num_components:3;
- uint8_t bit_size:3;
- uint8_t divergent:1;
+ uint8_t _pad : 1;
+ uint8_t num_components : 3;
+ uint8_t bit_size : 3;
+ uint8_t divergent : 1;
};
};
union packed_instr {
uint32_t u32;
struct {
- unsigned instr_type:4; /* always present */
- unsigned _pad:20;
- unsigned dest:8; /* always last */
+ unsigned instr_type : 4; /* always present */
+ unsigned _pad : 20;
+ unsigned dest : 8; /* always last */
} any;
struct {
- unsigned instr_type:4;
- unsigned exact:1;
- unsigned no_signed_wrap:1;
- unsigned no_unsigned_wrap:1;
- unsigned padding:1;
+ unsigned instr_type : 4;
+ unsigned exact : 1;
+ unsigned no_signed_wrap : 1;
+ unsigned no_unsigned_wrap : 1;
+ unsigned padding : 1;
/* Reg: writemask; SSA: swizzles for 2 srcs */
- unsigned writemask_or_two_swizzles:4;
- unsigned op:9;
- unsigned packed_src_ssa_16bit:1;
+ unsigned writemask_or_two_swizzles : 4;
+ unsigned op : 9;
+ unsigned packed_src_ssa_16bit : 1;
/* Scalarized ALUs always have the same header. */
- unsigned num_followup_alu_sharing_header:2;
- unsigned dest:8;
+ unsigned num_followup_alu_sharing_header : 2;
+ unsigned dest : 8;
} alu;
struct {
- unsigned instr_type:4;
- unsigned deref_type:3;
- unsigned cast_type_same_as_last:1;
- unsigned modes:5; /* See (de|en)code_deref_modes() */
- unsigned _pad:9;
- unsigned in_bounds:1;
- unsigned packed_src_ssa_16bit:1; /* deref_var redefines this */
- unsigned dest:8;
+ unsigned instr_type : 4;
+ unsigned deref_type : 3;
+ unsigned cast_type_same_as_last : 1;
+ unsigned modes : 5; /* See (de|en)code_deref_modes() */
+ unsigned _pad : 9;
+ unsigned in_bounds : 1;
+ unsigned packed_src_ssa_16bit : 1; /* deref_var redefines this */
+ unsigned dest : 8;
} deref;
struct {
- unsigned instr_type:4;
- unsigned deref_type:3;
- unsigned _pad:1;
- unsigned object_idx:16; /* if 0, the object ID is a separate uint32 */
- unsigned dest:8;
+ unsigned instr_type : 4;
+ unsigned deref_type : 3;
+ unsigned _pad : 1;
+ unsigned object_idx : 16; /* if 0, the object ID is a separate uint32 */
+ unsigned dest : 8;
} deref_var;
struct {
- unsigned instr_type:4;
- unsigned intrinsic:10;
- unsigned const_indices_encoding:2;
- unsigned packed_const_indices:8;
- unsigned dest:8;
+ unsigned instr_type : 4;
+ unsigned intrinsic : 10;
+ unsigned const_indices_encoding : 2;
+ unsigned packed_const_indices : 8;
+ unsigned dest : 8;
} intrinsic;
struct {
- unsigned instr_type:4;
- unsigned last_component:4;
- unsigned bit_size:3;
- unsigned packing:2; /* enum load_const_packing */
- unsigned packed_value:19; /* meaning determined by packing */
+ unsigned instr_type : 4;
+ unsigned last_component : 4;
+ unsigned bit_size : 3;
+ unsigned packing : 2; /* enum load_const_packing */
+ unsigned packed_value : 19; /* meaning determined by packing */
} load_const;
struct {
- unsigned instr_type:4;
- unsigned last_component:4;
- unsigned bit_size:3;
- unsigned _pad:21;
+ unsigned instr_type : 4;
+ unsigned last_component : 4;
+ unsigned bit_size : 3;
+ unsigned _pad : 21;
} undef;
struct {
- unsigned instr_type:4;
- unsigned num_srcs:4;
- unsigned op:5;
- unsigned _pad:11;
- unsigned dest:8;
+ unsigned instr_type : 4;
+ unsigned num_srcs : 4;
+ unsigned op : 5;
+ unsigned _pad : 11;
+ unsigned dest : 8;
} tex;
struct {
- unsigned instr_type:4;
- unsigned num_srcs:20;
- unsigned dest:8;
+ unsigned instr_type : 4;
+ unsigned num_srcs : 20;
+ unsigned dest : 8;
} phi;
struct {
- unsigned instr_type:4;
- unsigned type:2;
- unsigned _pad:26;
+ unsigned instr_type : 4;
+ unsigned type : 2;
+ unsigned _pad : 26;
} jump;
};
unsigned value = 0;
for (unsigned j = 0; j < 8 && o + j < src_channels; j++) {
- value |= (uint32_t)alu->src[i].swizzle[o + j] <<
- (4 * j); /* 4 bits per swizzle */
+ value |= (uint32_t)alu->src[i].swizzle[o + j] << (4 * j); /* 4 bits per swizzle */
}
blob_write_uint32(ctx->blob, value);
union packed_tex_data {
uint32_t u32;
struct {
- unsigned sampler_dim:4;
- unsigned dest_type:8;
- unsigned coord_components:3;
- unsigned is_array:1;
- unsigned is_shadow:1;
- unsigned is_new_style_shadow:1;
- unsigned is_sparse:1;
- unsigned component:2;
- unsigned texture_non_uniform:1;
- unsigned sampler_non_uniform:1;
- unsigned array_is_lowered_cube:1;
- unsigned is_gather_implicit_lod:1;
- unsigned unused:5; /* Mark unused for valgrind. */
+ unsigned sampler_dim : 4;
+ unsigned dest_type : 8;
+ unsigned coord_components : 3;
+ unsigned is_array : 1;
+ unsigned is_shadow : 1;
+ unsigned is_new_style_shadow : 1;
+ unsigned is_sparse : 1;
+ unsigned component : 2;
+ unsigned texture_non_uniform : 1;
+ unsigned sampler_non_uniform : 1;
+ unsigned array_is_lowered_cube : 1;
+ unsigned is_gather_implicit_lod : 1;
+ unsigned unused : 5; /* Mark unused for valgrind. */
} u;
};
nir_instr_insert_after_block(blk, &phi->instr);
for (unsigned i = 0; i < header.phi.num_srcs; i++) {
- nir_ssa_def *def = (nir_ssa_def *)(uintptr_t) blob_read_uint32(ctx->blob);
- nir_block *pred = (nir_block *)(uintptr_t) blob_read_uint32(ctx->blob);
+ nir_ssa_def *def = (nir_ssa_def *)(uintptr_t)blob_read_uint32(ctx->blob);
+ nir_block *pred = (nir_block *)(uintptr_t)blob_read_uint32(ctx->blob);
nir_phi_src *src = nir_phi_instr_add_src(phi, pred, nir_src_for_ssa(def));
/* Since we're not letting nir_insert_instr handle use/def stuff for us,
void
nir_serialize(struct blob *blob, const nir_shader *nir, bool strip)
{
- write_ctx ctx = {0};
+ write_ctx ctx = { 0 };
ctx.remap_table = _mesa_pointer_hash_table_create(NULL);
ctx.blob = blob;
ctx.nir = nir;
if (!strip && info.label)
blob_write_string(blob, info.label);
info.name = info.label = NULL;
- blob_write_bytes(blob, (uint8_t *) &info, sizeof(info));
+ blob_write_bytes(blob, (uint8_t *)&info, sizeof(info));
write_var_list(&ctx, &nir->variables);
const struct nir_shader_compiler_options *options,
struct blob_reader *blob)
{
- read_ctx ctx = {0};
+ read_ctx ctx = { 0 };
ctx.blob = blob;
list_inithead(&ctx.phi_srcs);
ctx.idx_table_len = blob_read_uint32(blob);
char *label = (strings & 0x2) ? blob_read_string(blob) : NULL;
struct shader_info info;
- blob_copy_bytes(blob, (uint8_t *) &info, sizeof(info));
+ blob_copy_bytes(blob, (uint8_t *)&info, sizeof(info));
ctx.nir = nir_shader_create(mem_ctx, info.stage, options, NULL);
#ifndef _NIR_SERIALIZE_H
#define _NIR_SERIALIZE_H
-#include "nir.h"
#include "util/blob.h"
+#include "nir.h"
#ifdef __cplusplus
extern "C" {
#include "nir.h"
#include "nir_builder.h"
-#include "nir_deref.h"
#include "util/hash_table.h"
+#include "nir_deref.h"
/* This pass splits stores to and loads from 64 bit vec3
* and vec4 local variables to use at most vec2, and it also
const void *data)
{
switch (instr->type) {
- case nir_instr_type_intrinsic: {
+ case nir_instr_type_intrinsic: {
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
switch (intr->intrinsic) {
return false;
return nir_src_num_components(intr->src[1]) >= 3;
default:
- return false;
- }
+ return false;
+ }
}
}
case nir_instr_type_phi: {
- nir_phi_instr *phi = nir_instr_as_phi(instr);
- if (nir_dest_bit_size(phi->dest) != 64)
- return false;
- return nir_dest_num_components(phi->dest) >= 3;
- }
+ nir_phi_instr *phi = nir_instr_as_phi(instr);
+ if (nir_dest_bit_size(phi->dest) != 64)
+ return false;
+ return nir_dest_num_components(phi->dest) >= 3;
+ }
default:
return false;
nir_variable *zw;
} variable_pair;
-
static nir_ssa_def *
merge_to_vec3_or_vec4(nir_builder *b, nir_ssa_def *load1,
nir_ssa_def *load2)
return offset;
}
-
static variable_pair *
get_var_pair(nir_builder *b, nir_variable *old_var,
- struct hash_table *split_vars)
+ struct hash_table *split_vars)
{
variable_pair *new_var = NULL;
unsigned old_components = glsl_get_components(
- glsl_without_array_or_matrix(old_var->type));
+ glsl_without_array_or_matrix(old_var->type));
assert(old_components > 2 && old_components <= 4);
_mesa_hash_table_insert(split_vars, old_var, new_var);
} else
- new_var = (variable_pair *)entry->data;
+ new_var = (variable_pair *)entry->data;
return new_var;
}
{
nir_variable *old_var = nir_intrinsic_get_var(intr, 0);
unsigned old_components = glsl_get_components(
- glsl_without_array_or_matrix(old_var->type));
+ glsl_without_array_or_matrix(old_var->type));
variable_pair *vars = get_var_pair(b, old_var, split_vars);
nir_ssa_dest_init(&vec->instr, &vec->dest.dest,
phi->dest.ssa.num_components, 64);
- int num_comp[2] = {2, phi->dest.ssa.num_components - 2};
+ int num_comp[2] = { 2, phi->dest.ssa.num_components - 2 };
nir_phi_instr *new_phi[2];
case nir_intrinsic_load_deref: {
nir_deref_instr *deref =
- nir_instr_as_deref(intr->src[0].ssa->parent_instr);
+ nir_instr_as_deref(intr->src[0].ssa->parent_instr);
if (deref->deref_type == nir_deref_type_var)
return split_load_deref(b, intr, NULL, split_vars);
else if (deref->deref_type == nir_deref_type_array) {
return split_load_deref(b, intr, get_linear_array_offset(b, deref), split_vars);
- }
- else
+ } else
unreachable("Only splitting of loads from vars and arrays");
}
case nir_intrinsic_store_deref: {
nir_deref_instr *deref =
- nir_instr_as_deref(intr->src[0].ssa->parent_instr);
+ nir_instr_as_deref(intr->src[0].ssa->parent_instr);
if (deref->deref_type == nir_deref_type_var)
return split_store_deref(b, intr, NULL, split_vars);
else if (deref->deref_type == nir_deref_type_array)
- return split_store_deref(b, intr, get_linear_array_offset(b, deref), split_vars);
+ return split_store_deref(b, intr, get_linear_array_offset(b, deref), split_vars);
else
unreachable("Only splitting of stores to vars and arrays");
- }
+ }
default:
unreachable("Only splitting load_deref and store_deref");
return NULL;
}
-
bool
nir_split_64bit_vec3_and_vec4(nir_shader *sh)
{
struct hash_table *split_vars = _mesa_pointer_hash_table_create(NULL);
bool progress =
- nir_shader_lower_instructions(sh,
- nir_split_64bit_vec3_and_vec4_filter,
- nir_split_64bit_vec3_and_vec4_impl,
- split_vars);
+ nir_shader_lower_instructions(sh,
+ nir_split_64bit_vec3_and_vec4_filter,
+ nir_split_64bit_vec3_and_vec4_impl,
+ split_vars);
_mesa_hash_table_destroy(split_vars, NULL);
return progress;
struct hash_table *var_to_member_map =
_mesa_pointer_hash_table_create(dead_ctx);
- nir_foreach_variable_with_modes_safe(var, shader, nir_var_shader_in |
- nir_var_shader_out |
- nir_var_system_value) {
+ nir_foreach_variable_with_modes_safe(var, shader, nir_var_shader_in | nir_var_shader_out | nir_var_system_value) {
if (var->num_members == 0)
continue;
nir_shader_instructions_pass(shader, rewrite_deref_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
var_to_member_map);
ralloc_free(dead_ctx);
} else if (glsl_type_is_struct_or_ifc(src->type)) {
for (unsigned i = 0; i < glsl_get_length(src->type); i++) {
split_deref_copy_instr(b, nir_build_deref_struct(b, dst, i),
- nir_build_deref_struct(b, src, i),
- dst_access, src_access);
+ nir_build_deref_struct(b, src, i),
+ dst_access, src_access);
}
} else {
assert(glsl_type_is_matrix(src->type) || glsl_type_is_array(src->type));
split_deref_copy_instr(b, nir_build_deref_array_wildcard(b, dst),
- nir_build_deref_array_wildcard(b, src),
- dst_access, src_access);
+ nir_build_deref_array_wildcard(b, src),
+ dst_access, src_access);
}
}
{
return nir_shader_instructions_pass(shader, split_var_copies_instr,
nir_metadata_block_index |
- nir_metadata_dominance,
+ nir_metadata_dominance,
NULL);
}
const char *name,
struct split_var_state *state)
{
- *field = (struct field) {
+ *field = (struct field){
.parent = parent,
.type = type,
};
modes, mem_ctx);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
progress = true;
} else {
nir_metadata_preserve(impl, nir_metadata_all);
struct array_var_info *info =
rzalloc_size(mem_ctx, sizeof(*info) +
- num_levels * sizeof(info->levels[0]));
+ num_levels * sizeof(info->levels[0]));
info->base_var = var;
info->num_levels = num_levels;
b.cursor = nir_instr_remove(©->instr);
emit_split_copies(&b, dst_info, &dst_path, 0, dst_path.path[0],
- src_info, &src_path, 0, src_path.path[0]);
+ src_info, &src_path, 0, src_path.path[0]);
}
}
}
if (intrin->intrinsic == nir_intrinsic_load_deref) {
nir_ssa_def *u =
nir_ssa_undef(&b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size);
+ intrin->dest.ssa.bit_size);
nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
u);
}
split_array_access_impl(impl, var_info_map, modes, mem_ctx);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
progress = true;
} else {
nir_metadata_preserve(impl, nir_metadata_all);
struct vec_var_usage *usage =
rzalloc_size(mem_ctx, sizeof(*usage) +
- num_levels * sizeof(usage->levels[0]));
+ num_levels * sizeof(usage->levels[0]));
usage->num_levels = num_levels;
const struct glsl_type *type = var->type;
unsigned max_used;
if (deref->deref_type == nir_deref_type_array) {
- max_used = nir_src_is_const(deref->arr.index) ?
- nir_src_as_uint(deref->arr.index) : UINT_MAX;
+ max_used = nir_src_is_const(deref->arr.index) ? nir_src_as_uint(deref->arr.index) : UINT_MAX;
} else {
/* For wildcards, we read or wrote the whole thing. */
assert(deref->deref_type == nir_deref_type_array_wildcard);
if (intrin->intrinsic == nir_intrinsic_load_deref) {
nir_ssa_def *u =
nir_ssa_undef(&b, intrin->dest.ssa.num_components,
- intrin->dest.ssa.bit_size);
+ intrin->dest.ssa.bit_size);
nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
u);
}
shrink_vec_var_access_impl(impl, var_usage_map, modes);
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
progress = true;
} else {
nir_metadata_preserve(impl, nir_metadata_all);
* earlier, and even many times, trading CPU cycles for memory savings.
*/
-#define steal_list(mem_ctx, type, list) \
- foreach_list_typed(type, obj, node, list) { ralloc_steal(mem_ctx, obj); }
+#define steal_list(mem_ctx, type, list) \
+ foreach_list_typed(type, obj, node, list) { \
+ ralloc_steal(mem_ctx, obj); \
+ }
static void sweep_cf_node(nir_shader *nir, nir_cf_node *cf_node);
return invariant;
}
-
/* An instruction is said to be loop-invariant if it
* - has no sideeffects and
* - solely depends on variables defined outside of the loop or
if (!(nir_intrinsic_infos[intrinsic->intrinsic].flags & NIR_INTRINSIC_CAN_REORDER))
return not_invariant;
}
- FALLTHROUGH;
+ FALLTHROUGH;
default:
return nir_foreach_src(instr, src_is_invariant, loop) ? invariant : not_invariant;
}
}
}
-end:
+ end:
/* For outer loops, the LCSSA-phi should be considered not invariant */
if (state->skip_invariants) {
nir_foreach_instr(instr, state->block_after_loop) {
state->skip_invariants = false;
state->skip_bool_invariants = false;
- nir_foreach_block_in_cf_node (block, &loop->cf_node) {
+ nir_foreach_block_in_cf_node(block, &loop->cf_node) {
nir_foreach_instr(instr, block)
nir_foreach_ssa_def(instr, convert_loop_exit_for_ssa, state);
}
if (state->progress) {
progress = true;
nir_metadata_preserve(impl, nir_metadata_block_index |
- nir_metadata_dominance);
+ nir_metadata_dominance);
} else {
nir_metadata_preserve(impl, nir_metadata_all);
}
ralloc_free(state);
return progress;
}
-
}
}
- /*
+/*
* Any load can be trivialized by copying immediately after the load and then
* rewriting uses of the load to read from the copy. That has no functional
* change, but it means that for every use of the load (the copy), there is no
trivialize_read_after_write(load_reg, possibly_trivial_stores);
return true;
-
}
static void
*
*/
-#include "nir.h"
-#include "nir_xfb_info.h"
+#include <assert.h>
#include "c11/threads.h"
#include "util/simple_mtx.h"
-#include <assert.h>
+#include "nir.h"
+#include "nir_xfb_info.h"
/*
* This file checks for invalid IR indicating a bug somewhere in the compiler.
#define validate_assert(state, cond) \
validate_assert_impl(state, (cond), #cond, __FILE__, __LINE__)
-
static void validate_src(nir_src *src, validate_state *state,
unsigned bit_sizes, unsigned num_components);
if (nir_alu_type_get_base_type(src_type) == nir_type_float) {
/* 8-bit float isn't a thing */
validate_assert(state, src_bit_size == 16 || src_bit_size == 32 ||
- src_bit_size == 64);
+ src_bit_size == 64);
}
/* In nir_opcodes.py, these are defined to take general uint or int
if (nir_alu_type_get_base_type(dest_type) == nir_type_float) {
/* 8-bit float isn't a thing */
validate_assert(state, dest_bit_size == 16 || dest_bit_size == 32 ||
- dest_bit_size == 64);
+ dest_bit_size == 64);
}
validate_alu_dest(instr, state);
struct hash_entry *entry = _mesa_hash_table_search(state->var_defs, var);
validate_assert(state, entry);
if (entry && var->data.mode == nir_var_function_temp)
- validate_assert(state, (nir_function_impl *) entry->data == state->impl);
+ validate_assert(state, (nir_function_impl *)entry->data == state->impl);
}
static void
case nir_deref_type_struct:
validate_assert(state, glsl_type_is_struct_or_ifc(parent->type));
validate_assert(state,
- instr->strct.index < glsl_get_length(parent->type));
+ instr->strct.index < glsl_get_length(parent->type));
validate_assert(state, instr->type ==
- glsl_get_struct_field(parent->type, instr->strct.index));
+ glsl_get_struct_field(parent->type, instr->strct.index));
break;
case nir_deref_type_array:
* Fortunately, nir_lower_io handles these just fine.
*/
validate_assert(state, glsl_type_is_array(parent->type) ||
- glsl_type_is_matrix(parent->type) ||
- glsl_type_is_vector(parent->type));
+ glsl_type_is_matrix(parent->type) ||
+ glsl_type_is_vector(parent->type));
} else {
/* Most of NIR cannot handle array derefs on vectors */
validate_assert(state, glsl_type_is_array(parent->type) ||
- glsl_type_is_matrix(parent->type));
+ glsl_type_is_matrix(parent->type));
}
validate_assert(state,
- instr->type == glsl_get_array_element(parent->type));
+ instr->type == glsl_get_array_element(parent->type));
if (instr->deref_type == nir_deref_type_array) {
validate_src(&instr->arr.index, state,
*/
validate_assert(state,
parent->deref_type == nir_deref_type_array ||
- parent->deref_type == nir_deref_type_ptr_as_array ||
- parent->deref_type == nir_deref_type_cast);
+ parent->deref_type == nir_deref_type_ptr_as_array ||
+ parent->deref_type == nir_deref_type_cast);
validate_src(&instr->arr.index, state,
nir_dest_bit_size(instr->dest), 1);
break;
validate_intrinsic_instr(nir_intrinsic_instr *instr, validate_state *state)
{
unsigned dest_bit_size = 0;
- unsigned src_bit_sizes[NIR_INTRINSIC_MAX_INPUTS] = { 0, };
+ unsigned src_bit_sizes[NIR_INTRINSIC_MAX_INPUTS] = {
+ 0,
+ };
switch (instr->intrinsic) {
case nir_intrinsic_decl_reg:
assert(state->block == nir_start_block(state->impl));
nir_deref_instr *src = nir_src_as_deref(instr->src[0]);
assert(src);
validate_assert(state, glsl_type_is_vector_or_scalar(src->type) ||
- (src->modes == nir_var_uniform &&
- glsl_get_base_type(src->type) == GLSL_TYPE_SUBROUTINE));
+ (src->modes == nir_var_uniform &&
+ glsl_get_base_type(src->type) == GLSL_TYPE_SUBROUTINE));
validate_assert(state, instr->num_components ==
- glsl_get_vector_elements(src->type));
+ glsl_get_vector_elements(src->type));
dest_bit_size = glsl_get_bit_size(src->type);
/* Also allow 32-bit boolean load operations */
if (glsl_type_is_boolean(src->type))
assert(dst);
validate_assert(state, glsl_type_is_vector_or_scalar(dst->type));
validate_assert(state, instr->num_components ==
- glsl_get_vector_elements(dst->type));
+ glsl_get_vector_elements(dst->type));
src_bit_sizes[1] = glsl_get_bit_size(dst->type);
/* Also allow 32-bit boolean store operations */
if (glsl_type_is_boolean(dst->type))
nir_deref_instr *dst = nir_src_as_deref(instr->src[0]);
nir_deref_instr *src = nir_src_as_deref(instr->src[1]);
validate_assert(state, glsl_get_bare_type(dst->type) ==
- glsl_get_bare_type(src->type));
+ glsl_get_bare_type(src->type));
validate_assert(state, !nir_deref_mode_may_be(dst, nir_var_read_only_modes));
/* FIXME: now that we track if the var copies were lowered, it would be
* good to validate here that no new copy derefs were added. Right now
int bit_size = nir_dest_bit_size(instr->dest);
validate_assert(state, bit_size >= 8);
validate_assert(state, (nir_intrinsic_component(instr) +
- instr->num_components) * (bit_size / 8) <= 16);
+ instr->num_components) *
+ (bit_size / 8) <=
+ 16);
break;
}
case nir_intrinsic_load_constant:
/* These memory load operations must have alignments */
validate_assert(state,
- util_is_power_of_two_nonzero(nir_intrinsic_align_mul(instr)));
+ util_is_power_of_two_nonzero(nir_intrinsic_align_mul(instr)));
validate_assert(state, nir_intrinsic_align_offset(instr) <
- nir_intrinsic_align_mul(instr));
+ nir_intrinsic_align_mul(instr));
FALLTHROUGH;
case nir_intrinsic_load_uniform:
case nir_intrinsic_store_scratch:
/* These memory store operations must also have alignments */
validate_assert(state,
- util_is_power_of_two_nonzero(nir_intrinsic_align_mul(instr)));
+ util_is_power_of_two_nonzero(nir_intrinsic_align_mul(instr)));
validate_assert(state, nir_intrinsic_align_offset(instr) <
- nir_intrinsic_align_mul(instr));
+ nir_intrinsic_align_mul(instr));
FALLTHROUGH;
case nir_intrinsic_store_output:
case nir_intrinsic_deref_mode_is:
case nir_intrinsic_addr_mode_is:
validate_assert(state,
- util_bitcount(nir_intrinsic_memory_modes(instr)) == 1);
+ util_bitcount(nir_intrinsic_memory_modes(instr)) == 1);
break;
case nir_intrinsic_image_deref_atomic:
validate_assert(state, allowed);
validate_assert(state, nir_dest_bit_size(instr->dest) ==
- util_format_get_blocksizebits(format));
+ util_format_get_blocksizebits(format));
}
break;
}
/* Make sure the writemask is derived from the component count. */
validate_assert(state,
writemask ==
- BITFIELD_MASK(nir_src_num_components(instr->src[0])));
+ BITFIELD_MASK(nir_src_num_components(instr->src[0])));
}
break;
unsigned used_mask = 0;
for (unsigned i = 0; i < 4; i++) {
- nir_io_xfb xfb = i < 2 ? nir_intrinsic_io_xfb(instr) :
- nir_intrinsic_io_xfb2(instr);
+ nir_io_xfb xfb = i < 2 ? nir_intrinsic_io_xfb(instr) : nir_intrinsic_io_xfb2(instr);
unsigned xfb_mask = BITFIELD_RANGE(i, xfb.out[i % 2].num_components);
/* Each component can be used only once by transform feedback info. */
validate_assert(state,
(nir_slot_is_sysval_output(sem.location, MESA_SHADER_NONE) &&
!sem.no_sysval_output) ||
- (nir_slot_is_varying(sem.location) && !sem.no_varying) ||
- nir_instr_xfb_write_mask(instr));
+ (nir_slot_is_varying(sem.location) && !sem.no_varying) ||
+ nir_instr_xfb_write_mask(instr));
}
}
case nir_tex_src_bias:
validate_assert(state, instr->op == nir_texop_txb ||
- instr->op == nir_texop_tg4);
+ instr->op == nir_texop_tg4);
break;
case nir_tex_src_lod:
validate_assert(state, instr->op != nir_texop_tex &&
- instr->op != nir_texop_txb &&
- instr->op != nir_texop_txd &&
- instr->op != nir_texop_lod);
+ instr->op != nir_texop_txb &&
+ instr->op != nir_texop_txd &&
+ instr->op != nir_texop_lod);
break;
case nir_tex_src_ddx:
break;
validate_assert(state, glsl_type_is_image(deref->type) ||
- glsl_type_is_texture(deref->type) ||
- glsl_type_is_sampler(deref->type));
+ glsl_type_is_texture(deref->type) ||
+ glsl_type_is_sampler(deref->type));
switch (instr->op) {
case nir_texop_descriptor_amd:
case nir_texop_sampler_descriptor_amd:
case nir_texop_fragment_mask_fetch_amd:
case nir_texop_txf_ms_mcs_intel:
validate_assert(state, nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
- nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint);
+ nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint);
break;
default:
validate_assert(state,
glsl_get_sampler_result_type(deref->type) == GLSL_TYPE_VOID ||
- glsl_base_type_is_integer(glsl_get_sampler_result_type(deref->type)) ==
- (nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
- nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint));
+ glsl_base_type_is_integer(glsl_get_sampler_result_type(deref->type)) ==
+ (nir_alu_type_get_base_type(instr->dest_type) == nir_type_int ||
+ nir_alu_type_get_base_type(instr->dest_type) == nir_type_uint));
}
break;
}
unsigned bit_size = nir_alu_type_get_type_size(instr->dest_type);
validate_assert(state,
(bit_size ? bit_size : 32) ==
- nir_dest_bit_size(instr->dest));
+ nir_dest_bit_size(instr->dest));
}
static void
exec_list_validate(&instr->srcs);
validate_assert(state, exec_list_length(&instr->srcs) ==
- state->block->predecessors->entries);
+ state->block->predecessors->entries);
}
static void
{
state->instr = &instr->instr;
-
exec_list_validate(&instr->srcs);
nir_foreach_phi_src(src, instr) {
if (src->pred == pred) {
/* And we have to be in our successor's predecessors set */
validate_assert(state,
- _mesa_set_search(block->successors[i]->predecessors, block));
+ _mesa_set_search(block->successors[i]->predecessors, block));
validate_phi_srcs(block, block->successors[i], state);
}
const nir_block *pred = entry->key;
validate_assert(state, _mesa_set_search(state->blocks, pred));
validate_assert(state, pred->successors[0] == block ||
- pred->successors[1] == block);
+ pred->successors[1] == block);
}
}
nir_foreach_instr(instr, block) {
if (instr->type == nir_instr_type_phi) {
validate_assert(state, instr == nir_block_first_instr(block) ||
- nir_instr_prev(instr)->type == nir_instr_type_phi);
+ nir_instr_prev(instr)->type == nir_instr_type_phi);
}
validate_instr(instr, state);
validate_assert(state, block->successors[0] == cont);
} else {
validate_assert(state, nir_loop_has_continue_construct(state->loop) &&
- block == nir_loop_last_continue_block(state->loop));
+ block == nir_loop_last_continue_block(state->loop));
nir_block *head = nir_loop_first_block(state->loop);
validate_assert(state, block->successors[0] == head);
}
if (next->type == nir_cf_node_if) {
nir_if *if_stmt = nir_cf_node_as_if(next);
validate_assert(state, block->successors[0] ==
- nir_if_first_then_block(if_stmt));
+ nir_if_first_then_block(if_stmt));
validate_assert(state, block->successors[1] ==
- nir_if_first_else_block(if_stmt));
+ nir_if_first_else_block(if_stmt));
} else if (next->type == nir_cf_node_loop) {
nir_loop *loop = nir_cf_node_as_loop(next);
validate_assert(state, block->successors[0] ==
- nir_loop_first_block(loop));
+ nir_loop_first_block(loop));
validate_assert(state, block->successors[1] == NULL);
} else {
validate_assert(state,
- !"Structured NIR cannot have consecutive blocks");
+ !"Structured NIR cannot have consecutive blocks");
}
}
}
}
-
static void
validate_end_block(nir_block *block, validate_state *state)
{
*/
_mesa_hash_table_insert(state->var_defs, var,
- valid_modes == nir_var_function_temp ?
- state->impl : NULL);
+ valid_modes == nir_var_function_temp ? state->impl : NULL);
state->var = NULL;
}
nir_phi_instr *phi = nir_instr_as_phi(instr);
nir_foreach_phi_src(src, phi) {
validate_assert(state,
- nir_block_dominates(src->src.ssa->parent_instr->block,
- src->pred));
+ nir_block_dominates(src->src.ssa->parent_instr->block,
+ src->pred));
}
} else {
nir_foreach_src(instr, validate_src_dominance, state);
state->ssa_defs_found = reralloc(state->mem_ctx, state->ssa_defs_found,
BITSET_WORD, BITSET_WORDS(impl->ssa_alloc));
- memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
- sizeof(BITSET_WORD));
+ memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
_mesa_set_clear(state->blocks, NULL);
_mesa_set_resize(state->blocks, impl->num_blocks);
NIR_DEBUG(VALIDATE_SSA_DOMINANCE);
}
if (validate_dominance) {
- memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
- sizeof(BITSET_WORD));
+ memset(state->ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
validate_ssa_dominance(impl, state);
}
}
exec_list_validate(&shader->variables);
nir_foreach_variable_in_shader(var, shader)
- validate_var_decl(var, valid_modes, &state);
+ validate_var_decl(var, valid_modes, &state);
exec_list_validate(&shader->functions);
foreach_list_typed(nir_function, func, node, &shader->functions) {
* has real transform feedback going on.
*/
validate_assert(&state, shader->info.stage == MESA_SHADER_VERTEX ||
- shader->info.stage == MESA_SHADER_TESS_EVAL ||
- shader->info.stage == MESA_SHADER_GEOMETRY);
+ shader->info.stage == MESA_SHADER_TESS_EVAL ||
+ shader->info.stage == MESA_SHADER_GEOMETRY);
validate_assert(&state, shader->xfb_info->buffers_written != 0);
validate_assert(&state, shader->xfb_info->streams_written != 0);
validate_assert(&state, shader->xfb_info->output_count > 0);
state.ssa_defs_found = reralloc(state.mem_ctx, state.ssa_defs_found,
BITSET_WORD,
BITSET_WORDS(impl->ssa_alloc));
- memset(state.ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) *
- sizeof(BITSET_WORD));
+ memset(state.ssa_defs_found, 0, BITSET_WORDS(impl->ssa_alloc) * sizeof(BITSET_WORD));
state.impl = impl;
validate_ssa_dominance(impl, &state);
#include "c99_alloca.h"
-
/* Declare a variable length array, with no initialization */
#define NIR_VLA(_type, _name, _length) \
_type *_name = alloca((_length) * sizeof *_name)
-
/* Declare a variable length array, and initialize it with the given byte.
*
* _length is evaluated twice, so expressions with side-effects must be
#define NIR_VLA_FILL(_type, _name, _length, _byte) \
_type *_name = memset(alloca((_length) * sizeof *_name), _byte, (_length) * sizeof *_name)
-
/* Declare a variable length array, and zero it.
*
* Just like NIR_VLA_FILL, _length is evaluated twice, so expressions with
#ifndef _NIR_WORKLIST_
#define _NIR_WORKLIST_
-#include "nir.h"
#include "util/set.h"
#include "util/u_vector.h"
#include "util/u_worklist.h"
+#include "nir.h"
#ifdef __cplusplus
extern "C" {
typedef u_worklist nir_block_worklist;
#define nir_block_worklist_init(w, num_blocks, mem_ctx) \
- u_worklist_init(w, num_blocks, mem_ctx)
+ u_worklist_init(w, num_blocks, mem_ctx)
#define nir_block_worklist_fini(w) u_worklist_fini(w)
#define nir_block_worklist_is_empty(w) u_worklist_is_empty(w)
#define nir_block_worklist_push_head(w, block) \
- u_worklist_push_head(w, block, index)
+ u_worklist_push_head(w, block, index)
#define nir_block_worklist_peek_head(w) \
- u_worklist_peek_head(w, nir_block, index)
+ u_worklist_peek_head(w, nir_block, index)
#define nir_block_worklist_pop_head(w) \
- u_worklist_pop_head(w, nir_block, index)
+ u_worklist_pop_head(w, nir_block, index)
#define nir_block_worklist_push_tail(w, block) \
- u_worklist_push_tail(w, block, index)
+ u_worklist_push_tail(w, block, index)
#define nir_block_worklist_peek_tail(w) \
- u_worklist_peek_tail(w, nir_block, index)
+ u_worklist_peek_tail(w, nir_block, index)
#define nir_block_worklist_pop_tail(w) \
- u_worklist_pop_tail(w, nir_block, index)
+ u_worklist_pop_tail(w, nir_block, index)
void nir_block_worklist_add_all(nir_block_worklist *w, nir_function_impl *impl);
} nir_instr_worklist;
static inline nir_instr_worklist *
-nir_instr_worklist_create() {
+nir_instr_worklist_create()
+{
nir_instr_worklist *wl = malloc(sizeof(nir_instr_worklist));
if (!wl)
return NULL;
nir_instr_worklist_add_ssa_srcs(nir_instr_worklist *wl, nir_instr *instr);
#define nir_foreach_instr_in_worklist(instr, wl) \
- for (nir_instr *instr; (instr = nir_instr_worklist_pop_head(wl));)
+ for (nir_instr * instr; (instr = nir_instr_worklist_pop_head(wl));)
#ifdef __cplusplus
} /* extern "C" */