Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Use of discard and return

  1. #1
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212

    Use of discard and return

    Looking in the OpenGL shading language reference, I can't find the definition of "discard".

    I think it will cancel output from the fragment shader. But will it also cancel execution? Or do you need to explicitely call "return" as well?

  2. #2
    Intern Contributor
    Join Date
    Jul 2010
    Posts
    93
    Quote Originally Posted by Kopelrativ View Post
    Looking in the OpenGL shading language reference, I can't find the definition of "discard".

    I think it will cancel output from the fragment shader. But will it also cancel execution? Or do you need to explicitely call "return" as well?
    You do need to call return as well to cancel execution. IIRC, AMD drivers abandon shader execution upon discard, whilst nVidia drivers don't. The OpenGL spec does not define a specific behavior.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,792
    Looking in the OpenGL shading language reference, I can't find the definition of "discard".
    It's on page 109 (115 in PDF numbering).

    Whether discard "cancels execution" depends entirely on the hardware. In general, execution will only be canceled if an entire pixel group (the size of which depends on hardware) all execute a discard. So if you're trying to discard to avoid expensive computations, it may or may not help, depending on the spatial locality of the discards.

  4. #4
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    676
    "The discard keyword is only allowed within fragment shaders. It can be used within a fragment shader to abandon the operation on the current fragment. This keyword causes the fragment to be discarded and no updates to any buffers will occur. Control flow exits the shader, and subsequent implicit or explicit derivatives are undefined when this exit is non-uniform."


    Seems clear enough; you should not need to call return. Even if this does not really cancel execution for that fragment, it must logically act like it.

  5. #5
    Intern Contributor
    Join Date
    Jul 2010
    Posts
    93
    I had started a thread about this issue a year ago, but this didn't go very far
    http://www.opengl.org/discussion_boa...L-compiler-bug

  6. #6
    Junior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    212
    Quote Originally Posted by Alfonse Reinheart View Post
    It's on page 109 (115 in PDF numbering).
    Found it on page 107 (113 PDF).

    I used the search function for the word "discard" when displaying the document in Google Chrome, which did not turn up this reference. When I downloaded the document, I could search as expected using Acrobat PDF reader. A little worrying, I have depended on this search a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •