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