IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Switching Textures, Parameters, etc, How optimized is Cg?
RealMarkP
post Nov 3 2009, 09:11 PM
Post #1


Newbie
*

Group: Members
Posts: 1
Joined: 3-November 09
Member No.: 9,745



Is Cg smart enough to ignore repeated cgD3D9SetTexture() which pass the same pointer to a texture?
Go to the top of the page
 
+Quote Post
Nigel @ NVIDIA
post Nov 9 2009, 04:07 PM
Post #2


Advanced Member
***

Group: Moderators
Posts: 264
Joined: 17-October 07
Member No.: 1,524



QUOTE (RealMarkP @ Nov 3 2009, 04:11 PM) *
Is Cg smart enough to ignore repeated cgD3D9SetTexture() which pass the same pointer to a texture?


Probably not. Generally we wouldn't want to penalize better-written applications for the sake
of less-well written ones. That's my understanding of the "rule of thumb".

- Nigel
Go to the top of the page
 
+Quote Post
Matthias
post Nov 17 2009, 03:07 AM
Post #3


Advanced Member
***

Group: Members
Posts: 31
Joined: 13-August 07
Member No.: 398



In general I found cgfx, especially the d3d9 version of cgfx to be very slow and unoptimized. The main problem is the runtime, who will issue way to many d3d api calls. E.g. for every parameter you set it will generate a d3ddevice->SetVertex/PixelShaderConstantF call. In my application this piled up to more than 16.000 calls per frame. Cg was using more than 50% of the cpu time on my machine due to internal functions being called and due to simple flooding of the driver with commands.

In the end, I wrote my own little version of the cg runtime, which batches things much more, uses constant buffers, also takes care of potential redundant set commands and the result is that I have less than 1000 d3d api calls now and my application performance is much much better.

If you have lots of objects with changing parameters, you will very likely have to write your own runtime, too. The cg d3d9 module has various problems (e.g. try using a CullMode state assignment - debugging with PIX will show you that cg d3d9 will completely ignore it. Or try setting some invalid effect state like "Blub = Linear;" - it will fail silently, fail the following state assignments and leave you scratching your head about things not working). This is not to bash cg - after all I am using it - but you can safe yourself some time if you use an alternative to cgd3d9 like cgd3d10 (which seems better from my rough first tests) or hlsl (with d3d11).

-Matthias
Go to the top of the page
 
+Quote Post
MakKlaski
post Nov 17 2009, 09:49 AM
Post #4


Advanced Member
***

Group: Members
Posts: 31
Joined: 6-July 08
From: European Union
Member No.: 5,741



QUOTE (Matthias @ Nov 17 2009, 06:07 AM) *
In general I found cgfx, especially the d3d9 version of cgfx to be very slow and unoptimized.
Cg was using more than 50% of the cpu time on my machine due to internal functions being called and due to simple flooding of the driver with commands.


Totally agree!
CgFX is very cpu-hungry and when I use PerfHUD to list all d3d calls per frame, I get a huge list of redundant state changes.
Here is my post about this: http://developer.nvidia.com/forums/index.php?showtopic=3755
So, looks like, if app uses CgFX, then it is CPU-bound and "even infinitely fast GPU can't make it run faster" ©. (In other words: no need for next-gen NVIDIA cards on the market.)
Too bad Cg users are forced to write their own runtime. Lot of time wasted.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Copyright © 2008 NVIDIA® Corporation.  Terms of Use | Legal Info | Privacy Policy Time is now: 24th November 2009 - 01:01 AM