denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.95k stars 5.4k forks source link

webgpu deno panic for bad display #24915

Open sigmaSd opened 3 months ago

sigmaSd commented 3 months ago
import { EventType, WindowBuilder } from "jsr:@divy/sdl2@0.11.0";

const width = 800;
const height = 600;

const win = new WindowBuilder("Hello, World!", width, height).build();

const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
  console.error("WebGPU not supported!");
  Deno.exit(1);
}
const device = await adapter.requestDevice();

/* Returns a Deno.UnsafeWindowSurface */
const surface = win.windowSurface();
/* Returns a WebGPU GPUCanvasContext */
const context = surface.getContext("webgpu");

context.configure({
  device,
  format: navigator.gpu.getPreferredCanvasFormat(),
  width,
  height,
}); // panics here

for await (const event of win.events()) {
  if (event.type === EventType.Quit) break;
  if (event.type !== EventType.Draw) continue;

  // Sine wave
  const r = Math.sin(Date.now() / 1000) / 2 + 0.5;
  const g = Math.sin(Date.now() / 1000 + 2) / 2 + 0.5;
  const b = Math.sin(Date.now() / 1000 + 4) / 2 + 0.5;

  const textureView = context.getCurrentTexture().createView();

  const commandEncoder = device.createCommandEncoder();
  const passEncoder = commandEncoder.beginRenderPass({
    colorAttachments: [
      {
        view: textureView,
        clearValue: { r, g, b, a: 1.0 },
        loadOp: "clear",
        storeOp: "store",
      },
    ],
  });
  passEncoder.end();

  device.queue.submit([commandEncoder.finish()]);
  surface.present();
}
deno 1.45.5 (release, x86_64-unknown-linux-gnu)

I'm using wayland, maybe that have to do with it

sigmaSd commented 3 months ago
SDL2_image not loaded. Some features will not be available.
SDL2_ttf not loaded. Some features will not be available.
SDL2 initialized on Linux

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 1.45.5
Args: ["deno", "run", "-A", "c.ts"]

thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.21.1/src/gles/egl.rs:296:14:
called `Result::unwrap()` on an `Err` value: BadDisplay
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
sigmaSd commented 3 months ago

WAYLAND_DISPLAY="" deno run -A works around the issue

yazan-abdalrahman commented 2 months ago

I think it was fixed in 1.46 because I am unable to reproduce it. @littledivy @sigmaSd

image

littledivy commented 2 months ago

Seems to be a Wayland (XWayland) + OpenGL ES issue. I was not able to reproduce this running Wayland (AMD Ryzen gpu)

The back-trace points to internal code in wgpu-hal so I would open an issue there.

littledivy commented 2 months ago

@yazan-abdalrahman You are running on Windows. This is a Linux + Wayland bug.