Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/scripts/generate_entry_points.py
1693 views
1
#!/usr/bin/python3
2
#
3
# Copyright 2017 The ANGLE Project Authors. All rights reserved.
4
# Use of this source code is governed by a BSD-style license that can be
5
# found in the LICENSE file.
6
#
7
# generate_entry_points.py:
8
# Generates the OpenGL bindings and entry point layers for ANGLE.
9
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
10
11
import sys, os, pprint, json
12
import registry_xml
13
from registry_xml import apis, script_relative, strip_api_prefix
14
15
# Paths
16
CL_STUBS_HEADER_PATH = "../src/libGLESv2/cl_stubs_autogen.h"
17
EGL_GET_LABELED_OBJECT_DATA_PATH = "../src/libGLESv2/egl_get_labeled_object_data.json"
18
EGL_STUBS_HEADER_PATH = "../src/libGLESv2/egl_stubs_autogen.h"
19
EGL_EXT_STUBS_HEADER_PATH = "../src/libGLESv2/egl_ext_stubs_autogen.h"
20
21
# List of GLES1 extensions for which we don't need to add Context.h decls.
22
GLES1_NO_CONTEXT_DECL_EXTENSIONS = [
23
"GL_OES_framebuffer_object",
24
]
25
26
# This is a list of exceptions for entry points which don't want to have
27
# the EVENT macro. This is required for some debug marker entry points.
28
NO_EVENT_MARKER_EXCEPTIONS_LIST = sorted([
29
"glPushGroupMarkerEXT",
30
"glPopGroupMarkerEXT",
31
"glInsertEventMarkerEXT",
32
])
33
34
# glRenderbufferStorageMultisampleEXT aliases glRenderbufferStorageMultisample on desktop GL, and is
35
# marked as such in the registry. However, that is not correct for GLES where this entry point
36
# comes from GL_EXT_multisampled_render_to_texture which is never promoted to core GLES.
37
ALIASING_EXCEPTIONS = [
38
'glRenderbufferStorageMultisampleEXT',
39
'renderbufferStorageMultisampleEXT',
40
]
41
42
# These are the entry points which potentially are used first by an application
43
# and require that the back ends are initialized before the front end is called.
44
INIT_DICT = {
45
"clGetPlatformIDs": "false",
46
"clGetPlatformInfo": "false",
47
"clGetDeviceIDs": "false",
48
"clCreateContext": "false",
49
"clCreateContextFromType": "false",
50
"clIcdGetPlatformIDsKHR": "true",
51
}
52
53
# Strip these suffixes from Context entry point names. NV is excluded (for now).
54
STRIP_SUFFIXES = ["ANDROID", "ANGLE", "EXT", "KHR", "OES", "CHROMIUM", "OVR"]
55
56
TEMPLATE_ENTRY_POINT_HEADER = """\
57
// GENERATED FILE - DO NOT EDIT.
58
// Generated by {script_name} using data from {data_source_name}.
59
//
60
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
61
// Use of this source code is governed by a BSD-style license that can be
62
// found in the LICENSE file.
63
//
64
// entry_points_{annotation_lower}_autogen.h:
65
// Defines the {comment} entry points.
66
67
#ifndef {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_
68
#define {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_
69
70
{includes}
71
72
{entry_points}
73
74
#endif // {lib}_ENTRY_POINTS_{annotation_upper}_AUTOGEN_H_
75
"""
76
77
TEMPLATE_ENTRY_POINT_SOURCE = """\
78
// GENERATED FILE - DO NOT EDIT.
79
// Generated by {script_name} using data from {data_source_name}.
80
//
81
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
82
// Use of this source code is governed by a BSD-style license that can be
83
// found in the LICENSE file.
84
//
85
// entry_points_{annotation_lower}_autogen.cpp:
86
// Defines the {comment} entry points.
87
88
{includes}
89
90
{entry_points}
91
"""
92
93
TEMPLATE_ENTRY_POINTS_ENUM_HEADER = """\
94
// GENERATED FILE - DO NOT EDIT.
95
// Generated by {script_name} using data from {data_source_name}.
96
//
97
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
98
// Use of this source code is governed by a BSD-style license that can be
99
// found in the LICENSE file.
100
//
101
// entry_points_enum_autogen.h:
102
// Defines the {lib} entry points enumeration.
103
104
#ifndef COMMON_ENTRYPOINTSENUM_AUTOGEN_H_
105
#define COMMON_ENTRYPOINTSENUM_AUTOGEN_H_
106
107
namespace angle
108
{{
109
enum class EntryPoint
110
{{
111
{entry_points_list}
112
}};
113
114
const char *GetEntryPointName(EntryPoint ep);
115
}} // namespace angle
116
#endif // COMMON_ENTRY_POINTS_ENUM_AUTOGEN_H_
117
"""
118
119
TEMPLATE_ENTRY_POINTS_NAME_CASE = """\
120
case EntryPoint::{enum}:
121
return "{cmd}";"""
122
123
TEMPLATE_ENTRY_POINTS_ENUM_SOURCE = """\
124
// GENERATED FILE - DO NOT EDIT.
125
// Generated by {script_name} using data from {data_source_name}.
126
//
127
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
128
// Use of this source code is governed by a BSD-style license that can be
129
// found in the LICENSE file.
130
//
131
// entry_points_enum_autogen.cpp:
132
// Helper methods for the {lib} entry points enumeration.
133
134
#include "common/entry_points_enum_autogen.h"
135
136
#include "common/debug.h"
137
138
namespace angle
139
{{
140
const char *GetEntryPointName(EntryPoint ep)
141
{{
142
switch (ep)
143
{{
144
{entry_points_name_cases}
145
default:
146
UNREACHABLE();
147
return "error";
148
}}
149
}}
150
}} // namespace angle
151
"""
152
153
TEMPLATE_LIB_ENTRY_POINT_SOURCE = """\
154
// GENERATED FILE - DO NOT EDIT.
155
// Generated by {script_name} using data from {data_source_name}.
156
//
157
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
158
// Use of this source code is governed by a BSD-style license that can be
159
// found in the LICENSE file.
160
//
161
// {lib_name}_autogen.cpp: Implements the exported {lib_description} functions.
162
163
{includes}
164
extern "C" {{
165
{entry_points}
166
}} // extern "C"
167
"""
168
169
TEMPLATE_ENTRY_POINT_DECL = """{angle_export}{return_type} {export_def} {name}({params});"""
170
171
TEMPLATE_GLES_ENTRY_POINT_NO_RETURN = """\
172
void GL_APIENTRY GL_{name}({params})
173
{{
174
Context *context = {context_getter};
175
{event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params});
176
177
if ({valid_context_check})
178
{{{packed_gl_enum_conversions}
179
std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context);
180
bool isCallValid = (context->skipValidation() || Validate{name}({validate_params}));
181
if (isCallValid)
182
{{
183
context->{name_lower_no_suffix}({internal_params});
184
}}
185
ANGLE_CAPTURE({name}, isCallValid, {validate_params});
186
}}
187
else
188
{{
189
{constext_lost_error_generator}
190
}}
191
}}
192
"""
193
194
TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN = """\
195
{return_type} GL_APIENTRY GL_{name}({params})
196
{{
197
Context *context = {context_getter};
198
{event_comment}EVENT(context, GL{name}, "context = %d{comma_if_needed}{format_params}", CID(context){comma_if_needed}{pass_params});
199
200
{return_type} returnValue;
201
if ({valid_context_check})
202
{{{packed_gl_enum_conversions}
203
std::unique_lock<angle::GlobalMutex> shareContextLock = GetContextLock(context);
204
bool isCallValid = (context->skipValidation() || Validate{name}({validate_params}));
205
if (isCallValid)
206
{{
207
returnValue = context->{name_lower_no_suffix}({internal_params});
208
}}
209
else
210
{{
211
returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>();
212
}}
213
ANGLE_CAPTURE({name}, isCallValid, {validate_params}, returnValue);
214
}}
215
else
216
{{
217
{constext_lost_error_generator}
218
returnValue = GetDefaultReturnValue<angle::EntryPoint::GL{name}, {return_type}>();
219
}}
220
return returnValue;
221
}}
222
"""
223
224
TEMPLATE_EGL_ENTRY_POINT_NO_RETURN = """\
225
void EGLAPIENTRY EGL_{name}({params})
226
{{
227
ANGLE_SCOPED_GLOBAL_LOCK();
228
EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
229
230
Thread *thread = egl::GetCurrentThread();
231
232
{packed_gl_enum_conversions}
233
234
ANGLE_EGL_VALIDATE_VOID(thread, {name}, {labeled_object}, {internal_params});
235
236
{name}(thread{comma_if_needed}{internal_params});
237
}}
238
"""
239
240
TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN = """\
241
{return_type} EGLAPIENTRY EGL_{name}({params})
242
{{
243
ANGLE_SCOPED_GLOBAL_LOCK();
244
EGL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
245
246
Thread *thread = egl::GetCurrentThread();
247
248
{packed_gl_enum_conversions}
249
250
ANGLE_EGL_VALIDATE(thread, {name}, {labeled_object}, {return_type}{comma_if_needed}{internal_params});
251
252
return {name}(thread{comma_if_needed}{internal_params});
253
}}
254
"""
255
256
TEMPLATE_CL_ENTRY_POINT_NO_RETURN = """\
257
void CL_API_CALL cl{name}({params})
258
{{
259
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
260
261
{packed_gl_enum_conversions}
262
263
ANGLE_CL_VALIDATE_VOID({name}{comma_if_needed}{internal_params});
264
265
{name}({internal_params});
266
}}
267
"""
268
269
TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR = """\
270
cl_int CL_API_CALL cl{name}({params})
271
{{{initialization}
272
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
273
274
{packed_gl_enum_conversions}
275
276
ANGLE_CL_VALIDATE_ERROR({name}{comma_if_needed}{internal_params});
277
278
return {name}({internal_params});
279
}}
280
"""
281
282
TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET = """\
283
{return_type} CL_API_CALL cl{name}({params})
284
{{{initialization}
285
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
286
287
{packed_gl_enum_conversions}
288
289
ANGLE_CL_VALIDATE_ERRCODE_RET({name}{comma_if_needed}{internal_params});
290
291
cl_int errorCode = CL_SUCCESS;
292
{return_type} object = {name}({internal_params}, errorCode);
293
294
ASSERT((errorCode == CL_SUCCESS) == (object != nullptr));
295
if (errcode_ret != nullptr)
296
{{
297
*errcode_ret = errorCode;
298
}}
299
return object;
300
}}
301
"""
302
303
TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER = """\
304
{return_type} CL_API_CALL cl{name}({params})
305
{{{initialization}
306
CL_EVENT({name}, "{format_params}"{comma_if_needed}{pass_params});
307
308
{packed_gl_enum_conversions}
309
310
ANGLE_CL_VALIDATE_POINTER({name}{comma_if_needed}{internal_params});
311
312
return {name}({internal_params});
313
}}
314
"""
315
316
TEMPLATE_CL_STUBS_HEADER = """\
317
// GENERATED FILE - DO NOT EDIT.
318
// Generated by {script_name} using data from {data_source_name}.
319
//
320
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
321
// Use of this source code is governed by a BSD-style license that can be
322
// found in the LICENSE file.
323
//
324
// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points.
325
326
#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
327
#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
328
329
#include "libANGLE/CLtypes.h"
330
331
namespace cl
332
{{
333
{stubs}
334
}} // namespace cl
335
#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
336
"""
337
338
TEMPLATE_EGL_STUBS_HEADER = """\
339
// GENERATED FILE - DO NOT EDIT.
340
// Generated by {script_name} using data from {data_source_name}.
341
//
342
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
343
// Use of this source code is governed by a BSD-style license that can be
344
// found in the LICENSE file.
345
//
346
// {annotation_lower}_stubs_autogen.h: Stubs for {title} entry points.
347
348
#ifndef LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
349
#define LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
350
351
#include <EGL/egl.h>
352
#include <EGL/eglext.h>
353
354
#include "common/PackedEGLEnums_autogen.h"
355
356
namespace gl
357
{{
358
class Context;
359
}} // namespace gl
360
361
namespace egl
362
{{
363
class AttributeMap;
364
class Device;
365
class Display;
366
class Image;
367
class Stream;
368
class Surface;
369
class Sync;
370
class Thread;
371
struct Config;
372
373
{stubs}
374
}} // namespace egl
375
#endif // LIBGLESV2_{annotation_upper}_STUBS_AUTOGEN_H_
376
"""
377
378
CONTEXT_HEADER = """\
379
// GENERATED FILE - DO NOT EDIT.
380
// Generated by {script_name} using data from {data_source_name}.
381
//
382
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
383
// Use of this source code is governed by a BSD-style license that can be
384
// found in the LICENSE file.
385
//
386
// Context_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context.
387
388
#ifndef ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_
389
#define ANGLE_CONTEXT_{annotation_upper}_AUTOGEN_H_
390
391
#define ANGLE_{annotation_upper}_CONTEXT_API \\
392
{interface}
393
394
#endif // ANGLE_CONTEXT_API_{version}_AUTOGEN_H_
395
"""
396
397
CONTEXT_DECL_FORMAT = """ {return_type} {name_lower_no_suffix}({internal_params}){maybe_const}; \\"""
398
399
TEMPLATE_CL_ENTRY_POINT_EXPORT = """\
400
{return_type} CL_API_CALL cl{name}({params})
401
{{
402
return cl::GetDispatch().cl{name}({internal_params});
403
}}
404
"""
405
406
TEMPLATE_GL_ENTRY_POINT_EXPORT = """\
407
{return_type} GL_APIENTRY gl{name}({params})
408
{{
409
return GL_{name}({internal_params});
410
}}
411
"""
412
413
TEMPLATE_EGL_ENTRY_POINT_EXPORT = """\
414
{return_type} EGLAPIENTRY egl{name}({params})
415
{{
416
EnsureEGLLoaded();
417
return EGL_{name}({internal_params});
418
}}
419
"""
420
421
TEMPLATE_GLEXT_FUNCTION_POINTER = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}PROC)({params});"""
422
TEMPLATE_GLEXT_FUNCTION_PROTOTYPE = """{apicall} {return_type}GL_APIENTRY {name}({params});"""
423
424
TEMPLATE_GL_VALIDATION_HEADER = """\
425
// GENERATED FILE - DO NOT EDIT.
426
// Generated by {script_name} using data from {data_source_name}.
427
//
428
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
429
// Use of this source code is governed by a BSD-style license that can be
430
// found in the LICENSE file.
431
//
432
// validation{annotation}_autogen.h:
433
// Validation functions for the OpenGL {comment} entry points.
434
435
#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
436
#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
437
438
#include "common/PackedEnums.h"
439
440
namespace gl
441
{{
442
class Context;
443
444
{prototypes}
445
}} // namespace gl
446
447
#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
448
"""
449
450
TEMPLATE_CL_VALIDATION_HEADER = """\
451
// GENERATED FILE - DO NOT EDIT.
452
// Generated by {script_name} using data from {data_source_name}.
453
//
454
// Copyright 2021 The ANGLE Project Authors. All rights reserved.
455
// Use of this source code is governed by a BSD-style license that can be
456
// found in the LICENSE file.
457
//
458
// validation{annotation}_autogen.h:
459
// Validation functions for the {comment} entry points.
460
461
#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
462
#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
463
464
#include "libANGLE/validationCL.h"
465
466
namespace cl
467
{{
468
{prototypes}
469
}} // namespace cl
470
471
#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
472
"""
473
474
TEMPLATE_EGL_VALIDATION_HEADER = """\
475
// GENERATED FILE - DO NOT EDIT.
476
// Generated by {script_name} using data from {data_source_name}.
477
//
478
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
479
// Use of this source code is governed by a BSD-style license that can be
480
// found in the LICENSE file.
481
//
482
// validation{annotation}_autogen.h:
483
// Validation functions for the {comment} entry points.
484
485
#ifndef LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
486
#define LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
487
488
#include "libANGLE/validationEGL.h"
489
490
namespace egl
491
{{
492
{prototypes}
493
}} // namespace egl
494
495
#endif // LIBANGLE_VALIDATION_{annotation}_AUTOGEN_H_
496
"""
497
498
TEMPLATE_CAPTURE_HEADER = """\
499
// GENERATED FILE - DO NOT EDIT.
500
// Generated by {script_name} using data from {data_source_name}.
501
//
502
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
503
// Use of this source code is governed by a BSD-style license that can be
504
// found in the LICENSE file.
505
//
506
// capture_gles_{annotation_lower}_autogen.h:
507
// Capture functions for the OpenGL ES {comment} entry points.
508
509
#ifndef LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_
510
#define LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_
511
512
#include "common/PackedEnums.h"
513
#include "libANGLE/capture/FrameCapture.h"
514
515
namespace gl
516
{{
517
{prototypes}
518
}} // namespace gl
519
520
#endif // LIBANGLE_CAPTURE_GLES_{annotation_upper}_AUTOGEN_H_
521
"""
522
523
TEMPLATE_CAPTURE_SOURCE = """\
524
// GENERATED FILE - DO NOT EDIT.
525
// Generated by {script_name} using data from {data_source_name}.
526
//
527
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
528
// Use of this source code is governed by a BSD-style license that can be
529
// found in the LICENSE file.
530
//
531
// capture_gles_{annotation_with_dash}_autogen.cpp:
532
// Capture functions for the OpenGL ES {comment} entry points.
533
534
#include "libANGLE/capture/capture_gles_{annotation_with_dash}_autogen.h"
535
536
#include "libANGLE/Context.h"
537
#include "libANGLE/capture/FrameCapture.h"
538
#include "libANGLE/capture/gl_enum_utils.h"
539
#include "libANGLE/validation{annotation_no_dash}.h"
540
541
using namespace angle;
542
543
namespace gl
544
{{
545
{capture_methods}
546
}} // namespace gl
547
"""
548
549
TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE = """
550
CallCapture Capture{short_name}({params_with_type}, {return_value_type_original} returnValue)
551
{{
552
ParamBuffer paramBuffer;
553
554
{parameter_captures}
555
556
ParamCapture returnValueCapture("returnValue", ParamType::T{return_value_type_custom});
557
InitParamValue(ParamType::T{return_value_type_custom}, returnValue, &returnValueCapture.value);
558
paramBuffer.addReturnValue(std::move(returnValueCapture));
559
560
return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer));
561
}}
562
"""
563
564
TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE = """
565
CallCapture Capture{short_name}({params_with_type})
566
{{
567
ParamBuffer paramBuffer;
568
569
{parameter_captures}
570
571
return CallCapture(angle::EntryPoint::GL{short_name}, std::move(paramBuffer));
572
}}
573
"""
574
575
TEMPLATE_PARAMETER_CAPTURE_VALUE = """paramBuffer.addValueParam("{name}", ParamType::T{type}, {name});"""
576
577
TEMPLATE_PARAMETER_CAPTURE_GL_ENUM = """paramBuffer.addEnumParam("{name}", GLenumGroup::{group}, ParamType::T{type}, {name});"""
578
579
TEMPLATE_PARAMETER_CAPTURE_POINTER = """
580
if (isCallValid)
581
{{
582
ParamCapture {name}Param("{name}", ParamType::T{type});
583
InitParamValue(ParamType::T{type}, {name}, &{name}Param.value);
584
{capture_name}({params}, &{name}Param);
585
paramBuffer.addParam(std::move({name}Param));
586
}}
587
else
588
{{
589
ParamCapture {name}Param("{name}", ParamType::T{type});
590
InitParamValue(ParamType::T{type}, static_cast<{cast_type}>(nullptr), &{name}Param.value);
591
paramBuffer.addParam(std::move({name}Param));
592
}}
593
"""
594
595
TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC = """void {name}({params});"""
596
597
TEMPLATE_CAPTURE_REPLAY_SOURCE = """\
598
// GENERATED FILE - DO NOT EDIT.
599
// Generated by {script_name} using data from {data_source_name}.
600
//
601
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
602
// Use of this source code is governed by a BSD-style license that can be
603
// found in the LICENSE file.
604
//
605
// frame_capture_replay_autogen.cpp:
606
// Util function to dispatch captured GL calls through Context and replay them.
607
608
#include "angle_gl.h"
609
610
#include "common/debug.h"
611
#include "common/debug.h"
612
#include "libANGLE/Context.h"
613
#include "libANGLE/Context.inl.h"
614
#include "libANGLE/capture/FrameCapture.h"
615
616
using namespace gl;
617
618
namespace angle
619
{{
620
621
void FrameCaptureShared::ReplayCall(gl::Context *context,
622
ReplayContext *replayContext,
623
const CallCapture &call)
624
{{
625
const ParamBuffer &params = call.params;
626
switch (call.entryPoint)
627
{{
628
{call_replay_cases}
629
default:
630
UNREACHABLE();
631
}}
632
}}
633
634
}} // namespace angle
635
636
"""
637
638
TEMPLATE_CAPTURE_REPLAY_CALL_CASE = """case angle::EntryPoint::GL{entry_point}:
639
context->{context_call}({param_value_access});break;"""
640
641
POINTER_FORMAT = "0x%016\" PRIxPTR \""
642
UNSIGNED_LONG_LONG_FORMAT = "%llu"
643
HEX_LONG_LONG_FORMAT = "0x%llX"
644
645
FORMAT_DICT = {
646
"GLbitfield": "%s",
647
"GLboolean": "%s",
648
"GLbyte": "%d",
649
"GLclampx": "0x%X",
650
"GLDEBUGPROC": POINTER_FORMAT,
651
"GLDEBUGPROCKHR": POINTER_FORMAT,
652
"GLdouble": "%f",
653
"GLeglClientBufferEXT": POINTER_FORMAT,
654
"GLeglImageOES": POINTER_FORMAT,
655
"GLenum": "%s",
656
"GLfixed": "0x%X",
657
"GLfloat": "%f",
658
"GLint": "%d",
659
"GLintptr": UNSIGNED_LONG_LONG_FORMAT,
660
"GLshort": "%d",
661
"GLsizei": "%d",
662
"GLsizeiptr": UNSIGNED_LONG_LONG_FORMAT,
663
"GLsync": POINTER_FORMAT,
664
"GLubyte": "%d",
665
"GLuint": "%u",
666
"GLuint64": UNSIGNED_LONG_LONG_FORMAT,
667
"GLushort": "%u",
668
"int": "%d",
669
# EGL-specific types
670
"EGLConfig": POINTER_FORMAT,
671
"EGLContext": POINTER_FORMAT,
672
"EGLDisplay": POINTER_FORMAT,
673
"EGLSurface": POINTER_FORMAT,
674
"EGLSync": POINTER_FORMAT,
675
"EGLNativeDisplayType": POINTER_FORMAT,
676
"EGLNativePixmapType": POINTER_FORMAT,
677
"EGLNativeWindowType": POINTER_FORMAT,
678
"EGLClientBuffer": POINTER_FORMAT,
679
"EGLenum": "0x%X",
680
"EGLint": "%d",
681
"EGLImage": POINTER_FORMAT,
682
"EGLTime": UNSIGNED_LONG_LONG_FORMAT,
683
"EGLGetBlobFuncANDROID": POINTER_FORMAT,
684
"EGLSetBlobFuncANDROID": POINTER_FORMAT,
685
"EGLuint64KHR": UNSIGNED_LONG_LONG_FORMAT,
686
"EGLSyncKHR": POINTER_FORMAT,
687
"EGLnsecsANDROID": UNSIGNED_LONG_LONG_FORMAT,
688
"EGLDeviceEXT": POINTER_FORMAT,
689
"EGLDEBUGPROCKHR": POINTER_FORMAT,
690
"EGLObjectKHR": POINTER_FORMAT,
691
"EGLLabelKHR": POINTER_FORMAT,
692
"EGLTimeKHR": UNSIGNED_LONG_LONG_FORMAT,
693
"EGLImageKHR": POINTER_FORMAT,
694
"EGLStreamKHR": POINTER_FORMAT,
695
"EGLFrameTokenANGLE": HEX_LONG_LONG_FORMAT,
696
# WGL-specific types
697
"BOOL": "%u",
698
"DWORD": POINTER_FORMAT,
699
"FLOAT": "%f",
700
"HDC": POINTER_FORMAT,
701
"HENHMETAFILE": POINTER_FORMAT,
702
"HGLRC": POINTER_FORMAT,
703
"LPCSTR": POINTER_FORMAT,
704
"LPGLYPHMETRICSFLOAT": POINTER_FORMAT,
705
"UINT": "%u",
706
# CL-specific types
707
"size_t": "%zu",
708
"cl_char": "%hhd",
709
"cl_uchar": "%hhu",
710
"cl_short": "%hd",
711
"cl_ushort": "%hu",
712
"cl_int": "%d",
713
"cl_uint": "%u",
714
"cl_long": "%lld",
715
"cl_ulong": "%llu",
716
"cl_half": "%hu",
717
"cl_float": "%f",
718
"cl_double": "%f",
719
"cl_platform_id": POINTER_FORMAT,
720
"cl_device_id": POINTER_FORMAT,
721
"cl_context": POINTER_FORMAT,
722
"cl_command_queue": POINTER_FORMAT,
723
"cl_mem": POINTER_FORMAT,
724
"cl_program": POINTER_FORMAT,
725
"cl_kernel": POINTER_FORMAT,
726
"cl_event": POINTER_FORMAT,
727
"cl_sampler": POINTER_FORMAT,
728
"cl_bool": "%u",
729
"cl_bitfield": "%llu",
730
"cl_properties": "%llu",
731
"cl_device_type": "%llu",
732
"cl_platform_info": "%u",
733
"cl_device_info": "%u",
734
"cl_device_fp_config": "%llu",
735
"cl_device_mem_cache_type": "%u",
736
"cl_device_local_mem_type": "%u",
737
"cl_device_exec_capabilities": "%llu",
738
"cl_device_svm_capabilities": "%llu",
739
"cl_command_queue_properties": "%llu",
740
"cl_device_partition_property": "%zu",
741
"cl_device_affinity_domain": "%llu",
742
"cl_context_properties": "%zu",
743
"cl_context_info": "%u",
744
"cl_queue_properties": "%llu",
745
"cl_command_queue_info": "%u",
746
"cl_channel_order": "%u",
747
"cl_channel_type": "%u",
748
"cl_mem_flags": "%llu",
749
"cl_svm_mem_flags": "%llu",
750
"cl_mem_object_type": "%u",
751
"cl_mem_info": "%u",
752
"cl_mem_migration_flags": "%llu",
753
"cl_mem_properties": "%llu",
754
"cl_image_info": "%u",
755
"cl_buffer_create_type": "%u",
756
"cl_addressing_mode": "%u",
757
"cl_filter_mode": "%u",
758
"cl_sampler_info": "%u",
759
"cl_map_flags": "%llu",
760
"cl_pipe_properties": "%zu",
761
"cl_pipe_info": "%u",
762
"cl_program_info": "%u",
763
"cl_program_build_info": "%u",
764
"cl_program_binary_type": "%u",
765
"cl_build_status": "%d",
766
"cl_kernel_info": "%u",
767
"cl_kernel_arg_info": "%u",
768
"cl_kernel_arg_address_qualifier": "%u",
769
"cl_kernel_arg_access_qualifier": "%u",
770
"cl_kernel_arg_type_qualifier": "%llu",
771
"cl_kernel_work_group_info": "%u",
772
"cl_kernel_sub_group_info": "%u",
773
"cl_event_info": "%u",
774
"cl_command_type": "%u",
775
"cl_profiling_info": "%u",
776
"cl_sampler_properties": "%llu",
777
"cl_kernel_exec_info": "%u",
778
"cl_device_atomic_capabilities": "%llu",
779
"cl_khronos_vendor_id": "%u",
780
"cl_version": "%u",
781
"cl_device_device_enqueue_capabilities": "%llu",
782
}
783
784
TEMPLATE_HEADER_INCLUDES = """\
785
#include <GLES{major}/gl{major}{minor}.h>
786
#include <export.h>"""
787
788
TEMPLATE_SOURCES_INCLUDES = """\
789
#include "libGLESv2/entry_points_{header_version}_autogen.h"
790
791
#include "common/entry_points_enum_autogen.h"
792
#include "libANGLE/Context.h"
793
#include "libANGLE/Context.inl.h"
794
#include "libANGLE/capture/capture_{header_version}_autogen.h"
795
#include "libANGLE/capture/gl_enum_utils.h"
796
#include "libANGLE/validation{validation_header_version}.h"
797
#include "libANGLE/entry_points_utils.h"
798
#include "libGLESv2/global_state.h"
799
800
using namespace gl;
801
"""
802
803
GLES_EXT_HEADER_INCLUDES = TEMPLATE_HEADER_INCLUDES.format(
804
major="", minor="") + """
805
#include <GLES/glext.h>
806
#include <GLES2/gl2.h>
807
#include <GLES2/gl2ext.h>
808
#include <GLES3/gl32.h>
809
"""
810
811
GLES_EXT_SOURCE_INCLUDES = TEMPLATE_SOURCES_INCLUDES.format(
812
header_version="gles_ext", validation_header_version="ESEXT") + """
813
#include "libANGLE/capture/capture_gles_1_0_autogen.h"
814
#include "libANGLE/capture/capture_gles_2_0_autogen.h"
815
#include "libANGLE/capture/capture_gles_3_0_autogen.h"
816
#include "libANGLE/capture/capture_gles_3_1_autogen.h"
817
#include "libANGLE/capture/capture_gles_3_2_autogen.h"
818
#include "libANGLE/validationES1.h"
819
#include "libANGLE/validationES2.h"
820
#include "libANGLE/validationES3.h"
821
#include "libANGLE/validationES31.h"
822
#include "libANGLE/validationES32.h"
823
824
using namespace gl;
825
"""
826
827
DESKTOP_GL_HEADER_INCLUDES = """\
828
#include <export.h>
829
#include "angle_gl.h"
830
"""
831
832
TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES = """\
833
#include "libGL/entry_points_{}_autogen.h"
834
835
#include "libANGLE/Context.h"
836
#include "libANGLE/Context.inl.h"
837
#include "libANGLE/capture/gl_enum_utils.h"
838
#include "libANGLE/validationEGL.h"
839
#include "libANGLE/validationES.h"
840
#include "libANGLE/validationES1.h"
841
#include "libANGLE/validationES2.h"
842
#include "libANGLE/validationES3.h"
843
#include "libANGLE/validationES31.h"
844
#include "libANGLE/validationES32.h"
845
#include "libANGLE/validationESEXT.h"
846
#include "libANGLE/validationGL{}_autogen.h"
847
#include "libANGLE/entry_points_utils.h"
848
#include "libGLESv2/global_state.h"
849
850
using namespace gl;
851
"""
852
853
EGL_HEADER_INCLUDES = """\
854
#include <EGL/egl.h>
855
#include <export.h>
856
"""
857
858
EGL_SOURCE_INCLUDES = """\
859
#include "libGLESv2/entry_points_egl_autogen.h"
860
861
#include "libANGLE/entry_points_utils.h"
862
#include "libANGLE/validationEGL_autogen.h"
863
#include "libGLESv2/egl_stubs_autogen.h"
864
#include "libGLESv2/global_state.h"
865
866
using namespace egl;
867
"""
868
869
EGL_EXT_HEADER_INCLUDES = """\
870
#include <EGL/egl.h>
871
#include <EGL/eglext.h>
872
#include <export.h>
873
"""
874
875
EGL_EXT_SOURCE_INCLUDES = """\
876
#include "libGLESv2/entry_points_egl_ext_autogen.h"
877
878
#include "libANGLE/entry_points_utils.h"
879
#include "libANGLE/validationEGL_autogen.h"
880
#include "libGLESv2/egl_ext_stubs_autogen.h"
881
#include "libGLESv2/global_state.h"
882
883
using namespace egl;
884
"""
885
886
LIBCL_EXPORT_INCLUDES = """
887
#include "libOpenCL/dispatch.h"
888
"""
889
890
LIBGLESV2_EXPORT_INCLUDES = """
891
#include "angle_gl.h"
892
893
#include "libGLESv2/entry_points_gles_1_0_autogen.h"
894
#include "libGLESv2/entry_points_gles_2_0_autogen.h"
895
#include "libGLESv2/entry_points_gles_3_0_autogen.h"
896
#include "libGLESv2/entry_points_gles_3_1_autogen.h"
897
#include "libGLESv2/entry_points_gles_3_2_autogen.h"
898
#include "libGLESv2/entry_points_gles_ext_autogen.h"
899
900
#include "common/event_tracer.h"
901
"""
902
903
LIBGL_EXPORT_INCLUDES = """
904
#include "angle_gl.h"
905
906
#include "libGL/entry_points_gl_1_autogen.h"
907
#include "libGL/entry_points_gl_2_autogen.h"
908
#include "libGL/entry_points_gl_3_autogen.h"
909
#include "libGL/entry_points_gl_4_autogen.h"
910
911
#include "common/event_tracer.h"
912
"""
913
914
LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE = """
915
#include "anglebase/no_destructor.h"
916
#include "common/system_utils.h"
917
918
#include <memory>
919
920
#if defined(ANGLE_USE_EGL_LOADER)
921
# include "libEGL/egl_loader_autogen.h"
922
#else
923
# include "libGLESv2/entry_points_egl_autogen.h"
924
# include "libGLESv2/entry_points_egl_ext_autogen.h"
925
#endif // defined(ANGLE_USE_EGL_LOADER)
926
927
namespace
928
{
929
#if defined(ANGLE_USE_EGL_LOADER)
930
bool gLoaded = false;
931
932
std::unique_ptr<angle::Library> &EntryPointsLib()
933
{
934
static angle::base::NoDestructor<std::unique_ptr<angle::Library>> sEntryPointsLib;
935
return *sEntryPointsLib;
936
}
937
938
angle::GenericProc KHRONOS_APIENTRY GlobalLoad(const char *symbol)
939
{
940
return reinterpret_cast<angle::GenericProc>(EntryPointsLib()->getSymbol(symbol));
941
}
942
943
void EnsureEGLLoaded()
944
{
945
if (gLoaded)
946
{
947
return;
948
}
949
950
EntryPointsLib().reset(
951
angle::OpenSharedLibrary(ANGLE_GLESV2_LIBRARY_NAME, angle::SearchType::ModuleDir));
952
angle::LoadEGL_EGL(GlobalLoad);
953
if (!EGL_GetPlatformDisplay)
954
{
955
fprintf(stderr, "Error loading EGL entry points.\\n");
956
}
957
else
958
{
959
gLoaded = true;
960
}
961
}
962
#else
963
void EnsureEGLLoaded() {}
964
#endif // defined(ANGLE_USE_EGL_LOADER)
965
} // anonymous namespace
966
"""
967
968
LIBCL_HEADER_INCLUDES = """\
969
#include "angle_cl.h"
970
"""
971
972
LIBCL_SOURCE_INCLUDES = """\
973
#include "libGLESv2/entry_points_cl_autogen.h"
974
975
#include "libANGLE/validationCL_autogen.h"
976
#include "libGLESv2/cl_stubs_autogen.h"
977
#include "libGLESv2/entry_points_cl_utils.h"
978
"""
979
980
TEMPLATE_EVENT_COMMENT = """\
981
// Don't run the EVENT() macro on the EXT_debug_marker entry points.
982
// It can interfere with the debug events being set by the caller.
983
// """
984
985
TEMPLATE_CAPTURE_PROTO = "angle::CallCapture Capture%s(%s);"
986
987
TEMPLATE_VALIDATION_PROTO = "%s Validate%s(%s);"
988
989
TEMPLATE_WINDOWS_DEF_FILE = """\
990
; GENERATED FILE - DO NOT EDIT.
991
; Generated by {script_name} using data from {data_source_name}.
992
;
993
; Copyright 2020 The ANGLE Project Authors. All rights reserved.
994
; Use of this source code is governed by a BSD-style license that can be
995
; found in the LICENSE file.
996
LIBRARY {lib}
997
EXPORTS
998
{exports}
999
"""
1000
1001
TEMPLATE_FRAME_CAPTURE_UTILS_HEADER = """\
1002
// GENERATED FILE - DO NOT EDIT.
1003
// Generated by {script_name} using data from {data_source_name}.
1004
//
1005
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
1006
// Use of this source code is governed by a BSD-style license that can be
1007
// found in the LICENSE file.
1008
//
1009
// frame_capture_utils_autogen.h:
1010
// ANGLE Frame capture types and helper functions.
1011
1012
#ifndef LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_
1013
#define LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_
1014
1015
#include "common/PackedEnums.h"
1016
1017
namespace angle
1018
{{
1019
enum class ParamType
1020
{{
1021
{param_types}
1022
}};
1023
1024
constexpr uint32_t kParamTypeCount = {param_type_count};
1025
1026
union ParamValue
1027
{{
1028
{param_union_values}
1029
}};
1030
1031
template <ParamType PType, typename T>
1032
T GetParamVal(const ParamValue &value);
1033
1034
{get_param_val_specializations}
1035
1036
template <ParamType PType, typename T>
1037
T GetParamVal(const ParamValue &value)
1038
{{
1039
UNREACHABLE();
1040
return T();
1041
}}
1042
1043
template <typename T>
1044
T AccessParamValue(ParamType paramType, const ParamValue &value)
1045
{{
1046
switch (paramType)
1047
{{
1048
{access_param_value_cases}
1049
}}
1050
}}
1051
1052
template <ParamType PType, typename T>
1053
void SetParamVal(T valueIn, ParamValue *valueOut);
1054
1055
{set_param_val_specializations}
1056
1057
template <ParamType PType, typename T>
1058
void SetParamVal(T valueIn, ParamValue *valueOut)
1059
{{
1060
UNREACHABLE();
1061
}}
1062
1063
template <typename T>
1064
void InitParamValue(ParamType paramType, T valueIn, ParamValue *valueOut)
1065
{{
1066
switch (paramType)
1067
{{
1068
{init_param_value_cases}
1069
}}
1070
}}
1071
1072
struct CallCapture;
1073
struct ParamCapture;
1074
1075
void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture &param);
1076
const char *ParamTypeToString(ParamType paramType);
1077
1078
enum class ResourceIDType
1079
{{
1080
{resource_id_types}
1081
}};
1082
1083
ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType);
1084
const char *GetResourceIDTypeName(ResourceIDType resourceIDType);
1085
1086
template <typename ResourceType>
1087
struct GetResourceIDTypeFromType;
1088
1089
{type_to_resource_id_type_structs}
1090
}} // namespace angle
1091
1092
#endif // LIBANGLE_FRAME_CAPTURE_UTILS_AUTOGEN_H_
1093
"""
1094
1095
TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE = """\
1096
// GENERATED FILE - DO NOT EDIT.
1097
// Generated by {script_name} using data from {data_source_name}.
1098
//
1099
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
1100
// Use of this source code is governed by a BSD-style license that can be
1101
// found in the LICENSE file.
1102
//
1103
// frame_capture_utils_autogen.cpp:
1104
// ANGLE Frame capture types and helper functions.
1105
1106
#include "libANGLE/capture/frame_capture_utils_autogen.h"
1107
1108
#include "libANGLE/capture/FrameCapture.h"
1109
1110
namespace angle
1111
{{
1112
void WriteParamCaptureReplay(std::ostream &os, const CallCapture &call, const ParamCapture &param)
1113
{{
1114
switch (param.type)
1115
{{
1116
{write_param_type_to_stream_cases}
1117
default:
1118
os << "unknown";
1119
break;
1120
}}
1121
}}
1122
1123
const char *ParamTypeToString(ParamType paramType)
1124
{{
1125
switch (paramType)
1126
{{
1127
{param_type_to_string_cases}
1128
default:
1129
UNREACHABLE();
1130
return "unknown";
1131
}}
1132
}}
1133
1134
ResourceIDType GetResourceIDTypeFromParamType(ParamType paramType)
1135
{{
1136
switch (paramType)
1137
{{
1138
{param_type_resource_id_cases}
1139
default:
1140
return ResourceIDType::InvalidEnum;
1141
}}
1142
}}
1143
1144
const char *GetResourceIDTypeName(ResourceIDType resourceIDType)
1145
{{
1146
switch (resourceIDType)
1147
{{
1148
{resource_id_type_name_cases}
1149
default:
1150
UNREACHABLE();
1151
return "GetResourceIDTypeName error";
1152
}}
1153
}}
1154
}} // namespace angle
1155
"""
1156
1157
TEMPLATE_GET_PARAM_VAL_SPECIALIZATION = """\
1158
template <>
1159
inline {type} GetParamVal<ParamType::T{enum}, {type}>(const ParamValue &value)
1160
{{
1161
return value.{union_name};
1162
}}"""
1163
1164
TEMPLATE_ACCESS_PARAM_VALUE_CASE = """\
1165
case ParamType::T{enum}:
1166
return GetParamVal<ParamType::T{enum}, T>(value);"""
1167
1168
TEMPLATE_SET_PARAM_VAL_SPECIALIZATION = """\
1169
template <>
1170
inline void SetParamVal<ParamType::T{enum}>({type} valueIn, ParamValue *valueOut)
1171
{{
1172
valueOut->{union_name} = valueIn;
1173
}}"""
1174
1175
TEMPLATE_INIT_PARAM_VALUE_CASE = """\
1176
case ParamType::T{enum}:
1177
SetParamVal<ParamType::T{enum}>(valueIn, valueOut);
1178
break;"""
1179
1180
TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE = """\
1181
case ParamType::T{enum_in}:
1182
WriteParamValueReplay<ParamType::T{enum_out}>(os, call, param.value.{union_name});
1183
break;"""
1184
1185
TEMPLATE_PARAM_TYPE_TO_STRING_CASE = """\
1186
case ParamType::T{enum}:
1187
return "{type}";"""
1188
1189
TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE = """\
1190
case ParamType::T{enum}:
1191
return ResourceIDType::{resource_id_type};"""
1192
1193
TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE = """\
1194
case ResourceIDType::{resource_id_type}:
1195
return "{resource_id_type}";"""
1196
1197
CL_PACKED_TYPES = {
1198
# Enums
1199
"cl_platform_info": "PlatformInfo",
1200
"cl_device_info": "DeviceInfo",
1201
"cl_context_info": "ContextInfo",
1202
"cl_command_queue_info": "CommandQueueInfo",
1203
"cl_mem_object_type": "MemObjectType",
1204
"cl_mem_info": "MemInfo",
1205
"cl_image_info": "ImageInfo",
1206
"cl_pipe_info": "PipeInfo",
1207
"cl_addressing_mode": "AddressingMode",
1208
"cl_filter_mode": "FilterMode",
1209
"cl_sampler_info": "SamplerInfo",
1210
"cl_program_info": "ProgramInfo",
1211
"cl_program_build_info": "ProgramBuildInfo",
1212
"cl_kernel_info": "KernelInfo",
1213
"cl_kernel_arg_info": "KernelArgInfo",
1214
"cl_kernel_work_group_info": "KernelWorkGroupInfo",
1215
"cl_kernel_sub_group_info": "KernelSubGroupInfo",
1216
"cl_kernel_exec_info": "KernelExecInfo",
1217
"cl_event_info": "EventInfo",
1218
"cl_profiling_info": "ProfilingInfo",
1219
# Bit fields
1220
"cl_device_type": "DeviceType",
1221
"cl_device_fp_config": "DeviceFpConfig",
1222
"cl_device_exec_capabilities": "DeviceExecCapabilities",
1223
"cl_device_svm_capabilities": "DeviceSvmCapabilities",
1224
"cl_command_queue_properties": "CommandQueueProperties",
1225
"cl_device_affinity_domain": "DeviceAffinityDomain",
1226
"cl_mem_flags": "MemFlags",
1227
"cl_svm_mem_flags": "SVM_MemFlags",
1228
"cl_mem_migration_flags": "MemMigrationFlags",
1229
"cl_map_flags": "MapFlags",
1230
"cl_kernel_arg_type_qualifier": "KernelArgTypeQualifier",
1231
"cl_device_atomic_capabilities": "DeviceAtomicCapabilities",
1232
"cl_device_device_enqueue_capabilities": "DeviceEnqueueCapabilities",
1233
}
1234
1235
EGL_PACKED_TYPES = {
1236
"EGLContext": "gl::Context *",
1237
"EGLConfig": "Config *",
1238
"EGLDeviceEXT": "Device *",
1239
# Needs an explicit namespace to avoid an X11 namespace collision.
1240
"EGLDisplay": "egl::Display *",
1241
"EGLImage": "Image *",
1242
"EGLImageKHR": "Image *",
1243
"EGLStreamKHR": "Stream *",
1244
"EGLSurface": "Surface *",
1245
"EGLSync": "Sync *",
1246
"EGLSyncKHR": "Sync *",
1247
}
1248
1249
1250
def is_aliasing_excepted(api, cmd_name):
1251
return api == apis.GLES and cmd_name in ALIASING_EXCEPTIONS
1252
1253
1254
def entry_point_export(api):
1255
if api == apis.CL:
1256
return ""
1257
return "ANGLE_EXPORT "
1258
1259
1260
def entry_point_prefix(api):
1261
if api == apis.CL:
1262
return "cl"
1263
if api == apis.GLES:
1264
return "GL_"
1265
return api + "_"
1266
1267
1268
def get_api_entry_def(api):
1269
if api == apis.EGL:
1270
return "EGLAPIENTRY"
1271
elif api == apis.CL:
1272
return "CL_API_CALL"
1273
else:
1274
return "GL_APIENTRY"
1275
1276
1277
def get_stubs_header_template(api):
1278
if api == apis.CL:
1279
return TEMPLATE_CL_STUBS_HEADER
1280
elif api == apis.EGL:
1281
return TEMPLATE_EGL_STUBS_HEADER
1282
else:
1283
return ""
1284
1285
1286
def format_entry_point_decl(api, cmd_name, proto, params):
1287
comma_if_needed = ", " if len(params) > 0 else ""
1288
stripped = strip_api_prefix(cmd_name)
1289
return TEMPLATE_ENTRY_POINT_DECL.format(
1290
angle_export=entry_point_export(api),
1291
export_def=get_api_entry_def(api),
1292
name="%s%s" % (entry_point_prefix(api), stripped),
1293
return_type=proto[:-len(cmd_name)].strip(),
1294
params=", ".join(params),
1295
comma_if_needed=comma_if_needed)
1296
1297
1298
# Returns index range of identifier in function parameter
1299
def find_name_range(param):
1300
1301
def is_allowed_in_identifier(char):
1302
return char.isalpha() or char.isdigit() or char == "_"
1303
1304
# If type is a function declaration, only search in first parentheses
1305
left_paren = param.find("(")
1306
if left_paren >= 0:
1307
min = left_paren + 1
1308
end = param.index(")")
1309
else:
1310
min = 0
1311
end = len(param)
1312
1313
# Find last identifier in search range
1314
while end > min and not is_allowed_in_identifier(param[end - 1]):
1315
end -= 1
1316
if end == min:
1317
raise ValueError
1318
start = end - 1
1319
while start > min and is_allowed_in_identifier(param[start - 1]):
1320
start -= 1
1321
return start, end
1322
1323
1324
def just_the_type(param):
1325
start, end = find_name_range(param)
1326
return param[:start].strip() + param[end:].strip()
1327
1328
1329
def just_the_name(param):
1330
start, end = find_name_range(param)
1331
return param[start:end]
1332
1333
1334
def make_param(param_type, param_name):
1335
1336
def insert_name(param_type, param_name, pos):
1337
return param_type[:pos] + " " + param_name + param_type[pos:]
1338
1339
# If type is a function declaration, insert identifier before first closing parentheses
1340
left_paren = param_type.find("(")
1341
if left_paren >= 0:
1342
right_paren = param_type.index(")")
1343
return insert_name(param_type, param_name, right_paren)
1344
1345
# If type is an array declaration, insert identifier before brackets
1346
brackets = param_type.find("[")
1347
if brackets >= 0:
1348
return insert_name(param_type, param_name, brackets)
1349
1350
# Otherwise just append identifier
1351
return param_type + " " + param_name
1352
1353
1354
def just_the_type_packed(param, entry):
1355
name = just_the_name(param)
1356
if name in entry:
1357
return entry[name]
1358
else:
1359
return just_the_type(param)
1360
1361
1362
def just_the_name_packed(param, reserved_set):
1363
name = just_the_name(param)
1364
if name in reserved_set:
1365
return name + 'Packed'
1366
else:
1367
return name
1368
1369
1370
def is_unsigned_long_format(fmt):
1371
return fmt == UNSIGNED_LONG_LONG_FORMAT or fmt == HEX_LONG_LONG_FORMAT
1372
1373
1374
def param_print_argument(command_node, param):
1375
name_only = just_the_name(param)
1376
type_only = just_the_type(param)
1377
1378
if "*" not in param and type_only not in FORMAT_DICT:
1379
print(" ".join(param))
1380
raise Exception("Missing '%s %s' from '%s' entry point" %
1381
(type_only, name_only, registry_xml.get_cmd_name(command_node)))
1382
1383
if "*" in param or FORMAT_DICT[type_only] == POINTER_FORMAT:
1384
return "(uintptr_t)%s" % name_only
1385
1386
if is_unsigned_long_format(FORMAT_DICT[type_only]):
1387
return "static_cast<unsigned long long>(%s)" % name_only
1388
1389
if type_only == "GLboolean":
1390
return "GLbooleanToString(%s)" % name_only
1391
1392
if type_only == "GLbitfield":
1393
group_name = find_gl_enum_group_in_command(command_node, name_only)
1394
return "GLbitfieldToString(GLenumGroup::%s, %s).c_str()" % (group_name, name_only)
1395
1396
if type_only == "GLenum":
1397
group_name = find_gl_enum_group_in_command(command_node, name_only)
1398
return "GLenumToString(GLenumGroup::%s, %s)" % (group_name, name_only)
1399
1400
return name_only
1401
1402
1403
def param_format_string(param):
1404
if "*" in param:
1405
return just_the_name(param) + " = 0x%016\" PRIxPTR \""
1406
else:
1407
type_only = just_the_type(param)
1408
if type_only not in FORMAT_DICT:
1409
raise Exception(type_only + " is not a known type in 'FORMAT_DICT'")
1410
1411
return just_the_name(param) + " = " + FORMAT_DICT[type_only]
1412
1413
1414
def is_context_lost_acceptable_cmd(cmd_name):
1415
lost_context_acceptable_cmds = [
1416
"glGetError",
1417
"glGetSync",
1418
"glGetQueryObjecti",
1419
"glGetProgramiv",
1420
"glGetGraphicsResetStatus",
1421
"glGetShaderiv",
1422
]
1423
1424
for context_lost_entry_pont in lost_context_acceptable_cmds:
1425
if cmd_name.startswith(context_lost_entry_pont):
1426
return True
1427
return False
1428
1429
1430
def get_context_getter_function(cmd_name):
1431
if is_context_lost_acceptable_cmd(cmd_name):
1432
return "GetGlobalContext()"
1433
1434
return "GetValidGlobalContext()"
1435
1436
1437
def get_valid_context_check(cmd_name):
1438
return "context"
1439
1440
1441
def get_constext_lost_error_generator(cmd_name):
1442
# Don't generate context lost errors on commands that accept lost contexts
1443
if is_context_lost_acceptable_cmd(cmd_name):
1444
return ""
1445
1446
return "GenerateContextLostErrorOnCurrentGlobalContext();"
1447
1448
1449
def strip_suffix(api, name):
1450
# For commands where aliasing is excepted, keep the suffix
1451
if is_aliasing_excepted(api, name):
1452
return name
1453
1454
for suffix in STRIP_SUFFIXES:
1455
if name.endswith(suffix):
1456
name = name[0:-len(suffix)]
1457
return name
1458
1459
1460
def find_gl_enum_group_in_command(command_node, param_name):
1461
group_name = None
1462
for param_node in command_node.findall('./param'):
1463
if param_node.find('./name').text == param_name:
1464
group_name = param_node.attrib.get('group', None)
1465
break
1466
1467
if group_name is None or group_name in registry_xml.unsupported_enum_group_names:
1468
group_name = registry_xml.default_enum_group_name
1469
1470
return group_name
1471
1472
1473
def get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types, params):
1474
# Always strip the suffix when querying packed enums.
1475
result = cmd_packed_gl_enums.get(strip_suffix(api, cmd_name), {})
1476
for param in params:
1477
param_type = just_the_type(param)
1478
if param_type in packed_param_types:
1479
result[just_the_name(param)] = packed_param_types[param_type]
1480
return result
1481
1482
1483
def get_def_template(api, return_type, has_errcode_ret):
1484
if return_type == "void":
1485
if api == apis.EGL:
1486
return TEMPLATE_EGL_ENTRY_POINT_NO_RETURN
1487
elif api == apis.CL:
1488
return TEMPLATE_CL_ENTRY_POINT_NO_RETURN
1489
else:
1490
return TEMPLATE_GLES_ENTRY_POINT_NO_RETURN
1491
elif return_type == "cl_int":
1492
return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_ERROR
1493
else:
1494
if api == apis.EGL:
1495
return TEMPLATE_EGL_ENTRY_POINT_WITH_RETURN
1496
elif api == apis.CL:
1497
if has_errcode_ret:
1498
return TEMPLATE_CL_ENTRY_POINT_WITH_ERRCODE_RET
1499
else:
1500
return TEMPLATE_CL_ENTRY_POINT_WITH_RETURN_POINTER
1501
else:
1502
return TEMPLATE_GLES_ENTRY_POINT_WITH_RETURN
1503
1504
1505
def format_entry_point_def(api, command_node, cmd_name, proto, params, cmd_packed_enums,
1506
packed_param_types, ep_to_object):
1507
packed_enums = get_packed_enums(api, cmd_packed_enums, cmd_name, packed_param_types, params)
1508
internal_params = [just_the_name_packed(param, packed_enums) for param in params]
1509
if internal_params and internal_params[-1] == "errcode_ret":
1510
internal_params.pop()
1511
has_errcode_ret = True
1512
else:
1513
has_errcode_ret = False
1514
packed_gl_enum_conversions = []
1515
for param in params:
1516
name = just_the_name(param)
1517
if name in packed_enums:
1518
internal_name = name + "Packed"
1519
internal_type = packed_enums[name]
1520
packed_gl_enum_conversions += [
1521
"\n " + internal_type + " " + internal_name + " = PackParam<" +
1522
internal_type + ">(" + name + ");"
1523
]
1524
1525
pass_params = [param_print_argument(command_node, param) for param in params]
1526
format_params = [param_format_string(param) for param in params]
1527
return_type = proto[:-len(cmd_name)].strip()
1528
initialization = "InitBackEnds(%s);\n" % INIT_DICT[cmd_name] if cmd_name in INIT_DICT else ""
1529
event_comment = TEMPLATE_EVENT_COMMENT if cmd_name in NO_EVENT_MARKER_EXCEPTIONS_LIST else ""
1530
name_lower_no_suffix = strip_suffix(api, cmd_name[2:3].lower() + cmd_name[3:])
1531
1532
format_params = {
1533
"name":
1534
strip_api_prefix(cmd_name),
1535
"name_lower_no_suffix":
1536
name_lower_no_suffix,
1537
"return_type":
1538
return_type,
1539
"params":
1540
", ".join(params),
1541
"internal_params":
1542
", ".join(internal_params),
1543
"initialization":
1544
initialization,
1545
"packed_gl_enum_conversions":
1546
"".join(packed_gl_enum_conversions),
1547
"pass_params":
1548
", ".join(pass_params),
1549
"comma_if_needed":
1550
", " if len(params) > 0 else "",
1551
"validate_params":
1552
", ".join(["context"] + internal_params),
1553
"format_params":
1554
", ".join(format_params),
1555
"context_getter":
1556
get_context_getter_function(cmd_name),
1557
"valid_context_check":
1558
get_valid_context_check(cmd_name),
1559
"constext_lost_error_generator":
1560
get_constext_lost_error_generator(cmd_name),
1561
"event_comment":
1562
event_comment,
1563
"labeled_object":
1564
get_egl_entry_point_labeled_object(ep_to_object, cmd_name, params, packed_enums)
1565
}
1566
1567
template = get_def_template(api, return_type, has_errcode_ret)
1568
return template.format(**format_params)
1569
1570
1571
def get_capture_param_type_name(param_type):
1572
pointer_count = param_type.count("*")
1573
is_const = "const" in param_type.split()
1574
1575
# EGL types are special
1576
for egl_type, angle_type in EGL_PACKED_TYPES.items():
1577
if angle_type == param_type:
1578
return egl_type
1579
1580
param_type = param_type.replace("*", "")
1581
param_type = param_type.replace("&", "")
1582
param_type = param_type.replace("const", "")
1583
param_type = param_type.replace("struct", "")
1584
param_type = param_type.strip()
1585
1586
if "EGL" not in param_type:
1587
if is_const and param_type != 'AttributeMap':
1588
param_type += "Const"
1589
for x in range(pointer_count):
1590
param_type += "Pointer"
1591
1592
return param_type
1593
1594
1595
def format_capture_method(api, command, cmd_name, proto, params, all_param_types,
1596
capture_pointer_funcs, cmd_packed_gl_enums, packed_param_types):
1597
1598
packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,
1599
params)
1600
1601
params_with_type = get_internal_params(api, cmd_name,
1602
["const State &glState", "bool isCallValid"] + params,
1603
cmd_packed_gl_enums, packed_param_types)
1604
params_just_name = ", ".join(
1605
["glState", "isCallValid"] +
1606
[just_the_name_packed(param, packed_gl_enums) for param in params])
1607
1608
parameter_captures = []
1609
for param in params:
1610
1611
param_name = just_the_name_packed(param, packed_gl_enums)
1612
param_type = just_the_type_packed(param, packed_gl_enums).strip()
1613
1614
# TODO(http://anglebug.com/4035: Add support for egl::AttributeMap.
1615
if 'AttributeMap' in param_type:
1616
# egl::AttributeMap is too complex for ParamCapture to handle it.
1617
continue
1618
1619
pointer_count = param_type.count("*")
1620
capture_param_type = get_capture_param_type_name(param_type)
1621
1622
if pointer_count > 0:
1623
params = params_just_name
1624
capture_name = "Capture%s_%s" % (strip_api_prefix(cmd_name), param_name)
1625
capture = TEMPLATE_PARAMETER_CAPTURE_POINTER.format(
1626
name=param_name,
1627
type=capture_param_type,
1628
capture_name=capture_name,
1629
params=params,
1630
cast_type=param_type)
1631
1632
capture_pointer_func = TEMPLATE_PARAMETER_CAPTURE_POINTER_FUNC.format(
1633
name=capture_name, params=params_with_type + ", angle::ParamCapture *paramCapture")
1634
capture_pointer_funcs += [capture_pointer_func]
1635
elif capture_param_type in ('GLenum', 'GLbitfield'):
1636
gl_enum_group = find_gl_enum_group_in_command(command, param_name)
1637
capture = TEMPLATE_PARAMETER_CAPTURE_GL_ENUM.format(
1638
name=param_name, type=capture_param_type, group=gl_enum_group)
1639
else:
1640
capture = TEMPLATE_PARAMETER_CAPTURE_VALUE.format(
1641
name=param_name, type=capture_param_type)
1642
1643
all_param_types.add(capture_param_type)
1644
1645
parameter_captures += [capture]
1646
1647
return_type = proto[:-len(cmd_name)].strip()
1648
1649
format_args = {
1650
"full_name": cmd_name,
1651
"short_name": strip_api_prefix(cmd_name),
1652
"params_with_type": params_with_type,
1653
"params_just_name": params_just_name,
1654
"parameter_captures": "\n ".join(parameter_captures),
1655
"return_value_type_original": return_type,
1656
"return_value_type_custom": get_capture_param_type_name(return_type)
1657
}
1658
1659
if return_type == "void":
1660
return TEMPLATE_CAPTURE_METHOD_NO_RETURN_VALUE.format(**format_args)
1661
else:
1662
return TEMPLATE_CAPTURE_METHOD_WITH_RETURN_VALUE.format(**format_args)
1663
1664
1665
def const_pointer_type(param, packed_gl_enums):
1666
type = just_the_type_packed(param, packed_gl_enums)
1667
if just_the_name(param) == "errcode_ret" or "(" in type:
1668
return type
1669
elif "**" in type and "const" not in type:
1670
return type.replace("**", "* const *")
1671
elif "*" in type and "const" not in type:
1672
return type.replace("*", "*const ") if "[]" in type else "const " + type
1673
else:
1674
return type
1675
1676
1677
def get_internal_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types):
1678
packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,
1679
params)
1680
return ", ".join([
1681
make_param(
1682
just_the_type_packed(param, packed_gl_enums),
1683
just_the_name_packed(param, packed_gl_enums)) for param in params
1684
])
1685
1686
1687
def get_validation_params(api, cmd_name, params, cmd_packed_gl_enums, packed_param_types):
1688
packed_gl_enums = get_packed_enums(api, cmd_packed_gl_enums, cmd_name, packed_param_types,
1689
params)
1690
last = -1 if params and just_the_name(params[-1]) == "errcode_ret" else None
1691
return ", ".join([
1692
make_param(
1693
const_pointer_type(param, packed_gl_enums),
1694
just_the_name_packed(param, packed_gl_enums)) for param in params[:last]
1695
])
1696
1697
1698
def format_context_decl(api, cmd_name, proto, params, template, cmd_packed_gl_enums,
1699
packed_param_types):
1700
internal_params = get_internal_params(api, cmd_name, params, cmd_packed_gl_enums,
1701
packed_param_types)
1702
1703
return_type = proto[:-len(cmd_name)].strip()
1704
name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
1705
name_lower_no_suffix = strip_suffix(api, name_lower_no_suffix)
1706
maybe_const = " const" if name_lower_no_suffix.startswith(
1707
"is") and name_lower_no_suffix[2].isupper() else ""
1708
1709
return template.format(
1710
return_type=return_type,
1711
name_lower_no_suffix=name_lower_no_suffix,
1712
internal_params=internal_params,
1713
maybe_const=maybe_const)
1714
1715
1716
def format_entry_point_export(cmd_name, proto, params, template):
1717
internal_params = [just_the_name(param) for param in params]
1718
return_type = proto[:-len(cmd_name)].strip()
1719
1720
return template.format(
1721
name=strip_api_prefix(cmd_name),
1722
return_type=return_type,
1723
params=", ".join(params),
1724
internal_params=", ".join(internal_params))
1725
1726
1727
def format_validation_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types):
1728
if api == apis.CL:
1729
return_type = "cl_int"
1730
else:
1731
return_type = "bool"
1732
if api in [apis.GL, apis.GLES]:
1733
with_extra_params = ["Context *context"] + params
1734
elif api == apis.EGL:
1735
with_extra_params = ["ValidationContext *val"] + params
1736
else:
1737
with_extra_params = params
1738
internal_params = get_validation_params(api, cmd_name, with_extra_params, cmd_packed_gl_enums,
1739
packed_param_types)
1740
return TEMPLATE_VALIDATION_PROTO % (return_type, strip_api_prefix(cmd_name), internal_params)
1741
1742
1743
def format_capture_proto(api, cmd_name, proto, params, cmd_packed_gl_enums, packed_param_types):
1744
internal_params = get_internal_params(api, cmd_name,
1745
["const State &glState", "bool isCallValid"] + params,
1746
cmd_packed_gl_enums, packed_param_types)
1747
return_type = proto[:-len(cmd_name)].strip()
1748
if return_type != "void":
1749
internal_params += ", %s returnValue" % return_type
1750
return TEMPLATE_CAPTURE_PROTO % (strip_api_prefix(cmd_name), internal_params)
1751
1752
1753
def path_to(folder, file):
1754
return os.path.join(script_relative(".."), "src", folder, file)
1755
1756
1757
class ANGLEEntryPoints(registry_xml.EntryPoints):
1758
1759
def __init__(self,
1760
api,
1761
xml,
1762
commands,
1763
all_param_types,
1764
cmd_packed_enums,
1765
export_template=TEMPLATE_GL_ENTRY_POINT_EXPORT,
1766
packed_param_types=[],
1767
ep_to_object={}):
1768
super().__init__(api, xml, commands)
1769
1770
self.decls = []
1771
self.defs = []
1772
self.export_defs = []
1773
self.validation_protos = []
1774
self.capture_protos = []
1775
self.capture_methods = []
1776
self.capture_pointer_funcs = []
1777
1778
for (cmd_name, command_node, param_text, proto_text) in self.get_infos():
1779
self.decls.append(format_entry_point_decl(self.api, cmd_name, proto_text, param_text))
1780
self.defs.append(
1781
format_entry_point_def(self.api, command_node, cmd_name, proto_text, param_text,
1782
cmd_packed_enums, packed_param_types, ep_to_object))
1783
1784
self.export_defs.append(
1785
format_entry_point_export(cmd_name, proto_text, param_text, export_template))
1786
1787
self.validation_protos.append(
1788
format_validation_proto(self.api, cmd_name, proto_text, param_text,
1789
cmd_packed_enums, packed_param_types))
1790
self.capture_protos.append(
1791
format_capture_proto(self.api, cmd_name, proto_text, param_text, cmd_packed_enums,
1792
packed_param_types))
1793
self.capture_methods.append(
1794
format_capture_method(self.api, command_node, cmd_name, proto_text, param_text,
1795
all_param_types, self.capture_pointer_funcs,
1796
cmd_packed_enums, packed_param_types))
1797
1798
1799
class GLEntryPoints(ANGLEEntryPoints):
1800
1801
all_param_types = set()
1802
1803
def __init__(self, api, xml, commands):
1804
super().__init__(api, xml, commands, GLEntryPoints.all_param_types,
1805
GLEntryPoints.get_packed_enums())
1806
1807
_packed_enums = None
1808
1809
@classmethod
1810
def get_packed_enums(cls):
1811
if not cls._packed_enums:
1812
with open(script_relative('entry_point_packed_gl_enums.json')) as f:
1813
cls._packed_enums = json.loads(f.read())
1814
return cls._packed_enums
1815
1816
1817
class EGLEntryPoints(ANGLEEntryPoints):
1818
1819
all_param_types = set()
1820
1821
def __init__(self, xml, commands):
1822
super().__init__(
1823
apis.EGL,
1824
xml,
1825
commands,
1826
EGLEntryPoints.all_param_types,
1827
EGLEntryPoints.get_packed_enums(),
1828
export_template=TEMPLATE_EGL_ENTRY_POINT_EXPORT,
1829
packed_param_types=EGL_PACKED_TYPES,
1830
ep_to_object=EGLEntryPoints._get_ep_to_object())
1831
1832
_ep_to_object = None
1833
1834
@classmethod
1835
def _get_ep_to_object(cls):
1836
1837
if cls._ep_to_object:
1838
return cls._ep_to_object
1839
1840
with open(EGL_GET_LABELED_OBJECT_DATA_PATH) as f:
1841
try:
1842
spec_json = json.loads(f.read())
1843
except ValueError:
1844
raise Exception("Could not decode JSON from %s" % EGL_GET_LABELED_OBJECT_DATA_PATH)
1845
1846
# Construct a mapping from EP to type. Fill in the gaps with Display/None.
1847
cls._ep_to_object = {}
1848
1849
for category, eps in spec_json.items():
1850
if category == 'description':
1851
continue
1852
for ep in eps:
1853
cls._ep_to_object[ep] = category
1854
1855
return cls._ep_to_object
1856
1857
_packed_enums = None
1858
1859
@classmethod
1860
def get_packed_enums(cls):
1861
if not cls._packed_enums:
1862
with open(script_relative('entry_point_packed_egl_enums.json')) as f:
1863
cls._packed_enums = json.loads(f.read())
1864
return cls._packed_enums
1865
1866
1867
class CLEntryPoints(ANGLEEntryPoints):
1868
1869
all_param_types = set()
1870
1871
def __init__(self, xml, commands):
1872
super().__init__(
1873
apis.CL,
1874
xml,
1875
commands,
1876
CLEntryPoints.all_param_types,
1877
CLEntryPoints.get_packed_enums(),
1878
export_template=TEMPLATE_CL_ENTRY_POINT_EXPORT,
1879
packed_param_types=CL_PACKED_TYPES)
1880
1881
@classmethod
1882
def get_packed_enums(cls):
1883
return {}
1884
1885
1886
def get_decls(api,
1887
formatter,
1888
all_commands,
1889
gles_commands,
1890
already_included,
1891
cmd_packed_gl_enums,
1892
packed_param_types=[]):
1893
decls = []
1894
for command in all_commands:
1895
proto = command.find('proto')
1896
cmd_name = proto.find('name').text
1897
1898
if cmd_name not in gles_commands:
1899
continue
1900
1901
name_no_suffix = strip_suffix(api, cmd_name)
1902
if name_no_suffix in already_included:
1903
continue
1904
1905
param_text = ["".join(param.itertext()) for param in command.findall('param')]
1906
proto_text = "".join(proto.itertext())
1907
decls.append(
1908
format_context_decl(api, cmd_name, proto_text, param_text, formatter,
1909
cmd_packed_gl_enums, packed_param_types))
1910
1911
return decls
1912
1913
1914
def get_glext_decls(all_commands, gles_commands, version):
1915
glext_ptrs = []
1916
glext_protos = []
1917
is_gles1 = False
1918
1919
if (version == ""):
1920
is_gles1 = True
1921
1922
for command in all_commands:
1923
proto = command.find('proto')
1924
cmd_name = proto.find('name').text
1925
1926
if cmd_name not in gles_commands:
1927
continue
1928
1929
param_text = ["".join(param.itertext()) for param in command.findall('param')]
1930
proto_text = "".join(proto.itertext())
1931
1932
return_type = proto_text[:-len(cmd_name)]
1933
params = ", ".join(param_text)
1934
1935
format_params = {
1936
"apicall": "GL_API" if is_gles1 else "GL_APICALL",
1937
"name": cmd_name,
1938
"name_upper": cmd_name.upper(),
1939
"return_type": return_type,
1940
"params": params,
1941
}
1942
1943
glext_ptrs.append(TEMPLATE_GLEXT_FUNCTION_POINTER.format(**format_params))
1944
glext_protos.append(TEMPLATE_GLEXT_FUNCTION_PROTOTYPE.format(**format_params))
1945
1946
return glext_ptrs, glext_protos
1947
1948
1949
def write_file(annotation, comment, template, entry_points, suffix, includes, lib, file):
1950
1951
content = template.format(
1952
script_name=os.path.basename(sys.argv[0]),
1953
data_source_name=file,
1954
annotation_lower=annotation.lower(),
1955
annotation_upper=annotation.upper(),
1956
comment=comment,
1957
lib=lib.upper(),
1958
includes=includes,
1959
entry_points=entry_points)
1960
1961
path = path_to(lib, "entry_points_{}_autogen.{}".format(annotation.lower(), suffix))
1962
1963
with open(path, "w") as out:
1964
out.write(content)
1965
out.close()
1966
1967
1968
def write_export_files(entry_points, includes, source, lib_name, lib_description):
1969
content = TEMPLATE_LIB_ENTRY_POINT_SOURCE.format(
1970
script_name=os.path.basename(sys.argv[0]),
1971
data_source_name=source,
1972
lib_name=lib_name,
1973
lib_description=lib_description,
1974
includes=includes,
1975
entry_points=entry_points)
1976
1977
path = path_to(lib_name, "{}_autogen.cpp".format(lib_name))
1978
1979
with open(path, "w") as out:
1980
out.write(content)
1981
out.close()
1982
1983
1984
def write_context_api_decls(decls, api):
1985
for (major, minor), version_decls in sorted(decls['core'].items()):
1986
if minor == "X":
1987
annotation = '{}_{}'.format(api, major)
1988
version = str(major)
1989
else:
1990
annotation = '{}_{}_{}'.format(api, major, minor)
1991
version = '{}_{}'.format(major, minor)
1992
content = CONTEXT_HEADER.format(
1993
annotation_lower=annotation.lower(),
1994
annotation_upper=annotation.upper(),
1995
script_name=os.path.basename(sys.argv[0]),
1996
data_source_name="gl.xml",
1997
version=version,
1998
interface="\n".join(version_decls))
1999
2000
path = path_to("libANGLE", "Context_%s_autogen.h" % annotation.lower())
2001
2002
with open(path, "w") as out:
2003
out.write(content)
2004
out.close()
2005
2006
if 'exts' in decls.keys():
2007
interface_lines = []
2008
for annotation in decls['exts'].keys():
2009
interface_lines.append("\\\n /* " + annotation + " */ \\\n\\")
2010
2011
for extname in sorted(decls['exts'][annotation].keys()):
2012
interface_lines.append(" /* " + extname + " */ \\")
2013
interface_lines.extend(decls['exts'][annotation][extname])
2014
2015
content = CONTEXT_HEADER.format(
2016
annotation_lower='gles_ext',
2017
annotation_upper='GLES_EXT',
2018
script_name=os.path.basename(sys.argv[0]),
2019
data_source_name="gl.xml",
2020
version='EXT',
2021
interface="\n".join(interface_lines))
2022
2023
path = path_to("libANGLE", "Context_gles_ext_autogen.h")
2024
2025
with open(path, "w") as out:
2026
out.write(content)
2027
out.close()
2028
2029
2030
def write_validation_header(annotation, comment, protos, source, template):
2031
content = template.format(
2032
script_name=os.path.basename(sys.argv[0]),
2033
data_source_name=source,
2034
annotation=annotation,
2035
comment=comment,
2036
prototypes="\n".join(protos))
2037
2038
path = path_to("libANGLE", "validation%s_autogen.h" % annotation)
2039
2040
with open(path, "w") as out:
2041
out.write(content)
2042
out.close()
2043
2044
2045
def write_gl_validation_header(annotation, comment, protos, source):
2046
return write_validation_header(annotation, comment, protos, source,
2047
TEMPLATE_GL_VALIDATION_HEADER)
2048
2049
2050
def write_capture_header(annotation, comment, protos, capture_pointer_funcs):
2051
content = TEMPLATE_CAPTURE_HEADER.format(
2052
script_name=os.path.basename(sys.argv[0]),
2053
data_source_name="gl.xml and gl_angle_ext.xml",
2054
annotation_lower=annotation.lower(),
2055
annotation_upper=annotation.upper(),
2056
comment=comment,
2057
prototypes="\n".join(["\n// Method Captures\n"] + protos + ["\n// Parameter Captures\n"] +
2058
capture_pointer_funcs))
2059
2060
path = path_to(os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.h" % annotation)
2061
2062
with open(path, "w") as out:
2063
out.write(content)
2064
out.close()
2065
2066
2067
def write_capture_source(annotation_with_dash, annotation_no_dash, comment, capture_methods):
2068
content = TEMPLATE_CAPTURE_SOURCE.format(
2069
script_name=os.path.basename(sys.argv[0]),
2070
data_source_name="gl.xml and gl_angle_ext.xml",
2071
annotation_with_dash=annotation_with_dash,
2072
annotation_no_dash=annotation_no_dash,
2073
comment=comment,
2074
capture_methods="\n".join(capture_methods))
2075
2076
path = path_to(
2077
os.path.join("libANGLE", "capture"), "capture_gles_%s_autogen.cpp" % annotation_with_dash)
2078
2079
with open(path, "w") as out:
2080
out.write(content)
2081
out.close()
2082
2083
2084
def is_packed_enum_param_type(param_type):
2085
return param_type[0:2] != "GL" and "void" not in param_type
2086
2087
2088
def add_namespace(param_type):
2089
param_type = param_type.strip()
2090
2091
if param_type == 'AHardwareBufferConstPointer' or param_type == 'charConstPointer':
2092
return param_type
2093
2094
if param_type[0:2] == "GL" or param_type[0:3] == "EGL" or "void" in param_type:
2095
return param_type
2096
2097
# ANGLE namespaced EGL types
2098
egl_namespace = [
2099
'CompositorTiming',
2100
'DevicePointer',
2101
'ObjectType',
2102
'StreamPointer',
2103
'Timestamp',
2104
]
2105
2106
if param_type in egl_namespace:
2107
return "egl::" + param_type
2108
else:
2109
return "gl::" + param_type
2110
2111
2112
def get_gl_pointer_type(param_type):
2113
2114
if "ConstPointerPointer" in param_type:
2115
return "const " + param_type.replace("ConstPointerPointer", "") + " * const *"
2116
2117
if "ConstPointer" in param_type:
2118
return "const " + param_type.replace("ConstPointer", "") + " *"
2119
2120
if "PointerPointer" in param_type:
2121
return param_type.replace("PointerPointer", "") + " **"
2122
2123
if "Pointer" in param_type:
2124
return param_type.replace("Pointer", "") + " *"
2125
2126
return param_type
2127
2128
2129
def get_param_type_type(param_type):
2130
param_type = add_namespace(param_type)
2131
return get_gl_pointer_type(param_type)
2132
2133
2134
def get_gl_param_type_type(param_type):
2135
if not is_packed_enum_param_type(param_type):
2136
return get_gl_pointer_type(param_type)
2137
else:
2138
base_type = param_type.replace("Pointer", "").replace("Const", "")
2139
if base_type[-2:] == "ID":
2140
replace_type = "GLuint"
2141
else:
2142
replace_type = "GLenum"
2143
param_type = param_type.replace(base_type, replace_type)
2144
return get_gl_pointer_type(param_type)
2145
2146
2147
def get_param_type_union_name(param_type):
2148
return param_type + "Val"
2149
2150
2151
def format_param_type_union_type(param_type):
2152
return "%s %s;" % (get_param_type_type(param_type), get_param_type_union_name(param_type))
2153
2154
2155
def format_get_param_val_specialization(param_type):
2156
return TEMPLATE_GET_PARAM_VAL_SPECIALIZATION.format(
2157
enum=param_type,
2158
type=get_param_type_type(param_type),
2159
union_name=get_param_type_union_name(param_type))
2160
2161
2162
def format_access_param_value_case(param_type):
2163
return TEMPLATE_ACCESS_PARAM_VALUE_CASE.format(enum=param_type)
2164
2165
2166
def format_set_param_val_specialization(param_type):
2167
return TEMPLATE_SET_PARAM_VAL_SPECIALIZATION.format(
2168
enum=param_type,
2169
type=get_param_type_type(param_type),
2170
union_name=get_param_type_union_name(param_type))
2171
2172
2173
def format_init_param_value_case(param_type):
2174
return TEMPLATE_INIT_PARAM_VALUE_CASE.format(enum=param_type)
2175
2176
2177
def format_write_param_type_to_stream_case(param_type):
2178
# Force all enum printing to go through "const void *"
2179
param_out = "voidConstPointer" if "Pointer" in param_type else param_type
2180
return TEMPLATE_WRITE_PARAM_TYPE_TO_STREAM_CASE.format(
2181
enum_in=param_type, enum_out=param_out, union_name=get_param_type_union_name(param_out))
2182
2183
2184
def get_resource_id_types(all_param_types):
2185
return [
2186
t[:-2]
2187
for t in filter(lambda t: t.endswith("ID") and not t.endswith("ANDROID"), all_param_types)
2188
]
2189
2190
2191
def format_resource_id_types(all_param_types):
2192
resource_id_types = get_resource_id_types(all_param_types)
2193
resource_id_types += ["EnumCount", "InvalidEnum = EnumCount"]
2194
resource_id_types = ",\n ".join(resource_id_types)
2195
return resource_id_types
2196
2197
2198
def format_resource_id_convert_structs(all_param_types):
2199
templ = """\
2200
template <>
2201
struct GetResourceIDTypeFromType<gl::%sID>
2202
{
2203
static constexpr ResourceIDType IDType = ResourceIDType::%s;
2204
};
2205
"""
2206
resource_id_types = get_resource_id_types(all_param_types)
2207
convert_struct_strings = [templ % (id, id) for id in resource_id_types]
2208
return "\n".join(convert_struct_strings)
2209
2210
2211
def write_capture_helper_header(all_param_types):
2212
2213
param_types = "\n ".join(["T%s," % t for t in all_param_types])
2214
param_union_values = "\n ".join([format_param_type_union_type(t) for t in all_param_types])
2215
get_param_val_specializations = "\n\n".join(
2216
[format_get_param_val_specialization(t) for t in all_param_types])
2217
access_param_value_cases = "\n".join(
2218
[format_access_param_value_case(t) for t in all_param_types])
2219
set_param_val_specializations = "\n\n".join(
2220
[format_set_param_val_specialization(t) for t in all_param_types])
2221
init_param_value_cases = "\n".join([format_init_param_value_case(t) for t in all_param_types])
2222
resource_id_types = format_resource_id_types(all_param_types)
2223
convert_structs = format_resource_id_convert_structs(all_param_types)
2224
2225
content = TEMPLATE_FRAME_CAPTURE_UTILS_HEADER.format(
2226
script_name=os.path.basename(sys.argv[0]),
2227
data_source_name="gl.xml and gl_angle_ext.xml",
2228
param_types=param_types,
2229
param_type_count=len(all_param_types),
2230
param_union_values=param_union_values,
2231
get_param_val_specializations=get_param_val_specializations,
2232
access_param_value_cases=access_param_value_cases,
2233
set_param_val_specializations=set_param_val_specializations,
2234
init_param_value_cases=init_param_value_cases,
2235
resource_id_types=resource_id_types,
2236
type_to_resource_id_type_structs=convert_structs)
2237
2238
path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.h")
2239
2240
with open(path, "w") as out:
2241
out.write(content)
2242
out.close()
2243
2244
2245
def format_param_type_to_string_case(param_type):
2246
return TEMPLATE_PARAM_TYPE_TO_STRING_CASE.format(
2247
enum=param_type, type=get_gl_param_type_type(param_type))
2248
2249
2250
def get_resource_id_type_from_param_type(param_type):
2251
if param_type.endswith("ConstPointer"):
2252
return param_type.replace("ConstPointer", "")[:-2]
2253
if param_type.endswith("Pointer"):
2254
return param_type.replace("Pointer", "")[:-2]
2255
return param_type[:-2]
2256
2257
2258
def format_param_type_to_resource_id_type_case(param_type):
2259
return TEMPLATE_PARAM_TYPE_TO_RESOURCE_ID_TYPE_CASE.format(
2260
enum=param_type, resource_id_type=get_resource_id_type_from_param_type(param_type))
2261
2262
2263
def format_param_type_resource_id_cases(all_param_types):
2264
id_types = filter(
2265
lambda t: (t.endswith("ID") and not t.endswith("ANDROID")) or t.endswith("IDConstPointer")
2266
or t.endswith("IDPointer"), all_param_types)
2267
return "\n".join([format_param_type_to_resource_id_type_case(t) for t in id_types])
2268
2269
2270
def format_resource_id_type_name_case(resource_id_type):
2271
return TEMPLATE_RESOURCE_ID_TYPE_NAME_CASE.format(resource_id_type=resource_id_type)
2272
2273
2274
def write_capture_helper_source(all_param_types):
2275
2276
write_param_type_to_stream_cases = "\n".join(
2277
[format_write_param_type_to_stream_case(t) for t in all_param_types])
2278
param_type_to_string_cases = "\n".join(
2279
[format_param_type_to_string_case(t) for t in all_param_types])
2280
2281
param_type_resource_id_cases = format_param_type_resource_id_cases(all_param_types)
2282
2283
resource_id_types = get_resource_id_types(all_param_types)
2284
resource_id_type_name_cases = "\n".join(
2285
[format_resource_id_type_name_case(t) for t in resource_id_types])
2286
2287
content = TEMPLATE_FRAME_CAPTURE_UTILS_SOURCE.format(
2288
script_name=os.path.basename(sys.argv[0]),
2289
data_source_name="gl.xml and gl_angle_ext.xml",
2290
write_param_type_to_stream_cases=write_param_type_to_stream_cases,
2291
param_type_to_string_cases=param_type_to_string_cases,
2292
param_type_resource_id_cases=param_type_resource_id_cases,
2293
resource_id_type_name_cases=resource_id_type_name_cases)
2294
2295
path = path_to(os.path.join("libANGLE", "capture"), "frame_capture_utils_autogen.cpp")
2296
2297
with open(path, "w") as out:
2298
out.write(content)
2299
out.close()
2300
2301
2302
def get_command_params_text(command_node, cmd_name):
2303
param_text_list = list()
2304
for param_node in command_node.findall('param'):
2305
param_text_list.append("".join(param_node.itertext()))
2306
return param_text_list
2307
2308
2309
def is_get_pointer_command(command_name):
2310
return command_name.endswith('Pointerv') and command_name.startswith('glGet')
2311
2312
2313
def format_capture_replay_param_access(api, command_name, param_text_list, cmd_packed_gl_enums,
2314
packed_param_types):
2315
param_access_strs = list()
2316
cmd_packed_enums = get_packed_enums(api, cmd_packed_gl_enums, command_name, packed_param_types,
2317
param_text_list)
2318
for i, param_text in enumerate(param_text_list):
2319
param_type = just_the_type_packed(param_text, cmd_packed_enums)
2320
param_name = just_the_name_packed(param_text, cmd_packed_enums)
2321
2322
pointer_count = param_type.count('*')
2323
is_const = 'const' in param_type
2324
if pointer_count == 0:
2325
param_template = 'params.getParam("{name}", ParamType::T{enum_type}, {index}).value.{enum_type}Val'
2326
elif pointer_count == 1 and is_const:
2327
param_template = 'replayContext->getAsConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'
2328
elif pointer_count == 2 and is_const:
2329
param_template = 'replayContext->getAsPointerConstPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'
2330
elif pointer_count == 1 or (pointer_count == 2 and is_get_pointer_command(command_name)):
2331
param_template = 'replayContext->getReadBufferPointer<{type}>(params.getParam("{name}", ParamType::T{enum_type}, {index}))'
2332
else:
2333
assert False, "Not supported param type %s" % param_type
2334
2335
param_access_strs.append(
2336
param_template.format(
2337
index=i,
2338
name=param_name,
2339
type=param_type,
2340
enum_type=get_capture_param_type_name(param_type)))
2341
return ",".join(param_access_strs)
2342
2343
2344
def format_capture_replay_call_case(api, command_to_param_types_mapping, cmd_packed_gl_enums,
2345
packed_param_types):
2346
call_str_list = list()
2347
for command_name, cmd_param_texts in sorted(command_to_param_types_mapping.items()):
2348
entry_point_name = strip_api_prefix(command_name)
2349
2350
call_str_list.append(
2351
TEMPLATE_CAPTURE_REPLAY_CALL_CASE.format(
2352
entry_point=entry_point_name,
2353
param_value_access=format_capture_replay_param_access(
2354
api, command_name, cmd_param_texts, cmd_packed_gl_enums, packed_param_types),
2355
context_call=entry_point_name[0].lower() + entry_point_name[1:],
2356
))
2357
2358
return '\n'.join(call_str_list)
2359
2360
2361
def write_capture_replay_source(api, all_commands_nodes, gles_command_names, cmd_packed_gl_enums,
2362
packed_param_types):
2363
all_commands_names = set(gles_command_names)
2364
2365
command_to_param_types_mapping = dict()
2366
for command_node in all_commands_nodes:
2367
command_name = command_node.find('proto').find('name').text
2368
if command_name not in all_commands_names:
2369
continue
2370
2371
command_to_param_types_mapping[command_name] = get_command_params_text(
2372
command_node, command_name)
2373
2374
call_replay_cases = format_capture_replay_call_case(api, command_to_param_types_mapping,
2375
cmd_packed_gl_enums, packed_param_types)
2376
2377
source_content = TEMPLATE_CAPTURE_REPLAY_SOURCE.format(
2378
script_name=os.path.basename(sys.argv[0]),
2379
data_source_name="gl.xml and gl_angle_ext.xml",
2380
call_replay_cases=call_replay_cases,
2381
)
2382
source_file_path = registry_xml.script_relative(
2383
"../src/libANGLE/capture/frame_capture_replay_autogen.cpp")
2384
with open(source_file_path, 'w') as f:
2385
f.write(source_content)
2386
2387
2388
def write_windows_def_file(data_source_name, lib, libexport, folder, exports):
2389
2390
content = TEMPLATE_WINDOWS_DEF_FILE.format(
2391
script_name=os.path.basename(sys.argv[0]),
2392
data_source_name=data_source_name,
2393
exports="\n".join(exports),
2394
lib=libexport)
2395
2396
path = path_to(folder, "%s_autogen.def" % lib)
2397
2398
with open(path, "w") as out:
2399
out.write(content)
2400
out.close()
2401
2402
2403
def get_exports(commands, fmt=None):
2404
if fmt:
2405
return [" %s" % fmt(cmd) for cmd in sorted(commands)]
2406
else:
2407
return [" %s" % cmd for cmd in sorted(commands)]
2408
2409
2410
# Get EGL exports
2411
def get_egl_exports():
2412
2413
egl = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml')
2414
exports = []
2415
2416
capser = lambda fn: "EGL_" + fn[3:]
2417
2418
for major, minor in registry_xml.EGL_VERSIONS:
2419
annotation = "{}_{}".format(major, minor)
2420
name_prefix = "EGL_VERSION_"
2421
2422
feature_name = "{}{}".format(name_prefix, annotation)
2423
2424
egl.AddCommands(feature_name, annotation)
2425
2426
commands = egl.commands[annotation]
2427
2428
if len(commands) == 0:
2429
continue
2430
2431
exports.append("\n ; EGL %d.%d" % (major, minor))
2432
exports += get_exports(commands, capser)
2433
2434
egl.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl'])
2435
2436
for extension_name, ext_cmd_names in sorted(egl.ext_data.items()):
2437
2438
if len(ext_cmd_names) == 0:
2439
continue
2440
2441
exports.append("\n ; %s" % extension_name)
2442
exports += get_exports(ext_cmd_names, capser)
2443
2444
return exports
2445
2446
2447
# Construct a mapping from an EGL EP to object function
2448
def get_egl_entry_point_labeled_object(ep_to_object, cmd_stripped, params, packed_enums):
2449
2450
if not ep_to_object:
2451
return ""
2452
2453
# Finds a packed parameter name in a list of params
2454
def find_param(params, type_name, packed_enums):
2455
for param in params:
2456
if just_the_type_packed(param, packed_enums).split(' ')[0] == type_name:
2457
return just_the_name_packed(param, packed_enums)
2458
return None
2459
2460
display_param = find_param(params, "egl::Display", packed_enums)
2461
2462
# For entry points not listed in the JSON file, they default to an EGLDisplay or nothing.
2463
if cmd_stripped not in ep_to_object:
2464
if display_param:
2465
return "GetDisplayIfValid(%s)" % display_param
2466
return "nullptr"
2467
2468
# We first handle a few special cases for certain type categories.
2469
category = ep_to_object[cmd_stripped]
2470
if category == "Thread":
2471
return "GetThreadIfValid(thread)"
2472
found_param = find_param(params, category, packed_enums)
2473
if category == "Context" and not found_param:
2474
return "GetContextIfValid(thread->getDisplay(), thread->getContext())"
2475
assert found_param, "Did not find %s for %s: %s" % (category, cmd_stripped, str(params))
2476
if category == "Device":
2477
return "GetDeviceIfValid(%s)" % found_param
2478
if category == "LabeledObject":
2479
object_type_param = find_param(params, "ObjectType", packed_enums)
2480
return "GetLabeledObjectIfValid(thread, %s, %s, %s)" % (display_param, object_type_param,
2481
found_param)
2482
2483
# We then handle the general case which handles the rest of the type categories.
2484
return "Get%sIfValid(%s, %s)" % (category, display_param, found_param)
2485
2486
2487
def write_stubs_header(api, annotation, title, data_source, out_file, all_commands, commands,
2488
cmd_packed_egl_enums, packed_param_types):
2489
2490
stubs = []
2491
2492
for command in all_commands:
2493
proto = command.find('proto')
2494
cmd_name = proto.find('name').text
2495
2496
if cmd_name not in commands:
2497
continue
2498
2499
proto_text = "".join(proto.itertext())
2500
params = [] if api == apis.CL else ["Thread *thread"]
2501
params += ["".join(param.itertext()) for param in command.findall('param')]
2502
if params and just_the_name(params[-1]) == "errcode_ret":
2503
params[-1] = "cl_int &errorCode"
2504
return_type = proto_text[:-len(cmd_name)].strip()
2505
2506
internal_params = get_internal_params(api, cmd_name, params, cmd_packed_egl_enums,
2507
packed_param_types)
2508
2509
stubs.append("%s %s(%s);" % (return_type, strip_api_prefix(cmd_name), internal_params))
2510
2511
args = {
2512
"annotation_lower": annotation.lower(),
2513
"annotation_upper": annotation.upper(),
2514
"data_source_name": data_source,
2515
"script_name": os.path.basename(sys.argv[0]),
2516
"stubs": "\n".join(stubs),
2517
"title": title,
2518
}
2519
2520
output = get_stubs_header_template(api).format(**args)
2521
2522
with open(out_file, "w") as f:
2523
f.write(output)
2524
2525
2526
def main():
2527
2528
# auto_script parameters.
2529
if len(sys.argv) > 1:
2530
inputs = [
2531
'entry_point_packed_egl_enums.json', 'entry_point_packed_gl_enums.json',
2532
EGL_GET_LABELED_OBJECT_DATA_PATH
2533
] + registry_xml.xml_inputs
2534
outputs = [
2535
CL_STUBS_HEADER_PATH,
2536
EGL_STUBS_HEADER_PATH,
2537
EGL_EXT_STUBS_HEADER_PATH,
2538
'../src/libOpenCL/libOpenCL_autogen.cpp',
2539
'../src/common/entry_points_enum_autogen.cpp',
2540
'../src/common/entry_points_enum_autogen.h',
2541
'../src/libANGLE/Context_gl_1_autogen.h',
2542
'../src/libANGLE/Context_gl_2_autogen.h',
2543
'../src/libANGLE/Context_gl_3_autogen.h',
2544
'../src/libANGLE/Context_gl_4_autogen.h',
2545
'../src/libANGLE/Context_gles_1_0_autogen.h',
2546
'../src/libANGLE/Context_gles_2_0_autogen.h',
2547
'../src/libANGLE/Context_gles_3_0_autogen.h',
2548
'../src/libANGLE/Context_gles_3_1_autogen.h',
2549
'../src/libANGLE/Context_gles_3_2_autogen.h',
2550
'../src/libANGLE/Context_gles_ext_autogen.h',
2551
'../src/libANGLE/capture/capture_gles_1_0_autogen.cpp',
2552
'../src/libANGLE/capture/capture_gles_1_0_autogen.h',
2553
'../src/libANGLE/capture/capture_gles_2_0_autogen.cpp',
2554
'../src/libANGLE/capture/capture_gles_2_0_autogen.h',
2555
'../src/libANGLE/capture/capture_gles_3_0_autogen.cpp',
2556
'../src/libANGLE/capture/capture_gles_3_0_autogen.h',
2557
'../src/libANGLE/capture/capture_gles_3_1_autogen.cpp',
2558
'../src/libANGLE/capture/capture_gles_3_1_autogen.h',
2559
'../src/libANGLE/capture/capture_gles_3_2_autogen.cpp',
2560
'../src/libANGLE/capture/capture_gles_3_2_autogen.h',
2561
'../src/libANGLE/capture/capture_gles_ext_autogen.cpp',
2562
'../src/libANGLE/capture/capture_gles_ext_autogen.h',
2563
'../src/libANGLE/capture/frame_capture_replay_autogen.cpp',
2564
'../src/libANGLE/capture/frame_capture_utils_autogen.cpp',
2565
'../src/libANGLE/capture/frame_capture_utils_autogen.h',
2566
'../src/libANGLE/validationCL_autogen.h',
2567
'../src/libANGLE/validationEGL_autogen.h',
2568
'../src/libANGLE/validationES1_autogen.h',
2569
'../src/libANGLE/validationES2_autogen.h',
2570
'../src/libANGLE/validationES31_autogen.h',
2571
'../src/libANGLE/validationES32_autogen.h',
2572
'../src/libANGLE/validationES3_autogen.h',
2573
'../src/libANGLE/validationESEXT_autogen.h',
2574
'../src/libANGLE/validationGL1_autogen.h',
2575
'../src/libANGLE/validationGL2_autogen.h',
2576
'../src/libANGLE/validationGL3_autogen.h',
2577
'../src/libANGLE/validationGL4_autogen.h',
2578
'../src/libEGL/libEGL_autogen.cpp',
2579
'../src/libEGL/libEGL_autogen.def',
2580
'../src/libGLESv2/entry_points_cl_autogen.cpp',
2581
'../src/libGLESv2/entry_points_cl_autogen.h',
2582
'../src/libGLESv2/entry_points_egl_autogen.cpp',
2583
'../src/libGLESv2/entry_points_egl_autogen.h',
2584
'../src/libGLESv2/entry_points_egl_ext_autogen.cpp',
2585
'../src/libGLESv2/entry_points_egl_ext_autogen.h',
2586
'../src/libGLESv2/entry_points_gles_1_0_autogen.cpp',
2587
'../src/libGLESv2/entry_points_gles_1_0_autogen.h',
2588
'../src/libGLESv2/entry_points_gles_2_0_autogen.cpp',
2589
'../src/libGLESv2/entry_points_gles_2_0_autogen.h',
2590
'../src/libGLESv2/entry_points_gles_3_0_autogen.cpp',
2591
'../src/libGLESv2/entry_points_gles_3_0_autogen.h',
2592
'../src/libGLESv2/entry_points_gles_3_1_autogen.cpp',
2593
'../src/libGLESv2/entry_points_gles_3_1_autogen.h',
2594
'../src/libGLESv2/entry_points_gles_3_2_autogen.cpp',
2595
'../src/libGLESv2/entry_points_gles_3_2_autogen.h',
2596
'../src/libGLESv2/entry_points_gles_ext_autogen.cpp',
2597
'../src/libGLESv2/entry_points_gles_ext_autogen.h',
2598
'../src/libGLESv2/libGLESv2_autogen.cpp',
2599
'../src/libGLESv2/libGLESv2_autogen.def',
2600
'../src/libGLESv2/libGLESv2_no_capture_autogen.def',
2601
'../src/libGLESv2/libGLESv2_with_capture_autogen.def',
2602
'../src/libGL/entry_points_gl_1_autogen.cpp',
2603
'../src/libGL/entry_points_gl_1_autogen.h',
2604
'../src/libGL/entry_points_gl_2_autogen.cpp',
2605
'../src/libGL/entry_points_gl_2_autogen.h',
2606
'../src/libGL/entry_points_gl_3_autogen.cpp',
2607
'../src/libGL/entry_points_gl_3_autogen.h',
2608
'../src/libGL/entry_points_gl_4_autogen.cpp',
2609
'../src/libGL/entry_points_gl_4_autogen.h',
2610
'../src/libGL/libGL_autogen.cpp',
2611
'../src/libGL/libGL_autogen.def',
2612
]
2613
2614
if sys.argv[1] == 'inputs':
2615
print(','.join(inputs))
2616
elif sys.argv[1] == 'outputs':
2617
print(','.join(outputs))
2618
else:
2619
print('Invalid script parameters')
2620
return 1
2621
return 0
2622
2623
glesdecls = {}
2624
glesdecls['core'] = {}
2625
glesdecls['exts'] = {}
2626
for ver in registry_xml.GLES_VERSIONS:
2627
glesdecls['core'][ver] = []
2628
for ver in ['GLES1 Extensions', 'GLES2+ Extensions', 'ANGLE Extensions']:
2629
glesdecls['exts'][ver] = {}
2630
2631
libgles_ep_defs = []
2632
libgles_ep_exports = []
2633
2634
xml = registry_xml.RegistryXML('gl.xml', 'gl_angle_ext.xml')
2635
2636
# Stores core commands to keep track of duplicates
2637
all_commands_no_suffix = []
2638
all_commands_with_suffix = []
2639
2640
# First run through the main GLES entry points. Since ES2+ is the primary use
2641
# case, we go through those first and then add ES1-only APIs at the end.
2642
for major_version, minor_version in registry_xml.GLES_VERSIONS:
2643
version = "{}_{}".format(major_version, minor_version)
2644
annotation = "GLES_{}".format(version)
2645
name_prefix = "GL_ES_VERSION_"
2646
2647
if major_version == 1:
2648
name_prefix = "GL_VERSION_ES_CM_"
2649
2650
comment = version.replace("_", ".")
2651
feature_name = "{}{}".format(name_prefix, version)
2652
2653
xml.AddCommands(feature_name, version)
2654
2655
version_commands = xml.commands[version]
2656
all_commands_no_suffix.extend(xml.commands[version])
2657
all_commands_with_suffix.extend(xml.commands[version])
2658
2659
eps = GLEntryPoints(apis.GLES, xml, version_commands)
2660
eps.decls.insert(0, "extern \"C\" {")
2661
eps.decls.append("} // extern \"C\"")
2662
eps.defs.insert(0, "extern \"C\" {")
2663
eps.defs.append("} // extern \"C\"")
2664
2665
# Write the version as a comment before the first EP.
2666
libgles_ep_exports.append("\n ; OpenGL ES %s" % comment)
2667
2668
libgles_ep_defs += ["\n// OpenGL ES %s" % comment] + eps.export_defs
2669
libgles_ep_exports += get_exports(version_commands)
2670
2671
major_if_not_one = major_version if major_version != 1 else ""
2672
minor_if_not_zero = minor_version if minor_version != 0 else ""
2673
2674
header_includes = TEMPLATE_HEADER_INCLUDES.format(
2675
major=major_if_not_one, minor=minor_if_not_zero)
2676
2677
# We include the platform.h header since it undefines the conflicting MemoryBarrier macro.
2678
if major_version == 3 and minor_version == 1:
2679
header_includes += "\n#include \"common/platform.h\"\n"
2680
2681
version_annotation = "%s%s" % (major_version, minor_if_not_zero)
2682
source_includes = TEMPLATE_SOURCES_INCLUDES.format(
2683
header_version=annotation.lower(), validation_header_version="ES" + version_annotation)
2684
2685
write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_HEADER,
2686
"\n".join(eps.decls), "h", header_includes, "libGLESv2", "gl.xml")
2687
write_file(annotation, "GLES " + comment, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(eps.defs),
2688
"cpp", source_includes, "libGLESv2", "gl.xml")
2689
2690
glesdecls['core'][(major_version,
2691
minor_version)] = get_decls(apis.GLES, CONTEXT_DECL_FORMAT,
2692
xml.all_commands, version_commands, [],
2693
GLEntryPoints.get_packed_enums())
2694
2695
validation_annotation = "ES%s%s" % (major_version, minor_if_not_zero)
2696
write_gl_validation_header(validation_annotation, "ES %s" % comment, eps.validation_protos,
2697
"gl.xml and gl_angle_ext.xml")
2698
2699
write_capture_header(version, comment, eps.capture_protos, eps.capture_pointer_funcs)
2700
write_capture_source(version, validation_annotation, comment, eps.capture_methods)
2701
2702
# After we finish with the main entry points, we process the extensions.
2703
extension_decls = ["extern \"C\" {"]
2704
extension_defs = ["extern \"C\" {"]
2705
extension_commands = []
2706
2707
# Accumulated validation prototypes.
2708
ext_validation_protos = []
2709
ext_capture_protos = []
2710
ext_capture_methods = []
2711
ext_capture_pointer_funcs = []
2712
2713
for gles1ext in registry_xml.gles1_extensions:
2714
glesdecls['exts']['GLES1 Extensions'][gles1ext] = []
2715
for glesext in registry_xml.gles_extensions:
2716
glesdecls['exts']['GLES2+ Extensions'][glesext] = []
2717
for angle_ext in registry_xml.angle_extensions:
2718
glesdecls['exts']['ANGLE Extensions'][angle_ext] = []
2719
2720
xml.AddExtensionCommands(registry_xml.supported_extensions, ['gles2', 'gles1'])
2721
2722
for extension_name, ext_cmd_names in sorted(xml.ext_data.items()):
2723
extension_commands.extend(xml.ext_data[extension_name])
2724
2725
# Detect and filter duplicate extensions.
2726
eps = GLEntryPoints(apis.GLES, xml, ext_cmd_names)
2727
2728
# Write the extension name as a comment before the first EP.
2729
comment = "\n// {}".format(extension_name)
2730
libgles_ep_exports.append("\n ; %s" % extension_name)
2731
2732
extension_defs += [comment] + eps.defs
2733
extension_decls += [comment] + eps.decls
2734
2735
# Avoid writing out entry points defined by a prior extension.
2736
for dupe in xml.ext_dupes[extension_name]:
2737
msg = "// {} is already defined.\n".format(strip_api_prefix(dupe))
2738
extension_defs.append(msg)
2739
2740
ext_validation_protos += [comment] + eps.validation_protos
2741
ext_capture_protos += [comment] + eps.capture_protos
2742
ext_capture_methods += eps.capture_methods
2743
ext_capture_pointer_funcs += eps.capture_pointer_funcs
2744
2745
libgles_ep_defs += [comment] + eps.export_defs
2746
libgles_ep_exports += get_exports(ext_cmd_names)
2747
2748
if (extension_name in registry_xml.gles1_extensions and
2749
extension_name not in GLES1_NO_CONTEXT_DECL_EXTENSIONS):
2750
glesdecls['exts']['GLES1 Extensions'][extension_name] = get_decls(
2751
apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,
2752
all_commands_no_suffix, GLEntryPoints.get_packed_enums())
2753
if extension_name in registry_xml.gles_extensions:
2754
glesdecls['exts']['GLES2+ Extensions'][extension_name] = get_decls(
2755
apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,
2756
all_commands_no_suffix, GLEntryPoints.get_packed_enums())
2757
if extension_name in registry_xml.angle_extensions:
2758
glesdecls['exts']['ANGLE Extensions'][extension_name] = get_decls(
2759
apis.GLES, CONTEXT_DECL_FORMAT, xml.all_commands, ext_cmd_names,
2760
all_commands_no_suffix, GLEntryPoints.get_packed_enums())
2761
2762
for name in extension_commands:
2763
all_commands_with_suffix.append(name)
2764
all_commands_no_suffix.append(strip_suffix(apis.GLES, name))
2765
2766
# Now we generate entry points for the desktop implementation
2767
desktop_gl_decls = {}
2768
desktop_gl_decls['core'] = {}
2769
for major, _ in registry_xml.DESKTOP_GL_VERSIONS:
2770
desktop_gl_decls['core'][(major, "X")] = []
2771
2772
libgl_ep_defs = []
2773
libgl_ep_exports = []
2774
2775
glxml = registry_xml.RegistryXML('gl.xml')
2776
2777
for major_version in sorted(
2778
set([major for (major, minor) in registry_xml.DESKTOP_GL_VERSIONS])):
2779
is_major = lambda ver: ver[0] == major_version
2780
2781
ver_decls = ["extern \"C\" {"]
2782
ver_defs = ["extern \"C\" {"]
2783
validation_protos = []
2784
2785
for _, minor_version in filter(is_major, registry_xml.DESKTOP_GL_VERSIONS):
2786
version = "{}_{}".format(major_version, minor_version)
2787
annotation = "GL_{}".format(version)
2788
name_prefix = "GL_VERSION_"
2789
2790
comment = version.replace("_", ".")
2791
feature_name = "{}{}".format(name_prefix, version)
2792
2793
glxml.AddCommands(feature_name, version)
2794
2795
all_libgl_commands = glxml.commands[version]
2796
2797
just_libgl_commands = [
2798
cmd for cmd in all_libgl_commands if cmd not in all_commands_no_suffix
2799
]
2800
just_libgl_commands_suffix = [
2801
cmd for cmd in all_libgl_commands if cmd not in all_commands_with_suffix
2802
]
2803
2804
# Validation duplicates handled with suffix
2805
eps_suffix = GLEntryPoints(apis.GL, glxml, just_libgl_commands_suffix)
2806
eps = GLEntryPoints(apis.GL, glxml, all_libgl_commands)
2807
2808
desktop_gl_decls['core'][(major_version,
2809
"X")] += get_decls(apis.GL, CONTEXT_DECL_FORMAT,
2810
glxml.all_commands, just_libgl_commands,
2811
all_commands_no_suffix,
2812
GLEntryPoints.get_packed_enums())
2813
2814
# Write the version as a comment before the first EP.
2815
cpp_comment = "\n// GL %s" % comment
2816
def_comment = "\n ; GL %s" % comment
2817
2818
libgl_ep_defs += [cpp_comment] + eps.export_defs
2819
libgl_ep_exports += [def_comment] + get_exports(all_libgl_commands)
2820
validation_protos += [cpp_comment] + eps_suffix.validation_protos
2821
ver_decls += [cpp_comment] + eps.decls
2822
ver_defs += [cpp_comment] + eps.defs
2823
2824
ver_decls.append("} // extern \"C\"")
2825
ver_defs.append("} // extern \"C\"")
2826
annotation = "GL_%d" % major_version
2827
name = "Desktop GL %s.x" % major_version
2828
2829
source_includes = TEMPLATE_DESKTOP_GL_SOURCE_INCLUDES.format(annotation.lower(),
2830
major_version)
2831
2832
# Entry point files
2833
write_file(annotation, name, TEMPLATE_ENTRY_POINT_HEADER, "\n".join(ver_decls), "h",
2834
DESKTOP_GL_HEADER_INCLUDES, "libGL", "gl.xml")
2835
write_file(annotation, name, TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(ver_defs), "cpp",
2836
source_includes, "libGL", "gl.xml")
2837
2838
# Validation files
2839
write_gl_validation_header("GL%s" % major_version, name, validation_protos, "gl.xml")
2840
2841
# OpenCL
2842
clxml = registry_xml.RegistryXML('cl.xml')
2843
2844
cl_validation_protos = []
2845
cl_decls = ["namespace cl\n{"]
2846
cl_defs = ["namespace cl\n{"]
2847
libcl_ep_defs = []
2848
libcl_windows_def_exports = []
2849
cl_commands = []
2850
2851
for major_version, minor_version in registry_xml.CL_VERSIONS:
2852
version = "%d_%d" % (major_version, minor_version)
2853
annotation = "CL_%s" % version
2854
name_prefix = "CL_VERSION_"
2855
2856
comment = version.replace("_", ".")
2857
feature_name = "%s%s" % (name_prefix, version)
2858
2859
clxml.AddCommands(feature_name, version)
2860
2861
cl_version_commands = clxml.commands[version]
2862
cl_commands += cl_version_commands
2863
2864
# Spec revs may have no new commands.
2865
if not cl_version_commands:
2866
continue
2867
2868
eps = CLEntryPoints(clxml, cl_version_commands)
2869
2870
comment = "\n// CL %d.%d" % (major_version, minor_version)
2871
win_def_comment = "\n ; CL %d.%d" % (major_version, minor_version)
2872
2873
cl_decls += [comment] + eps.decls
2874
cl_defs += [comment] + eps.defs
2875
libcl_ep_defs += [comment] + eps.export_defs
2876
cl_validation_protos += [comment] + eps.validation_protos
2877
libcl_windows_def_exports += [win_def_comment] + get_exports(clxml.commands[version])
2878
2879
clxml.AddExtensionCommands(registry_xml.supported_cl_extensions, ['cl'])
2880
for extension_name, ext_cmd_names in sorted(clxml.ext_data.items()):
2881
2882
# Extensions may have no new commands.
2883
if not ext_cmd_names:
2884
continue
2885
2886
# Detect and filter duplicate extensions.
2887
eps = CLEntryPoints(clxml, ext_cmd_names)
2888
2889
comment = "\n// %s" % extension_name
2890
win_def_comment = "\n ; %s" % (extension_name)
2891
2892
cl_commands += ext_cmd_names
2893
2894
cl_decls += [comment] + eps.decls
2895
cl_defs += [comment] + eps.defs
2896
libcl_ep_defs += [comment] + eps.export_defs
2897
cl_validation_protos += [comment] + eps.validation_protos
2898
libcl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names)
2899
2900
# Avoid writing out entry points defined by a prior extension.
2901
for dupe in clxml.ext_dupes[extension_name]:
2902
msg = "// %s is already defined.\n" % strip_api_prefix(dupe)
2903
cl_defs.append(msg)
2904
2905
cl_decls.append("} // namespace cl")
2906
cl_defs.append("} // namespace cl")
2907
2908
write_file("cl", "CL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(cl_decls), "h",
2909
LIBCL_HEADER_INCLUDES, "libGLESv2", "cl.xml")
2910
write_file("cl", "CL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(cl_defs), "cpp",
2911
LIBCL_SOURCE_INCLUDES, "libGLESv2", "cl.xml")
2912
write_validation_header("CL", "CL", cl_validation_protos, "cl.xml",
2913
TEMPLATE_CL_VALIDATION_HEADER)
2914
write_stubs_header("CL", "cl", "CL", "cl.xml", CL_STUBS_HEADER_PATH, clxml.all_commands,
2915
cl_commands, CLEntryPoints.get_packed_enums(), CL_PACKED_TYPES)
2916
2917
# EGL
2918
eglxml = registry_xml.RegistryXML('egl.xml', 'egl_angle_ext.xml')
2919
2920
egl_validation_protos = []
2921
egl_decls = ["extern \"C\" {"]
2922
egl_defs = ["extern \"C\" {"]
2923
libegl_ep_defs = []
2924
libegl_windows_def_exports = []
2925
egl_commands = []
2926
2927
for major_version, minor_version in registry_xml.EGL_VERSIONS:
2928
version = "%d_%d" % (major_version, minor_version)
2929
annotation = "EGL_%s" % version
2930
name_prefix = "EGL_VERSION_"
2931
2932
comment = version.replace("_", ".")
2933
feature_name = "%s%s" % (name_prefix, version)
2934
2935
eglxml.AddCommands(feature_name, version)
2936
2937
egl_version_commands = eglxml.commands[version]
2938
egl_commands += egl_version_commands
2939
2940
# Spec revs may have no new commands.
2941
if not egl_version_commands:
2942
continue
2943
2944
eps = EGLEntryPoints(eglxml, egl_version_commands)
2945
2946
comment = "\n// EGL %d.%d" % (major_version, minor_version)
2947
win_def_comment = "\n ; EGL %d.%d" % (major_version, minor_version)
2948
2949
egl_decls += [comment] + eps.decls
2950
egl_defs += [comment] + eps.defs
2951
libegl_ep_defs += [comment] + eps.export_defs
2952
egl_validation_protos += [comment] + eps.validation_protos
2953
libegl_windows_def_exports += [win_def_comment] + get_exports(eglxml.commands[version])
2954
2955
egl_decls.append("} // extern \"C\"")
2956
egl_defs.append("} // extern \"C\"")
2957
2958
write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_decls), "h",
2959
EGL_HEADER_INCLUDES, "libGLESv2", "egl.xml")
2960
write_file("egl", "EGL", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_defs), "cpp",
2961
EGL_SOURCE_INCLUDES, "libGLESv2", "egl.xml")
2962
write_stubs_header("EGL", "egl", "EGL", "egl.xml", EGL_STUBS_HEADER_PATH, eglxml.all_commands,
2963
egl_commands, EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES)
2964
2965
eglxml.AddExtensionCommands(registry_xml.supported_egl_extensions, ['egl'])
2966
egl_ext_decls = ["extern \"C\" {"]
2967
egl_ext_defs = ["extern \"C\" {"]
2968
egl_ext_commands = []
2969
2970
for extension_name, ext_cmd_names in sorted(eglxml.ext_data.items()):
2971
2972
# Extensions may have no new commands.
2973
if not ext_cmd_names:
2974
continue
2975
2976
# Detect and filter duplicate extensions.
2977
eps = EGLEntryPoints(eglxml, ext_cmd_names)
2978
2979
comment = "\n// %s" % extension_name
2980
win_def_comment = "\n ; %s" % (extension_name)
2981
2982
egl_ext_commands += ext_cmd_names
2983
2984
egl_ext_decls += [comment] + eps.decls
2985
egl_ext_defs += [comment] + eps.defs
2986
libegl_ep_defs += [comment] + eps.export_defs
2987
egl_validation_protos += [comment] + eps.validation_protos
2988
libegl_windows_def_exports += [win_def_comment] + get_exports(ext_cmd_names)
2989
2990
# Avoid writing out entry points defined by a prior extension.
2991
for dupe in eglxml.ext_dupes[extension_name]:
2992
msg = "// %s is already defined.\n" % strip_api_prefix(dupe)
2993
egl_ext_defs.append(msg)
2994
2995
egl_ext_decls.append("} // extern \"C\"")
2996
egl_ext_defs.append("} // extern \"C\"")
2997
2998
write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_HEADER, "\n".join(egl_ext_decls),
2999
"h", EGL_EXT_HEADER_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml")
3000
write_file("egl_ext", "EGL Extension", TEMPLATE_ENTRY_POINT_SOURCE, "\n".join(egl_ext_defs),
3001
"cpp", EGL_EXT_SOURCE_INCLUDES, "libGLESv2", "egl.xml and egl_angle_ext.xml")
3002
write_validation_header("EGL", "EGL", egl_validation_protos, "egl.xml and egl_angle_ext.xml",
3003
TEMPLATE_EGL_VALIDATION_HEADER)
3004
write_stubs_header("EGL", "egl_ext", "EXT extension", "egl.xml and egl_angle_ext.xml",
3005
EGL_EXT_STUBS_HEADER_PATH, eglxml.all_commands, egl_ext_commands,
3006
EGLEntryPoints.get_packed_enums(), EGL_PACKED_TYPES)
3007
3008
# WGL
3009
wglxml = registry_xml.RegistryXML('wgl.xml')
3010
3011
name_prefix = "WGL_VERSION_"
3012
version = "1_0"
3013
comment = version.replace("_", ".")
3014
feature_name = "{}{}".format(name_prefix, version)
3015
wglxml.AddCommands(feature_name, version)
3016
wgl_commands = wglxml.commands[version]
3017
3018
wgl_commands = [cmd if cmd[:3] == 'wgl' else 'wgl' + cmd for cmd in wgl_commands]
3019
3020
# Write the version as a comment before the first EP.
3021
libgl_ep_exports.append("\n ; WGL %s" % comment)
3022
3023
# Other versions of these functions are used
3024
wgl_commands.remove("wglUseFontBitmaps")
3025
wgl_commands.remove("wglUseFontOutlines")
3026
3027
libgl_ep_exports += get_exports(wgl_commands)
3028
extension_decls.append("} // extern \"C\"")
3029
extension_defs.append("} // extern \"C\"")
3030
3031
write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_HEADER,
3032
"\n".join([item for item in extension_decls]), "h", GLES_EXT_HEADER_INCLUDES,
3033
"libGLESv2", "gl.xml and gl_angle_ext.xml")
3034
write_file("gles_ext", "GLES extension", TEMPLATE_ENTRY_POINT_SOURCE,
3035
"\n".join([item for item in extension_defs]), "cpp", GLES_EXT_SOURCE_INCLUDES,
3036
"libGLESv2", "gl.xml and gl_angle_ext.xml")
3037
3038
write_gl_validation_header("ESEXT", "ES extension", ext_validation_protos,
3039
"gl.xml and gl_angle_ext.xml")
3040
write_capture_header("ext", "extension", ext_capture_protos, ext_capture_pointer_funcs)
3041
write_capture_source("ext", "ESEXT", "extension", ext_capture_methods)
3042
3043
write_context_api_decls(glesdecls, "gles")
3044
write_context_api_decls(desktop_gl_decls, "gl")
3045
3046
# Entry point enum
3047
cl_cmd_names = [strip_api_prefix(cmd) for cmd in clxml.all_cmd_names.get_all_commands()]
3048
egl_cmd_names = [strip_api_prefix(cmd) for cmd in eglxml.all_cmd_names.get_all_commands()]
3049
gles_cmd_names = ["Invalid"
3050
] + [strip_api_prefix(cmd) for cmd in xml.all_cmd_names.get_all_commands()]
3051
gl_cmd_names = [strip_api_prefix(cmd) for cmd in glxml.all_cmd_names.get_all_commands()]
3052
wgl_cmd_names = [strip_api_prefix(cmd) for cmd in wglxml.all_cmd_names.get_all_commands()]
3053
unsorted_enums = [("CL%s" % cmd, "cl%s" % cmd) for cmd in cl_cmd_names] + [
3054
("EGL%s" % cmd, "egl%s" % cmd) for cmd in egl_cmd_names
3055
] + [("GL%s" % cmd, "gl%s" % cmd) for cmd in set(gles_cmd_names + gl_cmd_names)
3056
] + [("WGL%s" % cmd, "wgl%s" % cmd) for cmd in wgl_cmd_names]
3057
all_enums = sorted(unsorted_enums)
3058
3059
entry_points_enum_header = TEMPLATE_ENTRY_POINTS_ENUM_HEADER.format(
3060
script_name=os.path.basename(sys.argv[0]),
3061
data_source_name="gl.xml and gl_angle_ext.xml",
3062
lib="GL/GLES",
3063
entry_points_list=",\n".join([" " + enum for (enum, _) in all_enums]))
3064
3065
entry_points_enum_header_path = path_to("common", "entry_points_enum_autogen.h")
3066
with open(entry_points_enum_header_path, "w") as out:
3067
out.write(entry_points_enum_header)
3068
out.close()
3069
3070
entry_points_cases = [
3071
TEMPLATE_ENTRY_POINTS_NAME_CASE.format(enum=enum, cmd=cmd) for (enum, cmd) in all_enums
3072
]
3073
entry_points_enum_source = TEMPLATE_ENTRY_POINTS_ENUM_SOURCE.format(
3074
script_name=os.path.basename(sys.argv[0]),
3075
data_source_name="gl.xml and gl_angle_ext.xml",
3076
lib="GL/GLES",
3077
entry_points_name_cases="\n".join(entry_points_cases))
3078
3079
entry_points_enum_source_path = path_to("common", "entry_points_enum_autogen.cpp")
3080
with open(entry_points_enum_source_path, "w") as out:
3081
out.write(entry_points_enum_source)
3082
out.close()
3083
3084
write_export_files("\n".join([item for item in libgles_ep_defs]), LIBGLESV2_EXPORT_INCLUDES,
3085
"gl.xml and gl_angle_ext.xml", "libGLESv2", "OpenGL ES")
3086
write_export_files("\n".join([item for item in libgl_ep_defs]), LIBGL_EXPORT_INCLUDES,
3087
"gl.xml and wgl.xml", "libGL", "Windows GL")
3088
write_export_files("\n".join([item for item in libegl_ep_defs]),
3089
LIBEGL_EXPORT_INCLUDES_AND_PREAMBLE, "egl.xml and egl_angle_ext.xml",
3090
"libEGL", "EGL")
3091
write_export_files("\n".join([item for item in libcl_ep_defs]), LIBCL_EXPORT_INCLUDES,
3092
"cl.xml", "libOpenCL", "CL")
3093
3094
libgles_ep_exports += get_egl_exports()
3095
3096
everything = "Khronos and ANGLE XML files"
3097
3098
for lib in ["libGLESv2" + suffix for suffix in ["", "_no_capture", "_with_capture"]]:
3099
write_windows_def_file(everything, lib, lib, "libGLESv2", libgles_ep_exports)
3100
write_windows_def_file(everything, "libGL", "openGL32", "libGL", libgl_ep_exports)
3101
write_windows_def_file("egl.xml and egl_angle_ext.xml", "libEGL", "libEGL", "libEGL",
3102
libegl_windows_def_exports)
3103
3104
all_gles_param_types = sorted(GLEntryPoints.all_param_types)
3105
all_egl_param_types = sorted(EGLEntryPoints.all_param_types)
3106
# Get a sorted list of param types without duplicates
3107
all_param_types = sorted(list(set(all_gles_param_types + all_egl_param_types)))
3108
write_capture_helper_header(all_param_types)
3109
write_capture_helper_source(all_param_types)
3110
write_capture_replay_source(apis.GLES, xml.all_commands, all_commands_no_suffix,
3111
GLEntryPoints.get_packed_enums(), [])
3112
3113
3114
if __name__ == '__main__':
3115
sys.exit(main())
3116
3117