15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci    QCOM_shader_framebuffer_fetch_rate
35bd8deadSopenharmony_ci
45bd8deadSopenharmony_ciName Strings
55bd8deadSopenharmony_ci
65bd8deadSopenharmony_ci    GL_QCOM_shader_framebuffer_fetch_rate
75bd8deadSopenharmony_ci
85bd8deadSopenharmony_ciContact
95bd8deadSopenharmony_ci
105bd8deadSopenharmony_ci    Jeff Leger ( jleger 'at' qti.qualcomm.com)
115bd8deadSopenharmony_ci
125bd8deadSopenharmony_ciContributors
135bd8deadSopenharmony_ci
145bd8deadSopenharmony_ci    Jeff Leger, Qualcomm
155bd8deadSopenharmony_ci    Jonathan Wicks, Qualcomm
165bd8deadSopenharmony_ci
175bd8deadSopenharmony_ciStatus
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ci    DRAFT
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ciVersion
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ci    Last Modified Date:         August 20, 2018
245bd8deadSopenharmony_ci    Revision:                   1
255bd8deadSopenharmony_ci
265bd8deadSopenharmony_ciNumber
275bd8deadSopenharmony_ci
285bd8deadSopenharmony_ci    OpenGL ES Extension #304
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ci
315bd8deadSopenharmony_ciDependencies
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ci    OpenGL ES 2.0 and GLSL ES 1.00 are required.
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ci    This extension is written against the OpenGL ES 3.2 (May 14, 2018)
365bd8deadSopenharmony_ci    and the OpenGL ES Shading Language 3.20.4 Specification
375bd8deadSopenharmony_ci    (June 14, 2018) specifications.
385bd8deadSopenharmony_ci
395bd8deadSopenharmony_ci    This extension interacts with EXT_shader_framebuffer_fetch.
405bd8deadSopenharmony_ci    This extension interacts with ARM_shader_framebuffer_fetch_depth_stencil.
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ciOverview
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    When certain built-ins (e.g. gl_LastFragData, gl_LastFragStencilARM)
455bd8deadSopenharmony_ci    are referenced in the shader, the shader is required to execute at sample-rate
465bd8deadSopenharmony_ci    if the attachments are multisampled.  In some use-cases executing such shaders
475bd8deadSopenharmony_ci    at fragment-rate is actually the preferred behavior.  When this extension is
485bd8deadSopenharmony_ci    enabled, such GLSL shaders will execute at fragment-rate and the built-in
495bd8deadSopenharmony_ci    will return a per-fragment value.  This avoids the significant performance
505bd8deadSopenharmony_ci    penalty that would otherwise be incurred with sample-rate shading.
515bd8deadSopenharmony_ci
525bd8deadSopenharmony_ci    The following built-ins are affected when this extension is enabled:
535bd8deadSopenharmony_ci
545bd8deadSopenharmony_ci        gl_LastFragData      (from EXT_shader_framebuffer_fetch)
555bd8deadSopenharmony_ci        gl_LastFragDepthARM  (from ARM_shader_framebuffer_fetch_depth_stencil)
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    The following built-ins are disallowed when this extension is enabled:
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ci        gl_SampleID
605bd8deadSopenharmony_ci        gl_SamplePosition
615bd8deadSopenharmony_ci        interpolateAtSample()
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ciIP Status
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ci    No known IP claims.
665bd8deadSopenharmony_ci
675bd8deadSopenharmony_ciNew Procedures and Functions
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ci    None
705bd8deadSopenharmony_ci
715bd8deadSopenharmony_ciNew Tokens
725bd8deadSopenharmony_ci
735bd8deadSopenharmony_ci    None
745bd8deadSopenharmony_ci
755bd8deadSopenharmony_ciAdditions to Chapter 13 of the OpenGL ES 3.2 Specification
765bd8deadSopenharmony_ci(Fixed-Function Primitive Assembly and Rasterization)
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci    Modify Section 13.4.1, Sample Shading, p. 353
795bd8deadSopenharmony_ci
805bd8deadSopenharmony_ci    Modify the first paragraph:
815bd8deadSopenharmony_ci        "Sample shading can be used to specify a minimum number of unique samples
825bd8deadSopenharmony_ci        to process for each fragment. Sample shading is controlled by calling
835bd8deadSopenharmony_ci        Enable or Disable with target SAMPLE_SHADING."
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ci    by adding one sentence to the end:
865bd8deadSopenharmony_ci        "Sample shading can be used to specify a minimum number of unique samples
875bd8deadSopenharmony_ci        to process for each fragment. Sample shading is controlled by calling
885bd8deadSopenharmony_ci        Enable or Disable with target SAMPLE_SHADING.  For any fragment shader
895bd8deadSopenharmony_ci        that has forced fragment-rate by enabling QCOM_shader_framebuffer_fetch_rate,
905bd8deadSopenharmony_ci        such shader will execute as if SAMPLE_SHADING is disabled."
915bd8deadSopenharmony_ci
925bd8deadSopenharmony_ciAdditions to Chapter 14 (Programmable Fragment Processing) of the OpenGL ES 3.2 Specification
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ci
955bd8deadSopenharmony_ci    Modify Section 14.2.2 (Shader Inputs), p. 372
965bd8deadSopenharmony_ci
975bd8deadSopenharmony_ci        Modify the sentence:
985bd8deadSopenharmony_ci            "Using gl_SampleID in a fragment shader causes the entire shader to
995bd8deadSopenharmony_ci            be executed per-sample."
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci        to:
1025bd8deadSopenharmony_ci            "Using gl_SampleID in a fragment shader causes the entire shader to
1035bd8deadSopenharmony_ci            be executed per-sample.  If GL_QCOM_shader_framebuffer_fetch_rate is
1045bd8deadSopenharmony_ci            enabled, any use of gl_SampleID will result in a compile or link error."
1055bd8deadSopenharmony_ci
1065bd8deadSopenharmony_ci        Modify the sentence:
1075bd8deadSopenharmony_ci            "Using gl_SamplePosition in a fragment shader causes the entire shader to
1085bd8deadSopenharmony_ci            be executed per-sample."
1095bd8deadSopenharmony_ci
1105bd8deadSopenharmony_ci        to:
1115bd8deadSopenharmony_ci            "Using gl_SamplePosition in a fragment shader causes the entire shader to
1125bd8deadSopenharmony_ci            be executed per-sample.  If GL_QCOM_shader_framebuffer_fetch_rate is
1135bd8deadSopenharmony_ci            enabled, any use of gl_SamplePosition will result in a compile or link
1145bd8deadSopenharmony_ci            error."
1155bd8deadSopenharmony_ci
1165bd8deadSopenharmony_ci
1175bd8deadSopenharmony_ci    Modify Section 14.2.3 (Shader Outputs), p. 372
1185bd8deadSopenharmony_ci
1195bd8deadSopenharmony_ci        [[ The following applies if EXT_shader_framebuffer_fetch is supported ]]
1205bd8deadSopenharmony_ci
1215bd8deadSopenharmony_ci            In the new paragraphs added by EXT_shader_framebuffer_fetch to the end
1225bd8deadSopenharmony_ci            this section, change the following added sentence:
1235bd8deadSopenharmony_ci
1245bd8deadSopenharmony_ci                From:
1255bd8deadSopenharmony_ci                   "Reading from a user-defined fragment output declared inout
1265bd8deadSopenharmony_ci                   causes the shader to be evaluated per-sample, since the
1275bd8deadSopenharmony_ci                   framebuffer potentially contains different color values for
1285bd8deadSopenharmony_ci                   each sample."
1295bd8deadSopenharmony_ci
1305bd8deadSopenharmony_ci                To:
1315bd8deadSopenharmony_ci                  "If QCOM_shader_framebuffer_fetch_rate is not enabled, reading from
1325bd8deadSopenharmony_ci                  a user-defined fragment output declared inout causes the shader
1335bd8deadSopenharmony_ci                  to be evaluated per-sample, since the framebuffer potentially
1345bd8deadSopenharmony_ci                  contains different color values for each sample."
1355bd8deadSopenharmony_ci
1365bd8deadSopenharmony_ci            Add the following paragraph to the end of "Shader Outputs" section:
1375bd8deadSopenharmony_ci
1385bd8deadSopenharmony_ci              "If the current rendertarget is multisampled and if
1395bd8deadSopenharmony_ci              QCOM_shader_framebuffer_fetch_rate is enabled, then reading from
1405bd8deadSopenharmony_ci              a user-defined fragment output declared inout will return an
1415bd8deadSopenharmony_ci              implementation-dependent weighted average of the samples within
1425bd8deadSopenharmony_ci              the destination pixel covered by the current fragment.  The value
1435bd8deadSopenharmony_ci              will be between the minium and maximum value of the covered samples.
1445bd8deadSopenharmony_ci              If the destination colors must be linearized from sRGB as
1455bd8deadSopenharmony_ci              described in the preceding paragraphs, the conversion from sRGB
1465bd8deadSopenharmony_ci              to linear happens before computing the weighted average.
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ciAdditions to the EGL Specifications
1495bd8deadSopenharmony_ci
1505bd8deadSopenharmony_ci    None.
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ciModifications to The OpenGL ES Shading Language Specification, Version 3.20.4
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci    Changes to section 7.1.5. (Fragment Shader Special Variables), p 120.
1555bd8deadSopenharmony_ci
1565bd8deadSopenharmony_ci        Add the following at the start of this section:
1575bd8deadSopenharmony_ci
1585bd8deadSopenharmony_ci            "Static use of certain built-in variables described in this section
1595bd8deadSopenharmony_ci            will cause the shader to be evaluated per-sample. This language feature
1605bd8deadSopenharmony_ci            can be optionally disabled, forcing such shaders to evaluate per-
1615bd8deadSopenharmony_ci            fragment.  The optional behavior can be enabled using:
1625bd8deadSopenharmony_ci
1635bd8deadSopenharmony_ci            #extension GL_QCOM_shader_framebuffer_fetch_rate : <behavior>
1645bd8deadSopenharmony_ci
1655bd8deadSopenharmony_ci            where <behavior> is as specified in section 3.4 (Preprocessor).
1665bd8deadSopenharmony_ci
1675bd8deadSopenharmony_ci            If GL_QCOM_shader_framebuffer_fetch_rate is enabled, it is a compile-time
1685bd8deadSopenharmony_ci            or link-time error if any variable is declared with the "sample"
1695bd8deadSopenharmony_ci            qualifier or if the built-in function interpolateAtSample() is statically
1705bd8deadSopenharmony_ci            referenced."
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ci            Add the New preprocessor #defines are added to the OpenGL ES Shading Language:
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ci            "#define GL_QCOM_shader_framebuffer_fetch_rate  1"
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci        Modify the last sentence of the paragraph starting with "The input variable
1775bd8deadSopenharmony_ci        gl_SampleID is filled with the sample number of the sample currently being
1785bd8deadSopenharmony_ci        processed"
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci        from:
1815bd8deadSopenharmony_ci            "Any static use of this variable in a fragment shader causes the entire
1825bd8deadSopenharmony_ci            shader to be evaluated per-sample."
1835bd8deadSopenharmony_ci        to
1845bd8deadSopenharmony_ci            "If GL_QCOM_shader_framebuffer_fetch_rate is not enabled, any static use
1855bd8deadSopenharmony_ci            of this variable in a fragment shader causes the entire shader to be evaluated
1865bd8deadSopenharmony_ci            per-sample.  If GL_QCOM_shader_framebuffer_fetch_rate is enabled, an static
1875bd8deadSopenharmony_ci            reference to gl_SampleID will cause a compile or link error."
1885bd8deadSopenharmony_ci
1895bd8deadSopenharmony_ci        Modify the last sentence of the paragraph starting with "The input variable
1905bd8deadSopenharmony_ci        gl_SamplePosition contains the position of the current sample within the
1915bd8deadSopenharmony_ci        multisample draw buffer."
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ci        from:
1945bd8deadSopenharmony_ci            "Any static use of this variable in a fragment shader causes the entire
1955bd8deadSopenharmony_ci            shader to be evaluated per-sample."
1965bd8deadSopenharmony_ci        to
1975bd8deadSopenharmony_ci            "If GL_QCOM_shader_framebuffer_fetch_rate is not enabled, any static use of
1985bd8deadSopenharmony_ci            this variable in a fragment shader causes the entire shader to be evaluated
1995bd8deadSopenharmony_ci            per-sample.  If GL_QCOM_shader_framebuffer_fetch_rate is enabled, an static
2005bd8deadSopenharmony_ci            reference to gl_SamplePosition will cause a compile or link error."
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ciInteractions with EXT_shader_framebuffer_fetch.
2035bd8deadSopenharmony_ci
2045bd8deadSopenharmony_ci    Extension EXT_shader_framebuffer_fetch adds built-ins (gl_LastFragData[] for
2055bd8deadSopenharmony_ci    version 1.0 shaders and inout variables version 3.0 shaders) that cause fragment
2065bd8deadSopenharmony_ci    shaders to run at sample-rate.  This extension relaxes that requirement to
2075bd8deadSopenharmony_ci    allow fragment-rate and specifies that the value returned from gl_LastFragData
2085bd8deadSopenharmony_ci    will be an implementation-dependent weighted average of the covered pixels.
2095bd8deadSopenharmony_ci
2105bd8deadSopenharmony_ciInteractions with ARM_shader_framebuffer_fetch_depth_stencil.
2115bd8deadSopenharmony_ci
2125bd8deadSopenharmony_ci   Extension ARM_shader_framebuffer_fetch adds built-in "gl_LastFragDepthARM",
2135bd8deadSopenharmony_ci   and specifies the value returned -- for both sample-rate and fragment-rate
2145bd8deadSopenharmony_ci   execution.  This extension can be used to control whether sample-rate or
2155bd8deadSopenharmony_ci   fragment-rate execution is used.
2165bd8deadSopenharmony_ci
2175bd8deadSopenharmony_ciErrors
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci    None.
2205bd8deadSopenharmony_ci
2215bd8deadSopenharmony_ciNew State
2225bd8deadSopenharmony_ci
2235bd8deadSopenharmony_ci    None.
2245bd8deadSopenharmony_ci
2255bd8deadSopenharmony_ciNew Implementation Dependent State
2265bd8deadSopenharmony_ci
2275bd8deadSopenharmony_ci    None
2285bd8deadSopenharmony_ci
2295bd8deadSopenharmony_ciIssues
2305bd8deadSopenharmony_ci
2315bd8deadSopenharmony_ci    (1) Does it make sense to enable this extension for a shader that references
2325bd8deadSopenharmony_ci        per-sample built-ins like gl_SampleID and gl_SamplePosition?
2335bd8deadSopenharmony_ci
2345bd8deadSopenharmony_ci        RESOLVED: No.  It doesn't make sense to force fragment-rate
2355bd8deadSopenharmony_ci        execution using this extension, while also referencing per-sample
2365bd8deadSopenharmony_ci        built-ins.  Since there is no known use-case, this will be a compile
2375bd8deadSopenharmony_ci        or link error.
2385bd8deadSopenharmony_ci
2395bd8deadSopenharmony_ci        For the same reason, using the "sample" qualifier or using
2405bd8deadSopenharmony_ci        interpolateAtSample() will cause a compile or link error.
2415bd8deadSopenharmony_ci
2425bd8deadSopenharmony_ci    (2) How does this extension interact with API-controlled sample-rate shading?
2435bd8deadSopenharmony_ci
2445bd8deadSopenharmony_ci        RESOLVED: For shaders that enable this this extension, those the shaders
2455bd8deadSopenharmony_ci        will always execute at fragment-rate, regardless of other API states.
2465bd8deadSopenharmony_ci        In particular, the enable/disable of SAMPLE_SHADING and the value of
2475bd8deadSopenharmony_ci        MIN_SAMPLE_SHADING_VALUE will have no effect on such shaders.
2485bd8deadSopenharmony_ci
2495bd8deadSopenharmony_ci    (3) How does this extension differ from ARM_shader_framebuffer_fetch?
2505bd8deadSopenharmony_ci
2515bd8deadSopenharmony_ci        ARM_shader_framebuffer_fetch provides a means for controlling whether
2525bd8deadSopenharmony_ci        shaders fetching color from the framebuffer should execute at sample-rate or
2535bd8deadSopenharmony_ci        fragement rate.  The API state "FETCH_PER_SAMPLE_ARM" controls
2545bd8deadSopenharmony_ci        this behavior.
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ci        This extension also provides control over sample-rate vs fragment-rate
2575bd8deadSopenharmony_ci        for framebuffer fetch shaders, but does so in the GLSL shader.  Some
2585bd8deadSopenharmony_ci        implementations require this information at shader compile time.
2595bd8deadSopenharmony_ci
2605bd8deadSopenharmony_ciRevision History
2615bd8deadSopenharmony_ci
2625bd8deadSopenharmony_ci    Rev.    Date      Author    Changes
2635bd8deadSopenharmony_ci    ----  ----------  --------  -----------------------------------------
2645bd8deadSopenharmony_ci    1     2018-08-20  jleger     initial version
265