xbintsc 0.7.0 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (351) hide show
  1. package/dist/src/ast/common.d.ts +10 -0
  2. package/dist/src/binder/references.js +13 -7
  3. package/dist/src/binder/references.js.map +1 -1
  4. package/dist/src/checker/source.js +4 -0
  5. package/dist/src/checker/source.js.map +1 -1
  6. package/dist/src/cli/help.d.ts +1 -1
  7. package/dist/src/cli/main.js +15 -3
  8. package/dist/src/cli/main.js.map +1 -1
  9. package/dist/src/codegen/generator/calls/access.js +4 -11
  10. package/dist/src/codegen/generator/calls/access.js.map +1 -1
  11. package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
  12. package/dist/src/codegen/generator/calls/element-inline.js +388 -0
  13. package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
  14. package/dist/src/codegen/generator/calls/invocation.js +82 -1
  15. package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
  16. package/dist/src/codegen/generator/calls.d.ts +3 -1
  17. package/dist/src/codegen/generator/calls.js +3 -1
  18. package/dist/src/codegen/generator/calls.js.map +1 -1
  19. package/dist/src/codegen/generator/debug.js +20 -3
  20. package/dist/src/codegen/generator/debug.js.map +1 -1
  21. package/dist/src/codegen/generator/expressions/assignment.js +10 -2
  22. package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
  23. package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
  24. package/dist/src/codegen/generator/expressions/global-values.js +49 -0
  25. package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
  26. package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
  27. package/dist/src/codegen/generator/expressions/primary.js +4 -24
  28. package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
  29. package/dist/src/codegen/generator/expressions.d.ts +2 -1
  30. package/dist/src/codegen/generator/expressions.js +2 -1
  31. package/dist/src/codegen/generator/expressions.js.map +1 -1
  32. package/dist/src/codegen/generator/layout.d.ts +65 -0
  33. package/dist/src/codegen/generator/layout.js +50 -0
  34. package/dist/src/codegen/generator/layout.js.map +1 -0
  35. package/dist/src/codegen/generator/state.js +4 -0
  36. package/dist/src/codegen/generator/state.js.map +1 -1
  37. package/dist/src/diagnostics/diagnostic.js +1 -1
  38. package/dist/src/diagnostics/diagnostic.js.map +1 -1
  39. package/dist/src/diagnostics/source-text.d.ts +37 -9
  40. package/dist/src/diagnostics/source-text.js +124 -23
  41. package/dist/src/diagnostics/source-text.js.map +1 -1
  42. package/dist/src/diagnostics/source.d.ts +16 -6
  43. package/dist/src/diagnostics/source.js +25 -4
  44. package/dist/src/diagnostics/source.js.map +1 -1
  45. package/dist/src/driver/build-key.d.ts +14 -0
  46. package/dist/src/driver/build-key.js +6 -1
  47. package/dist/src/driver/build-key.js.map +1 -1
  48. package/dist/src/driver/bundler/concatenate.js +11 -4
  49. package/dist/src/driver/bundler/concatenate.js.map +1 -1
  50. package/dist/src/driver/bundler/graph.js +2 -2
  51. package/dist/src/driver/bundler/graph.js.map +1 -1
  52. package/dist/src/driver/bundler/merge.js +11 -5
  53. package/dist/src/driver/bundler/merge.js.map +1 -1
  54. package/dist/src/driver/bundler/reexport-resolution.js +3 -0
  55. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
  56. package/dist/src/driver/compiler.js +13 -3
  57. package/dist/src/driver/compiler.js.map +1 -1
  58. package/dist/src/driver/frontend.js +3 -4
  59. package/dist/src/driver/frontend.js.map +1 -1
  60. package/dist/src/driver/runtime-objects.d.ts +1 -1
  61. package/dist/src/driver/runtime-objects.js +4 -0
  62. package/dist/src/driver/runtime-objects.js.map +1 -1
  63. package/dist/src/driver/toolchain.js +28 -5
  64. package/dist/src/driver/toolchain.js.map +1 -1
  65. package/dist/src/driver/version.d.ts +1 -1
  66. package/dist/src/driver/version.js +1 -1
  67. package/dist/src/extensions/gui/html.js +42 -10
  68. package/dist/src/extensions/gui/html.js.map +1 -1
  69. package/dist/src/extensions/gui/index.js +53 -0
  70. package/dist/src/extensions/gui/index.js.map +1 -1
  71. package/dist/src/extensions/registry.d.ts +20 -0
  72. package/dist/src/extensions/registry.js.map +1 -1
  73. package/dist/src/parser/expressions.js +2 -2
  74. package/dist/src/parser/expressions.js.map +1 -1
  75. package/dist/src/parser/helpers.d.ts +8 -0
  76. package/dist/src/parser/helpers.js +21 -0
  77. package/dist/src/parser/helpers.js.map +1 -1
  78. package/dist/tests/binder/binder.test.js +26 -4
  79. package/dist/tests/binder/binder.test.js.map +1 -1
  80. package/dist/tests/checker/checker.test.js +16 -0
  81. package/dist/tests/checker/checker.test.js.map +1 -1
  82. package/dist/tests/cli/main.test.js +9 -0
  83. package/dist/tests/cli/main.test.js.map +1 -1
  84. package/dist/tests/codegen/element-layout.test.d.ts +19 -0
  85. package/dist/tests/codegen/element-layout.test.js +80 -0
  86. package/dist/tests/codegen/element-layout.test.js.map +1 -0
  87. package/dist/tests/codegen/expressions.test.js +25 -0
  88. package/dist/tests/codegen/expressions.test.js.map +1 -1
  89. package/dist/tests/codegen/llvm.test.js +13 -0
  90. package/dist/tests/codegen/llvm.test.js.map +1 -1
  91. package/dist/tests/diagnostics/diagnostic.test.js +9 -0
  92. package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
  93. package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
  94. package/dist/tests/diagnostics/source-text.test.js +50 -0
  95. package/dist/tests/diagnostics/source-text.test.js.map +1 -0
  96. package/dist/tests/diagnostics/source.test.js +17 -0
  97. package/dist/tests/diagnostics/source.test.js.map +1 -1
  98. package/dist/tests/driver/build-key.test.d.ts +1 -0
  99. package/dist/tests/driver/build-key.test.js +49 -0
  100. package/dist/tests/driver/build-key.test.js.map +1 -0
  101. package/dist/tests/driver/toolchain.test.js +8 -1
  102. package/dist/tests/driver/toolchain.test.js.map +1 -1
  103. package/dist/tests/driver/usage.test.js +2 -1
  104. package/dist/tests/driver/usage.test.js.map +1 -1
  105. package/dist/tests/e2e/async-await.test.js +16 -0
  106. package/dist/tests/e2e/async-await.test.js.map +1 -1
  107. package/dist/tests/e2e/compile-builtins.test.js +29 -0
  108. package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
  109. package/dist/tests/e2e/compile-modules.test.js +13 -0
  110. package/dist/tests/e2e/compile-modules.test.js.map +1 -1
  111. package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
  112. package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
  113. package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
  114. package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
  115. package/dist/tests/e2e/differential-language.test.js +25 -0
  116. package/dist/tests/e2e/differential-language.test.js.map +1 -1
  117. package/dist/tests/e2e/differential-values.test.js +59 -0
  118. package/dist/tests/e2e/differential-values.test.js.map +1 -1
  119. package/dist/tests/e2e/gc.test.js +22 -0
  120. package/dist/tests/e2e/gc.test.js.map +1 -1
  121. package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
  122. package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
  123. package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
  124. package/dist/tests/e2e/gui-browser.test.js +66 -2
  125. package/dist/tests/e2e/gui-browser.test.js.map +1 -1
  126. package/dist/tests/e2e/gui-dom.test.js +88 -0
  127. package/dist/tests/e2e/gui-dom.test.js.map +1 -1
  128. package/dist/tests/e2e/gui-events.test.js +89 -0
  129. package/dist/tests/e2e/gui-events.test.js.map +1 -1
  130. package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
  131. package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
  132. package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
  133. package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
  134. package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
  135. package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
  136. package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
  137. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
  138. package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
  139. package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
  140. package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
  141. package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
  142. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
  143. package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
  144. package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
  145. package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
  146. package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
  147. package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
  148. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
  149. package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
  150. package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
  151. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
  152. package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
  153. package/dist/tests/e2e/gui-webgl2.test.js +59 -1
  154. package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
  155. package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
  156. package/dist/tests/e2e/hang-watchdog.test.js +50 -0
  157. package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
  158. package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
  159. package/dist/tests/e2e/method-call-cache.test.js +65 -0
  160. package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
  161. package/dist/tests/e2e/performance-now.test.d.ts +9 -0
  162. package/dist/tests/e2e/performance-now.test.js +36 -0
  163. package/dist/tests/e2e/performance-now.test.js.map +1 -0
  164. package/dist/tests/e2e/property-ic.test.js +33 -0
  165. package/dist/tests/e2e/property-ic.test.js.map +1 -1
  166. package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
  167. package/dist/tests/e2e/shape-interning.test.js +55 -0
  168. package/dist/tests/e2e/shape-interning.test.js.map +1 -0
  169. package/dist/tests/e2e/string-utf16.test.js +9 -0
  170. package/dist/tests/e2e/string-utf16.test.js.map +1 -1
  171. package/dist/tests/e2e/typed-array-views.test.js +26 -0
  172. package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
  173. package/dist/tests/e2e/url-search-params.test.js +19 -0
  174. package/dist/tests/e2e/url-search-params.test.js.map +1 -1
  175. package/dist/tests/extensions/gui.test.js +16 -1
  176. package/dist/tests/extensions/gui.test.js.map +1 -1
  177. package/dist/tests/helpers.js +1 -0
  178. package/dist/tests/helpers.js.map +1 -1
  179. package/dist/tests/parser/expressions.test.js +36 -0
  180. package/dist/tests/parser/expressions.test.js.map +1 -1
  181. package/doc/ai/contributing.md +8 -5
  182. package/doc/ai/extensions.md +12 -3
  183. package/doc/ai/language-support.md +2 -1
  184. package/doc/ai/troubleshooting.md +14 -0
  185. package/doc/ai/zh-CN/contributing.md +6 -3
  186. package/doc/ai/zh-CN/extensions.md +10 -2
  187. package/doc/ai/zh-CN/language-support.md +2 -1
  188. package/doc/ai/zh-CN/troubleshooting.md +12 -0
  189. package/doc/gui/api.md +35 -4
  190. package/doc/gui/dom.md +8 -0
  191. package/doc/gui/input.md +8 -0
  192. package/doc/gui/known-issues.md +43 -6
  193. package/doc/gui/runtime.md +16 -1
  194. package/doc/gui/webgl.md +97 -26
  195. package/doc/gui-scripts.md +2 -1
  196. package/doc/gui.md +8 -5
  197. package/doc/implemented/binder.md +1 -1
  198. package/doc/implemented/checker.md +9 -0
  199. package/doc/implemented/codegen.md +7 -0
  200. package/doc/implemented/parser.md +2 -1
  201. package/doc/implemented/runtime-core.md +9 -2
  202. package/doc/implemented/stdlib.md +10 -2
  203. package/doc/implemented/typed-arrays.md +18 -2
  204. package/doc/zh-CN/gui/api.md +27 -5
  205. package/doc/zh-CN/gui/dom.md +6 -0
  206. package/doc/zh-CN/gui/input.md +7 -0
  207. package/doc/zh-CN/gui/known-issues.md +30 -5
  208. package/doc/zh-CN/gui/runtime.md +13 -1
  209. package/doc/zh-CN/gui/webgl.md +20 -7
  210. package/doc/zh-CN/gui-scripts.md +2 -1
  211. package/doc/zh-CN/gui.md +4 -1
  212. package/doc/zh-CN/implemented/binder.md +1 -1
  213. package/doc/zh-CN/implemented/checker.md +7 -0
  214. package/doc/zh-CN/implemented/codegen.md +7 -0
  215. package/doc/zh-CN/implemented/parser.md +2 -1
  216. package/doc/zh-CN/implemented/runtime-core.md +9 -2
  217. package/doc/zh-CN/implemented/stdlib.md +6 -2
  218. package/doc/zh-CN/implemented/typed-arrays.md +14 -2
  219. package/package.json +7 -7
  220. package/runtime/ext_gui/audio.cpp +39 -3
  221. package/runtime/ext_gui/audio_extra.cpp +353 -0
  222. package/runtime/ext_gui/audio_extra.h +47 -0
  223. package/runtime/ext_gui/audio_fft.h +76 -0
  224. package/runtime/ext_gui/audio_internal.h +21 -0
  225. package/runtime/ext_gui/audio_mixer.cpp +46 -1
  226. package/runtime/ext_gui/audio_mixer.h +89 -1
  227. package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
  228. package/runtime/ext_gui/audio_nodes.cpp +242 -0
  229. package/runtime/ext_gui/audio_nodes_internal.h +81 -0
  230. package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
  231. package/runtime/ext_gui/browser.cpp +11 -0
  232. package/runtime/ext_gui/browser_screen.cpp +73 -0
  233. package/runtime/ext_gui/dom_api.cpp +4 -0
  234. package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
  235. package/runtime/ext_gui/dom_api_events.cpp +2 -1
  236. package/runtime/ext_gui/dom_api_internal.h +11 -0
  237. package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
  238. package/runtime/ext_gui/dom_api_node.cpp +21 -0
  239. package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
  240. package/runtime/ext_gui/dom_api_proto.cpp +6 -0
  241. package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
  242. package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
  243. package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
  244. package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
  245. package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
  246. package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
  247. package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
  248. package/runtime/ext_gui/gui.cpp +8 -1
  249. package/runtime/ext_gui/gui_engine.h +20 -2
  250. package/runtime/ext_gui/gui_events.cpp +31 -126
  251. package/runtime/ext_gui/gui_input.cpp +148 -0
  252. package/runtime/ext_gui/gui_webgl.cpp +3 -2
  253. package/runtime/ext_gui/pointer_lock.cpp +137 -0
  254. package/runtime/ext_gui/style_ua.cpp +4 -0
  255. package/runtime/ext_gui/warnings.cpp +1 -1
  256. package/runtime/ext_gui/webgl.h +102 -7
  257. package/runtime/ext_gui/webgl_api.h +3 -2
  258. package/runtime/ext_gui/webgl_blit.cpp +109 -15
  259. package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
  260. package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
  261. package/runtime/ext_gui/webgl_buffer.cpp +26 -170
  262. package/runtime/ext_gui/webgl_context.cpp +119 -169
  263. package/runtime/ext_gui/webgl_draw.cpp +116 -5
  264. package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
  265. package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
  266. package/runtime/ext_gui/webgl_draw_state.h +2 -0
  267. package/runtime/ext_gui/webgl_feature.cpp +2 -2
  268. package/runtime/ext_gui/webgl_feature.h +4 -3
  269. package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
  270. package/runtime/ext_gui/webgl_glsl.h +4 -0
  271. package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
  272. package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
  273. package/runtime/ext_gui/webgl_objects.h +18 -2
  274. package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
  275. package/runtime/ext_gui/webgl_shader.cpp +1 -1
  276. package/runtime/ext_gui/webgl_state.cpp +45 -36
  277. package/runtime/ext_gui/webgl_targets.cpp +440 -0
  278. package/runtime/ext_gui/webgl_texture.cpp +81 -25
  279. package/runtime/ext_gui/window.cpp +11 -83
  280. package/runtime/ext_gui/window_diagnostics.cpp +94 -1
  281. package/runtime/rt.h +27 -27
  282. package/runtime/rt_binary.h +44 -0
  283. package/runtime/rt_internal.h +52 -60
  284. package/runtime/rt_object.h +83 -0
  285. package/runtime/rt_profile.h +45 -0
  286. package/runtime/xt_alloc.c +88 -133
  287. package/runtime/xt_array_buffer.c +99 -71
  288. package/runtime/xt_builtins.c +3 -1
  289. package/runtime/xt_constructors.c +1 -0
  290. package/runtime/xt_containers/access.inc +96 -11
  291. package/runtime/xt_containers/arrays.inc +2 -1
  292. package/runtime/xt_containers/cstr_cache.inc +56 -0
  293. package/runtime/xt_containers/method_cache.inc +121 -0
  294. package/runtime/xt_containers/object_keys.inc +58 -0
  295. package/runtime/xt_containers/objects.inc +47 -79
  296. package/runtime/xt_containers/shapes.inc +153 -8
  297. package/runtime/xt_containers.c +4 -0
  298. package/runtime/xt_gc_release.c +70 -0
  299. package/runtime/xt_gc_stack.c +83 -0
  300. package/runtime/xt_gc_verify.c +1 -0
  301. package/runtime/xt_io/console.inc +66 -0
  302. package/runtime/xt_io/exception.inc +32 -6
  303. package/runtime/xt_io/watchdog.inc +101 -0
  304. package/runtime/xt_io.c +1 -0
  305. package/runtime/xt_loop.c +23 -3
  306. package/runtime/xt_pool.c +151 -0
  307. package/runtime/xt_profile.c +126 -0
  308. package/runtime/xt_stdlib/dispatch.inc +7 -1
  309. package/runtime/xt_stdlib/math.inc +272 -57
  310. package/runtime/xt_stdlib2/json_stringify.inc +1 -2
  311. package/runtime/xt_stdlib2/regexp-match.inc +17 -0
  312. package/runtime/xt_storage/indexed_db.c +4 -1
  313. package/runtime/xt_structured_clone.c +2 -1
  314. package/runtime/xt_typed_array/construction.inc +10 -0
  315. package/runtime/xt_typed_array/elements.inc +43 -23
  316. package/runtime/xt_url.c +50 -0
  317. package/runtime/xt_values/constructors.inc +4 -1
  318. package/runtime/xt_values/strings.inc +3 -1
  319. package/src/ast/common.ts +10 -0
  320. package/src/binder/references.ts +13 -7
  321. package/src/checker/source.ts +3 -0
  322. package/src/cli/main.ts +14 -3
  323. package/src/codegen/generator/calls/access.ts +5 -10
  324. package/src/codegen/generator/calls/element-inline.ts +433 -0
  325. package/src/codegen/generator/calls/invocation.ts +87 -1
  326. package/src/codegen/generator/calls.ts +5 -0
  327. package/src/codegen/generator/debug.ts +21 -3
  328. package/src/codegen/generator/expressions/assignment.ts +11 -2
  329. package/src/codegen/generator/expressions/global-values.ts +57 -0
  330. package/src/codegen/generator/expressions/primary.ts +4 -27
  331. package/src/codegen/generator/expressions.ts +3 -0
  332. package/src/codegen/generator/layout.ts +54 -0
  333. package/src/codegen/generator/state.ts +5 -0
  334. package/src/diagnostics/diagnostic.ts +1 -1
  335. package/src/diagnostics/source-text.ts +118 -22
  336. package/src/diagnostics/source.ts +29 -7
  337. package/src/driver/build-key.ts +21 -1
  338. package/src/driver/bundler/concatenate.ts +12 -5
  339. package/src/driver/bundler/graph.ts +2 -2
  340. package/src/driver/bundler/merge.ts +11 -4
  341. package/src/driver/bundler/reexport-resolution.ts +2 -0
  342. package/src/driver/compiler.ts +14 -3
  343. package/src/driver/frontend.ts +3 -4
  344. package/src/driver/runtime-objects.ts +4 -0
  345. package/src/driver/toolchain.ts +28 -5
  346. package/src/driver/version.ts +1 -1
  347. package/src/extensions/gui/html.ts +41 -11
  348. package/src/extensions/gui/index.ts +55 -1
  349. package/src/extensions/registry.ts +20 -0
  350. package/src/parser/expressions.ts +2 -2
  351. package/src/parser/helpers.ts +22 -0
@@ -174,45 +174,54 @@ void WebGLContext::clear(int mask) {
174
174
  }
175
175
  if (color_bit) {
176
176
  SDL_GPUTexture *source = clear_color_texture();
177
- SDL_GPUTexture *destination = target_color();
178
177
  int target_width = 0;
179
178
  int target_height = 0;
180
179
  framebuffer_size(bound_framebuffer_, &target_width, &target_height);
181
- if (source != nullptr && destination != nullptr && target_width > 0 && target_height > 0) {
182
- end_pass();
183
- ensure_command();
184
- if (cmd_ != nullptr) {
185
- int x = std::max(0, scissor_box_[0]);
186
- int y = std::max(0, scissor_box_[1]);
187
- int w = scissor_box_[2];
188
- int h = scissor_box_[3];
189
- if (x + w > target_width) w = target_width - x;
190
- if (y + h > target_height) h = target_height - y;
191
- if (w > 0 && h > 0) {
192
- SDL_GPUBlitRegion source_region;
193
- memset(&source_region, 0, sizeof(source_region));
194
- source_region.texture = source;
195
- source_region.w = 1;
196
- source_region.h = 1;
197
- SDL_GPUBlitRegion destination_region;
198
- memset(&destination_region, 0, sizeof(destination_region));
199
- destination_region.texture = destination;
200
- destination_region.x = (Uint32)x;
201
- destination_region.y = (Uint32)(target_height - (y + h));
202
- destination_region.w = (Uint32)w;
203
- destination_region.h = (Uint32)h;
204
- SDL_GPUBlitInfo info;
205
- memset(&info, 0, sizeof(info));
206
- info.source = source_region;
207
- info.destination = destination_region;
208
- /* The pixels outside the scissor rectangle must survive the clear, so
209
- * the blit has to load the destination. DONT_CARE maps to Metal's
210
- * MTLLoadActionDontCare, which discards the whole attachment before
211
- * the blit writes its region and leaves the rest undefined (Vulkan
212
- * happened to preserve it, which hid this in CI on Linux). */
213
- info.load_op = SDL_GPU_LOADOP_LOAD;
214
- info.filter = SDL_GPU_FILTER_NEAREST;
215
- SDL_BlitGPUTexture(cmd_, &info);
180
+ if (source != nullptr && target_width > 0 && target_height > 0) {
181
+ int x = std::max(0, scissor_box_[0]);
182
+ int y = std::max(0, scissor_box_[1]);
183
+ int w = scissor_box_[2];
184
+ int h = scissor_box_[3];
185
+ if (x + w > target_width) w = target_width - x;
186
+ if (y + h > target_height) h = target_height - y;
187
+ if (w > 0 && h > 0) {
188
+ const int destination[4] = {x, y, x + w, y + h};
189
+ if (target_samples() > 1) {
190
+ /* A multisampled texture cannot be the destination of a GPU blit;
191
+ * the quad draws the same clear rectangle into the MSAA target. */
192
+ const int source_rect[4] = {0, 0, 1, 1};
193
+ draw_color_quad(source, true, source_rect, 1, 1, destination);
194
+ } else {
195
+ end_pass();
196
+ ensure_command();
197
+ if (cmd_ != nullptr) {
198
+ SDL_GPUBlitRegion source_region;
199
+ memset(&source_region, 0, sizeof(source_region));
200
+ source_region.texture = source;
201
+ source_region.w = 1;
202
+ source_region.h = 1;
203
+ SDL_GPUBlitRegion destination_region;
204
+ memset(&destination_region, 0, sizeof(destination_region));
205
+ destination_region.texture = target_color();
206
+ destination_region.x = (Uint32)x;
207
+ destination_region.y = (Uint32)webgl_target_rect_y(
208
+ webgl_target_top_down(bound_framebuffer_), target_height, y, h);
209
+ destination_region.w = (Uint32)w;
210
+ destination_region.h = (Uint32)h;
211
+ SDL_GPUBlitInfo info;
212
+ memset(&info, 0, sizeof(info));
213
+ info.source = source_region;
214
+ info.destination = destination_region;
215
+ /* The pixels outside the scissor rectangle must survive the clear,
216
+ * so the blit has to load the destination. DONT_CARE maps to
217
+ * Metal's MTLLoadActionDontCare, which discards the whole
218
+ * attachment before the blit writes its region and leaves the rest
219
+ * undefined (Vulkan happened to preserve it, which hid this in CI
220
+ * on Linux). */
221
+ info.load_op = SDL_GPU_LOADOP_LOAD;
222
+ info.filter = SDL_GPU_FILTER_NEAREST;
223
+ SDL_BlitGPUTexture(cmd_, &info);
224
+ }
216
225
  }
217
226
  }
218
227
  }
@@ -0,0 +1,440 @@
1
+ /*
2
+ * xbintsc GUI engine — WebGL render targets, resolves and render passes.
3
+ *
4
+ * A context renders either into the multisampled default drawing buffer (which
5
+ * every pass resolves into the composited colour texture), into a
6
+ * single-sampled default target, or into a user framebuffer whose colour and
7
+ * depth attachments may themselves be multisampled. This unit owns the target
8
+ * lookup, the scratch resolve texture, `readPixels`'s resolved source and the
9
+ * render pass itself; lifetime and object tables stay in `webgl_context.cpp`.
10
+ */
11
+
12
+ #include "webgl.h"
13
+
14
+ #include <algorithm>
15
+ #include <cstring>
16
+
17
+ #include "gui_internal.h"
18
+ #include "perf.h"
19
+
20
+ namespace xtgui {
21
+
22
+ namespace {
23
+
24
+ /** `XT_GUI_TRACE=1` prints the WebGL resolve/blit/render-pass sequence and the
25
+ * SDL error of the first failing call, for diagnosing a lost Vulkan device. */
26
+ bool trace_enabled() {
27
+ static int value = -1;
28
+ if (value < 0) {
29
+ const char *env = SDL_getenv("XT_GUI_TRACE");
30
+ value = (env != nullptr && env[0] != '\0' && env[0] != '0') ? 1 : 0;
31
+ }
32
+ return value != 0;
33
+ }
34
+
35
+ } // namespace
36
+
37
+ /* -- passes -------------------------------------------------------------- */
38
+
39
+ SDL_GPUTexture *WebGLContext::target_color() { return draw_color_texture(0); }
40
+
41
+ SDL_GPUTexture *WebGLContext::color_attachment(uint32_t id, int index, int *format,
42
+ int *samples, int *width, int *height) {
43
+ *format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
44
+ *samples = 1;
45
+ if (index < 0 || index >= kWebGLMaxDrawBuffers) return nullptr;
46
+ if (id == 0) {
47
+ ensure_default_target();
48
+ *width = width_;
49
+ *height = height_;
50
+ return color_;
51
+ }
52
+ WebGLFramebuffer *framebuffer_ = framebuffer(id);
53
+ if (framebuffer_ == nullptr) return nullptr;
54
+ *width = framebuffer_->width;
55
+ *height = framebuffer_->height;
56
+ if (framebuffer_->color_textures[index] != 0) {
57
+ WebGLTexture *texture_ = texture(framebuffer_->color_textures[index]);
58
+ if (texture_ == nullptr) return nullptr;
59
+ /* The attachment may have been bound before its storage was defined (three.js
60
+ * re-binds a render target's texture on every resize, then allocates it with
61
+ * `texImage2D`). Resolve the size from the attachment instead of the size
62
+ * cached when it was attached, or the framebuffer stays 0x0 and incomplete
63
+ * and every draw into it is silently dropped. */
64
+ if (texture_->width > 0 && texture_->height > 0) {
65
+ framebuffer_->width = texture_->width;
66
+ framebuffer_->height = texture_->height;
67
+ *width = texture_->width;
68
+ *height = texture_->height;
69
+ }
70
+ *format = (int)texture_->format;
71
+ *samples = texture_->samples;
72
+ return ensure_texture_gpu(texture_, true);
73
+ }
74
+ if (framebuffer_->color_renderbuffers[index] != 0) {
75
+ WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer_->color_renderbuffers[index]);
76
+ if (renderbuffer_ == nullptr) return nullptr;
77
+ if (renderbuffer_->width > 0 && renderbuffer_->height > 0) {
78
+ framebuffer_->width = renderbuffer_->width;
79
+ framebuffer_->height = renderbuffer_->height;
80
+ *width = renderbuffer_->width;
81
+ *height = renderbuffer_->height;
82
+ }
83
+ *format = (int)renderbuffer_->format;
84
+ *samples = renderbuffer_->samples;
85
+ return renderbuffer_->gpu;
86
+ }
87
+ return nullptr;
88
+ }
89
+
90
+ SDL_GPUTexture *WebGLContext::framebuffer_color(uint32_t id) {
91
+ int format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
92
+ int samples = 1;
93
+ int width = 0;
94
+ int height = 0;
95
+ return color_attachment(id, 0, &format, &samples, &width, &height);
96
+ }
97
+
98
+ void WebGLContext::framebuffer_size(uint32_t id, int *width, int *height) {
99
+ if (id == 0) {
100
+ *width = width_;
101
+ *height = height_;
102
+ return;
103
+ }
104
+ WebGLFramebuffer *framebuffer_ = framebuffer(id);
105
+ if (framebuffer_ == nullptr) {
106
+ *width = 0;
107
+ *height = 0;
108
+ return;
109
+ }
110
+ /* Read the attachment's real size: a target re-bound after a resize only knows
111
+ * it once its storage exists, not from the size cached at attach time. This
112
+ * must not allocate anything, so it reads the records directly. */
113
+ for (int index = 0; index < kWebGLMaxDrawBuffers; index++) {
114
+ if (framebuffer_->color_textures[index] != 0) {
115
+ WebGLTexture *texture_ = texture(framebuffer_->color_textures[index]);
116
+ if (texture_ != nullptr && texture_->width > 0 && texture_->height > 0) {
117
+ framebuffer_->width = texture_->width;
118
+ framebuffer_->height = texture_->height;
119
+ break;
120
+ }
121
+ }
122
+ if (framebuffer_->color_renderbuffers[index] != 0) {
123
+ WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer_->color_renderbuffers[index]);
124
+ if (renderbuffer_ != nullptr && renderbuffer_->width > 0 && renderbuffer_->height > 0) {
125
+ framebuffer_->width = renderbuffer_->width;
126
+ framebuffer_->height = renderbuffer_->height;
127
+ break;
128
+ }
129
+ }
130
+ }
131
+ *width = framebuffer_->width;
132
+ *height = framebuffer_->height;
133
+ }
134
+
135
+ SDL_GPUTexture *WebGLContext::target_depth() {
136
+ return framebuffer_depth(bound_framebuffer_);
137
+ }
138
+
139
+ SDL_GPUTexture *WebGLContext::framebuffer_depth(uint32_t id) {
140
+ if (id == 0) {
141
+ ensure_default_target();
142
+ return depth_;
143
+ }
144
+ WebGLFramebuffer *framebuffer = this->framebuffer(id);
145
+ if (framebuffer == nullptr) return nullptr;
146
+ if (framebuffer->depth_renderbuffer != 0) {
147
+ WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer->depth_renderbuffer);
148
+ return renderbuffer_ != nullptr ? renderbuffer_->gpu : nullptr;
149
+ }
150
+ if (framebuffer->depth_texture != 0) {
151
+ WebGLTexture *texture = this->texture(framebuffer->depth_texture);
152
+ if (texture == nullptr) return nullptr;
153
+ texture->as_depth_target = true;
154
+ return ensure_texture_gpu(texture, true);
155
+ }
156
+ if (framebuffer->depth == nullptr && framebuffer->width > 0 && framebuffer->height > 0 &&
157
+ guidev::g_device != nullptr) {
158
+ SDL_GPUTextureCreateInfo info;
159
+ memset(&info, 0, sizeof(info));
160
+ info.type = SDL_GPU_TEXTURETYPE_2D;
161
+ info.format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
162
+ info.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
163
+ info.width = (Uint32)framebuffer->width;
164
+ info.height = (Uint32)framebuffer->height;
165
+ info.layer_count_or_depth = 1;
166
+ info.num_levels = 1;
167
+ /* The auto depth buffer must match the colour attachment's sample count or
168
+ * the render pass is invalid. */
169
+ info.sample_count = webgl_sample_count(framebuffer_samples(id));
170
+ framebuffer->depth = SDL_CreateGPUTexture(guidev::g_device, &info);
171
+ }
172
+ return framebuffer->depth;
173
+ }
174
+
175
+ int WebGLContext::target_color_format() {
176
+ int format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
177
+ int samples = 1;
178
+ int width = 0;
179
+ int height = 0;
180
+ return color_attachment(bound_framebuffer_, 0, &format, &samples, &width, &height) != nullptr
181
+ ? format
182
+ : SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
183
+ }
184
+
185
+ int WebGLContext::target_depth_format() {
186
+ if (bound_framebuffer_ != 0) {
187
+ WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
188
+ if (framebuffer != nullptr) {
189
+ if (framebuffer->depth_renderbuffer != 0) {
190
+ WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer->depth_renderbuffer);
191
+ if (renderbuffer_ != nullptr) return (int)renderbuffer_->format;
192
+ }
193
+ if (framebuffer->depth_texture != 0) {
194
+ WebGLTexture *texture = this->texture(framebuffer->depth_texture);
195
+ if (texture != nullptr) return (int)texture->format;
196
+ }
197
+ }
198
+ }
199
+ return SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
200
+ }
201
+
202
+ int WebGLContext::draw_color_samples(int slot) {
203
+ if (bound_framebuffer_ == 0) return default_samples_;
204
+ WebGLFramebuffer *framebuffer_ = framebuffer(bound_framebuffer_);
205
+ if (framebuffer_ == nullptr) return 1;
206
+ const int index = framebuffer_->draw_buffers[slot] - GL_COLOR_ATTACHMENT0;
207
+ if (index < 0 || index >= kWebGLMaxDrawBuffers) return 1;
208
+ int format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
209
+ int samples = 1;
210
+ int width = 0;
211
+ int height = 0;
212
+ return color_attachment(bound_framebuffer_, index, &format, &samples, &width, &height) !=
213
+ nullptr
214
+ ? samples
215
+ : 1;
216
+ }
217
+
218
+ int WebGLContext::framebuffer_samples(uint32_t id) {
219
+ if (id == 0) return default_samples_;
220
+ WebGLFramebuffer *framebuffer_ = framebuffer(id);
221
+ if (framebuffer_ == nullptr) return 1;
222
+ for (int index = 0; index < kWebGLMaxDrawBuffers; index++) {
223
+ int format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
224
+ int samples = 1;
225
+ int width = 0;
226
+ int height = 0;
227
+ if (color_attachment(id, index, &format, &samples, &width, &height) != nullptr) return samples;
228
+ }
229
+ return 1;
230
+ }
231
+
232
+ int WebGLContext::target_samples() {
233
+ if (bound_framebuffer_ == 0) return default_samples_;
234
+ for (int slot = 0; slot < kWebGLMaxDrawBuffers; slot++) {
235
+ if (draw_color_texture(slot) != nullptr) return draw_color_samples(slot);
236
+ }
237
+ return 1;
238
+ }
239
+
240
+ SDL_GPUTexture *WebGLContext::ensure_resolve_target(int width, int height,
241
+ SDL_GPUTextureFormat format) {
242
+ if (guidev::g_device == nullptr || width <= 0 || height <= 0) return nullptr;
243
+ if (resolve_texture_ != nullptr && resolve_width_ == width && resolve_height_ == height &&
244
+ resolve_format_ == format) {
245
+ return resolve_texture_;
246
+ }
247
+ if (resolve_texture_ != nullptr) {
248
+ submit();
249
+ SDL_WaitForGPUIdle(guidev::g_device);
250
+ SDL_ReleaseGPUTexture(guidev::g_device, resolve_texture_);
251
+ resolve_texture_ = nullptr;
252
+ }
253
+ SDL_GPUTextureCreateInfo info;
254
+ memset(&info, 0, sizeof(info));
255
+ info.type = SDL_GPU_TEXTURETYPE_2D;
256
+ info.format = format;
257
+ info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
258
+ info.width = (Uint32)width;
259
+ info.height = (Uint32)height;
260
+ info.layer_count_or_depth = 1;
261
+ info.num_levels = 1;
262
+ info.sample_count = SDL_GPU_SAMPLECOUNT_1;
263
+ resolve_texture_ = SDL_CreateGPUTexture(guidev::g_device, &info);
264
+ if (resolve_texture_ == nullptr) {
265
+ set_error(GL_OUT_OF_MEMORY);
266
+ return nullptr;
267
+ }
268
+ resolve_width_ = width;
269
+ resolve_height_ = height;
270
+ resolve_format_ = format;
271
+ return resolve_texture_;
272
+ }
273
+
274
+ bool WebGLContext::resolve_color_pass(SDL_GPUTexture *source, SDL_GPUTexture *destination) {
275
+ if (source == nullptr || destination == nullptr || guidev::g_device == nullptr) return false;
276
+ end_pass();
277
+ ensure_command();
278
+ if (cmd_ == nullptr) return false;
279
+ SDL_GPUColorTargetInfo info;
280
+ memset(&info, 0, sizeof(info));
281
+ info.texture = source;
282
+ info.load_op = SDL_GPU_LOADOP_LOAD;
283
+ /* Resolve on store, and keep the multisampled contents: the source is a
284
+ * framebuffer a later draw may still read. */
285
+ info.store_op = SDL_GPU_STOREOP_RESOLVE_AND_STORE;
286
+ info.resolve_texture = destination;
287
+ info.resolve_mip_level = 0;
288
+ info.resolve_layer = 0;
289
+ SDL_GPURenderPass *pass = SDL_BeginGPURenderPass(cmd_, &info, 1, nullptr);
290
+ if (pass == nullptr) {
291
+ if (trace_enabled()) {
292
+ fprintf(stderr, "xt_gui: resolve pass failed: %s\n", SDL_GetError());
293
+ }
294
+ set_error(GL_INVALID_OPERATION);
295
+ return false;
296
+ }
297
+ SDL_EndGPURenderPass(pass);
298
+ /* The pass was not opened through `begin_pass`, so the prepared-draw cache
299
+ * must bind its pipeline again in the next pass. */
300
+ last_setup_ = nullptr;
301
+ last_pipeline_ = nullptr;
302
+ return true;
303
+ }
304
+
305
+ SDL_GPUTexture *WebGLContext::read_color_texture(uint32_t id, int *width, int *height,
306
+ int *format) {
307
+ if (width == nullptr || height == nullptr || format == nullptr) return nullptr;
308
+ if (id == 0) {
309
+ ensure_default_target();
310
+ *width = width_;
311
+ *height = height_;
312
+ *format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
313
+ return color_;
314
+ }
315
+ WebGLFramebuffer *framebuffer_ = framebuffer(id);
316
+ if (framebuffer_ == nullptr) return nullptr;
317
+ int index = read_buffer_ - GL_COLOR_ATTACHMENT0;
318
+ if (index < 0 || index >= kWebGLMaxDrawBuffers) index = 0;
319
+ int samples = 1;
320
+ SDL_GPUTexture *attachment = color_attachment(id, index, format, &samples, width, height);
321
+ if (attachment == nullptr) return nullptr;
322
+ if (trace_enabled()) {
323
+ fprintf(stderr,
324
+ "xt_gui: read_color fb=%u index=%d samples=%d format=%d %dx%d samples_fb=%d\n", id,
325
+ index, samples, *format, *width, *height, framebuffer_samples(id));
326
+ }
327
+ if (samples <= 1) return attachment;
328
+ SDL_GPUTexture *resolved =
329
+ ensure_resolve_target(*width, *height, (SDL_GPUTextureFormat)*format);
330
+ if (resolved == nullptr) return nullptr;
331
+ if (!resolve_color_pass(attachment, resolved)) return nullptr;
332
+ return resolved;
333
+ }
334
+
335
+ void WebGLContext::end_pass() {
336
+ if (pass_ != nullptr && cmd_ != nullptr) {
337
+ SDL_EndGPURenderPass(pass_);
338
+ pass_ = nullptr;
339
+ }
340
+ }
341
+
342
+ void WebGLContext::begin_pass(bool clear_color, bool clear_depth, bool clear_stencil) {
343
+ if (guidev::g_device == nullptr) return;
344
+ if (pass_ != nullptr && pass_targets_default_ == (bound_framebuffer_ == 0) &&
345
+ pass_framebuffer_ == bound_framebuffer_ && !clear_color && !clear_depth &&
346
+ !clear_stencil) {
347
+ return;
348
+ }
349
+ end_pass();
350
+ ensure_command();
351
+ if (cmd_ == nullptr) return;
352
+ SDL_GPUTexture *depth = target_depth();
353
+ SDL_GPUColorTargetInfo color_infos[kWebGLMaxDrawBuffers];
354
+ int color_count = 0;
355
+ int pass_samples = 1;
356
+ for (int slot = 0; slot < kWebGLMaxDrawBuffers; slot++) {
357
+ SDL_GPUTexture *color = draw_color_texture(slot);
358
+ if (color == nullptr) continue;
359
+ const int samples = draw_color_samples(slot);
360
+ if (color_count > 0 && samples != pass_samples) {
361
+ /* Vulkan requires every attachment of a pass to share its sample count;
362
+ * the framebuffer is incomplete, so the draw cannot run. */
363
+ set_error(GL_INVALID_FRAMEBUFFER_OPERATION);
364
+ return;
365
+ }
366
+ pass_samples = samples;
367
+ SDL_GPUColorTargetInfo &color_info = color_infos[color_count++];
368
+ memset(&color_info, 0, sizeof(color_info));
369
+ color_info.texture = color;
370
+ color_info.layer_or_depth_plane = (Uint32)draw_color_layer(slot);
371
+ color_info.clear_color.r = clear_color_[0];
372
+ color_info.clear_color.g = clear_color_[1];
373
+ color_info.clear_color.b = clear_color_[2];
374
+ color_info.clear_color.a = clear_color_[3];
375
+ color_info.load_op = clear_color ? SDL_GPU_LOADOP_CLEAR : SDL_GPU_LOADOP_LOAD;
376
+ color_info.store_op = SDL_GPU_STOREOP_STORE;
377
+ /* The default framebuffer resolves its multisampled colour target into the
378
+ * texture the page composites, at the end of every pass. */
379
+ if (bound_framebuffer_ == 0 && slot == 0 && color_msaa_ != nullptr && color_ != nullptr) {
380
+ color_info.resolve_texture = color_;
381
+ color_info.store_op = SDL_GPU_STOREOP_RESOLVE_AND_STORE;
382
+ }
383
+ }
384
+ if (color_count == 0) {
385
+ set_error(GL_INVALID_FRAMEBUFFER_OPERATION);
386
+ return;
387
+ }
388
+ if (depth != nullptr) {
389
+ int depth_samples = 1;
390
+ if (bound_framebuffer_ == 0) {
391
+ depth_samples = default_samples_;
392
+ } else {
393
+ WebGLFramebuffer *framebuffer_ = framebuffer(bound_framebuffer_);
394
+ if (framebuffer_ != nullptr && framebuffer_->depth_renderbuffer != 0) {
395
+ WebGLRenderbuffer *renderbuffer_ = renderbuffer(framebuffer_->depth_renderbuffer);
396
+ if (renderbuffer_ != nullptr) depth_samples = renderbuffer_->samples;
397
+ } else if (framebuffer_ != nullptr && framebuffer_->depth_texture != 0) {
398
+ WebGLTexture *texture_ = texture(framebuffer_->depth_texture);
399
+ if (texture_ != nullptr) depth_samples = texture_->samples;
400
+ } else {
401
+ /* `framebuffer_depth` just created the auto depth buffer with the
402
+ * colour attachment's sample count. */
403
+ depth_samples = pass_samples;
404
+ }
405
+ }
406
+ if (depth_samples != pass_samples) {
407
+ set_error(GL_INVALID_FRAMEBUFFER_OPERATION);
408
+ return;
409
+ }
410
+ }
411
+
412
+ SDL_GPUDepthStencilTargetInfo depth_info;
413
+ memset(&depth_info, 0, sizeof(depth_info));
414
+ depth_info.texture = depth;
415
+ depth_info.clear_depth = clear_depth_;
416
+ depth_info.load_op = (clear_depth && depth != nullptr) ? SDL_GPU_LOADOP_CLEAR
417
+ : SDL_GPU_LOADOP_LOAD;
418
+ depth_info.store_op = SDL_GPU_STOREOP_STORE;
419
+ depth_info.clear_stencil = (Uint8)(clear_stencil_ & 0xFF);
420
+ depth_info.stencil_load_op = (clear_stencil && depth != nullptr) ? SDL_GPU_LOADOP_CLEAR
421
+ : SDL_GPU_LOADOP_LOAD;
422
+ depth_info.stencil_store_op = SDL_GPU_STOREOP_STORE;
423
+
424
+ pass_ = SDL_BeginGPURenderPass(cmd_, color_infos, (Uint32)color_count,
425
+ depth != nullptr ? &depth_info : nullptr);
426
+ if (pass_ == nullptr) {
427
+ if (trace_enabled()) {
428
+ fprintf(stderr, "xt_gui: begin_pass failed (fb=%u colors=%d samples=%d depth=%p): %s\n",
429
+ bound_framebuffer_, color_count, pass_samples, (void *)depth, SDL_GetError());
430
+ }
431
+ set_error(GL_INVALID_OPERATION);
432
+ return;
433
+ }
434
+ g_perf_frame.webglPasses += 1;
435
+ pass_serial_ += 1;
436
+ pass_targets_default_ = bound_framebuffer_ == 0;
437
+ pass_framebuffer_ = bound_framebuffer_;
438
+ }
439
+
440
+ } // namespace xtgui