Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Decrease Number of Temp Registers in Cg

  1. #1
    Intern Newbie
    Join Date
    Feb 2006
    Location
    Osaka, Japan
    Posts
    35

    Decrease Number of Temp Registers in Cg

    Hi,

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

    Chris

  2. #2
    Intern Newbie
    Join Date
    Apr 2003
    Posts
    42

    Re: Decrease Number of Temp Registers in Cg

    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.

  3. #3
    Intern Newbie
    Join Date
    Feb 2006
    Location
    Osaka, Japan
    Posts
    35

    Re: Decrease Number of Temp Registers in Cg

    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

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Decrease Number of Temp Registers in Cg

    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));

  5. #5
    Intern Newbie
    Join Date
    Feb 2006
    Location
    Osaka, Japan
    Posts
    35

    Re: Decrease Number of Temp Registers in Cg

    of course ^^
    sorry to post this stupid question!

    but what about re-using the temp registers?

  6. #6
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Decrease Number of Temp Registers in Cg

    We don't get anywhere if you don't post your shader code.
    If you can't or don't want to, start with a smaller piece of your shader which works, run it through the Cg compiler and look at the assembly output.
    It counts the number of registers used, IIRC.
    Then add stuff to your shader, look again, continue until it breaks.
    Now look at what code can be eliminated or refactured or otherwise cleaned.
    If that all doesn't lead to a successful compilation, try using a newer Cg compiler if available.
    If that still doesn'thelp, your shader might just be too complicated for today's hardware.

  7. #7
    Intern Newbie
    Join Date
    Feb 2006
    Location
    Osaka, Japan
    Posts
    35

    Re: Decrease Number of Temp Registers in Cg

    i see,
    i did some refacturing in the way, you proposed and finally got the program running.
    the program is a little big, so i didnt want to post it.
    thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •