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