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