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++; } } }
public ShaderReflection(ShaderBytecode byteCode) { reflector_ = new D3DShaderReflection(byteCode); }
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)); } } } }