[Mono-dev] Managed DirectX

Brian Crowell mono-devel at fluggo.com
Wed Oct 25 12:34:21 EDT 2006


Stefan Dösinger wrote:
> I am one of the programmers of the Wine Direct3D implementation, and I 
> wondered if there are any plans to implement Managed DirectX in Mono, and if 
> it is possible to share efforts between wine and mono?

Hello.

I started on an open implementation of the XNA libraries. Mostly because I was cheesed at the lack of good error messages. I know that isn't Managed DirectX, but Microsoft never really seemed interested in supporting that. The good news is that they're not terribly different from each other.

The only catch is that it's implemented in C++/CLI, which at present is really the best way to do it. I wouldn't attempt it in C#, unless you could figure out a better way to do all the calli instructions. I thought at one point about doing a simple wrapper around the COM implementation and doing the rest in C#, but even that's not all that great, and you still have the C++/CLI dependency.

Here, I'll give you a good example:

----------
_device->CreateTexture( width, height, levels, (DWORD) usage, (D3DFORMAT) format, (D3DPOOL) pool, &tex, NULL )
----------

...becomes:

----------
  IL_0006:  ldarg.0
  IL_0007:  ldfld      valuetype IDirect3DDevice9* Fluggo.Graphics.Direct3D.GraphicsDevice::_device
  IL_000c:  ldarg.1
  IL_000d:  ldarg.2
  IL_000e:  ldarg.3
  IL_000f:  ldarg.s    usage
  IL_0011:  ldarg.s    format
  IL_0013:  ldarg.s    pool
  IL_0015:  ldloca.s   tex
  IL_0017:  ldc.i4.0
  IL_0018:  ldarg.0
  IL_0019:  ldfld      valuetype IDirect3DDevice9* Fluggo.Graphics.Direct3D.GraphicsDevice::_device
  IL_001e:  ldind.i4
  IL_001f:  ldc.i4.s   92
  IL_0021:  add
  IL_0022:  ldind.i4
  IL_0023:  calli      unmanaged stdcall int32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong) modopt([mscorlib]System.Runtime.CompilerServices.CallConvStdcall)(native int,uint32,uint32,uint32,uint32 modopt([mscorlib]System.Runtime.CompilerServices.IsLong),valuetype _D3DFORMAT,valuetype _D3DPOOL,valuetype IDirect3DTexture9**,void**)
----------

Here, you can see C++ calculating the address of the pointer to the function, loading it, then issuing a calli. I don't know of a way to do that in C#, at least, not one that will give you any kind of good performance.

--Brian



More information about the Mono-devel-list mailing list