public IEmitVal EmitAttributeRef( MidAttributeDecl decl, IEmitBlock block, EmitEnv env) { if (env.ContainsKey(decl)) { return(env.Lookup(decl, block)); } IEmitVal attributeVal = null; if (decl.Exp != null) { attributeVal = block.Temp( decl.Name.ToString(), EmitExp(decl.Exp, block, env)); } else { // \todo: This is a *huge* hack, // since we use @Constant attributes // to make various D3D constants visible... :( attributeVal = block.BuiltinApp( EmitType(decl.Type, env), decl.Name.ToString(), null); } env.Insert(decl, (b) => attributeVal); return(attributeVal); }
public void ApplyTo(IEmitBlock block) { foreach (var a in _actions) { a(block); } }
public static IEmitVal Array( this IEmitBlock block, IEmitType elementType, IEnumerable <IEmitVal> elements) { return(block.Array(elementType, elements.ToArray())); }
public IEmitVal EmitExp( MidExp exp, IEmitBlock block, EmitEnv env) { return(EmitExpImpl((dynamic)exp, block, env)); }
private IEmitVal EmitExpImpl( MidAttributeRef attrRef, IEmitBlock block, EmitEnv env) { return(EmitAttributeRef(attrRef.Decl, block, env)); }
private IEmitVal EmitExpImpl( MidLit <float> lit, IEmitBlock block, EmitEnv env) { return(_target.LiteralF32(lit.Value)); }
private IEmitVal EmitExpImpl( MidLit <bool> lit, IEmitBlock block, EmitEnv env) { return(_target.LiteralBool(lit.Value)); }
private IEmitVal EmitExpImpl( MidBuiltinApp app, IEmitBlock block, EmitEnv env) { var template = app.Decl.GetTemplate(Target.TargetName); if (template == null) { Diagnostics.Add( Severity.Error, new SourceRange(), "No builtin function implementation defined for \"{0}\" for target \"{1}\"", app.Decl.Name, Target.TargetName); return(block.Local("error", EmitType(app.Type, env))); } var args = (from a in app.Args select EmitExp(a, block, env)).ToArray(); return(block.BuiltinApp( EmitType(app.Type, env), template, args)); }
private IEmitVal EmitExpImpl( MidVarRef exp, IEmitBlock block, EmitEnv env) { return(env.Lookup(exp.Var, block)); }
private void EmitShaderBinds( IEmitBlock block, string prefix, EmitContextHLSL hlslContext) { block.CallCOM( SubmitContext, "ID3D11DeviceContext", string.Format("{0}SetConstantBuffers", prefix), block.LiteralU32(0), block.LiteralU32(1), block.GetArrow(SubmitThis, EmitPass.CBField).GetAddress()); var resources = hlslContext.ShaderResources.ToArray(); var resourceCount = resources.Length; if (resourceCount != 0) { var resourceVals = (from r in resources select EmitContext.EmitExp(r, block, SubmitEnv)).ToArray(); var resourcesVal = block.Temp( string.Format("{0}Resources", prefix), block.Array( EmitTarget.GetOpaqueType("ID3D11ShaderResourceView*"), resourceVals)); block.CallCOM( SubmitContext, "ID3D11DeviceContext", string.Format("{0}SetShaderResources", prefix), block.LiteralU32(0), block.LiteralU32((UInt32)resourceCount), resourcesVal.GetAddress()); } var samplers = hlslContext.SamplerStates.ToArray(); var samplerCount = samplers.Length; if (samplerCount != 0) { var samplerVals = (from s in samplers select EmitContext.EmitExp(s, block, SubmitEnv)).ToArray(); var samplersVal = block.Temp( string.Format("{0}Samplers", prefix), block.Array( EmitTarget.GetOpaqueType("ID3D11SamplerState*"), samplerVals)); block.CallCOM( SubmitContext, "ID3D11DeviceContext", string.Format("{0}SetSamplers", prefix), block.LiteralU32(0), block.LiteralU32((UInt32)samplerCount), samplersVal.GetAddress()); } }
public static IEmitVal Enum32( this IEmitBlock block, string type, string name, Enum val) { return(block.Enum32(type, name, Convert.ToUInt32(val))); }
public static IEmitVal Enum32( this IEmitBlock block, Enum val) { return(block.Enum32( val.GetType().Name, val.ToString(), Convert.ToUInt32(val))); }
public IEmitVal EmitAttributeRef( MidAttributeWrapperDecl wrapper, IEmitBlock block, EmitEnv env) { return(EmitAttributeRef( wrapper.Attribute, block, env)); }
private IEnumerable <IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, StructInfo info) { foreach (var f in info.Fields) { var fieldElements = (DeclareInputElements( block, name, f.Info)).ToArray(); foreach (var fe in fieldElements) { yield return(fe); } } }
private IEnumerable <IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, InputElementInfo info) { _inputElementCount++; yield return(block.Struct( "D3D11_INPUT_ELEMENT_DESC", block.LiteralString(string.Format("USER_{0}", name)), block.LiteralU32(0), info.Format, block.LiteralU32((UInt32)info.InputSlotIndex), block.LiteralU32((UInt32)info.ByteOffset), info.Index.InputSlotClass, block.LiteralU32((UInt32)info.Index.StepRate))); }
private IEnumerable <IEmitVal> DeclareInputElements( IEmitBlock block, string name, AttributeInfo info) { try { return(DeclareInputElementsImpl( block, name, (dynamic)info)); } catch (D3D11InputAssemblerOperationTooComplex) { return(new IEmitVal[] { }); } }
private IEmitVal EmitExpImpl( MidLetExp exp, IEmitBlock block, EmitEnv env) { var letVar = exp.Var; var letVal = EmitExp(exp.Exp, block, env); var letEnv = new EmitEnv(env); letEnv.Insert(letVar, (b) => letVal); var bodyVal = EmitExp(exp.Body, block, letEnv); return(bodyVal); }
public IEmitVal Lookup( MidVar var, IEmitBlock block) { Func <IEmitBlock, IEmitVal> generator; if (_vars.TryGetValue(var, out generator)) { return(generator(block)); } if (_outer != null) { return(_outer.Lookup(var, block)); } throw new KeyNotFoundException(); }
public IEmitVal Lookup( Mid.MidAttributeDecl attribute, IEmitBlock block) { Func <IEmitBlock, IEmitVal> generator; if (_attributes.TryGetValue(attribute, out generator)) { return(generator(block)); } if (_outer != null) { return(_outer.Lookup(attribute, block)); } throw new KeyNotFoundException(); }
private IEnumerable <IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, AttributeInfo info) { // Default behavior is to emit an error: this value cannot (apparently) // be plumbed from the IA to the VS. // // We detect IA_VertexID and IA_IntanceID as special cases, since // they are so pervasive: if (info == _info[_vertexIDAttr]) { Diagnostics.Add( Severity.Error, info.Range, "The built-in attribute IA_VertexID cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); Diagnostics.Add( Severity.Info, info.Range, "Consider using the equivalent VS-stage attribute VS_VertexID"); } else if (info == _info[_instanceIDAttr]) { Diagnostics.Add( Severity.Error, info.Range, "The built-in attribute IA_InstanceID cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); Diagnostics.Add( Severity.Info, info.Range, "Consider using the equivalent VS-stage attribute VS_InstanceID"); } else { Diagnostics.Add( Severity.Error, info.Range, "This value cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); } throw new D3D11InputAssemblerOperationTooComplex(); }
public static IEmitVal LiteralF32(this IEmitBlock block, float val) { return(block.Target.LiteralF32(val)); }
public static IEmitVal LiteralS32(this IEmitBlock block, Int32 val) { return(block.Target.LiteralS32(val)); }
public static IEmitVal LiteralBool(this IEmitBlock block, bool val) { return(block.Target.LiteralBool(val)); }
private IEnumerable<IEmitVal> DeclareInputElements( IEmitBlock block, string name, AttributeInfo info) { try { return DeclareInputElementsImpl( block, name, (dynamic)info); } catch (D3D11InputAssemblerOperationTooComplex) { return new IEmitVal[] { }; } }
private IEnumerable<IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, AttributeInfo info) { // Default behavior is to emit an error: this value cannot (apparently) // be plumbed from the IA to the VS. // // We detect IA_VertexID and IA_IntanceID as special cases, since // they are so pervasive: if (info == _info[_vertexIDAttr]) { Diagnostics.Add( Severity.Error, info.Range, "The built-in attribute IA_VertexID cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); Diagnostics.Add( Severity.Info, info.Range, "Consider using the equivalent VS-stage attribute VS_VertexID"); } else if (info == _info[_instanceIDAttr]) { Diagnostics.Add( Severity.Error, info.Range, "The built-in attribute IA_InstanceID cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); Diagnostics.Add( Severity.Info, info.Range, "Consider using the equivalent VS-stage attribute VS_InstanceID"); } else { Diagnostics.Add( Severity.Error, info.Range, "This value cannot be plumbed from the D3D11 Input Assembler (IA) stage to the Vertex Shader (VS)"); } throw new D3D11InputAssemblerOperationTooComplex(); }
private IEnumerable<IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, StructInfo info) { foreach (var f in info.Fields) { var fieldElements = (DeclareInputElements( block, name, f.Info)).ToArray(); foreach (var fe in fieldElements) yield return fe; } }
private IEnumerable<IEmitVal> DeclareInputElementsImpl( IEmitBlock block, string name, InputElementInfo info) { _inputElementCount++; yield return block.Struct( "D3D11_INPUT_ELEMENT_DESC", block.LiteralString(string.Format("USER_{0}", name)), block.LiteralU32(0), info.Format, block.LiteralU32((UInt32) info.InputSlotIndex), block.LiteralU32((UInt32) info.ByteOffset), info.Index.InputSlotClass, block.LiteralU32((UInt32) info.Index.StepRate)); }
public static IEmitVal Enum32(this IEmitBlock block, string type, string name, UInt32 val) { return(block.Target.Enum32(type, name, val)); }
protected IEmitVal EmitExp(MidExp midExp, IEmitBlock block, EmitEnv env) { return EmitContext.EmitExp(midExp, block, env); }
public void ApplyTo(IEmitBlock block) { foreach (var a in _actions) a(block); }
public static IEmitVal CastRawPointer( this IEmitBlock block, IEmitVal val) { return(block.CastRawPointer(val, null)); }
protected IEmitVal EmitExp(MidExp midExp, IEmitBlock block, EmitEnv env) { return(EmitContext.EmitExp(midExp, block, env)); }