grill8
November 28th, 2008, 03:51 AM
Hello all,
I have some questions about programming effective shaders in DirectX.
I know how to program shaders but behind the scenes I have some questions, primarily about optimization.
Question 1:
I assume that shaders need more optimization than normal code run on the CPU, primarily because they will be run SO many times with certain things like terrain or many instances of an object being shaded, in both cases running through ALL vertices and ALL pixels. Highly executed code seems in need of highly optimized code. Is this always true of shaders?
Question 2:
Are there any performance hits to watch out for? For example, is optimized code that takes twice as many statements really actually more optimized? For example, does it take more time to load a large shader to the GPU than a smaller shader and in this case invalidating the point of the optimization?
Question 3:
Are there bottlenecks in passing data to shaders? For example is passing an array of 256 floats to a shader acceptible for many objects in a scene? Basically, things along that nature.
In summary, I am just trying to go from knowing how to program shaders to knowing how to program EFFECTIVE shaders and would appreciate as much input as possible.
Thank you for your help.
Jeremy
I have some questions about programming effective shaders in DirectX.
I know how to program shaders but behind the scenes I have some questions, primarily about optimization.
Question 1:
I assume that shaders need more optimization than normal code run on the CPU, primarily because they will be run SO many times with certain things like terrain or many instances of an object being shaded, in both cases running through ALL vertices and ALL pixels. Highly executed code seems in need of highly optimized code. Is this always true of shaders?
Question 2:
Are there any performance hits to watch out for? For example, is optimized code that takes twice as many statements really actually more optimized? For example, does it take more time to load a large shader to the GPU than a smaller shader and in this case invalidating the point of the optimization?
Question 3:
Are there bottlenecks in passing data to shaders? For example is passing an array of 256 floats to a shader acceptible for many objects in a scene? Basically, things along that nature.
In summary, I am just trying to go from knowing how to program shaders to knowing how to program EFFECTIVE shaders and would appreciate as much input as possible.
Thank you for your help.
Jeremy