15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_sample_mask_override_coverage
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_NV_sample_mask_override_coverage
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Jeff Bolz, NVIDIA Corporation (jbolz 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Jeff Bolz, NVIDIA
165bd8deadSopenharmony_ci    James Helferty, NVIDIA
175bd8deadSopenharmony_ci
185bd8deadSopenharmony_ciStatus
195bd8deadSopenharmony_ci
205bd8deadSopenharmony_ci    Shipping
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ciVersion
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ci    Last Modified Date:         March 27, 2015
255bd8deadSopenharmony_ci    Revision:                   2
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ciNumber
285bd8deadSopenharmony_ci
295bd8deadSopenharmony_ci    OpenGL Extension #473
305bd8deadSopenharmony_ci    OpenGL ES Extension #236
315bd8deadSopenharmony_ci
325bd8deadSopenharmony_ciDependencies
335bd8deadSopenharmony_ci
345bd8deadSopenharmony_ci    This extension is written against the OpenGL 4.3 specification
355bd8deadSopenharmony_ci    (Compatibility Profile).
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    This extension is written against version 4.30 of the OpenGL
385bd8deadSopenharmony_ci    Shading Language Specification.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    This extension interacts with NV_framebuffer_mixed_samples.
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ci    This extension interacts with NV_fragment_program4.
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    This extension interacts with the OpenGL ES 3.0 and 3.1 specifications.
455bd8deadSopenharmony_ci
465bd8deadSopenharmony_ci    If implemented in OpenGL ES 3.0 or 3.1, OES_sample_variables is required.
475bd8deadSopenharmony_ci
485bd8deadSopenharmony_ciOverview
495bd8deadSopenharmony_ci
505bd8deadSopenharmony_ci    This extension allows the fragment shader to control whether the
515bd8deadSopenharmony_ci    gl_SampleMask output can enable samples that were not covered by the
525bd8deadSopenharmony_ci    original primitive, or that failed the early depth/stencil tests.
535bd8deadSopenharmony_ci    This can be enabled by redeclaring the gl_SampleMask output with the
545bd8deadSopenharmony_ci    "override_coverage" layout qualifier:
555bd8deadSopenharmony_ci
565bd8deadSopenharmony_ci        layout(override_coverage) out int gl_SampleMask[];
575bd8deadSopenharmony_ci
585bd8deadSopenharmony_ciNew Procedures and Functions
595bd8deadSopenharmony_ci
605bd8deadSopenharmony_ci    None.
615bd8deadSopenharmony_ci
625bd8deadSopenharmony_ciNew Tokens
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ci    None.
655bd8deadSopenharmony_ci
665bd8deadSopenharmony_ciAdditions to Chapter 15 of the OpenGL 4.3 (Compatibility Profile) Specification
675bd8deadSopenharmony_ci(Rasterization)
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ci    Modify Section 15.2.3 Shader Outputs, p. 514
705bd8deadSopenharmony_ci
715bd8deadSopenharmony_ci    (replace the paragraph describing gl_SampleMask)
725bd8deadSopenharmony_ci
735bd8deadSopenharmony_ci    The built-in integer array gl_SampleMask can be used to change the sample
745bd8deadSopenharmony_ci    coverage for a fragment from within the shader. The number of elements in
755bd8deadSopenharmony_ci    the array is:
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ci        ceil(s/32)
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ci    where <s> is the maximum number of color samples supported by the
805bd8deadSopenharmony_ci    implementation. If bit <n> of element <w> in the array is set to zero,
815bd8deadSopenharmony_ci    sample <w>*32+<n> should be considered uncovered for the purposes of
825bd8deadSopenharmony_ci    multisample fragment operations (see section 17.3.3). Modifying the sample
835bd8deadSopenharmony_ci    mask in this way may exclude covered samples from being processed further
845bd8deadSopenharmony_ci    at a per-fragment granularity. If bit <n> of element <w> in the array is
855bd8deadSopenharmony_ci    set to one and gl_SampleMask is declared with the "override_coverage"
865bd8deadSopenharmony_ci    layout qualifier, then sample <w>*32+<n> should be considered covered for
875bd8deadSopenharmony_ci    the purposes of multisample fragment operations, even if it was not covered
885bd8deadSopenharmony_ci    by the original primitive or failed early fragment tests. If a bit is set
895bd8deadSopenharmony_ci    to one and gl_SampleMask was not declared with the "override_coverage"
905bd8deadSopenharmony_ci    layout qualifier, then that sample is considered covered only if it was
915bd8deadSopenharmony_ci    covered by the original primitive and was not discarded by early fragment
925bd8deadSopenharmony_ci    tests. If the fragment shader is being evaluated at any frequency other
935bd8deadSopenharmony_ci    than per-fragment, bits of the sample mask not corresponding to the current
945bd8deadSopenharmony_ci    fragment shader invocation are ignored.
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci    Modify Section 17.3.3 Multisample Fragment Operations, p. 534
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ci    (move gl_SampleMask description before SAMPLE_ALPHA_TO_COVERAGE, and
995bd8deadSopenharmony_ci    replace with the following)
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci    If a fragment shader is active and statically assigns to the built-in
1025bd8deadSopenharmony_ci    output variable gl_SampleMask, the fragment coverage is modified in a way
1035bd8deadSopenharmony_ci    that depends on the "override_coverage" layout qualifier. If gl_SampleMask
1045bd8deadSopenharmony_ci    is qualified with "override_coverage", the fragment coverage is replaced
1055bd8deadSopenharmony_ci    with the sample mask. If gl_SampleMask is not qualified with
1065bd8deadSopenharmony_ci    "override_coverage", the fragment coverage is ANDed with the bits of the
1075bd8deadSopenharmony_ci    sample mask. If such a fragment shader did not assign a value to
1085bd8deadSopenharmony_ci    gl_SampleMask due to flow control, the value ANDed with the fragment
1095bd8deadSopenharmony_ci    coverage or replacing the fragment coverage is undefined. If no fragment
1105bd8deadSopenharmony_ci    shader is active, or if the active fragment shader does not statically
1115bd8deadSopenharmony_ci    assign values to gl_SampleMask, the fragment coverage is not modified.
1125bd8deadSopenharmony_ci
1135bd8deadSopenharmony_ciNew Implementation Dependent State
1145bd8deadSopenharmony_ci
1155bd8deadSopenharmony_ci    None.
1165bd8deadSopenharmony_ci
1175bd8deadSopenharmony_ciNew State
1185bd8deadSopenharmony_ci
1195bd8deadSopenharmony_ci    None.
1205bd8deadSopenharmony_ci
1215bd8deadSopenharmony_ciAdditions to the AGL/GLX/WGL Specifications
1225bd8deadSopenharmony_ci
1235bd8deadSopenharmony_ci    None.
1245bd8deadSopenharmony_ci
1255bd8deadSopenharmony_ciGLX Protocol
1265bd8deadSopenharmony_ci
1275bd8deadSopenharmony_ci    None.
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ciModifications to the OpenGL Shading Language Specification, Version 4.30
1305bd8deadSopenharmony_ci
1315bd8deadSopenharmony_ci
1325bd8deadSopenharmony_ci    Including the following line in a shader can be used to control the
1335bd8deadSopenharmony_ci    language features described in this extension:
1345bd8deadSopenharmony_ci
1355bd8deadSopenharmony_ci      #extension GL_NV_sample_mask_override_coverage : <behavior>
1365bd8deadSopenharmony_ci
1375bd8deadSopenharmony_ci    where <behavior> is as specified in section 3.3.
1385bd8deadSopenharmony_ci
1395bd8deadSopenharmony_ci    New preprocessor #defines are added to the OpenGL Shading Language:
1405bd8deadSopenharmony_ci
1415bd8deadSopenharmony_ci      #define GL_NV_sample_mask_override_coverage               1
1425bd8deadSopenharmony_ci
1435bd8deadSopenharmony_ci
1445bd8deadSopenharmony_ci    Modify Section 4.4.2.3 Fragment Shader Outputs (p. 64)
1455bd8deadSopenharmony_ci
1465bd8deadSopenharmony_ci    (add to the end of the section)
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ci    The built-in fragment shader variable gl_SampleMask may be redeclared using
1495bd8deadSopenharmony_ci    the layout qualifier "override_coverage":
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci    layout-qualifier-id
1525bd8deadSopenharmony_ci        override_coverage
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci    For example:
1555bd8deadSopenharmony_ci
1565bd8deadSopenharmony_ci        layout(override_coverage) out int gl_SampleMask[];
1575bd8deadSopenharmony_ci
1585bd8deadSopenharmony_ci    The effect of this qualifier is defined in Section 7.1 (Built-in Variables)
1595bd8deadSopenharmony_ci    and Section 15.2.3 of the OpenGL Specification.
1605bd8deadSopenharmony_ci
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci    Modify Section 7.1 (Built-in Variables), p. 110
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ci    (replace the description of gl_SampleMask on p. 118)
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ci    The output array gl_SampleMask[] sets the sample mask for the fragment
1675bd8deadSopenharmony_ci    being processed. If gl_SampleMask is not declared with the
1685bd8deadSopenharmony_ci    "override_coverage" layout qualifier, coverage for the current fragment
1695bd8deadSopenharmony_ci    will become the logical AND of the coverage mask and the output
1705bd8deadSopenharmony_ci    gl_SampleMask. If gl_SampleMask is declared with the "override_coverage"
1715bd8deadSopenharmony_ci    layout qualifier, coverage for the current fragment will be replaced by
1725bd8deadSopenharmony_ci    the output gl_SampleMask. This array must be sized in the fragment shader
1735bd8deadSopenharmony_ci    either implicitly or explicitly to be the same size described above. If the
1745bd8deadSopenharmony_ci    fragment shader statically assigns a value to gl_SampleMask, the sample
1755bd8deadSopenharmony_ci    mask will be undefined for any array elements of any fragment shader
1765bd8deadSopenharmony_ci    invocations that fail to assign a value. If a shader does not statically
1775bd8deadSopenharmony_ci    assign a value to gl_SampleMask, the sample mask has no effect on the
1785bd8deadSopenharmony_ci    processing of a fragment.
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci
1815bd8deadSopenharmony_ciDependencies on NV_framebuffer_mixed_samples
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ci    If NV_framebuffer_mixed_samples is supported, the definition of
1845bd8deadSopenharmony_ci    gl_SampleMask should say "maximum number of color or raster samples
1855bd8deadSopenharmony_ci    supported...".
1865bd8deadSopenharmony_ci
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ciDependencies on NV_fragment_program4
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    Modify Section 2.X.6.Y of the NV_fragment_program4 specification
1915bd8deadSopenharmony_ci
1925bd8deadSopenharmony_ci    (add new option section)
1935bd8deadSopenharmony_ci
1945bd8deadSopenharmony_ci    + Sample Mask Override Coverage (NV_sample_mask_override_coverage)
1955bd8deadSopenharmony_ci
1965bd8deadSopenharmony_ci    If a fragment program specifies the "NV_sample_mask_override_coverage"
1975bd8deadSopenharmony_ci    option, the sample mask may enable coverage for samples not covered by the
1985bd8deadSopenharmony_ci    original primitive, or those that failed early fragment tests, as described
1995bd8deadSopenharmony_ci    in Section 15.2.3 Shader Outputs.
2005bd8deadSopenharmony_ci
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ciInteractions with OpenGL ES 3.0 and 3.1
2035bd8deadSopenharmony_ci
2045bd8deadSopenharmony_ci    Modify paragraph 2 of Shader Outputs from "where <s> is the maximum number
2055bd8deadSopenharmony_ci    of color samples supported by the implementation" to "where <s> is the
2065bd8deadSopenharmony_ci    value of MAX_SAMPLES, the maximum number of..."
2075bd8deadSopenharmony_ci
2085bd8deadSopenharmony_ci    Remove any references to implicit sizing of the gl_SampleMask array, and
2095bd8deadSopenharmony_ci    modify the example for "Fragment Shader Outputs" to have an explicit array
2105bd8deadSopenharmony_ci    size:
2115bd8deadSopenharmony_ci
2125bd8deadSopenharmony_ci        layout(override_coverage) out int gl_SampleMask[(gl_MaxSamples+31)/32];
2135bd8deadSopenharmony_ci
2145bd8deadSopenharmony_ci    Modify OpenGL ES Shading Language 3.00 Specification, section 3.8
2155bd8deadSopenharmony_ci    "Identifiers:"
2165bd8deadSopenharmony_ci    
2175bd8deadSopenharmony_ci        Replace the second paragraph with the following:
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci        Identifiers starting with "gl_" are reserved for use by OpenGL ES, and
2205bd8deadSopenharmony_ci        may not be declared in a shader as either a variable or a function;
2215bd8deadSopenharmony_ci        this results in a compile-time error. However, as noted in the
2225bd8deadSopenharmony_ci        specification, there are some cases where previously declared variables
2235bd8deadSopenharmony_ci        can be redeclared, and predeclared "gl_" names are allowed to be
2245bd8deadSopenharmony_ci        redeclared in a shader only for these specific purposes. More
2255bd8deadSopenharmony_ci        generally, it is a compile-time error to redeclare a variable,
2265bd8deadSopenharmony_ci        including those starting "gl_".
2275bd8deadSopenharmony_ci
2285bd8deadSopenharmony_ciErrors
2295bd8deadSopenharmony_ci
2305bd8deadSopenharmony_ci    None.
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ciIssues
2335bd8deadSopenharmony_ci
2345bd8deadSopenharmony_ci    (1) How does this extension differ from NV_conservative_raster?
2355bd8deadSopenharmony_ci
2365bd8deadSopenharmony_ci    RESOLVED: NV_conservative_raster will generate a fragment for any pixel
2375bd8deadSopenharmony_ci    that intersects the primitive, even if no samples are covered, and all
2385bd8deadSopenharmony_ci    pixels will initially be treated as fully covered. When using this
2395bd8deadSopenharmony_ci    extension without conservative raster, fragments will only be generated
2405bd8deadSopenharmony_ci    if at least one sample is covered by the primitive, but the shader may
2415bd8deadSopenharmony_ci    turn on other samples in the same pixel.
2425bd8deadSopenharmony_ci
2435bd8deadSopenharmony_ci    (2) How does this extension interact with per-sample shading (via
2445bd8deadSopenharmony_ci    GL_SAMPLE_SHADING/glSampleShading() or attributes declared with the
2455bd8deadSopenharmony_ci    "sample" interpolation qualifier)?
2465bd8deadSopenharmony_ci
2475bd8deadSopenharmony_ci    RESOLVED: Sample shading effectively runs multiple shading passes on each
2485bd8deadSopenharmony_ci    fragment. Each of these passes may only override the coverage for samples
2495bd8deadSopenharmony_ci    owned by that pass, other bits in the sample mask are ignored.
2505bd8deadSopenharmony_ci
2515bd8deadSopenharmony_ci    (3) For OpenGL ES, should we allow implicit sizing of the gl_SampleMask
2525bd8deadSopenharmony_ci    array when it's redeclared?
2535bd8deadSopenharmony_ci
2545bd8deadSopenharmony_ci    RESOLVED: No. OpenGL ES convention is to explicitly size arrays. See issues
2555bd8deadSopenharmony_ci    4 and 5 of OES_sample_variables.
2565bd8deadSopenharmony_ci
2575bd8deadSopenharmony_ciRevision History
2585bd8deadSopenharmony_ci
2595bd8deadSopenharmony_ci    Revision 2, 2015/03/27
2605bd8deadSopenharmony_ci      - Add ES interactions
2615bd8deadSopenharmony_ci
2625bd8deadSopenharmony_ci    Revision 1
2635bd8deadSopenharmony_ci      - Internal revisions.
264