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

Wgpu 0.8 flickering during render #1360

Closed
sotrh opened this issue May 2, 2021 · 15 comments
Closed

Wgpu 0.8 flickering during render #1360

sotrh opened this issue May 2, 2021 · 15 comments
Assignees
Labels
help required We need community help to make this happen. type: bug Something isn't working

Comments

@sotrh
Copy link

sotrh commented May 2, 2021

When I open my model loading tutorial, I notice a lot of flickering in my scene. The angle I view the scene seems to effect the flickering. Whole triangles are flickering.

https://youtu.be/pSXPMDl1J4o

I was guessing it might be something to do with my depth buffer, but I disabled the depth pass and the flickering persisted. I've linked the trace and code below.

flickering_trace.zip
https://github.com/sotrh/learn-wgpu/tree/0.8/code/beginner/tutorial9-models

I've tried running my code with RenderDoc, but for whatever reason RenderDoc isn't giving me the option to record a frame so I can't see any of the api calls.

Let me know if I can provide anymore information.

@kvark kvark transferred this issue from gfx-rs/wgpu-rs May 2, 2021
@kvark kvark added help required We need community help to make this happen. type: bug Something isn't working labels May 2, 2021
@kvark
Copy link
Member

kvark commented May 2, 2021

Interesting issue... I reproduced on NVidia/Linux/Vulkan and played with this code. What's your platform?
I had no luck reducing the bug yet, and RenderDoc has issues on this machine, so I wasn't able to capture anything. So far it looks like the vertex transformation (or the primitive assembly) fails in some what, but it's hard to tell how exactly. This is unlikely anything wgpu is doing wrong, looks more like a driver bug to me.

@JeroenCops
Copy link

I have encountered the same issue. I produced it on NVidia/Windows/Vulkan and when switching to DirectX 12 the problem went away.

@qthree
Copy link
Contributor

qthree commented May 2, 2021

Probably related #1316

@kvark
Copy link
Member

kvark commented May 2, 2021

Interesting. @sotrh could you try enabling "cross" feature and seeing if it makes anything different?

@sotrh
Copy link
Author

sotrh commented May 2, 2021

Yep that fixed it. I guess the output from shaderc works a little better with Spirv Cross enabled then? I'm going to check to see if it fixes my other issue #1359

@kvark
Copy link
Member

kvark commented May 2, 2021 via email

@kvark
Copy link
Member

kvark commented May 2, 2021 via email

@sotrh
Copy link
Author

sotrh commented May 2, 2021

Should I disable spirv cross as well as rewrite in wgsl?

@kvark
Copy link
Member

kvark commented May 2, 2021 via email

@sotrh
Copy link
Author

sotrh commented May 2, 2021

The wgsl code has no flickering. It does have some validation errors though.

// Vertex shader

[[block]]
struct Uniforms {
    view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
var<uniform> uniforms: Uniforms;

struct VertexInput {
    [[location(0)]] position: vec3<f32>;
    [[location(1)]] tex_coords: vec2<f32>;
};
struct InstanceInput {
    [[location(5)]] model_matrix_0: vec4<f32>;
    [[location(6)]] model_matrix_1: vec4<f32>;
    [[location(7)]] model_matrix_2: vec4<f32>;
    [[location(8)]] model_matrix_3: vec4<f32>;
};

struct VertexOutput {
    [[builtin(position)]] clip_position: vec4<f32>;
    [[location(0)]] tex_coords: vec2<f32>;
};

[[stage(vertex)]]
fn main(
    model: VertexInput,
    instance: InstanceInput,
) -> VertexOutput {
    let model_matrix = mat4x4<f32>(
        instance.model_matrix_0,
        instance.model_matrix_1,
        instance.model_matrix_2,
        instance.model_matrix_3,
    );
    var out: VertexOutput;
    out.tex_coords = model.tex_coords;
    out.clip_position = uniforms.view_proj * model_matrix * vec4<f32>(model.position, 1.0);
    return out;
}

// Fragment shader

[[group(0), binding(0)]]
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
var s_diffuse: sampler;

[[stage(fragment)]]
fn main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
    return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}
[2021-05-02T17:40:30Z ERROR gfx_backend_vulkan] 
    VALIDATION [UNASSIGNED-CoreValidation-Shader-InconsistentSpirv (0x6bbb14)] : Validation Error: [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object 0: handle = 0x55f74a6fa508, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x6bbb14 | SPIR-V module not valid: Capability Kernel is not allowed by Vulkan 1.2 specification (or requires extension)
      OpCapability Kernel
    
    object info: (type: DEVICE, hndl: 0x55f74a6fa508)
    
[2021-05-02T17:40:30Z ERROR gfx_backend_vulkan] 
    VALIDATION [UNASSIGNED-CoreValidation-Shader-FeatureNotEnabled (0x8c548bfd)] : Validation Error: [ UNASSIGNED-CoreValidation-Shader-FeatureNotEnabled ] Object 0: handle = 0x55f74a6fa508, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x8c548bfd | Shader requires VkPhysicalDeviceFeatures::shaderStorageImageMultisample but is not enabled on the device
    object info: (type: DEVICE, hndl: 0x55f74a6fa508)
    
[2021-05-02T17:40:30Z ERROR gfx_backend_vulkan] 
    VALIDATION [UNASSIGNED-CoreValidation-Shader-FeatureNotEnabled (0x8c548bfd)] : Validation Error: [ UNASSIGNED-CoreValidation-Shader-FeatureNotEnabled ] Object 0: handle = 0x55f74a6fa508, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x8c548bfd | Shader requires VkPhysicalDeviceFeatures::shaderStorageImageMultisample but is not enabled on the device
    object info: (type: DEVICE, hndl: 0x55f74a6fa508)

@kvark
Copy link
Member

kvark commented May 3, 2021

Looked at this tonight and found the reason - gfx-rs/naga#820

Also filed gfx-rs/naga#819 separately for the Kernel related validation error.

@kvark
Copy link
Member

kvark commented May 3, 2021

Fix is coming, hold tight!

@yanchith
Copy link
Contributor

I am guessing the fix for this didn't make it in 0.8.1?

I can still reproduce on win32-vulkan-nvidia (all others I have access to work correctly, including win32-vulkan-intel). Can provide traces and videos, and help verify the fix also.

@kvark
Copy link
Member

kvark commented May 14, 2021

It's not a part of a Naga release yet, we'll back-port the change now.

@kvark
Copy link
Member

kvark commented May 14, 2021

Naga-0.4.1 is up.

@kvark kvark closed this as completed May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help required We need community help to make this happen. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants