Page 1 of 1

Port Direct3D?

Posted: Thu Jun 20, 2013 6:22 pm
by BMW
Would it be possible to port Direct3D to my OS?

I could port OpenGL, then make all the D3D functions as wrappers that call corresponding OpenGL functions.

Now that would annoy Microsoft. :D

Re: Port Direct3D?

Posted: Thu Jun 20, 2013 6:47 pm
by Love4Boobies
ReactX works that way.

Re: Port Direct3D?

Posted: Thu Jun 20, 2013 6:53 pm
by BMW
Love4Boobies wrote:ReactX works that way.
Oh nice... I must check out ReactOS.

Re: Port Direct3D?

Posted: Fri Jun 21, 2013 8:02 am
by dozniak
Question is, why would you want that? If graphics is all about speed, putting layer on top of layer of wrappers isn't going to make it faster.

Re: Port Direct3D?

Posted: Fri Jun 21, 2013 8:47 am
by XanClic
BMW wrote:Would it be possible to port Direct3D to my OS?

I could port OpenGL, then make all the D3D functions as wrappers that call corresponding OpenGL functions.

Now that would annoy Microsoft. :D
The problem is not porting the interface, but having appropriate drivers underneath it. Of course, you could port MESA for having a software rasterizer at least, but well…

If you do manage to have acceptable OpenGL support, you could also try to port wine.

Re: Port Direct3D?

Posted: Fri Jun 21, 2013 4:45 pm
by BMW
dozniak wrote:Question is, why would you want that? If graphics is all about speed, putting layer on top of layer of wrappers isn't going to make it faster.
Exactly. The reason I would want to port Direct3D is for compatibility, not speed.

My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.

Re: Port Direct3D?

Posted: Fri Jun 21, 2013 7:09 pm
by XanClic
BMW wrote:My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.
Certainly it would be. Easiest way would be modifying Windows to boot directly into the desired program.

If you want to write your own OS for that, well, it is possible, but you'd require at least the same level of driver support as Windows. Which is theoretically possible, but practically impossible, obviously.

Also, it'd be practically useless, since you'd barely gain any performance. Especially since most modern games are GPU-bound, which is a resource they can use basically exclusively (same goes for CPU, but for GPU it might be even more obvious).

Re: Port Direct3D?

Posted: Fri Jun 21, 2013 10:59 pm
by dozniak
BMW wrote:My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.
If he disables all the trojans he downloaded from the web sites, together with the antivirus that keeps them at bay, performance might noticeably increase without ever writing a new operating system.

Re: Port Direct3D?

Posted: Sat Jun 22, 2013 1:00 am
by Kazinsal
dozniak wrote:
BMW wrote:My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.
If he disables all the trojans he downloaded from the web sites, together with the antivirus that keeps them at bay, performance might noticeably increase without ever writing a new operating system.
An even better and much more efficient way to increase performance is acquiring better hardware.

Re: Port Direct3D?

Posted: Sat Jun 22, 2013 12:04 pm
by Mikemk
XanClic wrote:
BMW wrote:My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.
Certainly it would be. Easiest way would be modifying Windows to boot directly into the desired program.
If im not mistaken, theres a command line trick/glitch in safe mode to do this.

Re: Port Direct3D?

Posted: Sat Jun 22, 2013 2:06 pm
by FallenAvatar
m12 wrote:
XanClic wrote:
BMW wrote:My little brother suggested that I make an OS with just one program running - his favourite game (which uses Direct3D) so he could get better performance, so I was wondering whether that would be possible.
Certainly it would be. Easiest way would be modifying Windows to boot directly into the desired program.
If im not mistaken, theres a command line trick/glitch in safe mode to do this.
Its actually easy than that, just open regedit and navigate to HKLM>Software>Microsoft>Windows NT>CurrentVersion>Winlogon and replace explorer.exe with whatever you want.

Or for a temporary solution, just open task manager, kill explorer and then File->New task to run only what you want.

- Monk

EDIT: The above is for Windows 7, tho it should be almost identical on other versions of windows.

Re: Port Direct3D?

Posted: Sat Jun 22, 2013 10:46 pm
by BMW
dozniak wrote: If he disables all the trojans he downloaded from the web sites, together with the antivirus that keeps them at bay, performance might noticeably increase without ever writing a new operating system.
Yeah... That's about it with my brother... no clue whatsoever. Installs anything and everything to try and get what he wants. Then asks me why there are all these gay toolbars in his browser. :evil:

Re: Port Direct3D?

Posted: Sun Jun 23, 2013 1:46 pm
by Mikemk
BMW wrote:
dozniak wrote: If he disables all the trojans he downloaded from the web sites, together with the antivirus that keeps them at bay, performance might noticeably increase without ever writing a new operating system.
Yeah... That's about it with my brother... no clue whatsoever. Installs anything and everything to try and get what he wants. Then asks me why there are all these gay toolbars in his browser. :evil:
Sounds like my brother on my Google Account.

Re: Port Direct3D?

Posted: Thu Jul 25, 2013 9:16 am
by AndrewAPrice
BMW wrote:Would it be possible to port Direct3D to my OS?

I could port OpenGL, then make all the D3D functions as wrappers that call corresponding OpenGL functions.

Now that would annoy Microsoft. :D
Yes.. Kind of..

Porting Direct3D to OpenGL:

It is possible. It's not as simple as simply wrapping functions though. 10 years ago, most Direct3D applications used what was called the Fixed Function Pipeline - you pass in textures, vertices, indices, configure the operators and lighting - call Draw() and away you go. Wrapping these Direct3D calls with OpenGL is trivial.

However, Direct3D 8.1 (2001) introduced shaders. Shaders are small programs that are executed on the GPU. At first, they were limited to pixel shaders (executed per pixel) and vertex shaders (executed per vertex) - you could run calculations on the GPU much faster than the CPU, and customize it with your own lighting, blending, or transformation algorithms. This is know as the Programmable Pipeline.

Shaders were optional in Direct3D 8.x and 9.x - there was still the Fixed Function Pipeline to fall back up, but within 5 years of their introduction they became near universal in most graphics applications, because of the flexibility and speed they provided. Direct3D 10 (2006) dropped support for the Fixed Function Pipeline completely. Everything was done in shaders. Over the years, new shader types have been introduced (geometry shaders, multiple types of tessellation shaders, computation shaders.)

Most of these shaders are written in a C-style language (HLSL for Direct3D and GLSL for OpenGL) and are compiled down to byte code representation that's specific to the API, and uploaded to the GPU (does the GPU execute this directly or the driver JITs it? I don't know.)

The problem is that Direct3D's shader byte code is incompatible with the byte code used by OpenGL. Many Direct3D to OpenGL wrappers either don't support the Programmable Pipeline/shaders - hence they allow you to play games from the early 2000s but fail with modern titles, or they spend a lot of time working on code that translates the bytecode from one representation to another. It's a large feat.

Emulating Direct3D
It's fully possible to emulate Direct3D. There are many drop in "d3d9.dll" solutions that will software emulate Direct3D. You still have the shader problem - some emulate the shader bytecode, commercial solutions may attempt to JIT the bytecode to machine language.

If you do want to write your own software wrapper for Direct3D I recommend you emulate Direct3D 10. Why? It's very barebones. They stripped all of the legacy fixed function stuff right out.. There is no need to deal with legacy lighting, blending, animation, transformation code out. It's all done in shaders now. For you, that means you just need to write a bytecode interpreter, some trivial code to load different types of data structures, and away you go.

Re: Port Direct3D?

Posted: Thu Jul 25, 2013 4:53 pm
by sortie
I would probably have a look at Wine, as it contains a DirectX implementation upon OpenGL.