build_raster_cmd_buffer.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. #!/usr/bin/env python3
  2. # Copyright 2018 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """code generator for raster command buffers."""
  6. import filecmp
  7. import os
  8. import sys
  9. from optparse import OptionParser
  10. import build_cmd_buffer_lib
  11. # Additional space required after "type" here and elsewhere because otherwise
  12. # pylint detects "# type:" as invalid syntax on Python 3.8, see
  13. # https://github.com/PyCQA/pylint/issues/3556.
  14. # Named type info object represents a named type that is used in OpenGL call
  15. # arguments. Each named type defines a set of valid OpenGL call arguments. The
  16. # named types are used in 'raster_cmd_buffer_functions.txt'.
  17. # type : The actual GL type of the named type.
  18. # valid: The list of values that are valid for both the client and the service.
  19. # invalid: Examples of invalid values for the type. At least these values
  20. # should be tested to be invalid.
  21. # is_complete: The list of valid values of type are final and will not be
  22. # modified during runtime.
  23. # validator: If set to False will prevent creation of a ValueValidator. Values
  24. # are still expected to be checked for validity and will be tested.
  25. _NAMED_TYPE_INFO = {
  26. 'GLState': {
  27. 'type': 'GLenum',
  28. 'valid': [
  29. 'GL_ACTIVE_TEXTURE',
  30. ],
  31. 'invalid': [
  32. 'GL_FOG_HINT',
  33. ],
  34. },
  35. 'QueryObjectParameter': {
  36. 'type': 'GLenum',
  37. 'is_complete': True,
  38. 'valid': [
  39. 'GL_QUERY_RESULT_EXT',
  40. 'GL_QUERY_RESULT_AVAILABLE_EXT',
  41. 'GL_QUERY_RESULT_AVAILABLE_NO_FLUSH_CHROMIUM_EXT',
  42. ],
  43. },
  44. 'QueryTarget': {
  45. 'type': 'GLenum',
  46. 'is_complete': True,
  47. 'valid': [
  48. 'GL_COMMANDS_ISSUED_CHROMIUM',
  49. 'GL_COMMANDS_ISSUED_TIMESTAMP_CHROMIUM',
  50. 'GL_COMMANDS_COMPLETED_CHROMIUM',
  51. ],
  52. 'invalid': [
  53. 'GL_LATENCY_QUERY_CHROMIUM',
  54. ],
  55. },
  56. 'TextureParameter': {
  57. 'type': 'GLenum',
  58. 'valid': [
  59. 'GL_TEXTURE_MAG_FILTER',
  60. 'GL_TEXTURE_MIN_FILTER',
  61. 'GL_TEXTURE_WRAP_S',
  62. 'GL_TEXTURE_WRAP_T',
  63. ],
  64. 'invalid': [
  65. 'GL_GENERATE_MIPMAP',
  66. ],
  67. },
  68. 'TextureWrapMode': {
  69. 'type': 'GLenum',
  70. 'valid': [
  71. 'GL_CLAMP_TO_EDGE',
  72. ],
  73. 'invalid': [
  74. 'GL_REPEAT',
  75. ],
  76. },
  77. 'TextureMinFilterMode': {
  78. 'type': 'GLenum',
  79. 'valid': [
  80. 'GL_NEAREST',
  81. ],
  82. 'invalid': [
  83. 'GL_NEAREST_MIPMAP_NEAREST',
  84. ],
  85. },
  86. 'TextureMagFilterMode': {
  87. 'type': 'GLenum',
  88. 'valid': [
  89. 'GL_NEAREST',
  90. ],
  91. 'invalid': [
  92. 'GL_LINEAR',
  93. ],
  94. },
  95. 'ResetStatus': {
  96. 'type': 'GLenum',
  97. 'is_complete': True,
  98. 'valid': [
  99. 'GL_GUILTY_CONTEXT_RESET_ARB',
  100. 'GL_INNOCENT_CONTEXT_RESET_ARB',
  101. 'GL_UNKNOWN_CONTEXT_RESET_ARB',
  102. ],
  103. },
  104. 'gfx::BufferUsage': {
  105. 'type': 'gfx::BufferUsage',
  106. 'valid': [
  107. 'gfx::BufferUsage::GPU_READ',
  108. 'gfx::BufferUsage::SCANOUT',
  109. 'gfx::BufferUsage::GPU_READ_CPU_READ_WRITE',
  110. ],
  111. 'invalid': [
  112. 'gfx::BufferUsage::SCANOUT_CAMERA_READ_WRITE',
  113. 'gfx::BufferUsage::CAMERA_AND_CPU_READ_WRITE',
  114. ],
  115. },
  116. 'viz::ResourceFormat': {
  117. 'type': 'viz::ResourceFormat',
  118. 'valid': [
  119. 'viz::ResourceFormat::RGBA_8888',
  120. 'viz::ResourceFormat::RGBA_4444',
  121. 'viz::ResourceFormat::BGRA_8888',
  122. 'viz::ResourceFormat::ALPHA_8',
  123. 'viz::ResourceFormat::LUMINANCE_8',
  124. 'viz::ResourceFormat::RGB_565',
  125. 'viz::ResourceFormat::BGR_565',
  126. 'viz::ResourceFormat::RED_8',
  127. 'viz::ResourceFormat::RG_88',
  128. 'viz::ResourceFormat::LUMINANCE_F16',
  129. 'viz::ResourceFormat::RGBA_F16',
  130. 'viz::ResourceFormat::R16_EXT',
  131. 'viz::ResourceFormat::RGBX_8888',
  132. 'viz::ResourceFormat::BGRX_8888',
  133. 'viz::ResourceFormat::RGBA_1010102',
  134. 'viz::ResourceFormat::BGRA_1010102',
  135. 'viz::ResourceFormat::YVU_420',
  136. 'viz::ResourceFormat::YUV_420_BIPLANAR',
  137. 'viz::ResourceFormat::P010',
  138. ],
  139. 'invalid': [
  140. 'viz::ResourceFormat::ETC1',
  141. ],
  142. },
  143. 'gpu::raster::MsaaMode': {
  144. 'type': 'gpu::raster::MsaaMode',
  145. 'is_complete': True,
  146. 'valid': [
  147. 'gpu::raster::MsaaMode::kNoMSAA',
  148. 'gpu::raster::MsaaMode::kMSAA',
  149. 'gpu::raster::MsaaMode::kDMSAA',
  150. ],
  151. },
  152. }
  153. # A function info object specifies the type and other special data for the
  154. # command that will be generated. A base function info object is generated by
  155. # parsing the "raster_cmd_buffer_functions.txt", one for each function in the
  156. # file. These function info objects can be augmented and their values can be
  157. # overridden by adding an object to the table below.
  158. #
  159. # Must match function names specified in "raster_cmd_buffer_functions.txt".
  160. #
  161. # type : defines which handler will be used to generate code.
  162. # decoder_func: defines which function to call in the decoder to execute the
  163. # corresponding GL command. If not specified the GL command will
  164. # be called directly.
  165. # cmd_args: The arguments to use for the command. This overrides generating
  166. # them based on the GL function arguments.
  167. # data_transfer_methods: Array of methods that are used for transfering the
  168. # pointer data. Possible values: 'immediate', 'shm', 'bucket'.
  169. # The default is 'immediate' if the command has one pointer
  170. # argument, otherwise 'shm'. One command is generated for each
  171. # transfer method. Affects only commands which are not of type
  172. # 'GETn' or 'GLcharN'.
  173. # Note: the command arguments that affect this are the final args,
  174. # taking cmd_args override into consideration.
  175. # impl_func: Whether or not to generate the GLES2Implementation part of this
  176. # command.
  177. # internal: If true, this is an internal command only, not exposed to the
  178. # client.
  179. # count: The number of units per element. For PUTn or PUT types.
  180. # use_count_func: If True the actual data count needs to be computed; the count
  181. # argument specifies the maximum count.
  182. # unit_test: If False no service side unit test will be generated.
  183. # client_test: If False no client side unit test will be generated.
  184. # expectation: If False the unit test will have no expected calls.
  185. # valid_args: A dictionary of argument indices to args to use in unit tests
  186. # when they can not be automatically determined.
  187. # invalid_test: False if no invalid test needed.
  188. # not_shared: For GENn types, True if objects can't be shared between contexts
  189. _FUNCTION_INFO = {
  190. 'CopySubTextureINTERNAL': {
  191. 'decoder_func': 'DoCopySubTextureINTERNAL',
  192. 'internal': True,
  193. 'type': 'PUT',
  194. 'count': 32, # GL_MAILBOX_SIZE_CHROMIUM x2
  195. 'unit_test': False,
  196. 'trace_level': 2,
  197. },
  198. 'WritePixelsINTERNAL': {
  199. 'decoder_func': 'DoWritePixelsINTERNAL',
  200. 'internal': True,
  201. 'type': 'PUT',
  202. 'count': 16, # GL_MAILBOX_SIZE_CHROMIUM
  203. 'unit_test': False,
  204. 'trace_level': 2,
  205. },
  206. 'ReadbackARGBImagePixelsINTERNAL': {
  207. 'decoder_func': 'DoReadbackARGBImagePixelsINTERNAL',
  208. 'internal': True,
  209. 'type': 'PUT',
  210. 'count': 16, # GL_MAILBOX_SIZE_CHROMIUM
  211. 'unit_test': False,
  212. 'result': ['uint32_t'],
  213. 'trace_level': 2,
  214. },
  215. 'ReadbackYUVImagePixelsINTERNAL': {
  216. 'decoder_func': 'DoReadbackYUVImagePixelsINTERNAL',
  217. 'internal': True,
  218. 'type': 'PUT',
  219. 'count': 16, # GL_MAILBOX_SIZE_CHROMIUM
  220. 'unit_test': False,
  221. 'result': ['uint32_t'],
  222. 'trace_level': 2,
  223. },
  224. 'ConvertYUVAMailboxesToRGBINTERNAL': {
  225. 'decoder_func': 'DoConvertYUVAMailboxesToRGBINTERNAL',
  226. 'internal': True,
  227. 'type': 'PUT',
  228. 'count': 144, #GL_MAILBOX_SIZE_CHROMIUM x5 + 16 floats
  229. 'unit_test': False,
  230. 'trace_level': 2,
  231. },
  232. 'ConvertRGBAToYUVAMailboxesINTERNAL': {
  233. 'decoder_func': 'DoConvertRGBAToYUVAMailboxesINTERNAL',
  234. 'internal': True,
  235. 'type': 'PUT',
  236. 'count': 80, #GL_MAILBOX_SIZE_CHROMIUM x5
  237. 'unit_test': False,
  238. 'trace_level': 2,
  239. },
  240. 'Finish': {
  241. 'impl_func': False,
  242. 'client_test': False,
  243. 'decoder_func': 'DoFinish',
  244. 'unit_test': False,
  245. 'trace_level': 1,
  246. },
  247. 'Flush': {
  248. 'impl_func': False,
  249. 'decoder_func': 'DoFlush',
  250. 'unit_test': False,
  251. 'trace_level': 1,
  252. },
  253. 'GetError': {
  254. 'type': 'Is',
  255. 'decoder_func': 'GetErrorState()->GetGLError',
  256. 'impl_func': False,
  257. 'result': ['GLenum'],
  258. 'client_test': False,
  259. },
  260. 'GetGraphicsResetStatusKHR': {
  261. 'type': 'NoCommand',
  262. 'trace_level': 1,
  263. },
  264. 'GenQueriesEXT': {
  265. 'type': 'GENn',
  266. 'gl_test_func': 'glGenQueriesARB',
  267. 'resource_type': 'Query',
  268. 'resource_types': 'Queries',
  269. 'unit_test': False,
  270. 'not_shared': 'True',
  271. },
  272. 'DeleteQueriesEXT': {
  273. 'type': 'DELn',
  274. 'gl_test_func': 'glDeleteQueriesARB',
  275. 'resource_type': 'Query',
  276. 'resource_types': 'Queries',
  277. 'unit_test': False,
  278. },
  279. 'BeginQueryEXT': {
  280. 'type': 'Custom',
  281. 'impl_func': False,
  282. 'cmd_args': 'GLenumQueryTarget target, GLidQuery id, void* sync_data',
  283. 'data_transfer_methods': ['shm'],
  284. 'gl_test_func': 'glBeginQuery',
  285. },
  286. 'EndQueryEXT': {
  287. 'type': 'Custom',
  288. 'impl_func': False,
  289. 'cmd_args': 'GLenumQueryTarget target, GLuint submit_count',
  290. 'gl_test_func': 'glEndnQuery',
  291. 'client_test': False,
  292. },
  293. 'QueryCounterEXT' : {
  294. 'type': 'Custom',
  295. 'impl_func': False,
  296. 'cmd_args': 'GLidQuery id, GLenumQueryTarget target, '
  297. 'void* sync_data, GLuint submit_count',
  298. 'data_transfer_methods': ['shm'],
  299. 'gl_test_func': 'glQueryCounter',
  300. },
  301. 'GetQueryObjectuivEXT': {
  302. 'type': 'NoCommand',
  303. 'gl_test_func': 'glGetQueryObjectuiv',
  304. },
  305. 'GetQueryObjectui64vEXT': {
  306. 'type': 'NoCommand',
  307. 'gl_test_func': 'glGetQueryObjectui64v',
  308. },
  309. 'OrderingBarrierCHROMIUM': {
  310. 'type': 'NoCommand',
  311. },
  312. 'TraceBeginCHROMIUM': {
  313. 'type': 'Custom',
  314. 'impl_func': False,
  315. 'client_test': False,
  316. 'cmd_args': 'GLuint category_bucket_id, GLuint name_bucket_id',
  317. 'extension': 'CHROMIUM_trace_marker',
  318. },
  319. 'TraceEndCHROMIUM': {
  320. 'impl_func': False,
  321. 'client_test': False,
  322. 'decoder_func': 'DoTraceEndCHROMIUM',
  323. 'unit_test': False,
  324. 'extension': 'CHROMIUM_trace_marker',
  325. },
  326. 'SetActiveURLCHROMIUM': {
  327. 'type': 'Custom',
  328. 'impl_func': False,
  329. 'client_test': False,
  330. 'cmd_args': 'GLuint url_bucket_id',
  331. },
  332. 'LoseContextCHROMIUM': {
  333. 'decoder_func': 'DoLoseContextCHROMIUM',
  334. 'unit_test': False,
  335. 'trace_level': 1,
  336. },
  337. 'BeginRasterCHROMIUM': {
  338. 'decoder_func': 'DoBeginRasterCHROMIUM',
  339. 'type': 'PUT',
  340. 'count': 16, # GL_MAILBOX_SIZE_CHROMIUM
  341. 'internal': True,
  342. 'impl_func': False,
  343. 'unit_test': False,
  344. },
  345. 'RasterCHROMIUM': {
  346. 'decoder_func': 'DoRasterCHROMIUM',
  347. 'internal': True,
  348. 'impl_func': True,
  349. 'cmd_args': 'GLuint raster_shm_id, GLuint raster_shm_offset,'
  350. 'GLsizeiptr raster_shm_size, GLuint font_shm_id,'
  351. 'GLuint font_shm_offset, GLsizeiptr font_shm_size',
  352. 'extension': 'CHROMIUM_raster_transport',
  353. 'unit_test': False,
  354. },
  355. 'EndRasterCHROMIUM': {
  356. 'decoder_func': 'DoEndRasterCHROMIUM',
  357. 'impl_func': False,
  358. 'unit_test': False,
  359. 'client_test': False,
  360. },
  361. 'CreateTransferCacheEntryINTERNAL': {
  362. 'decoder_func': 'DoCreateTransferCacheEntryINTERNAL',
  363. 'cmd_args': 'GLuint entry_type, GLuint entry_id, GLuint handle_shm_id, '
  364. 'GLuint handle_shm_offset, GLuint data_shm_id, '
  365. 'GLuint data_shm_offset, GLuint data_size',
  366. 'internal': True,
  367. 'impl_func': True,
  368. 'client_test': False,
  369. 'unit_test': False,
  370. },
  371. 'DeleteTransferCacheEntryINTERNAL': {
  372. 'decoder_func': 'DoDeleteTransferCacheEntryINTERNAL',
  373. 'cmd_args': 'GLuint entry_type, GLuint entry_id',
  374. 'internal': True,
  375. 'impl_func': True,
  376. 'client_test': False,
  377. 'unit_test': False,
  378. },
  379. 'DeletePaintCachePathsINTERNAL': {
  380. 'type': 'DELn',
  381. 'internal': True,
  382. 'unit_test': False,
  383. },
  384. 'ClearPaintCacheINTERNAL': {
  385. 'decoder_func': 'DoClearPaintCacheINTERNAL',
  386. 'internal': True,
  387. 'unit_test': False,
  388. },
  389. 'UnlockTransferCacheEntryINTERNAL': {
  390. 'decoder_func': 'DoUnlockTransferCacheEntryINTERNAL',
  391. 'cmd_args': 'GLuint entry_type, GLuint entry_id',
  392. 'internal': True,
  393. 'impl_func': True,
  394. 'client_test': False,
  395. 'unit_test': False,
  396. },
  397. }
  398. def main(argv):
  399. """This is the main function."""
  400. parser = OptionParser()
  401. parser.add_option(
  402. "--output-dir",
  403. help="Output directory for generated files. Defaults to chromium root "
  404. "directory.")
  405. parser.add_option(
  406. "-v", "--verbose", action="store_true", help="Verbose logging output.")
  407. parser.add_option(
  408. "-c", "--check", action="store_true",
  409. help="Check if output files match generated files in chromium root "
  410. "directory. Use this in PRESUBMIT scripts with --output-dir.")
  411. (options, _) = parser.parse_args(args=argv)
  412. # This script lives under src/gpu/command_buffer.
  413. script_dir = os.path.dirname(os.path.abspath(__file__))
  414. assert script_dir.endswith(os.path.normpath("src/gpu/command_buffer"))
  415. # os.path.join doesn't do the right thing with relative paths.
  416. chromium_root_dir = os.path.abspath(script_dir + "/../..")
  417. # Support generating files under gen/ and for PRESUBMIT.
  418. if options.output_dir:
  419. output_dir = options.output_dir
  420. else:
  421. output_dir = chromium_root_dir
  422. os.chdir(output_dir)
  423. build_cmd_buffer_lib.InitializePrefix("Raster")
  424. gen = build_cmd_buffer_lib.GLGenerator(
  425. options.verbose, "2018", _FUNCTION_INFO, _NAMED_TYPE_INFO,
  426. chromium_root_dir)
  427. gen.ParseGLH("gpu/command_buffer/raster_cmd_buffer_functions.txt")
  428. gen.WriteCommandIds("gpu/command_buffer/common/raster_cmd_ids_autogen.h")
  429. gen.WriteFormat("gpu/command_buffer/common/raster_cmd_format_autogen.h")
  430. gen.WriteFormatTest(
  431. "gpu/command_buffer/common/raster_cmd_format_test_autogen.h")
  432. gen.WriteGLES2InterfaceHeader(
  433. "gpu/command_buffer/client/raster_interface_autogen.h")
  434. gen.WriteGLES2ImplementationHeader(
  435. "gpu/command_buffer/client/raster_implementation_autogen.h")
  436. gen.WriteGLES2Implementation(
  437. "gpu/command_buffer/client/raster_implementation_impl_autogen.h")
  438. gen.WriteGLES2ImplementationUnitTests(
  439. "gpu/command_buffer/client/raster_implementation_unittest_autogen.h")
  440. gen.WriteCmdHelperHeader(
  441. "gpu/command_buffer/client/raster_cmd_helper_autogen.h")
  442. gen.WriteServiceImplementation(
  443. "gpu/command_buffer/service/raster_decoder_autogen.h")
  444. gen.WriteServiceUnitTests(
  445. "gpu/command_buffer/service/raster_decoder_unittest_%d_autogen.h")
  446. gen.WriteServiceUtilsHeader(
  447. "gpu/command_buffer/service/raster_cmd_validation_autogen.h")
  448. gen.WriteServiceUtilsImplementation(
  449. "gpu/command_buffer/service/"
  450. "raster_cmd_validation_implementation_autogen.h")
  451. build_cmd_buffer_lib.Format(gen.generated_cpp_filenames, output_dir,
  452. chromium_root_dir)
  453. if gen.errors > 0:
  454. print("build_raster_cmd_buffer.py: Failed with %d errors" % gen.errors)
  455. return 1
  456. check_failed_filenames = []
  457. if options.check:
  458. for filename in gen.generated_cpp_filenames:
  459. if not filecmp.cmp(os.path.join(output_dir, filename),
  460. os.path.join(chromium_root_dir, filename)):
  461. check_failed_filenames.append(filename)
  462. if len(check_failed_filenames) > 0:
  463. print('Please run gpu/command_buffer/build_raster_cmd_buffer.py')
  464. print('Failed check on autogenerated command buffer files:')
  465. for filename in check_failed_filenames:
  466. print(filename)
  467. return 1
  468. return 0
  469. if __name__ == '__main__':
  470. sys.exit(main(sys.argv[1:]))