mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-21 20:10:14 +01:00
nir/spirv: Update to the latest revision
This commit is contained in:
parent
ce70cae756
commit
22fdb2f855
5 changed files with 2313 additions and 1313 deletions
|
|
@ -32,8 +32,16 @@
|
||||||
|
|
||||||
#include "nir.h"
|
#include "nir.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count,
|
nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count,
|
||||||
gl_shader_stage stage,
|
gl_shader_stage stage,
|
||||||
const nir_shader_compiler_options *options);
|
const nir_shader_compiler_options *options);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _NIR_SPIRV_H_ */
|
#endif /* _NIR_SPIRV_H_ */
|
||||||
|
|
|
||||||
1484
src/glsl/nir/spirv.h
1484
src/glsl/nir/spirv.h
File diff suppressed because it is too large
Load diff
|
|
@ -139,13 +139,14 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
const uint32_t *w, unsigned count)
|
const uint32_t *w, unsigned count)
|
||||||
{
|
{
|
||||||
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
|
||||||
val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
|
val->ssa = rzalloc(b, struct vtn_ssa_value);
|
||||||
|
val->ssa->type = vtn_value(b, w[1], vtn_value_type_type)->type->type;
|
||||||
|
|
||||||
/* Collect the various SSA sources */
|
/* Collect the various SSA sources */
|
||||||
unsigned num_inputs = count - 5;
|
unsigned num_inputs = count - 5;
|
||||||
nir_ssa_def *src[3];
|
nir_ssa_def *src[3];
|
||||||
for (unsigned i = 0; i < num_inputs; i++)
|
for (unsigned i = 0; i < num_inputs; i++)
|
||||||
src[i] = vtn_ssa_value(b, w[i + 5]);
|
src[i] = vtn_ssa_value(b, w[i + 5])->def;
|
||||||
|
|
||||||
nir_op op;
|
nir_op op;
|
||||||
switch (entrypoint) {
|
switch (entrypoint) {
|
||||||
|
|
@ -158,16 +159,16 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
case Ceil: op = nir_op_fceil; break;
|
case Ceil: op = nir_op_fceil; break;
|
||||||
case Fract: op = nir_op_ffract; break;
|
case Fract: op = nir_op_ffract; break;
|
||||||
case Radians:
|
case Radians:
|
||||||
val->ssa = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 0.01745329251));
|
val->ssa->def = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 0.01745329251));
|
||||||
return;
|
return;
|
||||||
case Degrees:
|
case Degrees:
|
||||||
val->ssa = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 57.2957795131));
|
val->ssa->def = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 57.2957795131));
|
||||||
return;
|
return;
|
||||||
case Sin: op = nir_op_fsin; break;
|
case Sin: op = nir_op_fsin; break;
|
||||||
case Cos: op = nir_op_fcos; break;
|
case Cos: op = nir_op_fcos; break;
|
||||||
case Tan:
|
case Tan:
|
||||||
val->ssa = nir_fdiv(&b->nb, nir_fsin(&b->nb, src[0]),
|
val->ssa->def = nir_fdiv(&b->nb, nir_fsin(&b->nb, src[0]),
|
||||||
nir_fcos(&b->nb, src[0]));
|
nir_fcos(&b->nb, src[0]));
|
||||||
return;
|
return;
|
||||||
case Pow: op = nir_op_fpow; break;
|
case Pow: op = nir_op_fpow; break;
|
||||||
case Exp2: op = nir_op_fexp2; break;
|
case Exp2: op = nir_op_fexp2; break;
|
||||||
|
|
@ -180,7 +181,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
case Max: op = nir_op_fmax; break;
|
case Max: op = nir_op_fmax; break;
|
||||||
case Mix: op = nir_op_flrp; break;
|
case Mix: op = nir_op_flrp; break;
|
||||||
case Step:
|
case Step:
|
||||||
val->ssa = nir_sge(&b->nb, src[1], src[0]);
|
val->ssa->def = nir_sge(&b->nb, src[1], src[0]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case FloatBitsToInt:
|
case FloatBitsToInt:
|
||||||
|
|
@ -188,7 +189,7 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
case IntBitsToFloat:
|
case IntBitsToFloat:
|
||||||
case UintBitsToFloat:
|
case UintBitsToFloat:
|
||||||
/* Probably going to be removed from the final version of the spec. */
|
/* Probably going to be removed from the final version of the spec. */
|
||||||
val->ssa = src[0];
|
val->ssa->def = src[0];
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case Fma: op = nir_op_ffma; break;
|
case Fma: op = nir_op_ffma; break;
|
||||||
|
|
@ -207,13 +208,13 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
case UnpackHalf2x16: op = nir_op_unpack_half_2x16; break;
|
case UnpackHalf2x16: op = nir_op_unpack_half_2x16; break;
|
||||||
|
|
||||||
case Length:
|
case Length:
|
||||||
val->ssa = build_length(&b->nb, src[0]);
|
val->ssa->def = build_length(&b->nb, src[0]);
|
||||||
return;
|
return;
|
||||||
case Distance:
|
case Distance:
|
||||||
val->ssa = build_length(&b->nb, nir_fsub(&b->nb, src[0], src[1]));
|
val->ssa->def = build_length(&b->nb, nir_fsub(&b->nb, src[0], src[1]));
|
||||||
return;
|
return;
|
||||||
case Normalize:
|
case Normalize:
|
||||||
val->ssa = nir_fdiv(&b->nb, src[0], build_length(&b->nb, src[0]));
|
val->ssa->def = nir_fdiv(&b->nb, src[0], build_length(&b->nb, src[0]));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case UaddCarry: op = nir_op_uadd_carry; break;
|
case UaddCarry: op = nir_op_uadd_carry; break;
|
||||||
|
|
@ -255,8 +256,8 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
|
||||||
|
|
||||||
nir_alu_instr *instr = nir_alu_instr_create(b->shader, op);
|
nir_alu_instr *instr = nir_alu_instr_create(b->shader, op);
|
||||||
nir_ssa_dest_init(&instr->instr, &instr->dest.dest,
|
nir_ssa_dest_init(&instr->instr, &instr->dest.dest,
|
||||||
glsl_get_vector_elements(val->type), val->name);
|
glsl_get_vector_elements(val->ssa->type), val->name);
|
||||||
val->ssa = &instr->dest.dest.ssa;
|
val->ssa->def = &instr->dest.dest.ssa;
|
||||||
|
|
||||||
for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
|
for (unsigned i = 0; i < nir_op_infos[op].num_inputs; i++)
|
||||||
instr->src[i].src = nir_src_for_ssa(src[i]);
|
instr->src[i].src = nir_src_for_ssa(src[i]);
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -25,6 +25,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "nir.h"
|
||||||
#include "nir_spirv.h"
|
#include "nir_spirv.h"
|
||||||
#include "nir_builder.h"
|
#include "nir_builder.h"
|
||||||
#include "spirv.h"
|
#include "spirv.h"
|
||||||
|
|
@ -60,30 +61,88 @@ struct vtn_function {
|
||||||
|
|
||||||
nir_function_overload *overload;
|
nir_function_overload *overload;
|
||||||
struct vtn_block *start_block;
|
struct vtn_block *start_block;
|
||||||
|
|
||||||
|
const uint32_t *end;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef bool (*vtn_instruction_handler)(struct vtn_builder *, uint32_t,
|
typedef bool (*vtn_instruction_handler)(struct vtn_builder *, uint32_t,
|
||||||
const uint32_t *, unsigned);
|
const uint32_t *, unsigned);
|
||||||
|
|
||||||
|
struct vtn_ssa_value {
|
||||||
|
union {
|
||||||
|
nir_ssa_def *def;
|
||||||
|
struct vtn_ssa_value **elems;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* For matrices, a transposed version of the value, or NULL if it hasn't
|
||||||
|
* been computed
|
||||||
|
*/
|
||||||
|
struct vtn_ssa_value *transposed;
|
||||||
|
|
||||||
|
const struct glsl_type *type;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct vtn_type {
|
||||||
|
const struct glsl_type *type;
|
||||||
|
|
||||||
|
/* for matrices, whether the matrix is stored row-major */
|
||||||
|
bool row_major;
|
||||||
|
|
||||||
|
/* for structs, the offset of each member */
|
||||||
|
unsigned *offsets;
|
||||||
|
|
||||||
|
/* for structs, whether it was decorated as a "non-SSBO-like" block */
|
||||||
|
bool block;
|
||||||
|
|
||||||
|
/* for structs, whether it was decorated as an "SSBO-like" block */
|
||||||
|
bool buffer_block;
|
||||||
|
|
||||||
|
/* for structs with block == true, whether this is a builtin block (i.e. a
|
||||||
|
* block that contains only builtins).
|
||||||
|
*/
|
||||||
|
bool builtin_block;
|
||||||
|
|
||||||
|
/* for arrays and matrices, the array stride */
|
||||||
|
unsigned stride;
|
||||||
|
|
||||||
|
/* for arrays, the vtn_type for the elements of the array */
|
||||||
|
struct vtn_type *array_element;
|
||||||
|
|
||||||
|
/* for structures, the vtn_type for each member */
|
||||||
|
struct vtn_type **members;
|
||||||
|
|
||||||
|
/* Whether this type, or a parent type, has been decorated as a builtin */
|
||||||
|
bool is_builtin;
|
||||||
|
|
||||||
|
SpvBuiltIn builtin;
|
||||||
|
};
|
||||||
|
|
||||||
struct vtn_value {
|
struct vtn_value {
|
||||||
enum vtn_value_type value_type;
|
enum vtn_value_type value_type;
|
||||||
const char *name;
|
const char *name;
|
||||||
struct vtn_decoration *decoration;
|
struct vtn_decoration *decoration;
|
||||||
const struct glsl_type *type;
|
|
||||||
union {
|
union {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
char *str;
|
char *str;
|
||||||
nir_constant *constant;
|
struct vtn_type *type;
|
||||||
nir_deref_var *deref;
|
struct {
|
||||||
|
nir_constant *constant;
|
||||||
|
const struct glsl_type *const_type;
|
||||||
|
};
|
||||||
|
struct {
|
||||||
|
nir_deref_var *deref;
|
||||||
|
struct vtn_type *deref_type;
|
||||||
|
};
|
||||||
struct vtn_function *func;
|
struct vtn_function *func;
|
||||||
struct vtn_block *block;
|
struct vtn_block *block;
|
||||||
nir_ssa_def *ssa;
|
struct vtn_ssa_value *ssa;
|
||||||
vtn_instruction_handler ext_handler;
|
vtn_instruction_handler ext_handler;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vtn_decoration {
|
struct vtn_decoration {
|
||||||
struct vtn_decoration *next;
|
struct vtn_decoration *next;
|
||||||
|
int member; /* -1 if not a member decoration */
|
||||||
const uint32_t *literals;
|
const uint32_t *literals;
|
||||||
struct vtn_value *group;
|
struct vtn_value *group;
|
||||||
SpvDecoration decoration;
|
SpvDecoration decoration;
|
||||||
|
|
@ -96,6 +155,25 @@ struct vtn_builder {
|
||||||
nir_function_impl *impl;
|
nir_function_impl *impl;
|
||||||
struct vtn_block *block;
|
struct vtn_block *block;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In SPIR-V, constants are global, whereas in NIR, the load_const
|
||||||
|
* instruction we use is per-function. So while we parse each function, we
|
||||||
|
* keep a hash table of constants we've resolved to nir_ssa_value's so
|
||||||
|
* far, and we lazily resolve them when we see them used in a function.
|
||||||
|
*/
|
||||||
|
struct hash_table *const_table;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Map from nir_block to the vtn_block which ends with it -- used for
|
||||||
|
* handling phi nodes.
|
||||||
|
*/
|
||||||
|
struct hash_table *block_table;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NIR variable for each SPIR-V builtin.
|
||||||
|
*/
|
||||||
|
nir_variable *builtins[42]; /* XXX need symbolic constant from SPIR-V header */
|
||||||
|
|
||||||
unsigned value_id_bound;
|
unsigned value_id_bound;
|
||||||
struct vtn_value *values;
|
struct vtn_value *values;
|
||||||
|
|
||||||
|
|
@ -134,10 +212,11 @@ vtn_value(struct vtn_builder *b, uint32_t value_id,
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
nir_ssa_def *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id);
|
struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id);
|
||||||
|
|
||||||
typedef void (*vtn_decoration_foreach_cb)(struct vtn_builder *,
|
typedef void (*vtn_decoration_foreach_cb)(struct vtn_builder *,
|
||||||
struct vtn_value *,
|
struct vtn_value *,
|
||||||
|
int member,
|
||||||
const struct vtn_decoration *,
|
const struct vtn_decoration *,
|
||||||
void *);
|
void *);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue