nir/spirv: Use the actual GLSL 450 extension header from Khronos

This commit is contained in:
Jason Ekstrand 2015-09-04 18:39:57 -07:00
parent 9e2c13350e
commit f32d16a9f0
2 changed files with 203 additions and 180 deletions

View File

@ -0,0 +1,130 @@
/*
** Copyright (c) 2014-2015 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a copy
** of this software and/or associated documentation files (the "Materials"),
** to deal in the Materials without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Materials, and to permit persons to whom the
** Materials are furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Materials.
**
** MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
** STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
** HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
** OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
** THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
** IN THE MATERIALS.
*/
#ifndef GLSLstd450_H
#define GLSLstd450_H
const int GLSLstd450Version = 99;
const int GLSLstd450Revision = 2;
enum GLSLstd450 {
GLSLstd450Bad = 0, // Don't use
GLSLstd450Round = 1,
GLSLstd450RoundEven = 2,
GLSLstd450Trunc = 3,
GLSLstd450FAbs = 4,
GLSLstd450SAbs = 5,
GLSLstd450FSign = 6,
GLSLstd450SSign = 7,
GLSLstd450Floor = 8,
GLSLstd450Ceil = 9,
GLSLstd450Fract = 10,
GLSLstd450Radians = 11,
GLSLstd450Degrees = 12,
GLSLstd450Sin = 13,
GLSLstd450Cos = 14,
GLSLstd450Tan = 15,
GLSLstd450Asin = 16,
GLSLstd450Acos = 17,
GLSLstd450Atan = 18,
GLSLstd450Sinh = 19,
GLSLstd450Cosh = 20,
GLSLstd450Tanh = 21,
GLSLstd450Asinh = 22,
GLSLstd450Acosh = 23,
GLSLstd450Atanh = 24,
GLSLstd450Atan2 = 25,
GLSLstd450Pow = 26,
GLSLstd450Exp = 27,
GLSLstd450Log = 28,
GLSLstd450Exp2 = 29,
GLSLstd450Log2 = 30,
GLSLstd450Sqrt = 31,
GLSLstd450InverseSqrt = 32,
GLSLstd450Determinant = 33,
GLSLstd450MatrixInverse = 34,
GLSLstd450Modf = 35, // second operand needs an OpVariable to write to
GLSLstd450ModfStruct = 36, // no OpVariable operand
GLSLstd450FMin = 37,
GLSLstd450UMin = 38,
GLSLstd450SMin = 39,
GLSLstd450FMax = 40,
GLSLstd450UMax = 41,
GLSLstd450SMax = 42,
GLSLstd450FClamp = 43,
GLSLstd450UClamp = 44,
GLSLstd450SClamp = 45,
GLSLstd450Mix = 46,
GLSLstd450Step = 47,
GLSLstd450SmoothStep = 48,
GLSLstd450Fma = 49,
GLSLstd450Frexp = 50, // second operand needs an OpVariable to write to
GLSLstd450FrexpStruct = 51, // no OpVariable operand
GLSLstd450Ldexp = 52,
GLSLstd450PackSnorm4x8 = 53,
GLSLstd450PackUnorm4x8 = 54,
GLSLstd450PackSnorm2x16 = 55,
GLSLstd450PackUnorm2x16 = 56,
GLSLstd450PackHalf2x16 = 57,
GLSLstd450PackDouble2x32 = 58,
GLSLstd450UnpackSnorm2x16 = 59,
GLSLstd450UnpackUnorm2x16 = 60,
GLSLstd450UnpackHalf2x16 = 61,
GLSLstd450UnpackSnorm4x8 = 62,
GLSLstd450UnpackUnorm4x8 = 63,
GLSLstd450UnpackDouble2x32 = 64,
GLSLstd450Length = 65,
GLSLstd450Distance = 66,
GLSLstd450Cross = 67,
GLSLstd450Normalize = 68,
GLSLstd450FaceForward = 69,
GLSLstd450Reflect = 70,
GLSLstd450Refract = 71,
GLSLstd450FindILSB = 72,
GLSLstd450FindSMSB = 73,
GLSLstd450FindUMSB = 74,
GLSLstd450InterpolateAtCentroid = 75,
GLSLstd450InterpolateAtSample = 76,
GLSLstd450InterpolateAtOffset = 77,
GLSLstd450AddCarry = 78, // These three should move to the core instruction set
GLSLstd450SubBorrow = 79,
GLSLstd450MulExtended = 80,
GLSLstd450Count
};
#endif // #ifndef GLSLstd450_H

View File

@ -26,100 +26,7 @@
*/
#include "spirv_to_nir_private.h"
enum GLSL450Entrypoint {
Round = 0,
RoundEven = 1,
Trunc = 2,
Abs = 3,
Sign = 4,
Floor = 5,
Ceil = 6,
Fract = 7,
Radians = 8,
Degrees = 9,
Sin = 10,
Cos = 11,
Tan = 12,
Asin = 13,
Acos = 14,
Atan = 15,
Sinh = 16,
Cosh = 17,
Tanh = 18,
Asinh = 19,
Acosh = 20,
Atanh = 21,
Atan2 = 22,
Pow = 23,
Exp = 24,
Log = 25,
Exp2 = 26,
Log2 = 27,
Sqrt = 28,
InverseSqrt = 29,
Determinant = 30,
MatrixInverse = 31,
Modf = 32, // second argument needs the OpVariable = , not an OpLoad
Min = 33,
Max = 34,
Clamp = 35,
Mix = 36,
Step = 37,
SmoothStep = 38,
FloatBitsToInt = 39,
FloatBitsToUint = 40,
IntBitsToFloat = 41,
UintBitsToFloat = 42,
Fma = 43,
Frexp = 44,
Ldexp = 45,
PackSnorm4x8 = 46,
PackUnorm4x8 = 47,
PackSnorm2x16 = 48,
PackUnorm2x16 = 49,
PackHalf2x16 = 50,
PackDouble2x32 = 51,
UnpackSnorm2x16 = 52,
UnpackUnorm2x16 = 53,
UnpackHalf2x16 = 54,
UnpackSnorm4x8 = 55,
UnpackUnorm4x8 = 56,
UnpackDouble2x32 = 57,
Length = 58,
Distance = 59,
Cross = 60,
Normalize = 61,
Ftransform = 62,
FaceForward = 63,
Reflect = 64,
Refract = 65,
UaddCarry = 66,
UsubBorrow = 67,
UmulExtended = 68,
ImulExtended = 69,
BitfieldExtract = 70,
BitfieldInsert = 71,
BitfieldReverse = 72,
BitCount = 73,
FindLSB = 74,
FindMSB = 75,
InterpolateAtCentroid = 76,
InterpolateAtSample = 77,
InterpolateAtOffset = 78,
Count
};
#include "spirv_glsl450.h"
static nir_ssa_def*
build_length(nir_builder *b, nir_ssa_def *vec)
@ -135,7 +42,7 @@ build_length(nir_builder *b, nir_ssa_def *vec)
}
static void
handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
handle_glsl450_alu(struct vtn_builder *b, enum GLSLstd450 entrypoint,
const uint32_t *w, unsigned count)
{
struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_ssa);
@ -150,106 +57,92 @@ handle_glsl450_alu(struct vtn_builder *b, enum GLSL450Entrypoint entrypoint,
nir_op op;
switch (entrypoint) {
case Round: op = nir_op_fround_even; break; /* TODO */
case RoundEven: op = nir_op_fround_even; break;
case Trunc: op = nir_op_ftrunc; break;
case Abs: op = nir_op_fabs; break;
case Sign: op = nir_op_fsign; break;
case Floor: op = nir_op_ffloor; break;
case Ceil: op = nir_op_fceil; break;
case Fract: op = nir_op_ffract; break;
case Radians:
case GLSLstd450Round: op = nir_op_fround_even; break; /* TODO */
case GLSLstd450RoundEven: op = nir_op_fround_even; break;
case GLSLstd450Trunc: op = nir_op_ftrunc; break;
case GLSLstd450FAbs: op = nir_op_fabs; break;
case GLSLstd450FSign: op = nir_op_fsign; break;
case GLSLstd450Floor: op = nir_op_ffloor; break;
case GLSLstd450Ceil: op = nir_op_fceil; break;
case GLSLstd450Fract: op = nir_op_ffract; break;
case GLSLstd450Radians:
val->ssa->def = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 0.01745329251));
return;
case Degrees:
case GLSLstd450Degrees:
val->ssa->def = nir_fmul(&b->nb, src[0], nir_imm_float(&b->nb, 57.2957795131));
return;
case Sin: op = nir_op_fsin; break;
case Cos: op = nir_op_fcos; break;
case Tan:
case GLSLstd450Sin: op = nir_op_fsin; break;
case GLSLstd450Cos: op = nir_op_fcos; break;
case GLSLstd450Tan:
val->ssa->def = nir_fdiv(&b->nb, nir_fsin(&b->nb, src[0]),
nir_fcos(&b->nb, src[0]));
return;
case Pow: op = nir_op_fpow; break;
case Exp2: op = nir_op_fexp2; break;
case Log2: op = nir_op_flog2; break;
case Sqrt: op = nir_op_fsqrt; break;
case InverseSqrt: op = nir_op_frsq; break;
case GLSLstd450Pow: op = nir_op_fpow; break;
case GLSLstd450Exp2: op = nir_op_fexp2; break;
case GLSLstd450Log2: op = nir_op_flog2; break;
case GLSLstd450Sqrt: op = nir_op_fsqrt; break;
case GLSLstd450InverseSqrt: op = nir_op_frsq; break;
case Modf: op = nir_op_fmod; break;
case Min: op = nir_op_fmin; break;
case Max: op = nir_op_fmax; break;
case Mix: op = nir_op_flrp; break;
case Step:
case GLSLstd450Modf: op = nir_op_fmod; break;
case GLSLstd450FMin: op = nir_op_fmin; break;
case GLSLstd450FMax: op = nir_op_fmax; break;
case GLSLstd450Mix: op = nir_op_flrp; break;
case GLSLstd450Step:
val->ssa->def = nir_sge(&b->nb, src[1], src[0]);
return;
case FloatBitsToInt:
case FloatBitsToUint:
case IntBitsToFloat:
case UintBitsToFloat:
/* Probably going to be removed from the final version of the spec. */
val->ssa->def = src[0];
return;
case Fma: op = nir_op_ffma; break;
case Ldexp: op = nir_op_ldexp; break;
case GLSLstd450Fma: op = nir_op_ffma; break;
case GLSLstd450Ldexp: op = nir_op_ldexp; break;
/* Packing/Unpacking functions */
case PackSnorm4x8: op = nir_op_pack_snorm_4x8; break;
case PackUnorm4x8: op = nir_op_pack_unorm_4x8; break;
case PackSnorm2x16: op = nir_op_pack_snorm_2x16; break;
case PackUnorm2x16: op = nir_op_pack_unorm_2x16; break;
case PackHalf2x16: op = nir_op_pack_half_2x16; break;
case UnpackSnorm4x8: op = nir_op_unpack_snorm_4x8; break;
case UnpackUnorm4x8: op = nir_op_unpack_unorm_4x8; break;
case UnpackSnorm2x16: op = nir_op_unpack_snorm_2x16; break;
case UnpackUnorm2x16: op = nir_op_unpack_unorm_2x16; break;
case UnpackHalf2x16: op = nir_op_unpack_half_2x16; break;
case GLSLstd450PackSnorm4x8: op = nir_op_pack_snorm_4x8; break;
case GLSLstd450PackUnorm4x8: op = nir_op_pack_unorm_4x8; break;
case GLSLstd450PackSnorm2x16: op = nir_op_pack_snorm_2x16; break;
case GLSLstd450PackUnorm2x16: op = nir_op_pack_unorm_2x16; break;
case GLSLstd450PackHalf2x16: op = nir_op_pack_half_2x16; break;
case GLSLstd450UnpackSnorm4x8: op = nir_op_unpack_snorm_4x8; break;
case GLSLstd450UnpackUnorm4x8: op = nir_op_unpack_unorm_4x8; break;
case GLSLstd450UnpackSnorm2x16: op = nir_op_unpack_snorm_2x16; break;
case GLSLstd450UnpackUnorm2x16: op = nir_op_unpack_unorm_2x16; break;
case GLSLstd450UnpackHalf2x16: op = nir_op_unpack_half_2x16; break;
case Length:
case GLSLstd450Length:
val->ssa->def = build_length(&b->nb, src[0]);
return;
case Distance:
case GLSLstd450Distance:
val->ssa->def = build_length(&b->nb, nir_fsub(&b->nb, src[0], src[1]));
return;
case Normalize:
case GLSLstd450Normalize:
val->ssa->def = nir_fdiv(&b->nb, src[0], build_length(&b->nb, src[0]));
return;
case UaddCarry: op = nir_op_uadd_carry; break;
case UsubBorrow: op = nir_op_usub_borrow; break;
case BitfieldExtract: op = nir_op_ubitfield_extract; break; /* TODO */
case BitfieldInsert: op = nir_op_bitfield_insert; break;
case BitfieldReverse: op = nir_op_bitfield_reverse; break;
case BitCount: op = nir_op_bit_count; break;
case FindLSB: op = nir_op_find_lsb; break;
case FindMSB: op = nir_op_ufind_msb; break; /* TODO */
case GLSLstd450AddCarry: op = nir_op_uadd_carry; break;
case GLSLstd450SubBorrow: op = nir_op_usub_borrow; break;
case Exp:
case Log:
case Clamp:
case Asin:
case Acos:
case Atan:
case Atan2:
case Sinh:
case Cosh:
case Tanh:
case Asinh:
case Acosh:
case Atanh:
case SmoothStep:
case Frexp:
case PackDouble2x32:
case UnpackDouble2x32:
case Cross:
case Ftransform:
case FaceForward:
case Reflect:
case Refract:
case UmulExtended:
case ImulExtended:
case GLSLstd450Exp:
case GLSLstd450Log:
case GLSLstd450FClamp:
case GLSLstd450UClamp:
case GLSLstd450SClamp:
case GLSLstd450Asin:
case GLSLstd450Acos:
case GLSLstd450Atan:
case GLSLstd450Atan2:
case GLSLstd450Sinh:
case GLSLstd450Cosh:
case GLSLstd450Tanh:
case GLSLstd450Asinh:
case GLSLstd450Acosh:
case GLSLstd450Atanh:
case GLSLstd450SmoothStep:
case GLSLstd450Frexp:
case GLSLstd450PackDouble2x32:
case GLSLstd450UnpackDouble2x32:
case GLSLstd450Cross:
case GLSLstd450FaceForward:
case GLSLstd450Reflect:
case GLSLstd450Refract:
case GLSLstd450MulExtended:
default:
unreachable("Unhandled opcode");
}
@ -269,16 +162,16 @@ bool
vtn_handle_glsl450_instruction(struct vtn_builder *b, uint32_t ext_opcode,
const uint32_t *words, unsigned count)
{
switch ((enum GLSL450Entrypoint)ext_opcode) {
case Determinant:
case MatrixInverse:
case InterpolateAtCentroid:
case InterpolateAtSample:
case InterpolateAtOffset:
switch ((enum GLSLstd450)ext_opcode) {
case GLSLstd450Determinant:
case GLSLstd450MatrixInverse:
case GLSLstd450InterpolateAtCentroid:
case GLSLstd450InterpolateAtSample:
case GLSLstd450InterpolateAtOffset:
unreachable("Unhandled opcode");
default:
handle_glsl450_alu(b, (enum GLSL450Entrypoint)ext_opcode, words, count);
handle_glsl450_alu(b, (enum GLSLstd450)ext_opcode, words, count);
}
return true;