Port Direct3D?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Port Direct3D?

Post 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
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Port Direct3D?

Post by Love4Boobies »

ReactX works that way.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Port Direct3D?

Post by BMW »

Love4Boobies wrote:ReactX works that way.
Oh nice... I must check out ReactOS.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Port Direct3D?

Post 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.
Learn to read.
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: Port Direct3D?

Post 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.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Port Direct3D?

Post 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.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: Port Direct3D?

Post 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).
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: Port Direct3D?

Post 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.
Learn to read.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Port Direct3D?

Post 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.
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Port Direct3D?

Post 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.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
FallenAvatar
Member
Member
Posts: 283
Joined: Mon Jan 03, 2011 6:58 pm

Re: Port Direct3D?

Post 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.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Port Direct3D?

Post 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:
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Mikemk
Member
Member
Posts: 409
Joined: Sat Oct 22, 2011 12:27 pm

Re: Port Direct3D?

Post 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.
Programming is 80% Math, 20% Grammar, and 10% Creativity <--- Do not make fun of my joke!
If you're new, check this out.
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Port Direct3D?

Post 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.
Last edited by AndrewAPrice on Tue Aug 06, 2013 12:55 pm, edited 6 times in total.
My OS is Perception.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Port Direct3D?

Post by sortie »

I would probably have a look at Wine, as it contains a DirectX implementation upon OpenGL.
Post Reply