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