Add a runtime-disabled dialog element skeleton
[WebKit-https.git] / LayoutTests / webgpu / whlsl-read-modify-write.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="js/webgpu-functions.js"></script>
5 <script src="../resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <script>
9 const shaderSource = `
10 [numthreads(1, 1, 1)]
11 compute void computeShader(device int[] buffer : register(u0)) {
12     buffer[0] = 1;
13     buffer[1] = buffer[0]++;
14
15     buffer[2] = 1;
16     buffer[3] = ++buffer[2];
17
18     buffer[4] = 1;
19     buffer[4] += 5;
20
21     buffer[5] = 1;
22     buffer[5] *= 7;
23
24     int total = 14;
25     for (int i = 0; i < 10; i += 2) {
26         total += i;
27     }
28     buffer[6] = total;
29
30     total = 14;
31     for (int i = 0; i < 10; ++i) {
32         total += i;
33     }
34     buffer[7] = total;
35 }
36 `;
37
38 async function start() {
39     const adapter = await navigator.gpu.requestAdapter();
40     const device = await adapter.requestDevice();
41
42     const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
43     const computeStage = {module: shaderModule, entryPoint: "computeShader"};
44
45     const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
46     const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
47     const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
48     const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
49
50     const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
51     const computePipeline = device.createComputePipeline(computePipelineDescriptor);
52
53     const size = Int32Array.BYTES_PER_ELEMENT * 8;
54
55     const bufferDescriptor = {size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.MAP_READ};
56     const buffer = device.createBuffer(bufferDescriptor);
57
58     const bufferBinding = {buffer: buffer, size};
59     const bindGroupBinding = {binding: 0, resource: bufferBinding};
60     const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
61     const bindGroup = device.createBindGroup(bindGroupDescriptor);
62
63     const commandEncoder = device.createCommandEncoder(); // {}
64     const computePassEncoder = commandEncoder.beginComputePass();
65     computePassEncoder.setPipeline(computePipeline);
66     computePassEncoder.setBindGroup(0, bindGroup);
67     computePassEncoder.dispatch(1, 1, 1);
68     computePassEncoder.endPass();
69     const commandBuffer = commandEncoder.finish();
70     device.getQueue().submit([commandBuffer]);
71
72     const resultsArrayBuffer = await buffer.mapReadAsync();
73     const results = new Int32Array(resultsArrayBuffer);
74     if (results[0] == 2
75         && results[1] == 1
76         && results[2] == 2
77         && results[3] == 2
78         && results[4] == 6
79         && results[5] == 7
80         && results[6] == 34
81         && results[7] == 59)
82         testPassed("");
83     else
84         testFailed("");
85     buffer.unmap();
86 }
87 window.jsTestIsAsync = true;
88 getBasicDevice().then(function(device) {
89     start(device).then(function() {
90         finishJSTest();
91     }, function() {
92         testFailed("");
93         finishJSTest();
94     });
95 }, function() {
96     testPassed("");
97     finishJSTest();
98 });
99 </script>
100 <script src="../resources/js-test-post.js"></script>
101 </body>
102 </html>