Supporting Multiple DirectX Versions

Started by
14 comments, last by ryan20fun 9 years, 3 months ago

Hello,

I have interface IRenderer, two classes are derived from this interface IDX9Renderer and IDX11Renderer.

Now, I'm trying to be able to support either DX9 or DX11 in my engine

So my question is: How IRenderer interface structure should look like?

For example:


IRenderer::createVertexBuffer(...);
IRenderer::draw(...);

What to put in the above methods as a parameter so I can use it in both classes IDX9Renderer and IDX11Renderer?

Advertisement
If you want to follow this path, you need to create functions in the renderer class that apply to both the dx9 and dx11 inherited classes. Everything dx9/dx11 specific you can add (members and functions) to the inherited classes.

Just out of curiosity, why go though this at all? Since all gpu's from 3 years old and younger (by head) support dx11. Plus windows xp isn't supported anymore (and I believe not often used among gamers). Of course if it's just for practice then it's another case.

I created an engine which I've been working on for years using dx9. But it's set up quite modular and flexible so later on I can "update" it to dx11.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

@cozzie: The reason why is that I want to be able to add any future version of DirectX to the engine.

I'm still not sure what the correct rendering interface IRenderer should look like.

class IRenderer
{
// generic renderer stuff
}

class IDirectX9Renderer : public IRenderer
{
// specific dx9 stuff
}

If this is not what you're looking for, then maybe can you be a bit more specific.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

@cozzie: That's already what I have, now I'm not sure what the correct parameters that I should put here so I can support multiple version of DX:


IRenderer::createVertexBuffer(...);
IRenderer::createIndexBuffer(...);
IRenderer::draw(...);

@cozzie: That's already what I have, now I'm not sure what the correct parameters that I should put here so I can support multiple version of DX:


IRenderer::createVertexBuffer(...);
IRenderer::createIndexBuffer(...);
IRenderer::draw(...);

I would say that you should start by doing a low level abstraction of the one you want your interface to emulate.

Right now I have a "ResourceCreator" class that you can get after you load the library(DLL), This in tern is used to create any type of resource that is supported.

An example of my index buffer's create method(I do need to make alowance for 2byte indices):


/*! This creates the vertex buffer with the specified number of elements and in the specified memory pool.
*
*	Parameters:
*		Elements	: The number of elements of length of sizeof( pIndices[ 0 ] ).
*		pIndices	: A pointer to the index data to use for creation.
*		Topology	: How the elements will be use to create the rendering surface.
*		Usage		: The usage pattern to apply to this resource.
*		CPUAccess	: What access should the CPU have to this resource.
*/
DLLEXPORT virtual HRESULT Create( const unsigned Elements, const unsigned* pIndices,
								  const PrimitiveTopology Topology = PrimitiveTopology::TriangleList,
								  const UsageType Usage = UsageType::Immutable,
								  const CPUAccess CPUAccess = CPUAccess::None ) = NOT_IMPLEMENTED;


And the vertex buffer:


/*! This creates the vertex buffer with the specified number of elements.
*
*	Parameters:
*		Elements	: The number of elements of length of Description.length().
*		Description	: The layout of each element in memory.
*		pVertices	: A pointer to the vertex data to use for creation.
*		Usage		: The usage pattern to apply to this resource.
*		CPUAccess	: What access should the CPU have to this resource.
*/
DLLEXPORT virtual HRESULT Create( const unsigned Elements, const Vertex::Layout Description,
								  const void* pVertices, UsageType Usage = UsageType::Immutable,
								  const CPUAccess CPUAccess = CPUAccess::None ) = NOT_IMPLEMENTED;

HTH

Ryan.

Never say Never, Because Never comes too soon. - ryan20fun

Disclaimer: Each post of mine is intended as an attempt of helping and/or bringing some meaningfull insight to the topic at hand. Due to my nature, my good intentions will not always be plainly visible. I apologise in advance and assure you I mean no harm and do not intend to insult anyone.

What is the purpose of DX9 support? If it is for old hardware instead of Windows XP you can use Direct3D feature levels to target SM 2.x and SM 3.0 GPUs (keep in mind that you will unable to use SM 3.0 features) https://msdn.microsoft.com/en-us/library/ff476876.aspx

Otherwise as suggested you should write different rendering path for D3D9 and D3D11 (write you own graphics API could be really challenging since DX9 and DX11 are really different in features).

"Recursion is the first step towards madness." - "Skegg?ld, Skálm?ld, Skildir ro Klofnir!"
Direct3D 12 quick reference: https://github.com/alessiot89/D3D12QuickRef/


Just out of curiosity, why go though this at all? Since all gpu's from 3 years old and younger (by head) support dx11. Plus windows xp isn't supported anymore (and I believe not often used among gamers). Of course if it's just for practice then it's another case.


What is the purpose of DX9 support?

As of Dezember 2014, Windows XP still holds 18,26% of market share according to this site:

http://www.netmarketshare.com/operating-system-market-share.aspx?qprid=10&qpcustomd=0

I don't know how much of those 18,26% are gamers, but it based on those numbers it could still be viable to support XP to get an increased userbase.


I don't know how much of those 18,26% are gamers

I'm not sure I'd trust these figures at all for gaming metrics, as it is based on Web browser useragent strings which are not relevant to what we are doing.

On the other hand steam records much better statistics of operating system usage: http://store.steampowered.com/hwsurvey

Edit: this shows about 4% XP users, 32 and 64 bit combined...

Right now there is a problem:

vs_4_0 is working in DX11 but NOT working in DX9

vs_3_0 is NOT working in DX11 but working in DX9

NOT working means HRESULT (E_FAIL) When calling Device::CreateVertexBuffer()

Why?

This topic is closed to new replies.

Advertisement