PDA

View Full Version : SV_Coverage input -> GLSL?



Dark Photon
11-22-2010, 07:54 PM
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.

aqnuep
11-23-2010, 07:15 AM
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.

Dark Photon
11-24-2010, 08:03 PM
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.

LoopinFool
07-13-2011, 01:30 PM
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

Alfonse Reinheart
07-13-2011, 02:15 PM
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.

Foobarbazqux
07-13-2011, 02:51 PM
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.

Alfonse Reinheart
07-13-2011, 05:21 PM
That's... annoying. I dropped a bug (http://www.khronos.org/bugzilla/show_bug.cgi?id=495) on this; hopefully they'll fix this one.

LoopinFool
07-13-2011, 05:25 PM
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.

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