File: test_queue_write_perf.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (102 lines) | stat: -rw-r--r-- 2,890 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
  </head>

  <body>
    <script type="text/javascript">
      "use strict";

      var perfMetadata = {
        owner: "Graphics Team",
        name: "Queue Write",
        description:
          "Test the performance of Queue.writeBuffer and Queue.writeTexture",
        test: "mochitest",
        options: {
          default: {
            perfherder: true,
            perfherder_metrics: [
              { name: "writeBuffer Time", unit: "ms" },
              { name: "writeTexture Time", unit: "ms" },
            ],
            manifest: "perftest.toml",
            manifest_flavor: "plain",
          },
        },
      };

      const iters = 100;

      ok(
        SpecialPowers.getBoolPref("dom.webgpu.enabled"),
        "WebGPU pref should be enabled."
      );

      async function runTest() {
        const adapter = await navigator.gpu.requestAdapter();
        const device = await adapter.requestDevice();
        device.onuncapturederror = function (e) {
          ok(false, "WebGPU error: " + e.error.message);
        };
        const buffer = device.createBuffer({
          size: 1024 * 1024,
          usage:
            GPUBufferUsage.COPY_DST |
            GPUBufferUsage.COPY_SRC |
            GPUBufferUsage.VERTEX,
        });
        const arrayBuf = new ArrayBuffer(256 * 1024 * 1024);
        new Int32Array(arrayBuf).fill(0x55);

        performance.mark("start writeBuffer");
        for (var i = 0; i < iters; i++) {
          device.queue.writeBuffer(buffer, 0, arrayBuf, 0, 1024 * 1024);
        }
        const writeBufferTime = performance.measure(
          "writeBuffer",
          "start writeBuffer"
        ).duration;

        const texture = device.createTexture({
          size: [512, 512, 1],
          dimension: "2d",
          format: "rgba8unorm",
          usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC,
        });

        performance.mark("start writeTexture");
        for (i = 0; i < iters; i++) {
          device.queue.writeTexture(
            { texture },
            arrayBuf,
            { bytesPerRow: 2048 },
            [512, 512, 1]
          );
        }
        const writeTextureTime = performance.measure(
          "writeTexture",
          "start writeTexture"
        ).duration;

        ok(device !== undefined, "");
        info(
          "perfMetrics",
          JSON.stringify({
            "writeBuffer Time": writeBufferTime,
            "writeTexture Time": writeTextureTime,
          })
        );
      }

      SimpleTest.waitForExplicitFinish();

      runTest()
        .catch(e => ok(false, "Unhandled exception " + e))
        .finally(() => SimpleTest.finish());
    </script>
  </body>
</html>