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