Skip to content

Commit 6f7c215

Browse files
committed
Move preferred format queries to the adapter
Fixes #2747 Removes the need to have a canvas context in order to query a preffered format. This should help put developers at ease that they don't need to rebuild all their pipelines when rendering to multiple canvases.
1 parent cbfa42b commit 6f7c215

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

spec/index.bs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ interface GPUAdapter {
17911791
readonly attribute boolean isFallbackAdapter;
17921792

17931793
Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
1794+
GPUTextureFormat getPreferredContextFormat();
17941795
};
17951796
</script>
17961797

@@ -1895,6 +1896,23 @@ interface GPUAdapter {
18951896
1. Return |promise|.
18961897

18971898
</div>
1899+
1900+
: <dfn>getPreferredContextFormat()</dfn>
1901+
::
1902+
Returns an optimal {{GPUTextureFormat}} to use for {{GPUCanvasContext}}s with devices
1903+
created from this adapter.
1904+
1905+
<div algorithm="GPUCanvasContext.getPreferredContextFormat">
1906+
**Called on:** {{GPUAdapter}} |this|.
1907+
1908+
**Returns:** {{GPUTextureFormat}}
1909+
1910+
<div class=content-timeline>
1911+
1. Return an optimal {{GPUTextureFormat}} to use when calling
1912+
{{GPUCanvasContext/configure()}} on a {{GPUCanvasContext}} with a {{GPUDevice}}
1913+
created by |this|. Must be one of the [=supported context formats=].
1914+
</div>
1915+
</div>
18981916
</dl>
18991917

19001918
<div class="example">
@@ -9482,7 +9500,6 @@ interface GPUCanvasContext {
94829500
undefined configure(GPUCanvasConfiguration configuration);
94839501
undefined unconfigure();
94849502

9485-
GPUTextureFormat getPreferredFormat(GPUAdapter adapter);
94869503
GPUTexture getCurrentTexture();
94879504
};
94889505
</script>
@@ -9590,27 +9607,6 @@ interface GPUCanvasContext {
95909607
1. Set |this|.{{GPUCanvasContext/[[currentTexture]]}} to `null`.
95919608
</div>
95929609

9593-
: <dfn>getPreferredFormat(adapter)</dfn>
9594-
::
9595-
Returns an optimal {{GPUTextureFormat}} to use with this context and devices created from
9596-
the given adapter.
9597-
9598-
<div algorithm="GPUCanvasContext.getPreferredFormat">
9599-
**Called on:** {{GPUCanvasContext}} this.
9600-
9601-
**Arguments:**
9602-
<pre class=argumentdef for="GPUCanvasContext/getPreferredFormat(adapter)">
9603-
|adapter|: Adapter the format should be queried for.
9604-
</pre>
9605-
9606-
**Returns:** {{GPUTextureFormat}}
9607-
9608-
<div class=content-timeline>
9609-
1. Return an optimal {{GPUTextureFormat}} to use when calling {{GPUCanvasContext/configure()}}
9610-
with the given |adapter|. Must be one of the [=supported context formats=].
9611-
</div>
9612-
</div>
9613-
96149610
: <dfn>getCurrentTexture()</dfn>
96159611
::
96169612
Get the {{GPUTexture}} that will be composited to the document by the {{GPUCanvasContext}}
@@ -9755,7 +9751,7 @@ dictionary GPUCanvasConfiguration {
97559751

97569752
context.configure({
97579753
device: gpuDevice,
9758-
format: context.getPreferredFormat(gpuAdapter),
9754+
format: gpuAdapter.getPreferredContextFormat(),
97599755
});
97609756
</pre>
97619757
</div>
@@ -9808,7 +9804,7 @@ must be reconfigured by calling {{GPUCanvasContext/configure()}} again with the
98089804
if (entry.target != canvas) { continue; }
98099805
context.configure({
98109806
device: gpuDevice,
9811-
format: context.getPreferredFormat(gpuAdapter),
9807+
format: gpuAdapter.getPreferredContextFormat(),
98129808
size: {
98139809
// This reports the size of the canvas element in pixels
98149810
width: entry.devicePixelContentBoxSize[0].inlineSize,

0 commit comments

Comments
 (0)