[WHLSL] Rewrite all tests to use WHLSL and delete the isWHLSL flag
[WebKit-https.git] / LayoutTests / webgpu / whlsl / nested-dot-expression-rvalue.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
11 struct Bar {
12     float shade;
13 }
14 struct Foo {
15     Bar bar;
16 }
17
18 struct Wrapper {
19     Foo foo;
20 }
21
22 struct VertexOut {
23     float4 position : SV_Position;
24     float shade : attribute(0);
25 }
26
27 vertex VertexOut vertexShader(float4 position : attribute(0), float shade : attribute(1)) {
28     Wrapper wrapper;
29     wrapper.foo.bar.shade = shade;
30     VertexOut result;
31     result.position = position;
32     result.shade = wrapper.foo.bar.shade;
33     return result;
34 }
35
36 fragment float4 fragmentShader(float shade : attribute(0)) : SV_Target 0 {
37     return float4(shade, shade, shade, 1.0);
38 }
39 `;
40
41 const canvas = document.getElementById("canvas");
42
43 async function start(device) {
44     const shaderModule = device.createShaderModule({code: shaderSource});
45     const vertexStage = {module: shaderModule, entryPoint: "vertexShader"};
46     const fragmentStage = {module: shaderModule, entryPoint: "fragmentShader"};
47     const primitiveTopology = "triangle-strip";
48     const rasterizationState = {frontFace: "cw", cullMode: "none"};
49     const alphaBlend = {};
50     const colorBlend = {};
51     const colorStates = [{format: "rgba8unorm", alphaBlend, colorBlend, writeMask: 15}]; // GPUColorWriteBits.ALL
52     const depthStencilState = null;
53
54     const attribute0 = {shaderLocation: 0, format: "float4"};
55     const attribute1 = {shaderLocation: 1, format: "float", offset: 16};
56     const attributes = [attribute0, attribute1];
57     const input0 = {stride: 20, attributeSet: attributes};
58     const inputs = [input0];
59     const vertexInput = {vertexBuffers: inputs};
60
61     const bindGroupLayoutDescriptor = {bindings: [{binding: 0, visibility: 7, type: "uniform-buffer"}]};
62     const bindGroupLayout = device.createBindGroupLayout(bindGroupLayoutDescriptor);
63     const pipelineLayoutDescriptor = {bindGroupLayouts: [bindGroupLayout]};
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 vertexBuffer0Descriptor = {size: Float32Array.BYTES_PER_ELEMENT * 5 * 4, usage: GPUBufferUsage.VERTEX | GPUBufferUsage.MAP_WRITE};
70     const vertexBuffer0 = device.createBuffer(vertexBuffer0Descriptor);
71     const vertexBuffer0ArrayBuffer = await vertexBuffer0.mapWriteAsync();
72     const vertexBuffer0Float32Array = new Float32Array(vertexBuffer0ArrayBuffer);
73     vertexBuffer0Float32Array[0] = -0.5;
74     vertexBuffer0Float32Array[1] = -0.5;
75     vertexBuffer0Float32Array[2] = 1.0;
76     vertexBuffer0Float32Array[3] = 1.0;
77     vertexBuffer0Float32Array[4] = 1.0;
78
79     vertexBuffer0Float32Array[5] = -0.5;
80     vertexBuffer0Float32Array[6] = 0.5;
81     vertexBuffer0Float32Array[7] = 1.0;
82     vertexBuffer0Float32Array[8] = 1.0;
83     vertexBuffer0Float32Array[9] = 1.0;
84
85     vertexBuffer0Float32Array[10] = 0.5;
86     vertexBuffer0Float32Array[11] = -0.5;
87     vertexBuffer0Float32Array[12] = 1.0;
88     vertexBuffer0Float32Array[13] = 1.0;
89     vertexBuffer0Float32Array[14] = 1.0;
90
91     vertexBuffer0Float32Array[15] = 0.5;
92     vertexBuffer0Float32Array[16] = 0.5;
93     vertexBuffer0Float32Array[17] = 1.0;
94     vertexBuffer0Float32Array[18] = 1.0;
95     vertexBuffer0Float32Array[19] = 1.0;
96     vertexBuffer0.unmap();
97
98     const resourceBufferDescriptor = {size: Float32Array.BYTES_PER_ELEMENT, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.MAP_WRITE};
99     const resourceBuffer = device.createBuffer(resourceBufferDescriptor);
100     const resourceBufferArrayBuffer = await resourceBuffer.mapWriteAsync();
101     const resourceBufferFloat32Array = new Float32Array(resourceBufferArrayBuffer);
102     resourceBufferFloat32Array[0] = 1;
103     resourceBuffer.unmap();
104
105     const bufferBinding = {buffer: resourceBuffer, size: 4};
106     const bindGroupBinding = {binding: 0, resource: bufferBinding};
107     const bindGroupDescriptor = {layout: bindGroupLayout, bindings: [bindGroupBinding]};
108     const bindGroup = device.createBindGroup(bindGroupDescriptor);
109
110     const context = canvas.getContext("gpu");
111     const swapChainDescriptor = {device, format: "bgra8unorm"};
112     const swapChain = context.configureSwapChain(swapChainDescriptor);
113     const outputTexture = swapChain.getCurrentTexture();
114     const outputTextureView = outputTexture.createDefaultView();
115
116     const commandEncoder = device.createCommandEncoder(); // {}
117     const red = {r: 0, g: 0, b: 1, a: 1};
118     const colorAttachments = [{attachment: outputTextureView, resolveTarget: null, loadOp: "clear", storeOp: "store", clearColor: red}];
119     const depthStencilAttachment = null;
120     const renderPassDescriptor = {colorAttachments, depthStencilAttachment};
121     const renderPassEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);
122     renderPassEncoder.setPipeline(renderPipeline);
123     renderPassEncoder.setBindGroup(0, bindGroup);
124     renderPassEncoder.setVertexBuffers(0, [vertexBuffer0], [0]);
125     renderPassEncoder.draw(4, 1, 0, 0);
126     renderPassEncoder.endPass();
127     const commandBuffer = commandEncoder.finish();
128     device.getQueue().submit([commandBuffer]);
129 }
130 if (window.testRunner)
131     testRunner.waitUntilDone();
132 getBasicDevice().then(function(device) {
133     start(device).then(function() {
134         if (window.testRunner)
135             testRunner.notifyDone();
136     }, function() {
137         if (window.testRunner)
138             testRunner.notifyDone();
139     });
140 }, function() {
141     drawWhiteSquareOnBlueBackgroundInSoftware(canvas);
142     if (window.testRunner)
143         testRunner.notifyDone();
144 });
145 </script>
146 </body>
147 </html>