Пример #1
0
        public ShaderRegisters(SourceShader source, string techniqueName, Platform platform)
        {
            AsmTechnique technique = source.GetAsmTechnique(techniqueName, platform);

            vsReg = technique.VertexShader.RegisterSet;
            psReg = technique.PixelShader.RegisterSet;


            if (technique.VertexPreShader != null)
            {
                vsPreReg = technique.VertexPreShader.RegisterSet;
            }

            if (technique.PixelPreShader != null)
            {
                psPreReg = technique.PixelPreShader.RegisterSet;
            }

            staticArrays = new Dictionary <string, CodeExpression>();

            if (technique.TechniqueExtraData != null)
            {
                this.techniqueData = technique.TechniqueExtraData;

                psDefault = technique.TechniqueExtraData.PixelShaderConstants;
                vsDefault = technique.TechniqueExtraData.VertexShaderConstants;

                psBooleanDefault = technique.TechniqueExtraData.PixelShaderBooleanConstants;
                vsBooleanDefault = technique.TechniqueExtraData.VertexShaderBooleanConstants;
            }
        }
Пример #2
0
        public ShaderBytes(SourceShader source, string techniqueName, Platform platform)
        {
            this.source   = source;
            this.platform = platform;

            this.asmTechnique  = source.GetAsmTechnique(techniqueName, platform);
            this.hlslTechnique = source.GetTechnique(techniqueName, platform);
        }
Пример #3
0
        public ConstantSetup(SourceShader source, string techniqueName, Platform platform)
        {
            this.source        = source;
            this.techniqueName = techniqueName;

            this.attributeNames       = new List <string>();
            this.attributeFields      = new List <CodeFieldReferenceExpression>();
            this.attributeArrayFields = new List <CodeFieldReferenceExpression>();
            this.attributeAssignment  = new Dictionary <Type, List <CodeStatement> >();
            this.semanticMapping      = new List <SemanticMapping>();
            this.globals = new List <GlobalAttribute>();

            this.asm = source.GetAsmTechnique(techniqueName, platform);

            ComputeAllValidSemantics();
        }
Пример #4
0
        public Preshaders(SourceShader source, string techniqueName, Platform platform)
        {
            technique = source.GetAsmTechnique(techniqueName, platform);

            if (technique.PixelPreShader != null)
            {
                pixelPreShaderStatements = new CodeStatementCollection();
                pixelPreShader           = new PreshaderSrc(technique.PixelPreShader, pixelPreShaderStatements);

                technique.PixelShader.RegisterSet.SetMinFloatRegisterCount(pixelPreShader.MaxConstantRegisterAccess);
                technique.PixelShader.RegisterSet.SetMinBooleanRegisterCount(pixelPreShader.MaxBooleanConstantRegisterWrite);
            }

            if (technique.VertexPreShader != null)
            {
                vertexPreShaderStatements = new CodeStatementCollection();
                vertexPreShader           = new PreshaderSrc(technique.VertexPreShader, vertexPreShaderStatements);

                technique.VertexShader.RegisterSet.SetMinFloatRegisterCount(vertexPreShader.MaxConstantRegisterAccess);
                technique.VertexShader.RegisterSet.SetMinBooleanRegisterCount(vertexPreShader.MaxBooleanConstantRegisterWrite);
            }
        }
Пример #5
0
        public ShaderTextures(SourceShader source, string techniqueName, Platform platform)
        {
            this.psSamplers  = new List <Register>();
            this.vsSamplers  = new List <Register>();
            this.allSamplers = new Dictionary <string, SharedSampler>();

            AsmTechnique       technique = source.GetAsmTechnique(techniqueName, platform);
            TechniqueExtraData extras    = technique.TechniqueExtraData;

            //pull out the textures that will be used
            textures = new TextureAssociation[extras.TechniqueTextures.Length];
            for (int i = 0; i < extras.TechniqueTextures.Length; i++)
            {
                textures[i] = new TextureAssociation(extras.TechniqueTextures[i]);
            }

            //now do the samplers
            RegisterSet set = technique.PixelShader.RegisterSet;

            //pixel first
            foreach (Register reg in set)
            {
                if (reg.Category == RegisterCategory.Sampler)
                {
                    psSamplers.Add(reg);

                    int textureIndex = extras.PixelSamplerTextureIndex[reg.Index];

                    if (textureIndex == -1)
                    {
                        ThrowSamplerNoTextureException(reg);
                    }

                    textures[textureIndex].PsSamplers.Add(reg.Index);

                    //add the sampler to 'allSamplers'
                    SharedSampler ss = new SharedSampler();
                    ss.PsIndex        = reg.Index;
                    ss.SamplerDetails = reg;
                    ss.Index          = allSamplers.Count;
                    ss.DefaultState   = extras.PixelSamplerStates[reg.Index];
                    allSamplers.Add(reg.Name, ss);
                }
            }

            set = technique.VertexShader.RegisterSet;

            //now vertex
            foreach (Register reg in set)
            {
                if (reg.Category == RegisterCategory.Sampler)
                {
                    vsSamplers.Add(reg);

                    int textureIndex = extras.VertexSamplerTextureIndex[reg.Index];
                    if (textureIndex == -1)
                    {
                        ThrowSamplerNoTextureException(reg);
                    }

                    textures[textureIndex].VsSamplers.Add(reg.Index);

                    //add the sampler to 'allSamplers'
                    SharedSampler ss;
                    if (!allSamplers.TryGetValue(reg.Name, out ss))
                    {
                        ss = new SharedSampler();
                        ss.SamplerDetails = reg;
                        ss.Index          = allSamplers.Count;
                        ss.DefaultState   = extras.VertexSamplerStates[reg.Index];
                        allSamplers.Add(reg.Name, ss);
                    }
                    ss.VsIndex = reg.Index;
                }
            }
        }
Пример #6
0
        public override void AddBindBegin(IShaderDom shader, Action <CodeStatement, string> add)
        {
            //create the shader change bools..
            CodeStatement typeChange = new CodeVariableDeclarationStatement(typeof(bool), bindShaderChange.VariableName, new CodePrimitiveExpression(false));

            add(typeChange, "Shader type changed?");
            CodeStatement instanceChange = new CodeVariableDeclarationStatement(typeof(bool), bindInstanceChange.VariableName, new CodePrimitiveExpression(false));

            add(instanceChange, "Shader instance changed?");

            //call the Bind method in the shader system

            //int devIndex = state.Begin(this, 2, 0, out tc, out ic);

            CodeVariableReferenceExpression devIndex = new CodeVariableReferenceExpression("devIndex");

            AsmTechnique technique = source.GetAsmTechnique(techniqueName, Platform);

            int maxPixelSamplers  = MaxSamplers(technique.PixelShader.RegisterSet);
            int maxVertexSamplers = MaxSamplers(technique.VertexShader.RegisterSet);

            CodeMethodInvokeExpression beginInvoke = new CodeMethodInvokeExpression(
                new CodeMethodReferenceExpression(ShaderSystemRef, "Begin"),
                Instance,
                new CodePrimitiveExpression(maxPixelSamplers),
                new CodePrimitiveExpression(maxVertexSamplers),
                new CodeDirectionExpression(FieldDirection.Out, BindShaderTypeChange),
                new CodeDirectionExpression(FieldDirection.Out, BindShaderInstanceChange));

            CodeStatement callBegin = new CodeVariableDeclarationStatement(typeof(int), devIndex.VariableName, beginInvoke);

            add(callBegin, "About to start the bind");

            //if the devIndex has changed, call Warm() and set both bools to true

            //if extending in some way, then don't compare the devIndex to the class static, compare it to the virtual g uid
            CodeExpression classDevIndex = GraphicsDeviceUID;

            if (isShaderExtenable)
            {
                classDevIndex = new CodePropertyReferenceExpression(Instance, "lgd");
            }

            CodeExpression devChanged = new CodeBinaryOperatorExpression(devIndex, CodeBinaryOperatorType.IdentityInequality, classDevIndex);

            CodeStatement checkChanged =
                new CodeConditionStatement(devChanged,
                                           ETS(new CodeMethodInvokeExpression(Instance, "WarmShader", ShaderSystemRef)), // Call warm
                                           new CodeAssignStatement(BindShaderInstanceChange, new CodePrimitiveExpression(true)),
                                           new CodeAssignStatement(BindShaderTypeChange, new CodePrimitiveExpression(true)));

            add(checkChanged, "if the device changed, call Warm()");

            //bind the shaders if tc is true (type has changed)
            //and that 'owner' is true (owns the shaders)

            //if (((tc && this.owner)
            //            == true))
            //{
            //    state.SetShaders(ShadowShader.vs, ShadowShader.ps);
            //}

            //for classes that are either extendable or extended from another shader,
            //then the SetShaders call is put into a virtual method that is overridden.

            CodeBinaryOperatorExpression bindShaders = new CodeBinaryOperatorExpression(
                new CodeBinaryOperatorExpression(BindShaderTypeChange, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(true)),
                CodeBinaryOperatorType.BooleanAnd,
                new CodeBinaryOperatorExpression(new CodeFieldReferenceExpression(Instance, "owner"), CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(true)));

            CodeExpression setShaders = new CodeMethodInvokeExpression(
                ShaderSystemRef, "SetShaders", VertexShaderRef, PixelShaderRef);


            //if extendable, the call goes into a local 'SetShaders' method
            if (isShaderExtenable)
            {
                setShaders = new CodeMethodInvokeExpression(Instance, "SetShaders", ShaderSystemRef);
            }

            CodeStatement exp = new CodeConditionStatement(
                bindShaders, ETS(setShaders));

            if (shaderExtendsFrom == null)
            {
                add(exp, "If the type has changed, and this class owns it's shaders, then bind the shaders");
            }
        }