AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
[WebKit-https.git] / LayoutTests / webgpu / depth-enabled-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="vertex-buffer-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 #include <metal_stdlib>
15     
16 using namespace metal;
17
18 struct VertexIn
19 {
20     float4 position [[attribute(0)]];
21 };
22
23 struct VertexOut
24 {
25     float4 position [[position]];
26     float4 color;
27 };
28
29 vertex VertexOut vertex_main(VertexIn vertexIn [[stage_in]], uint iid [[instance_id]])
30 {
31     VertexOut vOut;
32     vOut.position = vertexIn.position;
33
34     if (iid == 0) {
35         vOut.position.z = 0.5;
36         vOut.color = float4(1, 0, 0, 1);
37     } else {
38         vOut.color = float4(0, 1, 0, 1);
39     }
40
41     return vOut;
42 }
43
44 fragment float4 fragment_main(VertexOut v [[stage_in]])
45 {
46     return v.color;
47 }
48 `
49
50 function createVertexBuffer(device) {
51     const bufferSize = 4 * 4 * 4;
52     const buffer = device.createBuffer({ size: bufferSize, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.TRANSFER_DST });
53     const arrayBuffer = new Float32Array([
54         // float4 xyzw
55         -1, 1, 0, 1,
56         -1, -1, 0, 1,
57         1, 1, 0, 1,
58         1, -1, 0, 1
59     ]).buffer;
60     
61     buffer.setSubData(0, arrayBuffer);
62     return buffer;
63 }
64
65 function createInputStateDescriptor() {
66     return {
67         indexFormat: "uint32",
68         attributes: [{
69             shaderLocation: 0,
70             inputSlot: 0,
71             offset: 0,
72             format: "float4"
73         }],
74         inputs: [{
75             inputSlot: 0,
76             stride: 4 * 4,
77             stepMode: "vertex"
78         }]
79     }
80 }
81
82 async function test() {
83     const device = await getBasicDevice();
84     const canvas = document.querySelector("canvas");
85     const swapChain = createBasicSwapChain(canvas, device);
86     // FIXME: Replace with non-MSL shaders.
87     const shaderModule = device.createShaderModule({ code: shaderCode });
88     const vertexBuffer = createVertexBuffer(device);
89     const inputStateDescriptor = createInputStateDescriptor();
90     const depthStateDescriptor = createBasicDepthStateDescriptor();
91     const pipeline = createBasicPipeline(shaderModule, device, null, null, inputStateDescriptor, depthStateDescriptor);
92     const commandEncoder = device.createCommandEncoder();
93
94     const basicAttachment = {
95         attachment: swapChain.getCurrentTexture().createDefaultView(),
96         loadOp: "clear",
97         storeOp: "store",
98         clearColor: { r: 1.0, g: 0, b: 0, a: 1.0 }
99     };
100
101     const depthAttachment = {
102         attachment: createBasicDepthTexture(canvas, device).createDefaultView(),
103         depthLoadOp: "clear",
104         depthStoreOp: "store",
105         clearDepth: 1.0
106     };
107
108     const encoder = commandEncoder.beginRenderPass({
109         colorAttachments: [basicAttachment],
110         depthStencilAttachment: depthAttachment
111     });
112
113     encoder.setVertexBuffers(0, [vertexBuffer], [0]);
114     encoder.setPipeline(pipeline);
115     encoder.draw(4, 2, 0, 0);
116     encoder.endPass();
117
118     device.getQueue().submit([commandEncoder.finish()]);
119
120     if (window.testRunner)
121         testRunner.notifyDone();
122 }
123
124 test();
125 </script>