From 2fd38144bbaf0b4b121f18eb626bd699f72327f4 Mon Sep 17 00:00:00 2001 From: Katajisto Date: Sat, 1 Nov 2025 23:15:30 +0200 Subject: [PATCH] fix bizarre issue with web perf and other stuff --- build_web.sh | 1 + first.jai | 27 +++- log_nvprosample.txt | 146 +++++++++++++++++--- mise.toml | 3 + modules/sokol-jai/sokol/app/module.jai | 4 + modules/sokol-jai/sokol/build_clibs_wasm.sh | 2 +- modules/sokol-jai/sokol/c/sokol_app.h | 4 +- modules/sokol-jai/sokol/c/sokol_gfx.h | 9 +- src/main.jai | 17 ++- src/platform_specific/common.jai | 17 +-- src/platform_specific/shell.html | 1 + src/rendering/backend_sokol.jai | 31 +++-- src/rendering/pipelines.jai | 15 +- src/rendering/sky.jai | 4 +- src/shaders/jai/shader_plane.jai | 60 ++++---- src/shaders/shader_plane.glsl | 10 +- 16 files changed, 257 insertions(+), 94 deletions(-) create mode 100755 build_web.sh create mode 100644 mise.toml diff --git a/build_web.sh b/build_web.sh new file mode 100755 index 0000000..6d82cc3 --- /dev/null +++ b/build_web.sh @@ -0,0 +1 @@ +jai first.jai - wasm release && rm -rf dist/packs/ && cp -r packs/ dist/ && rm dist/main.o diff --git a/first.jai b/first.jai index 35f5f77..e0a6ed1 100644 --- a/first.jai +++ b/first.jai @@ -27,10 +27,16 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); doWasmBuild := false; hasTacoma := false; releaseBuild := false; + iprof := false; + uncap_frames := false; + for arg : args { if arg == "wasm" then doWasmBuild = true; if arg == "tacoma" then hasTacoma = true; if arg == "release" then releaseBuild = true; + if arg == "iprof" then iprof = true; + if arg == "iprof" then iprof = true; + if arg == "uncap_frames" then uncap_frames = true; } if doWasmBuild { @@ -81,6 +87,13 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); add_build_file("src/platform_specific/main_web.jai", w); add_build_string("HAS_TACOMA :: false;", w); add_build_string("HAS_IPROF :: false;", w); + add_build_string("UNCAPPED_FRAMES :: false;", w); + + if releaseBuild { + add_build_string("RELEASE_BUILD :: true;", w); + } else { + add_build_string("RELEASE_BUILD :: false;", w); + } if is_directory("./game") { add_build_string("USE_SAMPLE_GAME :: false;", w); @@ -149,7 +162,7 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); set_build_options(opts, w); iprof_plugin: *Iprof.My_Plugin; - profile := !releaseBuild; + profile := iprof; if profile { iprof_plugin = cast(*Iprof.My_Plugin) Iprof.get_plugin(); @@ -174,6 +187,18 @@ Iprof :: #import "Iprof"(IMPORT_MODE = .METAPROGRAM); add_build_string("USE_SAMPLE_GAME :: true;", w); } + if uncap_frames { + add_build_string("UNCAPPED_FRAMES :: true;", w); + } else { + add_build_string("UNCAPPED_FRAMES :: false;", w); + } + + if releaseBuild { + add_build_string("RELEASE_BUILD :: true;", w); + } else { + add_build_string("RELEASE_BUILD :: false;", w); + } + if profile { add_build_string("HAS_IPROF :: true;", w); iprof_plugin.add_source(iprof_plugin); diff --git a/log_nvprosample.txt b/log_nvprosample.txt index 9d298da..a4cbff9 100644 --- a/log_nvprosample.txt +++ b/log_nvprosample.txt @@ -24,7 +24,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -51,7 +51,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -78,7 +78,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -105,7 +105,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -132,7 +132,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -159,7 +159,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -186,7 +186,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -213,7 +213,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -240,7 +240,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -267,7 +267,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -294,7 +294,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -321,7 +321,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -348,7 +348,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -375,7 +375,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -402,7 +402,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -429,7 +429,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -456,7 +456,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -483,7 +483,7 @@ VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query -BLAS Compaction: 0.2MB -> 0.1MB (0.2MB saved, 65.8% smaller) +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) _______________ Vulkan Version: - available: 1.4.309 @@ -509,3 +509,113 @@ Used Device Extensions : VK_KHR_deferred_host_operations VK_KHR_acceleration_structure VK_KHR_ray_query + +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) +_______________ +Vulkan Version: + - available: 1.4.309 + - requesting: 1.3.0 +______________________ +Used Instance Layers : +VK_LAYER_KHRONOS_validation + +Used Instance Extensions : +____________________ +Devices : 1 +0: AMD Radeon RX 6950 XT + - Compatible +Compatible physical devices found : 1 +Using Device: + - Device Name : AMD Radeon RX 6950 XT + - Vendor : AMD + - Driver Version : 2.0.341 + - API Version : 1.4.308 + - Device Type : Discrete GPU +________________________ +Used Device Extensions : +VK_KHR_deferred_host_operations +VK_KHR_acceleration_structure +VK_KHR_ray_query + +BLAS Compaction: 1.0MB -> 0.3MB (0.6MB saved, 66.2% smaller) diff --git a/mise.toml b/mise.toml new file mode 100644 index 0000000..0c56e23 --- /dev/null +++ b/mise.toml @@ -0,0 +1,3 @@ +[tasks] +build_web = "$HOME/bin/jai/bin/jai-linux first.jai - wasm release && rm -rf dist/packs/ && cp -r packs/ dist/ && rm dist/main.o" +ship_web = "" diff --git a/modules/sokol-jai/sokol/app/module.jai b/modules/sokol-jai/sokol/app/module.jai index 046017c..da3ec59 100644 --- a/modules/sokol-jai/sokol/app/module.jai +++ b/modules/sokol-jai/sokol/app/module.jai @@ -1435,6 +1435,10 @@ sapp_html5_ask_leave_site :: (ask: bool) -> void #foreign sokol_app_clib; sapp_html5_get_dropped_file_size :: (index: s32) -> u32 #foreign sokol_app_clib; // HTML5: asynchronously load the content of a dropped file sapp_html5_fetch_dropped_file :: (request: *sapp_html5_fetch_request) -> void #foreign sokol_app_clib; + +// DEBUG DISABLE VSYNC: +sapp_glx_swapinterval :: (interval: s32) -> void #foreign sokol_app_clib; + // Metal: get bridged pointer to Metal device object sapp_metal_get_device :: () -> *void #foreign sokol_app_clib; // Metal: get bridged pointer to MTKView's current drawable of type CAMetalDrawable diff --git a/modules/sokol-jai/sokol/build_clibs_wasm.sh b/modules/sokol-jai/sokol/build_clibs_wasm.sh index 7bc75f2..3c49359 100755 --- a/modules/sokol-jai/sokol/build_clibs_wasm.sh +++ b/modules/sokol-jai/sokol/build_clibs_wasm.sh @@ -5,7 +5,7 @@ build_lib_wasm_release() { dst=$2 backend=$3 echo $dst - emcc -c -O2 -DNDEBUG -sMEMORY64 -sSHARED_MEMORY -DIMPL -D$backend c/$src.c + emcc -c -O2 -DNDEBUG -DSKIP_ERROR_CHECK -sMEMORY64 -sSHARED_MEMORY -DIMPL -D$backend c/$src.c emar rcs $dst.a $src.o } diff --git a/modules/sokol-jai/sokol/c/sokol_app.h b/modules/sokol-jai/sokol/c/sokol_app.h index c91b68b..242ad29 100644 --- a/modules/sokol-jai/sokol/c/sokol_app.h +++ b/modules/sokol-jai/sokol/c/sokol_app.h @@ -10475,7 +10475,7 @@ _SOKOL_PRIVATE void _sapp_glx_swap_buffers(void) { _sapp.glx.SwapBuffers(_sapp.x11.display, _sapp.glx.window); } -_SOKOL_PRIVATE void _sapp_glx_swapinterval(int interval) { +void sapp_glx_swapinterval(int interval) { if (_sapp.glx.EXT_swap_control) { _sapp.glx.SwapIntervalEXT(_sapp.x11.display, _sapp.glx.window, interval); } @@ -11731,7 +11731,7 @@ _SOKOL_PRIVATE void _sapp_linux_run(const sapp_desc* desc) { _sapp_glx_choose_visual(&visual, &depth); _sapp_x11_create_window(visual, depth); _sapp_glx_create_context(); - _sapp_glx_swapinterval(_sapp.swap_interval); + sapp_glx_swapinterval(_sapp.swap_interval); #else _sapp_egl_init(); #endif diff --git a/modules/sokol-jai/sokol/c/sokol_gfx.h b/modules/sokol-jai/sokol/c/sokol_gfx.h index 1e63aa3..6c82f4c 100644 --- a/modules/sokol-jai/sokol/c/sokol_gfx.h +++ b/modules/sokol-jai/sokol/c/sokol_gfx.h @@ -5350,8 +5350,15 @@ inline int sg_append_buffer(sg_buffer buf_id, const sg_range& data) { return sg_ #ifndef GL_COMPUTE_SHADER #define GL_COMPUTE_SHADER 0x91B9 #endif + #ifndef SKIP_ERROR_CHECK #ifndef _SG_GL_CHECK_ERROR - #define _SG_GL_CHECK_ERROR() { SOKOL_ASSERT(glGetError() == GL_NO_ERROR); } + #define _SG_GL_CHECK_ERROR() { } + #endif + #endif + #ifdef SKIP_ERROR_CHECK + #ifndef _SG_GL_CHECK_ERROR + #define _SG_GL_CHECK_ERROR() { } + #endif #endif #endif diff --git a/src/main.jai b/src/main.jai index 13f0740..0c82a81 100644 --- a/src/main.jai +++ b/src/main.jai @@ -32,9 +32,11 @@ stbi :: #import "stb_image"; #load "../game/game.jai"; } -last_frame_time : float64; +last_frame_time : float64; // timestamp of the last frame delta\ _time : float64; +latest_frametime : float64; // latest frame generation duration + V_MAJOR :: 0; V_MINOR :: 6; @@ -70,6 +72,7 @@ round_pow2 :: (v: float) -> s32 { return cast(s32) (vi + 1); } +debug_font : *Font; init :: () { sg_setup(*(sg_desc.{ @@ -98,7 +101,8 @@ init :: () { state.pass_action.colors[0] = .{ load_action = .LOAD }; init_asset_pack_load(); - + useless_mem : [1]u8; + debug_font = get_font_at_size(useless_mem, 15); } init_after_asset_pack :: () { @@ -127,6 +131,8 @@ init_after_asset_pack :: () { // We want to do this last. game_init(); + + #if UNCAPPED_FRAMES then sapp_glx_swapinterval(0); } is_in_reflection_pass : bool = false; @@ -138,6 +144,7 @@ frame :: () { delta_time = get_time() - last_frame_time; last_frame_time = get_time(); + sfetch_dowork(); if mandatory_loads_done() && !init_after_mandatory_done { @@ -148,6 +155,8 @@ frame :: () { if !mandatory_loads_done() then return; fonsClearState(state.fons); + frame_start_time := get_time(); + dpis := state.dpi_scale; #if OS != .WASM { tick_profiler(); } @@ -173,6 +182,8 @@ frame :: () { ui_clear_mouse_occluders(); ui_pass(); + prepare_text(debug_font, tprint("frametime: % ms", latest_frametime * 1000)); + draw_prepared_text(debug_font, 10, 10, .{0.0, 1.0, 0.0, 1.0}); draw_editor(); render(); input_per_frame_event_and_flag_update(); @@ -182,6 +193,8 @@ frame :: () { #if OS != .WASM { profiler_update(); } reset_temporary_storage(); + frame_end_time := get_time(); + latest_frametime = frame_end_time - frame_start_time; } cleanup :: () { diff --git a/src/platform_specific/common.jai b/src/platform_specific/common.jai index b5e5b59..b85e694 100644 --- a/src/platform_specific/common.jai +++ b/src/platform_specific/common.jai @@ -1,12 +1,12 @@ -#import,dir "../../modules/sokol-jai/sokol/app"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/gfx"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/gl"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/glue"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/shape"(DEBUG = true); +#import,dir "../../modules/sokol-jai/sokol/app"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/gfx"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/gl"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/glue"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/shape"(DEBUG = RELEASE_BUILD); #import,dir "../../modules/sokol-jai/sokol/fontstash"; -#import,dir "../../modules/sokol-jai/sokol/log"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/time"(DEBUG = true); -#import,dir "../../modules/sokol-jai/sokol/fetch"(DEBUG = true); +#import,dir "../../modules/sokol-jai/sokol/log"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/time"(DEBUG = RELEASE_BUILD); +#import,dir "../../modules/sokol-jai/sokol/fetch"(DEBUG = RELEASE_BUILD); #load "../main.jai"; @@ -38,6 +38,7 @@ sapp_init :: () { window_title = wi.title, // icon = .{ sokol_default = true }, logger = .{ func = slog_func }, + swap_interval = 0, sample_count = 1, // I think I'll end up pixelifying the whole thing, so I don't think we need MSAA. })); } diff --git a/src/platform_specific/shell.html b/src/platform_specific/shell.html index e843bc0..c879349 100644 --- a/src/platform_specific/shell.html +++ b/src/platform_specific/shell.html @@ -55,6 +55,7 @@ body {