Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Graphics Layers for different for Directx11 and Directx12


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 BlackBrain   Members   -  Reputation: 364

Like
1Likes
Like

Posted 29 May 2014 - 02:28 AM

Hi .

 

Well I'm in the middle of developing a graphics engine and I heard about the Directx12 . I want that in future I can get Directx12 support to my engine with minimal effort . So I think I have to create a Graphics layer that objects call that and that layer get in to contact with the graphics API.

 

How should this be done ? Is there any standandard form ? any example ?



Sponsor:

#2 Hodgman   Moderators   -  Reputation: 32049

Like
13Likes
Like

Posted 29 May 2014 - 04:30 AM

My engine has 7 rendering back-ends, with plans to support 4 more, including D3D12 :D

The approach I take is that I have header files full of platform-agnostic structures/enum/interfaces/functions, e.g.
• an enum of comparison modes for depth testing,
• a struct describing the depth/stencil state,
• a device class, contexts, states, etc
• a CreateDevice function
etc

I then have many cpp files that implement then stuff in these headers, e.g. I'd have a single Device.h, and then Device_D3D11.cpp, Device_D3D9.cpp, etc...

I then compile the exe using only one set of these cpp files - e.g. I'd end up with Game_D3D11.exe, Game_D3D12.exe, etc...
You can then have a 'launcher' exe choose the right one automagically -- when the user runs Game.exe, it will check for D3D 12, 11 and 9 compatibility and then run the appropriate exe.


As for your actual platform-agnostic API, you need to take care in how you design it. If you model it on just one back-end-API, then that implementation will be a simple wrapper, but the implementations for other back-ends may involve complicated emulation.
You need to find a common abstraction that's easily implemented on all of your target back-ends.

#3 BlackBrain   Members   -  Reputation: 364

Like
0Likes
Like

Posted 29 May 2014 - 06:08 AM

That's nice . I think this the fastest way . Maybe function pointers come handy at this situation . Instead of havina a launcher the application can in realtime assign appropriate functions that the platform supports to the pointers . And then application moves on with calling only these function pointers .



#4 L. Spiro   Crossbones+   -  Reputation: 14447

Like
2Likes
Like

Posted 29 May 2014 - 06:48 AM

I then have many cpp files that implement then stuff in these headers, e.g. I'd have a single Device.h, and then Device_D3D11.cpp, Device_D3D9.cpp, etc...

This is what we do at work.
 

Maybe function pointers come handy at this situation . Instead of havina a launcher the application can in realtime assign appropriate functions that the platform supports to the pointers . And then application moves on with calling only these function pointers .

 
That would be a great way to make a mess of your code, and since the application would link to both Direct3D 11 and Direct3D 12, only people running Direct3D 12 could run it, making Direct3D 11 a useless parasitic twin.

If you took anything away from what Hodgman said let it be the part regarding multiple executables.  This is standard in the industry for a reason.

 

 

L. Spiro


Edited by L. Spiro, 29 May 2014 - 07:31 AM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 phantom   Moderators   -  Reputation: 7597

Like
7Likes
Like

Posted 29 May 2014 - 06:53 AM

That would be a great way to make a mess of your code, and since the application would link to both Direct3D 11 and Direct3D 12, only people running Direct3D 12 could run it, making Direct3D 11 a useless parasitic twin.


You could, of course, push the API specific code into a DLL and at runtime detect and load the correct DLL in which would remove that problem.

Granted, it brings with it other things to consider but it's also not an uncommon way to do things.

#6 BlackBrain   Members   -  Reputation: 364

Like
0Likes
Like

Posted 29 May 2014 - 10:07 AM

Since I am using c# there is no concept of headers or such things . What I am thinking right now is using interfaces , delegates and virtual methods to make things clear .

When I link direct3d11 and direct3d12 to my project (sharpdx versions in my case) they are loaded but as far as I don't initialize a device on direct3d12 is that going to cause a problem ?

When I don't initialize the direct3d12 device how is that going to cause a problem ?



#7 Alessio1989   Members   -  Reputation: 2134

Like
1Likes
Like

Posted 29 May 2014 - 11:06 AM

 

Since I am using c# there is no concept of headers or such things . What I am thinking right now is using interfaces , delegates and virtual methods to make things clear .

When I link direct3d11 and direct3d12 to my project (sharpdx versions in my case) they are loaded but as far as I don't initialize a device on direct3d12 is that going to cause a problem ?

When I don't initialize the direct3d12 device how is that going to cause a problem ?

 

At least you need to provide many final compiled objects (EXEs or DLLs) as many platform you want to support since if you put and link all together in a single executable you will require the final user to have a system supporting all those implementations!

 

As Hodgman and phantom suggested:

- you can provide many different executables as many platform you want to support (e.g.: game11.exe, game12.exe, gameOGL.exe)

- you pack every single API stuffs implementation into a DLL for each platform and then dynamically link the right DLL to the final executable depending on which platform the executable is running (eg: game.exe, gfx11.dll, gfx12.dll, gfxogl.dll)

 

You can also provide a luncher and let the user choose the implementation supported by the system, using one of the above solutions (eg: luncher.exe, game11.exe, game12.exe, gameOGL.exe OR luncher.exe, game.exe, gfx11.dll, gfx12.dll, gfxogl.dll).

 

In my opinion the DLL option is better for maintenance reasons. 

 

This matter is valid not only for graphics or gaming, but for every software that need to target multiple platforms and systems requirements.


Edited by Alessio1989, 29 May 2014 - 11:07 AM.

"Software does not run in a magical fairy aether powered by the fevered dreams of CS PhDs"


#8 MJP   Moderators   -  Reputation: 11846

Like
5Likes
Like

Posted 29 May 2014 - 11:53 AM

We also do things similar to how Hodgman described, except in our cases we have "Windows" and "PS4" platforms that extend into areas beyond just the graphics API's. 



#9 Armus   Members   -  Reputation: 577

Like
1Likes
Like

Posted 29 May 2014 - 01:01 PM

In my hobby project i have some abstract classes(interfaces) for graphics rendering like: Vertex Buffer, Shader, Texture etc.

Any new rendering system(OGL, DirectX) needs to implement those classes.

 

Also i'm loading it as .dll plugin so it libraries can be run-swapped and there is no need for recompiling code for those subsystems.

 

The biggest price you pay for this interfacing are cache misses which can damage your cpu performance, but for home projects that shouldn't be that big problem



#10 mhagain   Crossbones+   -  Reputation: 8286

Like
5Likes
Like

Posted 29 May 2014 - 04:41 PM

Since I am using c# there is no concept of headers or such things . What I am thinking right now is using interfaces , delegates and virtual methods to make things clear .

When I link direct3d11 and direct3d12 to my project (sharpdx versions in my case) they are loaded but as far as I don't initialize a device on direct3d12 is that going to cause a problem ?

When I don't initialize the direct3d12 device how is that going to cause a problem ?

 

To be honest I don't think you should be worrying about this right now.  D3D12 is at least a year away, we don't yet know what the interface is going to be like, so trying to pre-empt an unreleased API version doesn't seem like good sense.  It would be better to focus on doing a good job with D3D11 instead.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#11 Jason Z   Crossbones+   -  Reputation: 5446

Like
9Likes
Like

Posted 29 May 2014 - 07:48 PM


To be honest I don't think you should be worrying about this right now. D3D12 is at least a year away, we don't yet know what the interface is going to be like, so trying to pre-empt an unreleased API version doesn't seem like good sense. It would be better to focus on doing a good job with D3D11 instead.

I would echo this caution, and I'll actually be the dissenting voice in this discussion and say that you shouldn't try to abstract away the differences between D3D11 and D3D12.  D3D12 is supposed to be a superset of 11, except with more direct control over low level details so that you can squeeze the last few drops of performance out of your hardware.  If you try to make a common abstraction between 11 & 12, then you will end up muting the benefits of 12 without really gaining anything.  Assuming that D3D11 will be available anywhere that D3D12 is, then there isn't any benefit to supporting both on a common abstraction.

 

For pro studios, this makes sense to allow running your game on multiple platforms and supporting multiple APIs.  But if you can't gain anything from the common abstraction (due to D3D11 and 12 being together everywhere) then this system doesn't make much sense.  Instead, I would suggest that you write your D3D11 renderer now, and keep in mind any pain points you are encountering, then design a new renderer in about a year when D3D12 comes out that incorporates what you learned from the first time around.



#12 BlackBrain   Members   -  Reputation: 364

Like
0Likes
Like

Posted 30 May 2014 - 02:03 AM

Thanks every one . I've designed a renderer using xna ( http://www.gamedev.net/gallery/album/800-smile-engine/ )   . I decided to migrate to dx11 because I needed a lot of more modern things (atomic functions,compute shaders,tesselation) . At Least I know things that are possible now probably will be possible in dx12 too. I want to reuse my code as much as possible for future. Howecer, as mentioned we are not aware of the dx12 design . Maybe my code just makes it slower and no benefit from dx12.

But at least I need a level of abstraction because in future I probably want to support OpenGL too.



#13 andur   Members   -  Reputation: 638

Like
0Likes
Like

Posted 30 May 2014 - 07:17 PM

 

I then have many cpp files that implement then stuff in these headers, e.g. I'd have a single Device.h, and then Device_D3D11.cpp, Device_D3D9.cpp, etc...

This is what we do at work.
 

Maybe function pointers come handy at this situation . Instead of havina a launcher the application can in realtime assign appropriate functions that the platform supports to the pointers . And then application moves on with calling only these function pointers .

 
That would be a great way to make a mess of your code, and since the application would link to both Direct3D 11 and Direct3D 12, only people running Direct3D 12 could run it, making Direct3D 11 a useless parasitic twin.

If you took anything away from what Hodgman said let it be the part regarding multiple executables.  This is standard in the industry for a reason.

 

 

L. Spiro

 

 

Not entirely true. I've had success in the past with Direct3D 9 and 10 in the same executable by marking the D3D dlls as being delay loadable, and then checking for which version of Direct3D the user's system was capable of running and loading that rendering path.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS