Path: blob/21.2-virgl/src/compiler/spirv/vtn_glsl450.c
4545 views
/*1* Copyright © 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22* Authors:23* Jason Ekstrand ([email protected])24*25*/2627#include <math.h>2829#include "nir/nir_builtin_builder.h"3031#include "vtn_private.h"32#include "GLSL.std.450.h"3334#define M_PIf ((float) M_PI)35#define M_PI_2f ((float) M_PI_2)36#define M_PI_4f ((float) M_PI_4)3738static nir_ssa_def *39build_mat2_det(nir_builder *b, nir_ssa_def *col[2])40{41unsigned swiz[2] = {1, 0 };42nir_ssa_def *p = nir_fmul(b, col[0], nir_swizzle(b, col[1], swiz, 2));43return nir_fsub(b, nir_channel(b, p, 0), nir_channel(b, p, 1));44}4546static nir_ssa_def *47build_mat3_det(nir_builder *b, nir_ssa_def *col[3])48{49unsigned yzx[3] = {1, 2, 0 };50unsigned zxy[3] = {2, 0, 1 };5152nir_ssa_def *prod0 =53nir_fmul(b, col[0],54nir_fmul(b, nir_swizzle(b, col[1], yzx, 3),55nir_swizzle(b, col[2], zxy, 3)));56nir_ssa_def *prod1 =57nir_fmul(b, col[0],58nir_fmul(b, nir_swizzle(b, col[1], zxy, 3),59nir_swizzle(b, col[2], yzx, 3)));6061nir_ssa_def *diff = nir_fsub(b, prod0, prod1);6263return nir_fadd(b, nir_channel(b, diff, 0),64nir_fadd(b, nir_channel(b, diff, 1),65nir_channel(b, diff, 2)));66}6768static nir_ssa_def *69build_mat4_det(nir_builder *b, nir_ssa_def **col)70{71nir_ssa_def *subdet[4];72for (unsigned i = 0; i < 4; i++) {73unsigned swiz[3];74for (unsigned j = 0; j < 3; j++)75swiz[j] = j + (j >= i);7677nir_ssa_def *subcol[3];78subcol[0] = nir_swizzle(b, col[1], swiz, 3);79subcol[1] = nir_swizzle(b, col[2], swiz, 3);80subcol[2] = nir_swizzle(b, col[3], swiz, 3);8182subdet[i] = build_mat3_det(b, subcol);83}8485nir_ssa_def *prod = nir_fmul(b, col[0], nir_vec(b, subdet, 4));8687return nir_fadd(b, nir_fsub(b, nir_channel(b, prod, 0),88nir_channel(b, prod, 1)),89nir_fsub(b, nir_channel(b, prod, 2),90nir_channel(b, prod, 3)));91}9293static nir_ssa_def *94build_mat_det(struct vtn_builder *b, struct vtn_ssa_value *src)95{96unsigned size = glsl_get_vector_elements(src->type);9798nir_ssa_def *cols[4];99for (unsigned i = 0; i < size; i++)100cols[i] = src->elems[i]->def;101102switch(size) {103case 2: return build_mat2_det(&b->nb, cols);104case 3: return build_mat3_det(&b->nb, cols);105case 4: return build_mat4_det(&b->nb, cols);106default:107vtn_fail("Invalid matrix size");108}109}110111/* Computes the determinate of the submatrix given by taking src and112* removing the specified row and column.113*/114static nir_ssa_def *115build_mat_subdet(struct nir_builder *b, struct vtn_ssa_value *src,116unsigned size, unsigned row, unsigned col)117{118assert(row < size && col < size);119if (size == 2) {120return nir_channel(b, src->elems[1 - col]->def, 1 - row);121} else {122/* Swizzle to get all but the specified row */123unsigned swiz[NIR_MAX_VEC_COMPONENTS] = {0};124for (unsigned j = 0; j < 3; j++)125swiz[j] = j + (j >= row);126127/* Grab all but the specified column */128nir_ssa_def *subcol[3];129for (unsigned j = 0; j < size; j++) {130if (j != col) {131subcol[j - (j > col)] = nir_swizzle(b, src->elems[j]->def,132swiz, size - 1);133}134}135136if (size == 3) {137return build_mat2_det(b, subcol);138} else {139assert(size == 4);140return build_mat3_det(b, subcol);141}142}143}144145static struct vtn_ssa_value *146matrix_inverse(struct vtn_builder *b, struct vtn_ssa_value *src)147{148nir_ssa_def *adj_col[4];149unsigned size = glsl_get_vector_elements(src->type);150151/* Build up an adjugate matrix */152for (unsigned c = 0; c < size; c++) {153nir_ssa_def *elem[4];154for (unsigned r = 0; r < size; r++) {155elem[r] = build_mat_subdet(&b->nb, src, size, c, r);156157if ((r + c) % 2)158elem[r] = nir_fneg(&b->nb, elem[r]);159}160161adj_col[c] = nir_vec(&b->nb, elem, size);162}163164nir_ssa_def *det_inv = nir_frcp(&b->nb, build_mat_det(b, src));165166struct vtn_ssa_value *val = vtn_create_ssa_value(b, src->type);167for (unsigned i = 0; i < size; i++)168val->elems[i]->def = nir_fmul(&b->nb, adj_col[i], det_inv);169170return val;171}172173/**174* Approximate asin(x) by the piecewise formula:175* for |x| < 0.5, asin~(x) = x * (1 + x²(pS0 + x²(pS1 + x²*pS2)) / (1 + x²*qS1))176* for |x| ≥ 0.5, asin~(x) = sign(x) * (π/2 - sqrt(1 - |x|) * (π/2 + |x|(π/4 - 1 + |x|(p0 + |x|p1))))177*178* The latter is correct to first order at x=0 and x=±1 regardless of the p179* coefficients but can be made second-order correct at both ends by selecting180* the fit coefficients appropriately. Different p coefficients can be used181* in the asin and acos implementation to minimize some relative error metric182* in each case.183*/184static nir_ssa_def *185build_asin(nir_builder *b, nir_ssa_def *x, float p0, float p1, bool piecewise)186{187if (x->bit_size == 16) {188/* The polynomial approximation isn't precise enough to meet half-float189* precision requirements. Alternatively, we could implement this using190* the formula:191*192* asin(x) = atan2(x, sqrt(1 - x*x))193*194* But that is very expensive, so instead we just do the polynomial195* approximation in 32-bit math and then we convert the result back to196* 16-bit.197*/198return nir_f2f16(b, build_asin(b, nir_f2f32(b, x), p0, p1, piecewise));199}200nir_ssa_def *one = nir_imm_floatN_t(b, 1.0f, x->bit_size);201nir_ssa_def *half = nir_imm_floatN_t(b, 0.5f, x->bit_size);202nir_ssa_def *abs_x = nir_fabs(b, x);203204nir_ssa_def *p0_plus_xp1 = nir_fadd_imm(b, nir_fmul_imm(b, abs_x, p1), p0);205206nir_ssa_def *expr_tail =207nir_fadd_imm(b, nir_fmul(b, abs_x,208nir_fadd_imm(b, nir_fmul(b, abs_x,209p0_plus_xp1),210M_PI_4f - 1.0f)),211M_PI_2f);212213nir_ssa_def *result0 = nir_fmul(b, nir_fsign(b, x),214nir_fsub(b, nir_imm_floatN_t(b, M_PI_2f, x->bit_size),215nir_fmul(b, nir_fsqrt(b, nir_fsub(b, one, abs_x)),216expr_tail)));217if (piecewise) {218/* approximation for |x| < 0.5 */219const float pS0 = 1.6666586697e-01f;220const float pS1 = -4.2743422091e-02f;221const float pS2 = -8.6563630030e-03f;222const float qS1 = -7.0662963390e-01f;223224nir_ssa_def *x2 = nir_fmul(b, x, x);225nir_ssa_def *p = nir_fmul(b,226x2,227nir_fadd_imm(b,228nir_fmul(b,229x2,230nir_fadd_imm(b, nir_fmul_imm(b, x2, pS2),231pS1)),232pS0));233234nir_ssa_def *q = nir_fadd(b, one, nir_fmul_imm(b, x2, qS1));235nir_ssa_def *result1 = nir_fadd(b, x, nir_fmul(b, x, nir_fdiv(b, p, q)));236return nir_bcsel(b, nir_flt(b, abs_x, half), result1, result0);237} else {238return result0;239}240}241242static nir_op243vtn_nir_alu_op_for_spirv_glsl_opcode(struct vtn_builder *b,244enum GLSLstd450 opcode,245unsigned execution_mode,246bool *exact)247{248*exact = false;249switch (opcode) {250case GLSLstd450Round: return nir_op_fround_even;251case GLSLstd450RoundEven: return nir_op_fround_even;252case GLSLstd450Trunc: return nir_op_ftrunc;253case GLSLstd450FAbs: return nir_op_fabs;254case GLSLstd450SAbs: return nir_op_iabs;255case GLSLstd450FSign: return nir_op_fsign;256case GLSLstd450SSign: return nir_op_isign;257case GLSLstd450Floor: return nir_op_ffloor;258case GLSLstd450Ceil: return nir_op_fceil;259case GLSLstd450Fract: return nir_op_ffract;260case GLSLstd450Sin: return nir_op_fsin;261case GLSLstd450Cos: return nir_op_fcos;262case GLSLstd450Pow: return nir_op_fpow;263case GLSLstd450Exp2: return nir_op_fexp2;264case GLSLstd450Log2: return nir_op_flog2;265case GLSLstd450Sqrt: return nir_op_fsqrt;266case GLSLstd450InverseSqrt: return nir_op_frsq;267case GLSLstd450NMin: *exact = true; return nir_op_fmin;268case GLSLstd450FMin: return nir_op_fmin;269case GLSLstd450UMin: return nir_op_umin;270case GLSLstd450SMin: return nir_op_imin;271case GLSLstd450NMax: *exact = true; return nir_op_fmax;272case GLSLstd450FMax: return nir_op_fmax;273case GLSLstd450UMax: return nir_op_umax;274case GLSLstd450SMax: return nir_op_imax;275case GLSLstd450FMix: return nir_op_flrp;276case GLSLstd450Fma: return nir_op_ffma;277case GLSLstd450Ldexp: return nir_op_ldexp;278case GLSLstd450FindILsb: return nir_op_find_lsb;279case GLSLstd450FindSMsb: return nir_op_ifind_msb;280case GLSLstd450FindUMsb: return nir_op_ufind_msb;281282/* Packing/Unpacking functions */283case GLSLstd450PackSnorm4x8: return nir_op_pack_snorm_4x8;284case GLSLstd450PackUnorm4x8: return nir_op_pack_unorm_4x8;285case GLSLstd450PackSnorm2x16: return nir_op_pack_snorm_2x16;286case GLSLstd450PackUnorm2x16: return nir_op_pack_unorm_2x16;287case GLSLstd450PackHalf2x16: return nir_op_pack_half_2x16;288case GLSLstd450PackDouble2x32: return nir_op_pack_64_2x32;289case GLSLstd450UnpackSnorm4x8: return nir_op_unpack_snorm_4x8;290case GLSLstd450UnpackUnorm4x8: return nir_op_unpack_unorm_4x8;291case GLSLstd450UnpackSnorm2x16: return nir_op_unpack_snorm_2x16;292case GLSLstd450UnpackUnorm2x16: return nir_op_unpack_unorm_2x16;293case GLSLstd450UnpackHalf2x16:294if (execution_mode & FLOAT_CONTROLS_DENORM_FLUSH_TO_ZERO_FP16)295return nir_op_unpack_half_2x16_flush_to_zero;296else297return nir_op_unpack_half_2x16;298case GLSLstd450UnpackDouble2x32: return nir_op_unpack_64_2x32;299300default:301vtn_fail("No NIR equivalent");302}303}304305#define NIR_IMM_FP(n, v) (nir_imm_floatN_t(n, v, src[0]->bit_size))306307static void308handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,309const uint32_t *w, unsigned count)310{311struct nir_builder *nb = &b->nb;312const struct glsl_type *dest_type = vtn_get_type(b, w[1])->type;313314/* Collect the various SSA sources */315unsigned num_inputs = count - 5;316nir_ssa_def *src[3] = { NULL, };317for (unsigned i = 0; i < num_inputs; i++) {318/* These are handled specially below */319if (vtn_untyped_value(b, w[i + 5])->value_type == vtn_value_type_pointer)320continue;321322src[i] = vtn_get_nir_ssa(b, w[i + 5]);323}324325struct vtn_ssa_value *dest = vtn_create_ssa_value(b, dest_type);326vtn_handle_no_contraction(b, vtn_untyped_value(b, w[2]));327switch (entrypoint) {328case GLSLstd450Radians:329dest->def = nir_radians(nb, src[0]);330break;331case GLSLstd450Degrees:332dest->def = nir_degrees(nb, src[0]);333break;334case GLSLstd450Tan:335dest->def = nir_ftan(nb, src[0]);336break;337338case GLSLstd450Modf: {339nir_ssa_def *sign = nir_fsign(nb, src[0]);340nir_ssa_def *abs = nir_fabs(nb, src[0]);341dest->def = nir_fmul(nb, sign, nir_ffract(nb, abs));342343struct vtn_pointer *i_ptr = vtn_value(b, w[6], vtn_value_type_pointer)->pointer;344struct vtn_ssa_value *whole = vtn_create_ssa_value(b, i_ptr->type->type);345whole->def = nir_fmul(nb, sign, nir_ffloor(nb, abs));346vtn_variable_store(b, whole, i_ptr, 0);347break;348}349350case GLSLstd450ModfStruct: {351nir_ssa_def *sign = nir_fsign(nb, src[0]);352nir_ssa_def *abs = nir_fabs(nb, src[0]);353vtn_assert(glsl_type_is_struct_or_ifc(dest_type));354dest->elems[0]->def = nir_fmul(nb, sign, nir_ffract(nb, abs));355dest->elems[1]->def = nir_fmul(nb, sign, nir_ffloor(nb, abs));356break;357}358359case GLSLstd450Step:360dest->def = nir_sge(nb, src[1], src[0]);361break;362363case GLSLstd450Length:364dest->def = nir_fast_length(nb, src[0]);365break;366case GLSLstd450Distance:367dest->def = nir_fast_distance(nb, src[0], src[1]);368break;369case GLSLstd450Normalize:370dest->def = nir_fast_normalize(nb, src[0]);371break;372373case GLSLstd450Exp:374dest->def = nir_fexp(nb, src[0]);375break;376377case GLSLstd450Log:378dest->def = nir_flog(nb, src[0]);379break;380381case GLSLstd450FClamp:382dest->def = nir_fclamp(nb, src[0], src[1], src[2]);383break;384case GLSLstd450NClamp:385nb->exact = true;386dest->def = nir_fclamp(nb, src[0], src[1], src[2]);387nb->exact = false;388break;389case GLSLstd450UClamp:390dest->def = nir_uclamp(nb, src[0], src[1], src[2]);391break;392case GLSLstd450SClamp:393dest->def = nir_iclamp(nb, src[0], src[1], src[2]);394break;395396case GLSLstd450Cross: {397dest->def = nir_cross3(nb, src[0], src[1]);398break;399}400401case GLSLstd450SmoothStep: {402dest->def = nir_smoothstep(nb, src[0], src[1], src[2]);403break;404}405406case GLSLstd450FaceForward:407dest->def =408nir_bcsel(nb, nir_flt(nb, nir_fdot(nb, src[2], src[1]),409NIR_IMM_FP(nb, 0.0)),410src[0], nir_fneg(nb, src[0]));411break;412413case GLSLstd450Reflect:414/* I - 2 * dot(N, I) * N */415dest->def =416nir_fsub(nb, src[0], nir_fmul(nb, NIR_IMM_FP(nb, 2.0),417nir_fmul(nb, nir_fdot(nb, src[0], src[1]),418src[1])));419break;420421case GLSLstd450Refract: {422nir_ssa_def *I = src[0];423nir_ssa_def *N = src[1];424nir_ssa_def *eta = src[2];425nir_ssa_def *n_dot_i = nir_fdot(nb, N, I);426nir_ssa_def *one = NIR_IMM_FP(nb, 1.0);427nir_ssa_def *zero = NIR_IMM_FP(nb, 0.0);428/* According to the SPIR-V and GLSL specs, eta is always a float429* regardless of the type of the other operands. However in practice it430* seems that if you try to pass it a float then glslang will just431* promote it to a double and generate invalid SPIR-V. In order to432* support a hypothetical fixed version of glslang we’ll promote eta to433* double if the other operands are double also.434*/435if (I->bit_size != eta->bit_size) {436nir_op conversion_op =437nir_type_conversion_op(nir_type_float | eta->bit_size,438nir_type_float | I->bit_size,439nir_rounding_mode_undef);440eta = nir_build_alu(nb, conversion_op, eta, NULL, NULL, NULL);441}442/* k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I)) */443nir_ssa_def *k =444nir_fsub(nb, one, nir_fmul(nb, eta, nir_fmul(nb, eta,445nir_fsub(nb, one, nir_fmul(nb, n_dot_i, n_dot_i)))));446nir_ssa_def *result =447nir_fsub(nb, nir_fmul(nb, eta, I),448nir_fmul(nb, nir_fadd(nb, nir_fmul(nb, eta, n_dot_i),449nir_fsqrt(nb, k)), N));450/* XXX: bcsel, or if statement? */451dest->def = nir_bcsel(nb, nir_flt(nb, k, zero), zero, result);452break;453}454455case GLSLstd450Sinh:456/* 0.5 * (e^x - e^(-x)) */457dest->def =458nir_fmul_imm(nb, nir_fsub(nb, nir_fexp(nb, src[0]),459nir_fexp(nb, nir_fneg(nb, src[0]))),4600.5f);461break;462463case GLSLstd450Cosh:464/* 0.5 * (e^x + e^(-x)) */465dest->def =466nir_fmul_imm(nb, nir_fadd(nb, nir_fexp(nb, src[0]),467nir_fexp(nb, nir_fneg(nb, src[0]))),4680.5f);469break;470471case GLSLstd450Tanh: {472/* tanh(x) := (e^x - e^(-x)) / (e^x + e^(-x))473*474* We clamp x to [-10, +10] to avoid precision problems. When x > 10,475* e^x dominates the sum, e^(-x) is lost and tanh(x) is 1.0 for 32 bit476* floating point.477*478* For 16-bit precision this we clamp x to [-4.2, +4.2].479*/480const uint32_t bit_size = src[0]->bit_size;481const double clamped_x = bit_size > 16 ? 10.0 : 4.2;482nir_ssa_def *x = nir_fclamp(nb, src[0],483nir_imm_floatN_t(nb, -clamped_x, bit_size),484nir_imm_floatN_t(nb, clamped_x, bit_size));485dest->def =486nir_fdiv(nb, nir_fsub(nb, nir_fexp(nb, x),487nir_fexp(nb, nir_fneg(nb, x))),488nir_fadd(nb, nir_fexp(nb, x),489nir_fexp(nb, nir_fneg(nb, x))));490break;491}492493case GLSLstd450Asinh:494dest->def = nir_fmul(nb, nir_fsign(nb, src[0]),495nir_flog(nb, nir_fadd(nb, nir_fabs(nb, src[0]),496nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),4971.0f)))));498break;499case GLSLstd450Acosh:500dest->def = nir_flog(nb, nir_fadd(nb, src[0],501nir_fsqrt(nb, nir_fadd_imm(nb, nir_fmul(nb, src[0], src[0]),502-1.0f))));503break;504case GLSLstd450Atanh: {505nir_ssa_def *one = nir_imm_floatN_t(nb, 1.0, src[0]->bit_size);506dest->def =507nir_fmul_imm(nb, nir_flog(nb, nir_fdiv(nb, nir_fadd(nb, src[0], one),508nir_fsub(nb, one, src[0]))),5090.5f);510break;511}512513case GLSLstd450Asin:514dest->def = build_asin(nb, src[0], 0.086566724, -0.03102955, true);515break;516517case GLSLstd450Acos:518dest->def =519nir_fsub(nb, nir_imm_floatN_t(nb, M_PI_2f, src[0]->bit_size),520build_asin(nb, src[0], 0.08132463, -0.02363318, false));521break;522523case GLSLstd450Atan:524dest->def = nir_atan(nb, src[0]);525break;526527case GLSLstd450Atan2:528dest->def = nir_atan2(nb, src[0], src[1]);529break;530531case GLSLstd450Frexp: {532dest->def = nir_frexp_sig(nb, src[0]);533534struct vtn_pointer *i_ptr = vtn_value(b, w[6], vtn_value_type_pointer)->pointer;535struct vtn_ssa_value *exp = vtn_create_ssa_value(b, i_ptr->type->type);536exp->def = nir_frexp_exp(nb, src[0]);537vtn_variable_store(b, exp, i_ptr, 0);538break;539}540541case GLSLstd450FrexpStruct: {542vtn_assert(glsl_type_is_struct_or_ifc(dest_type));543dest->elems[0]->def = nir_frexp_sig(nb, src[0]);544dest->elems[1]->def = nir_frexp_exp(nb, src[0]);545break;546}547548default: {549unsigned execution_mode =550b->shader->info.float_controls_execution_mode;551bool exact;552nir_op op = vtn_nir_alu_op_for_spirv_glsl_opcode(b, entrypoint, execution_mode, &exact);553/* don't override explicit decoration */554b->nb.exact |= exact;555dest->def = nir_build_alu(&b->nb, op, src[0], src[1], src[2], NULL);556break;557}558}559b->nb.exact = false;560561vtn_push_ssa_value(b, w[2], dest);562}563564static void565handle_glsl450_interpolation(struct vtn_builder *b, enum GLSLstd450 opcode,566const uint32_t *w, unsigned count)567{568nir_intrinsic_op op;569switch (opcode) {570case GLSLstd450InterpolateAtCentroid:571op = nir_intrinsic_interp_deref_at_centroid;572break;573case GLSLstd450InterpolateAtSample:574op = nir_intrinsic_interp_deref_at_sample;575break;576case GLSLstd450InterpolateAtOffset:577op = nir_intrinsic_interp_deref_at_offset;578break;579default:580vtn_fail("Invalid opcode");581}582583nir_intrinsic_instr *intrin = nir_intrinsic_instr_create(b->nb.shader, op);584585struct vtn_pointer *ptr =586vtn_value(b, w[5], vtn_value_type_pointer)->pointer;587nir_deref_instr *deref = vtn_pointer_to_deref(b, ptr);588589/* If the value we are interpolating has an index into a vector then590* interpolate the vector and index the result of that instead. This is591* necessary because the index will get generated as a series of nir_bcsel592* instructions so it would no longer be an input variable.593*/594const bool vec_array_deref = deref->deref_type == nir_deref_type_array &&595glsl_type_is_vector(nir_deref_instr_parent(deref)->type);596597nir_deref_instr *vec_deref = NULL;598if (vec_array_deref) {599vec_deref = deref;600deref = nir_deref_instr_parent(deref);601}602intrin->src[0] = nir_src_for_ssa(&deref->dest.ssa);603604switch (opcode) {605case GLSLstd450InterpolateAtCentroid:606break;607case GLSLstd450InterpolateAtSample:608case GLSLstd450InterpolateAtOffset:609intrin->src[1] = nir_src_for_ssa(vtn_get_nir_ssa(b, w[6]));610break;611default:612vtn_fail("Invalid opcode");613}614615intrin->num_components = glsl_get_vector_elements(deref->type);616nir_ssa_dest_init(&intrin->instr, &intrin->dest,617glsl_get_vector_elements(deref->type),618glsl_get_bit_size(deref->type), NULL);619620nir_builder_instr_insert(&b->nb, &intrin->instr);621622nir_ssa_def *def = &intrin->dest.ssa;623if (vec_array_deref)624def = nir_vector_extract(&b->nb, def, vec_deref->arr.index.ssa);625626vtn_push_nir_ssa(b, w[2], def);627}628629bool630vtn_handle_glsl450_instruction(struct vtn_builder *b, SpvOp ext_opcode,631const uint32_t *w, unsigned count)632{633switch ((enum GLSLstd450)ext_opcode) {634case GLSLstd450Determinant: {635vtn_push_nir_ssa(b, w[2], build_mat_det(b, vtn_ssa_value(b, w[5])));636break;637}638639case GLSLstd450MatrixInverse: {640vtn_push_ssa_value(b, w[2], matrix_inverse(b, vtn_ssa_value(b, w[5])));641break;642}643644case GLSLstd450InterpolateAtCentroid:645case GLSLstd450InterpolateAtSample:646case GLSLstd450InterpolateAtOffset:647handle_glsl450_interpolation(b, (enum GLSLstd450)ext_opcode, w, count);648break;649650default:651handle_glsl450_alu(b, (enum GLSLstd450)ext_opcode, w, count);652}653654return true;655}656657658