Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when using depth sampler with web gl backend #7370

Open
Sunday111 opened this issue Mar 19, 2025 · 0 comments
Open

Crash when using depth sampler with web gl backend #7370

Sunday111 opened this issue Mar 19, 2025 · 0 comments

Comments

@Sunday111
Copy link

Description
I have a straightforward piece of functionality that should display depth texture, which means I have to sample depth texture in the fragment shader. Here is what my fragment shader:

display_depth_shader.wgsl
struct VertexInput {
    @location(0) position: vec2<f32>,
};

struct VertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) uv: vec2<f32>,
};

@vertex
fn vs_main(
    model: VertexInput,
) -> VertexOutput {
    var out: VertexOutput;
    out.clip_position = vec4<f32>(model.position, 0.0, 1.0);
    out.uv = (model.position + 1) / 2;
    out.uv.y = 1 - out.uv.y;
    return out;
}

@group(0) @binding(0)
var t_depth: texture_depth_2d;
@group(0) @binding(1)
var s_depth: sampler;

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    let near = 0.1;
    let far = 100.0;
    let depth = textureSampleLevel(t_depth, s_depth, in.uv, 0);
    let r = (2.0 * near) / (far + near - depth * (far - near));
    return vec4<f32>(vec3<f32>(r), 1.0);
}

The problem is that the translated shader fails to compile. If I understand correctly, Web GL 2.0 allows using depth textures in shaders but only with comparison samplers (which works fine on Windows).

The message in Chrome's console log says I should report this issue so here I am.

Repro steps
It can be reproduced here https://sunday111.github.io/rust-learn-wgpu/tutorial_8 (focus the surface and press key O).

The source code with build instructions is available here: https://github.com/Sunday111/rust-learn-wgpu . I am not sure if that can be fixed for Web GL 2 backend at all but the error description could be better.

Extra materials
Here is console log from the browser where I printed device limits.

lockdown-install.js:1 Removing unpermitted intrinsics
wasm-package.js:1245 device limits: Limits { max_texture_dimension_1d: 2048, max_texture_dimension_2d: 4096, max_texture_dimension_3d: 256, max_texture_array_layers: 256, max_bind_groups: 4, max_bindings_per_bind_group: 1000, max_dynamic_uniform_buffers_per_pipeline_layout: 8, max_dynamic_storage_buffers_per_pipeline_layout: 0, max_sampled_textures_per_shader_stage: 16, max_samplers_per_shader_stage: 16, max_storage_buffers_per_shader_stage: 0, max_storage_textures_per_shader_stage: 0, max_uniform_buffers_per_shader_stage: 11, max_uniform_buffer_binding_size: 16384, max_storage_buffer_binding_size: 0, max_vertex_buffers: 8, max_buffer_size: 268435456, max_vertex_attributes: 16, max_vertex_buffer_array_stride: 255, min_uniform_buffer_offset_alignment: 256, min_storage_buffer_offset_alignment: 256, max_inter_stage_shader_components: 31, max_color_attachments: 8, max_color_attachment_bytes_per_sample: 32, max_compute_workgroup_storage_size: 0, max_compute_invocations_per_workgroup: 0, max_compute_workgroup_size_x: 0, max_compute_workgroup_size_y: 0, max_compute_workgroup_size_z: 0, max_compute_workgroups_per_dimension: 0, min_subgroup_size: 0, max_subgroup_size: 0, max_push_constant_size: 0, max_non_sampler_bindings: 1000000 }
wasm-package.js:1245 adapter info: AdapterInfo { name: "ANGLE (NVIDIA, NVIDIA GeForce RTX 4080 SUPER (0x00002702) Direct3D11 vs_5_0 ps_5_0, D3D11)", vendor: 4318, device: 0, device_type: Other, driver: "", driver_info: "WebGL 2.0 (OpenGL ES 3.0 Chromium)", backend: Gl }
wasm-package.js:1022 	Shader compilation failed: ERROR: 0:20: 'textureLod' : no matching overloaded function found

Here is the validation error

wgpu error: Validation Error

Caused by:
  In Device::create_render_pipeline, label = 'depth_pass.render_pipeline'
    Internal error in ShaderStages(FRAGMENT) shader: ERROR: 0:20: 'textureLod' : no matching overloaded function found

Platform
Windows, WebGL 2.0 (OpenGL ES 3.0 Chromium), Rust compiled to wasm with wgpu 24.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant