Example #1
0
 private static uint DecodeLen(SpvOp op, uint len)
 {
     len++;
     if (op == SpvOp.VectorShuffle)
     {
         len += 4;
     }
     if (op == SpvOp.VectorShuffleCompact)
     {
         len += 4;
     }
     if (op == SpvOp.Decorate)
     {
         len += 2;
     }
     if (op == SpvOp.Load)
     {
         len += 3;
     }
     if (op == SpvOp.AccessChain)
     {
         len += 3;
     }
     return(len);
 }
Example #2
0
        private static uint DecodeLen(SpvOp op, uint len)
        {
            len++;
            switch (op)
            {
            case SpvOp.VectorShuffle:
                len += 4;
                break;

            case SpvOp.VectorShuffleCompact:
                len += 4;
                break;

            case SpvOp.Decorate:
                len += 2;
                break;

            case SpvOp.Load:
                len += 3;
                break;

            case SpvOp.AccessChain:
                len += 3;
                break;
            }
            return(len);
        }
Example #3
0
 public static bool OpVarRest(this SpvOp _this)
 {
     if (_this < 0 || _this >= SpvOp.KnownOpsCount)
     {
         return(false);
     }
     return(OpData.SpirvOpData[(int)_this].varrest != 0);
 }
Example #4
0
 public static int OpDeltaFromResult(this SpvOp _this)
 {
     if (_this < 0 || _this >= SpvOp.KnownOpsCount)
     {
         return(0);
     }
     return(OpData.SpirvOpData[(int)_this].deltaFromResult);
 }
Example #5
0
 public static bool OpHasType(this SpvOp _this)
 {
     if (_this < 0 || _this >= SpvOp.KnownOpsCount)
     {
         return(false);
     }
     return(OpData.SpirvOpData[(int)_this].hasType != 0);
 }
Example #6
0
 public static bool OpDebugInfo(this SpvOp _this)
 {
     return
         (_this == SpvOp.SourceContinued ||
          _this == SpvOp.Source ||
          _this == SpvOp.SourceExtension ||
          _this == SpvOp.Name ||
          _this == SpvOp.MemberName ||
          _this == SpvOp.String ||
          _this == SpvOp.Line ||
          _this == SpvOp.NoLine ||
          _this == SpvOp.ModuleProcessed);
 }
Example #7
0
        private static bool ReadLengthOp(BinaryReader input, out uint len, out SpvOp op)
        {
            len = default;
            op  = default;
            if (!ReadVarint(input, out uint value))
            {
                return(false);
            }
            len = ((value >> 20) << 4) | ((value >> 4) & 0xF);
            op  = (SpvOp)(((value >> 4) & 0xFFF0) | (value & 0xF));

            op  = RemapOp(op);
            len = DecodeLen(op, len);
            return(true);
        }
Example #8
0
 /// <summary>
 /// Remap most common Op codes (Load, Store, Decorate, VectorShuffle etc.) to be in &lt; 16 range, for
 /// more compact varint encoding. This basically swaps rarely used op values that are &lt; 16 with the
 /// ones that are common.
 /// </summary>
 private static SpvOp RemapOp(SpvOp op)
 {
     // 0: 24%
     if (op == SpvOp.Decorate)
     {
         return(SpvOp.Nop);
     }
     if (op == SpvOp.Nop)
     {
         return(SpvOp.Decorate);
     }
     // 1: 17%
     if (op == SpvOp.Load)
     {
         return(SpvOp.Undef);
     }
     if (op == SpvOp.Undef)
     {
         return(SpvOp.Load);
     }
     // 2: 9%
     if (op == SpvOp.Store)
     {
         return(SpvOp.SourceContinued);
     }
     if (op == SpvOp.SourceContinued)
     {
         return(SpvOp.Store);
     }
     // 3: 7.2%
     if (op == SpvOp.AccessChain)
     {
         return(SpvOp.Source);
     }
     if (op == SpvOp.Source)
     {
         return(SpvOp.AccessChain);
     }
     // 4: 5.0%
     // Name - already small enum value - 5: 4.4%
     // MemberName - already small enum value - 6: 2.9%
     if (op == SpvOp.VectorShuffle)
     {
         return(SpvOp.SourceExtension);
     }
     if (op == SpvOp.SourceExtension)
     {
         return(SpvOp.VectorShuffle);
     }
     // 7: 4.0%
     if (op == SpvOp.MemberDecorate)
     {
         return(SpvOp.String);
     }
     if (op == SpvOp.String)
     {
         return(SpvOp.MemberDecorate);
     }
     // 8: 0.9%
     if (op == SpvOp.Label)
     {
         return(SpvOp.Line);
     }
     if (op == SpvOp.Line)
     {
         return(SpvOp.Label);
     }
     // 9: 3.9%
     if (op == SpvOp.Variable)
     {
         return((SpvOp)9);
     }
     if (op == (SpvOp)9)
     {
         return(SpvOp.Variable);
     }
     // 10: 3.9%
     if (op == SpvOp.FMul)
     {
         return(SpvOp.Extension);
     }
     if (op == SpvOp.Extension)
     {
         return(SpvOp.FMul);
     }
     // 11: 2.5%
     // ExtInst - already small enum value - 12: 1.2%
     // VectorShuffleCompact - already small enum value - used for compact shuffle encoding
     if (op == SpvOp.FAdd)
     {
         return(SpvOp.ExtInstImport);
     }
     if (op == SpvOp.ExtInstImport)
     {
         return(SpvOp.FAdd);
     }
     // 14: 2.2%
     if (op == SpvOp.TypePointer)
     {
         return(SpvOp.MemoryModel);
     }
     if (op == SpvOp.MemoryModel)
     {
         return(SpvOp.TypePointer);
     }
     // 15: 1.1%
     if (op == SpvOp.FNegate)
     {
         return(SpvOp.EntryPoint);
     }
     if (op == SpvOp.EntryPoint)
     {
         return(SpvOp.FNegate);
     }
     return(op);
 }