Web Inspector: Canvas: show WebGPU shader pipelines
[WebKit-https.git] / LayoutTests / inspector / canvas / setShaderProgramDisabled.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
5 <script src="resources/shaderProgram-utilities-webgl.js"></script>
6 <script id="vertex-shader" type="x-shader/x-vertex">
7     attribute vec3 position;
8     void main(void) {
9         gl_Position = vec4(position, 1.0);
10     }
11 </script>
12 <script id="fragment-shader" type="x-shader/x-fragment">
13     precision mediump float;
14
15     void main(void) {
16         gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
17     }
18 </script>
19 <script>
20 function load() {
21     createProgram("webgl");
22     linkProgram("vertex-shader", "fragment-shader");
23     context.useProgram(program);
24
25     clearContext();
26
27     runTest();
28 }
29
30 function clearContext() {
31     context.clearColor(0.0, 0.0, 0.0, 1.0);
32     context.clear(context.COLOR_BUFFER_BIT);
33 }
34
35 function drawArrays() {
36     clearContext();
37
38     let vertexes = [
39         -0.5,  0.5,  0.0,
40         -0.5, -0.5,  0.0,
41          0.5, -0.5,  0.0, 
42     ];
43     let vertexBuffer = context.createBuffer();
44     context.bindBuffer(context.ARRAY_BUFFER, vertexBuffer);
45     context.bufferData(context.ARRAY_BUFFER, new Float32Array(vertexes), context.STATIC_DRAW);
46
47     let position = context.getAttribLocation(program, "position");
48     context.vertexAttribPointer(position, 3, context.FLOAT, false, 0, 0); 
49     context.enableVertexAttribArray(position);
50
51     context.drawArrays(context.TRIANGLES, 0, 3);
52 }
53
54 function drawElements() {
55     clearContext();
56
57     let vertexes = [
58          0.5,  0.5,  0.0,
59         -0.5, -0.5,  0.0,
60          0.5, -0.5,  0.0, 
61     ];
62     let vertexBuffer = context.createBuffer();
63     context.bindBuffer(context.ARRAY_BUFFER, vertexBuffer);
64     context.bufferData(context.ARRAY_BUFFER, new Float32Array(vertexes), context.STATIC_DRAW);
65
66     let indexes = [0, 1, 2];
67     let indexBuffer = context.createBuffer();
68     context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, indexBuffer);
69     context.bufferData(context.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexes), context.STATIC_DRAW);
70
71     let position = context.getAttribLocation(program, "position");
72     context.vertexAttribPointer(position, 3, context.FLOAT, false, 0, 0); 
73     context.enableVertexAttribArray(position);
74
75     context.drawElements(context.TRIANGLES, indexes.length, context.UNSIGNED_SHORT, 0);
76 }
77
78 function test() {
79     let suite = InspectorTest.createAsyncSuite("Canvas.setShaderProgramDisabled");
80
81     let shaderProgram = WI.canvasManager.shaderPrograms[0];
82     let originalContent = null;
83
84     function validTest({name, disabled, evaluateString}) {
85         suite.addTestCase({
86             name,
87             test(resolve, reject) {
88                 CanvasAgent.setShaderProgramDisabled(shaderProgram.identifier, disabled, (error) => {
89                     if (error) {
90                         reject(error);
91                         return;
92                     }
93
94                     InspectorTest.evaluateInPage(evaluateString, (error) => {
95                         if (error) {
96                             reject(error);
97                             return;
98                         }
99
100                         CanvasAgent.requestContent(shaderProgram.canvas.identifier)
101                         .then(({content}) => {
102                             if (disabled)
103                                 InspectorTest.expectEqual(content, originalContent, "Disabling a shader program should prevent it from drawing.");
104                             else
105                                 InspectorTest.expectNotEqual(content, originalContent, "Re-enabling a shader program should allow it to draw.");
106                         })
107                         .then(resolve, reject);
108                     });
109                 });
110             }
111         });
112     }
113
114     validTest({
115         name: "Canvas.setShaderProgramDisabled.disabledDrawArrays",
116         disabled: true,
117         evaluateString: `drawArrays()`,
118     });
119
120     validTest({
121         name: "Canvas.setShaderProgramDisabled.disabledDrawElements",
122         disabled: true,
123         evaluateString: `drawElements()`,
124     });
125
126     validTest({
127         name: "Canvas.setShaderProgramDisabled.reenabledDrawArrays",
128         disabled: false,
129         evaluateString: `drawArrays()`,
130     });
131
132     validTest({
133         name: "Canvas.setShaderProgramDisabled.reenabledDrawElements",
134         disabled: false,
135         evaluateString: `drawElements()`,
136     });
137
138     suite.addTestCase({
139         name: "Canvas.setShaderProgramDisabled.invalidProgramId",
140         description: "Invalid program identifiers should cause an error.",
141         test(resolve, reject) {
142             const programId = "INVALID_PROGRAM_ID";
143             const disabled = false;
144             CanvasAgent.setShaderProgramDisabled(programId, disabled, (error) => {
145                 InspectorTest.expectThat(error, "Should produce an error.");
146                 InspectorTest.log("Error: " + error);
147                 resolve();
148             });
149         }
150     });
151
152     CanvasAgent.requestContent(shaderProgram.canvas.identifier, (error, content) => {
153         originalContent = content;
154
155         suite.runTestCasesAndFinish();
156     });
157 }
158 </script>
159 </head>
160 <body onload="load()">
161     <p>Test disabling and re-enabling of shader programs.</p>
162 </body>
163 </html>