Manta Interactive Ray Tracer Development Mailing List

Text archives Help


Re: [MANTA] some coding advice requested


Chronological Thread 
  • From: James Bigler <bigler@cs.utah.edu>
  • Cc: manta@sci.utah.edu
  • Subject: Re: [MANTA] some coding advice requested
  • Date: Fri, 13 May 2005 10:13:08 -0600

1. Often we can either go stack or heap, e.g.

    float *co = new float[4];   // 4 rays in this particular packet

    vs

    float co[32];  // 32 is max packet size

   I am inclined to change the former to the latter in the current code
   but perhaps my insincts are wrong?

A lot depends on where this code is. You don't want to allocate memory from the heap during the rendering phase. You also don't want to blow the stack size for your code. However, since we set the per thread stack size to 1 MB I would go ahead and put it on the stack.

2.  A lot of the direct lighting code is:

    if shadow directions are normalized
        for each shadow ray
             20-30 lines of code
    else
        for each shadow ray
             normalize
             20-30 lines of code

   I am inclined to bite the bullet and change this to

    if shadow directions are not normalized
        for each shadow ray
             normalize
    for each shadow ray
         20-30 lines of code

    My guess is that extra loop is just not that expensive, and the code
    is cleaner/smaller.

Opinions on either appreciated.  I know profiling is a good answer,
but we don't yet have a full working system with complex models so
I am leery of that now.

What you should do is put the 20-30 lines in a macro. That way it will be completely clear what's going on and easy to debug at the same time. ;)

With the proper motivation I would hope the compiler would unroll the loops and not be too much overhead. My guess is that the performance difference is negligible compared to the readability and maintainability of the code.

James





Archive powered by MHonArc 2.6.16.

Top of page