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