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> /// 名前からコンスタントバッファのバインド位置を取得する /// </summary> /// <param name="name"></param> /// <param name="bindIndex"></param> /// <returns></returns> public bool FindConstantBufferByName(string name, out int bindIndex) { // コンスタントバッファの実体をとってきて確実にある状況でGetResourceBindingDescriptionを呼ぶ int cb_num = reflector_.Description.ConstantBuffers; for (int i = 0; i < cb_num; i++) { var cb = reflector_.GetConstantBuffer(i); if (cb.Description.Name == name) { InputBindingDescription desc = reflector_.GetResourceBindingDescription(name); bindIndex = desc.BindPoint; return(true); } } bindIndex = -1; return(false); }