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