yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
0d16228ae
master
1#pragma once 2 3#include "../core/slang-dictionary.h" 4#include "../core/slang-smart-pointer.h" 5#include "../core/slang-string-slice-pool.h" 6#include "../core/slang-string.h" 7 8#include <optional> 9#include <spirv/unified1/NonSemanticShaderDebugInfo100.h> 10#include <spirv/unified1/spirv.h> 11 12namespace Slang 13{ 14using SpvWord = uint32_t ; 15class DiagnosticSink ; 16class SourceView ; 17 18struct SPIRVCoreGrammarInfo :public RefObject 19{ 20static RefPtr < SPIRVCoreGrammarInfo > loadFromJSON (SourceView & source ,DiagnosticSink & sink ); 21static RefPtr < SPIRVCoreGrammarInfo >& getEmbeddedVersion (); 22static inline void freeEmbeddedGrammerInfo () {getEmbeddedVersion ()= nullptr ; } 23 24template < typename K ,typename T > 25struct Lookup 26 { 27std ::optional < T > lookup (const K & name )const 28 { 29T ret ; 30if (embedded ?embedded (name ,ret ) :dict .tryGetValue (name ,ret )) 31return ret ; 32else 33return std ::nullopt ; 34 } 35 36bool (* embedded )(const K & ,T & )= nullptr ; 37Dictionary < K ,T > dict ; 38 }; 39 40struct OperandKind 41 { 42uint8_t index ; 43SLANG_COMPONENTWISE_HASHABLE_1 ; 44SLANG_COMPONENTWISE_EQUALITY_1 (OperandKind ); 45 }; 46 47struct QualifiedEnumName 48 { 49OperandKind kind ; 50UnownedStringSlice name ; 51SLANG_COMPONENTWISE_HASHABLE_2 ; 52SLANG_COMPONENTWISE_EQUALITY_2 (QualifiedEnumName ); 53 }; 54 55struct QualifiedEnumValue 56 { 57OperandKind kind ; 58SpvWord value ; 59SLANG_COMPONENTWISE_HASHABLE_2 ; 60SLANG_COMPONENTWISE_EQUALITY_2 (QualifiedEnumValue ); 61 }; 62 63struct OpInfo 64 { 65enum Class 66 { 67// Unrecognized instructions go in here 68Other , 69 70// Adding to this? Don't forget to update the embedding generator 71Miscellaneous , 72Debug , 73Annotation , 74Extension , 75ModeSetting , 76TypeDeclaration , 77ConstantCreation , 78Memory , 79Function , 80Image , 81Conversion , 82Composite , 83Arithmetic , 84Bit , 85Relational_and_Logical , 86Derivative , 87ControlFlow , 88Atomic , 89Primitive , 90Barrier , 91Group , 92DeviceSideEnqueue , 93Pipe , 94NonUniform , 95Reserved , 96 }; 97 constexprstatic int8_t kNoResultTypeId = -1 ; 98 constexprstatic int8_t kNoResultId = -1 ; 99 100Class class_ ; 101// -1 or 0 102int8_t resultTypeIndex = kNoResultTypeId ; 103// -1 or 0 or 1 104int8_t resultIdIndex = kNoResultId ; 105// The range of valid operand counts for this instruction, 106// including any result type and id. Multi-word operands count as a 107// single operand. 108uint16_t minOperandCount ; 109uint16_t maxOperandCount ; 110// when looking up an operand type, clamp to this number-1 to 111// account for variable length operands at the end 112uint16_t numOperandTypes ; 113const OperandKind * operandTypes ; 114 }; 115 116// 117// Our tables: 118// 119 120// Instruction name to opcode 121Lookup < UnownedStringSlice ,SpvOp > opcodes ; 122// Capability name to value 123Lookup < UnownedStringSlice ,SpvCapability > capabilities ; 124// String-qualified enum name (one with the type prefix) to value 125Lookup < UnownedStringSlice ,SpvWord > allEnumsWithTypePrefix ; 126// kind * enum name to value 127Lookup < QualifiedEnumName ,SpvWord > allEnums ; 128// kine * enum value to unqualified name 129Lookup < QualifiedEnumValue ,UnownedStringSlice > allEnumNames ; 130// Any other information on instructions 131Lookup < SpvOp ,OpInfo > opInfos ; 132// Opcode to instruction name 133Lookup < SpvOp ,UnownedStringSlice > opNames ; 134// Operand kind string to numeric id 135Lookup < UnownedStringSlice ,OperandKind > operandKinds ; 136// Operand kind id to string 137Lookup < OperandKind ,UnownedStringSlice > operandKindNames ; 138// Operand kind to the "un-id" version of itself, for example IdMemorySemantics to 139// MemorySemantics 140Lookup < OperandKind ,OperandKind > operandKindUnderneathIds ; 141 142private : 143// If this is loaded from JSON, we keep the strings around instead of 144// copying them as dictionary keys 145StringSlicePool strings = StringSlicePool (StringSlicePool ::Style ::Empty ); 146List < OperandKind > operandTypesStorage ; 147}; 148}// namespace Slang