Page 1 of 1

GPU shared parameter array size mismatch behavior is broken

Posted: Fri Sep 21, 2012 6:49 pm
by lunkhound
Suppose I define some shared parameters in a material script like so:

Code: Select all

shared_params shadowParams
{
    // should probably construct this object in code to set the array lengths
    shared_param_named csmSplits float [9]
}
And I have some shader code that declares the parameter like:

Code: Select all

        uniform float csmSplits[4],
The current behavior is that because the array sizes don't match it will silently fail. The shader will see an array of all zeros. There is no exception raised, no warnings in the log, just silent broken-ness.
One obvious fix would be to either throw an exception or log a warning. However, I think an even better solution would be to just work as long as the destination array is less than or equal to the source array, and only throw an exception if the source array is too small.
This would be useful to me because I have a family of shaders which take arrays of different sizes (depending on how many shadow cascades are selected), and it is nice to be able to feed them all from a single set of shared parameters.
Any thoughts or opinions? I already have a patch for my preferred solution.