Checking d3d caps, best approach?

Started by
15 comments, last by cozzie 11 years, 3 months ago

Hi,

Like any other enthousiast, before releasing my top selling FPS game, I'd like to make my 3d engine/ apps hardware variants proof smile.png

I see doing this with the following steps:

1. Check top 5 items while creating device and select 'lower' value if a specific adapter or bufferformat is not available (same for MSAA). Let's call this the basics (i.e. if MSAA not available, though requested, I select no MSAA and let the user continue). In place today and working fine.

2. Create a list of D3D (related) caps that are needed for the current functionalities, and check if these are available.
For now not available means, too bad. Application quits. I keep these up to date as soon as I add new functionality in my engine.

3. Create backwards compability variances for situaties in '2' where a device doesn't meet the requirements.
Same for the vertex and pixel shaders.

Step 3 is something I'll postpone for now, since I'm using D3D9 and PS/VS 2.0, which most devices today support.

I really to hear your advice and tips to make step 2 more efficient, I've posted the code I have now
(accepting that I send away users with hardware that doesn't meet the requirements smile.png)


bool CD3d::CheckDeviceCaps()
{
	int nrReqDevCaps = 9;
	DWORD reqDevCaps[9] =	{	D3DDEVCAPS_DRAWPRIMTLVERTEX,	D3DDEVCAPS_HWRASTERIZATION,		D3DDEVCAPS_TLVERTEXSYSTEMMEMORY, 
								D3DDEVCAPS_TLVERTEXVIDEOMEMORY, D3DPRASTERCAPS_ZBUFFERLESSHSR,	D3DPRASTERCAPS_ZTEST,
								D3DDEVCAPS_EXECUTESYSTEMMEMORY, D3DDEVCAPS_EXECUTEVIDEOMEMORY,  D3DDEVCAPS_TEXTUREVIDEOMEMORY };
	int nrReqPresentCaps = 3;
	DWORD reqPresentCaps[3] = {	D3DPRESENT_INTERVAL_ONE,		D3DPRESENT_INTERVAL_TWO,		D3DPRESENT_INTERVAL_IMMEDIATE };
	int nrReqTexFilterCaps = 4; 
	DWORD reqTexFilterCaps[4]= {D3DPTFILTERCAPS_MAGFLINEAR,		D3DPTFILTERCAPS_MINFLINEAR,		D3DPTFILTERCAPS_MIPFLINEAR,
								D3DPTFILTERCAPS_MINFANISOTROPIC };
	int nrReqPrimMiscCaps =3;
	DWORD reqPrimMiscCaps[3] = {D3DPMISCCAPS_CULLNONE,			D3DPMISCCAPS_CULLCW,			D3DPMISCCAPS_CULLCCW };
	int nrReqTextureCaps = 2;
	DWORD reqTextureCaps[2] = {	D3DPTEXTURECAPS_MIPMAP,			D3DPTEXTURECAPS_ALPHA };		// CUBEMAP and VOLUMEMAP later
	int nrReqTexAddrCaps = 5;
	DWORD reqTexAddrCaps[5] = {	D3DPTADDRESSCAPS_BORDER,		D3DPTADDRESSCAPS_CLAMP,			D3DPTADDRESSCAPS_WRAP,
								D3DPTADDRESSCAPS_INDEPENDENTUV,	D3DPTADDRESSCAPS_MIRROR  };
	int nrReqRasterCaps = 2;
	DWORD reqRasterCaps[2] = {	D3DPRASTERCAPS_ANISOTROPY,		D3DPRASTERCAPS_DITHER };
	int nrReqShadeCaps = 3;
	DWORD reqShadeCaps[3] = {	D3DPSHADECAPS_ALPHAGOURAUDBLEND,D3DPSHADECAPS_SPECULARGOURAUDRGB,
								D3DPSHADECAPS_COLORGOURAUDRGB };
	
	if(mD3d != NULL)
	{
		D3DCAPS9	caps;
		if(D3D_OK != mD3d->GetDeviceCaps(D3DADAPTER_DEFAULT, mDevType, &caps)) return false;
		
		for(cc=0;cc<nrReqDevCaps;++cc)		{ if(!(caps.DevCaps & reqDevCaps[cc])) return false; }
		for(cc=0;cc<nrReqPresentCaps;++cc)	{ if(!(caps.PresentationIntervals & reqPresentCaps[cc])) return false; }
		for(cc=0;cc<nrReqTexFilterCaps;++cc){ if(!(caps.VertexTextureFilterCaps & reqTexFilterCaps[cc])) return false; }
		for(cc=0;cc<nrReqTexAddrCaps;++cc)	{ if(!(caps.TextureAddressCaps & reqTexAddrCaps[cc])) return false; }
		for(cc=0;cc<nrReqPrimMiscCaps;++cc) { if(!(caps.PrimitiveMiscCaps & reqPrimMiscCaps[cc])) return false; }
		for(cc=0;cc<nrReqRasterCaps;++cc)	{ if(!(caps.RasterCaps & reqRasterCaps[cc])) return false; }
		for(cc=0;cc<nrReqShadeCaps;++cc)	{ if(!(caps.ShadeCaps & reqShadeCaps[cc])) return false; }

		if(D3D_OK != mD3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, mDevType, mAdapterFormat, D3DUSAGE_AUTOGENMIPMAP, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8)) return false;
		if(!(caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP)) return false;

		if(caps.VertexShaderVersion < D3DVS_VERSION(2,0)) return false;
		if(caps.PixelShaderVersion < D3DPS_VERSION(2,0)) return false;
		if(caps.MaxAnisotropy < 4) return false;
		if(caps.MaxTextureWidth < 256) return false;
		if(caps.MaxTextureHeight < 256) return false;
		if(caps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) return false;

		return true;
	}
	else return false;
}

Can this be done, easier? (i.e. with an array of DWORD values / caps and the corresponding caps.'' etc.)

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

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

Advertisement

Use multimaps to store possible caps values for a particular d3dcap (Use d3dcap name as the key, if you please). It has several advantages.

1) No more iterations to find out a particular capacity. Just a "find" will do.

2) Easy to take different combinations from various multimaps to support different combos in future.

3) Looks much more systematic and better than static arrays and for loops. :-)

Thanks, that sounds like something I could use.

Is this basically an error which says:

Col1 Col2

caps.DevCaps D3DDEVCAPS_.....

caps.DevCaps D3DDEVCAPS_....somethingelse

caps.PresentationsInverals D3DPRESENT_...something

So I can loop through all of them?

Do you maybe have a simple example how multimaps would do the above?

Will also try to find out in the mean time (googling :))

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

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

was bit too lazy I suppose, already made a bit of a start:

multimap <???, DWORD> capsTable;

capsTable.insert(pair<???, DWORD>(caps.DevCaps, D3DDEVCAPS_..something));

and so on

- what type should I use for caps.DevCaps? (it's basically also a DWORD I suppose)

- how do I 'use them'; like if(!(capsTable.1st col[0] & capsTable.2nd col[1]) ......

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

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

Don't rush/panic buddy. Multimaps are very easy to figure out and there is tons of reference on google that will always do better than any of my explanations on the same.

As for your query about type of DevCaps, it is a DWORD like almost all other attributes of the structure. Still, MSDN lists all of them with their values. Best would be to define some key of your own. You might very well use a string as a key for different attributes to map and check.

Play around with this a bit, you will get a hang of it and eventually like it. :-)

Thanks, I think you're right, it is kinda fun :)

Up till now I have:


void just4fun()
{
	D3DCAPS9	caps;
	std::multimap <DWORD, DWORD> capsTable;

	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_DRAWPRIMTLVERTEX));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_HWRASTERIZATION));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TLVERTEXSYSTEMMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TLVERTEXVIDEOMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DPRASTERCAPS_ZBUFFERLESSHSR));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DPRASTERCAPS_ZTEST));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_EXECUTESYSTEMMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_EXECUTEVIDEOMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TEXTUREVIDEOMEMORY));

	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRESENT_INTERVAL_ONE));
	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRESENT_INTERVAL_TWO));
	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRESENT_INTERVAL_IMMEDIATE));

	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MAGFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MINFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MIPFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MINFANISOTROPIC));

	std::ofstream test("multimap.txt");

	for (std::multimap<DWORD, DWORD, std::less<DWORD> >::const_iterator iter =capsTable.begin();
      iter != capsTable.end(); ++iter )
	{
		test << iter->first << " " << iter->second << std::endl;
	}

The output though says that the "first" values are all the same..

Will play around to find how it works, maybe this is correct.

Output:

3435973836 1024
3435973836 524288
3435973836 64
3435973836 128
3435973836 32768
3435973836 16
3435973836 16
3435973836 32
3435973836 512
3435973836 1
3435973836 2
3435973836 2147483648
3435973836 33554432
3435973836 512
3435973836 131072
3435973836 1024

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

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

This post is almost becoming a live chatbox ;-)

Got it working now, maybe not optimal yet, but the result is OK (Tested it by passing a faulty D3D caps value in the 2nd 'colom', and this gives a correct 'not found' back).

Here's the code:


void just4fun()
{
	LPDIRECT3D9	mD3d;

	mD3d = Direct3DCreate9(D3D_SDK_VERSION);

	D3DCAPS9	caps;
	mD3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	std::multimap <DWORD, DWORD> capsTable;

	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_DRAWPRIMTLVERTEX));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_HWRASTERIZATION));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TLVERTEXSYSTEMMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TLVERTEXVIDEOMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DPRASTERCAPS_ZBUFFERLESSHSR));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DPRASTERCAPS_ZTEST));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_EXECUTESYSTEMMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_EXECUTEVIDEOMEMORY));
	capsTable.insert(std::make_pair(caps.DevCaps, D3DDEVCAPS_TEXTUREVIDEOMEMORY));

	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRASTERCAPS_ZTEST));
	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRESENT_INTERVAL_TWO));
	capsTable.insert(std::make_pair(caps.PresentationIntervals, D3DPRESENT_INTERVAL_IMMEDIATE));

	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MAGFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MINFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MIPFLINEAR));
	capsTable.insert(std::make_pair(caps.VertexTextureFilterCaps, D3DPTFILTERCAPS_MINFANISOTROPIC));

	std::ofstream test("multimap.txt");

	for (std::multimap<DWORD, DWORD, std::less<DWORD> >::const_iterator iter =capsTable.begin();
      iter != capsTable.end(); ++iter )
	{
//		test << iter->first << " " << iter->second << std::endl;
		if(iter->first & iter->second) MessageBox(NULL, L"Cap found", L"test", MB_OK);
		else MessageBox(NULL, L"Cap not found", L"Test", MB_OK);
	}
	mD3d->Release();
}

Maybe I'll put the definition of the capsTable and contents in my header file, to keep code/ function clean.

Thanks for your hints, really looks better and cleaner this way.

Any pointers on improving it more, always welcome ;)

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

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

Like I mentioned earlier, you may define your multimap like this :

std::multimap <std::string, DWORD> capsTable;

This way your key values can be "DevCaps" or "PresentationIntervals" or "VertexTextureFilterCaps" or XYZ", with their associated values always mapped uniquely to them.

Currently you have just associated the structure reference, that's why all the key values came out to be the same.

Later on you can expand upon above multimap, by making several distinct multimaps for different attributes and then do some combos. Many ways to make this work elegantly now, its all upto how you want to design this.

Thanks, I partially understand.

Say I make a multimap which holds i.e.:

DevCaps D3DDEVCAP_something

And I want to to a comparison:

if(Caps.Devcaps & D3DDEVCAP_something)

I got it working now with the reference, but how do I add the D3DCAPS9 structure (say Caps) with a string, to be a valid member indication of Caps?

(Caps.Devcaps)?

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

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

Ok, I will try to give you a use-case which has some real implication and should be in line with your requirements.

So what we want to achieve is a container that holds Device cap attributes and possible values for each of these capacities.

Now, multimap has a method called equal_range that returns all the values associated to a particular key.

Eg.


typedef std::multimap<std::string, DWORD> xyzMap;
xyzMap capsTable;

capsTable.insert(std::make_pair("PresentationIntervals", D3DPRASTERCAPS_ZTEST));
capsTable.insert(std::make_pair("PresentationIntervals", D3DPRESENT_INTERVAL_TWO));
capsTable.insert(std::make_pair("PresentationIntervals", D3DPRESENT_INTERVAL_IMMEDIATE));

std::pair<xyzMap::iterator, xyzMap::iterator> range;

range = capsTable.equal_range("PresentationIntervals");

for (xyzMap::iterator it = range.first; it != range.second; ++it)
{
    // Do something with PresentationIntervals values
}

As it is, you don't have to do anything with the attribute name itself, but the value it holds. So the way I have mentioned above, you can use and expand your implementation to dynamically hold, add and configure your Device cap attributes as you please.

This topic is closed to new replies.

Advertisement