Error in Surface::configure: invalid surface
Description The open GL Backend fails to create a surface. Here is the code in question.
let size = window.inner_size();
// The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::new(wgpu::Backends::GL);
// let instance = wgpu::Instance::new(wgpu::Backends::all());
let surface = unsafe { instance.create_surface(window) };
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::default(),
compatible_surface: Some(&surface),
force_fallback_adapter: false,
})
.await
.unwrap();
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
// WebGL doesn't support all of wgpu's features, so if
// we're building for the web we'll have to disable some.
limits: if cfg!(target_arch = "wasm32") {
wgpu::Limits::downlevel_webgl2_defaults()
} else {
wgpu::Limits::default()
},
},
Some(&std::path::Path::new("trace")), // Trace path
// None,
)
.await
.unwrap();
let config = wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: surface.get_preferred_format(&adapter).unwrap(),
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
};
surface.configure(&device, &config);
Repro steps
You need to be on the v0.12 branch.
Here is a trace.ron that replicates the issue.
[
Init(
desc: (
label: None,
features: 0,
limits: (
maxTextureDimension1d: 8192,
maxTextureDimension2d: 8192,
maxTextureDimension3d: 2048,
maxTextureArrayLayers: 256,
maxBindGroups: 4,
maxDynamicUniformBuffersPerPipelineLayout: 8,
maxDynamicStorageBuffersPerPipelineLayout: 4,
maxSampledTexturesPerShaderStage: 16,
maxSamplersPerShaderStage: 16,
maxStorageBuffersPerShaderStage: 8,
maxStorageTexturesPerShaderStage: 8,
maxUniformBuffersPerShaderStage: 12,
maxUniformBufferBindingSize: 65536,
maxStorageBufferBindingSize: 134217728,
maxVertexBuffers: 8,
maxVertexAttributes: 16,
maxVertexBufferArrayStride: 2048,
maxPushConstantSize: 0,
minUniformBufferOffsetAlignment: 256,
minStorageBufferOffsetAlignment: 256,
maxInterStageShaderComponents: 60,
maxComputeWorkgroupStorageSize: 16352,
maxComputeInvocationsPerWorkgroup: 256,
maxComputeWorkgroupSizeX: 256,
maxComputeWorkgroupSizeY: 256,
maxComputeWorkgroupSizeZ: 64,
maxComputeWorkgroupsPerDimension: 65535,
),
),
backend: Gl,
),
ConfigureSurface(Id(0, 1, Empty), (
usage: 16,
format: r#bgra8unorm-srgb,
width: 800,
height: 600,
present_mode: Fifo,
)),
]
Expected vs observed behavior WGPU should create a surface using the GL backend
Extra materials
Running the trace with RUST_LOG=INFO:
RUST_LOG=INFO cargo run -p player --features winit -- ../learn-wgpu/trace/
Finished dev [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/play ../learn-wgpu/trace/`
[2022-02-26T18:45:47Z INFO play] Loading trace '"../learn-wgpu/trace/"'
[2022-02-26T18:45:47Z INFO play] Found 2 actions
[2022-02-26T18:45:47Z INFO play] Creating a window
[2022-02-26T18:45:47Z INFO winit::platform_impl::platform::x11::window] Guessed window scale factor: 1
[2022-02-26T18:45:47Z WARN wgpu_hal::vulkan::instance] Unable to find layer: VK_LAYER_KHRONOS_validation
[2022-02-26T18:45:47Z INFO wgpu_hal::vulkan::instance] Instance version: 0x4020a2
[2022-02-26T18:45:47Z INFO wgpu_hal::vulkan::instance] Enabling debug utils
[2022-02-26T18:45:47Z INFO wgpu_hal::vulkan::instance] Enabling device properties2
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Loading Wayland library to get the current display
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Loading X11 library to get the current display
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Using default platform
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Enabling EGL debug output
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Display vendor "Mesa Project", version (1, 5)
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] EGL surface: +srgb
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Trying native-render
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] EGL context: +debug
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] EGL context: +robust access
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] EGL context: +surfaceless
[2022-02-26T18:45:47Z INFO play] Initializing the device for backend: Gl
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Max label length: 256
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::egl] Enabling GLES debug output
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::adapter] Vendor: AMD
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::adapter] Renderer: AMD RENOIR (DRM 3.42.0, 5.15.5-76051505-generic, LLVM 12.0.1)
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::adapter] Version: OpenGL ES 3.2 Mesa 21.2.2
[2022-02-26T18:45:47Z INFO wgpu_hal::gles::adapter] SL version: OpenGL ES GLSL ES 3.20
[2022-02-26T18:45:47Z INFO wgpu_core::instance] Adapter Gl AdapterInfo { name: "AMD RENOIR (DRM 3.42.0, 5.15.5-76051505-generic, LLVM 12.0.1)", vendor: 4098, device: 0, device_type: DiscreteGpu, backend: Gl }
[2022-02-26T18:45:47Z INFO play] Picked 'AMD RENOIR (DRM 3.42.0, 5.15.5-76051505-generic, LLVM 12.0.1)'
[2022-02-26T18:45:47Z INFO play] Executing actions
[2022-02-26T18:45:47Z INFO play] Configuring the surface
[2022-02-26T18:45:47Z INFO wgpu_core::device] configuring surface with SurfaceConfiguration { usage: RENDER_ATTACHMENT, format: Bgra8UnormSrgb, width: 800, height: 600, present_mode: Fifo }
[2022-02-26T18:45:47Z ERROR wgpu_hal::gles::egl] EGL 'eglCreateWindowSurface' code 0x3003: dri3_surface_create
[2022-02-26T18:45:47Z WARN wgpu_hal::gles::egl] Error in create_window_surface: BadAlloc
thread 'main' panicked at 'InvalidSurface', player/src/bin/play.rs:132:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2022-02-26T18:45:47Z INFO wgpu_core::hub] Dropping Global
[2022-02-26T18:45:47Z INFO wgpu_core::device] Destroying 0 command encoders
Platform Wgpu v0.12 (from crates.io) Pop!_OS 21.10 cargo 1.57.0 (b2e52d7ca 2021-10-21) rustc 1.57.0 (f1edd0429 2021-11-29) rustup 1.24.3 (ce5817a94 2021-05-31)
I have the same issue, I managed to bisect the error to e867a743 (#2257).
Is this issue still present?
Same issue, but through bevyengine/bevy I'm using Arch on a Positivo Sim+ Intel Pentium B940 (old, isn't it?) integrated GPU
When trying to run cargo run --example breakout for bevyengine/bevy, in latest branch I get this
2024-09-30T10:32:51.962424Z ERROR wgpu_core::device::global: surface configuration failed: incompatible window kind
thread 'Compute Task Pool (17)' panicked at /home/george/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.20.1/src/backend/wgpu_core.rs:751:18:
Error in Surface::configure: Validation Error
Caused by:
Invalid surface
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_render::view::window::create_surfaces`!
2024-09-30T10:32:52.114758Z ERROR wgpu_hal::gles: GLES: [API/Error] ID 1 : GL_INVALID_VALUE in glTexSubImage2D(yoffset 0 + height 560 > 160)
2024-09-30T10:32:52.173891Z ERROR wgpu_core::device::global: Device::create_render_pipeline error: Internal error in ShaderStages(VERTEX) shader: The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE)
2024-09-30T10:32:52.173961Z ERROR wgpu::backend::wgpu_core: Shader translation error for stage ShaderStages(VERTEX): The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE)
2024-09-30T10:32:52.173974Z ERROR wgpu::backend::wgpu_core: Please report it to https://github.com/gfx-rs/wgpu
2024-09-30T10:32:52.174008Z ERROR wgpu::backend::wgpu_core: Handling wgpu errors as fatal by default
thread 'Async Compute Task Pool (0)' panicked at /home/george/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.20.1/src/backend/wgpu_core.rs:2996:5:
wgpu error: Validation Error
Caused by:
In Device::create_render_pipeline
note: label = `transparent_mesh2d_pipeline`
Internal error in ShaderStages(VERTEX) shader: The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE)
When trying to run
cargo run --example breakoutfor bevyengine/bevy, inlatestbranch I get this2024-09-30T10:32:51.962424Z ERROR wgpu_core::device::global: surface configuration failed: incompatible window kind thread 'Compute Task Pool (17)' panicked at /home/george/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.20.1/src/backend/wgpu_core.rs:751:18: Error in Surface::configure: Validation Error Caused by: Invalid surface note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Encountered a panic in system `bevy_render::view::window::create_surfaces`! 2024-09-30T10:32:52.114758Z ERROR wgpu_hal::gles: GLES: [API/Error] ID 1 : GL_INVALID_VALUE in glTexSubImage2D(yoffset 0 + height 560 > 160) 2024-09-30T10:32:52.173891Z ERROR wgpu_core::device::global: Device::create_render_pipeline error: Internal error in ShaderStages(VERTEX) shader: The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE) 2024-09-30T10:32:52.173961Z ERROR wgpu::backend::wgpu_core: Shader translation error for stage ShaderStages(VERTEX): The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE) 2024-09-30T10:32:52.173974Z ERROR wgpu::backend::wgpu_core: Please report it to https://github.com/gfx-rs/wgpu 2024-09-30T10:32:52.174008Z ERROR wgpu::backend::wgpu_core: Handling wgpu errors as fatal by default thread 'Async Compute Task Pool (0)' panicked at /home/george/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.20.1/src/backend/wgpu_core.rs:2996:5: wgpu error: Validation Error Caused by: In Device::create_render_pipeline note: label = `transparent_mesh2d_pipeline` Internal error in ShaderStages(VERTEX) shader: The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE)
Same here
Original issue and recently posted log are distinct. In the original issue we're seeing
[2022-02-26T18:45:47Z WARN wgpu_hal::gles::egl] Error in create_window_surface: BadAlloc thread 'main' panicked at 'InvalidSurface', player/src/bin/play.rs:132:37
which means that self.egl.instance.create_window_surface didn't work out. Bad alloc might mean all sort of things, maybe the size was invalid, would be worth populating the error message with more things.
Whereas the newly posted log has two errors:
-
surface configuration failed: incompatible window kind: this means that EGL (gl presentation) is not able to draw to the given window -
The selected version doesn't support Features(DYNAMIC_ARRAY_SIZE): This simply means that Bevy requires dynamic array size in shaders which isn't supported by the picked GLES adapter
In any case we really shouldn't make surface configuration a fatal error since there's myriads of reasons why this could fail. These errors need to be always forwarded.