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