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