• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
angelmu88

Support Directx 9 and Directx 11 (both)

17 posts in this topic

Hi!
I have my own graphic engine written in DirectX 9.0c. Now I want to add new DirectX 11 features like hardware tesselation, but I don't want to rewrite the whole code, I just want to support both DirectX 9 and DirectX 11. For instance, Unreal let you switch between a DirectX 9 renderer and a DirectX 11 one.
How could I do that as soon as posible?
Thanks!
1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1346510528' post='4975436']
[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code[/quote]Any of your code that interacts with the Direct3D API will need to be re-written.

Have you written your own D3D wrapper so that only some of your code interacts with D3D directly ([i]and the rest interacts with your wrapper[/i]), or does your whole engine use parts of D3D?
[/quote]

No, not all my code interacts with D3D. In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?
1

Share this post


Link to post
Share on other sites
You would also link the program against both DX in Delay Download DLL or load them by LoadLibrary.
It would work on legacy and future Windows versions.
1

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1346514567' post='4975460']
[quote name='angelmu88' timestamp='1346511579' post='4975439']
In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?
[/quote]Yes that's what I meant. So, the lower level of your hierarchy, which deals directly with D3D9, will have to be entirely re-written [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
Large parts of it may be similar in the D3D11 rewrite, but none of it will likely be reusable without modification.

I would recommend separating your D3D9 and D3D11 code via [font=courier new,courier,monospace]#ifdef[/font]s, and only compiling for one at a time ([i]which means you've got two different EXEs - one for people on WinXP, and one for people on Win7[/i]).
However, you could alternatively make your "wrapper" into abstract-base-classes with virtual methods if that's more attractive to you.
[/quote]

The good thing about the second option (virtual methods) is that I only have one .exe and I can decide wheter I use D3D9 or D3D11 at run-time, isn't it?

Actually I was looking in the Crysis 2 installation folder (Crysis 2 let you use both D3D9 and D3D11) and I found only one .exe(Crysis2.exe) and two dll's :one for D3D9 (CryRenderD3D9.dll) and another for D3D11(CryRenderD3D11.dll); So I supose they're using something similar to the "virtual method approach". Am I right? Edited by angelmu88
1

Share this post


Link to post
Share on other sites
[quote name='hupsilardee' timestamp='1346521721' post='4975489']
[quote name='angelmu88' timestamp='1346515907' post='4975466']
[quote name='Hodgman' timestamp='1346514567' post='4975460']
[quote name='angelmu88' timestamp='1346511579' post='4975439']
In most cases I tried to create a hierarchical model, so I have classes that interacts directly with D3D (basic classes) and classes that only use those basic classes and do not interact with D3D. is that what you mean?
[/quote]Yes that's what I meant. So, the lower level of your hierarchy, which deals directly with D3D9, will have to be entirely re-written [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img]
Large parts of it may be similar in the D3D11 rewrite, but none of it will likely be reusable without modification.

I would recommend separating your D3D9 and D3D11 code via [font=courier new,courier,monospace]#ifdef[/font]s, and only compiling for one at a time ([i]which means you've got two different EXEs - one for people on WinXP, and one for people on Win7[/i]).
However, you could alternatively make your "wrapper" into abstract-base-classes with virtual methods if that's more attractive to you.
[/quote]

The good thing about the second option (virtual methods) is that I only have one .exe and I can decide wheter I use D3D9 or D3D11 at run-time, isn't it?

Actually I was looking in the Crysis 2 installation folder (Crysis 2 let you use both D3D9 and D3D11) and I found only one .exe(Crysis2.exe) and two dll's :one for D3D9 (CryRenderD3D9.dll) and another for D3D11(CryRenderD3D11.dll); So I supose they're using something similar to the "virtual method approach". Am I right?
[/quote]

Actually if ou think about it, this means they used the #ifdef approach, because there are 2 different DLLs. I expect this is because there is overhead with virtual functions (very very small), and they want their graphics to run as quickly as possible
[/quote]

But #ifdef is a preprocessor directive, that means you have to recompile every time you change from D3D9 to D3D11 (or from D3D11 to D3D9). You could aslo have two .exe files but as I said there's only one .exe and I don't think they recompile every time you enable or disable D3D11 in the options menu. Maybe there's another option I'm missing. Edited by angelmu88
1

Share this post


Link to post
Share on other sites
[quote name='angelmu88' timestamp='1346523324' post='4975499']

But #ifdef is a preprocessor directive, that means you have to recompile every time you change from D3D9 to D3D11 (or from D3D11 to D3D9). You could aslo have two .exe files but as I said there's only one .exe and I don't think they recompile every time you enable or disable D3D11 in the options menu. Maybe there's another option I'm missing.
[/quote]

Hi i think they use one interface for their rendering system and derive renderers from this interface. It's really clean and easy solution, you can also switch between renderers at runtime. And about virtual method overhead -> don't bother unless you have milions of calls per frame
1

Share this post


Link to post
Share on other sites
[quote]

Hi i think they use one interface for their rendering system and derive renderers from this interface. It's really clean and easy solution, you can also switch between renderers at runtime. And about virtual method overhead -> don't bother unless you have milions of calls per frame
[/quote]

Yes. I agree with you. I think they have a Renderer Interface and they store the derived renderers in CryRenderD3D9.dll and CryRenderD3D11.dll.
I also think when you start the game, depending on the renderer selected, they do something like this:

[source lang="cpp"]
#include "CryRenderD3D9.h"
#include "CryRenderD3D11.h"

Renderer* renderer;

if(D3D11enabled)
renderer = new D3D11Renderer();
else
renderer = new D3D9Renderer();
[/source]

On second thought this is not completely dynamic because you have to reset the App every time you change the renderer but you don't need two .exe files like in the #ifdef approach. I think Crysis 2 does something similar because if you change the renderer in the Crysis 2 option menu you have to reset the game. Edited by angelmu88
0

Share this post


Link to post
Share on other sites
[quote name='L. Spiro' timestamp='1346579761' post='4975676']
They are using #ifdef. One build compiles to a DirectX 9.0 .DLL, another to a DirectX 11 .DLL. The .EXE has no idea what DirectX is and is not linking to either of them.
The .DLL simply provides an agnostic interface for rendering and the .EXE loads one or the other at run-time based on parameters passed to it.


L. Spiro
[/quote]

Yes, I'm not saying they didn't use #ifdef to create the dlls, what I say is that the .exe does something similar to the code I posted (the .exe doesn't use #ifdef). Edited by angelmu88
0

Share this post


Link to post
Share on other sites
Actually the .EXE will only have branches for which DLL to load.
Both DLL’s probably expose the same classes, so the EXE is more likely to just do a check on the input flags and branch for just the DLL, followed by something like:

[CODE]Render * prRenderer = new Renderer();[/CODE]


L. Spiro
1

Share this post


Link to post
Share on other sites
[quote name='L. Spiro' timestamp='1346588330' post='4975704']
Actually the .EXE will only have branches for which DLL to load.
Both DLL’s probably expose the same classes, so the EXE is more likely to just do a check on the input flags and branch for just the DLL, followed by something like:

[CODE]Render * prRenderer = new Renderer();[/CODE]


L. Spiro
[/quote]

what would be the code for that flag-based branching?
I can't figure it out without using LoadLibrary, and I don't like LoadLibrary because then you have to get pointers to every function you use (In addition there's overhead when calling through a function pointer). Edited by angelmu88
0

Share this post


Link to post
Share on other sites
[quote name='phantom' timestamp='1346592597' post='4975720']
You'd only have to get a function pointer for creating the Renderer; after that you use the returned pointer as normal.

The cost is going to be no worse than a non-inlined function call at that point.

1. Decide which DLL to load
2. Load DLL
3. Get pointer to creation function
4. Use creation function to create renderer
5. Use returned object pointer as normal

No mess, no fuss.
[/quote]

I got it.
Thank you very much!
0

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1346510528' post='4975436']
[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code[/quote]Any of your code that interacts with the Direct3D API will need to be re-written.

Have you written your own D3D wrapper so that only some of your code interacts with D3D directly ([i]and the rest interacts with your wrapper[/i]), or does your whole engine use parts of D3D?
[/quote]

wait what about feature levels? http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876(v=vs.85).aspx
0

Share this post


Link to post
Share on other sites
[quote name='mrheisenberg' timestamp='1346785908' post='4976535']
[quote name='Hodgman' timestamp='1346510528' post='4975436']
[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code[/quote]Any of your code that interacts with the Direct3D9 API will need to be re-written [for the Direct3D11 API].
[/quote]wait what about feature levels? http://msdn.microsoft.com/en-us/library/windows/desktop/ff476876(v=vs.85).aspx
[/quote]Features levels are a part of the D3D11 API that allows you to use that API on older hardware (e.g. DX9 compatible hardware).
If you wanted to use the "9 on 11" feature level, you'd still have to port your renderer over to the D3D11 API first.

Also, for some stupid reason, there's no DX11 feature-level that corresponds to SM3.0, so if you want to support SM3 ([i]360/PS3 level hardware[/i]) then you've still got to maintain the DX9 version of your renderer :/
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0