diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-09-24 17:20:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-09-24 17:20:32 -0400 |
| commit | 32c8479fb964b1936564ef9cf68e434500d7b7df (patch) | |
| tree | 533481f95f031141186e71ad5857c3c2ee8f1470 /source | |
| parent | 7250ed1e73351b6f3f72d6a42a90f2878f78b0f8 (diff) | |
Remap IROp value ranges
* Change the layout of IROp such that 'main' IROps are 0-x. (#649)
* Removed MANUAL_RANGE instuction types, as no longer needed.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 4 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 4 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 2 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 2 | ||||
| -rw-r--r-- | source/slang/ir-inst-defs.h | 19 | ||||
| -rw-r--r-- | source/slang/ir.h | 43 | ||||
| -rw-r--r-- | source/slang/lower-to-ir.cpp | 2 |
7 files changed, 43 insertions, 33 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index fd8826de3..56f5d8d1f 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -461,7 +461,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "__generic<T = float4> "; sb << "__magic_type(TextureSampler," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureSamplerType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureSamplerType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct Sampler"; sb << kBaseTextureAccessLevels[accessLevel].name; sb << name; @@ -519,7 +519,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "__generic<T = float4> "; sb << "__magic_type(Texture," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct "; sb << kBaseTextureAccessLevels[accessLevel].name; sb << name; diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index d5b513d2f..3b6801a25 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -476,7 +476,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "__generic<T = float4> "; sb << "__magic_type(TextureSampler," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureSamplerType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureSamplerType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct Sampler"; sb << kBaseTextureAccessLevels[accessLevel].name; sb << name; @@ -534,7 +534,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "__generic<T = float4> "; sb << "__magic_type(Texture," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct "; sb << kBaseTextureAccessLevels[accessLevel].name; sb << name; diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index b8cd7a4ad..208f98278 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -1180,7 +1180,7 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) auto flavor = TextureFlavor::create(TextureFlavor::Shape::ShapeBuffer, kBaseBufferAccessLevels[aa].access).flavor; sb << "__generic<T>\n"; sb << "__magic_type(Texture," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct "; sb << kBaseBufferAccessLevels[aa].name; sb << "Buffer {\n"; diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 7a2bcc759..f5ed05745 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -1225,7 +1225,7 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa) auto flavor = TextureFlavor::create(TextureFlavor::Shape::ShapeBuffer, kBaseBufferAccessLevels[aa].access).flavor; sb << "__generic<T>\n"; sb << "__magic_type(Texture," << int(flavor) << ")\n"; - sb << "__intrinsic_type(" << (kIROp_FirstTextureType + flavor) << ")\n"; + sb << "__intrinsic_type(" << (kIROp_TextureType + (int(flavor) << kIROp_Mask_Shift)) << ")\n"; sb << "struct "; sb << kBaseBufferAccessLevels[aa].name; sb << "Buffer {\n"; diff --git a/source/slang/ir-inst-defs.h b/source/slang/ir-inst-defs.h index 25ef86eaf..c12a69304 100644 --- a/source/slang/ir-inst-defs.h +++ b/source/slang/ir-inst-defs.h @@ -8,10 +8,6 @@ #define INST_RANGE(BASE, FIRST, LAST) /* empty */ #endif -#ifndef MANUAL_INST_RANGE -#define MANUAL_INST_RANGE(NAME, START, COUNT) /* empty */ -#endif - #ifndef PSEUDO_INST #define PSEUDO_INST(ID) /* empty */ #endif @@ -82,15 +78,17 @@ INST(Nop, nop, 0, 0) /* ResourceTypeBase */ /* ResourceType */ /* TextureTypeBase */ + // NOTE! TextureFlavor::Flavor is stored in 'other' bits for these types. /* TextureType */ - MANUAL_INST_RANGE(TextureType, 0x10000, TextureFlavor::Count) + INST(TextureType, TextureType, 0, 0) /* TextureSamplerType */ - MANUAL_INST_RANGE(TextureSamplerType, 0x20000, TextureFlavor::Count) + INST(TextureSamplerType, TextureSamplerType, 0, 0) /* GLSLImageType */ - MANUAL_INST_RANGE(GLSLImageType, 0x30000, TextureFlavor::Count) - INST_RANGE(TextureTypeBase, FirstTextureType, LastGLSLImageType) - INST_RANGE(ResourceType, FirstTextureType, LastGLSLImageType) - INST_RANGE(ResourceTypeBase, FirstTextureType, LastGLSLImageType) + INST(GLSLImageType, GLSLImageType, 0, 0) + INST_RANGE(TextureTypeBase, TextureType, GLSLImageType) + INST_RANGE(ResourceType, TextureType, GLSLImageType) + INST_RANGE(ResourceTypeBase, TextureType, GLSLImageType) + /* UntypedBufferResourceType */ INST(HLSLByteAddressBufferType, ByteAddressBuffer, 0, 0) @@ -382,7 +380,6 @@ PSEUDO_INST(Or) #undef PSEUDO_INST #undef PARENT -#undef MANUAL_INST_RANGE #undef INST_RANGE #undef INST diff --git a/source/slang/ir.h b/source/slang/ir.h index 15edb9b6c..739a38e84 100644 --- a/source/slang/ir.h +++ b/source/slang/ir.h @@ -38,23 +38,32 @@ enum : IROpFlags kIROpFlag_Parent = 1 << 0, }; +/* Bit usage of IROp is a follows + + MainOp | Pseudo | Other +Bit range: 0-7 | 8 | Remaining bits + +If an instruction is 'pseudo' (ie shouldn't appear in output IR), then the Pseudo bit is set - and 'Invalid' falls into +this category as well as all pseudo ops. +For doing range checks (for example for doing isa tests), the value is masked by kIROp_Mask_OpMask, such that the Other bits don't interfere. +The other bits can be used for storage for anything that needs to identify as a different 'op' or 'type'. It is currently +used currently for storing the TextureFlavor of a IRResourceTypeBase derived types for example. +*/ enum IROp : int32_t { #define INST(ID, MNEMONIC, ARG_COUNT, FLAGS) \ kIROp_##ID, -#define MANUAL_INST_RANGE(ID, START, COUNT) \ - kIROp_First##ID = START, kIROp_Last##ID = kIROp_First##ID + ((COUNT) - 1), - #include "ir-inst-defs.h" kIROpCount, - // We use the negative range of opcode values - // to encode "pseudo" instructions that should - // not appear in valid IR. + // We use the range 0x100 to 0x1ff set for pseudo/non main codes + // Instructions that should not appear in valid IR. - kIRPseduoOp_FirstPseudo = -1000, + + kIROp_Invalid = 0x100, ///< If bit set, then in pseudo/not normal space + kIRPseduoOp_FirstPseudo, #define INST(ID, MNEMONIC, ARG_COUNT, FLAGS) /* empty */ #define PSEUDO_INST(ID) kIRPseudoOp_##ID, @@ -68,10 +77,14 @@ enum IROp : int32_t #include "ir-inst-defs.h" - kIROp_Invalid = -1, - + kIROp_Mask_Shift = 9, + kIROp_Mask_OpMask = (int32_t(1) << kIROp_Mask_Shift) - 1, ///< Mask for regular ops + kIROp_Mask_OtherMask = ~kIROp_Mask_OpMask, }; +// True if op is pseudo (or invalid which is 'pseudo-like' at least in as so far as current behavior) +SLANG_FORCE_INLINE bool isPseudoOp(IROp op) { return (op & kIROp_Invalid) != 0; } + IROp findIROp(char const* name); // A logical operation/opcode in the IR @@ -405,8 +418,8 @@ struct IRInstList : IRInstListBase // Types -#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return op == kIROp_##NAME; } -#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp op) { return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; } +#define IR_LEAF_ISA(NAME) static bool isaImpl(IROp op) { return (kIROp_Mask_OpMask & op) == kIROp_##NAME; } +#define IR_PARENT_ISA(NAME) static bool isaImpl(IROp opIn) { const int op = (kIROp_Mask_OpMask & opIn); return op >= kIROp_First##NAME && op <= kIROp_Last##NAME; } #define SIMPLE_IR_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_LEAF_ISA(NAME) }; #define SIMPLE_IR_PARENT_TYPE(NAME, BASE) struct IR##NAME : IR##BASE { IR_PARENT_ISA(NAME) }; @@ -683,7 +696,7 @@ struct IRResourceTypeBase : IRType { TextureFlavor getFlavor() const { - return TextureFlavor(op & 0xFFFF); + return TextureFlavor((op >> kIROp_Mask_Shift) & 0xFFFF); } TextureFlavor::Shape GetBaseShape() const @@ -712,17 +725,17 @@ struct IRTextureTypeBase : IRResourceType struct IRTextureType : IRTextureTypeBase { - IR_PARENT_ISA(TextureType) + IR_LEAF_ISA(TextureType) }; struct IRTextureSamplerType : IRTextureTypeBase { - IR_PARENT_ISA(TextureSamplerType) + IR_LEAF_ISA(TextureSamplerType) }; struct IRGLSLImageType : IRTextureTypeBase { - IR_PARENT_ISA(GLSLImageType) + IR_LEAF_ISA(GLSLImageType) }; struct IRSamplerStateTypeBase : IRType diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 8f9335c0a..b0ec6cbf0 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -623,7 +623,7 @@ LoweredValInfo emitCallToDeclRef( { auto op = getIntrinsicOp(funcDecl, intrinsicOpModifier); - if (Int(op) < 0) + if (isPseudoOp(op)) { switch (op) { |
