Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


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
9 replies to this topic

#1 Roberto Vbr   Members   -  Reputation: 114

Like
0Likes
Like

Posted 28 August 2013 - 11:07 PM

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.



Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6966

Like
1Likes
Like

Posted 28 August 2013 - 11:27 PM

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.


Edited by Cornstalks, 28 August 2013 - 11:28 PM.

[ 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 ]

#3 Roberto Vbr   Members   -  Reputation: 114

Like
0Likes
Like

Posted 28 August 2013 - 11:48 PM

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;
}

Edited by Roberto Vbr, 28 August 2013 - 11:51 PM.


#4 Cornstalks   Crossbones+   -  Reputation: 6966

Like
0Likes
Like

Posted 29 August 2013 - 12:09 AM

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.


Edited by Cornstalks, 29 August 2013 - 12:09 AM.

[ 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 ]

#5 Roberto Vbr   Members   -  Reputation: 114

Like
0Likes
Like

Posted 29 August 2013 - 12:53 AM

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.



#6 NightCreature83   Crossbones+   -  Reputation: 2674

Like
2Likes
Like

Posted 29 August 2013 - 01:15 AM

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, Mad Max

#7 Roberto Vbr   Members   -  Reputation: 114

Like
0Likes
Like

Posted 29 August 2013 - 01:27 AM

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



#8 DaBono   Members   -  Reputation: 928

Like
1Likes
Like

Posted 29 August 2013 - 02:56 AM

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.



#9 Roberto Vbr   Members   -  Reputation: 114

Like
0Likes
Like

Posted 29 August 2013 - 03:33 AM

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



#10 NightCreature83   Crossbones+   -  Reputation: 2674

Like
0Likes
Like

Posted 29 August 2013 - 03:40 AM

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, Mad Max




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