"Whenever you find that you are on the side of the majority, it is time to reform."
- Mark Twain

GDC slides
Thursday, April 4, 2013 | Permalink

The slides from my GDC presentation Low-Level Thinking in High-Level Shading Languages are now available for download in the Articles section.

Name

Comment

Enter the code below



Dan Y
Tuesday, April 9, 2013

Great stuff, thanks for posting these. Some of the transformations done on simple equations to get them into optimized forms cut down on "readability". Do you ever find yourself putting the original naive implementation in comments near the optimized versions, or is it just something people need to get used to?

Humus
Wednesday, April 10, 2013

Sometimes it improves readability, sometimes makes it worse, depending on what's most intuitive for the situation. Sometimes I clarify with a comment, or just put the original or more naive expression in a comment. Sometimes it's just a matter of rewriting the shader to be more readable. For instance,

const float start = 0.7f;
const float slope = 3.2f;
return (x - start) * slope;

turns into:

const float start = 0.7f;
const float slope = 3.2f;
const float bias = -start * slope;
return x * slope + bias;

CeeJay.dk
Thursday, April 11, 2013

Awesome tips. I've already begun using some of them.

Some tips of my own:
If you want to do smoothstep(0,1,x) , then instead do x * x * (3 - 2 * x) . It will be slightly faster.
Hmm thinking of it now, I think -x * x * (2 * x - 3) might be slightly faster but I will need to get home so I can verify this with GPU Shaderanalyzer.

Also you often need to compare the length of a vector to a value and often people do pythagoras:
if (sqrt( dot(vector,vector) ) < threshold)
Instead try:
if (dot(vector,vector) < (threshold * threshold))
because it's faster do the square of the threshold (especially if it's a constant) than do a sqrt()

CeeJay.dk
Friday, April 12, 2013

-x * x * (2 * x - 3) ran just as fast as x * x * (3 - 2 * x)

CeeJay.dk
Friday, April 12, 2013

-x * x * (2 * x - 3) ran just as fast as x * x * (3 - 2 * x)

Abnormalia
Tuesday, May 7, 2013

Hi, what tools have you used to see low level code that are executed on GPU ?

Thanks,
Irakli

Abnormalia
Tuesday, May 7, 2013

Hi, what tools have you used to see low level code that are executed on GPU ?

Thanks,
Irakli