• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1    Name
2
3        EXT_fragment_shading_rate
4
5    Name Strings
6
7        GL_EXT_fragment_shading_rate
8        GL_EXT_fragment_shading_rate_primitive
9        GL_EXT_fragment_shading_rate_attachment
10
11    Contributors
12
13        Jan-Harald Fredriksen, Arm
14        Ralph Potter, Samsung
15        Tate Hornbeck, Qualcomm
16        Laurie Hedge, Imagination Technologies
17        Contributors to QCOM_shading_rate
18
19    Contact
20
21        Jan-Harald Fredriksen ( jan-harald.fredriksen 'at' arm.com)
22
23    Status
24
25        Complete
26
27    Version
28
29        Last Modified Date: July 7, 2022
30        Revision: #2
31
32    Number
33
34        OpenGL ES Extension #340
35
36    Dependencies
37
38        OpenGL ES 2.0 is required.  This extension is written against OpenGL ES 3.2.
39
40        This extension interacts with OVR_multiview.
41        This extension interacts with QCOM_framebuffer_foveated and QCOM_texture_foveated
42        This extension interacts with EXT_shader_pixel_local_storage and
43        EXT_shader_pixel_local_storage2
44
45        When the GL_EXT_fragment_shading_rate extension or the
46        GL_EXT_fragment_shading_rate_attachment extension is advertised, the
47        implementation must also advertise either GLSL extension
48        GL_EXT_fragment_shading_rate or GLSL extension
49        GL_EXT_fragment_invocation_density (both documented separately).
50        The GLSL extensions provide built-in variables that allow fragment
51        shaders to determine the effective shading rate used for fragment
52        invocations.
53
54        When the GL_EXT_fragment_shading_rate_primitive extension is advertised,
55        the implementation must also advertise GLSL
56        extension "GL_EXT_fragment_shading_rate" (documented separately), which
57        provides new built-in variables that allow vertex and geometry shaders to
58        specify the fragment shading per primitive and also allow fragment shaders to
59        determine the effective shading rate used for fragment invocations.
60
61    Overview
62
63        By default, OpenGL runs a fragment shader once for each pixel covered by a
64        primitive being rasterized.  When using multisampling, the outputs of that
65        fragment shader are broadcast to each covered sample of the fragment's
66        pixel.  When using multisampling, applications can optionally request that
67        the fragment shader be run once per color sample (e.g., by using the "sample"
68        qualifier on one or more active fragment shader inputs), or run a minimum
69        number of times per pixel using SAMPLE_SHADING enable and the
70        MinSampleShading frequency value.
71
72        This extension allows applications to specify fragment shading rates of less
73        than 1 invocation per pixel.  Instead of invoking the fragment shader
74        once for each covered pixel, the fragment shader can be run once for a
75        group of adjacent pixels in the framebuffer.  The outputs of that fragment
76        shader invocation are broadcast to each covered sample for all of the pixels
77        in the group.  The initial version of this extension allows for groups of
78        1, 2, 4, 8, and 16 pixels.
79
80        This can be useful for effects like motion volumetric rendering
81        where a portion of scene is processed at full shading rate and a portion can
82        be processed at a reduced shading rate, saving power and processing resources.
83        The requested rate can vary from (finest and default) 1 fragment shader
84        invocation per pixel to (coarsest) one fragment shader invocation for each
85        4x4 block of pixels.
86
87    New Tokens
88
89        Accepted by the <attachment> parameter of FramebufferShadingRateEXT
90        and GetFramebufferAttachmentParameteriv:
91
92            SHADING_RATE_ATTACHMENT_EXT                             0x96D1
93
94        Allowed in the <rate> parameter in ShadingRateEXT:
95            SHADING_RATE_1X1_PIXELS_EXT                             0x96A6
96            SHADING_RATE_1X2_PIXELS_EXT                             0x96A7
97            SHADING_RATE_1X4_PIXELS_EXT                             0x96AA
98            SHADING_RATE_2X1_PIXELS_EXT                             0x96A8
99            SHADING_RATE_2X2_PIXELS_EXT                             0x96A9
100            SHADING_RATE_2X4_PIXELS_EXT                             0x96AD
101            SHADING_RATE_4X1_PIXELS_EXT                             0x96AB
102            SHADING_RATE_4X2_PIXELS_EXT                             0x96AC
103            SHADING_RATE_4X4_PIXELS_EXT                             0x96AE
104
105        Accepted by the <combinerOp0> and <combinerOp1> parameters of
106        ShadingRateCombinerOpsEXT:
107
108            FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT              0x96D2
109            FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT           0x96D3
110            FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_EXT               0x96D4
111            FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_EXT               0x96D5
112            FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_EXT               0x96D6
113
114        Accepted by the <pname> parameter of GetIntegerv, GetBooleanv, GetFloatv,
115        and GetInteger64v:
116
117            SHADING_RATE_EXT                                                         0x96D0
118            MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT                     0x96D7
119            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT                     0x96D8
120            MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT                    0x96D9
121            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT                    0x96DA
122            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO_EXT              0x96DB
123            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS_EXT                          0x96DC
124            FRAGMENT_SHADING_RATE_WITH_SHADER_DEPTH_STENCIL_WRITES_SUPPORTED_EXT     0x96DD
125            FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED_EXT                     0x96DE
126            FRAGMENT_SHADING_RATE_ATTACHMENT_WITH_DEFAULT_FRAMEBUFFER_SUPPORTED_EXT  0x96DF
127            FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT                0x8F6F
128
129    New Procedures and Functions
130
131        void ShadingRateEXT(enum rate)
132        void ShadingRateCombinerOpsEXT(enum combinerOp0, enum combinerOp1)
133        void FramebufferShadingRateEXT(enum target, enum attachment, uint texture, int baseLayer, sizei numLayers, sizei texelWidth, sizei texelHeight)
134        void GetFragmentShadingRatesEXT(sizei samples, sizei maxCount, sizei *count, enum *shadingRates)
135
136    Modifications to the OpenGL ES 3.2 Specification
137
138        Modify Section 8.14.1, Scale Factor and Level of Detail, p. 196
139
140        (Modify the function approximating Scale Factor (P), to allow implementations
141         to scale implicit derivatives based on the shading rate.  The scale occurs before
142         the LOD bias and before LOD clamping).
143
144         Modify the definitions of (mu, mv, mw):
145
146                        |   du       du    |
147              mu = max  |  -----  , -----  |
148                        |   dx       dy    |
149
150                        |   dv       dv    |
151              mv = max  |  -----  , -----  |
152                        |   dx       dy    |
153
154                        |   dw       dw    |
155              mw = max  |  -----  , -----  |
156                        |   dx       dy    |
157         to:
158                        |   du          du        |
159              mu = max  |  ---- * sx , ---- * sy  |
160                        |   dx          dy        |
161
162                        |   dv          dv        |
163              mv = max  |  ---- * sx , ---- * sy  |
164                        |   dx          dy        |
165
166                        |   dw          dw        |
167              mw = max  |  ---- * sx , ---- * sy  |
168                        |   dx          dy        |
169
170              where (sx, sy) refer to _effective shading rate_ (w', h') specified in
171              section 13.X.2.
172
173        Modifications to Chapter 9 of the OpenGL ES 3.2 Specification (Framebuffers
174        and Framebuffer Objects)
175
176            Modify the description of GetFramebufferAttachmentParameteriv to include
177            SHADING_RATE_ATTACHMENT_EXT:
178
179            "Otherwise, attachment must be one of the attachment points of the framebuffer
180             listed in table 9.1 or SHADING_RATE_ATTACHMENT_EXT."
181
182            Add the following to the list of conditions required for framebuffer
183            attachment completeness in section 9.4.1 (Framebuffer Attachment
184            Completeness):
185
186            If <image> is a two-dimensional array and the attachment
187            is SHADING_RATE_ATTACHMENT_EXT, all the selected layers,
188            [<baseLayer>, <baseLayer> + <numLayers>), are less than the layer
189            count of the texture.
190
191        Modify Section 13.4, Multisampling, p. 353
192
193        (add to the end of the section)
194
195            When SHADING_RATE_EXT is set to a value other than SHADING_RATE_1X1_PIXELS_EXT,
196            the rasterization will occur at the _effective shading rate_ (Section 13.X) and
197            will result in fragments covering a <W>x<H> group of pixels.
198
199            When multisample rasterization is enabled, the samples of the fragment will consist
200            of the samples for each of the pixels in the group.  The fragment center will be
201            the center of this group of pixels.  Each fragment will include a coverage value
202            with (W x H x SAMPLES) bits.  For example, if SHADING_RATE_EXT is 2x2 and the
203            currently bound framebuffer object has SAMPLES equal to 4 (4xMSAA), then the fragment
204            will consist of 4 pixels and 16 samples.  Similarly, each fragment will have
205            (W * H * SAMPLES) depth values and associated data.
206
207        The contents of Section 13.4.1, Sample Shading, p. 355 is moved to the new Section 13.X.3, "Sample Shading".
208
209        Add new section 13.X before Section 13.5, Points, p. 355
210
211            Section 13.X, Shading Rate
212
213            By default, each fragment processed by programmable fragment processing
214            corresponds to a single pixel with a single (x,y) coordinate. When using
215            multisampling, implementations are permitted to run separate fragment shader
216            invocations for each sample, but often only run a single invocation for all
217            samples of the fragment.  We will refer to the density of fragment shader
218            invocations as the _shading rate_.
219            Applications can use the shading rate to increase the size of fragments to
220            cover multiple pixels and reduce the amount of fragment shader work.
221            Applications can also use the shading rate to explicitly control the minimum
222            number of fragment shader invocations when multisampling.
223
224            Section 13.X.1, Draw Call Fragment Shading Rate
225
226            The draw call fragment shading rate can controlled with the command
227
228               void ShadingRateEXT(enum rate);
229
230            <rate> specifies the value of SHADING_RATE_EXT, and defines the
231            _shading rate_.  Valid values for <rate> are described in
232            table X.1
233
234                Shading Rate                   Size
235                ----------------------------   -----
236                SHADING_RATE_1X1_PIXELS_EXT    1x1
237                SHADING_RATE_1X2_PIXELS_EXT    1x2
238                SHADING_RATE_1X4_PIXELS_EXT    1x4
239                SHADING_RATE_2X1_PIXELS_EXT    2x1
240                SHADING_RATE_2X2_PIXELS_EXT    2x2
241                SHADING_RATE_2X4_PIXELS_EXT    2x4
242                SHADING_RATE_4X1_PIXELS_EXT    4x1
243                SHADING_RATE_4X2_PIXELS_EXT    4x2
244                SHADING_RATE_4X4_PIXELS_EXT    4x4
245
246                Table X.1:  Shading rates accepted by ShadingRateEXT.  An
247                entry of "<W>x<H>" in the "Size" column indicates that the shading
248                rate request for fragments with a width and height (in pixels) of <W>
249                and <H>, respectively.
250
251            If the shading rate is specified with ShadingRateEXT, it will apply to all
252            draw buffers.  If the shading rate has not been set, the shading rate
253            will be SHADING_RATE_1X1_PIXELS_EXT.  In either case, the shading rate will
254            be further adjusted as described in the following sections.
255
256            Errors
257
258                INVALID_ENUM is generated by ShadingRateEXT if <rate> is not
259                a valid shading rate from table X.1
260
261
262[[If GL_EXT_fragment_shading_rate_primitive is supported]]
263            Section 13.X.2, Primitive Fragment Shading Rate
264
265            The primitive fragment shading rate can be set via the gl_PrimitiveShadingRateEXT
266            built-in in the last active pre-rasterization shader stage. The rate associated
267            with a given primitive is sourced from the value written to gl_PrimitiveShadingRateEXT
268            by that primitive’s provoking vertex.
269            If the last active pre-rasterization shader stage does not write to
270            gl_PrimitiveShadingRateEXT,then it is as if the shader specified a
271            fragment shading rate value of 0, indicating a horizontal and vertical
272            rate of 1 pixel.
273
274[[If GL_EXT_fragment_shading_rate_attachment is supported]]
275            Section 13.X.3, Attachment Fragment Shading Rate
276
277            An attachment shading rate can be set by attaching a specified image from a
278            texture object as one of the logical buffers of a framebuffer
279            object with the command:
280
281            void FramebufferShadingRateEXT(enum target, enum attachment, uint texture, GLint baseLayer, GLsizei numLayers, GLsizei texelWidth, GLsizei texelHeight);
282
283            <target> must be DRAW_FRAMEBUFFER, READ_FRAMEBUFFER, or FRAMEBUFFER.
284            FRAMEBUFFER is equivalent to DRAW_FRAMEBUFFER.
285
286            <attachment> must be SHADING_RATE_ATTACHMENT_EXT.
287
288            If <texture> is not zero, then <texture> must name an existing
289            immutable-format texture with a target of TEXTURE_2D or TEXTURE_2D_ARRAY
290            with a format of R8UI.
291
292            If <texture> has multiple mipmap levels, only the base level will be
293            used as the fragment shading rate attachment.
294
295            <baseLayer> specifies the base layer of a two-dimensional image within
296            <texture>.
297
298            <numLayers> specifies the number of layers, starting from <baseLayer> from
299            within <texture> to attach.
300
301            <texelWidth> is the width of the framebuffer corresponding to each texel
302            in a fragment shading rate attachment. It must be a power-of-two value that
303            is greater or equal to MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
304            and less than or equal to MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT.
305
306            The values of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
307            and MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
308            indicate, respectively, the minimum and maximum supported width of
309            the portion of the framebuffer corresponding to each texel in a
310            fragment shading rate attachment. Both values must be a power-of-two
311            and the value of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
312            must be less than or equal to the value of
313            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT.
314
315            <texelHeight> is the height of the framebuffer corresponding to each texel
316            in a fragment shading rate attachment. It must be a power-of-two value that
317            is greater or equal to MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
318            and less than or equal to MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT.
319
320            The values of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
321            and MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
322            indicate, respectively, the minimum and maximum supported height of
323            the portion of the framebuffer corresponding to each texel in a
324            fragment shading rate attachment. Both values must be a power-of-two
325            and the value of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
326            must be less than or equal to the value of
327            MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT.
328
329            Each pixel in the framebuffer is assigned an attachment fragment shading rate
330            by the corresponding texel in the fragment shading rate attachment, according to:
331
332                x' = floor(x / region_x)
333                y' = floor(y / region_y)
334
335            where x' and y' are the coordinates of a texel in the fragment shading
336            rate attachment, x and y are the coordinates of the pixel in the
337            framebuffer, and region_x and region_y are the size of the region each
338            texel corresponds to, as defined by the <texelWidth> and <texelHeight>
339            parameters to FramebufferShadingRateEXT.
340
341            [[If OVR_Multiview is supported]]
342            If multiview is enabled and the shading rate attachment has multiple
343            layers, the shading rate attachment texel is selected from the layer
344            determined by the gl_ViewID_OVR built-in. If multiview is disabled, and
345            both the shading rate attachment and the framebuffer have multiple
346            layers, the shading rate attachment texel is selected from the layer
347            determined by the Layer built-in. Otherwise, the texel is
348            unconditionally selected from the first layer of the attachment.
349
350            The fragment size is encoded into the first component of the identified
351            texel as follows:
352
353                size_w = 2^((texel/4)&3)
354                size_h = 2^(texel&3)
355
356            where texel is the value in the first component of the identified
357            texel, and size_w and size_h are the width and height of the fragment
358            size, decoded from the texel.
359            If no fragment shading rate attachment is specified, this size is
360            calculated as size_w = size_h = 1.
361
362            Applications must not specify a width or height greater than 4 by this
363            method.
364            The encoding of the gl_ShadingRateEXT built-in in
365            GL_EXT_fragment_shading_rate adheres to the above encoding.
366
367            Errors
368
369                An INVALID_ENUM error is generated if <target> is not
370                DRAW_FRAMEBUFFER, READ_FRAMEBUFFER, or FRAMEBUFFER.
371
372                An INVALID_ENUM error is generated if <attachment> is not
373                SHADING_RATE_ATTACHMENT_EXT.
374
375                An INVALID_VALUE error is generated if <texture> is not zero
376                and is not the name of an immutable texture object.
377
378                An INVALID_VALUE error is generated if <baseLayer> is greater
379                than or equal to the value of
380                MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS_EXT.
381
382                An INVALID_VALUE error is generated if <numLayers> is greater
383                than the value of
384                MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS_EXT.
385
386                An INVALID_VALUE error is generated if
387                <texelWidth> / <texelHeight> is larger than
388                MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO_EXT.
389
390                An INVALID_VALUE error is generated if
391                <texelHeight> / <texelWidth> is larger than
392                MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO_EXT.
393
394                An INVALID_OPERATION error is generated if the default
395                framebuffer is bound to <target> and the value of
396                FRAGMENT_SHADING_RATE_ATTACHMENT_WITH_DEFAULT_FRAMEBUFFER_SUPPORTED_EXT
397                is FALSE.
398
399            Section 13.X.4, Combining the Fragment Shading Rates
400
401            The final rate (Cxy') used for fragment shading must be one of the rates returned by
402            GetFragmentShadingRatesEXT for the sample count
403            used by rasterization.
404
405            If any of the following conditions are met, Cxy' must be set to {1,1}:
406                * Per-sample shading is enabled.
407                * The fragment shader statically writes to gl_FragDepth and the
408                  value of FRAGMENT_SHADING_RATE_WITH_SHADER_DEPTH_STENCIL_WRITES_SUPPORTED_EXT
409                  is FALSE.
410                * The value of FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED_EXT is FALSE
411                  and either the value of SAMPLE_MASK_VALUE does not have all bits of all words set,
412                  or the fragment shader statically writes to gl_SampleMask.
413                * The fragment shader statically references the gl_FragCoord built-in variable and does
414                  not enable the GL_EXT_fragment_shading_rate extension.
415
416            Otherwise, each of the specified shading rates are combined and then used to derive the value of Cxy'.
417            As there are three ways to specify shading rates, two combiner
418            operations are specified - between the pipeline and primitive shading
419            rates, and between the result of that and the attachment shading rate.
420
421            The fragment shading rate combiner operations can controlled with the command
422
423                void ShadingRateCombinerOpsEXT(enum combinerOp0, enum combinerOp1)
424
425            <combinerOps> is an array of combiner equations, specified as:
426
427                * FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT specifies a combiner operation of combine(Axy ,Bxy) = Axy.
428                * FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT specifies a combiner operation of combine(Axy,Bxy) = Bxy.
429                * FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_EXT specifies a combiner operation of combine(Axy,Bxy) = min(Axy,Bxy).
430                * FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_EXT specifies a combiner operation of combine(Axy,Bxy) = max(Axy,Bxy).
431                * FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_EXT specifies a combiner operation of combine(Axy,Bxy) = Axy*Bxy.
432
433            where combine(Axy,Bxy) is the combine operation, and Axy and Bxy are the inputs to the operation.
434
435           The FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_EXT, FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_EXT, and
436           FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_EXT combiner operations are only supported if the value of
437           FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT is TRUE.
438
439           These operations are performed in a component-wise fashion.
440
441           This is used to generate a combined fragment area using the equation:
442
443               Cxy = combine(Axy,Bxy)
444
445           where Cxy is the combined fragment area result, and Axy and Bxy are the fragment areas of the
446           fragment shading rates being combined.
447           Two combine operations are performed, first with Axy equal to the draw call fragment shading rate
448           and Bxy equal to the primitive fragment shading rate, with the combine() operation selected by
449           combinerOp0. A second combination is then performed, with Axy equal to the result of the first
450           combination and Bxy equal to the attachment fragment shading rate, with the combine() operation
451           selected by combinerOp1. The result of the second combination is used as the final fragment
452           shading rate, reported via the ShadingRateKHR built-in.
453           Implementations may clamp the Cxy result of each combiner operation separately, or only after the
454           second combiner operation.
455
456           If the final combined rate is one of the rates returned by GetFragmentShadingRatesEXT for the
457           sample count used by rasterization, Cxy' = Cxy. Otherwise, Cxy' is selected from the rates returned
458           by GetFragmentShadingRatesEXT for the sample count used by rasterization.
459           From this list of supported rates, the following steps are applied in order, to select a single value:
460
461               1. Keep only rates where Cx' ≤ Cx and Cy' ≤ Cy.
462                  * Implementations may also keep rates where Cx' ≤ Cy and Cy' ≤ Cx.
463               2. Keep only rates with the highest area (Cx' × Cy').
464               3. Keep only rates with the lowest aspect ratio (Cx' + Cy').
465               4. In cases where a wide (e.g. 4x1) and tall (e.g. 1x4) rate remain, the implementation may choose
466                  either rate. However, it must choose this rate consistently for the same shading rates and
467                  combiner operations for the lifetime of the GL context.
468
469            Errors
470
471                An INVALID_ENUM error is generated if <combinerOp0> is not
472                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT,
473                FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT,
474                FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_EXT,
475                FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_EXT, or
476                FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_EXT
477
478                An INVALID_ENUM error is generated if <combinerOp1> is not
479                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT,
480                FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT,
481                FRAGMENT_SHADING_RATE_COMBINER_OP_MIN_EXT,
482                FRAGMENT_SHADING_RATE_COMBINER_OP_MAX_EXT, or
483                FRAGMENT_SHADING_RATE_COMBINER_OP_MUL_EXT
484
485                An INVALID_OPERATION error is generated if
486                the value of
487                FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT
488                is FALSE and <combinerOp0> is not
489                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT or
490                FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT
491
492                An INVALID_OPERATION error is generated if
493                the value of
494                FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT
495                is FALSE and <combinerOp1> is not
496                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT or
497                FRAGMENT_SHADING_RATE_COMBINER_OP_REPLACE_EXT
498
499[[If GL_EXT_fragment_shading_rate_primitive is not supported]]
500                An INVALID_OPERATION error is generated if <combinerOp0> is not
501                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT
502
503[[If GL_EXT_fragment_shading_rate_attachment is not supported]]
504                An INVALID_OPERATION error is generated if <combinerOp1> is not
505                FRAGMENT_SHADING_RATE_COMBINER_OP_KEEP_EXT
506
507
508            Section 13.X.5 Sample Shading
509
510            [[The contents from Section 13.4.1, Sample Shading, p. 355 is copied here]]
511
512        Modifications to Section 13.8.2, Scissor Test (p. 367)
513        (add to the end of the section)
514
515        When the _effective shading rate_ results in fragments covering more than one pixel,
516        the scissor tests are performed separately for each pixel in the fragment.
517        If a pixel covered by a fragment fails the scissor test, that pixel is
518        treated as though it was not covered by the primitive.  If all pixels covered
519        by a fragment are either not covered by the primitive being rasterized or fail
520        the scissor test, the fragment is discarded.
521
522        Modifications to Section 13.8.3, Multisample Fragment Operations (p. 368)
523
524       (modify the last sentence of the the first paragraph to indicate that sample mask
525        operations are performed when shading rate is used, even if multisampling is not
526        enabled which can produce fragments covering more than one pixel where each pixel
527        is considered a "sample")
528
529        Change the following sentence from:
530            "If the value of SAMPLE_BUFFERS is not one, this step is skipped."
531        to:
532            "This step is skipped if SAMPLE_BUFFERS is not one, unless SHADING_RATE_EXT
533            is set to a value other than SHADING_RATE_1X1_PIXELS_EXT."
534
535        (add to the end of the section)
536
537        When the _effective shading rate_ results in fragments covering more than one pixel,
538        each fragment will generate a composite coverage mask that includes separate
539        coverage bits for each sample in each pixel covered by the fragment.  This
540        composite coverage mask will be used by the GLSL built-in input variable
541        gl_SampleMaskIn[] and updated according to the built-in output variable
542        gl_SampleMask[].  The number of composite coverage mask bits in the built-in
543        variables and their mapping to a specific pixel and sample number
544        within that pixel is implementation-defined.
545
546        Modify Section 14.1, Fragment Shader Variables (p. 370)
547
548        (modify sixth paragraph, p. 371, specifying that the "centroid" location
549         for multi-pixel fragments is implementation-dependent, and is allowed to
550         be outside the primitive)
551
552        After the following sentence:
553            "When interpolating variables declared using "centroid in",
554             the variable is sampled at a location within the pixel covered
555             by the primitive generating the fragment."
556        Add the following sentence:
557            "When the _effective shading rate_ results in fragments covering more than one
558            pixel, variables declared using "centroid in" are sampled from an
559            implementation-dependent location within any one of the covered pixels."
560
561        Modify Section 15.1, Per-Fragment Operations (p. 378)
562
563        (insert a new paragraph after the first paragraph of the section)
564
565        When the _effective shading rate_ results in fragments covering multiple pixels,
566        the operations described in the section are performed independently for
567        each pixel covered by the fragment.  The set of samples covered by each pixel
568        is determined by extracting the portion of the fragment's composite coverage
569        that applies to that pixel, as described in section 13.8.3.
570
571
572        Section 13.X.5 Fragment shading rate queries
573
574        The supported fragment shading rates can be queried with the command
575
576               void GetFragmentShadingRatesEXT(sizei samples, sizei maxCount, sizei *count, enum *shadingRates);
577
578        The actual number of rates written into <shadingRates> is returned in <count>. If no rates are
579        supported, <count> is set to zero. If <count> is NULL then it is ignored. The maximum number of
580        rates that may be written into <shadingRates> is specified by <maxCount>.
581
582        The shading rates must include the combinations listed in Table X.2.
583
584                Samples       |   Shading Rate
585                --------------|--------------------------------
586                1             |   SHADING_RATE_1X1_PIXELS_EXT,
587                              |   SHADING_RATE_1X2_PIXELS_EXT,
588                              |   SHADING_RATE_2X1_PIXELS_EXT,
589                              |   SHADING_RATE_2X2_PIXELS_EXT
590                --------------|--------------------------------
591                4             |   SHADING_RATE_1X1_PIXELS_EXT,
592                              |   SHADING_RATE_1X2_PIXELS_EXT,
593                              |   SHADING_RATE_2X1_PIXELS_EXT,
594                              |   SHADING_RATE_2X2_PIXELS_EXT
595                -----------------------------------------------
596
597                Table X.2:  Required shading rates
598
599
600    New State
601
602    Add to table 21.7, Rasterization
603
604    Get Value                               Type  Get Command  Initial Value                     Description              Sec
605    -------------------------------------   ----  -----------  --------------------------------  --------------           ------
606    SHADING_RATE_EXT                        E     GetIntegerv  SHADING_RATE_1X1_PIXELS_EXT       draw call shading rate   13.X.1
607
608
609[[If GL_EXT_fragment_shading_rate_attachment is supported]]
610    Add to table 21.40, Implementation Dependent Values
611
612    Get Value                                                   Type  Get Command  Minimum Value  Description                         Sec
613    -------------------------------------                       ----  -----------  -------------  --------------                      ------
614    MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT        Z+    GetIntegerv  32 (**)        minimum supported width of the      13.X.3
615                                                                                                  portion of the framebuffer
616                                                                                                  corresponding to each texel in
617                                                                                                  a fragment shading rate attachment
618    MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT       Z+    GetIntegerv  32 (**)        minimum supported height of the     13.X.3
619                                                                                                  portion of the framebuffer
620                                                                                                  corresponding to each texel in
621                                                                                                  a fragment shading rate attachment
622    MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT        Z+    GetIntegerv  8              maximum supported width of the      13.X.3
623                                                                                                  portion of the framebuffer
624                                                                                                  corresponding to each texel in
625                                                                                                  a fragment shading rate attachment
626    MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT       Z+    GetIntegerv  8              maximum supported height of the     13.X.3
627                                                                                                  portion of the framebuffer
628                                                                                                  corresponding to each texel in
629                                                                                                  a fragment shading rate attachment
630    MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO_EXT Z+    GetIntegerv  1              maximum aspect ratio between the    13.X.3
631                                                                                                  width and height of the portion of
632                                                                                                  the framebuffer corresponding to
633                                                                                                  each texel in a fragment shading
634                                                                                                  rate attachment
635    MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS_EXT             Z+    GetIntegerv  1              maximum number of layers in a
636                                                                                                  fragment shading rate attachment    13.X.3
637    FRAGMENT_SHADING_RATE_WITH_SHADER_DEPTH_STENCIL_WRITES_SUPPORTED_EXT
638                                                                B     GetBooleanv  -              support for writing FragDepth from  13.X.4
639                                                                                                  a fragment shader for multi-pixel
640                                                                                                  fragments
641    FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED_EXT        B     GetBooleanv  -              support for sample masks with       13.X.4
642                                                                                                  multi-pixel fragments
643    FRAGMENT_SHADING_RATE_ATTACHMENT_WITH_-                     B    GetBooleanv  -               support for attachment shading      13.X.3
644    DEFAULT_FRAMEBUFFER_SUPPORTED_EXT                                                             rates on the default framebuffer
645    FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT   B    GetBooleanv  -               support for non-trivial combiners   13.X.4
646
647
648    (**) The value of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT is the maximum allowed, not the minimum
649    (**) The value of MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT is the maximum allowed, not the minimum
650
651
652    Interactions with OVR_Multiview
653
654        If OVR_Multiview is supported, SHADING_RATE_EXT applies to all views.
655
656    Interactions with QCOM_framebuffer_foveated and QCOM_texture_foveated
657
658        QCOM_framebuffer_foveated and QCOM_texture_foveated specify a pixel
659        density which is exposed as a fragment size via the fragment
660        shader built-in gl_FragSizeEXT.  This extension defines an effective
661        shading rate which is exposed to fragment shaders via the shader
662        built-in gl_ShadingRateEXT. If either foveation extension is enabled in
663        conjunction with this extension, then the values of the gl_FragSizeEXT
664        and gl_ShadingRateEXT built-ins will be the component-wise product of
665        both fragment sizes.
666
667    Interactions with GL_EXT_fragment_invocation_density
668
669        If the shader enables the GL_EXT_fragment_invocation_density in combination
670        with this extension, then the gl_FragSizeEXT and gl_FragInvocationCountEXT
671        built-in variables contain the fragment size and the number of invocations,
672        respectively, based on the effective fragment shading rate.
673
674    Interactions with GL_EXT_shader_pixel_local_storage and GL_EXT_shader_pixel_local_storage2
675
676        Pixel local storage is not supported in combination with shading
677        rates other than SHADING_RATE_1X1_PIXELS_EXT.
678
679        Attempting to enable pixel local storage while the currently bound
680        framebuffer object has a non-zero value of SHADING_RATE_ATTACHMENT_EXT
681        will generate an INVALID_OPERATION error.
682        Attempting to enable pixel local storage while the current value
683        of SHADING_RATE_EXT is not SHADING_RATE_1X1_PIXELS_EXT will
684        generate an INVALID_OPERATION error.
685        If pixel local storage is enabled, an INVALID_OPERATION error will
686        be generated by ShadingRateEXT if <rate> is not
687        SHADING_RATE_1X1_PIXELS_EXT.
688
689        [[If GL_EXT_fragment_shading_rate_primitive is supported]]
690        A program will fail to link if a per primitive shading rate
691        is specified in a vertex or geometry shader while the fragment
692        shader statically reads or writes to a pixel local storage
693        variable.
694
695    Interactions with GL_EXT_shader_framebuffer_fetch and GL_EXT_shader_framebuffer_fetch_non_coherent
696
697        When the value of SAMPLE_BUFFERS is 0, gl_LastFragData[] is populated with
698        the value last written to one of the pixels to which the current fragment
699        is destined, chosen in an implementation-dependent manner.
700        When the value of SAMPLE_BUFFERS is 1 and the
701        current framebuffer color is accessed in the fragment shader, the fragment
702        shader will be invoked separately for each covered sample. Since this is
703        equivalent to per-sample shading, the fragment shading rate will be set to
704        {1,1} in this case.
705
706    Interactions with GL_ARM_shader_framebuffer_fetch and GL_ARM_shader_framebuffer_fetch_depth_stencil
707
708        If FETCH_PER_SAMPLE_ARM is enabled, the fragment shading rate is set to {1,1}.
709
710        Otherwise, the values of gl_LastFragColorARM, gl_LastFragDepthARM and
711        gl_LastFragStencilARM, is the color, depth, or stencil value, respectively,
712        is an implementation-dependent combination of the values of the pixels to which
713        the current fragment is destined.
714        If the current render target is multisampled, the values are an
715        implementation-dependent combination of the samples covered by the fragment.
716
717    Issues
718
719        (1) Do we need individual 'feature bits' for the draw call, primitive, and
720            attachment shading rates?
721
722        RESOLVED: Yes.
723
724        This extension exposes different extension strings for these features:
725         * GL_EXT_fragment_shading_rate is the baseline, and requires per draw call shading rates
726         * GL_EXT_fragment_shading_rate_attachment adds support for shading rate attachments
727         * GL_EXT_fragment_shading_rate_primitive adds support for per primitive shading rates
728
729        (2) What optional parameters and options should we expose?
730
731        RESOLVED: For reference, the Vulkan VK_KHR_fragment_shading_rate extension has the
732        following properties:
733
734        typedef struct VkPhysicalDeviceFragmentShadingRatePropertiesKHR {
735            VkStructureType          sType;
736            void*                    pNext;
737            VkExtent2D               minFragmentShadingRateAttachmentTexelSize;
738            VkExtent2D               maxFragmentShadingRateAttachmentTexelSize;
739            uint32_t                 maxFragmentShadingRateAttachmentTexelSizeAspectRatio;
740            VkBool32                 primitiveFragmentShadingRateWithMultipleViewports;
741            VkBool32                 layeredShadingRateAttachments;
742            VkBool32                 fragmentShadingRateNonTrivialCombinerOps;
743            VkExtent2D               maxFragmentSize;
744            uint32_t                 maxFragmentSizeAspectRatio;
745            uint32_t                 maxFragmentShadingRateCoverageSamples;
746            VkSampleCountFlagBits    maxFragmentShadingRateRasterizationSamples;
747            VkBool32                 fragmentShadingRateWithShaderDepthStencilWrites;
748            VkBool32                 fragmentShadingRateWithSampleMask;
749            VkBool32                 fragmentShadingRateWithShaderSampleMask;
750            VkBool32                 fragmentShadingRateWithConservativeRasterization;
751            VkBool32                 fragmentShadingRateWithFragmentShaderInterlock;
752            VkBool32                 fragmentShadingRateWithCustomSampleLocations;
753            VkBool32                 fragmentShadingRateStrictMultiplyCombiner;
754        } VkPhysicalDeviceFragmentShadingRatePropertiesKHR;
755
756       The mapping to this extension is as follows:
757
758            minFragmentShadingRateAttachmentTexelSize              => MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
759                                                                      MIN_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
760            maxFragmentShadingRateAttachmentTexelSize              => MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_WIDTH_EXT
761                                                                      MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_HEIGHT_EXT
762            maxFragmentShadingRateAttachmentTexelSizeAspectRatio   => MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_TEXEL_ASPECT_RATIO_EXT
763            primitiveFragmentShadingRateWithMultipleViewports      => - (not supported; would be an interaction with GL_OES_viewport_array)
764            layeredShadingRateAttachments                          => MAX_FRAGMENT_SHADING_RATE_ATTACHMENT_LAYERS_EXT
765            fragmentShadingRateNonTrivialCombinerOps               => FRAGMENT_SHADING_RATE_NON_TRIVIAL_COMBINERS_SUPPORTED_EXT
766            maxFragmentSize                                        => - (not exposed as a limit; min requirements are stated in description of GetFragmentShadingRatesEXT)
767            maxFragmentSizeAspectRatio                             => - (not exposed as a limit; min requirements are stated in description of GetFragmentShadingRatesEXT)
768            maxFragmentShadingRateCoverageSamples                  => - (not exposed as a limit; min requirements are stated in description of GetFragmentShadingRatesEXT)
769            maxFragmentShadingRateRasterizationSamples             => - (not exposed as a limit; min requirements are stated in description of GetFragmentShadingRatesEXT)
770            fragmentShadingRateWithShaderDepthStencilWrites        => FRAGMENT_SHADING_RATE_WITH_SHADER_DEPTH_STENCIL_WRITES_SUPPORTED_EXT
771            fragmentShadingRateWithSampleMask                      => FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED_EXT
772            fragmentShadingRateWithShaderSampleMask                => FRAGMENT_SHADING_RATE_WITH_SAMPLE_MASK_SUPPORTED_EXT
773            fragmentShadingRateWithConservativeRasterization       => - (not supported; would be an interaction with GL_NV_conservative_raster and GL_INTEL_conservative_rasterization)
774            fragmentShadingRateWithFragmentShaderInterlock         => - (not supported; would be an interaction with GL_NV_fragment_shader_interlock)
775            fragmentShadingRateWithCustomSampleLocations           => - (not supported; would be an interaction with GL_NV_sample_locations)
776            fragmentShadingRateStrictMultiplyCombiner              => - (implicitly required)
777
778      (3) Should we add enumerants for 1x4 and 4x1 shading rates?
779
780        RESOLVED: Yes, they are all included, but support is optional.
781
782      (4) Should we have an equivalent to PRESERVE_SHADING_RATE_ASPECT_RATIO_QCOM
783          from QCOM_shading_rate?
784
785        RESOLVED: No. This extension follows the conventions of the
786        VK_KHR_fragment_shading_rate extension, where the aspect ratios are
787        constrained in a slightly different way than in QCOM_shading_rate.
788
789      (5) Should the GLSL dependency be on GL_EXT_fragment_invocation_density or
790          GLSL_EXT_fragment_shading_rate?
791
792        RESOLVED: Primarily GL_EXT_fragment_shading_rate, but
793        GL_EXT_fragment_invocation_density is also sufficient unless
794        GL_EXT_fragment_shading_rate_primitive is used.
795
796      (6) What is the interaction with QCOM_framebuffer_foveated and QCOM_texture_foveated?
797
798        RESOLVED: See Interactions.
799
800      (7) What fragment shading rates should be required?
801
802        RESOLVED: The current draft matches the minimum requirements in other APIs
803        (assuming 2xMSAA is not supported).
804
805     (8) What are the interactions with GL_EXT_fragment_invocation_density?
806
807        REESOLVED: If a shader declares that extension (and the implementation
808        supports it), then the built-in variables defined by the extension
809        will be filled with values representing the effective fragment shading
810        rate.
811
812     (9) How do we handle gl_FragCoord in the cases where the shader does not
813         enable GL_EXT_fragment_shading_rate?
814
815        RESOLVED: We fall back to 1x1 shading rate.
816
817        The implementation may need to calculate gl_FragCoord differently depending
818        on the shading rate. But the shading rate is not known at shader
819        compile-time. The implementation could add instructions to the shader
820        to handle this, but that could affect performance in the general case
821        - even when no shading rate is specified.
822
823        A potential solution is to fallback to a 1x1 shading rate if the shader
824        accesses gl_FragCoord unless GL_EXT_fragment_shading_rate is enabled.
825        Enabling the extension acts as a hint that the shading rate will be
826        specified at run-time.
827
828    (10) How does this compare to GL_NV_shading_rate_image and
829         GL_NV_primitive_shading_rate?
830
831        RESOLVED: GL_NV_shading_rate_image and GL_NV_primitive_shading_rate
832        offer similar functionality as this extension, but exposes it in a
833        slightly different way.
834
835        Differences include:
836         - This extension does not include the concept of a shader rate image
837           palette. In the case where no shading image is bound,
838           GL_NV_shading_rate_image uses the palette to provide a per draw-call
839           rate. This extension sets the per-draw call rate separately.
840        - GL_NV_shading_rate_image does not include rate combiners.
841        - GL_NV_shading_rate_image does not allow the shading rates to be
842          changed for the default framebuffer.
843        - This extension binds the shading rate as a framebuffer attachment,
844          GL_NV_shading_rate_image binds it directly to the state vector.
845
846    (11) Should we include any functionality or restrictions from
847         GL_NV_shading_rate_image?
848
849       RESOLVED:
850
851       Interactions with ARB_fragment_shader_interlock are not included
852       No equivalent of ShadingRateImageBarrierNV is included
853       No equivalent of ShadingRateSampleOrderNV and ShadingRateSampleOrderCustomNV
854       is included.
855       Restrictions on using fragment shading rate with the default framebuffer
856       are included - by the DEFAULT_FRAMEBUFFER_SUPPORTED_EXT state.
857
858    (12) Can we reuse the shading rate enumeration values from
859         GL_QCOM_shading_rate?
860
861       RESOLVED: Yes, since the semantics are identical.
862
863
864    Revision History
865
866        Rev.    Date     Author    Changes
867        ----  --------   --------  ----------------------------------------------
868         1    2022-05-30 jhf       Initial EXT draft
869         2    2022-07-07 jhf       Fixed typos in the spec text
870