Example #1
0
 public DX11ShaderData(DX11RenderContext context, DX11Effect effect)
 {
     this.context = context;
     this.passid  = 0;
     this.techid  = 0;
     this.SetEffect(effect);
 }
Example #2
0
        private void HandleConfigDefinesChangeOnStartup(IDiffSpread <string> spread)
        {
            if (FConfigShader[0] != "" && !configWritten)
            {
                DX11ShaderInclude  FIncludeHandler = new DX11ShaderInclude();
                List <ShaderMacro> sms             = new List <ShaderMacro>();

                if (FConfigDefines[0] != "")
                {
                    string[] defines = FConfigDefines[0].Split(",".ToCharArray());
                    for (int i = 0; i < defines.Length; i++)
                    {
                        try
                        {
                            string[] s = defines[i].Split("=".ToCharArray());

                            if (s.Length == 2)
                            {
                                ShaderMacro sm = new ShaderMacro();
                                sm.Name  = s[0];
                                sm.Value = s[1];
                                sms.Add(sm);
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                FShader = DX11Effect.FromString(FConfigShader[0], FIncludeHandler, sms.ToArray());
                this.SetShader(FShader, !ShaderCreatedByConfig);
                ShaderCreatedByConfig = true;
            }
        }
Example #3
0
            public QuadShaderDeviceData(DX11RenderContext context)
            {
                string     basepath = "VVVV.DX11.Nodes.effects.quad.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);

                quadshader      = new DX11ShaderInstance(context, effect);
                texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource();
                samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler();

                Quad quad = new Quad();

                quad.Size = new Vector2(1.0f);

                quadgeometry = context.Primitives.QuadNormals(quad);

                quadlayouts = new List <InputLayout>();
                for (int i = 0; i < 4; i++)
                {
                    InputLayout layout;
                    quadshader.SelectTechnique(i);

                    bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout);
                    quadlayouts.Add(layout);
                }
            }
Example #4
0
        public void SetEffect(DX11Effect shader)
        {
            //Create
            if (this.shader == null)
            {
                this.shader = shader;

                if (shader.IsCompiled)
                {
                    this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode);
                    this.UpdateTechnique();
                }
            }
            else
            {
                if (shader.IsCompiled)
                {
                    //Update shader
                    if (shader != this.shader)
                    {
                        //Dispose old effect if applicable
                        this.shader = shader;
                        if (this.shaderinstance != null)
                        {
                            this.shaderinstance.Dispose();
                        }
                        this.shaderinstance = new DX11ShaderInstance(this.context, shader.ByteCode);
                        this.UpdateTechnique();

                        this.DisposeLayouts();
                    }
                }
            }
        }
Example #5
0
        void shadernode_WantRecompile(object sender, EventArgs e)
        {
            IDX11ShaderNodeWrapper wrp = (IDX11ShaderNodeWrapper)sender;
            FIncludeHandler.ParentPath = Path.GetDirectoryName(wrp.Source.Filename);
            string code = File.ReadAllText(wrp.Source.Filename);

            var shader = DX11Effect.FromString(code, FIncludeHandler,wrp.Macros);
            wrp.SetShader(shader, false);
        }
Example #6
0
        public void SetShader(DX11Effect shader, bool isnew)
        {
            if (shader.IsCompiled)
            {
                this.FShader = shader;
                this.varmanager.SetShader(shader);
                this.shaderVariableCache.Clear();
                this.deviceshaderdata.Dispose();
                this.currentEffectOut[0] = shader;
            }
            //Only set technique if new, otherwise do it on update/evaluate
            if (isnew)
            {
                string defaultenum;
                if (shader.IsCompiled)
                {
                    defaultenum = shader.TechniqueNames[0];
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.CreateShaderPins();
                }
                else
                {
                    defaultenum = "";
                    this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]);
                }

                //Create Technique enum pin

                /*InputAttribute inAttr = new InputAttribute("Technique");
                *  inAttr.EnumName = this.TechniqueEnumId;
                *  inAttr.DefaultEnumEntry = defaultenum;
                *  inAttr.Order = 1000;
                *  this.FInTechnique = this.FFactory.CreateDiffSpread<EnumEntry>(inAttr);
                *
                *  this.FoutCS.AssignFrom(this.varmanager.GetCustomData());*/

                if (shader.TechniqueNames != null)
                {
                    this.techniqueindex   = Array.IndexOf(shader.TechniqueNames, FInTechnique[0].Name);
                    this.techniquechanged = true;
                }
            }
            else
            {
                if (shader.IsCompiled)
                {
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.UpdateShaderPins();
                    this.FoutCS.AssignFrom(this.varmanager.GetCustomData());
                }
            }
            this.FInvalidate = true;
        }
Example #7
0
        private void HandleConfigShaderChangeOnStartup(IDiffSpread <string> spread)
        {
            if (FConfigShader[0] != "" && !configWritten)
            {
                DX11ShaderInclude  FIncludeHandler = new DX11ShaderInclude();
                List <ShaderMacro> sms             = new List <ShaderMacro>();

                FShader = DX11Effect.FromString(FConfigShader[0], FIncludeHandler, sms.ToArray());
                this.SetShader(FShader, true);
                ShaderCreatedByConfig = true;
            }
        }
        private void ParseErrors(string e, FXProject project, DX11Effect shader)
        {
            string filePath        = project.LocalPath;
            var    compilerResults = ShaderCompilerErrorParser.ParseCompilerResult(e, project.LocalPath, filePath);

            //Add some extra error from reflection
            if (shader.IsCompiled)
            {
                compilerResults.Errors.AddRange(this.VerifyShader(project.LocalPath, shader).ToArray());
            }

            project.CompilerResults = compilerResults;
        }
Example #9
0
        public override void Initialize()
        {
            base.Initialize();

            var effect = DX11Effect.CompileFromString(@"
struct VS_IN
{
	float4 PosO : POSITION;
	float2 TexCd : TEXCOORD0;
};

struct vs2ps
{
    float4 PosWVP: SV_POSITION;
    float2 TexCd: TEXCOORD0;
};

cbuffer cbTest : register(b0)
{
    float4 offset;
};

Texture2D tex;

SamplerState linSamp
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};


vs2ps VS(VS_IN input)
{
    vs2ps Out = (vs2ps)0;
    Out.PosWVP  =input.PosO + offset;
    Out.TexCd = input.TexCd + tex.Load(int3(0,0,0));
    return Out;
}

technique10 Render
{
	pass P0
	{
		SetVertexShader( CompileShader( vs_4_0, VS() ) );
	}
}");

            this.shader = new EffectInstance(this.Device, effect);
        }
Example #10
0
        public override void SetShader(DX11Effect shader, bool isnew, string fileName)
        {
            FOutPath.SliceCount = 1;
            FOutPath[0]         = fileName;

            if (shader.IsCompiled)
            {
                this.FShader = shader;
                this.varmanager.SetShader(shader);
                this.shaderVariableCache.Clear();
                this.deviceshaderdata.Dispose();
                this.currentEffectOut[0] = shader;
            }

            //Only set technique if new, otherwise do it on update/evaluate
            if (isnew)
            {
                string defaultenum;
                if (shader.IsCompiled)
                {
                    defaultenum = shader.TechniqueNames[0];
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.CreateShaderPins();
                }
                else
                {
                    defaultenum = "";
                    this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]);
                }

                //Create Technique enum pin
                InputAttribute inAttr = new InputAttribute("Technique");
                inAttr.EnumName         = this.TechniqueEnumId;
                inAttr.DefaultEnumEntry = defaultenum;
                inAttr.Order            = 1000;
                this.FInTechnique       = this.FFactory.CreateDiffSpread <EnumEntry>(inAttr);

                this.FoutCS.AssignFrom(this.varmanager.GetCustomData());
            }
            else
            {
                if (shader.IsCompiled)
                {
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.UpdateShaderPins();
                    this.FoutCS.AssignFrom(this.varmanager.GetCustomData());
                }
            }
            this.FInvalidate = true;
        }
Example #11
0
            public ShaderDeviceData(DX11RenderContext context)
            {
                string basepath = "VVVV.DX11.Nodes.effects.DrawFullScreen.fx";

                using (DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath))
                {
                    shaderInstance = new DX11ShaderInstance(context, effect);

                    inputTextureVariable = shaderInstance.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource();
                    colorVariable        = shaderInstance.Effect.GetVariableBySemantic("COLOR").AsVector();
                    samplerVariable      = shaderInstance.Effect.GetVariableBySemantic("TEXTURESAMPLER").AsSampler();
                    texTransformVariable = shaderInstance.Effect.GetVariableBySemantic("TEXTUREMATRIX").AsMatrix();
                    pass = shaderInstance.CurrentTechnique.GetPassByIndex(0);
                }
            }
        public int GetPreferredTechnique(DX11Effect shader)
        {
            string[] techniqueNames = shader.TechniqueNames;

            foreach (string pref in this.PreferredTechniques)
            {
                for (int i = 0; i < techniqueNames.Length; ++i)
                {
                    if (techniqueNames[i].ToLower() == pref)
                    {
                        return(i);
                    }
                }
            }

            return(-1);
        }
Example #13
0
        public bool HasDynamicPins(DX11Effect shader)
        {
            if (shader?.DefaultEffect == null)
            {
                return(false);
            }
            for (int i = 0; i < shader.DefaultEffect.Description.GlobalVariableCount; i++)
            {
                EffectVariable var = shader.DefaultEffect.GetVariableByIndex(i);
                if (ShaderPinFactory.IsShaderPin(var))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #14
0
        public override void SetShader(DX11Effect shader, bool isnew, string fileName)
        {
            FOutPath.SliceCount = 1;
            FOutPath[0]         = fileName;

            if (isnew)
            {
                this.FShader = shader;
            }

            if (shader.IsCompiled)
            {
                this.FShader = shader;
                this.varmanager.SetShader(shader);
            }

            //Only set technique if new, otherwise do it on update/evaluate
            if (isnew)
            {
                string defaultenum;
                if (shader.IsCompiled)
                {
                    defaultenum = shader.TechniqueNames[0];
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.CreateShaderPins();
                }
                else
                {
                    defaultenum = "";
                    this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]);
                }
            }
            else
            {
                if (shader.IsCompiled)
                {
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.UpdateShaderPins();
                }
            }


            this.shaderupdated = true;
            this.FInvalidate   = true;
        }
Example #15
0
        protected override bool CreateNode(INodeInfo nodeInfo, IInternalPluginHost pluginHost)
        {
            if (nodeInfo.Type != NodeType.Plugin)
            {
                return(false);
            }

            //get the code of the FXProject associated with the nodeinfos filename
            //effectHost.SetEffect(nodeInfo.Filename, project.Code);

            //compile shader

            var shader = DX11Effect.FromByteCode(nodeInfo.Filename);

            //create or update plugin
            if (pluginHost.Plugin == null)
            {
                //IPluginBase plug = this.FDotNetFactory.CreatePluginCustom(nodeInfo, pluginHost as IPluginHost2, typeof(DX11ShaderNode));
                nodeInfo.AutoEvaluate = false;
                nodeInfo.Arguments    = typeof(T).ToString();

                var pluginContainer = new PluginContainer(pluginHost, FIORegistry, FParentContainer, FNodeInfoFactory, FDotNetFactory, typeof(T), nodeInfo);
                pluginHost.Plugin = pluginContainer;

                FPluginContainers[pluginContainer.PluginBase] = pluginContainer;

                IDX11ShaderNodeWrapper shaderNode = pluginContainer.PluginBase as IDX11ShaderNodeWrapper;
                shaderNode.SetShader(shader, true, nodeInfo.Filename);

                if (this.PluginCreated != null)
                {
                    this.PluginCreated(pluginContainer, pluginHost);
                }
            }
            else
            {
                PluginContainer container  = pluginHost.Plugin as PluginContainer;
                var             shaderNode = container.PluginBase as IDX11ShaderNodeWrapper;
                shaderNode.SetShader(shader, false, nodeInfo.Filename);
            }


            return(true);
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutPointcloudBuffer[0].Contains(context) || !this.FOutIndexBuffer[0].Contains(context) || this.FInEleCount.IsChanged)
            {
                this.FOutPointcloudBuffer[0].Dispose(context);
                this.FOutIndexBuffer[0].Dispose(context);
                DX11RWStructuredBuffer pcBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], FInStride[0], eDX11BufferMode.Counter);
                DX11RWStructuredBuffer idBuffer = new DX11RWStructuredBuffer(device, FInEleCount[0], 4, eDX11BufferMode.Counter);
                this.FOutPointcloudBuffer[0][context] = pcBuffer;
                this.FOutIndexBuffer[0][context]      = idBuffer;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutIndexBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "RingBufferIndexing.effects.RingBufferIndexing.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPointcloudBuffer.PluginIO.IsConnected /* && currentFrame != FHDEHost.FrameTime*/)
            {
                currentFrame = FHDEHost.FrameTime; // prevents to execute this a second time

                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFERIN", FInPointcloudBuffer[0][context].SRV);
                shader.SetBySemantic("POINTCLOUDBUFFEROUT", FOutPointcloudBuffer[0][context].UAV, 0);
                shader.SetBySemantic("INDEXBUFFER", FOutIndexBuffer[0][context].UAV);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
Example #17
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            Device        device = context.Device;
            DeviceContext ctx    = context.CurrentDeviceContext;

            if (!this.FOutLinkBuffer[0].Contains(context) || !this.FOutOffsetBuffer[0].Contains(context) || FInGridcellCount.IsChanged)
            {
                this.FOutLinkBuffer[0].Dispose(context);
                this.FOutOffsetBuffer[0].Dispose(context);
                DX11RWStructuredBuffer lb = new DX11RWStructuredBuffer(device, FInEleCount[0], 8, eDX11BufferMode.Counter);
                DX11RWStructuredBuffer ob = new DX11RWStructuredBuffer(device, FInGridcellCount[0] * FInGridcellCount[0] * FInGridcellCount[0], 4, eDX11BufferMode.Counter);
                this.FOutLinkBuffer[0][context]   = lb;
                this.FOutOffsetBuffer[0][context] = ob;
            }

            // clear offsetbuffer
            int[] mask = new int[4] {
                -1, -1, -1, -1
            };
            ctx.ClearUnorderedAccessView(FOutOffsetBuffer[0][context].UAV, mask);

            // load shader
            if (this.shader == null)
            {
                string     basepath = "LinkedList.effects.LinkedList.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);
                this.shader = new DX11ShaderInstance(context, effect);
            }

            if (this.FInPcBuffer.PluginIO.IsConnected)
            {
                shader.SelectTechnique("BuildHash");
                shader.SetBySemantic("POINTCLOUDBUFFER", FInPcBuffer[0][context].SRV);
                shader.SetBySemantic("POINTTRANSFORM", FInTransform[0]);
                shader.SetBySemantic("RWLINKBUFFER", FOutLinkBuffer[0][context].UAV, 0);
                shader.SetBySemantic("RWOFFSETBUFFER", FOutOffsetBuffer[0][context].UAV);
                shader.SetBySemantic("GRIDCELLSIZE", FInGridcellCount[0]);

                shader.ApplyPass(0);
                ctx.Dispatch((FInEleCount[0] + 63) / 64, 1, 1);
                context.CleanUp();
                context.CleanUpCS();
            }
        }
Example #18
0
        public SolidColorTransformed(DX11RenderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            this.context = context;

            using (var cef = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), "FeralTic.Effects.TransformColor.fx"))
            {
                this.effect = new Effect(context.Device, cef.ByteCode);
                this.pass   = this.effect.GetTechniqueByIndex(0).GetPassByIndex(0);

                this.viewProjVariable = this.effect.GetVariableByName("tVP").AsMatrix();
                this.worldVariable    = this.effect.GetVariableByName("tW").AsMatrix();
                this.colorVariable    = this.effect.GetVariableByName("objectColor").AsVector();
            }
        }
Example #19
0
        public override void SetShader(DX11Effect shader, bool isnew)
        {
            this.FShader = shader;

            this.varmanager.SetShader(shader);

            //Only set technique if new, otherwise do it on update/evaluate
            if (isnew)
            {
                string defaultenum;
                if (shader.IsCompiled)
                {
                    defaultenum = shader.TechniqueNames[0];
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.CreateShaderPins();
                }
                else
                {
                    defaultenum = "";
                    this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]);
                }

                //Create Technique enum pin
                InputAttribute inAttr = new InputAttribute("Technique");
                inAttr.EnumName         = this.TechniqueEnumId;
                inAttr.DefaultEnumEntry = defaultenum;
                inAttr.Order            = 1000;
                this.FInTechnique       = this.FFactory.CreateDiffSpread <EnumEntry>(inAttr);
            }
            else
            {
                if (shader.IsCompiled)
                {
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.UpdateShaderPins();
                }
            }

            this.shaderupdated = true;
            this.FInvalidate   = true;
        }
        public override void SetShader(DX11Effect shader, bool isnew)
        {
            if (shader.IsCompiled)
            {
                this.FShader = shader;
                this.varmanager.SetShader(shader);
                this.varmanager.RebuildTextureCache();

                this.varmanager.RebuildPassCache(tid);
                //this.varmanager.RebuildPassCache(0);
            }

            //Only set technique if new, otherwise do it on update/evaluate
            if (isnew)
            {
                string defaultenum;
                if (shader.IsCompiled)
                {
                    defaultenum = shader.TechniqueNames[0];
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.CreateShaderPins();
                }
                else
                {
                    defaultenum = "";
                    this.FHost.UpdateEnum(this.TechniqueEnumId, "", new string[0]);
                }
            }
            else
            {
                if (shader.IsCompiled)
                {
                    this.FHost.UpdateEnum(this.TechniqueEnumId, shader.TechniqueNames[0], shader.TechniqueNames);
                    this.varmanager.UpdateShaderPins();
                }
            }


            this.shaderupdated = true;
            this.FInvalidate   = true;
        }
Example #21
0
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            if (quadshader == null)
            {
                string     basepath = "VVVV.DX11.Nodes.effects.quad.fx";
                DX11Effect effect   = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), basepath);

                quadshader      = new DX11ShaderInstance(context, effect);
                texturevariable = quadshader.Effect.GetVariableBySemantic("INPUTTEXTURE").AsResource();
                samplervariable = quadshader.Effect.GetVariableBySemantic("SAMPLERSTATE").AsSampler();

                Quad quad = new Quad();
                quad.Size = new Vector2(1.0f);

                quadgeometry = context.Primitives.QuadNormals(quad);

                quadlayouts = new List <InputLayout>();
                for (int i = 0; i < 4; i++)
                {
                    InputLayout layout;
                    quadshader.SelectTechnique(i);

                    bool res = quadgeometry.ValidateLayout(quadshader.GetPass(0), out layout);
                    quadlayouts.Add(layout);
                }
            }

            if (this.spmax > 0)
            {
                if (!this.FOutLayer[0].Contains(context))
                {
                    this.FOutLayer[0][context]        = new DX11Layer();
                    this.FOutLayer[0][context].Render = this.Render;
                }
            }
        }
Example #22
0
 public abstract void SetShader(DX11Effect shader, bool isnew, string fileName);
 protected virtual List <CompilerError> VerifyShader(string file, DX11Effect effect)
 {
     return(new List <CompilerError>());
 }
        protected override bool CreateNode(INodeInfo nodeInfo, IInternalPluginHost pluginHost)
        {
            if (nodeInfo.Type != NodeType.Dynamic)
            {
                return(false);
            }

            var project = nodeInfo.UserData as FXProject;

            /*if (!project.IsLoaded)
             *  project.Load();*/

            //compile shader
            FIncludeHandler.ParentPath = Path.GetDirectoryName(nodeInfo.Filename);
            string code = File.ReadAllText(nodeInfo.Filename);

            DX11Effect shader;

            //create or update plugin
            if (pluginHost.Plugin == null)
            {
                nodeInfo.AutoEvaluate = false;
                nodeInfo.Arguments    = typeof(T).ToString();

                var pluginContainer = new PluginContainer(pluginHost, FIORegistry, FParentContainer, FNodeInfoFactory, FDotNetFactory, typeof(T), nodeInfo);
                pluginHost.Plugin = pluginContainer;

                FPluginContainers[pluginContainer.PluginBase] = pluginContainer;

                IDX11ShaderNodeWrapper shaderNode = pluginContainer.PluginBase as IDX11ShaderNodeWrapper;
                shaderNode.Source         = nodeInfo;
                shaderNode.WantRecompile += new EventHandler(shadernode_WantRecompile);

                shader = DX11Effect.FromString(code, FIncludeHandler, shaderNode.Macros);

                shaderNode.SetShader(shader, true, nodeInfo.Filename);

                if (this.PluginCreated != null)
                {
                    this.PluginCreated(pluginContainer, pluginHost);
                }
            }
            else
            {
                PluginContainer container  = pluginHost.Plugin as PluginContainer;
                var             shaderNode = container.PluginBase as IDX11ShaderNodeWrapper;
                shader = DX11Effect.FromString(code, FIncludeHandler, shaderNode.Macros);

                shaderNode.SetShader(shader, false, nodeInfo.Filename);
            }

            //now the effect is compiled in vvvv and we can access the errors
            string e = shader.ErrorMessage;//effectHost.GetErrors();

            if (string.IsNullOrEmpty(e))
            {
                e = "";
            }

            this.ParseErrors(e, project, shader);



            //and the input pins
            string f = "";// effectHost.GetParameterDescription();

            if (string.IsNullOrEmpty(f))
            {
                f = "";
            }
            project.ParameterDescription = f;

            return(true);
        }
        private void ParseErrors(string e, FXProject project, DX11Effect shader)
        {
            var compilerResults = new CompilerResults(null);
            //now parse errors to CompilerResults
            //split errorstring linewise
            var errorlines = e.Split(new char[1] {
                '\n'
            });

            foreach (var line in errorlines)
            {
                string filePath  = project.LocalPath;
                string eCoords   = string.Empty;
                int    eLine     = 0;
                int    eChar     = 0;
                string eNumber   = string.Empty;
                string eText     = string.Empty;
                bool   isWarning = false;

                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                //split the line at ": "
                //which results in 3 or 4 lines:
                //[0] filename (line, character)
                //[1] error/warning code
                //[2] (optional) erroneous character
                //[3] error description
                var eItems = line.Split(new string[1] {
                    ": "
                }, StringSplitOptions.None);

                //extract line/char substring
                int start = eItems[0].LastIndexOf('(');
                int end   = eItems[0].LastIndexOf(')');

                if (start > 0)
                {
                    string relativePath = eItems[0].Substring(0, start);

                    //if this is a path to an include..
                    if (relativePath != Path.Combine(FHDEHost.ExePath, "memory"))
                    {
                        // we need to guess here. shader compiler outputs relative paths.
                        // we don't know if the include was "local" or <global>

                        filePath = Path.Combine(Path.GetDirectoryName(project.LocalPath), relativePath);
                        if (!File.Exists(filePath))
                        {
                            string fileName = Path.GetFileName(relativePath);

                            foreach (var reference in project.References)
                            {
                                var referenceFileName = Path.GetFileName((reference as FXReference).ReferencedDocument.LocalPath);
                                if (referenceFileName.ToLower() == fileName.ToLower())
                                {
                                    filePath = reference.AssemblyLocation;
                                }
                            }
                        }
                    }
                }

                if (start > -1 && end > 0)
                {
                    eCoords = eItems[0].Substring(start + 1, end - start - 1);
                    var eLineChar = eCoords.Split(new char[1] {
                        ','
                    });
                    eLine = Convert.ToInt32(eLineChar[0]);
                    eChar = Convert.ToInt32(eLineChar[1]);

                    if (eItems[1].StartsWith("warning"))
                    {
                        isWarning = true;
                        eNumber   = eItems[1].Substring(8, 5);
                    }
                    else
                    {
                        eNumber = eItems[1].Substring(6, 5);
                    }

                    if (eItems.Length == 2)
                    {
                        isWarning = false;
                        eNumber   = "-1";
                        eText     = eItems[1];
                    }
                    else
                    {
                        eText = eItems[2];
                        if (eItems.Length > 3)
                        {
                            eText += ": " + eItems[3];
                        }
                    }
                }
                else
                {
                    eText = line;
                }

                var error = new CompilerError(filePath, eLine, eChar, eNumber, eText);
                error.IsWarning = isWarning;
                compilerResults.Errors.Add(error);
            }

            //Add some extra error from reflection
            if (shader.IsCompiled)
            {
                compilerResults.Errors.AddRange(this.VerifyShader(project.LocalPath, shader).ToArray());
            }

            project.CompilerResults = compilerResults;
        }
Example #26
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);
        }
Example #27
0
        public void Evaluate(int SpreadMax)
        {
            this.shaderupdated = false;
            this.spmax         = this.CalculateSpreadMax();

            if (FShaderCode.IsChanged || FFileName.IsChanged || FInDefines.IsChanged)
            {
                List <ShaderMacro> sms = new List <ShaderMacro>();
                for (int i = 0; i < this.FInDefines.SliceCount; i++)
                {
                    try
                    {
                        string[] s = this.FInDefines[i].Split("=".ToCharArray());

                        if (s.Length == 2)
                        {
                            ShaderMacro sm = new ShaderMacro();
                            sm.Name  = s[0];
                            sm.Value = s[1];
                            sms.Add(sm);
                        }
                    }
                    catch
                    {
                    }
                }

                DX11ShaderInclude FIncludeHandler = new DX11ShaderInclude();
                FIncludeHandler.ParentPath = Path.GetDirectoryName(FFileName[0]);
                FShader = DX11Effect.FromString(FShaderCode[0], FIncludeHandler, sms.ToArray());
                if (init && !ShaderCreatedByConfig)
                {
                    this.SetShader(FShader, true);
                    init = false;
                }
                else
                {
                    this.SetShader(FShader, false);
                }

                // Write Shadercode & Defines into config -> needed to restore dynamic pins
                if (HasDynamicPins(FShader))
                {
                    configWritten = true;
                    if (FConfigShader[0] != FShaderCode[0])
                    {
                        FConfigShader[0]  = FShaderCode[0];
                        FConfigDefines[0] = "";

                        for (int i = 0; i < FInDefines.SliceCount; i++)
                        {
                            if (i != 0)
                            {
                                FConfigDefines[0] += ",";
                            }
                            FConfigDefines[0] += this.FInDefines[i];
                        }
                    }
                }
                else
                {
                    if (FConfigShader[0] != "")
                    {
                        FConfigShader[0]  = "";
                        FConfigDefines[0] = "";
                    }
                }
            }


            if (FShader.TechniqueNames != null && this.FInTechnique.IsChanged && FInTechnique.SliceCount > 0)
            {
                this.techniqueindex   = Array.IndexOf(FShader.TechniqueNames, FInTechnique[0].Name);
                this.techniquechanged = true;
            }

            float *src;

            //Cache world pointer
            this.FInWorld.GetMatrixPointer(out this.mworldcount, out src);
            this.mworld = (Matrix *)src;

            this.FOutLayer.SliceCount = 1;
            if (this.FOutLayer[0] == null)
            {
                this.FOutLayer[0] = new DX11Resource <DX11Layer>();
            }

            if (this.FInvalidate)
            {
                if (this.FShader.IsCompiled)
                {
                    this.FOutCompiled[0] = true;
                    this.FOutTechniqueValid.SliceCount = this.FShader.TechniqueValids.Length;

                    for (int i = 0; i < this.FShader.TechniqueValids.Length; i++)
                    {
                        this.FOutTechniqueValid[i] = this.FShader.TechniqueValids[i];
                    }
                }
                else
                {
                    this.FOutCompiled[0] = false;
                    this.FOutTechniqueValid.SliceCount = 0;
                }
                this.FInvalidate = false;
            }
            if (this.FOutQueryable[0] == null)
            {
                this.FOutQueryable[0] = this;
            }
        }
Example #28
0
        public void RecalcShader(bool isNew)
        {
            var declarations = "";
            var pscode       = @"
    float4 col = float4(1, 1, 1, 1);
    return col;";

            if (FShaderProvider.SliceCount > 0 && FShaderProvider[0] != null)
            {
                this.traverseResult = FShaderProvider[0].Traverse();

                declarations = string.Join(@"
", traverseResult.GlobalVars.Select(gv => gv.Value.ToString()).Concat(traverseResult.FunctionDeclarations.Values));

                pscode = string.Join(@"
    ", traverseResult.LocalDeclarations.Values) + $@"
    return {traverseResult.LocalDeclarations[FShaderProvider[0]].Identifier};";
                ;
            }

            var effectText = declarations +
                             @" 
SamplerState linearSampler: IMMUTABLE
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};

cbuffer cbPerDraw : register(b0)
{
    float4x4 tVP : LAYERVIEWPROJECTION;
};

cbuffer cbPerObj : register(b1)
{
    float4x4 tW : WORLD;
};

struct VS_IN
{
    float4 PosO : POSITION;
	float4 TexCd : TEXCOORD0;
};

struct vs2ps
{
    float4 PosWVP: SV_Position;
    float2 TexCd: TEXCOORD0;
};

vs2ps VS(VS_IN input)
{
    vs2ps output;
    output.PosWVP = mul(input.PosO, mul(tW, tVP));
    output.TexCd = input.TexCd.xy;
    return output;
}

float4 PS(vs2ps In): SV_Target
{
    "
                             + pscode +
                             @"
}

technique10 Patched
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_4_0, VS()));
        SetPixelShader(CompileShader(ps_4_0, PS()));
    }
}";

            FCode.SliceCount = 1;
            FCode[0]         = effectText;

            SetShader(DX11Effect.FromString(effectText), isNew, "");
        }
        public void Update(DX11RenderContext context)
        {
            for (int i = 0; i < framePool.Count; i++)
            {
                framePool[i].UnLock();
            }
            framePool.Clear();

            if (this.textureOutput.SliceCount == 0)
            {
                return;
            }

            //

            //Compile shader if necessary
            if (shader == null)
            {
                using (DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), Consts.EffectPath + ".ExtractChannel.fx"))
                {
                    shader = new DX11ShaderInstance(context, effect);
                }
            }
            if (shaderExpand == null)
            {
                using (DX11Effect effect = DX11Effect.FromResource(Assembly.GetExecutingAssembly(), Consts.EffectPath + ".ExtractChannelExpand.fx"))
                {
                    shaderExpand = new DX11ShaderInstance(context, effect);
                }
            }

            for (int i = 0; i < this.textureOutput.SliceCount; i++)
            {
                if (this.textureInput[i] == null)
                {
                    this.SetDefault(context, i);
                }
                else if (this.textureInput[i].Contains(context))
                {
                    var instance = this.singleChannelOut[i] ? shader : shaderExpand;

                    var input = this.textureInput[i][context];

                    string prefix = "Float";

                    var inputFormat = input.SRV.Description.Format;
                    inputFormat = inputFormat.DefaultOutputForCompressed();

                    if (inputFormat.IsSignedInt())
                    {
                        prefix = "UInt";
                    }
                    if (inputFormat.IsUnsignedInt())
                    {
                        prefix = "Int";
                    }

                    prefix += this.channel[i].ToString();
                    instance.SelectTechnique(prefix);
                    instance.SetByName("InputTexture", input.SRV);

                    var outputFormat = inputFormat;
                    if (this.singleChannelOut[i])
                    {
                        var singleFormat = outputFormat.GetSingleChannelEquivalent();
                        if (singleFormat == SlimDX.DXGI.Format.Unknown)
                        {
                            this.message[i] = "Could not find a single channel format suitable for : " + outputFormat.ToString();
                            this.SetDefault(context, i);
                            continue;
                        }
                        else
                        {
                            outputFormat = singleFormat;
                        }
                    }


                    var output = context.ResourcePool.LockRenderTarget(input.Width, input.Height, outputFormat, false, 1, false);
                    context.RenderTargetStack.Push(output.Element);

                    context.Primitives.ApplyFullTriVSPosition();
                    instance.ApplyPass(0);
                    context.CurrentDeviceContext.Draw(3, 0);

                    context.RenderTargetStack.Pop();

                    this.framePool.Add(output);



                    this.textureOutput[i][context] = output.Element;
                    this.message[i] = "ok";
                }
                else
                {
                    this.SetDefault(context, i);
                }
            }

            if (this.BeginQuery != null)
            {
                this.BeginQuery(context);
            }

            if (this.EndQuery != null)
            {
                this.EndQuery(context);
            }
        }
Example #30
0
 public void SetShader(DX11Effect shader)
 {
     this.shader = shader;
 }