Add a runtime-disabled dialog element skeleton
[WebKit-https.git] / LayoutTests / webgpu / whlsl / propertyresolver / indexer-ander.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../js/webgpu-functions.js"></script>
5 </head>
6 <body>
7 <canvas id="canvas" width="400" height="400"></canvas>
8 <script>
9 const shaderSource = `
10 vertex float4 vertexShader(float4 position : attribute(0)) : SV_Position {
11     return position;
12 }
13
14 struct Foo {
15     float x;
16 }
17
18 thread float* operator&[](thread Foo* f, uint index) {
19     return &f->x;
20 }
21
22 Foo generateFoo() {
23     Foo f;
24     f.x = 1.0;
25     return f;
26 }
27
28 fragment float4 fragmentShader() : SV_Target 0 {
29     return float4(generateFoo()[0], generateFoo()[1], generateFoo()[2], 1.0);
30 }
31 `;
32
33 const canvas = document.getElementById("canvas");
34
35 async function start(device) {
36     const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
37     const vertexStage = {module: shaderModule, entryPoint: "vertexShader"};
38     const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"};
39     const primitiveTopology = "triangle-strip";
40     const rasterizationState = {frontFace: "cw", cullMode: "none"};
41     const alphaBlend = {};
42     const colorBlend = {};
43     const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL
44     const depthStencilState = null;
45     
46     const attribute0 = {shaderLocation: 0, format: "float4"};
47     const input0 = {stride: 16, attributeSet: [attribute0]};
48     const inputs = [input0];
49     const vertexInput = {vertexBuffers: inputs};
50
51     const pipelineLayoutDescriptor = {bindGroupLayouts: []};
52     const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
53
54     const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, vertexInput, sampleCount: 1, layout: pipelineLayout};
55     const renderPipeline = device.createRenderPipeline(renderPipelineDescriptor);
56
57     const vertexBufferDescriptor = {size: Float32Array.BYTES_PER_ELEMENT * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.MAP_WRITE};
58     const vertexBuffer = device.createBuffer(vertexBufferDescriptor);
59     const vertexBufferArrayBuffer = await vertexBuffer.mapWriteAsync();
60     const vertexBufferFloat32Array = new Float32Array(vertexBufferArrayBuffer);
61     vertexBufferFloat32Array[0] = -0.5;
62     vertexBufferFloat32Array[1] = -0.5;
63     vertexBufferFloat32Array[2] = 1.0;
64     vertexBufferFloat32Array[3] = 1;
65     vertexBufferFloat32Array[4] = -0.5;
66     vertexBufferFloat32Array[5] = 0.5;
67     vertexBufferFloat32Array[6] = 1.0;
68     vertexBufferFloat32Array[7] = 1;
69     vertexBufferFloat32Array[8] = 0.5;
70     vertexBufferFloat32Array[9] = -0.5;
71     vertexBufferFloat32Array[10] = 1.0;
72     vertexBufferFloat32Array[11] = 1;
73     vertexBufferFloat32Array[12] = 0.5;
74     vertexBufferFloat32Array[13] = 0.5;
75     vertexBufferFloat32Array[14] = 1.0;
76     vertexBufferFloat32Array[15] = 1;
77     vertexBuffer.unmap();
78
79     const context = canvas.getContext("gpu");
80     const swapChainDescriptor = {device, format: "bgra8unorm"};
81     const swapChain = context.configureSwapChain(swapChainDescriptor);
82     const outputTexture = swapChain.getCurrentTexture();
83     const outputTextureView = outputTexture.createDefaultView();
84
85     const commandEncoder = device.createCommandEncoder(); // {}
86     const red = {r: 0, g: 0, b: 1, a: 1};
87     const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor: red}];
88     const depthStencilAttachment = null;
89     const renderPassDescriptor = {colorAttachments, depthStencilAttachment};
90     const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
91     renderPassEncoder.setPipeline(renderPipeline);
92     renderPassEncoder.setVertexBuffers(0, [vertexBuffer], [0]);
93     renderPassEncoder.draw(4, 1, 0, 0);
94     renderPassEncoder.endPass();
95     const commandBuffer = commandEncoder.finish();
96     device.getQueue().submit([commandBuffer]);
97 }
98 if (window.testRunner)
99     testRunner.waitUntilDone();
100 getBasicDevice().then(function(device) {
101     start(device).then(function() {
102         if (window.testRunner)
103             testRunner.notifyDone();
104     }, function() {
105         if (window.testRunner)
106             testRunner.notifyDone();
107     });
108 }, function() {
109     drawWhiteSquareOnBlueBackgroundInSoftware(canvas);
110     if (window.testRunner)
111         testRunner.notifyDone();
112 });
113 </script>
114 </body>
115 </html>