diff options
Diffstat (limited to '3rdparty/bgfx/src/shader_spirv.h')
-rw-r--r-- | 3rdparty/bgfx/src/shader_spirv.h | 406 |
1 files changed, 257 insertions, 149 deletions
diff --git a/3rdparty/bgfx/src/shader_spirv.h b/3rdparty/bgfx/src/shader_spirv.h index 73577e77030..9a7c81b1ac2 100644 --- a/3rdparty/bgfx/src/shader_spirv.h +++ b/3rdparty/bgfx/src/shader_spirv.h @@ -8,30 +8,45 @@ #include <bx/readerwriter.h> +BX_ERROR_RESULT(BGFX_SHADER_SPIRV_INVALID_HEADER, BX_MAKEFOURCC('S', 'H', 0, 1) ); +BX_ERROR_RESULT(BGFX_SHADER_SPIRV_INVALID_INSTRUCTION, BX_MAKEFOURCC('S', 'H', 0, 2) ); + namespace bgfx { // Reference: https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html - struct SpirvOpcode + struct SpvOpcode { enum Enum { Nop, + Undef, + SourceContinued, Source, SourceExtension, + Name, + MemberName, + String, + Line, + Invalid9, Extension, ExtInstImport, + ExtInst, + Invalid13, MemoryModel, EntryPoint, ExecutionMode, + Capability, + Invalid18, TypeVoid, TypeBool, TypeInt, TypeFloat, TypeVector, TypeMatrix, + TypeImage, TypeSampler, - TypeFilter, + TypeSampledImage, TypeArray, TypeRuntimeArray, TypeStruct, @@ -43,37 +58,44 @@ namespace bgfx TypeReserveId, TypeQueue, TypePipe, + TypeForwardPointer, + Invalid40, ConstantTrue, ConstantFalse, Constant, ConstantComposite, ConstantSampler, - ConstantNullPointer, - ConstantNullObject, + ConstantNull, + Invalid47, SpecConstantTrue, SpecConstantFalse, SpecConstant, SpecConstantComposite, - Variable, - VariableArray, + SpecConstantOp, + Invalid53, Function, FunctionParameter, FunctionEnd, FunctionCall, - ExtInst, - Undef, + Invalid58, + Variable, + ImageTexelPointer, Load, Store, - Phi, - DecorationGroup, + CopyMemory, + CopyMemorySized, + AccessChain, + InBoundsAccessChain, + PtrAccessChain, + ArrayLength, + GenericPtrMemSemantics, + InBoundsPtrAccessChain, Decorate, MemberDecorate, + DecorationGroup, GroupDecorate, GroupMemberDecorate, - Name, - MemberName, - String, - Line, + Invalid76, VectorExtractDynamic, VectorInsertDynamic, VectorShuffle, @@ -81,41 +103,31 @@ namespace bgfx CompositeExtract, CompositeInsert, CopyObject, - CopyMemory, - CopyMemorySized, - Sampler, - TextureSample, - TextureSampleDref, - TextureSampleLod, - TextureSampleProj, - TextureSampleGrad, - TextureSampleOffset, - TextureSampleProjLod, - TextureSampleProjGrad, - TextureSampleLodOffset, - TextureSampleProjOffset, - TextureSampleGradOffset, - TextureSampleProjLodOffset, - TextureSampleProjGradOffset, - TextureFetchTexelLod, - TextureFetchTexelOffset, - TextureFetchSample, - TextureFetchTexel, - TextureGather, - TextureGatherOffset, - TextureGatherOffsets, - TextureQuerySizeLod, - TextureQuerySize, - TextureQueryLod, - TextureQueryLevels, - TextureQuerySamples, - AccessChain, - InBoundsAccessChain, - SNegate, - FNegate, - Not, - Any, - All, + Transpose, + Invalid85, + SampledImage, + ImageSampleImplicitLod, + ImageSampleExplicitLod, + ImageSampleDrefImplicitLod, + ImageSampleDrefExplicitLod, + ImageSampleProjImplicitLod, + ImageSampleProjExplicitLod, + ImageSampleProjDrefImplicitLod, + ImageSampleProjDrefExplicitLod, + ImageFetch, + ImageGather, + ImageDrefGather, + ImageRead, + ImageWrite, + Image, + ImageQueryFormat, + ImageQueryOrder, + ImageQuerySizeLod, + ImageQuerySize, + ImageQueryLod, + ImageQueryLevels, + ImageQuerySamples, + Invalid108, ConvertFToU, ConvertFToS, ConvertSToF, @@ -123,21 +135,18 @@ namespace bgfx UConvert, SConvert, FConvert, + QuantizeToF16, ConvertPtrToU, + SatConvertSToU, + SatConvertUToS, ConvertUToPtr, PtrCastToGeneric, GenericCastToPtr, + GenericCastToPtrExplicit, Bitcast, - Transpose, - IsNan, - IsInf, - IsFinite, - IsNormal, - SignBitSet, - LessOrGreater, - Ordered, - Unordered, - ArrayLength, + Invalid125, + SNegate, + FNegate, IAdd, FAdd, ISub, @@ -159,38 +168,64 @@ namespace bgfx MatrixTimesMatrix, OuterProduct, Dot, - ShiftRightLogical, - ShiftRightArithmetic, - ShiftLeftLogical, + IAddCarry, + ISubBorrow, + UMulExtended, + SMulExtended, + Invalid153, + Any, + All, + IsNan, + IsInf, + IsFinite, + IsNormal, + SignBitSet, + LessOrGreater, + Ordered, + Unordered, + LogicalEqual, + LogicalNotEqual, LogicalOr, - LogicalXor, LogicalAnd, - BitwiseOr, - BitwiseXor, - BitwiseAnd, + LogicalNot, Select, IEqual, + INotEqual, + UGreaterThan, + SGreaterThan, + UGreaterThanEqual, + SGreaterThanEqual, + ULessThan, + SLessThan, + ULessThanEqual, + SLessThanEqual, FOrdEqual, FUnordEqual, - INotEqual, FOrdNotEqual, FUnordNotEqual, - ULessThan, - SLessThan, FOrdLessThan, FUnordLessThan, - UGreaterThan, - SGreaterThan, FOrdGreaterThan, FUnordGreaterThan, - ULessThanEqual, - SLessThanEqual, FOrdLessThanEqual, FUnordLessThanEqual, - UGreaterThanEqual, - SGreaterThanEqual, FOrdGreaterThanEqual, FUnordGreaterThanEqual, + Invalid192, + Invalid193, + ShiftRightLogical, + ShiftRightArithmetic, + ShiftLeftLogical, + BitwiseOr, + BitwiseXor, + BitwiseAnd, + Not, + BitFieldInsert, + BitFieldSExtract, + BitFieldUExtract, + BitReverse, + BitCount, + Invalid206, DPdx, DPdy, Fwidth, @@ -200,14 +235,17 @@ namespace bgfx DPdxCoarse, DPdyCoarse, FwidthCoarse, + Invalid216, + Invalid217, EmitVertex, EndPrimitive, EmitStreamVertex, EndStreamPrimitive, + Invalid222, + Invalid223, ControlBarrier, MemoryBarrier, - ImagePointer, - AtomicInit, + Invalid226, AtomicLoad, AtomicStore, AtomicExchange, @@ -217,11 +255,16 @@ namespace bgfx AtomicIDecrement, AtomicIAdd, AtomicISub, + AtomicSMin, AtomicUMin, + AtomicSMax, AtomicUMax, AtomicAnd, AtomicOr, AtomicXor, + Invalid243, + Invalid244, + Phi, LoopMerge, SelectionMerge, Label, @@ -234,9 +277,9 @@ namespace bgfx Unreachable, LifetimeStart, LifetimeStop, - CompileFlag, - AsyncGroupCopy, - WaitGroupEvents, + Invalid258, + GroupAsyncCopy, + GroupWaitEvents, GroupAll, GroupAny, GroupBroadcast, @@ -248,8 +291,8 @@ namespace bgfx GroupFMax, GroupUMax, GroupSMax, - GenericCastToPtrExplicit, - GenericPtrMemSemantics, + Invalid272, + Invalid273, ReadPipe, WritePipe, ReservedReadPipe, @@ -265,6 +308,8 @@ namespace bgfx GroupReserveWritePipePackets, GroupCommitReadPipe, GroupCommitWritePipe, + Invalid289, + Invalid290, EnqueueMarker, EnqueueKernel, GetKernelNDrangeSubGroupCount, @@ -279,10 +324,22 @@ namespace bgfx CaptureEventProfilingInfo, GetDefaultQueue, BuildNDRange, - SatConvertSToU, - SatConvertUToS, - AtomicIMin, - AtomicIMax, + ImageSparseSampleImplicitLod, + ImageSparseSampleExplicitLod, + ImageSparseSampleDrefImplicitLod, + ImageSparseSampleDrefExplicitLod, + ImageSparseSampleProjImplicitLod, + ImageSparseSampleProjExplicitLod, + ImageSparseSampleProjDrefImplicitLod, + ImageSparseSampleProjDrefExplicitLod, + ImageSparseFetch, + ImageSparseGather, + ImageSparseDrefGather, + ImageSparseTexelsResident, + NoLine, + AtomicFlagTestAndSet, + AtomicFlagClear, + ImageSparseRead, Count }; @@ -294,12 +351,11 @@ namespace bgfx { Position, PointSize, - ClipVertex, ClipDistance, CullDistance, VertexId, InstanceId, - BuiltInPrimitiveId, + PrimitiveId, InvocationId, Layer, ViewportIndex, @@ -313,7 +369,6 @@ namespace bgfx SampleId, SamplePosition, SampleMask, - FragColor, FragDepth, HelperInvocation, NumWorkgroups, @@ -327,17 +382,20 @@ namespace bgfx EnqueuedWorkgroupSize, GlobalOffset, GlobalLinearId, - WorkgroupLinearId, SubgroupSize, SubgroupMaxSize, NumSubgroups, NumEnqueuedSubgroups, SubgroupId, SubgroupLocalInvocationId, + VertexIndex, + InstanceIndex, + + Count }; }; - struct SpirvExecutionModel + struct SpvExecutionModel { enum Enum { @@ -353,21 +411,31 @@ namespace bgfx }; }; - struct SpirvMemoryModel + struct SpvAddressingModel + { + enum Enum + { + Logical, + Physical32, + Physical64, + + Count + }; + }; + + struct SpvMemoryModel { enum Enum { Simple, GLSL450, - OpenCL12, - OpenCL20, - OpenCL21, + OpenCL, Count }; }; - struct SpirvStorageClass + struct SpvStorageClass { enum Enum { @@ -375,17 +443,20 @@ namespace bgfx Input, Uniform, Output, - WorkgroupLocal, - WorkgroupGlobal, - PrivateGlobal, + Workgroup, + CrossWorkgroup, + Private, Function, Generic, - Private, + PushConstant, AtomicCounter, + Image, + + Count }; }; - struct SpirvResourceDim + struct SpvResourceDim { enum Enum { @@ -395,26 +466,27 @@ namespace bgfx TextureCube, TextureRect, Buffer, + SubpassData, }; }; - struct SpirvDecoration + struct SpvDecoration { enum Enum { - PrecisionLow, - PrecisionMedium, - PrecisionHigh, + RelaxedPrecision, + SpecId, Block, BufferBlock, RowMajor, ColMajor, + ArrayStride, + MatrixStride, GLSLShared, - GLSLStd140, - GLSLStd430, GLSLPacked, - Smooth, - Noperspective, + CPacked, + BuiltIn, + NoPerspective, Flat, Patch, Centroid, @@ -425,11 +497,9 @@ namespace bgfx Volatile, Constant, Coherent, - Nonwritable, - Nonreadable, + NonWritable, + NonReadable, Uniform, - NoStaticUse, - CPacked, SaturatedConversion, Stream, Location, @@ -438,66 +508,104 @@ namespace bgfx Binding, DescriptorSet, Offset, - Alignment, XfbBuffer, - Stride, - BuiltIn, + XfbStride, FuncParamAttr, FPRoundingMode, FPFastMathMode, LinkageAttributes, - SpecId, + NoContraction, + InputAttachmentIndex, + Alignment, Count }; }; - struct SpirvOperand + struct SpvOperand { + enum Enum + { + AccessQualifier, + AddressingModel, + Base, + Capability, + Component, + ComponentType, + Composite, + Condition, + Coordinate, + Decoration, + Dim, + Dref, + ExecutionModel, + Function, + FunctionControl, + Id, + IdRep, + ImageFormat, + ImageOperands, + LiteralNumber, + LiteralRep, + LiteralString, + Matrix, + MemoryAccess, + MemoryModel, + Object, + Pointer, + SampledType, + SampledImage, + SamplerAddressingMode, + SamplerFilterMode, + Scalar, + SourceLanguage, + StorageClass, + StructureType, + Vector, + + Count + }; + + Enum type; + uint32_t data[4]; + + uint32_t target; + stl::string literalString; }; - struct SpirvInstruction + struct SpvInstruction { - SpirvOpcode::Enum opcode; + SpvOpcode::Enum opcode; uint16_t length; + uint16_t numOperands; - uint8_t numOperands; - SpirvOperand operand[6]; - - union - { - struct ResultTypeId - { - uint32_t resultType; - uint32_t id; - }; - - ResultTypeId constant; - ResultTypeId constantComposite; + uint32_t type; + uint32_t result; + bool hasType; + bool hasResult; - uint32_t value[8]; - } un; + SpvOperand operand[8]; }; - int32_t read(bx::ReaderI* _reader, SpirvInstruction& _instruction); - int32_t write(bx::WriterI* _writer, const SpirvInstruction& _instruction); - int32_t toString(char* _out, int32_t _size, const SpirvInstruction& _instruction); + int32_t read(bx::ReaderI* _reader, SpvInstruction& _instruction, bx::Error* _err); + int32_t write(bx::WriterI* _writer, const SpvInstruction& _instruction, bx::Error* _err); + int32_t toString(char* _out, int32_t _size, const SpvInstruction& _instruction); - struct SpirvShader + struct SpvShader { stl::vector<uint8_t> byteCode; }; - int32_t read(bx::ReaderSeekerI* _reader, SpirvShader& _shader); - int32_t write(bx::WriterI* _writer, const SpirvShader& _shader); + int32_t read(bx::ReaderSeekerI* _reader, SpvShader& _shader, bx::Error* _err); + int32_t write(bx::WriterI* _writer, const SpvShader& _shader, bx::Error* _err); - typedef void (*SpirvParseFn)(uint32_t _offset, const SpirvInstruction& _instruction, void* _userData); - void parse(const SpirvShader& _src, SpirvParseFn _fn, void* _userData); + typedef bool (*SpirvParseFn)(uint32_t _offset, const SpvInstruction& _instruction, void* _userData); + void parse(const SpvShader& _src, SpirvParseFn _fn, void* _userData, bx::Error* _err = NULL); - typedef void (*SpirvFilterFn)(SpirvInstruction& _instruction, void* _userData); - void filter(SpirvShader& _dst, const SpirvShader& _src, SpirvFilterFn _fn, void* _userData); + typedef void (*SpirvFilterFn)(SpvInstruction& _instruction, void* _userData); + void filter(SpvShader& _dst, const SpvShader& _src, SpirvFilterFn _fn, void* _userData, bx::Error* _err = NULL); - struct Spirv + struct SpirV { struct Header { @@ -509,11 +617,11 @@ namespace bgfx }; Header header; - SpirvShader shader; + SpvShader shader; }; - int32_t read(bx::ReaderSeekerI* _reader, Spirv& _spirv); - int32_t write(bx::WriterSeekerI* _writer, const Spirv& _spirv); + int32_t read(bx::ReaderSeekerI* _reader, SpirV& _spirv, bx::Error* _err); + int32_t write(bx::WriterSeekerI* _writer, const SpirV& _spirv, bx::Error* _err); } // namespace bgfx |