ich will mir gerade ein kleines Tool schreiben und brauche dazu im C# die Möglichkeit den D3DCompiler anzusprechen. Der Funktionsaufruf von D3DCompile funktioniert auch und ein kleiner Testshader wird auch kompiliert (Rückgabewert ist S_OK und ich bekomme einen CodeBlob). Wenn ich dann aber versuche über GetBufferPointer() oder GetBufferSize() das Ergebnis abzufragen erhalte ich nur IntPtr.Zero bzw 0 zurück.
Code: Alles auswählen
// Definitionen
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("8BA5FB08-5195-40e2-AC58-0D989C3A0102")]
public interface ID3DBlob {
IntPtr GetBufferPointer();
ulong GetBufferSize();
};
[DllImport("d3dcompiler_43.dll", EntryPoint="D3DCompile", CallingConvention=CallingConvention.StdCall, PreserveSig=true)]
public static extern IntPtr Compile([In] IntPtr pSrcData,
[In] uint srcDataSize,
[MarshalAs(UnmanagedType.LPStr), In, Optional] String pSourceName,
[In, Optional]ShaderMacro[] pDefines,
[In, Optional] IntPtr pInclude,
[MarshalAs(UnmanagedType.LPStr), In] String pEntryPoint,
[MarshalAs(UnmanagedType.LPStr), In] String pTarget,
[In] uint flags1,
[In] uint flags2,
[MarshalAs(UnmanagedType.Interface), Out] out ID3DBlob ppCode,
[MarshalAs(UnmanagedType.Interface), Out, Optional] out ID3DBlob ppErrorMsgs);
// Aufruf
String shader = "void vs_main(in float4 pos : POSITION, out float4 opos : SV_POSITION) { opos = pos; }";
ID3DBlob pCode = null, pMsg = null, pDisassembly = null;
IntPtr globalShader= Marshal.StringToHGlobalAnsi(shader);
IntPtr hr = D3D.Compiler.Compile(globalShader, (ulong)shader.Length, null, null, IntPtr.Zero, "vs_main", "vs_5_0", 0, 0, out pCode, out pMsg);
IntPtr codePtr = pCode.GetBufferPointer();
ulong codeSize = pCode.GetBufferSize();
Mit freundlichem Gruß
RazorX