[WHLSL] Rewrite all tests to use WHLSL and delete the isWHLSL flag
[WebKit-https.git] / LayoutTests / webgpu / color-write-mask-triangle-strip.html
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>WebGPU Hello Triangles</title>
4 <meta name="assert" content="WebGPU correctly renders a green canvas.">
5 <link rel="match" href="color-write-mask-triangle-strip-expected.html">
6 <p>Pass if square canvas below is completely green.</p>
7 <canvas width="400" height="400"></canvas>
8 <script src="js/webgpu-functions.js"></script>
9 <script>
10 if (window.testRunner)
11     testRunner.waitUntilDone();
12
13 const shaderCode = `
14 vertex float4 vertex_main(uint vid : SV_VertexID) : SV_Position
15 {
16     float4 v;
17     switch (vid) {
18     case 0:
19         v = float4(-1, 1, 0, 1);
20         break;
21     case 1:
22         v = float4(-1, -1, 0, 1);
23         break;
24     case 2:
25         v = float4(1, 1, 0, 1);
26         break;
27     default:
28         v = float4(1, -1, 0, 1);
29         break;
30     }
31     return v;
32 }
33
34 fragment float4 fragment_main() : SV_Target 0
35 {
36     return float4(1, 1, 1, 1);
37 }
38 `
39
40 const canvas = document.querySelector("canvas");
41
42 async function test(device) {
43     const swapChain = createBasicSwapChain(canvas, device);
44     const shaderModule = device.createShaderModule({ code: shaderCode });
45     const colorStates = [{
46         format: "bgra8unorm",
47         alphaBlend: {},
48         colorBlend: {},
49         writeMask: GPUColorWriteBits.GREEN | GPUColorWriteBits.ALPHA
50     }];
51     const pipeline = createBasicPipeline(shaderModule, device, colorStates);
52     const commandEncoder = device.createCommandEncoder();
53     const colorAttachment = {
54         attachment: swapChain.getCurrentTexture().createDefaultView(),
55         loadOp: "clear",
56         storeOp: "store",
57         clearColor: { r: 0, g: 0, b: 0, a: 0 }
58     };
59     const passEncoder = commandEncoder.beginRenderPass({ colorAttachments: [colorAttachment] });
60     encodeBasicCommands(passEncoder, pipeline);
61     const queue = device.getQueue();
62
63     queue.submit([commandEncoder.finish()]);
64 }
65
66 getBasicDevice().then(function(device) {
67     test(device).then(function() {
68         if (window.testRunner)
69             testRunner.notifyDone();
70     }, function() {
71         if (window.testRunner)
72             testRunner.notifyDone();
73     });
74 }, function() {
75     drawGreenSquareInSoftware(canvas);
76     if (window.testRunner)
77         testRunner.notifyDone();
78 });
79 </script>