예제 #1
0
        public void Update(int techid, int passid, ISpread <DX11Resource <IDX11Geometry> > geoms)
        {
            this.techid = techid;
            this.passid = passid;
            this.UpdateTechnique();

            //Rebuild Layout
            this.DisposeLayouts();

            for (int i = 0; i < geoms.SliceCount; i++)
            {
                try
                {
                    if (pass.Description.Signature != null)
                    {
                        InputLayout layout = new InputLayout(this.context.Device, pass.Description.Signature, geoms[i][this.context].InputLayout);
                        this.layouts.Add(layout);
                        this.layoutvalid.Add(true);
                        this.layoutmsg.Add("OK");
                    }
                    else
                    {
                        this.layouts.Add(null);
                        this.layoutvalid.Add(true);
                        this.layoutmsg.Add("OK");
                    }
                }
                catch
                {
                    try
                    {
                        //Do bit of reflection work to get missing semantic
                        EffectShaderVariable vs = pass.VertexShaderDescription.Variable;
                        int    inputcount       = vs.GetShaderDescription(0).InputParameterCount;
                        string missingsemantics = "Geometry is missing semantics: ";

                        bool first = true;

                        for (int vip = 0; vip < inputcount; vip++)
                        {
                            ShaderParameterDescription sd = vs.GetInputParameterDescription(0, vip);

                            if (sd.SystemType == SystemValueType.Undefined) //Ignore SV semantics
                            {
                                bool found = false;
                                foreach (InputElement e in geoms[i][this.context].InputLayout)
                                {
                                    if (sd.SemanticName == e.SemanticName && sd.SemanticIndex == e.SemanticIndex)
                                    {
                                        found = true;
                                    }
                                }

                                if (!found)
                                {
                                    string sem = sd.SemanticIndex == 0 ? "" : sd.SemanticIndex.ToString();
                                    if (first)
                                    {
                                        first = false;
                                    }
                                    else
                                    {
                                        missingsemantics += " : ";
                                    }
                                    missingsemantics += sd.SemanticName + sem;
                                }
                            }
                        }

                        this.layouts.Add(null);
                        this.layoutvalid.Add(false);
                        this.layoutmsg.Add(missingsemantics);
                    }
                    catch (Exception ex)
                    {
                        //Just in case
                        this.layouts.Add(null);
                        this.layoutvalid.Add(false);
                        this.layoutmsg.Add(ex.Message);
                    }
                }
            }
        }
예제 #2
0
        public static InputElement[] GetStreamOutputLayout(this EffectPass pass, out int vertexsize)
        {
            vertexsize = 0;
            if (pass.GeometryShaderDescription.Variable == null)
            {
                return(new InputElement[0]);
            }
            else
            {
                EffectShaderVariable gs = pass.GeometryShaderDescription.Variable;
                int outputcount         = gs.GetShaderDescription(0).OutputParameterCount;

                InputElement[] elems = new InputElement[outputcount];

                int offset = 0;

                for (int vip = 0; vip < outputcount; vip++)
                {
                    ShaderParameterDescription sd = gs.GetOutputParameterDescription(0, vip);
                    int componentcount            = 0;

                    if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentX))
                    {
                        componentcount++;
                    }
                    if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentY))
                    {
                        componentcount++;
                    }
                    if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentZ))
                    {
                        componentcount++;
                    }
                    if (sd.UsageMask.HasFlag(RegisterComponentMaskFlags.ComponentW))
                    {
                        componentcount++;
                    }

                    int vsize = 4 * componentcount;

                    string fmt = "";
                    if (componentcount == 1)
                    {
                        fmt = "R32_";
                    }
                    if (componentcount == 2)
                    {
                        fmt = "R32G32_";
                    }
                    if (componentcount == 3)
                    {
                        fmt = "R32G32B32_";
                    }
                    if (componentcount == 4)
                    {
                        fmt = "R32G32B32A32_";
                    }

                    switch (sd.ComponentType)
                    {
                    case RegisterComponentType.Float32:
                        fmt += "Float";
                        break;

                    case RegisterComponentType.SInt32:
                        fmt += "SInt";
                        break;

                    case RegisterComponentType.UInt32:
                        fmt += "UInt";
                        break;
                    }

                    Format f = (Format)Enum.Parse(typeof(Format), fmt);

                    InputElement elem = new InputElement(sd.SemanticName, (int)sd.SemanticIndex, f, offset, 0);

                    elems[vip] = elem;

                    offset     += vsize;
                    vertexsize += vsize;
                }

                return(elems);
            }
        }
예제 #3
0
        protected override List <CompilerError> VerifyShader(string file, DX11Effect effect)
        {
            List <CompilerError> errors = new List <CompilerError>();

            if (effect.DefaultEffect.Description.TechniqueCount == 0)
            {
                errors.Add(new CompilerError(file, 0, 0, "", "Effect Has No techniques"));
                return(errors);
            }


            //Verify techniques
            for (int i = 0; i < effect.DefaultEffect.Description.TechniqueCount; i++)
            {
                EffectTechnique tech = effect.DefaultEffect.GetTechniqueByIndex(i);

                if (tech.Description.PassCount == 0)
                {
                    errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " has no passes"));
                    return(errors);
                }
                else
                {
                    for (int p = 0; p < tech.Description.PassCount; p++)
                    {
                        EffectPass pass = tech.GetPassByIndex(p);

                        if (!this.ComputeOrPixelOnly(pass))
                        {
                            errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " : Pass : "******" Must be pixel only or compute only"));
                        }
                        else
                        {
                            //Manually validate layout for pixelshader
                            if (this.PixelOnly(pass))
                            {
                                EffectShaderVariable ps = pass.PixelShaderDescription.Variable;
                                int inputcount          = ps.GetShaderDescription(0).InputParameterCount;

                                bool hassvpos = false;
                                bool hasuv    = false;

                                for (int ip = 0; ip < inputcount; ip++)
                                {
                                    ShaderParameterDescription sd = ps.GetInputParameterDescription(0, ip);
                                    if (sd.SystemType == SystemValueType.Position)
                                    {
                                        hassvpos = true;
                                    }
                                    if (sd.SemanticName == "TEXCOORD")
                                    {
                                        hasuv = true;
                                    }
                                }

                                if (!(hassvpos && hasuv) && inputcount == 2)
                                {
                                    errors.Add(new CompilerError(file, 0, 0, "", "Technique: " + tech.Description.Name + " : Pass : "******" Must be SV_Position and TEXCOORD0 as input"));
                                }
                            }
                        }
                    }
                }
            }

            return(errors);
        }