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.
- package/dist/src/ast/common.d.ts +10 -0
- package/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +4 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +10 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- package/dist/src/codegen/generator/state.js +4 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/parser/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +13 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- package/dist/tests/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
- package/dist/tests/e2e/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +66 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- package/dist/tests/e2e/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +6 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
|
@@ -17,11 +17,32 @@
|
|
|
17
17
|
#include "gui_internal.h"
|
|
18
18
|
#include "perf.h"
|
|
19
19
|
|
|
20
|
+
/* Optional draw-buffer tracing (`XT_GUI_TRACE=1`), implemented in
|
|
21
|
+
* `webgl_draw.cpp`. */
|
|
22
|
+
extern "C" void xt_gui_trace_submit(int submitted);
|
|
23
|
+
|
|
20
24
|
namespace xtgui {
|
|
21
25
|
namespace {
|
|
22
26
|
|
|
23
27
|
std::unordered_map<uint64_t, WebGLContext *> g_contexts;
|
|
24
28
|
|
|
29
|
+
/** Whether the backend can allocate and resolve multisampled targets. The
|
|
30
|
+
* WebGL engine runs on Vulkan and Metal; both resolve a 4× colour attachment
|
|
31
|
+
* into the composited texture (including scissored clears and instanced
|
|
32
|
+
* draws), so ask the device rather than pinning MSAA to one driver. */
|
|
33
|
+
bool probe_multisample() {
|
|
34
|
+
if (guidev::g_device == nullptr) return false;
|
|
35
|
+
const char *driver = xt_gui_driver();
|
|
36
|
+
if (driver == nullptr) return false;
|
|
37
|
+
if (strcmp(driver, "vulkan") != 0 && strcmp(driver, "metal") != 0) return false;
|
|
38
|
+
return SDL_GPUTextureSupportsSampleCount(guidev::g_device,
|
|
39
|
+
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
|
|
40
|
+
SDL_GPU_SAMPLECOUNT_4) &&
|
|
41
|
+
SDL_GPUTextureSupportsSampleCount(guidev::g_device,
|
|
42
|
+
SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT,
|
|
43
|
+
SDL_GPU_SAMPLECOUNT_4);
|
|
44
|
+
}
|
|
45
|
+
|
|
25
46
|
} // namespace
|
|
26
47
|
|
|
27
48
|
WebGLContext *xt_webgl_by_id(uint64_t id) {
|
|
@@ -29,7 +50,7 @@ WebGLContext *xt_webgl_by_id(uint64_t id) {
|
|
|
29
50
|
return found == g_contexts.end() ? nullptr : found->second;
|
|
30
51
|
}
|
|
31
52
|
|
|
32
|
-
WebGLContext::WebGLContext(uint64_t id, int width, int height, bool webgl2)
|
|
53
|
+
WebGLContext::WebGLContext(uint64_t id, int width, int height, bool webgl2, bool antialias)
|
|
33
54
|
: id_(id), webgl2_(webgl2) {
|
|
34
55
|
width_ = width > 0 ? width : 1;
|
|
35
56
|
height_ = height > 0 ? height : 1;
|
|
@@ -43,6 +64,10 @@ WebGLContext::WebGLContext(uint64_t id, int width, int height, bool webgl2)
|
|
|
43
64
|
scissor_box_[3] = height_;
|
|
44
65
|
g_contexts[id] = this;
|
|
45
66
|
if (guidev::g_device == nullptr) lost_ = true;
|
|
67
|
+
multisample_supported_ = probe_multisample();
|
|
68
|
+
/* The WebGL default is `antialias: true`; a backend that cannot resolve
|
|
69
|
+
* multisampled targets reports the attribute as false instead. */
|
|
70
|
+
default_samples_ = antialias && multisample_supported_ ? kWebGLMaxSamples : 1;
|
|
46
71
|
}
|
|
47
72
|
|
|
48
73
|
WebGLContext::~WebGLContext() {
|
|
@@ -90,9 +115,9 @@ void WebGLContext::release_gpu_resources() {
|
|
|
90
115
|
}
|
|
91
116
|
}
|
|
92
117
|
for (auto &entry : renderbuffers_) {
|
|
93
|
-
if (entry.second->
|
|
94
|
-
SDL_ReleaseGPUTexture(guidev::g_device, entry.second->
|
|
95
|
-
entry.second->
|
|
118
|
+
if (entry.second->gpu != nullptr) {
|
|
119
|
+
SDL_ReleaseGPUTexture(guidev::g_device, entry.second->gpu);
|
|
120
|
+
entry.second->gpu = nullptr;
|
|
96
121
|
}
|
|
97
122
|
}
|
|
98
123
|
for (SDL_GPUBuffer *buffer : temp_buffers_) SDL_ReleaseGPUBuffer(guidev::g_device, buffer);
|
|
@@ -109,10 +134,24 @@ void WebGLContext::release_gpu_resources() {
|
|
|
109
134
|
SDL_ReleaseGPUSampler(guidev::g_device, blit_sampler_);
|
|
110
135
|
blit_sampler_ = nullptr;
|
|
111
136
|
}
|
|
137
|
+
if (blit_sampler_linear_ != nullptr) {
|
|
138
|
+
SDL_ReleaseGPUSampler(guidev::g_device, blit_sampler_linear_);
|
|
139
|
+
blit_sampler_linear_ = nullptr;
|
|
140
|
+
}
|
|
112
141
|
if (color_ != nullptr) {
|
|
113
142
|
SDL_ReleaseGPUTexture(guidev::g_device, color_);
|
|
114
143
|
color_ = nullptr;
|
|
115
144
|
}
|
|
145
|
+
if (color_msaa_ != nullptr) {
|
|
146
|
+
SDL_ReleaseGPUTexture(guidev::g_device, color_msaa_);
|
|
147
|
+
color_msaa_ = nullptr;
|
|
148
|
+
}
|
|
149
|
+
if (resolve_texture_ != nullptr) {
|
|
150
|
+
SDL_ReleaseGPUTexture(guidev::g_device, resolve_texture_);
|
|
151
|
+
resolve_texture_ = nullptr;
|
|
152
|
+
resolve_width_ = 0;
|
|
153
|
+
resolve_height_ = 0;
|
|
154
|
+
}
|
|
116
155
|
if (depth_ != nullptr) {
|
|
117
156
|
SDL_ReleaseGPUTexture(guidev::g_device, depth_);
|
|
118
157
|
depth_ = nullptr;
|
|
@@ -166,6 +205,9 @@ void WebGLContext::lose_context() {
|
|
|
166
205
|
lost_ = true;
|
|
167
206
|
clear_program_ = 0;
|
|
168
207
|
clear_buffer_ = 0;
|
|
208
|
+
blit_program_ = 0;
|
|
209
|
+
blit_color_program_ = 0;
|
|
210
|
+
blit_buffer_ = 0;
|
|
169
211
|
}
|
|
170
212
|
|
|
171
213
|
void WebGLContext::restore_context() {
|
|
@@ -205,18 +247,55 @@ void WebGLContext::ensure_default_target() {
|
|
|
205
247
|
SDL_GPUTextureCreateInfo info;
|
|
206
248
|
memset(&info, 0, sizeof(info));
|
|
207
249
|
info.type = SDL_GPU_TEXTURETYPE_2D;
|
|
208
|
-
info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
209
|
-
info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
|
|
210
250
|
info.width = (Uint32)width_;
|
|
211
251
|
info.height = (Uint32)height_;
|
|
212
252
|
info.layer_count_or_depth = 1;
|
|
213
253
|
info.num_levels = 1;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
254
|
+
/* `color_` is the single-sampled texture the page composites and reads. With
|
|
255
|
+
* MSAA the draws go into `color_msaa_` instead, and every render pass
|
|
256
|
+
* resolves that target into `color_`. */
|
|
257
|
+
if (color_ == nullptr) {
|
|
258
|
+
info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
259
|
+
info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER | SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
|
|
260
|
+
info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
|
261
|
+
color_ = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
262
|
+
if (color_ == nullptr) {
|
|
263
|
+
set_error(GL_OUT_OF_MEMORY);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (default_samples_ > 1 && color_msaa_ == nullptr) {
|
|
268
|
+
info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
269
|
+
/* A multisampled texture is a render target only: SDL_GPU cannot bind one
|
|
270
|
+
* to a sampler, which is why the resolved copy is what the page sees. */
|
|
271
|
+
info.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET;
|
|
272
|
+
info.sample_count = webgl_sample_count(default_samples_);
|
|
273
|
+
color_msaa_ = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
274
|
+
if (color_msaa_ == nullptr) default_samples_ = 1;
|
|
275
|
+
}
|
|
276
|
+
if (depth_ == nullptr) {
|
|
277
|
+
info.format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
278
|
+
info.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
|
|
279
|
+
/* A multisampled attachment cannot be sampled, and SDL_GPU has no depth
|
|
280
|
+
* resolve; with MSAA the depth buffer is draw-only. */
|
|
281
|
+
if (default_samples_ <= 1) info.usage |= SDL_GPU_TEXTUREUSAGE_SAMPLER;
|
|
282
|
+
info.sample_count = webgl_sample_count(default_samples_);
|
|
283
|
+
depth_ = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
284
|
+
if (depth_ == nullptr && default_samples_ > 1) {
|
|
285
|
+
/* Do not mix a multisampled colour target with a depth-less pass: fall
|
|
286
|
+
* back to the single-sampled drawing buffer instead. */
|
|
287
|
+
SDL_ReleaseGPUTexture(guidev::g_device, color_msaa_);
|
|
288
|
+
color_msaa_ = nullptr;
|
|
289
|
+
default_samples_ = 1;
|
|
290
|
+
info.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER;
|
|
291
|
+
info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
|
292
|
+
depth_ = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
293
|
+
}
|
|
294
|
+
if (depth_ == nullptr) {
|
|
295
|
+
set_error(GL_OUT_OF_MEMORY);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
220
299
|
}
|
|
221
300
|
|
|
222
301
|
void WebGLContext::rebuild_default_target() {
|
|
@@ -231,8 +310,10 @@ void WebGLContext::rebuild_default_target() {
|
|
|
231
310
|
}
|
|
232
311
|
SDL_WaitForGPUIdle(guidev::g_device);
|
|
233
312
|
if (color_ != nullptr) SDL_ReleaseGPUTexture(guidev::g_device, color_);
|
|
313
|
+
if (color_msaa_ != nullptr) SDL_ReleaseGPUTexture(guidev::g_device, color_msaa_);
|
|
234
314
|
if (depth_ != nullptr) SDL_ReleaseGPUTexture(guidev::g_device, depth_);
|
|
235
315
|
color_ = nullptr;
|
|
316
|
+
color_msaa_ = nullptr;
|
|
236
317
|
depth_ = nullptr;
|
|
237
318
|
ensure_default_target();
|
|
238
319
|
}
|
|
@@ -266,163 +347,19 @@ void WebGLContext::resize(int width, int height) {
|
|
|
266
347
|
void WebGLContext::submit() {
|
|
267
348
|
end_pass();
|
|
268
349
|
if (cmd_ != nullptr) {
|
|
269
|
-
SDL_SubmitGPUCommandBuffer(cmd_);
|
|
350
|
+
const bool submitted = SDL_SubmitGPUCommandBuffer(cmd_);
|
|
351
|
+
xt_gui_trace_submit(submitted ? 1 : 0);
|
|
352
|
+
if (!submitted) {
|
|
353
|
+
static int reported = 0;
|
|
354
|
+
if (!reported) {
|
|
355
|
+
reported = 1;
|
|
356
|
+
fprintf(stderr, "xt_gui: submit failed: %s\n", SDL_GetError());
|
|
357
|
+
}
|
|
358
|
+
}
|
|
270
359
|
cmd_ = nullptr;
|
|
271
360
|
}
|
|
272
361
|
}
|
|
273
362
|
|
|
274
|
-
/* -- passes -------------------------------------------------------------- */
|
|
275
|
-
|
|
276
|
-
SDL_GPUTexture *WebGLContext::target_color() {
|
|
277
|
-
if (bound_framebuffer_ == 0) {
|
|
278
|
-
ensure_default_target();
|
|
279
|
-
return color_;
|
|
280
|
-
}
|
|
281
|
-
WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
|
|
282
|
-
if (framebuffer == nullptr || framebuffer->color_textures[0] == 0) return nullptr;
|
|
283
|
-
WebGLTexture *texture = this->texture(framebuffer->color_textures[0]);
|
|
284
|
-
if (texture == nullptr) return nullptr;
|
|
285
|
-
return ensure_texture_gpu(texture, true);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
SDL_GPUTexture *WebGLContext::framebuffer_color(uint32_t id) {
|
|
289
|
-
if (id == 0) {
|
|
290
|
-
ensure_default_target();
|
|
291
|
-
return color_;
|
|
292
|
-
}
|
|
293
|
-
WebGLFramebuffer *framebuffer_ = framebuffer(id);
|
|
294
|
-
if (framebuffer_ == nullptr || framebuffer_->color_textures[0] == 0) return nullptr;
|
|
295
|
-
WebGLTexture *texture_ = texture(framebuffer_->color_textures[0]);
|
|
296
|
-
return texture_ != nullptr ? ensure_texture_gpu(texture_, true) : nullptr;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
void WebGLContext::framebuffer_size(uint32_t id, int *width, int *height) {
|
|
300
|
-
if (id == 0) {
|
|
301
|
-
*width = width_;
|
|
302
|
-
*height = height_;
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
WebGLFramebuffer *framebuffer_ = framebuffer(id);
|
|
306
|
-
*width = framebuffer_ != nullptr ? framebuffer_->width : 0;
|
|
307
|
-
*height = framebuffer_ != nullptr ? framebuffer_->height : 0;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
SDL_GPUTexture *WebGLContext::target_depth() {
|
|
311
|
-
return framebuffer_depth(bound_framebuffer_);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
SDL_GPUTexture *WebGLContext::framebuffer_depth(uint32_t id) {
|
|
315
|
-
if (id == 0) {
|
|
316
|
-
ensure_default_target();
|
|
317
|
-
return depth_;
|
|
318
|
-
}
|
|
319
|
-
WebGLFramebuffer *framebuffer = this->framebuffer(id);
|
|
320
|
-
if (framebuffer == nullptr) return nullptr;
|
|
321
|
-
if (framebuffer->depth_texture != 0) {
|
|
322
|
-
WebGLTexture *texture = this->texture(framebuffer->depth_texture);
|
|
323
|
-
if (texture == nullptr) return nullptr;
|
|
324
|
-
texture->as_depth_target = true;
|
|
325
|
-
return ensure_texture_gpu(texture, true);
|
|
326
|
-
}
|
|
327
|
-
if (framebuffer->depth == nullptr && framebuffer->depth_renderbuffer == 0 &&
|
|
328
|
-
framebuffer->width > 0 && framebuffer->height > 0 && guidev::g_device != nullptr) {
|
|
329
|
-
SDL_GPUTextureCreateInfo info;
|
|
330
|
-
memset(&info, 0, sizeof(info));
|
|
331
|
-
info.type = SDL_GPU_TEXTURETYPE_2D;
|
|
332
|
-
info.format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
333
|
-
info.usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET;
|
|
334
|
-
info.width = (Uint32)framebuffer->width;
|
|
335
|
-
info.height = (Uint32)framebuffer->height;
|
|
336
|
-
info.layer_count_or_depth = 1;
|
|
337
|
-
info.num_levels = 1;
|
|
338
|
-
info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
|
339
|
-
framebuffer->depth = SDL_CreateGPUTexture(guidev::g_device, &info);
|
|
340
|
-
}
|
|
341
|
-
return framebuffer->depth;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
int WebGLContext::target_color_format() {
|
|
345
|
-
if (bound_framebuffer_ == 0) return SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
346
|
-
WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
|
|
347
|
-
if (framebuffer == nullptr || framebuffer->color_textures[0] == 0) {
|
|
348
|
-
return SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
349
|
-
}
|
|
350
|
-
WebGLTexture *texture = this->texture(framebuffer->color_textures[0]);
|
|
351
|
-
return texture != nullptr ? (int)texture->format : SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
int WebGLContext::target_depth_format() {
|
|
355
|
-
if (bound_framebuffer_ == 0) return SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
356
|
-
WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
|
|
357
|
-
if (framebuffer == nullptr) return SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
358
|
-
if (framebuffer->depth_texture != 0) {
|
|
359
|
-
WebGLTexture *texture = this->texture(framebuffer->depth_texture);
|
|
360
|
-
if (texture != nullptr) return (int)texture->format;
|
|
361
|
-
}
|
|
362
|
-
return SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
void WebGLContext::end_pass() {
|
|
366
|
-
if (pass_ != nullptr && cmd_ != nullptr) {
|
|
367
|
-
SDL_EndGPURenderPass(pass_);
|
|
368
|
-
pass_ = nullptr;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
void WebGLContext::begin_pass(bool clear_color, bool clear_depth, bool clear_stencil) {
|
|
373
|
-
if (guidev::g_device == nullptr) return;
|
|
374
|
-
if (pass_ != nullptr && pass_targets_default_ == (bound_framebuffer_ == 0) &&
|
|
375
|
-
pass_framebuffer_ == bound_framebuffer_ && !clear_color && !clear_depth &&
|
|
376
|
-
!clear_stencil) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
end_pass();
|
|
380
|
-
ensure_command();
|
|
381
|
-
if (cmd_ == nullptr) return;
|
|
382
|
-
SDL_GPUTexture *depth = target_depth();
|
|
383
|
-
SDL_GPUColorTargetInfo color_infos[kWebGLMaxDrawBuffers];
|
|
384
|
-
int color_count = 0;
|
|
385
|
-
for (int slot = 0; slot < kWebGLMaxDrawBuffers; slot++) {
|
|
386
|
-
SDL_GPUTexture *color = draw_color_texture(slot);
|
|
387
|
-
if (color == nullptr) continue;
|
|
388
|
-
SDL_GPUColorTargetInfo &color_info = color_infos[color_count++];
|
|
389
|
-
memset(&color_info, 0, sizeof(color_info));
|
|
390
|
-
color_info.texture = color;
|
|
391
|
-
color_info.layer_or_depth_plane = (Uint32)draw_color_layer(slot);
|
|
392
|
-
color_info.clear_color.r = clear_color_[0];
|
|
393
|
-
color_info.clear_color.g = clear_color_[1];
|
|
394
|
-
color_info.clear_color.b = clear_color_[2];
|
|
395
|
-
color_info.clear_color.a = clear_color_[3];
|
|
396
|
-
color_info.load_op = clear_color ? SDL_GPU_LOADOP_CLEAR : SDL_GPU_LOADOP_LOAD;
|
|
397
|
-
color_info.store_op = SDL_GPU_STOREOP_STORE;
|
|
398
|
-
}
|
|
399
|
-
if (color_count == 0) {
|
|
400
|
-
set_error(GL_INVALID_FRAMEBUFFER_OPERATION);
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
SDL_GPUDepthStencilTargetInfo depth_info;
|
|
405
|
-
memset(&depth_info, 0, sizeof(depth_info));
|
|
406
|
-
depth_info.texture = depth;
|
|
407
|
-
depth_info.clear_depth = clear_depth_;
|
|
408
|
-
depth_info.load_op = (clear_depth && depth != nullptr) ? SDL_GPU_LOADOP_CLEAR
|
|
409
|
-
: SDL_GPU_LOADOP_LOAD;
|
|
410
|
-
depth_info.store_op = SDL_GPU_STOREOP_STORE;
|
|
411
|
-
depth_info.clear_stencil = (Uint8)(clear_stencil_ & 0xFF);
|
|
412
|
-
depth_info.stencil_load_op = (clear_stencil && depth != nullptr) ? SDL_GPU_LOADOP_CLEAR
|
|
413
|
-
: SDL_GPU_LOADOP_LOAD;
|
|
414
|
-
depth_info.stencil_store_op = SDL_GPU_STOREOP_STORE;
|
|
415
|
-
|
|
416
|
-
pass_ = SDL_BeginGPURenderPass(cmd_, color_infos, (Uint32)color_count,
|
|
417
|
-
depth != nullptr ? &depth_info : nullptr);
|
|
418
|
-
if (pass_ != nullptr) {
|
|
419
|
-
g_perf_frame.webglPasses += 1;
|
|
420
|
-
pass_serial_ += 1;
|
|
421
|
-
}
|
|
422
|
-
pass_targets_default_ = bound_framebuffer_ == 0;
|
|
423
|
-
pass_framebuffer_ = bound_framebuffer_;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
363
|
/* -- queries ------------------------------------------------------------- */
|
|
427
364
|
|
|
428
365
|
double WebGLContext::parameter(int pname) {
|
|
@@ -449,9 +386,20 @@ double WebGLContext::parameter(int pname) {
|
|
|
449
386
|
return 8192;
|
|
450
387
|
case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
|
|
451
388
|
return 8192;
|
|
452
|
-
case
|
|
453
|
-
|
|
454
|
-
|
|
389
|
+
case 0x84FF: // MAX_TEXTURE_MAX_ANISOTROPY_EXT
|
|
390
|
+
return 16;
|
|
391
|
+
case GL_SAMPLES: {
|
|
392
|
+
const int samples = bound_framebuffer_ == 0 ? default_samples_
|
|
393
|
+
: framebuffer_samples(bound_framebuffer_);
|
|
394
|
+
/* A single-sampled framebuffer reports 0 samples (SAMPLE_BUFFERS is 0);
|
|
395
|
+
* only a multisampled one reports its sample count. */
|
|
396
|
+
return samples > 1 ? samples : 0;
|
|
397
|
+
}
|
|
398
|
+
case GL_SAMPLE_BUFFERS: {
|
|
399
|
+
const int samples = bound_framebuffer_ == 0 ? default_samples_
|
|
400
|
+
: framebuffer_samples(bound_framebuffer_);
|
|
401
|
+
return samples > 1 ? 1 : 0;
|
|
402
|
+
}
|
|
455
403
|
case GL_SUBPIXEL_BITS:
|
|
456
404
|
return 4;
|
|
457
405
|
case GL_RED_BITS:
|
|
@@ -492,7 +440,7 @@ double WebGLContext::parameter(int pname) {
|
|
|
492
440
|
case GL_DRAW_BUFFER3:
|
|
493
441
|
return draw_buffer_value(3);
|
|
494
442
|
case GL_MAX_SAMPLES:
|
|
495
|
-
return 0;
|
|
443
|
+
return multisample_supported_ ? kWebGLMaxSamples : 0;
|
|
496
444
|
case GL_MAX_UNIFORM_BUFFER_BINDINGS:
|
|
497
445
|
case GL_MAX_VERTEX_UNIFORM_BLOCKS:
|
|
498
446
|
case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
|
|
@@ -551,6 +499,8 @@ uint32_t WebGLContext::bound_texture(int unit) const {
|
|
|
551
499
|
return bound_textures_[unit];
|
|
552
500
|
}
|
|
553
501
|
|
|
502
|
+
uint32_t WebGLContext::bound_texture() const { return bound_texture(active_unit_); }
|
|
503
|
+
|
|
554
504
|
uint32_t WebGLContext::bound_cube_texture(int unit) const {
|
|
555
505
|
if (unit < 0 || unit >= kWebGLMaxTextureUnits) return 0;
|
|
556
506
|
return bound_cube_textures_[unit];
|
|
@@ -25,6 +25,82 @@
|
|
|
25
25
|
namespace xtgui {
|
|
26
26
|
namespace {
|
|
27
27
|
|
|
28
|
+
/** `XT_GUI_TRACE=1` records the last draws of each submitted command buffer, so
|
|
29
|
+
* the buffer a lost Vulkan device was executing can be inspected. */
|
|
30
|
+
bool trace_enabled() {
|
|
31
|
+
static int value = -1;
|
|
32
|
+
if (value < 0) {
|
|
33
|
+
const char *env = SDL_getenv("XT_GUI_TRACE");
|
|
34
|
+
value = (env != nullptr && env[0] != '\0' && env[0] != '0') ? 1 : 0;
|
|
35
|
+
}
|
|
36
|
+
return value != 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
struct DrawTrace {
|
|
40
|
+
uint32_t program;
|
|
41
|
+
uint32_t framebuffer;
|
|
42
|
+
int mode;
|
|
43
|
+
int first;
|
|
44
|
+
int count;
|
|
45
|
+
int instances;
|
|
46
|
+
int samples;
|
|
47
|
+
int color_format;
|
|
48
|
+
int depth_format;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
constexpr int kTraceDraws = 64;
|
|
52
|
+
DrawTrace g_draw_trace[kTraceDraws];
|
|
53
|
+
int g_draw_trace_count = 0;
|
|
54
|
+
DrawTrace g_submitted_trace[kTraceDraws];
|
|
55
|
+
int g_submitted_trace_count = 0;
|
|
56
|
+
|
|
57
|
+
void trace_draw(const WebGLContext *context, uint32_t program, int mode, int first, int count,
|
|
58
|
+
int instances, int samples, int color_format, int depth_format) {
|
|
59
|
+
if (!trace_enabled()) return;
|
|
60
|
+
if (g_draw_trace_count >= kTraceDraws) {
|
|
61
|
+
memmove(g_draw_trace, g_draw_trace + 1, sizeof(DrawTrace) * (kTraceDraws - 1));
|
|
62
|
+
g_draw_trace_count = kTraceDraws - 1;
|
|
63
|
+
}
|
|
64
|
+
DrawTrace &entry = g_draw_trace[g_draw_trace_count++];
|
|
65
|
+
entry.program = program;
|
|
66
|
+
entry.framebuffer = context != nullptr ? context->bound_framebuffer_id() : 0;
|
|
67
|
+
entry.mode = mode;
|
|
68
|
+
entry.first = first;
|
|
69
|
+
entry.count = count;
|
|
70
|
+
entry.instances = instances;
|
|
71
|
+
entry.samples = samples;
|
|
72
|
+
entry.color_format = color_format;
|
|
73
|
+
entry.depth_format = depth_format;
|
|
74
|
+
(void)context;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} // namespace
|
|
78
|
+
|
|
79
|
+
} // namespace xtgui
|
|
80
|
+
|
|
81
|
+
extern "C" void xt_gui_trace_submit(int submitted) {
|
|
82
|
+
if (!xtgui::trace_enabled()) return;
|
|
83
|
+
if (submitted) {
|
|
84
|
+
memcpy(xtgui::g_submitted_trace, xtgui::g_draw_trace,
|
|
85
|
+
sizeof(xtgui::DrawTrace) * (size_t)xtgui::g_draw_trace_count);
|
|
86
|
+
xtgui::g_submitted_trace_count = xtgui::g_draw_trace_count;
|
|
87
|
+
xtgui::g_draw_trace_count = 0;
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
fprintf(stderr, "xt_gui: last submitted buffer had %d draws:\n",
|
|
91
|
+
xtgui::g_submitted_trace_count);
|
|
92
|
+
for (int i = 0; i < xtgui::g_submitted_trace_count; i++) {
|
|
93
|
+
const xtgui::DrawTrace &d = xtgui::g_submitted_trace[i];
|
|
94
|
+
fprintf(stderr,
|
|
95
|
+
" draw prog=%u mode=%d first=%d count=%d inst=%d samples=%d fmt=%d dfmt=%d fbo=%u\n",
|
|
96
|
+
d.program, d.mode, d.first, d.count, d.instances, d.samples, d.color_format,
|
|
97
|
+
d.depth_format, d.framebuffer);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
namespace xtgui {
|
|
102
|
+
namespace {
|
|
103
|
+
|
|
28
104
|
int type_size(int type) {
|
|
29
105
|
switch (type) {
|
|
30
106
|
case GL_BYTE:
|
|
@@ -181,6 +257,7 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
181
257
|
bound_framebuffer_ != 0 ? framebuffer(bound_framebuffer_) : nullptr;
|
|
182
258
|
const int target_width = framebuffer_ != nullptr ? framebuffer_->width : width_;
|
|
183
259
|
const int target_height = framebuffer_ != nullptr ? framebuffer_->height : height_;
|
|
260
|
+
const bool top_down = webgl_target_top_down(bound_framebuffer_);
|
|
184
261
|
/* A pipeline bakes in the attachment formats; float colour targets, MRT
|
|
185
262
|
* layouts and depth textures therefore need their own pipeline variants. */
|
|
186
263
|
state_.color_target_count = 0;
|
|
@@ -190,6 +267,17 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
190
267
|
}
|
|
191
268
|
if (state_.color_target_count == 0) state_.color_target_count = 1;
|
|
192
269
|
state_.depth_format = target_depth_format();
|
|
270
|
+
state_.sample_count = target_samples();
|
|
271
|
+
|
|
272
|
+
/* The viewport of a bottom-up target is flipped (see below), which also
|
|
273
|
+
* mirrors the winding the rasteriser sees. Flip the GL front-face comparison
|
|
274
|
+
* for such a target while its pipeline is prepared; the draw hash carries the
|
|
275
|
+
* effective value, so the two orientations get distinct pipelines, and the
|
|
276
|
+
* page's logical state is restored right after. */
|
|
277
|
+
const int requested_front_face = state_.front_face;
|
|
278
|
+
if (!top_down) {
|
|
279
|
+
state_.front_face = requested_front_face == GL_CW ? GL_CCW : GL_CW;
|
|
280
|
+
}
|
|
193
281
|
|
|
194
282
|
WebGLDrawKey key;
|
|
195
283
|
key.program = current_program_;
|
|
@@ -202,17 +290,31 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
202
290
|
draw_state_hash(&key.state_hash, &key.state_hash2);
|
|
203
291
|
|
|
204
292
|
const WebGLDrawSetup *setup = prepare_draw(key);
|
|
293
|
+
state_.front_face = requested_front_face;
|
|
205
294
|
if (setup == nullptr) return;
|
|
206
295
|
|
|
207
296
|
begin_pass(false, false, false);
|
|
208
297
|
if (pass_ == nullptr) return;
|
|
209
298
|
|
|
299
|
+
/* GL window y counts from the target's bottom edge while SDL_GPU's viewport
|
|
300
|
+
* is top-down. The composited drawing buffer stores GL top at row 0, so a
|
|
301
|
+
* positive-height viewport at `height - (y + h)` reproduces GL. A user
|
|
302
|
+
* framebuffer stores GL row y at storage row y (shaders sample it with v = 0
|
|
303
|
+
* at the bottom), which needs the opposite y direction: SDL's Vulkan backend
|
|
304
|
+
* negates a viewport height and Metal flips a negative one, so passing the
|
|
305
|
+
* viewport from `y + h` down to `y` renders GL rows in place. */
|
|
210
306
|
SDL_GPUViewport viewport;
|
|
211
307
|
memset(&viewport, 0, sizeof(viewport));
|
|
212
308
|
viewport.x = (float)viewport_[0];
|
|
213
|
-
viewport.y = (float)(target_height - (viewport_[1] + viewport_[3]));
|
|
214
309
|
viewport.w = (float)std::max(1, viewport_[2]);
|
|
215
|
-
|
|
310
|
+
const int viewport_h = std::max(1, viewport_[3]);
|
|
311
|
+
if (top_down) {
|
|
312
|
+
viewport.y = (float)webgl_target_rect_y(true, target_height, viewport_[1], viewport_h);
|
|
313
|
+
viewport.h = (float)viewport_h;
|
|
314
|
+
} else {
|
|
315
|
+
viewport.y = (float)(viewport_[1] + viewport_h);
|
|
316
|
+
viewport.h = (float)-viewport_h;
|
|
317
|
+
}
|
|
216
318
|
viewport.min_depth = 0.0f;
|
|
217
319
|
viewport.max_depth = 1.0f;
|
|
218
320
|
SDL_SetGPUViewport(pass_, &viewport);
|
|
@@ -224,7 +326,7 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
224
326
|
scissor.h = target_height;
|
|
225
327
|
if (scissor_test_ && scissor_box_[2] > 0 && scissor_box_[3] > 0) {
|
|
226
328
|
scissor.x = scissor_box_[0];
|
|
227
|
-
scissor.y = target_height
|
|
329
|
+
scissor.y = webgl_target_rect_y(top_down, target_height, scissor_box_[1], scissor_box_[3]);
|
|
228
330
|
scissor.w = scissor_box_[2];
|
|
229
331
|
scissor.h = scissor_box_[3];
|
|
230
332
|
}
|
|
@@ -325,8 +427,13 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
325
427
|
texture_id = bound_array_textures_[unit];
|
|
326
428
|
}
|
|
327
429
|
WebGLTexture *sampled = texture(texture_id);
|
|
328
|
-
|
|
329
|
-
|
|
430
|
+
/* A multisampled texture is not sampleable: binding one makes the
|
|
431
|
+
* texture incomplete, which reads as the fallback texel, exactly like a
|
|
432
|
+
* browser's incomplete texture. */
|
|
433
|
+
SDL_GPUTexture *gpu =
|
|
434
|
+
sampled != nullptr && sampled->samples <= 1
|
|
435
|
+
? ensure_texture_gpu(sampled, sampled->as_target)
|
|
436
|
+
: nullptr;
|
|
330
437
|
WebGLSampler *sampler_object = this->sampler(bound_samplers_[unit]);
|
|
331
438
|
SDL_GPUSampler *sampler = nullptr;
|
|
332
439
|
if (sampler_object != nullptr) {
|
|
@@ -355,9 +462,13 @@ void WebGLContext::draw(int mode, int first, int count, int index_type, int offs
|
|
|
355
462
|
bind_samplers(program_->fs_sampler_uniforms, false);
|
|
356
463
|
|
|
357
464
|
if (index_size > 0) {
|
|
465
|
+
trace_draw(this, current_program_, draw_mode, first, count, instances, state_.sample_count,
|
|
466
|
+
state_.color_target_count > 0 ? state_.color_formats[0] : 0, state_.depth_format);
|
|
358
467
|
SDL_DrawGPUIndexedPrimitives(pass_, (Uint32)count, (Uint32)instances, (Uint32)first_index, 0,
|
|
359
468
|
0);
|
|
360
469
|
} else {
|
|
470
|
+
trace_draw(this, current_program_, draw_mode, first, count, instances, state_.sample_count,
|
|
471
|
+
state_.color_target_count > 0 ? state_.color_formats[0] : 0, state_.depth_format);
|
|
361
472
|
SDL_DrawGPUPrimitives(pass_, (Uint32)count, (Uint32)instances, (Uint32)first, 0);
|
|
362
473
|
}
|
|
363
474
|
}
|
|
@@ -17,16 +17,23 @@ SDL_GPUTexture *WebGLContext::draw_color_texture(int slot) {
|
|
|
17
17
|
if (slot < 0 || slot >= kWebGLMaxDrawBuffers) return nullptr;
|
|
18
18
|
if (bound_framebuffer_ == 0) {
|
|
19
19
|
ensure_default_target();
|
|
20
|
-
return slot == 0 && default_draw_buffers_[0] == GL_BACK ?
|
|
20
|
+
return slot == 0 && default_draw_buffers_[0] == GL_BACK ? color_msaa_ != nullptr ? color_msaa_ : color_
|
|
21
|
+
: nullptr;
|
|
21
22
|
}
|
|
22
23
|
WebGLFramebuffer *framebuffer = this->framebuffer(bound_framebuffer_);
|
|
23
24
|
if (framebuffer == nullptr) return nullptr;
|
|
24
25
|
const int buffer = framebuffer->draw_buffers[slot];
|
|
25
26
|
const int index = buffer - GL_COLOR_ATTACHMENT0;
|
|
26
27
|
if (index < 0 || index >= kWebGLMaxDrawBuffers) return nullptr;
|
|
27
|
-
if (framebuffer->color_textures[index]
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
if (framebuffer->color_textures[index] != 0) {
|
|
29
|
+
WebGLTexture *texture = this->texture(framebuffer->color_textures[index]);
|
|
30
|
+
return texture != nullptr ? ensure_texture_gpu(texture, true) : nullptr;
|
|
31
|
+
}
|
|
32
|
+
if (framebuffer->color_renderbuffers[index] != 0) {
|
|
33
|
+
WebGLRenderbuffer *renderbuffer = this->renderbuffer(framebuffer->color_renderbuffers[index]);
|
|
34
|
+
return renderbuffer != nullptr ? renderbuffer->gpu : nullptr;
|
|
35
|
+
}
|
|
36
|
+
return nullptr;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
int WebGLContext::draw_color_format(int slot) {
|
|
@@ -37,8 +44,16 @@ int WebGLContext::draw_color_format(int slot) {
|
|
|
37
44
|
if (index < 0 || index >= kWebGLMaxDrawBuffers) {
|
|
38
45
|
return SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
39
46
|
}
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
if (framebuffer->color_textures[index] != 0) {
|
|
48
|
+
WebGLTexture *texture = this->texture(framebuffer->color_textures[index]);
|
|
49
|
+
return texture != nullptr ? (int)texture->format : SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
50
|
+
}
|
|
51
|
+
if (framebuffer->color_renderbuffers[index] != 0) {
|
|
52
|
+
WebGLRenderbuffer *renderbuffer = this->renderbuffer(framebuffer->color_renderbuffers[index]);
|
|
53
|
+
return renderbuffer != nullptr ? (int)renderbuffer->format
|
|
54
|
+
: SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
55
|
+
}
|
|
56
|
+
return SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
int WebGLContext::draw_color_layer(int slot) {
|
|
@@ -223,6 +223,7 @@ void WebGLContext::draw_state_hash(uint64_t *first, uint64_t *second) const {
|
|
|
223
223
|
mix((uint64_t)(uint32_t)state_.color_formats[i]);
|
|
224
224
|
}
|
|
225
225
|
mix((uint64_t)(uint32_t)state_.depth_format);
|
|
226
|
+
mix((uint64_t)(uint32_t)state_.sample_count);
|
|
226
227
|
|
|
227
228
|
*first = h1;
|
|
228
229
|
*second = h2;
|
|
@@ -54,6 +54,8 @@ struct WebGLDrawState {
|
|
|
54
54
|
SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM};
|
|
55
55
|
int color_target_count = 1;
|
|
56
56
|
int depth_format = SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT;
|
|
57
|
+
/** Samples per texel of the render targets; a pipeline bakes it in. */
|
|
58
|
+
int sample_count = 1;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
/**
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
namespace {
|
|
18
18
|
|
|
19
|
-
void *get(XtGuiWindow *win, const void *node, bool webgl2) {
|
|
20
|
-
return xt_gui_webgl_get(win, static_cast<const xtgui::Node *>(node), webgl2);
|
|
19
|
+
void *get(XtGuiWindow *win, const void *node, bool webgl2, bool antialias) {
|
|
20
|
+
return xt_gui_webgl_get(win, static_cast<const xtgui::Node *>(node), webgl2, antialias);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
void *find(XtGuiWindow *win, const void *node) {
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
#include "webgl.h"
|
|
14
14
|
|
|
15
15
|
/** The WebGL context of a `<canvas>`, creating it on first use. `webgl2`
|
|
16
|
-
* selects the WebGL 2 API/prototype
|
|
17
|
-
* asked for. */
|
|
18
|
-
xtgui::WebGLContext *xt_gui_webgl_get(XtGuiWindow *win, const xtgui::Node *node, bool webgl2
|
|
16
|
+
* selects the WebGL 2 API/prototype and `antialias` the context-creation
|
|
17
|
+
* attribute; a canvas keeps the first context kind it asked for. */
|
|
18
|
+
xtgui::WebGLContext *xt_gui_webgl_get(XtGuiWindow *win, const xtgui::Node *node, bool webgl2,
|
|
19
|
+
bool antialias = true);
|
|
19
20
|
/** The existing WebGL context of `node`, or null (no side effects). */
|
|
20
21
|
xtgui::WebGLContext *xt_gui_webgl_find(XtGuiWindow *win, const xtgui::Node *node);
|
|
21
22
|
/** Drop a node's WebGL context (called when its handle is forgotten). */
|