summaryrefslogtreecommitdiff
path: root/ext/webgpu
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-09-22 09:10:54 +0530
committerGitHub <noreply@github.com>2024-09-22 09:10:54 +0530
commit0cb00a6e89d83d4e16e6616f7af8819bd894b0da (patch)
treeceb2411d41cd36fd9c13488b7bbfc31ecef0e0a8 /ext/webgpu
parent9be8dce0c7f8deaeff5523735e0867194ec04c59 (diff)
BREAKING(webgpu/unstable): move `width` and `height` options to `UnsafeWindowSurface` constructor (#24200)
Fixes https://github.com/denoland/deno/issues/23508 `width` and `height` are required to configure the wgpu surface because Deno is headless and depends on user to create a window. The options were non-standard extension of `GPUCanvasConfiguration#configure`. This PR adds a required options parameter with the `width` and `height` options to `Deno.UnsafeWindowSurface` constructor. ```typescript // Old, non-standard extension of GPUCanvasConfiguration const surface = new Deno.UnsafeWindowSurface("x11", displayHandle, windowHandle); const context = surface.getContext(); context.configure({ width: 600, height: 800, /* ... */ }); ``` ```typescript // New const surface = new Deno.UnsafeWindowSurface({ system: "x11", windowHandle, displayHandle, width: 600, height: 800, }); const context = surface.getContext(); context.configure({ /* ... */ }); ```
Diffstat (limited to 'ext/webgpu')
-rw-r--r--ext/webgpu/01_webgpu.js10
-rw-r--r--ext/webgpu/02_surface.js37
2 files changed, 30 insertions, 17 deletions
diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js
index f292aeec1..719877750 100644
--- a/ext/webgpu/01_webgpu.js
+++ b/ext/webgpu/01_webgpu.js
@@ -7435,16 +7435,6 @@ const dictMembersGPUCanvasConfiguration = [
converter: webidl.converters["GPUPresentMode"],
},
{
- key: "width",
- converter: webidl.converters["long"],
- required: true,
- },
- {
- key: "height",
- converter: webidl.converters["long"],
- required: true,
- },
- {
key: "viewFormats",
converter: webidl.createSequenceConverter(
webidl.converters["GPUTextureFormat"],
diff --git a/ext/webgpu/02_surface.js b/ext/webgpu/02_surface.js
index c48787dbf..ce723b891 100644
--- a/ext/webgpu/02_surface.js
+++ b/ext/webgpu/02_surface.js
@@ -29,6 +29,8 @@ const _configuration = Symbol("[[configuration]]");
const _canvas = Symbol("[[canvas]]");
const _currentTexture = Symbol("[[currentTexture]]");
const _present = Symbol("[[present]]");
+const _dim = Symbol("[[dimensions]]");
+
class GPUCanvasContext {
/** @type {number} */
[_surfaceRid];
@@ -36,6 +38,7 @@ class GPUCanvasContext {
[_canvas];
/** @type {GPUTexture | undefined} */
[_currentTexture];
+ [_dim];
get canvas() {
webidl.assertBranded(this, GPUCanvasContextPrototype);
@@ -69,8 +72,8 @@ class GPUCanvasContext {
format: configuration.format,
viewFormats: configuration.viewFormats,
usage: configuration.usage,
- width: configuration.width,
- height: configuration.height,
+ width: this[_dim].width,
+ height: this[_dim].height,
alphaMode: configuration.alphaMode,
});
@@ -110,8 +113,8 @@ class GPUCanvasContext {
const texture = createGPUTexture(
{
size: {
- width: this[_configuration].width,
- height: this[_configuration].height,
+ width: this[_dim].width,
+ height: this[_dim].height,
depthOrArrayLayers: 1,
},
mipLevelCount: 1,
@@ -163,6 +166,8 @@ function createCanvasContext(options) {
const canvasContext = webidl.createBranded(GPUCanvasContext);
canvasContext[_surfaceRid] = options.surfaceRid;
canvasContext[_canvas] = options.canvas;
+ canvasContext[_dim] = { width: options.width, height: options.height };
+
return canvasContext;
}
@@ -172,16 +177,34 @@ function createCanvasContext(options) {
class UnsafeWindowSurface {
#ctx;
#surfaceRid;
+ #options;
- constructor(system, win, display) {
- this.#surfaceRid = op_webgpu_surface_create(system, win, display);
+ constructor(options) {
+ if (typeof options !== "object") {
+ throw new TypeError("options must be provided.");
+ }
+ if (
+ typeof options.width !== "number" || typeof options.height !== "number"
+ ) {
+ throw new TypeError("width and height must be provided.");
+ }
+
+ this.#surfaceRid = op_webgpu_surface_create(
+ options.system,
+ options.windowHandle,
+ options.displayHandle,
+ );
+ this.#options = options;
}
getContext(context) {
if (context !== "webgpu") {
throw new TypeError("Only 'webgpu' context is supported");
}
- this.#ctx = createCanvasContext({ surfaceRid: this.#surfaceRid });
+ this.#ctx = createCanvasContext({
+ surfaceRid: this.#surfaceRid,
+ ...this.#options,
+ });
return this.#ctx;
}