Support Directx 9 and Directx 11 (both)

Started by
16 comments, last by Hodgman 11 years, 7 months ago
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!
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
Advertisement
but I don't want to rewrite the whole code
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 (and the rest interacts with your wrapper), or does your whole engine use parts of D3D?

[quote name='angelmu88' timestamp='1346507798' post='4975431']but I don't want to rewrite the whole code
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 (and the rest interacts with your wrapper), 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?
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/
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.

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?
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 sad.png
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 (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
However, you could alternatively make your "wrapper" into abstract-base-classes with virtual methods if that's more attractive to you.

[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?
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 sad.png
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 (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
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?
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/

[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?
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 sad.png
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 (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
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 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?
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 sad.png
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 (which means you've got two different EXEs - one for people on WinXP, and one for people on Win7).
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.
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/


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.


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


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.
My 3D graphic engine: http://graphicprogramming.wordpress.com/rebirthengine/
My blog: http://graphicprogramming.wordpress.com/

This topic is closed to new replies.

Advertisement