Skip to content

Commit b3acacb

Browse files
Add "texture-component-swizzle" feature (#193)
This PR adds the "texture-component-swizzle" feature added to the spec in gpuweb/gpuweb#5361
1 parent eb1d104 commit b3acacb

4 files changed

Lines changed: 59 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ Please contribute a PR to add instructions for other setups or improve existing
8383
- Make sure the submodule is checked out: `git submodule update --init`
8484
- Pull `gpuweb` changes: `pushd gpuweb && git checkout main && git pull && popd`
8585
- Install dependencies: `npm ci`
86-
- Generate `generated/index-fixed.d.ts`: `npm run generate`
87-
- Open a diff between `generated/index-fixed.d.ts` and `dist/index.d.ts`.
86+
- Generate `generated/index.d.ts`: `npm run generate`
87+
- Open a diff between `generated/index.d.ts` and `dist/index.d.ts`.
8888
The generated file is tracked by Git so you can see what has changed.
8989
Update the latter according to changes from the former.
9090
Note the `generated/` and `dist/` files are not the same.

dist/index.d.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ type GPUFeatureName =
318318
| "subgroups"
319319
| "texture-formats-tier1"
320320
| "texture-formats-tier2"
321-
| "primitive-index";
321+
| "primitive-index"
322+
| "texture-component-swizzle";
322323
type GPUFilterMode =
323324

324325
| "nearest"
@@ -1808,6 +1809,21 @@ interface GPUTextureViewDescriptor
18081809
* to the texture view.
18091810
*/
18101811
arrayLayerCount?: GPUIntegerCoordinate;
1812+
/**
1813+
* A string of length four, with each character mapping to the texture view's red/green/blue/alpha
1814+
* channels, respectively.
1815+
* When accessed by a shader, the red/green/blue/alpha channels are replaced by the value
1816+
* corresponding to the component specified in `swizzle[0]`, `swizzle[1]`, `swizzle[2]`, and
1817+
* `swizzle[3]`, respectively:
1818+
* - `"r"`: Take its value from the red channel of the texture.
1819+
* - `"g"`: Take its value from the green channel of the texture.
1820+
* - `"b"`: Take its value from the blue channel of the texture.
1821+
* - `"a"`: Take its value from the alpha channel of the texture.
1822+
* - `"0"`: Force its value to 0.
1823+
* - `"1"`: Force its value to 1.
1824+
* Requires the {@link GPUFeatureName} `"texture-component-swizzle"` feature to be enabled.
1825+
*/
1826+
swizzle?: string;
18111827
}
18121828

18131829
interface GPUUncapturedErrorEventInit

generated/index.d.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ type GPUFeatureName =
318318
| "subgroups"
319319
| "texture-formats-tier1"
320320
| "texture-formats-tier2"
321-
| "primitive-index";
321+
| "primitive-index"
322+
| "texture-component-swizzle";
322323
type GPUFilterMode =
323324

324325
| "nearest"
@@ -755,7 +756,18 @@ interface GPUCanvasConfiguration {
755756
/**
756757
* The tone mapping determines how the content of textures returned by
757758
* {@link GPUCanvasContext#getCurrentTexture} are to be displayed.
758-
* Note: If an implementation doesn't support HDR WebGPU canvases, it should also not expose this member, to allow for feature detection. See {@link GPUCanvasContext#getConfiguration}.
759+
* <div class=note heading>
760+
* This is a required feature, but user agents might not yet implement it,
761+
* effectively supporting only the default {@link GPUCanvasToneMapping}.
762+
* In such implementations, this member **should not** exist in its implementation of
763+
* {@link GPUCanvasConfiguration}, to make feature detection possible using
764+
* {@link GPUCanvasContext#getConfiguration}.
765+
* This is especially important in implementations which otherwise have HDR capabilities
766+
* (where a <l>'@media/dynamic-range'</l> of <l>''@media/dynamic-range/high''</l> would be
767+
* exposed).
768+
* If an implementation exposes this member and a `high` dynamic range, it **should** render the
769+
* canvas as an HDR element, not clamp values to the SDR range of the HDR display.
770+
* </div>
759771
*/
760772
toneMapping?: GPUCanvasToneMapping;
761773
/**
@@ -854,7 +866,7 @@ interface GPUCopyExternalImageDestInfo
854866
* Otherwise, the results are clamped to the target texture format's range.
855867
* Note:
856868
* If {@link GPUCopyExternalImageDestInfo#colorSpace} matches the source image,
857-
* conversion may not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}.
869+
* conversion might not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}.
858870
*/
859871
colorSpace?: PredefinedColorSpace;
860872
/**
@@ -865,7 +877,7 @@ interface GPUCopyExternalImageDestInfo
865877
* corresponding alpha values.
866878
* Note:
867879
* If {@link GPUCopyExternalImageDestInfo#premultipliedAlpha} matches the source image,
868-
* conversion may not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}.
880+
* conversion might not be necessary. See {@link https://www.w3.org/TR/webgpu/#color-space-conversion-elision}.
869881
*/
870882
premultipliedAlpha?: boolean;
871883
}
@@ -1769,6 +1781,21 @@ interface GPUTextureViewDescriptor
17691781
* to the texture view.
17701782
*/
17711783
arrayLayerCount?: GPUIntegerCoordinate;
1784+
/**
1785+
* A string of length four, with each character mapping to the texture view's red/green/blue/alpha
1786+
* channels, respectively.
1787+
* When accessed by a shader, the red/green/blue/alpha channels are replaced by the value
1788+
* corresponding to the component specified in `swizzle[0]`, `swizzle[1]`, `swizzle[2]`, and
1789+
* `swizzle[3]`, respectively:
1790+
* - `"r"`: Take its value from the red channel of the texture.
1791+
* - `"g"`: Take its value from the green channel of the texture.
1792+
* - `"b"`: Take its value from the blue channel of the texture.
1793+
* - `"a"`: Take its value from the alpha channel of the texture.
1794+
* - `"0"`: Force its value to 0.
1795+
* - `"1"`: Force its value to 1.
1796+
* Requires the {@link GPUFeatureName} `"texture-component-swizzle"` feature to be enabled.
1797+
*/
1798+
swizzle?: string;
17721799
}
17731800

17741801
interface GPUUncapturedErrorEventInit
@@ -2115,6 +2142,7 @@ interface GPUCanvasContext {
21152142
/**
21162143
* Configures the context for this canvas.
21172144
* This clears the drawing buffer to transparent black (in [$Replace the drawing buffer$]).
2145+
* See {@link GPUCanvasContext#getConfiguration} for information on feature detection.
21182146
* @param configuration - Desired configuration for the context.
21192147
*/
21202148
configure(
@@ -2125,7 +2153,11 @@ interface GPUCanvasContext {
21252153
*/
21262154
unconfigure(): undefined;
21272155
/**
2128-
* Returns the context configuration.
2156+
* Returns the context configuration, or `null` if the context is not configured.
2157+
* Note:
2158+
* This method exists primarily for feature detection of members (and sub-members) of
2159+
* {@link GPUCanvasConfiguration}; see those members for details.
2160+
* For supported members, it returns the originally-supplied values.
21292161
*/
21302162
getConfiguration(): GPUCanvasConfiguration | null;
21312163
/**
@@ -2849,8 +2881,8 @@ interface GPUShaderModule
28492881
readonly __brand: "GPUShaderModule";
28502882
/**
28512883
* Returns any messages generated during the {@link GPUShaderModule}'s compilation.
2852-
* The locations, order, and contents of messages are implementation-defined
2853-
* In particular, messages may not be ordered by {@link GPUCompilationMessage#lineNum}.
2884+
* The locations, order, and contents of messages are implementation-defined.
2885+
* In particular, messages aren't necessarily ordered by {@link GPUCompilationMessage#lineNum}.
28542886
*/
28552887
getCompilationInfo(): Promise<GPUCompilationInfo>;
28562888
}

0 commit comments

Comments
 (0)