Skip to content

[DX12] Multiple threads submitting and then waiting can cause 60sec hang #8267

@Vecvec

Description

@Vecvec

Description
On the DX12 backend, if two (or more, but never just one) threads submit work and then wait on that submitted work one of the threads will hang for almost exactly 60 seconds (plus or minus a millisecond or so) on fence.wait (at Threading::WaitForSingleObject. This read-locks the fence causing the other thread to get stuck in queue submit on the other thread because that tries to write-lock the fence. None of this happens on vulkan.

Repro steps
https://github.com/Vecvec/wgpu_dx12_timeout reproduces this. There seems to need to be a workload, but that is probably because otherwise the submit would have finished by the time the fence waits.

Expected vs observed behavior
like vulkan, there should be no 60 second hangs

Extra materials
start of the logs from running the program.

   Compiling wgpu_dx12_timeout v0.1.0 (C:\Users\danie\code_projects\wgpu_dx12_timeout)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.85s
     Running `target\debug\wgpu_dx12_timeout.exe`
selected device Intel(R) Arc(TM) Graphics in backend Dx12, features: Features { features_wgpu: FeaturesWGPU(TEXTURE_FORMAT_16BIT_NORM | TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES | TIMESTAMP_QUERY_INSIDE_ENCODERS | TIMESTAMP_QUERY_INSIDE_PASSES | MAPPABLE_PRIMARY_BUFFERS | TEXTURE_BINDING_ARRAY | STORAGE_RESOURCE_BINDING_ARRAY | SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING | STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING | PARTIALLY_BOUND_BINDING_ARRAY | MULTI_DRAW_INDIRECT | MULTI_DRAW_INDIRECT_COUNT | PUSH_CONSTANTS | ADDRESS_MODE_CLAMP_TO_ZERO | ADDRESS_MODE_CLAMP_TO_BORDER | POLYGON_MODE_LINE | CONSERVATIVE_RASTERIZATION | VERTEX_WRITABLE_STORAGE | CLEAR_TEXTURE | TEXTURE_ATOMIC | TEXTURE_FORMAT_NV12 | EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE | EXPERIMENTAL_RAY_QUERY | SHADER_PRIMITIVE_INDEX | SHADER_INT64 | SUBGROUP | TEXTURE_INT64_ATOMIC | EXTENDED_ACCELERATION_STRUCTURE_VERTEX_FORMATS), features_webgpu: FeaturesWebGPU(DEPTH_CLIP_CONTROL | DEPTH32FLOAT_STENCIL8 | TEXTURE_COMPRESSION_BC | TEXTURE_COMPRESSION_BC_SLICED_3D | TIMESTAMP_QUERY | INDIRECT_FIRST_INSTANCE | SHADER_F16 | RG11B10UFLOAT_RENDERABLE | BGRA8UNORM_STORAGE | FLOAT32_FILTERABLE | DUAL_SOURCE_BLENDING) }
0
0
suspiciously long time - took 60.000504s to get to end of loop
suspiciously long time - took 59.999744s to get to end of submission
suspiciously long time - took 60.001125s to get to end of loop
100
100
suspiciously long time - took 60.007477s to get to end of loop
suspiciously long time - took 60.004585s to get to end of submission
suspiciously long time - took 60.00586s to get to end of loop
200
200
suspiciously long time - took 60.00143s to get to end of loop
suspiciously long time - took 59.99961s to get to end of submission
suspiciously long time - took 60.00068s to get to end of loop
300
300
400
400
500
500
600
600

Platform
Both on wgpu 26.0.1 (latest version), and a fork of trunk. Happens on both my intel IGPU as well as my RTX 3050.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions