From: Caio Marcelo de Oliveira Filho Date: Mon, 3 Jun 2019 21:41:46 +0000 (-0700) Subject: spirv: Update the OpenCL.std.h header X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d482a8f680f7a4aa3073d08a868b5ab69ec86bbb;p=mesa.git spirv: Update the OpenCL.std.h header This corresponds to commit 8b911bd2ba37677037b38c9bd286c7c05701bcda on GitHub. We previously tweaked OpenCL.std.h from upstream to be included in C code. Now upstream header can be included, however the symbol names are slightly different (include an OpenCLstd_ prefix), so this patch also fixes vtn_opencl.c to use those. Reviewed-by: Karol Herbst --- diff --git a/src/compiler/spirv/OpenCL.std.h b/src/compiler/spirv/OpenCL.std.h index 5a6c23a26eb..2745e30df3b 100644 --- a/src/compiler/spirv/OpenCL.std.h +++ b/src/compiler/spirv/OpenCL.std.h @@ -27,7 +27,10 @@ #ifndef OPENCLstd_H #define OPENCLstd_H -enum OpenCLstd { +#ifdef __cplusplus +namespace OpenCLLIB { + +enum Entrypoints { // Section 2.1: Math extended instructions Acos = 0, @@ -208,4 +211,191 @@ enum OpenCLstd { Prefetch = 185, }; +} // end namespace OpenCLLIB + +#else + +enum OpenCLstd_Entrypoints { + + // Section 2.1: Math extended instructions + OpenCLstd_Acos = 0, + OpenCLstd_Acosh = 1, + OpenCLstd_Acospi = 2, + OpenCLstd_Asin = 3, + OpenCLstd_Asinh = 4, + OpenCLstd_Asinpi = 5, + OpenCLstd_Atan = 6, + OpenCLstd_Atan2 = 7, + OpenCLstd_Atanh = 8, + OpenCLstd_Atanpi = 9, + OpenCLstd_Atan2pi = 10, + OpenCLstd_Cbrt = 11, + OpenCLstd_Ceil = 12, + OpenCLstd_Copysign = 13, + OpenCLstd_Cos = 14, + OpenCLstd_Cosh = 15, + OpenCLstd_Cospi = 16, + OpenCLstd_Erfc = 17, + OpenCLstd_Erf = 18, + OpenCLstd_Exp = 19, + OpenCLstd_Exp2 = 20, + OpenCLstd_Exp10 = 21, + OpenCLstd_Expm1 = 22, + OpenCLstd_Fabs = 23, + OpenCLstd_Fdim = 24, + OpenCLstd_Floor = 25, + OpenCLstd_Fma = 26, + OpenCLstd_Fmax = 27, + OpenCLstd_Fmin = 28, + OpenCLstd_Fmod = 29, + OpenCLstd_Fract = 30, + OpenCLstd_Frexp = 31, + OpenCLstd_Hypot = 32, + OpenCLstd_Ilogb = 33, + OpenCLstd_Ldexp = 34, + OpenCLstd_Lgamma = 35, + OpenCLstd_Lgamma_r = 36, + OpenCLstd_Log = 37, + OpenCLstd_Log2 = 38, + OpenCLstd_Log10 = 39, + OpenCLstd_Log1p = 40, + OpenCLstd_Logb = 41, + OpenCLstd_Mad = 42, + OpenCLstd_Maxmag = 43, + OpenCLstd_Minmag = 44, + OpenCLstd_Modf = 45, + OpenCLstd_Nan = 46, + OpenCLstd_Nextafter = 47, + OpenCLstd_Pow = 48, + OpenCLstd_Pown = 49, + OpenCLstd_Powr = 50, + OpenCLstd_Remainder = 51, + OpenCLstd_Remquo = 52, + OpenCLstd_Rint = 53, + OpenCLstd_Rootn = 54, + OpenCLstd_Round = 55, + OpenCLstd_Rsqrt = 56, + OpenCLstd_Sin = 57, + OpenCLstd_Sincos = 58, + OpenCLstd_Sinh = 59, + OpenCLstd_Sinpi = 60, + OpenCLstd_Sqrt = 61, + OpenCLstd_Tan = 62, + OpenCLstd_Tanh = 63, + OpenCLstd_Tanpi = 64, + OpenCLstd_Tgamma = 65, + OpenCLstd_Trunc = 66, + OpenCLstd_Half_cos = 67, + OpenCLstd_Half_divide = 68, + OpenCLstd_Half_exp = 69, + OpenCLstd_Half_exp2 = 70, + OpenCLstd_Half_exp10 = 71, + OpenCLstd_Half_log = 72, + OpenCLstd_Half_log2 = 73, + OpenCLstd_Half_log10 = 74, + OpenCLstd_Half_powr = 75, + OpenCLstd_Half_recip = 76, + OpenCLstd_Half_rsqrt = 77, + OpenCLstd_Half_sin = 78, + OpenCLstd_Half_sqrt = 79, + OpenCLstd_Half_tan = 80, + OpenCLstd_Native_cos = 81, + OpenCLstd_Native_divide = 82, + OpenCLstd_Native_exp = 83, + OpenCLstd_Native_exp2 = 84, + OpenCLstd_Native_exp10 = 85, + OpenCLstd_Native_log = 86, + OpenCLstd_Native_log2 = 87, + OpenCLstd_Native_log10 = 88, + OpenCLstd_Native_powr = 89, + OpenCLstd_Native_recip = 90, + OpenCLstd_Native_rsqrt = 91, + OpenCLstd_Native_sin = 92, + OpenCLstd_Native_sqrt = 93, + OpenCLstd_Native_tan = 94, + + // Section 2.2: Integer instructions + OpenCLstd_SAbs = 141, + OpenCLstd_SAbs_diff = 142, + OpenCLstd_SAdd_sat = 143, + OpenCLstd_UAdd_sat = 144, + OpenCLstd_SHadd = 145, + OpenCLstd_UHadd = 146, + OpenCLstd_SRhadd = 147, + OpenCLstd_URhadd = 148, + OpenCLstd_SClamp = 149, + OpenCLstd_UClamp = 150, + OpenCLstd_Clz = 151, + OpenCLstd_Ctz = 152, + OpenCLstd_SMad_hi = 153, + OpenCLstd_UMad_sat = 154, + OpenCLstd_SMad_sat = 155, + OpenCLstd_SMax = 156, + OpenCLstd_UMax = 157, + OpenCLstd_SMin = 158, + OpenCLstd_UMin = 159, + OpenCLstd_SMul_hi = 160, + OpenCLstd_Rotate = 161, + OpenCLstd_SSub_sat = 162, + OpenCLstd_USub_sat = 163, + OpenCLstd_U_Upsample = 164, + OpenCLstd_S_Upsample = 165, + OpenCLstd_Popcount = 166, + OpenCLstd_SMad24 = 167, + OpenCLstd_UMad24 = 168, + OpenCLstd_SMul24 = 169, + OpenCLstd_UMul24 = 170, + OpenCLstd_UAbs = 201, + OpenCLstd_UAbs_diff = 202, + OpenCLstd_UMul_hi = 203, + OpenCLstd_UMad_hi = 204, + + // Section 2.3: Common instructions + OpenCLstd_FClamp = 95, + OpenCLstd_Degrees = 96, + OpenCLstd_FMax_common = 97, + OpenCLstd_FMin_common = 98, + OpenCLstd_Mix = 99, + OpenCLstd_Radians = 100, + OpenCLstd_Step = 101, + OpenCLstd_Smoothstep = 102, + OpenCLstd_Sign = 103, + + // Section 2.4: Geometric instructions + OpenCLstd_Cross = 104, + OpenCLstd_Distance = 105, + OpenCLstd_Length = 106, + OpenCLstd_Normalize = 107, + OpenCLstd_Fast_distance = 108, + OpenCLstd_Fast_length = 109, + OpenCLstd_Fast_normalize = 110, + + // Section 2.5: Relational instructions + OpenCLstd_Bitselect = 186, + OpenCLstd_Select = 187, + + // Section 2.6: Vector Data Load and Store instructions + OpenCLstd_Vloadn = 171, + OpenCLstd_Vstoren = 172, + OpenCLstd_Vload_half = 173, + OpenCLstd_Vload_halfn = 174, + OpenCLstd_Vstore_half = 175, + OpenCLstd_Vstore_half_r = 176, + OpenCLstd_Vstore_halfn = 177, + OpenCLstd_Vstore_halfn_r = 178, + OpenCLstd_Vloada_halfn = 179, + OpenCLstd_Vstorea_halfn = 180, + OpenCLstd_Vstorea_halfn_r = 181, + + // Section 2.7: Miscellaneous Vector instructions + OpenCLstd_Shuffle = 182, + OpenCLstd_Shuffle2 = 183, + + // Section 2.8: Misc instructions + OpenCLstd_Printf = 184, + OpenCLstd_Prefetch = 185, +}; + +#endif + #endif // #ifndef OPENCLstd_H diff --git a/src/compiler/spirv/vtn_opencl.c b/src/compiler/spirv/vtn_opencl.c index 5f0f5ac2988..4ba7c648e9e 100644 --- a/src/compiler/spirv/vtn_opencl.c +++ b/src/compiler/spirv/vtn_opencl.c @@ -31,13 +31,14 @@ #include "vtn_private.h" #include "OpenCL.std.h" -typedef nir_ssa_def *(*nir_handler)(struct vtn_builder *b, enum OpenCLstd opcode, +typedef nir_ssa_def *(*nir_handler)(struct vtn_builder *b, + enum OpenCLstd_Entrypoints opcode, unsigned num_srcs, nir_ssa_def **srcs, const struct glsl_type *dest_type); static void -handle_instr(struct vtn_builder *b, enum OpenCLstd opcode, const uint32_t *w, - unsigned count, nir_handler handler) +handle_instr(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, + const uint32_t *w, unsigned count, nir_handler handler) { const struct glsl_type *dest_type = vtn_value(b, w[1], vtn_value_type_type)->type->type; @@ -60,121 +61,124 @@ handle_instr(struct vtn_builder *b, enum OpenCLstd opcode, const uint32_t *w, } static nir_op -nir_alu_op_for_opencl_opcode(struct vtn_builder *b, enum OpenCLstd opcode) +nir_alu_op_for_opencl_opcode(struct vtn_builder *b, + enum OpenCLstd_Entrypoints opcode) { switch (opcode) { - case Fabs: return nir_op_fabs; - case SAbs: return nir_op_iabs; - case SAdd_sat: return nir_op_iadd_sat; - case UAdd_sat: return nir_op_uadd_sat; - case Ceil: return nir_op_fceil; - case Cos: return nir_op_fcos; - case Exp2: return nir_op_fexp2; - case Log2: return nir_op_flog2; - case Floor: return nir_op_ffloor; - case SHadd: return nir_op_ihadd; - case UHadd: return nir_op_uhadd; - case Fma: return nir_op_ffma; - case Fmax: return nir_op_fmax; - case SMax: return nir_op_imax; - case UMax: return nir_op_umax; - case Fmin: return nir_op_fmin; - case SMin: return nir_op_imin; - case UMin: return nir_op_umin; - case Fmod: return nir_op_fmod; - case Mix: return nir_op_flrp; - case SMul_hi: return nir_op_imul_high; - case UMul_hi: return nir_op_umul_high; - case Popcount: return nir_op_bit_count; - case Pow: return nir_op_fpow; - case Remainder: return nir_op_frem; - case SRhadd: return nir_op_irhadd; - case URhadd: return nir_op_urhadd; - case Rsqrt: return nir_op_frsq; - case Sign: return nir_op_fsign; - case Sin: return nir_op_fsin; - case Sqrt: return nir_op_fsqrt; - case SSub_sat: return nir_op_isub_sat; - case USub_sat: return nir_op_usub_sat; - case Trunc: return nir_op_ftrunc; + case OpenCLstd_Fabs: return nir_op_fabs; + case OpenCLstd_SAbs: return nir_op_iabs; + case OpenCLstd_SAdd_sat: return nir_op_iadd_sat; + case OpenCLstd_UAdd_sat: return nir_op_uadd_sat; + case OpenCLstd_Ceil: return nir_op_fceil; + case OpenCLstd_Cos: return nir_op_fcos; + case OpenCLstd_Exp2: return nir_op_fexp2; + case OpenCLstd_Log2: return nir_op_flog2; + case OpenCLstd_Floor: return nir_op_ffloor; + case OpenCLstd_SHadd: return nir_op_ihadd; + case OpenCLstd_UHadd: return nir_op_uhadd; + case OpenCLstd_Fma: return nir_op_ffma; + case OpenCLstd_Fmax: return nir_op_fmax; + case OpenCLstd_SMax: return nir_op_imax; + case OpenCLstd_UMax: return nir_op_umax; + case OpenCLstd_Fmin: return nir_op_fmin; + case OpenCLstd_SMin: return nir_op_imin; + case OpenCLstd_UMin: return nir_op_umin; + case OpenCLstd_Fmod: return nir_op_fmod; + case OpenCLstd_Mix: return nir_op_flrp; + case OpenCLstd_SMul_hi: return nir_op_imul_high; + case OpenCLstd_UMul_hi: return nir_op_umul_high; + case OpenCLstd_Popcount: return nir_op_bit_count; + case OpenCLstd_Pow: return nir_op_fpow; + case OpenCLstd_Remainder: return nir_op_frem; + case OpenCLstd_SRhadd: return nir_op_irhadd; + case OpenCLstd_URhadd: return nir_op_urhadd; + case OpenCLstd_Rsqrt: return nir_op_frsq; + case OpenCLstd_Sign: return nir_op_fsign; + case OpenCLstd_Sin: return nir_op_fsin; + case OpenCLstd_Sqrt: return nir_op_fsqrt; + case OpenCLstd_SSub_sat: return nir_op_isub_sat; + case OpenCLstd_USub_sat: return nir_op_usub_sat; + case OpenCLstd_Trunc: return nir_op_ftrunc; /* uhm... */ - case UAbs: return nir_op_mov; + case OpenCLstd_UAbs: return nir_op_mov; default: vtn_fail("No NIR equivalent"); } } static nir_ssa_def * -handle_alu(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs, - nir_ssa_def **srcs, const struct glsl_type *dest_type) +handle_alu(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, + unsigned num_srcs, nir_ssa_def **srcs, + const struct glsl_type *dest_type) { return nir_build_alu(&b->nb, nir_alu_op_for_opencl_opcode(b, opcode), srcs[0], srcs[1], srcs[2], NULL); } static nir_ssa_def * -handle_special(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs, - nir_ssa_def **srcs, const struct glsl_type *dest_type) +handle_special(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, + unsigned num_srcs, nir_ssa_def **srcs, + const struct glsl_type *dest_type) { nir_builder *nb = &b->nb; switch (opcode) { - case SAbs_diff: + case OpenCLstd_SAbs_diff: return nir_iabs_diff(nb, srcs[0], srcs[1]); - case UAbs_diff: + case OpenCLstd_UAbs_diff: return nir_uabs_diff(nb, srcs[0], srcs[1]); - case Bitselect: + case OpenCLstd_Bitselect: return nir_bitselect(nb, srcs[0], srcs[1], srcs[2]); - case FClamp: + case OpenCLstd_FClamp: return nir_fclamp(nb, srcs[0], srcs[1], srcs[2]); - case SClamp: + case OpenCLstd_SClamp: return nir_iclamp(nb, srcs[0], srcs[1], srcs[2]); - case UClamp: + case OpenCLstd_UClamp: return nir_uclamp(nb, srcs[0], srcs[1], srcs[2]); - case Copysign: + case OpenCLstd_Copysign: return nir_copysign(nb, srcs[0], srcs[1]); - case Cross: + case OpenCLstd_Cross: if (glsl_get_components(dest_type) == 4) return nir_cross4(nb, srcs[0], srcs[1]); return nir_cross3(nb, srcs[0], srcs[1]); - case Degrees: + case OpenCLstd_Degrees: return nir_degrees(nb, srcs[0]); - case Fdim: + case OpenCLstd_Fdim: return nir_fdim(nb, srcs[0], srcs[1]); - case Distance: + case OpenCLstd_Distance: return nir_distance(nb, srcs[0], srcs[1]); - case Fast_distance: + case OpenCLstd_Fast_distance: return nir_fast_distance(nb, srcs[0], srcs[1]); - case Fast_length: + case OpenCLstd_Fast_length: return nir_fast_length(nb, srcs[0]); - case Fast_normalize: + case OpenCLstd_Fast_normalize: return nir_fast_normalize(nb, srcs[0]); - case Length: + case OpenCLstd_Length: return nir_length(nb, srcs[0]); - case Mad: + case OpenCLstd_Mad: return nir_fmad(nb, srcs[0], srcs[1], srcs[2]); - case Maxmag: + case OpenCLstd_Maxmag: return nir_maxmag(nb, srcs[0], srcs[1]); - case Minmag: + case OpenCLstd_Minmag: return nir_minmag(nb, srcs[0], srcs[1]); - case Nan: + case OpenCLstd_Nan: return nir_nan(nb, srcs[0]); - case Nextafter: + case OpenCLstd_Nextafter: return nir_nextafter(nb, srcs[0], srcs[1]); - case Normalize: + case OpenCLstd_Normalize: return nir_normalize(nb, srcs[0]); - case Radians: + case OpenCLstd_Radians: return nir_radians(nb, srcs[0]); - case Rotate: + case OpenCLstd_Rotate: return nir_rotate(nb, srcs[0], srcs[1]); - case Smoothstep: + case OpenCLstd_Smoothstep: return nir_smoothstep(nb, srcs[0], srcs[1], srcs[2]); - case Select: + case OpenCLstd_Select: return nir_select(nb, srcs[0], srcs[1], srcs[2]); - case Step: + case OpenCLstd_Step: return nir_sge(nb, srcs[1], srcs[0]); - case S_Upsample: - case U_Upsample: + case OpenCLstd_S_Upsample: + case OpenCLstd_U_Upsample: return nir_upsample(nb, srcs[0], srcs[1]); default: vtn_fail("No NIR equivalent"); @@ -183,7 +187,7 @@ handle_special(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs, } static void -_handle_v_load_store(struct vtn_builder *b, enum OpenCLstd opcode, +_handle_v_load_store(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, const uint32_t *w, unsigned count, bool load) { struct vtn_type *type; @@ -218,22 +222,23 @@ _handle_v_load_store(struct vtn_builder *b, enum OpenCLstd opcode, } static void -vtn_handle_opencl_vload(struct vtn_builder *b, enum OpenCLstd opcode, +vtn_handle_opencl_vload(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, const uint32_t *w, unsigned count) { _handle_v_load_store(b, opcode, w, count, true); } static void -vtn_handle_opencl_vstore(struct vtn_builder *b, enum OpenCLstd opcode, +vtn_handle_opencl_vstore(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, const uint32_t *w, unsigned count) { _handle_v_load_store(b, opcode, w, count, false); } static nir_ssa_def * -handle_printf(struct vtn_builder *b, enum OpenCLstd opcode, unsigned num_srcs, - nir_ssa_def **srcs, const struct glsl_type *dest_type) +handle_printf(struct vtn_builder *b, enum OpenCLstd_Entrypoints opcode, + unsigned num_srcs, nir_ssa_def **srcs, + const struct glsl_type *dest_type) { /* hahah, yeah, right.. */ return nir_imm_int(&b->nb, -1); @@ -244,83 +249,83 @@ vtn_handle_opencl_instruction(struct vtn_builder *b, uint32_t ext_opcode, const uint32_t *w, unsigned count) { switch (ext_opcode) { - case Fabs: - case SAbs: - case UAbs: - case SAdd_sat: - case UAdd_sat: - case Ceil: - case Cos: - case Exp2: - case Log2: - case Floor: - case Fma: - case Fmax: - case SHadd: - case UHadd: - case SMax: - case UMax: - case Fmin: - case SMin: - case UMin: - case Mix: - case Fmod: - case SMul_hi: - case UMul_hi: - case Popcount: - case Pow: - case Remainder: - case SRhadd: - case URhadd: - case Rsqrt: - case Sign: - case Sin: - case Sqrt: - case SSub_sat: - case USub_sat: - case Trunc: + case OpenCLstd_Fabs: + case OpenCLstd_SAbs: + case OpenCLstd_UAbs: + case OpenCLstd_SAdd_sat: + case OpenCLstd_UAdd_sat: + case OpenCLstd_Ceil: + case OpenCLstd_Cos: + case OpenCLstd_Exp2: + case OpenCLstd_Log2: + case OpenCLstd_Floor: + case OpenCLstd_Fma: + case OpenCLstd_Fmax: + case OpenCLstd_SHadd: + case OpenCLstd_UHadd: + case OpenCLstd_SMax: + case OpenCLstd_UMax: + case OpenCLstd_Fmin: + case OpenCLstd_SMin: + case OpenCLstd_UMin: + case OpenCLstd_Mix: + case OpenCLstd_Fmod: + case OpenCLstd_SMul_hi: + case OpenCLstd_UMul_hi: + case OpenCLstd_Popcount: + case OpenCLstd_Pow: + case OpenCLstd_Remainder: + case OpenCLstd_SRhadd: + case OpenCLstd_URhadd: + case OpenCLstd_Rsqrt: + case OpenCLstd_Sign: + case OpenCLstd_Sin: + case OpenCLstd_Sqrt: + case OpenCLstd_SSub_sat: + case OpenCLstd_USub_sat: + case OpenCLstd_Trunc: handle_instr(b, ext_opcode, w, count, handle_alu); return true; - case SAbs_diff: - case UAbs_diff: - case Bitselect: - case FClamp: - case SClamp: - case UClamp: - case Copysign: - case Cross: - case Degrees: - case Fdim: - case Distance: - case Fast_distance: - case Fast_length: - case Fast_normalize: - case Length: - case Mad: - case Maxmag: - case Minmag: - case Nan: - case Nextafter: - case Normalize: - case Radians: - case Rotate: - case Select: - case Step: - case Smoothstep: - case S_Upsample: - case U_Upsample: + case OpenCLstd_SAbs_diff: + case OpenCLstd_UAbs_diff: + case OpenCLstd_Bitselect: + case OpenCLstd_FClamp: + case OpenCLstd_SClamp: + case OpenCLstd_UClamp: + case OpenCLstd_Copysign: + case OpenCLstd_Cross: + case OpenCLstd_Degrees: + case OpenCLstd_Fdim: + case OpenCLstd_Distance: + case OpenCLstd_Fast_distance: + case OpenCLstd_Fast_length: + case OpenCLstd_Fast_normalize: + case OpenCLstd_Length: + case OpenCLstd_Mad: + case OpenCLstd_Maxmag: + case OpenCLstd_Minmag: + case OpenCLstd_Nan: + case OpenCLstd_Nextafter: + case OpenCLstd_Normalize: + case OpenCLstd_Radians: + case OpenCLstd_Rotate: + case OpenCLstd_Select: + case OpenCLstd_Step: + case OpenCLstd_Smoothstep: + case OpenCLstd_S_Upsample: + case OpenCLstd_U_Upsample: handle_instr(b, ext_opcode, w, count, handle_special); return true; - case Vloadn: + case OpenCLstd_Vloadn: vtn_handle_opencl_vload(b, ext_opcode, w, count); return true; - case Vstoren: + case OpenCLstd_Vstoren: vtn_handle_opencl_vstore(b, ext_opcode, w, count); return true; - case Printf: + case OpenCLstd_Printf: handle_instr(b, ext_opcode, w, count, handle_printf); return true; - case Prefetch: + case OpenCLstd_Prefetch: /* TODO maybe add a nir instruction for this? */ return true; default: