Slashdot Mirror


Valve Open Sources Their DirectX To OpenGL Layer

jones_supa writes "A bit surprisingly, Valve Software has uploaded their Direct3D to OpenGL translation layer onto GitHub as open source. It is provided as-is and with no support, under the MIT license allowing you to do pretty much anything with it. Taken directly from the DOTA2 source tree, the translation layer supports limited subset of D3D 9.0c, bytecode-level HLSL to GLSL translator, and some SM3 support. It will require some tinkering to get it to compile, and there is some hardcoded Source-specific stuff included. The project might bring some value to developers who are planning to port their product from Windows to Linux."

34 of 130 comments (clear)

  1. Winelib by Wootery · · Score: 5, Interesting

    Could this be of use to the Winelib project?

    (As the name implies, it's the compile-time analogue of Wine.)

    1. Re:Winelib by Anonymous Coward · · Score: 4, Interesting

      Possibly, I havn't looked at the source yet. But the readme says its a subset of the DirectX 9.0c features, making it not only obsolete, but incomplete. Fortunately, its open source so a bit of wrangling could make it swallow dx10 and 11

    2. Re:Winelib by Anonymous Coward · · Score: 3, Insightful

      Could this be of use to the Winelib project?

      (As the name implies, it's the compile-time analogue of Wine.)

      Probably not. The wine guys tend to be more or less anti toward anything that they didn't write and thus can assert that it's not infringement on Microsoft's source code. Accepting that much code from Valve sounds very risky for them.

    3. Re:Winelib by JDG1980 · · Score: 4, Insightful

      Probably not. The wine guys tend to be more or less anti toward anything that they didn't write and thus can assert that it's not infringement on Microsoft's source code. Accepting that much code from Valve sounds very risky for them.

      Valve isn't some fly-by-night operation. They almost certainly have more exposure to legal liability than the Wine project would.

    4. Re:Winelib by Richard_at_work · · Score: 4, Informative

      Odd considering their (Wines) last copyright cockup was entirely due to an internal contributor committing decompiles of Microsoft binaries as contributed code...

    5. Re:Winelib by LoRdTAW · · Score: 5, Insightful

      Hold on, The subset of DX9.0c is probably the Xbox360 native API: http://en.wikipedia.org/wiki/Comparison_of_OpenGL_and_Direct3D#Gaming

      The original Xbox supported Direct3D 8.1 as its native API while the Xbox 360 supports a modified version of Direct3D 9.0c as its native API.

      This could be useful for studios looking to port Xbox360 titles to the Steam Box platform. It makes sense as there are a lot of titles that could see a sort of resurrection on Steam and bring in some more money. It is also possibly the same D3D API subset used for Windows Phone 8.

  2. On the road to replacing DirectX by Anonymous Coward · · Score: 5, Insightful

    With a big company (in terms of money) like Valve pushing OpenGL there is a real chance DirectX will face serious and permanent competition. We will finally have a serious alternative to the suffocating model of forcing a new operating system down peoples throat through software. It worked great with the browser, now lets hope Valve can make it happen for games.

    1. Re:On the road to replacing DirectX by CastrTroy · · Score: 4, Insightful

      I think that only worked so well for the browser because MS let IE stagnate for so long. I don't think they are doing the same with DirectX. DirectX continues to evolve and stay up to date. It's one thing to convince the non-programmer, general computer user to keep using mediocre tools, it's a whole other story to try and get developers to do the same.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    2. Re:On the road to replacing DirectX by MBGMorden · · Score: 2

      Newsflash: IE still has >50% market share.

      Um, no. Depending on what site you're looking at it might go up or down, but nobody is ranking IE at over 50% anymore. W3 is actually reporting IE at around 20% these days:

      http://www.w3counter.com/globa...

      --
      "People who think they know everything are very annoying to those of us who do."-Mark Twain
    3. Re:On the road to replacing DirectX by Anonymous Coward · · Score: 3, Insightful

      In light of the fact that OpenGL's more portable to more platforms, it's not as hard a sell as you'd think. Esp. for more casual games. Want to target iOS and Android? You'll be doing OpenGL ES 2.x. The same game will target PS3, PS4, OSX, Linux, and Steam/SteamBox with only a few modifications.

    4. Re:On the road to replacing DirectX by Anonymous Coward · · Score: 2, Insightful

      Since OpenGL is the only language to run on mobile, and Mac, and Linux plus it's available on all the consoles it seems kind of crazy to target anything else if your code is expected to survive for any length of time given the decline of the Windows PC market.

    5. Re:On the road to replacing DirectX by TyFoN · · Score: 2

      And the reason those 20% still use it is because of company lock-in / legacy web apps.

      Even my almost 70 year old mother is on Firefox without me being involved.

    6. Re:On the road to replacing DirectX by jones_supa · · Score: 3, Informative

      It was only AMD speculation (which also happened to fit nicely with their Mantle strategy). DirectX 12 is now confirmed.

    7. Re:On the road to replacing DirectX by bloodhawk · · Score: 3, Insightful

      It was a garbage rumor back then that was only believed by those with a heavy anti MS bias and is even more so now given the next version has been announced.

    8. Re:On the road to replacing DirectX by JDG1980 · · Score: 5, Interesting

      Swapping to OpenGL provides significantly less functionality than DirectX as DirectX isn't just a graphics API.

      Pretty much all aspects of DirectX except for Direct3D have been deprecated by Microsoft. They still work, but aren't recommended for new code, and have been superseded by other APIs.

    9. Re:On the road to replacing DirectX by LoRdTAW · · Score: 4, Insightful

      OpenGL is pretty much used everywhere but Microsoft targeted games (Windows and Xbox). Using DirectX on Windows games allowed them to be portable between PC and the Xbox so more and more games went the D3D route to remain portable between the two.

      I believe almost all CAD and 3D modelling software are OpenGL based. Android and iOS use OpenGL ES while any non Windows OS such as Linux and OSX use OpenGL for 3D graphics. With the big push to mobile and Microsoft left in the dust, OpenGL is the dominant player.

    10. Re:On the road to replacing DirectX by wertigon · · Score: 5, Informative

      If you're going to be nitpicky, then yes, it's SDL+OpenGL.

      However, the only DirectX system still relevant in Win8.1 is Direct3D. Everything else has been removed;

      DirectDraw - Repaced by Direct2D
      DirectInput - Replaced by XInput
      DirectSound - Replaced by XAudio2
      DirectMusic - Legacy MIDI format - also replaced by XAudio2
      DirectPlay - A complete joke, replaced by Games for Windows Live and XB Live.
      DirectX Media/Media Objects: Deprecated and replaced/removed by all of above

      That leaves DirectWrite and Direct2D as the only relevant (and minor) DIrectX components left. So yes, DX is more than a graphics API; these days and for gaming though, the only thing being used is D3D in DX.

      --
      systemd is not an init system. It's a GNU replacement.
    11. Re:On the road to replacing DirectX by DrXym · · Score: 5, Informative
      OpenGL is definitely more portable than DirectX but that's not to say it's portable with a few modifications. There are various OpenGL and OpenGL ES profiles, and while they are related they can be radically different in important ways. For example OpenGL ES 1.1 and 2.0 are totally incompatible despite what you might think - 1.1. uses a fixed function pipeline and 2.0 expects you to write shaders for basically everything. OpenGL ES 2.x is roughly but not completely a subset of OpenGL 2.1. Every version of OpenGL supports a different selection of extensions.

      Aside from the differences on paper, the actual implementations can be broken, buggy or inefficient. e.g. Some older desktop drivers might not offer an ES 2.x profile, or it could be hopelessly crap.

      There is no GLU / GLUT either for ES 2.x and every platform implements its own equivalent but proprietary set of APIs. So you may discover a lot of work is required to fix that. Then you may discover that one platform or language's bindings are different from another in subtle but annoying ways, e.g. there are several OpenGL ES 2.x bindings for Java and one might return a handle in an int[] array while another expects you to supply a 1-element sized IntBuffer. Annoyances which add up.

      In summary, yes you can port code, and OpenGL is definitely one family of APIs that offers support across a wide selection of devices. But it's not guaranteed to be simple and probably won't be. The best bet is use a good third party library (e.g. libgdx) and let the library hide as much of the work as possible.

    12. Re:On the road to replacing DirectX by Ardyvee · · Score: 2

      You want OpenAL for audio.

      --
      I don't care if I'm wrong. I only care about everyone obtaining something from the discussion.
    13. Re:On the road to replacing DirectX by Jakeula · · Score: 2

      You're correct that it seems like OpenGL is playing catch up with D3D, but to assume that it will *NEVER* get ahead of the curve is quite an assumption. The Linux Kernel took years of playing catch up, and now its just as modern as anything else (as a pure kernel). If Valve is moving to OpenGL and others follow Valve, then it stands to reason that Khronos will likely be able to make strides and eventually close the gap. Right now more graphically driven things are done on Windows (gaming), so of course it has the best tools for the job. However, the tides are slowly changing, and if they change in a quality fashion, I see no reason OGL has to stay in the back seat. I say this as someone with limited experience dealing with both OpenGL and Direct3D.

  3. Makes sense by mwfischer · · Score: 2

    Valve makes money with Steam.

    Valve has hammered out a useful content delivery platform for Linux and OS X.

    Valve makes it easier to translate DX to OGL.

    Collect profit... eventually.

    1. Re:Makes sense by RaceProUK · · Score: 4, Insightful

      If only it was MIT-licensed so people could club together and add support for the rest of Dx9 (and 10 and 11 while they're at it)...

      --
      No colour or religion ever stopped the bullet from a gun
    2. Re:Makes sense by Carewolf · · Score: 4, Informative

      A limited subset, as in every PC game that still supports WinXP. Which is practically all of them.

    3. Re:Makes sense by Anonymous Coward · · Score: 2, Informative

      The majority of games on Valve's catalogue use D3D9.0c. That could be what they're aiming for - the huge collection of DX9 games already there.

    4. Re:Makes sense by jones_supa · · Score: 2

      They probably simply aimed to get the Source engine ported, which happens to be DX9-based. That there are lots of other DX9 games is a nice side effect.

  4. Re:performance? by Anonymous Coward · · Score: 2, Informative

    Valves presentation on the topic http://adrienb.fr/blog/wp-content/uploads/2013/04/PortingSourceToLinux.pdf states better performance using togl for their games (togl starts at slide 18, performance is mentioned on 23).

  5. Lessons learned by jones_supa · · Score: 5, Informative

    If you are interested in this stuff, the Porting Source to Linux: Valve's Lessons Learned is also good watch, if you haven't seen it yet.

  6. Re:performance? by Creepy · · Score: 4, Informative

    Yeah, probably minimal, since it is bytecode level (what HLSL and GLSL compile into)

    The bad - this is DX 9.0c, which is analogous to OpenGL 2.0 (with extensions - note that ATI drivers didn't support extensions at the time, so more like 2.2+ for them) and in console terms, XBox 360/PS3 tech. OTOH, OpenGL went through a major paradigm shift with OpenGL 3 and 4 that make it work more like HLSL, so I expect shader conversion is much easier. When I ported a DX10 shader to OpenGL 3 it was much easier (but much harder was porting the entire OpenGL 2 project to 3).

  7. Re:Any replies will be immediately upmodded! by Anonymous Coward · · Score: 5, Interesting

    Boobs

  8. Re:question by Creepy · · Score: 2

    It runs on OSX and Linux, neither of which have native DirectX support because Microsoft keeps their graphics technology under tight wraps. All implementations of it not shipped by Microsoft need to be reverse engineered from the API. OpenGL is licensed to hardware manufacturers (which is how development is paid for) and accessing the API is free for software developers.

  9. Re:question by Cley+Faye · · Score: 3, Insightful

    My guess it that they were doing a "two birds with one stone" strategy - using this project as an excuse (and test-case) for the translation layer, hoping that some devs would take this opportunity to port their DX9 games to Linux because of it, thereby improving the value of SteamOS.

    Another option is that they didn't write DOTA2 from scratch, but reused an existing engine. Which in turn was based on some previous works, and at some point Direct3D was used, and remained there the whole time.

  10. Going the other way like Microsoft does... by tlambert · · Score: 5, Informative

    Going the other way like Microsoft does is more interesting.

    One of the biggest issues with OpenGL is that you can get shaders that won't run in bounded time. You can see this with a number of games in Flash, or natively in OpenGL, when run on a Mac. If the shader doesn't exit, it eats a channel, and there are a limited number of channels, and once they are gone, the renderer, which is also used for the desktop, basically crashes. There are nice system log messages from the video driver about it, but besically everything ends up restarted, which is pretty useless.

    FWIW: this accounts for the majority of system instabilities in the card specific portions of both Mac OS X and Linux render pipelines.

    DirectX doesn't allow things to run in unbounded time in its OpenGL to DirectX translator; instead, it loop unrolls shaders, and if it can't do that such that they run linearly, and therefore in bounded time, it omits them from the render. So you might not get distance blurring, haze effects, fog effects, rain effect, and so on, but at least the thing doesn't crash, and if the person porting the code to the Windows platform cares about these things, they fix the code so that it'll run using DirectX. Usually, this reduced the perceived "quality" of the final render, but you get at least a crude version of your effect back.

    The other thing DirectX does is, in the video driver, keep a reserve channel for sending commands to the video hardware; the common reason for this is in-band signaling to comply with the DirectX 9 requirement that the video hardware be capable of being reset, without rebooting the system, such that a video card hang doesn't necessitate a reboot.

    While a DirectX to OpenGL translation layer is a nifty idea (I lobbied very hard for a FreeBSD emulator for Linux, rather than a Linux emulator for FreeBSD so that developers would target FreeBSD rather than Linux as their development platform), I don't think that as long as the OpenGL shader looping issues don't also get addressed at the translation layer that translating from DirectX to OpenGL will be in anyway superior to translating from OpenGL to DirectX.

    So basically, it's nice they released this, but the code is of little practical use in the real world, since there are features that will get lost in translation.

    1. Re:Going the other way like Microsoft does... by Windwraith · · Score: 2

      Strange, I use and code plenty of games using shaders like that, and I run KDE4 in Linux, in both GL composite and regular X11 mode, and have never experienced any crash like you describe. Is it because I use Nvidia drivers or something, or maybe because I happened to have had the luck to only play games that do it right, and had the luck to never code any shaders triggering that? Seems rather unlikely, but I am genuinely curious here.

  11. Re:question by Anonymous Coward · · Score: 3, Interesting

    Speaking as someone who's written a native D3D 9.0c implementation from scratch (on the PS3), implementing it is not the issue. I probably implemented the exact same subset as Valve did - only the shader-driven part, no fixed-function emulation - and it took maybe 4 weeks total (160 hrs). My implementation was 10x faster (seriously) than the D3D 9.0c implementation on X360. (That's CPU usage of the API; obviously the GPU ran at comparable rates. The X360 port team on the project I was on hit frame rate just issuing too many D3D calls, while the PS3 port was running the exact same D3D calls using 10% of the CPU. It correctly handled locking, sync, cache flushes, etc. so it gave the exact same guarantees as the real D3D; I guess Microsoft's 9.0c still had a lot of Windows cruft in it's X360 incarnation. Probably doing too many kernel transitions - I had zero except at the end of the frame.)

    The reason I never turned this into a product and sold it was because to get the D3D 9.0c headers you have to accept an EULA that says it's all confidential, and my dog simply isn't in that fight. Valve's dog is in that fight now, but they have a much bigger dog than I do. Using their code as a starting point I could in theory release my code now (only to PS3 developers though because of Sony's NDAs ... and that's no click-through EULA, that's a cast iron contract between my company and Sony). A bit late though, who the hell needs D3D 9.0c on PS3 in 2014? Direct3D 12 on PS4, now that might be worth considering ...