[WHLSL] Move WHLSL tests to their own folder
[WebKit-https.git] / LayoutTests / webgpu / whlsl / textures-getdimensions.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(Texture2D<float4> theTexture : register(t0), device uint[] theBuffer : register(u1)) {
12     uint width;
13     uint height;
14     uint numberOfLevels;
15     GetDimensions(theTexture, 0, &width, &height, &numberOfLevels);
16     theBuffer[0] = width;
17     theBuffer[1] = height;
18     theBuffer[2] = numberOfLevels;
19 }
20 `;
21
22 async function start(device) {
23     const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
24     const computeStage = {module: shaderModule, entryPoint: "computeShader"};
25
26     const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "sampled-texture"}, {binding: 1, visibility: 7, type: "storage-buffer"}]};
27     const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
28     const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
29     const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
30
31     const computePipelineDescriptor = {computeStage, layout: pipelineLayout};
32     const computePipeline = device.createComputePipeline(computePipelineDescriptor);
33
34     const textureDescriptor = {size: {width: 2, height: 2, depth: 1}, format: "rgba8unorm", usage: GPUTextureUsage.SAMPLED};
35     const texture = device.createTexture(textureDescriptor);
36     const textureView = texture.createDefaultView();
37
38     const resultsBufferDescriptor = {size: Uint32Array.BYTES_PER_ELEMENT * 3, usage: GPUBufferUsage.STORAGE | GPUBufferUsage.MAP_READ};
39     const resultsBuffer = device.createBuffer(resultsBufferDescriptor);
40
41     const bufferBinding = {buffer: resultsBuffer, size: Uint32Array.BYTES_PER_ELEMENT * 3};
42     const bindGroupBindings = [{binding: 0, resource: textureView}, {binding: 1, resource: bufferBinding}];
43     const bindGroupDescriptor = {layout: bindGroupLayout, bindings: bindGroupBindings};
44     const bindGroup = device.createBindGroup(bindGroupDescriptor);
45
46     const commandEncoder = device.createCommandEncoder(); // {}
47     const computePassEncoder = commandEncoder.beginComputePass();
48     computePassEncoder.setPipeline(computePipeline);
49     computePassEncoder.setBindGroup(0, bindGroup);
50     computePassEncoder.dispatch(1, 1, 1);
51     computePassEncoder.endPass();
52     const commandBuffer = commandEncoder.finish();
53     device.getQueue().submit([commandBuffer]);
54
55     const resultsArrayBuffer = await resultsBuffer.mapReadAsync();
56     const resultsUint32Array = new Uint32Array(resultsArrayBuffer);
57     if (resultsUint32Array[0] == 2
58         && resultsUint32Array[1] == 2
59         && resultsUint32Array[2] == 1)
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>