Sign in to follow this  
Meowza

[.net] Program priority

Recommended Posts

hello using C#, my game's FPS fluctuates between 30 - 60 it seems like random on each time I run it. I check in task manager and it says that regardless of FPS it is using 0% of CPU. Is there way to force a program's priority to give it more CPU resources or something like that?

Share this post


Link to post
Share on other sites
It is highly likely that it isn't CPU resources creating your bottleneck if you have such a rigid upper bound of 60 fps. It's much more likely that it is an issue with the way that you are rendering, and fixing your program to the V-sync on your monitor, with likely an extra sleep call somewhere that it making you drop the occasional frame.

Generally though, raising your CPU priority is a bad idea. Raise it too high and you're capable of suffocating other programs. Is your CPU usage for the entire system stuck at 100%, with just your program getting a tiny slice of it?

In short, how are you rendering, and what libs are you using to do it? Any sleep statements?

Share this post


Link to post
Share on other sites
Get a GPU profiler. It will tell you how long the GPU is spending rendering your frames. It could be that it's close to the threshold between 30fps and 60fps and that's why you see it fluctuate.

If you're aiming for 60fps, you likely need some optimizations

If you're aiming for 30fps, you might be OK for now and could consider capping the framerate at 30 so you don't get that fluctuation

Share this post


Link to post
Share on other sites
Well I'm only drawing 50 tiles with this example and I don't think it is with how I'm drawing because when the FPS is 30 or 40 or 50 or 60 it only fluctuates 1-2.

It is like sometimes when I run it, it's good and stays good, and sometimes it's bad and stays bad. And it's completely random, I'll start up my computer and get 30, wait a couple of hours and try again and it's 60.

Also, during every test, CPU is 99% idle.

I'm using csharp, and drawing 2D with directX in a 3D world.

Drivogas, ya I know what your saying about V-sync, my FPS never goes beyond 60 cuz of that.. could it be that my monitor is causing the weirdness in my FPS?

Here is how I am rendering, there are 50 tiles of ground and 2 tiles of objects

[source="csharp"]
public static void drawExplore()
{
Tools.device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1f, 0);
Tools.device.BeginScene();

Tools.device.SetStreamSource(0, Maps.vb, 0);

int vertCounter = 0;
for (int i = 0; i < Maps.ground.Count; i++)
{
Tools.device.SetTexture(0, Maps.ground[i].texture);
Tools.device.DrawPrimitives(PrimitiveType.TriangleStrip, vertCounter, 2);
vertCounter += 4;
}
for (int i = 0; i < Maps.objects.Count; i++)
{
Tools.device.SetTexture(0, Maps.objects[i].texture);
Tools.device.DrawPrimitives(PrimitiveType.TriangleStrip, vertCounter, 2);
vertCounter += 4;
}

Tools.device.Transform.View = Matrix.LookAtLH(Tools.cameraPosition, Tools.cameraTarget, Tools.cameraUp);

Tools.device.EndScene();
Tools.device.Present();
Tools.key = 0;
}

Share this post


Link to post
Share on other sites
[source="csharp"]
int adapterOrdinal = Microsoft.DirectX.Direct3D.Manager.Adapters.Default.Adapter;
Microsoft.DirectX.Direct3D.DeviceType dType = Microsoft.DirectX.Direct3D.DeviceType.Hardware;

foreach (AdapterInformation ai in Microsoft.DirectX.Direct3D.Manager.Adapters)
{
if (ai.Information.Description.IndexOf("NVPerfHUD") >= 0)
{
adapterOrdinal = ai.Adapter;
dType = Microsoft.DirectX.Direct3D.DeviceType.Reference;
}
}





Added this code in and it's a steady 60 FPS, maybe my default adapter was integrated graphics or something..

Also, do you guys know how to get the NVPerfHUD working? I configured the shortcut keys and I right click my .exe and drop it on the NVPerfHUD icon and it starts up but there is red text in the center saying this application is not configured to use NVPerfHUD.

I am using C# express 2008

Share this post


Link to post
Share on other sites
Ya I've read that a couple of times already Ezbez, all of the samples are in C++ though. The only C# example I could find on internet was here on GameDev and it's in my previous post.

Another weird thing I noticed, when I use the NVPerfHUD adapter my FPS is 300 something and not 30 when I run it with default adapter. Also CPU usage is 50 (im on dual core) which looks like how a game should be running.

Here is how I create my device..

[source = "csharp"]

pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;

pp.EnableAutoDepthStencil = true;
pp.AutoDepthStencilFormat = DepthFormat.D16;

int adapterOrdinal = Microsoft.DirectX.Direct3D.Manager.Adapters.Default.Adapter;
Microsoft.DirectX.Direct3D.DeviceType dType = Microsoft.DirectX.Direct3D.DeviceType.Hardware;

foreach (AdapterInformation ai in Microsoft.DirectX.Direct3D.Manager.Adapters)
{
if (ai.Information.Description.IndexOf("NVPerfHUD") >= 0)
{
adapterOrdinal = ai.Adapter;
dType = Microsoft.DirectX.Direct3D.DeviceType.Reference;
}
}

device = new Microsoft.DirectX.Direct3D.Device(adapterOrdinal, dType, window, CreateFlags.HardwareVertexProcessing, pp);
device.RenderState.Lighting = false;
device.RenderState.CullMode = Cull.None;
device.RenderState.AlphaTestEnable = true;
device.RenderState.ReferenceAlpha = 0x08;
device.RenderState.AlphaFunction = Compare.GreaterEqual;
device.VertexFormat = CustomVertex.PositionTextured.Format;

device.Transform.Projection = Matrix.OrthoLH(800, 600, 1.0f, 10.0f);




You guys see any problems as to why the program is not acting like a game?

Share this post


Link to post
Share on other sites
Oh man, it's doing it again.. it's gotten better after using the NVPerfHUD adapter but just booted up this morning and FPS was solid 30. I closed C# Express and reloaded my project and still 30.

Was trying to figure out why for half an hour and now it's back up to 60. Has anyone else had this problem? Like your CPU/GPU is asleep sometimes and other times it is running good?

Also, still can't get NVPerfHUD running, when launching my game with NVPerfHUD this is what I get..

http://img695.imageshack.us/img695/3796/testto.png

As you can see in the top left corner of image my FPS with NVPerfHUD is 280 and checking in task manager CPU usage is 50 instead of 0.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this