Exemple #1
0
        /// <summary>
        /// Creates a new effect implementation.
        /// </summary>
        /// <param name="shaderByteCode">Compiled shader byte code.</param>
        /// <returns>
        /// Effect implementation
        /// </returns>
        public EffectImplementation CreateEffectImplementation(byte[] shaderByteCode)
        {
            D3D10EffectImplementation impl = new D3D10EffectImplementation(_renderer, shaderByteCode, "fx_4_0", D3DC.ShaderFlags.None, D3DC.EffectFlags.None);

            SetGraphicsID(impl);
            return(impl);
        }
        internal D3D10EffectTechnique Clone(D3D.EffectTechnique tech, D3D10EffectImplementation parent)
        {
            D3D10EffectTechnique clone = new D3D10EffectTechnique(parent, tech);

            clone._passes = _passes.Clone(tech);
            return(clone);
        }
        /// <summary>
        /// Clones the technique collection with the new effect instance
        /// and the new parent implementation.
        /// </summary>
        /// <param name="effect">The D3D10 effect.</param>
        /// <param name="parent">The D3D10 implementation.</param>
        /// <returns></returns>
        internal D3D10EffectTechniqueCollection Clone(D3D.Effect effect, D3D10EffectImplementation parent)
        {
            D3D10EffectTechniqueCollection clone = new D3D10EffectTechniqueCollection();

            for (int i = 0; i < Count; i++)
            {
                clone.Add(_techniques[i].Clone(effect.GetTechniqueByIndex(i), parent));
            }
            return(clone);
        }
Exemple #4
0
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectPass"/>.
        /// </summary>
        /// <param name="parent">The implementation parent.</param>
        /// <param name="effect">The D3D10 effect so we can query for variables.</param>
        /// <param name="pass">The D3D10 pass.</param>
        internal D3D10EffectPass(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectPass pass)
        {
            _pass     = pass;
            _renderer = parent.Renderer;

            D3D.EffectPassDescription desc = pass.Description;
            _name      = desc.Name;
            _layoutMap = new InputLayoutMap(_renderer, desc.Signature);

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _pass.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                    continue;
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                    continue;
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Unknown));
                    continue;
                }
                annoVar = anno.AsVector();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Vector, EffectParameterType.Unknown));
                }
            }

            //Now to reflect the parameters and start adding them to the shader
            D3D.EffectPassShaderDescription vertexShaderDesc = pass.VertexShaderDescription;
            D3D.EffectShaderVariable        vertexShaderVar  = vertexShaderDesc.Variable;
            ParseShader(parent, effect, vertexShaderVar);
            ParseShader(parent, effect, pass.PixelShaderDescription.Variable);

            //And the standard input layout
            CreateInputLayout(vertexShaderVar, vertexShaderDesc.Index);
        }
Exemple #5
0
        private static void ParseShaderParameters(D3D10EffectImplementation parent, D3D.Effect effect, D3DC.ShaderReflection reflect)
        {
            D3DC.ShaderDescription desc = reflect.Description;
            int constantBuffers         = desc.ConstantBuffers;
            int boundResources          = desc.BoundResources;

            //Grab parameters
            for (int i = 0; i < constantBuffers; i++)
            {
                D3DC.ConstantBuffer cb = reflect.GetConstantBuffer(i);
                for (int j = 0; j < cb.Description.Variables; j++)
                {
                    D3DC.ShaderReflectionVariable cbVar = cb.GetVariable(j);
                    String name = cbVar.Description.Name;
                    if (parent.Parameters[name] == null)
                    {
                        D3D.EffectVariable         param     = effect.GetVariableByName(name);
                        D3DC.ShaderReflectionType  paramType = cbVar.GetVariableType();
                        D3DC.ShaderTypeDescription typeDesc  = paramType.Description;
                        if (Want(typeDesc.Class, typeDesc.Type))
                        {
                            ((D3D10EffectParameterCollection)parent.Parameters).Add(new D3D10EffectParameter(param, paramType));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            //Grab resources
            for (int i = 0; i < boundResources; i++)
            {
                D3DC.InputBindingDescription inputBinding = reflect.GetResourceBindingDescription(i);
                String name = inputBinding.Name;
                if (parent.Parameters[name] == null)
                {
                    D3D.EffectVariable param = effect.GetVariableByName(name);
                    if (Want(inputBinding.Type, inputBinding.Dimension))
                    {
                        ((D3D10EffectParameterCollection)parent.Parameters).Add(new D3D10EffectParameter(param, inputBinding));
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectTechnique"/>.
        /// </summary>
        /// <param name="parent">The implementation parent.</param>
        /// <param name="effect">The D3D10 effect.</param>
        /// <param name="tech">The D3D10 technique.</param>
        internal D3D10EffectTechnique(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectTechnique tech)
        {
            _tech   = tech;
            _parent = parent;

            D3D.EffectTechniqueDescription desc = _tech.Description;
            _name = desc.Name;

            //Fetch annotations
            int annoCount = desc.AnnotationCount;

            _annotations = new D3D10EffectAnnotationCollection();
            for (int i = 0; i < annoCount; i++)
            {
                D3D.EffectVariable            anno     = _tech.GetAnnotationByIndex(i);
                D3D.EffectVariableDescription annoDesc = anno.Description;
                D3D.EffectVariable            annoVar  = anno.AsString();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Object, EffectParameterType.String));
                }
                annoVar = anno.AsScalar();
                if (annoVar != null)
                {
                    //Need to find a way to get the param type...
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Scalar, EffectParameterType.Unknown));
                }
                annoVar = anno.AsMatrix();
                if (annoVar != null)
                {
                    _annotations.Add(new D3D10EffectAnnotation(annoVar, annoDesc.Name, annoDesc.Semantic, EffectParameterClass.Matrix, EffectParameterType.Single));
                }
            }

            _passes = new D3D10EffectPassCollection();
            for (int i = 0; i < desc.PassCount; i++)
            {
                _passes.Add(new D3D10EffectPass(parent, effect, tech.GetPassByIndex(i)));
            }
        }
Exemple #7
0
        private static void ParseShader(D3D10EffectImplementation parent, D3D.Effect effect, D3D.EffectShaderVariable shaderVar)
        {
            D3D.EffectVariable testElem = shaderVar.GetElement(0);

            if (testElem == null)
            {
                if (shaderVar.IsValid)
                {
                    D3D.ShaderDescription shDesc;
                    shaderVar.GetShaderDescription(0, out shDesc);
                    D3DC.ShaderReflection reflect = new D3DC.ShaderReflection(shDesc.Bytecode);
                    ParseShaderParameters(parent, effect, reflect);

                    //Dispose of the reflection variable *and* the bytecode/signature of the shader desc...bytecode will reported as a leaked in ObjectTable
                    reflect.Dispose();
                    shDesc.Signature.Dispose();
                    shDesc.Bytecode.Dispose();
                }
            }
            else
            {
                int k = 1;
                while ((testElem = shaderVar.GetElement(k)) != null)
                {
                    if (testElem.IsValid)
                    {
                        D3D.ShaderDescription shDesc;
                        testElem.AsShader().GetShaderDescription(0, out shDesc);
                        D3DC.ShaderReflection reflect = new D3DC.ShaderReflection(shDesc.Bytecode);
                        ParseShaderParameters(parent, effect, reflect);

                        //Dispose of the reflection variable *and* the bytecode/signature of the shader desc...bytecode will reported as a leaked in ObjectTable
                        reflect.Dispose();
                        shDesc.Signature.Dispose();
                        shDesc.Bytecode.Dispose();
                    }
                    k++;
                }
            }
        }