Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional feature dual_source_blending #4621

Merged
merged 43 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7ee65b1
Add optional feature dual_source_blending
Jiawei-Shao May 6, 2024
ba12281
Fix
Jiawei-Shao May 6, 2024
5583b86
Add blend_src_attr.syntax.bs.include
Jiawei-Shao May 7, 2024
2d1ef2d
Update wgsl/syntax.bnf
Jiawei-Shao May 7, 2024
8619b93
dos2unix
Jiawei-Shao May 7, 2024
ba36153
Fix more wgsl include files
Jiawei-Shao May 7, 2024
e41e5f0
Improve the statements
Jiawei-Shao May 7, 2024
9c596ab
Fix
Jiawei-Shao May 7, 2024
cd5aaf6
Improve the statements
Jiawei-Shao May 7, 2024
1e5c07c
Further refactoring of the api validation
kainino0x May 8, 2024
c2c5eb4
fix typos
kainino0x May 8, 2024
43e53f1
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 8, 2024
4ca6452
Address reviewers' comments
Jiawei-Shao May 8, 2024
0b8efef
Small fix
Jiawei-Shao May 8, 2024
add28f1
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 9, 2024
94a1689
Add `Feature` column in the `GPUBlendFactor` table
Jiawei-Shao May 9, 2024
bafaa41
Address Alan's comments
Jiawei-Shao May 11, 2024
7718b21
Fix typo
Jiawei-Shao May 11, 2024
8aec9dc
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 14, 2024
7c8d300
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 16, 2024
cb35343
Sort builtins alphabetically.
Jiawei-Shao May 16, 2024
c084773
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 20, 2024
45b5c0e
Don't apply `location overlapping` rules on `blend_src` members
Jiawei-Shao May 20, 2024
fa9f445
`blend_src` can only be specified on fragment outputs
Jiawei-Shao May 20, 2024
b914f26
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 21, 2024
097aaf1
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 23, 2024
34a2eb7
Address Kai's comments
Jiawei-Shao May 23, 2024
9f4e8d7
Small fix
Jiawei-Shao May 23, 2024
939387a
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 29, 2024
df42b25
Require all the @location(0) @blend_src(N) outputs have same type
Jiawei-Shao May 29, 2024
0e2b419
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 30, 2024
c04f859
Address reviewers' comments
Jiawei-Shao May 30, 2024
0f7d944
Small fix
Jiawei-Shao May 30, 2024
3b66fbd
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao May 31, 2024
1b00d2a
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao Jun 5, 2024
775c2d4
Require `@blend_src` must be used together with `@location`
Jiawei-Shao Jun 5, 2024
66f5a8a
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao Jun 7, 2024
e3fad84
Require all the outputs with `@blend_src` have same type
Jiawei-Shao Jun 7, 2024
d5ffbb7
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao Jun 11, 2024
07cc9d7
Address reviewer's comment
Jiawei-Shao Jun 11, 2024
d0f5259
Remove tabs
Jiawei-Shao Jun 11, 2024
4bbb2fe
Merge branch 'main' into add-dual-source-blending
Jiawei-Shao Jun 12, 2024
b98a4b0
Small fixes
Jiawei-Shao Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 80 additions & 12 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ spec: WGSL; urlPrefix: https://gpuweb.github.io/gpuweb/wgsl/#
type: dfn
text: f16; url: f16
text: location; url: input-output-locations
text: blend_src; url: input-output-locations
text: interpolation; url: interpolation
text: pipeline-overridable; url: pipeline-overridable
text: pipeline constant ID; url: pipeline-constant-id
Expand Down Expand Up @@ -124,6 +125,7 @@ spec: WGSL; urlPrefix: https://gpuweb.github.io/gpuweb/wgsl/#
text: frag_depth; url: built-in-values-frag_depth
for: extension
text: f16; url: extension-f16
text: dual_source_blending; url: extension-dual_source_blending
type: abstract-op
text: SizeOf; url: sizeof
spec: Internationalization Glossary; urlPrefix: https://www.w3.org/TR/i18n-glossary/#
Expand Down Expand Up @@ -8101,20 +8103,30 @@ dictionary GPUFragmentState
- [$validating GPUProgrammableStage$]({{GPUShaderStage/FRAGMENT}}, |descriptor|, |layout|) succeeds.
- |descriptor|.{{GPUFragmentState/targets}}.length must be ≤
|device|.{{device/[[limits]]}}.{{supported limits/maxColorAttachments}}.
- Let |entryPoint| be [$get the entry point$]({{GPUShaderStage/FRAGMENT}}, |descriptor|).
- Let |usesDualSourceBlending| be `false`.
teoxoy marked this conversation as resolved.
Show resolved Hide resolved
- [=list/For each=] |index| of the [=list/indices=] of |descriptor|.{{GPUFragmentState/targets}}
containing a non-`null` value |colorState|:
- |colorState|.{{GPUColorTargetState/format}} must be listed in [[#plain-color-formats]]
with {{GPUTextureUsage/RENDER_ATTACHMENT}} capability.
- |colorState|.{{GPUColorTargetState/writeMask}} must be < 16.
- If |colorState|.{{GPUColorTargetState/blend}} is [=map/exist|provided=]:
- The |colorState|.{{GPUColorTargetState/format}} must be [=blendable=].
- |colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}
must be a [=valid GPUBlendComponent=].
- |colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/alpha}}
must be a [=valid GPUBlendComponent=].
- |colorState|.{{GPUColorTargetState/writeMask}} must be < 16.
- If [$get the entry point$]({{GPUShaderStage/FRAGMENT}}, |descriptor|) has a
[=shader stage output=] value |output| with [=location=] attribute equal to |index|:

- If |colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/srcFactor}} or
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/dstFactor}} or
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/alpha}}.{{GPUBlendComponent/srcFactor}} or
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/alpha}}.{{GPUBlendComponent/dstFactor}}
uses the second input of the corresponding blending unit (is any of
{{GPUBlendFactor/"src1"}}, {{GPUBlendFactor/"one-minus-src1"}},
{{GPUBlendFactor/"src1-alpha"}}, {{GPUBlendFactor/"one-minus-src1-alpha"}}), then:

- Set |usesDualSourceBlending| to `true`.
- For each [=shader stage output=] value |output| with [=location=] attribute equal to |index|
in |entryPoint|:
- For each component in |colorState|.{{GPUColorTargetState/format}}, there must be a
corresponding component in |output|.
(That is, RGBA requires vec4, RGB requires vec3 or vec4, RG requires vec2 or vec3 or vec4.)
Expand All @@ -8129,16 +8141,33 @@ dictionary GPUFragmentState
: {{GPUTextureSampleType/"uint"}}
:: |output| must have an unsigned integer scalar type.
</dl>
- If |colorState|.{{GPUColorTargetState/blend}} is [=map/exist|provided=] and
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/srcFactor}}
or .{{GPUBlendComponent/dstFactor}} uses the source alpha
(is any of {{GPUBlendFactor/"src-alpha"}}, {{GPUBlendFactor/"one-minus-src-alpha"}},
or {{GPUBlendFactor/"src-alpha-saturated"}}), then:
- |output| must have an alpha channel (that is, it must be a vec4).
- If |colorState|.{{GPUColorTargetState/blend}} is [=map/exist|provided=] and **either**:
- The [=blend_src=] attribute of |output| is omitted or 0 and
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/srcFactor}} or
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/dstFactor}}
uses the alpha channel of the first input of the corresponding blend unit (is any of
{{GPUBlendFactor/"src-alpha"}}, {{GPUBlendFactor/"one-minus-src-alpha"}} or
{{GPUBlendFactor/"src-alpha-saturated"}})
- The [=blend_src=] attribute of |output| is 1 and
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/srcFactor}} or
|colorState|.{{GPUColorTargetState/blend}}.{{GPUBlendState/color}}.{{GPUBlendComponent/dstFactor}}
uses the alpha channel of the second input of the corresponding blending unit (is any of
{{GPUBlendFactor/"src1-alpha"}} or {{GPUBlendFactor/"one-minus-src1-alpha"}})

Then:

Otherwise, since there is no shader output for the attachment:
- |output| must have an alpha channel (that is, it must be a vec4).

- |colorState|.{{GPUColorTargetState/writeMask}} must be 0.
- If |colorState|.{{GPUColorTargetState/writeMask}} is not 0:
- |entryPoint| must have a [=shader stage output=] with [=location=] equal to |index|
and [=blend_src=] omitted or equal to 0.
- If |usesDualSourceBlending| is `true`:
- All the [=shader stage output=] values of |entryPoint| must have a [=blend_src=] attribute.
- |descriptor|.{{GPUFragmentState/targets}}.length must be `1`.
- Let |colorState| be |descriptor|.{{GPUFragmentState/targets}}[0].
- If |colorState|.{{GPUColorTargetState/writeMask}} is not 0:
- |entryPoint| must have a [=shader stage output=] with [=location=] equal to 0
and [=blend_src=] equal to 1.
- [$Validating GPUFragmentState's color attachment bytes per sample$](|device|, |descriptor|.{{GPUFragmentState/targets}}) succeeds.
</div>
</div>
Expand Down Expand Up @@ -8269,6 +8298,12 @@ location:
<td><b><code>RGBA<sub>src</src></code></b>
<td>Color output by the fragment shader for the color attachment.
If the shader doesn't return an alpha channel, src-alpha blend factors cannot be used.
<tr>
<td><b><code>RGBA<sub>src1</src></code></b>
<td>Color output by the fragment shader for the color attachment with
<a href="https://gpuweb.github.io/gpuweb/wgsl/#input-output-locations">"@blend_src" attribute</a>
equal to `1`.
If the shader doesn't return an alpha channel, src1-alpha blend factors cannot be used.
<tr>
<td><b><code>RGBA<sub>dst</src></code></b>
<td>Color currently in the color attachment.
Expand Down Expand Up @@ -8300,6 +8335,10 @@ enum GPUBlendFactor {
"src-alpha-saturated",
"constant",
"one-minus-constant",
"src1",
"one-minus-src1",
"src1-alpha",
"one-minus-src1-alpha",
};
</script>

Expand Down Expand Up @@ -8352,6 +8391,18 @@ enum GPUBlendFactor {
<tr>
<td><dfn>"one-minus-constant"</dfn>
<td><code>(1 - R<sub>const</sub>, 1 - G<sub>const</sub>, 1 - B<sub>const</sub>, 1 - A<sub>const</sub>)</code>
<tr>
<td><dfn>"src1"</dfn>
<td><code>(R<sub>src1</sub>, G<sub>src1</sub>, B<sub>src1</sub>, A<sub>src1</sub>)</code>
<tr>
<td><dfn>"one-minus-src1"</dfn>
<td><code>(1 - R<sub>src1</sub>, 1 - G<sub>src1</sub>, 1 - B<sub>src1</sub>, 1 - A<sub>src1</sub>)</code>
<tr>
<td><dfn>"src1-alpha"</dfn>
<td><code>(A<sub>src1</sub>, A<sub>src1</sub>, A<sub>src1</sub>, A<sub>src1</sub>)</code>
<tr>
<td><dfn>"one-minus-src1-alpha"</dfn>
<td><code>(1 - A<sub>src1</sub>, 1 - A<sub>src1</sub>, 1 - A<sub>src1</sub>, 1 - A<sub>src1</sub>)</code>
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved
</tbody>
</table>

Expand Down Expand Up @@ -15257,6 +15308,23 @@ This feature adds no [=optional API surfaces=].
Makes textures with formats {{GPUTextureFormat/"r32float"}}, {{GPUTextureFormat/"rg32float"}}, and
{{GPUTextureFormat/"rgba32float"}} [=filterable=].

<h3 id=dom-gpufeaturename-dual-source-blending data-dfn-type=enum-value data-dfn-for=GPUFeatureName>`"dual-source-blending"`
</h3>

Allows the use of [=blend_src=] in WGSL and simultaneously using both pixel shader outputs
(`@blend_src(0)` and `@blend_src(1)`) as inputs to a blending operation with the single color
attachment at [=location=] `0`.

This feature adds the following [=optional API surfaces=]:
- Allows the use of the below {{GPUBlendFactor}}s:
- {{GPUBlendFactor/"src1"}}
- {{GPUBlendFactor/"one-minus-src1"}}
- {{GPUBlendFactor/"src1-alpha"}}
- {{GPUBlendFactor/"one-minus-src1-alpha"}}

- New WGSL extensions:
- [=extension/dual_source_blending=]

# Appendices # {#appendices}

## Texture Format Capabilities ## {#texture-format-caps}
Expand Down
54 changes: 50 additions & 4 deletions wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ The [=syntax/attribute=] names are:
* <a for=attribute lt=interpolate>`'interpolate'`</a>
* <a for=attribute lt=invariant>`'invariant'`</a>
* <a for=attribute lt=location>`'location'`</a>
* <a for=attribute lt=blend_src>`'blend_src'`</a>
* <a for=attribute lt=must_use>`'must_use'`</a>
* <a for=attribute lt=size>`'size'`</a>
* <a for=attribute lt=vertex>`'vertex'`</a>
Expand Down Expand Up @@ -1751,6 +1752,10 @@ The valid [=enable-extensions=] are listed in the following table.
<tr><td><dfn noexport dfn-for="extension">`f16`</dfn>
<td>`"shader-f16"`
<td>The [=f16=] type is valid to use in the WGSL module. Otherwise, using [=f16=] (directly or indirectly) will result in a [=shader-creation error=].
<tr><td><dfn noexport dfn-for="extension">`dual_source_blending`</dfn>
<td>`"dual_source_blending"`
<td>The attribute [=attribute/blend_src=] is valid to use in the WGSL module. Otherwise, using
[=attribute/blend_src=] will result in a [=shader-creation error=].
</table>

<div class='example wgsl using extensions expect-error' heading="Using hypothetical enable-extensions">
Expand Down Expand Up @@ -3099,12 +3104,13 @@ The following attributes can be applied to structure members:
* [=attribute/align=]
* [=attribute/builtin=]
* [=attribute/location=]
* [=attribute/blend_src=]
* [=attribute/interpolate=]
* [=attribute/invariant=]
* [=attribute/size=]

Attributes [=attribute/builtin=], [=attribute/location=], [=attribute/interpolate=], and [=attribute/invariant=]
are [=IO attributes=].
Attributes [=attribute/builtin=], [=attribute/location=], [=attribute/blend_src=],
[=attribute/interpolate=], and [=attribute/invariant=] are [=IO attributes=].
An [=IO attribute=] on a member of a structure *S* has effect only when
*S* is used as the type of a [=formal parameter=] or [=return type=] of an [=entry point=].
See [[#stage-inputs-outputs]].
Expand Down Expand Up @@ -8013,6 +8019,7 @@ WGSL defines the following attributes that can be applied to function
parameters and return types:
* [=attribute/builtin=]
* [=attribute/location=]
* [=attribute/blend_src=]
* [=attribute/interpolate=]
* [=attribute/invariant=]

Expand Down Expand Up @@ -8608,6 +8615,30 @@ path: syntax/location_attr.syntax.bs.include

</table>

<pre class=include>
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved
path: syntax/blend_src_attr.syntax.bs.include
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved
</pre>

<table class='data builtin'>
<caption><dfn noexport dfn-for="attribute">`blend_src`</dfn> Attribute</caption>
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved
<tr>
<td style="width:10%">Description
<td>
Specifies a part of the [=fragment=] output when the feature [=extension/dual_source_blending=]
is enabled.
See [[#input-output-locations]].

[=shader-creation error|Must=] only be applied to a member of a [=structure=] type.
[=shader-creation error|Must=] only be applied to declarations of objects with [=numeric scalar=]
or [=numeric vector=] type.
[=shader-creation error|Must=] only be used as an output of the [=fragment=] shader stage.

<tr>
<td>Parameters
<td>[=shader-creation error|Must=] be a [=const-expression=] that [=resolves=] to an i32 or u32 with value of `0` or `1`.

</table>

## `must_use` ## {#must-use-attr}

<pre class=include>
Expand Down Expand Up @@ -8915,6 +8946,7 @@ or to further describe the properties of an input or output.
The <dfn noexport>IO attributes</dfn> are:
* [=attribute/builtin=]
* [=attribute/location=]
* [=attribute/blend_src=]
* [=attribute/interpolate=]
* [=attribute/invariant=]

Expand Down Expand Up @@ -9390,18 +9422,32 @@ Each input-output location can store a value up to 16 bytes in size.
The byte size of a type is defined using the *SizeOf* column in [[#alignment-and-size]].
For example, a four-component vector of floating-point values occupies a single location.

IO locations are specified via the [=attribute/location=] attribute.

Each user-defined [=user-defined input datum|input=] and [=user-defined output datum|output=] [=shader-creation error|must=] have an explicitly specified IO location.
Each structure member in the entry point IO [=shader-creation error|must=] be one of either a built-in value
(see [[#builtin-inputs-outputs]]), or assigned a location.

A location can be specified via either the [=attribute/location=] attribute only or both the
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved
[=attribute/location=] attribute and the [=attribute/blend_src=] attribute. The optional
[=attribute/blend_src=] attribute can only be specified on a [=fragment=] shader
[=user-defined output datum|output=] and used to specify up to two [=fragment=] shader
[=user-defined output datum|outputs=] for the only color attachment as the inputs to the blend
equation.

Locations [=shader-creation error|must not=] overlap within each of the following sets:
* Members within a structure type.
This applies to any structure, not just those used in shader stage inputs or outputs.
* An entry point's shader stage inputs,
i.e. locations for its formal parameters, or for the members of its formal parameters of structure type.
Jiawei-Shao marked this conversation as resolved.
Show resolved Hide resolved

When the [=attribute/blend_src=] attribute is specified:
kainino0x marked this conversation as resolved.
Show resolved Hide resolved
* There [=shader-creation error|must=] be exactly `2` [=fragment=] shader
[=user-defined output datum|user-defined outputs=].
* The [=attribute/location=] attribute of all [=fragment=] shader
[=user-defined output datum|outputs=] [=shader-creation error|must=] be `0`.
* The value of [=attribute/blend_src=] attribute [=shader-creation error|must=] be `0` for one
[=fragment=] shader [=user-defined output datum|output=], and `1` for the other [=fragment=]
shader [=user-defined output datum|output=].

Note: Location numbering is distinct between inputs and outputs:
Location numbers for an entry point's shader stage inputs do not conflict with location numbers for the entry point's shader stage outputs.

Expand Down
5 changes: 5 additions & 0 deletions wgsl/syntax.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ binding_attr :
'@' 'binding' '(' expression ',' ? ')'
;

blend_src_attr :
'@' 'blend_src' '(' expression ',' ? ')'
;

builtin_attr :
'@' 'builtin' '(' builtin_value_name ',' ? ')'
;
Expand Down Expand Up @@ -184,6 +188,7 @@ attribute :
'@' ident_pattern_token argument_expression_list ?
| align_attr
| binding_attr
| blend_src_attr
| builtin_attr
| const_attr
| diagnostic_attr
Expand Down
2 changes: 2 additions & 0 deletions wgsl/syntax/attribute.syntax.bs.include
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<span class="choice">|</span> [=syntax/binding_attr=]

<span class="choice">|</span> [=syntax/blend_src_attr=]

<span class="choice">|</span> [=syntax/builtin_attr=]

<span class="choice">|</span> [=syntax/const_attr=]
Expand Down
5 changes: 5 additions & 0 deletions wgsl/syntax/blend_src_attr.syntax.bs.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class='syntax' noexport='true'>
<dfn for=syntax>blend_src_attr</dfn> :

<span class="choice"></span> <a for=syntax_sym lt=attr>`'@'`</a> `'blend_src'` <a for=syntax_sym lt=paren_left>`'('`</a> [=syntax/expression=] <a for=syntax_sym lt=comma>`','`</a> ? <a for=syntax_sym lt=paren_right>`')'`</a>
</div>
2 changes: 2 additions & 0 deletions wgsl/wgsl.recursive.bs.include
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

| `'@'` `'binding'` `'('` [=recursive descent syntax/expression=] `','` ? `')'`

| `'@'` `'blend_src'` `'('` [=recursive descent syntax/expression=] `','` ? `')'`

| `'@'` `'builtin'` `'('` [=syntax/ident_pattern_token=] `','` ? `')'`

| `'@'` `'diagnostic'` [=recursive descent syntax/diagnostic_control=]
Expand Down
Loading