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