Add a runtime-disabled dialog element skeleton
[WebKit-https.git] / LayoutTests / webgpu / whlsl-checker-should-set-type-of-read-modify-write-variables.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 float[] buffer : register(u0), float3 threadID : SV_DispatchThreadID) {
12     float4 vec;
13     vec[0] += 42.0;
14     buffer[uint(threadID.x)] = vec[0];
15 }
16 `;
17
18 async function start(device) {
19     const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
20     const computeStage = {module: shaderModule, entryPoint: "computeShader"};
21
22     const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "storage-buffer"}]};
23     const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
24     const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
25     const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
26
27     const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
28     const computePipeline = device.createComputePipeline(computePipelineDescriptor);
29
30     const size = Float32Array.BYTES_PER_ELEMENT * 1;
31
32     const bufferDescriptor = {size, usage: GPUBufferUsage.MAP_WRITE | GPUBufferUsage.TRANSFER_SRC};
33     const buffer = device.createBuffer(bufferDescriptor);
34     const bufferArrayBuffer = await buffer.mapWriteAsync();
35     const bufferFloat32Array = new Float32Array(bufferArrayBuffer);
36     bufferFloat32Array[0] = 0;
37     buffer.unmap();
38
39     const resultsBufferDescriptor = {size, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.TRANSFER_DST | GPUBufferUsage.MAP_READ};
40     const resultsBuffer = device.createBuffer(resultsBufferDescriptor);
41
42     const bufferBinding = {buffer: resultsBuffer, size};
43     const bindGroupBinding = {binding: 0, resource: bufferBinding};
44     const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
45     const bindGroup = device.createBindGroup(bindGroupDescriptor);
46
47     const commandEncoder = device.createCommandEncoder(); // {}
48     commandEncoder.copyBufferToBuffer(buffer, 0, resultsBuffer, 0, size);
49     const computePassEncoder = commandEncoder.beginComputePass();
50     computePassEncoder.setPipeline(computePipeline);
51     computePassEncoder.setBindGroup(0, bindGroup);
52     computePassEncoder.dispatch(1, 1, 1);
53     computePassEncoder.endPass();
54     const commandBuffer = commandEncoder.finish();
55     device.getQueue().submit([commandBuffer]);
56
57     const resultsArrayBuffer = await resultsBuffer.mapReadAsync();
58     const resultsFloat32Array = new Float32Array(resultsArrayBuffer);
59     if (resultsFloat32Array[0] == 42)
60         testPassed("");
61     else
62         testFailed("");
63     resultsBuffer.unmap();
64 }
65 window.jsTestIsAsync = true;
66 getBasicDevice().then(function(device) {
67     start(device).then(function() {
68         finishJSTest();
69     }, function() {
70         testFailed("");
71         finishJSTest();
72     });
73 }, function() {
74     testPassed("");
75     finishJSTest();
76 });
77 </script>
78 <script src="../resources/js-test-post.js"></script>
79 </body>
80 </html>