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 all 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
78 changes: 70 additions & 8 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,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 @@ -114,6 +115,7 @@ spec: WGSL; urlPrefix: https://gpuweb.github.io/gpuweb/wgsl/#
for: extension
text: f16; url: extension-f16
text: clip_distances; url: extension-clip_distances
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 @@ -8239,20 +8241,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 @@ -8271,12 +8283,20 @@ dictionary GPUFragmentState
|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:
{{GPUBlendFactor/"src-alpha-saturated"}}, {{GPUBlendFactor/"src1-alpha"}} or
{{GPUBlendFactor/"one-minus-src1-alpha"}}), then:
- |output| must have an alpha channel (that is, it must be a vec4).

Otherwise, since there is no shader output for the attachment:

- |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 @@ -8407,6 +8427,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 @@ -8438,6 +8464,10 @@ enum GPUBlendFactor {
"src-alpha-saturated",
"constant",
"one-minus-constant",
"src1",
"one-minus-src1",
"src1-alpha",
"one-minus-src1-alpha",
};
</script>

Expand All @@ -8448,12 +8478,14 @@ enum GPUBlendFactor {
<tr>
<th>GPUBlendFactor
<th>Blend factor RGBA components
<th>[=Feature=]
</tr>
</thead>
<tbody dfn-type=enum-value dfn-for=GPUBlendFactor>
<tr>
<td><dfn>"zero"</dfn>
<td><code>(0, 0, 0, 0)</code>
<td rowspan=13>
<tr>
<td><dfn>"one"</dfn>
<td><code>(1, 1, 1, 1)</code>
Expand Down Expand Up @@ -8490,6 +8522,19 @@ 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>
<td rowspan=4>{{GPUFeatureName/dual-source-blending}}
<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 @@ -15484,6 +15529,23 @@ This feature adds the following [=optional API surfaces=]:
- New WGSL extensions:
- [=extension/clip_distances=]

<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
59 changes: 52 additions & 7 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 @@ -1758,6 +1759,10 @@ The valid [=enable-extensions=] are listed in the following table.
<td>The built-in variable [=built-in values/clip_distances=] is valid to use in the WGSL
module. Otherwise, using [=built-in values/clip_distances=] 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 @@ -3106,12 +3111,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 @@ -8020,6 +8026,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 @@ -8411,6 +8418,33 @@ path: syntax/binding_attr.syntax.bs.include

</table>

## `blend_src` ## {#blend-src-attr}

<pre class=include>
path: syntax/blend_src_attr.syntax.bs.include
</pre>

<table class='data builtin'>
<caption><dfn noexport dfn-for="attribute">`blend_src`</dfn> Attribute</caption>
<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 with a
[=attribute/location=] attribute.
[=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>

## `builtin` ## {#builtin-attr}

<pre class=include>
Expand Down Expand Up @@ -8922,6 +8956,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 @@ -9429,11 +9464,21 @@ Each user-defined [=user-defined input datum|input=] and [=user-defined output d
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.

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.

<div algorithm="locations in entry point inputs">
For each entry point defined in a WGSL module, let |inputs| be its set of shader stage inputs
(i.e. locations for its formal parameters, or for the members of its formal parameters of structure type).
- |inputs| [=shader-creation error|must not=] contain two entries with the same [=attribute/location=] value.
</div>
<div algorithm="locations in structs">
For each structure type |S| defined in a WGSL module (not just those used in shader stage inputs or outputs),
let |members| be the set of members of |S| that have [=attribute/location=] attributes.
- If any entry in |members| specifies a [=attribute/blend_src=] attribute:
- |members| [=shader-creation error|must=] contain exactly `2` entries,
one with `@location(0) @blend_src(0)` and one with `@location(0) @blend_src(1)`.
- All the |members| [=shader-creation error|must=] have same data type.
- Otherwise, |members| [=shader-creation error|must not=] contain two entries with the same [=attribute/location=] value.
</div>

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