Beispiel #1
0
        public ShaderOp CreateConstant(ConstantOpKey key)
        {
            ShaderOp op = new ShaderOp();

            mConstantOps.Add(key, op);
            return(op);
        }
Beispiel #2
0
        public ShaderOp CreateConstantOp(ShaderType constantType, ShaderConstantLiteral constantLiteral)
        {
            var constantOpKey = new ConstantOpKey(constantLiteral);
            var constantOp    = mCurrentLibrary.FindConstant(constantOpKey);

            if (constantOp == null)
            {
                constantOp = mCurrentLibrary.FindOrCreateConstant(constantOpKey);
                // Handle bools specially (they're special ops in spirv)
                if (constantType.mBaseType == OpType.Bool)
                {
                    var boolVal = (bool)constantLiteral.mValue;
                    if (boolVal == true)
                    {
                        InitializeOp(constantOp, OpInstructionType.OpConstantTrue, constantType, null);
                    }
                    else
                    {
                        InitializeOp(constantOp, OpInstructionType.OpConstantFalse, constantType, null);
                    }
                }
                else
                {
                    InitializeOp(constantOp, OpInstructionType.OpConstant, constantType, new List <IShaderIR> {
                        constantLiteral
                    });
                }
            }
            return(constantOp);
        }
Beispiel #3
0
        public ShaderOp FindConstant(ConstantOpKey key, bool checkDependencies = true)
        {
            var result = mConstantOps.GetValueOrDefault(key);

            if (result == null && checkDependencies && mDependencies != null)
            {
                result = mDependencies.FindConstant(key, checkDependencies);
            }
            return(result);
        }
Beispiel #4
0
        public ShaderOp FindOrCreateConstant(ConstantOpKey key, bool checkDependencies = true)
        {
            var result = FindConstant(key, checkDependencies);

            if (result == null)
            {
                result = CreateConstant(key);
            }
            return(result);
        }
Beispiel #5
0
 public ShaderOp FindConstant(ConstantOpKey key, bool checkDependencies = true)
 {
     foreach (var library in this)
     {
         var result = library.FindConstant(key, checkDependencies);
         if (result != null)
         {
             return(result);
         }
     }
     return(null);
 }
Beispiel #6
0
        //---------------------------------------------------------------Constant Literals
        public ShaderConstantLiteral GetOrCreateConstantLiteral(ShaderConstantLiteral constantLiteral)
        {
            var key    = new ConstantOpKey(constantLiteral);
            var result = mConstantLiterals.GetValueOrDefault(key);

            if (result == null)
            {
                result = constantLiteral;
                mConstantLiterals.Add(key, result);
            }
            return(result);
        }
Beispiel #7
0
        public ShaderOp CreateConstantOp(ShaderType constantType, bool constantLiteral)
        {
            var constantOpKey = new ConstantOpKey(mCurrentLibrary.FindType(new TypeKey(typeof(bool))), constantLiteral);
            var constantOp    = mCurrentLibrary.FindConstant(constantOpKey);

            if (constantOp == null)
            {
                constantOp = mCurrentLibrary.FindOrCreateConstant(constantOpKey);
                if (constantLiteral == true)
                {
                    InitializeOp(constantOp, OpInstructionType.OpConstantTrue, constantType, null);
                }
                else
                {
                    InitializeOp(constantOp, OpInstructionType.OpConstantFalse, constantType, null);
                }
            }
            return(constantOp);
        }
Beispiel #8
0
 //---------------------------------------------------------------Constants
 public bool AddConstant(ConstantOpKey key, ShaderOp shaderOp)
 {
     return(mConstantOps.TryAdd(key, shaderOp));
 }