Quick question on rendering!

Started by
16 comments, last by Kitasia 16 years, 10 months ago
This seems like it'll work! Thanks! I'll see how it goes!

Update: Well I reduced both and no go. It's almost as if I didn't change anything. I'd like to say it's all the vertex buffer issue but if I simply skip drawing I still get hit hard. I'm stumped. It seems things only go right if I don't commit to any changes (This includes - Matrix Changes, Material changes to an extent, and most importantly Texture changes) Should I be using HLSL or maybe (XNA related) use effect.Being and effect.End more often instead of piling everthing I draw inbetween it once and making a bunch of changes in betweeen?

(Just tried that effect part and everything was a lot worse! Not sure what I was thinking)

[Edited by - AntiGuy on May 24, 2007 9:37:07 AM]
Advertisement
Quote:Original post by AntiGuy
Update: Well I reduced both and no go. It's almost as if I didn't change anything. I'd like to say it's all the vertex buffer issue but if I simply skip drawing I still get hit hard. I'm stumped.

You're rendering all the geometry in one batch using a single vertex buffer, and have taken all your textures down to a reasonable size (no bigger than 512x512) with mip-mapping enabled (right?) and it's still running slowly? Something is amiss.

I don't follow that second sentence in my quoted text. Do you mean that it runs slowly even if you don't submit the geometry to the video card? Changing state very frequently is highly detrimental to otherwise fast performance, but it shouldn't have too much effect when nothing is being drawn. Maybe the problem is more fundamental. I trust you have the debug runtimes enabled, with maximum debug spew, and are looking for performance warnings. If not, this comes before anything else on the to-do list [smile].

If things are no better after all that, then we'll need to see some code. And I don't mean to patronise, but are you sure the problem is in your render process and not something external clogging up your CPU?

By the way - sorry about the terminology. You translated correctly. For some reason, I always tend to assume people are using C++ [rolleyes].

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
XD I have no idea what any of those debug settings are. But I'm using Visual Studio Express and running in debug configuration.

As for the rest of the information. I haven't set up any vertex buffer yet so I'm just commented out the line DrawUserPrimitives to isolate other errors first. All my textures are no greater than 200x200 and mip-mapping is enabled.

Here's my rendering code!

            public static void DrawLimb(Limb limb, SortedTextureList textureList)            {                PushMatrix();                MultiplyMatrix(limb.matrix);                //Draw                effect.Texture = limb.GetTexture(textureList);                effect.SpecularColor = limb.shadowColor.ToVector3();                effect.Alpha = limb.Alpha;                effect.CommitChanges();                device.DrawUserPrimitives<Vertex>(PrimitiveType.TriangleStrip, limb.vert, 0, limb.vert.Length - 2);                PopMatrix();            }            public static void DrawCharacter(Character.Character character, SortedTextureList texList)            {                //Updates all Matrix Positions                character.UpdateMatrix();                foreach (Limb part in character.drawOrder)                {                    if (part.IsVisible == false) { continue; }                    DrawLimb(part, texList);                    device.RenderState.SlopeScaleDepthBias -= 0.1f;                }                device.RenderState.SlopeScaleDepthBias = 0;            }



I know it's not perfect but should it really kill me this much? I used the same technique in OpenGL and it wasn't half as bad as this.

Ooh I forgot to add! I can handle about 8 of them at fps when I'm not in debug mode and I'm not using DrawUserPrimitives.

[Edited by - AntiGuy on May 24, 2007 12:03:25 PM]
Your code looks fine to me.

You can maximise debug output by opening 'DirectX' in the control panel and putting the corresponding slider up to maximum. Now, when you run a DirectX program that's compiled with the debug libraries from VS++EE, the API will report anything it thinks you should know in the 'Output' window. You should keep an eye on this every time you test-run. It can save you a lot of time and a lot of headaches.

I must ask. If you comment out the calls to DrawLimb and DrawCharacter (and further, any other graphic-related calls) do you get the performance back? It's looking more and more like you're trying to fix the wrong problem [rolleyes].

But now that we've reached the point where the bottleneck isn't obvious, it's time to bring out the most powerful optimisation tool you'll ever need - the profiler. I don't have much experience with C#, but I've heard some good things about Ants. Language-independent alternatives would be VTune if you have an Intel processor or CodeAnalyst for AMD. Profile a few seconds of execution and look to see where most of the CPU time is being spent. If it's in your program then use the profiler to find out where, and fix it. On the other hand, if the time is being wasted in a device driver or a DirectX DLL then you'll need a different, graphics-oriented, profiler. Luckily for you, the DirectX SDK comes with PIX, with which you can isolate the bottleneck in no time.

So they are your orders. Report back with your findings [wink].

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
[smile] Okay! Sorry for the wait!

Before I begin I'd like to know everything works swimmingly when I skip drawlimb all together.

My slowest method is apparently getting the texture which comes as a complete shocker seeing as all I do is return a list entry. The next slowest invoves setting the matrix which Multipy, Push, and Pop Matrix do. I'll comment out some things and see what I find and.....

Not too much of a difference. It's maddening!? As if everything in that function is working as one to slow me down. The only way to get a decent speed is to not draw anything, not make any texture changes, and don't change the material. Pretty much everything DirectX is control of! [razz]

I'm beginning to wonder if my video card is responsible somehow.

Oh yeah, I couldn't set Maximum Debuging output because it was grayed out for some mysterious reason.
Quote:All my textures are no greater than 200x200 and mip-mapping is enabled.


Now you do realize your card likely isn't a fan of non-power of 2 textures right? I took a quick look online at your card and couldn't find if it supported them or not. But make sure all your textures are like 32x32, 64x64, 128x128, 128x256, 256x128, 256x256, etc. Any combo of power of 2.

I know it doesn't seem to be the bottle neck but when I seen your 200x200 quote I worried :)

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Thanks! I'm familiar with that rule but I don't think it'll hurt that bad. I use textures in powers of 2 for things like scenery and such.

More news I downloaded a XNA game I found Here and it runs INCREDIBLY SLOW!!! Even the menu is slow! So I'm beginning to think this is related to a driver of some sort. I'll look into it some more.

I'm guessing you can test it for yourself, but I'll note it's kinda gorey for my tastes. [dead]
Oy, never imagined I'd be sorting this out this long 9_9.

Well I downloaded the latest DirectX SDK hoping to achieve a conclusion but, alas, nothing. I was able to increase debug output however! My findings using the Ants profiler reported effect.CommitChanges() and DrawUserPrimitives to be the biggest thorns in my side. Third runner up would be EffectParameter.SetValue.

I was about to purchase a new computer being that mine is 7 years old. May as well now, just may solve the issue. I have a feeling my code doesn't have much to do with this.

I'll note I found a post with a nearly identical problem.
http://forums.nvidia.com/index.php?showtopic=36278&mode=linear

[Edited by - AntiGuy on May 25, 2007 6:06:52 PM]

This topic is closed to new replies.

Advertisement