Пример #1
0
 public ShaderOp DefaultConstructPrimitive(ShaderType resultType, FrontEndContext context)
 {
     if (resultType.mBaseType == OpType.Bool)
     {
         return(CreateConstantOp(resultType, false));
     }
     else if (resultType.mBaseType == OpType.Int)
     {
         if (ShaderType.IsSignedInt(resultType))
         {
             return(CreateConstantOp <int>(resultType, 0));
         }
         else
         {
             return(CreateConstantOp <uint>(resultType, 0u));
         }
     }
     else if (resultType.mBaseType == OpType.Float)
     {
         return(CreateConstantOp <float>(resultType, 0.0f));
     }
     else
     {
         var leafType      = ShaderType.FindLeafType(resultType);
         var leafTypeValue = DefaultConstructPrimitive(leafType, context);
         return(CompositeSplatConstruct(leafType, leafTypeValue, context));
     }
 }
Пример #2
0
        public ShaderConstantLiteral CreateConstantLiteralZero(ShaderType constantType)
        {
            switch (constantType.mBaseType)
            {
            case OpType.Bool:
                return(CreateConstantLiteral(false));

            case OpType.Int:
            {
                if (ShaderType.IsSignedInt(constantType))
                {
                    return(CreateConstantLiteral(0));
                }
                else
                {
                    return(CreateConstantLiteral(0u));
                }
            }

            case OpType.Float:
                return(CreateConstantLiteral(0.0f));

            default:
                throw new Exception();
            }
        }
Пример #3
0
        void Validate()
        {
            switch (mType.mBaseType)
            {
            case OpType.Bool:
            {
                if (!(mValue is bool value))
                {
                    throw new Exception();
                }
                break;
            }

            case OpType.Int:
            {
                if (mType.mParameters.Count < 2)
                {
                    return;
                }
                if (!ShaderType.IsSignedInt(mType))
                {
                    if (!(mValue is uint value))
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    if (!(mValue is int value))
                    {
                        throw new Exception();
                    }
                }
                break;
            }

            case OpType.Float:
            {
                if (!(mValue is float value))
                {
                    throw new Exception();
                }
                break;
            }
            }
        }
Пример #4
0
        public ShaderConstantLiteral CreateConstantLiteral(ShaderType constantType, string value)
        {
            var constantOp = new ShaderConstantLiteral();

            constantOp.mType = constantType;
            switch (constantType.mBaseType)
            {
            case OpType.Bool:
            {
                constantOp.mValue = bool.Parse(value);
                break;
            }

            case OpType.Int:
            {
                if (ShaderType.IsSignedInt(constantType))
                {
                    constantOp.mValue = int.Parse(value);
                }
                else
                {
                    constantOp.mValue = uint.Parse(value);
                }
                break;
            }

            case OpType.Float:
            {
                constantOp.mValue = float.Parse(value);
                break;
            }
            }

            mCurrentLibrary.GetOrCreateConstantLiteral(constantOp);
            return(constantOp);
        }