where I don't have to hard-code the number of streams in the shader. But EmitStreamVertex explicitly says it only takes a constant integral argument, and I don't see a way to define an output that applies to any requested stream.

I don't think there is a way to avoid the crux of your problem: wanting to arbitrarily choose where to output which data, without having a switch statement.

Every method for outputting data, whether it's streams, regular shader outputs, or even writing to image variables, ultimately requires either an integral constant expression or a dynamically uniform expression.

Through the use of image variables, you can avoid the limited stream count issue. You'll of course need your own atomic variable to figure out how to insert it into the next slot in the image variable. But while image variable arrays are allowed, the array index has to be a dynamically uniform expression. And even then, you can only have a limited number of image variables. It's required to be at least 8 (but only in the fragment/compute shader).

I don't think there is a way to avoid the crux of your problem: wanting to arbitrarily choose where to output which data, without having a switch statement.

Hmm. Ok, thanks.

Originally Posted by Alfonse Reinheart

Every method for outputting data, whether it's streams, regular shader outputs, or even writing to image variables, ultimately requires either an integral constant expression or a dynamically uniform expression.

Reading up a bit on what's out there for GPU binning, one common method (popularized 4 years back by ATI) which gets you past this limitation seems to be computing the bin index in the vertex shader (gl_Position) and then using normal point rasterization to toss the data in that bin. Has its own shortcomings though. Have a few other options to explore as well.

Through the use of image variables, you can avoid the limited stream count issue. You'll of course need your own atomic variable to figure out how to insert it into the next slot in the image variable. But while image variable arrays are allowed, the array index has to be a dynamically uniform expression. And even then, you can only have a limited number of image variables. It's required to be at least 8 (but only in the fragment/compute shader).