PDA

View Full Version : Decrease Number of Temp Registers in Cg

nitschke
07-11-2006, 12:23 AM
Hi,

My Cg fragment program uses to much temporary registers. What can I do to decrese the number used?

Chris

PfhorSlayer
07-11-2006, 03:00 AM
Use algebra to simplify the operations you're performing, rearrange the code so that the registers that are required can be reused later (instead of requiring new ones), things like that?

It would probably help more if you were a little more specific (ie, showed us your program?) about what you're trying to solve here.

nitschke
07-11-2006, 03:12 AM
thanks very much for the fast reply!

how can i control to re-use temporary registers later? whats the trick?

f.e. the number of temp registers is inreased by 6, if i just perform the following:

float4 val1,val2;
float4 temp = val1-val2;
float res = temp.x + temp.y + temp.z + temp.w;

how can i sum up the values of a vector in a efficient way?

chris

Relic
07-11-2006, 03:24 AM
That code snippet doesn't help to explain your issue (e.g. what is in val1 and val2?)

"how can i sum up the values of a vector in a efficient way?"
Easy: float res = dot(temp, float4(1.0));

nitschke
07-11-2006, 03:37 AM
of course ^^
sorry to post this stupid question!

but what about re-using the temp registers?

Relic
07-11-2006, 04:13 AM