SV_Coverage input -> GLSL?

Allegedly in D3D11, a frag shader can take this as input to get the MSAA coverage mask. Is there a GLSL analog? All I found was the gl_SampleMask, which is an output.

I don’t know about any direct equivalent.
What would you like to use it for?
Maybe there is some equivalent for your particular use case.

I don’t need it. Just saw it in somebody’s blog. And naturally wondered about it’s GL counterpart. Couldn’t find one.

If you just want to know about edge pixels, can use the centroid interpolation trick and eat a few varyings. But if you really need the sample mask or didn’t want to give up a few varyings, not sure what you could do.

Sorry to resurrect an old thread but I was just looking into this very thing.

According to the GL_ARB_sample_shading spec, the gl_SampleMask[] variable is output-only.

However, Mark Kilgard says it’s read-able in a GTC presentation:
http://www.nvidia.com/content/GTC-2010/pdfs/2127_GTC2010.pdf

On nVidia hardware (Quadro 5000), it appears he’s right. I hope AMD sees it the same way. There are some good reasons to make the sample mask available to per-fragment shaders (avoiding per-sample shading and some issues that creates).

  • LoopinFool

On nVidia hardware (Quadro 5000), it appears he’s right. I hope AMD sees it the same way.

Um, no. If the spec says it’s output-only, then it is OUTPUT ONLY. However useful it may be to read it, the behavior dictated by the OpenGL Specification is the correct behavior.

Now, what should happen is the creation of GL_ARB_sample_shading_2, where they correct this oversight. Because it’s really, really stupid. But that doesn’t excuse NVIDIA from violating the spec as it currently reads. Indeed, NVIDIA could have come out with GL_NV_sample_shading_2 if they wanted.

Page 326 of the Opengl 4.0 Compatibility spec (page 230 in the core spec, somewhere in the 4.1 spec) it says

The built-in variable gl_SampleMaskIn is an integer array holding bitfields
dicating the set of fragment samples covered by the primitive corresponding to
e fragment shader invocation.
which sounds like it does what you want.

It’s strange that this is mentioned in the OpenGL spec but not the GLSL spec.

That’s… annoying. I dropped a bug on this; hopefully they’ll fix this one.

Very interesting. I will look into that more. So far, I’ve only managed to crash the graphics driver by referencing gl_SampleMaskIn.

Since I posted, I found that I was wrong that gl_SampleMask works as an input on nVidia hardware. I was playing with a demo rather than my own code and forgot I had to copy the shader files elsewhere.

I’m glad to hear it exists in the spec. I did find gl_SampleMaskIn mentioned in the GLSLangSpec file I have, but not in all the places you’d expect (only in the Introduction).

Thanks all,

  • LoopinFool