A simple window directx 10 takes 25% of the processor. Is this normal?

Started by
8 comments, last by NightCreature83 10 years, 7 months ago

I'm studying directx for some time now, in fact shortly. While I was learning directx 9 processor was little used, but with a simple window directx 10 steals 25% of the processor and so far I can not find anything that answers why this difference.

Advertisement

Are you using a quad core CPU? Is your program taking 100% of one of the four cores?

If so, it's likely your drivers and vsync. Your old program on D3D 9 was probably using vsync (without a busy loop, allowing the CPU to sleep), while your new program with D3D 10 is probably either not using vsync, or if its, it's using a busy loop to stall.

[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Not my CPU is an Intel Core i5-2410M and there is still the application swapchain. The beginning of the program code is this (always starting at windowed mode) :


void SystemClass::InitializeWindows(int& screenWidth, int& screenHeight)
{
	WNDCLASSEX wc;
	DEVMODE dmScreenSettings;
	int posX, posY;


	// Get an external pointer to this object.	
	ApplicationHandle = this;

	// Get the instance of this application.
	//m_hinstance = GetModuleHandle(NULL);

	// Give the application a name.
	m_applicationName = L"Directx10";

	// Setup the windows class with default settings.
	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = m_hinstance;
	wc.hIcon		 = LoadIcon(NULL, IDI_WINLOGO);
	wc.hIconSm       = wc.hIcon;
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = m_applicationName;
	wc.cbSize        = sizeof(WNDCLASSEX);
	
	// Register the window class.
	RegisterClassEx(&wc);

	// Determine the resolution of the clients desktop screen.
	screenWidth  = GetSystemMetrics(SM_CXSCREEN);
	screenHeight = GetSystemMetrics(SM_CYSCREEN);

	// Setup the screen settings depending on whether it is running in full screen or in windowed mode.
	if(FULL_SCREEN)
	{
		// If full screen set the screen to maximum size of the users desktop and 32bit.
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize       = sizeof(dmScreenSettings);
		dmScreenSettings.dmPelsWidth  = (unsigned long)screenWidth;
		dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight;
		dmScreenSettings.dmBitsPerPel = 32;			
		dmScreenSettings.dmFields     = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
		

		// Change the display settings to full screen.
		ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);

		// Set the position of the window to the top left corner.
		posX = posY = 0;
	}
	else
	{
		// If windowed then set it to 800x600 resolution.
		screenWidth  = 800;
		screenHeight = 600;

		// Place the window in the middle of the screen.
		posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth)  / 2;
		posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2;
	}

	// Create the window with the screen settings and get the handle to it.
	m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName, 
							WS_OVERLAPPEDWINDOW,
						    posX, posY, screenWidth, screenHeight, NULL, NULL, m_hinstance, NULL);

	// Bring the window up on the screen and set it as main focus.
	ShowWindow(m_hwnd, SW_SHOW);
	SetForegroundWindow(m_hwnd);
	SetFocus(m_hwnd);

	// Hide the mouse cursor.
	ShowCursor(true);

	return;
}

Not my CPU is an Intel Core i5-2410M and there is still the application swapchain.

And exactly how are you determining 25% of your CPU is being used? That CPU is hyperthreaded, so the OS (and other things) will treat it (and report it) as a quad core, and 100% of one of 4 logical cores is still 25% of the theoretical max.

My money is still on the whole vsync stuff.

[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

I open the task manager, look for the name of the program and there is even running with 25 percent of the CPU and only this program is marked the same occupancy. When this application is not running the amount of CPU usage is always marked as zero.

Is there a sleep in your main loop? If not you have a busy loop and it will take up a full CPU core to execute on it.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

That was exactly what was missing. Thank you. Swapchain tested both with and without this and now the CPU is ok.

I'd advise against using a sleep to limit the frame rate of your application.

It is quite normal for a game to render as much frames as possible when VSync is off (and thus using 100% of a core). You can pass 1 as the sync interval to Present() to have VSync enabled.

Ok DaBono now I'm learning more about swapchain I'm also learning to set this sleep to save the processor.

I was about to mention that sleep should only be used when your app doesn't have focus, generally a game will tax a CPU to 100% and this is fine for multithreaded games.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

This topic is closed to new replies.

Advertisement