public UnaryOp(UnaryOpKind op, DestRegister dest, SrcRegister src) { this.op = op; this.dest = dest; this.src = src; }
public TernaryOp(TernaryOpKind op, DestRegister dest, SrcRegister src1, SrcRegister src2, SrcRegister src3) { this.op = op; this.dest = dest; this.src1 = src1; this.src2 = src2; this.src3 = src3; }
public TexLoad(DestRegister dest, SrcRegister sampler, SrcRegister tex) { this.dest = dest; this.sampler = sampler; this.tex = tex; }
public DefVar(TextureKind kind, DestRegister reg) { this.kind = kind; this.reg = reg; }
public Mov(DestRegister dest, SrcRegister src) { this.dest = dest; this.src = src; }
internal void StoreValue(DestRegister dst) { var dest = GetReg (dst.Kind, dst.Number); if (dst.WriteMask != 0xF) { //return var mask = GetMask (dst.WriteMask); //src & mask ilgen.Emit (OpCodes.Ldloc, mask); ilgen.Emit (OpCodes.Call, typeof (Vector4f).GetMethod ("op_BitwiseAnd")); //mask.AndNot (dest) ilgen.Emit (OpCodes.Ldloc, mask); ilgen.Emit (OpCodes.Ldloc, dest); ilgen.Emit (OpCodes.Call, typeof (VectorOperations).GetMethod ("AndNot", new Type[] { typeof (Vector4f), typeof (Vector4f)})); //(mask & src) | mask.AndNot (dest); ilgen.Emit (OpCodes.Call, typeof (Vector4f).GetMethod ("op_BitwiseOr")); } ilgen.Emit (OpCodes.Stloc, dest); }
public BinaryOp(BinOpKind op, DestRegister dest, SrcRegister src1, SrcRegister src2) { this.op = op; this.dest = dest; this.src1 = src1; this.src2 = src2; }
internal void DefineVar(TextureKind kind, DestRegister reg) { switch (reg.Kind) { case RegKind.Texture: if (tex0 != null) throw new Exception ("Cannot handle multiple texture registers"); if (reg.Number != 0) throw new Exception ("Only one texture register supported"); //FIXME since we only support 2d textures, is this the right thing? if (reg.WriteMask != DestRegister.MakeMask (true, true, false, false)) throw new Exception ("Cannot handle a texture register with a write mask different than rg"); tex0 = DeclareAndZeroLocal (typeof (Vector4f), "tex_" + reg.Number); //FIXME using a pair of floats would be faster break; case RegKind.SamplerState: if (kind != TextureKind.Text2d) throw new Exception ("Cannot handle non text2d samplers."); if (samplerMap.ContainsKey (reg.Number)) throw new Exception (String.Format ("sampler {0} already defined", reg.Number)); LocalBuilder lb = DeclareLocal (typeof (Sampler), "sampler_" + reg.Number); samplerMap [reg.Number] = lb; ilgen.Emit (OpCodes.Ldarg_0); ilgen.Emit (OpCodes.Ldc_I4, reg.Number); ilgen.Emit (OpCodes.Call, typeof (ShaderData).GetMethod ("GetSampler")); ilgen.Emit (OpCodes.Stloc, lb); break; } }
internal void StoreValue(DestRegister dst, Vector4f value) { Vector4f reg = GetReg (dst); if (dst.WriteMask != 0xF) { if ((dst.WriteMask & 0x1) == 0x1) reg.X = value.X; if ((dst.WriteMask & 0x2) == 0x2) reg.Y = value.Y; if ((dst.WriteMask & 0x4) == 0x4) reg.Z = value.Z; if ((dst.WriteMask & 0x8) == 0x8) reg.W = value.W; } else reg = value; switch (dst.Kind) { case RegKind.Temp: temp [dst.Number] = reg; break; case RegKind.ColorOut: colorOut [dst.Number] = reg; break; default: throw new Exception ("can't handle store to " + dst.Kind); } }
DestRegister ParseDestReg() { int val = 0; if (!Read (ref val)) throw new Exception ("can't read dest register"); DestRegister reg = new DestRegister (val); if (reg.Number >= 32) throw new Exception ("Invalid dest reg number " + reg.Number); return reg; }
void VisitDestReg(DestRegister dest) { VisitReg (dest); if (dest.WriteMask != 0xF) writeMasks.Add (dest.WriteMask); }
void ApplyMathScalarUnaryToElement(DestRegister dest, SrcRegister src, string func, string element) { ilgen.Emit (OpCodes.Ldloca, GetReg (dest.Kind, dest.Number)); LoadScalar (src); ilgen.Emit (OpCodes.Call, typeof (Math).GetMethod (func)); ilgen.Emit (OpCodes.Conv_R4); ilgen.Emit (OpCodes.Call, typeof (Vector4f).GetMethod ("set_" + element)); }