REGRESSION: ( r246394 ) webgpu/whlsl-buffer-fragment.html and webgpu/whlsl-buffer...
[WebKit-https.git] / LayoutTests / webgpu / propertyresolver / indexer-setter-lvalue.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 f.x;
20 }
21
22 Foo operator[]=(Foo f, uint index, float x) {
23     f.x = x;
24     return f;
25 }
26
27 struct Bar {
28     Foo z;
29 }
30
31 thread Foo* operator&[](thread Bar* b, uint index) {
32     return &b->z;
33 }
34
35 fragment float4 fragmentShader() : SV_Target 0 {
36     Bar b;
37     b[2][3] = 1.0;
38     return float4(b[2][3], b[2][3], b[2][3], 1.0);
39 }
40 `;
41
42 const canvas = document.getElementById("canvas");
43
44 async function start(device) {
45     const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
46     const vertexStage = {module: shaderModule, entryPoint: "vertexShader"};
47     const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"};
48     const primitiveTopology = "triangle-strip";
49     const rasterizationState = {frontFace: "cw", cullMode: "none"};
50     const alphaBlend = {};
51     const colorBlend = {};
52     const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL
53     const depthStencilState = null;
54     
55     const attribute0 = {shaderLocation: 0, format: "float4"};
56     const input0 = {stride: 16, attributeSet: [attribute0]};
57     const inputs = [input0];
58     const vertexInput = {vertexBuffers: inputs};
59
60     const pipelineLayoutDescriptor = {bindGroupLayouts: []};
61     const pipelineLayout = device.createPipelineLayout(pipelineLayoutDescriptor);
62
63     const renderPipelineDescriptor = {vertexStage, fragmentStage, primitiveTopology, rasterizationState, colorStates, depthStencilState, vertexInput, sampleCount: 1, layout: pipelineLayout};
64     const renderPipeline = device.createRenderPipeline(renderPipelineDescriptor);
65
66     const vertexBufferDescriptor = {size: Float32Array.BYTES_PER_ELEMENT * 4 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.MAP_WRITE};
67     const vertexBuffer = device.createBuffer(vertexBufferDescriptor);
68     const vertexBufferArrayBuffer = await vertexBuffer.mapWriteAsync();
69     const vertexBufferFloat32Array = new Float32Array(vertexBufferArrayBuffer);
70     vertexBufferFloat32Array[0] = -0.5;
71     vertexBufferFloat32Array[1] = -0.5;
72     vertexBufferFloat32Array[2] = 1.0;
73     vertexBufferFloat32Array[3] = 1;
74     vertexBufferFloat32Array[4] = -0.5;
75     vertexBufferFloat32Array[5] = 0.5;
76     vertexBufferFloat32Array[6] = 1.0;
77     vertexBufferFloat32Array[7] = 1;
78     vertexBufferFloat32Array[8] = 0.5;
79     vertexBufferFloat32Array[9] = -0.5;
80     vertexBufferFloat32Array[10] = 1.0;
81     vertexBufferFloat32Array[11] = 1;
82     vertexBufferFloat32Array[12] = 0.5;
83     vertexBufferFloat32Array[13] = 0.5;
84     vertexBufferFloat32Array[14] = 1.0;
85     vertexBufferFloat32Array[15] = 1;
86     vertexBuffer.unmap();
87
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 getBasicDevice().then(function(device) {
110     start(device).then(function() {
111         if (window.testRunner)
112             testRunner.notifyDone();
113     }, function() {
114         if (window.testRunner)
115             testRunner.notifyDone();
116     });
117 }, function() {
118     drawWhiteSquareOnBlueBackgroundInSoftware(canvas);
119     if (window.testRunner)
120         testRunner.notifyDone();
121 });
122 </script>
123 </body>
124 </html>