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); }
public ShaderConstantLiteral CreateConstantLiteral <T>(ShaderType literalType, T value) { var constantOp = new ShaderConstantLiteral(); constantOp.mType = literalType; constantOp.mValue = value; constantOp = mCurrentLibrary.GetOrCreateConstantLiteral(constantOp); return(constantOp); }
//---------------------------------------------------------------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); }
void WriteConstantLiteral(ShaderConstantLiteral constantLiteral) { if (constantLiteral.mType.mBaseType == OpType.Int) { if (constantLiteral.mValue is int intValue) { mWriter.Write(intValue); } else if (constantLiteral.mValue is uint uintValue) { mWriter.Write(uintValue); } else { throw new Exception(); } } else { throw new Exception(); } }
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); }
public void Visit(ShaderConstantLiteral constantLiteral) { Visit(constantLiteral.mType); }
public ConstantOpKey(ShaderConstantLiteral constant) { mType = constant.mType; mValue = constant.mValue; Validate(); }