Skip to main content
gamedev.net
🔒 Locked

using the REF rasterizer

Started by treeway Feb 24, 2007 at 10:46 AM 2 replies 1k views
Original Post
treeway
treeway
Hi Im trying to check if the hardware im working on reaches a specified PS and VS version. If it doesnt, I intend to use the REF rasterizer. However, im running into some problems creating a device with REF. heres my code:

bool Base::initialiseDirect3D( BOOL Windowed,
							   UINT screenWidth,
							   UINT screenHeight,
							   UINT BackBufferCount,
							   D3DMULTISAMPLE_TYPE MultiSampleType,
							   D3DSWAPEFFECT SwapEffect,
							   UINT FullScreen_RefreshRateInHz,
							   UINT PresentationInterval,
							   UINT RequiredVS_Major,
							   UINT RequiredVS_Minor,
							   UINT RequiredPS_Major,
							   UINT RequiredPS_Minor
						     )

{
	//First of all, create the main D3D object. If it is created successfully we 
	//should get a pointer to an IDirect3D interface.
	if((m_pD3D = Direct3DCreate(D3D_SDK_VERSION)) == NULL)
	{
		logError("<li>Unable to create DirectX interface.");
		return false;
	}

	//Get the current display mode
	D3DDISPLAYMODE d3ddm;
	ZeroMemory(&d3ddm, sizeof(d3ddm));

	// Get the current display format.
	if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
		return false;


	// Create a structure to hold the settings for the device
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory(&d3dpp, sizeof(d3dpp));

	//Use Hardware Vertex Processing By Default.
	D3DDEVTYPE HardwareOrSoftware = D3DDEVTYPE_HAL;
	DWORD Behaviour = D3DCREATE_HARDWARE_VERTEXPROCESSING; 

	// Fill the structure.
	d3dpp.BackBufferCount				= BackBufferCount;
	d3dpp.MultiSampleType				= MultiSampleType;
	d3dpp.SwapEffect					= SwapEffect;
	d3dpp.FullScreen_RefreshRateInHz	= FullScreen_RefreshRateInHz;

#ifdef _XBOX

	d3dpp.FullScreen_PresentationInterval = PresentationInterval;
	d3dpp.BackBufferFormat = D3DFMT_LIN_A8R8G8B8;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	d3dpp.EnableAutoDepthStencil = true;
	d3dpp.BackBufferWidth				= screenWidth;
	d3dpp.BackBufferHeight				= screenHeight;

#elif _WIN32
	d3dpp.Windowed = Windowed;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.PresentationInterval = PresentationInterval;

	if(d3dpp.Windowed)
	{
		d3dpp.BackBufferWidth				= screenWidth;
		d3dpp.BackBufferHeight				= screenHeight;
	}else
	{
		d3dpp.BackBufferWidth				= d3ddm.Width;
		d3dpp.BackBufferHeight				= d3ddm.Height;
	}

	d3ddm.Format = checkDisplayMode(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, 32);
	if(d3ddm.Format == D3DFMT_UNKNOWN)
	{
		d3ddm.Format = checkDisplayMode(d3dpp.BackBufferWidth, d3dpp.BackBufferHeight, 16);
		if(d3ddm.Format == D3DFMT_UNKNOWN)
		{
			logError("<li>Unable to select back buffer format for %d x %d.", d3dpp.BackBufferWidth, d3dpp.BackBufferHeight);
			return false;
		}
	}

	d3dpp.BackBufferFormat = d3ddm.Format;

	D3DCAPS9 checkShaderCaps;
	// get the capabilities of the hardware device
	if(FAILED(m_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&checkShaderCaps)))
	{
		sprintf(buffer,"Unable to get Device Caps for Default Adapter");
		messageBox(hWnd,buffer);
	}else
	{
		UINT vs_major = D3DSHADER_VERSION_MAJOR(checkShaderCaps.VertexShaderVersion);
		UINT vs_minor = D3DSHADER_VERSION_MINOR(checkShaderCaps.VertexShaderVersion);
		UINT ps_major = D3DSHADER_VERSION_MAJOR(checkShaderCaps.PixelShaderVersion);
		UINT ps_minor = D3DSHADER_VERSION_MINOR(checkShaderCaps.PixelShaderVersion);

		if(checkShaderCaps.VertexShaderVersion < D3DVS_VERSION(RequiredVS_Major,RequiredVS_Minor) 
			|| checkShaderCaps.PixelShaderVersion < D3DPS_VERSION(RequiredPS_Major,RequiredPS_Minor))
		{
			sprintf(buffer,"Your Graphics Hardware supports shader model: \nVS_%d_%d PS_%d_%d \nSupport for Model: \nVS_%d_%d PS_%d_%d \n is required to run this program using the hardware rasterizer. \nReverting to REF This will be SLOW! ",
				vs_major,vs_minor,ps_major,ps_minor,RequiredVS_Major,RequiredVS_Minor,RequiredPS_Major,RequiredPS_Minor);
			messageBox(hWnd,buffer);
			HardwareOrSoftware = D3DDEVTYPE_REF;
			Behaviour = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		}
	}

	//Select the best depth buffer, select 32, 24 or 16 bit
	if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, HardwareOrSoftware, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) == D3D_OK)
	{
		d3dpp.AutoDepthStencilFormat = D3DFMT_D32;
		d3dpp.EnableAutoDepthStencil = true;
	}
	else if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, HardwareOrSoftware, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) == D3D_OK)
	{
		d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;
		d3dpp.EnableAutoDepthStencil = true;
	}
	else if(m_pD3D->CheckDeviceFormat(D3DADAPTER_DEFAULT, HardwareOrSoftware, d3ddm.Format, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) == D3D_OK)
	{
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		d3dpp.EnableAutoDepthStencil = true;
	}
	else
	{
		d3dpp.EnableAutoDepthStencil = false;
		logError("<li>Unable to select depth buffer.");
	}

#endif

	D3dDevice = NULL;

	//Create a Direct3D device.
	if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, HardwareOrSoftware, hWnd, 
		Behaviour, &d3dpp,
		&D3dDevice)))

	{
		logError("<li>Unable to create device.");
		messageBox(NULL,"Unable to create device!");
		return false;
	}

	return true;
}

Im deliberately working on hardware which is only capable of VS_2_0 and PS_1_4 and i have set the required ps and vs to 2_0 to test it. I get the message box telling me that the program is going to use REF and i set the HardwareOrSoftware variable to D3DDEVTYPE_REF. This is then used in the CreateDevice but it ALWAYS fails to create the device. I can create a ref device on my other computer which is ps/vs 3.0 by setting the required values to 4 or more. but why cant i create a ref device on my lower level pc?
sirob
sirob
the REF device is only available when the DX SDK is installed. If it isn't, the REF device is not available.

If you do have the SDK installed on the other machine, turn on the debug runtimes. If a call fails, you'll get some debug info as to why it failed.
Sirob Yes.» - status: Work-O-Rama.
treeway
treeway
I have the DirectX 9.0 sdk installed on both machines but even render monkey fails to create a REF device on the older one does this mean its using retail and not debug? If so do i have to re-install the sdk to set it to debug?

Also if REF only works on computers with the Debug version installed what do I do if the computer only has the retail directx installed and i want to show shaders later then the hardware supports?
ET3D
ET3D
Quote:
Original post by treeway
Also if REF only works on computers with the Debug version installed what do I do if the computer only has the retail directx installed and i want to show shaders later then the hardware supports?

Either fail or reduce functionality. The REF is not a practical runtime solution, anyway, because it's very slow.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.