[.net] Program priority

Started by
11 comments, last by Meowza 14 years, 3 months ago
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?
Advertisement
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?
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
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.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.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;    }
A gpu profiler will show you exactly what's going on. No reason to guess here or assume it is or isn't something you're doing
you know any good ones RDragon? I'm downloading the nvidia one right now
NVPerfHUD is excellent
What does your render loop look like? Tom Miller's blog has a good one.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

[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
For PerfHUD, read this and the section called "Modifying your Application".

This topic is closed to new replies.

Advertisement