/// <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); }
private void CreateInputLayout(D3D.EffectShaderVariable shaderVar, int shaderIndex) { D3D.ShaderDescription shaderDesc; shaderVar.GetShaderDescription(shaderIndex, out shaderDesc); int paramCount = shaderDesc.InputParameterCount; //Dispose of the description's bytecode/sig...bytecode will be reported as a leak in ObjectTable shaderDesc.Bytecode.Dispose(); shaderDesc.Signature.Dispose(); VertexElement[] elements = new VertexElement[paramCount]; D3D.ShaderParameterDescription desc; int offset = 0; for (int i = 0; i < paramCount; i++) { shaderVar.GetInputParameterDescription(shaderIndex, i, out desc); elements[i] = CreateVertexElement(desc, ref offset); } _layoutMap.CreateLayout(new VertexDeclaration(elements)); }
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++; } } }