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