Skip to content

Write timestamp lands on wrong side of barriers #2521

@fintelia

Description

@fintelia

Description
I've been experimenting with wgpu's write_timestamp functionality to measure the execution time of compute shaders. Unfortunately, the lack of control of when they happen in relation to pipeline barriers seems to be preventing them from being of much use.

Repro steps
Execute two compute dispatches, and measure how long the second one takes:

cpass.dispatch(...);
cpass.write_timestamp(...);
cpass.dispatch(...);
cpass.write_timestamp(...);

Expected vs observed behavior
I would expect that the difference between the timestamps would reflect the execution time of the second dispatch. Instead, I observed that the measurement would sometimes be an order of magnitude larger, presumably including much of the time executing the first dispatch.

I assume this is related to vkCmdWriteTimestamp happening too early. Partial trace:

47 vkCmdBindPipeline(pipeline.generate.displacements)
48 vkCmdBindDescriptorSets(0, { bindgroup.generate.displacements })
49 vkCmdResetQueryPool(Query Pool 250)
50 vkCmdWriteTimestamp(Query Pool 250, 6)
51 vkCmdPipelineBarrier({ buffer.nodes })
52 vkCmdPipelineBarrier({ texture.tiles.displacements })
53 vkCmdDispatch(9, 9, 1)
54 vkCmdResetQueryPool(Query Pool 250)
55 vkCmdWriteTimestamp(Query Pool 250, 7)

Platform
I'm using Linux with an AMD GPU + mesa drivers, though I imagine this applies more broadly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions