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

Set the new naga capabilities #3494

Merged
merged 5 commits into from
Feb 17, 2023
Merged

Conversation

teoxoy
Copy link
Member

@teoxoy teoxoy commented Feb 17, 2023

Checklist

  • Run cargo clippy.
  • Run RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md. See simple instructions inside file.

Connections

Description

  • set the right naga capabilities
  • add Features::SHADER_EARLY_DEPTH_TEST
  • set the MULTISAMPLED_SHADING downlevel flag for gles and dx11

Testing

wgpu-types/src/lib.rs Show resolved Hide resolved
@cwfitzgerald cwfitzgerald merged commit 074d1da into gfx-rs:master Feb 17, 2023
@teoxoy teoxoy deleted the update-features branch February 17, 2023 11:26
@maaku
Copy link

maaku commented Jun 28, 2023

I'm going through the process of upgrading to wgpu 0.16, and this PR has broken my application. The following excerpt of my fragment shader for imposter-based drawing of atoms (spheres) has worked in all previous version of wgpu, on all platforms I have access to test (Metal on macOS, Vulkan on Linux, DX12 on Windows, WebGL2 for web):

    const float dist = length(uv);
    if (dist > element.radius) {
        discard;
    }

    const float z = sqrt(element.radius * element.radius - dist * dist);
    const vec4 in_pos_clipspace = position_clip_space + camera.projection[2] * z;

    gl_FragDepth = in_pos_clipspace.z / in_pos_clipspace.w;

Why is this feature gated for GLES 3.1+ only? As noted in the code review above, it works perfectly fine on other platforms.

@Wumpf
Copy link
Member

Wumpf commented Jun 29, 2023

@maaku what error are you getting? The snippet seems unrelated to both multisampled shading and early depth test

@maaku
Copy link

maaku commented Jun 29, 2023

[2023-06-29T10:32:00Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_shader_module
      note: label = `/Users/mark/Development/atomCAD/target/debug/build/atomcad-render-30b7e31c716879fe/out/shaders/billboard.frag`
    
Shader validation error: 


    Entry point main at Fragment is invalid
    Capability EARLY_DEPTH_TEST is not supported

Here is the whole fragment shader:

#version 450

struct Element {
    vec3 color;
    float radius;
};

layout(set = 0, binding = 0) uniform Camera {
    vec4 projection[4];
    vec4 view[4];
    vec4 projection_view[4];
} camera;

layout(location = 0) in vec2 uv;
layout(location = 1) in vec4 position_clip_space;
layout(location = 2) flat in vec4 element_vec;
layout(location = 4) flat in vec4 center_view_space;
layout(location = 5) in vec4 position_view_space;

layout(depth_greater) out float gl_FragDepth;
layout(location = 0) out vec4 color;
layout(location = 1) out vec4 normal;

float map(float value, float low1, float high1, float low2, float high2) {
    return low2 + (value - low1) * (high2 - low2) / (high1 - low1);
}

vec4 linear_to_srgb(vec4 input_color) {
    bvec3 cutoff = lessThan(input_color.rgb, vec3(0.0031308));
    vec3 higher = vec3(1.005) * pow(input_color.rgb, vec3(1.0 / 2.4)) - vec3(0.055);
    vec3 lower = input_color.rgb * vec3(12.92);

    return vec4(mix(higher, lower, cutoff), input_color.a);
}

void main(void) {
    Element element;
    element.color = element_vec.xyz;
    element.radius = element_vec.w;
    const float dist = length(uv);
    if (dist > element.radius) {
        discard;
    }

    const float z = sqrt(element.radius * element.radius - dist * dist);
    const vec4 in_pos_clipspace = position_clip_space + camera.projection[2] * z;

    gl_FragDepth = in_pos_clipspace.z / in_pos_clipspace.w;

    color = vec4(
        element.color * map(z, 0.0, element.radius, 0.25, 1.0),
        1.0
    );
    normal = vec4(normalize(position_view_space.xyz - center_view_space.xyz), 0.0);

#ifdef TARGET_WASM
    // Currently, firefox webgpu doesn't automatically convert linear rgb outputs to srgb
    // so we do it manually.
    color = linear_to_srgb(color);
#endif
}

@teoxoy
Copy link
Member Author

teoxoy commented Jun 29, 2023

That shader doesn't seem to contain the early_fragment_tests qualifier, so I don't see how the validation would get triggered in this case.

Also, trying to validate the shader via naga cli, I'm getting:

error: Unexpected qualifier
   ┌─ test.frag:20:8
   │
20 │ layout(depth_greater) out float gl_FragDepth;
   │        ^^^^^^^^^^^^^

Which sounds right since we don't have conservative depth implemented in the GLSL frontend.

@maaku
Copy link

maaku commented Jun 30, 2023

Thank you. I think I misunderstood how early fragment tests worked. I thought that setting was required for what I was doing. Removing it fixes the problem and I was able to upgrade to 0.16 without any other major issues. Thank you.

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

Successfully merging this pull request may close these issues.

4 participants