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