From 61b2aae34a98f4a48b85dc003d645e4187bae9ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Tue, 12 Mar 2024 10:40:16 -0300 Subject: [PATCH 1/2] updated (https://github.com/floooh/sokol/commit/db32cf409a9eb984e1ababa96e243f141c7f40ed) --- build.zig | 11 ++++++++--- src/sokol/app.d | 2 ++ src/sokol/c/sokol_app.h | 28 ++++++++++++++++++++-------- src/sokol/c/sokol_gfx.h | 17 ++++++++++------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/build.zig b/build.zig index 93f48bc..45e4a61 100644 --- a/build.zig +++ b/build.zig @@ -504,8 +504,13 @@ pub fn ldcBuildStep(b: *Build, options: DCompileStep) !*RunStep { try cmds.append(b.fmt("-mtriple={s}", .{mtriple})); // cpu model (e.g. "baseline") - if (options.target.query.isNative()) - try cmds.append(b.fmt("-mcpu={s}", .{builtin.cpu.model.name})); + if (options.target.query.isNative()) { + const cpu_model = if (options.target.result.isDarwin()) + builtin.cpu.model.llvm_name orelse "generic" + else + builtin.cpu.model.name; + try cmds.append(b.fmt("-mcpu={s}", .{cpu_model})); + } const outputDir = switch (options.kind) { .lib => "lib", @@ -582,7 +587,7 @@ pub const DCompileStep = struct { target: Build.ResolvedTarget, optimize: std.builtin.OptimizeMode = .Debug, kind: CompileStep.Kind = .exe, - linkage: CompileStep.Linkage = .static, + linkage: std.builtin.LinkMode = .static, betterC: bool = false, sources: []const []const u8, dflags: []const []const u8, diff --git a/src/sokol/app.d b/src/sokol/app.d index f686610..dc5d61c 100644 --- a/src/sokol/app.d +++ b/src/sokol/app.d @@ -374,6 +374,8 @@ struct Desc { bool html5_bubble_wheel_events = false; bool html5_bubble_key_events = false; bool html5_bubble_char_events = false; + bool html5_use_emsc_set_main_loop = false; + bool html5_emsc_set_main_loop_simulate_infinite_loop = false; bool ios_keyboard_resizes_canvas = false; } enum Html5FetchError { diff --git a/src/sokol/c/sokol_app.h b/src/sokol/c/sokol_app.h index e0c3462..db73ebb 100644 --- a/src/sokol/c/sokol_app.h +++ b/src/sokol/c/sokol_app.h @@ -1716,6 +1716,8 @@ typedef struct sapp_desc { bool html5_bubble_wheel_events; // same for wheel events bool html5_bubble_key_events; // if true, bubble up *all* key events to browser, not just key events that represent characters bool html5_bubble_char_events; // if true, bubble up character events to browser + bool html5_use_emsc_set_main_loop; // if true, use emscripten_set_main_loop() instead of emscripten_request_animation_frame_loop() + bool html5_emsc_set_main_loop_simulate_infinite_loop; // this will be passed as the simulate_infinite_loop arg to emscripten_set_main_loop() bool ios_keyboard_resizes_canvas; // if true, showing the iOS keyboard shrinks the canvas } sapp_desc; @@ -2594,7 +2596,7 @@ typedef struct { PFNWGLGETEXTENSIONSSTRINGARBPROC GetExtensionsStringARB; PFNWGLCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; // special case glGetIntegerv - void (*GetIntegerv)(uint32_t pname, int32_t* data); + void (WINAPI *GetIntegerv)(uint32_t pname, int32_t* data); bool ext_swap_control; bool arb_multisample; bool arb_pixel_format; @@ -4751,7 +4753,7 @@ _SOKOL_PRIVATE void _sapp_ios_show_keyboard(bool shown) { #if defined(_SAPP_EMSCRIPTEN) #if defined(EM_JS_DEPS) -EM_JS_DEPS(sokol_app, "$withStackSave,$allocateUTF8OnStack"); +EM_JS_DEPS(sokol_app, "$withStackSave,$stringToUTF8OnStack"); #endif #ifdef __cplusplus @@ -4868,7 +4870,7 @@ EM_JS(void, sapp_js_add_clipboard_listener, (void), { Module.sokol_paste = (event) => { const pasted_str = event.clipboardData.getData('text'); withStackSave(() => { - const cstr = allocateUTF8OnStack(pasted_str); + const cstr = stringToUTF8OnStack(pasted_str); __sapp_emsc_onpaste(cstr); }); }; @@ -4925,7 +4927,7 @@ EM_JS(void, sapp_js_add_dragndrop_listeners, (const char* canvas_name_cstr), { __sapp_emsc_begin_drop(files.length); for (let i = 0; i < files.length; i++) { withStackSave(() => { - const cstr = allocateUTF8OnStack(files[i].name); + const cstr = stringToUTF8OnStack(files[i].name); __sapp_emsc_drop(i, cstr); }); } @@ -5854,7 +5856,7 @@ _SOKOL_PRIVATE void _sapp_emsc_unregister_eventhandlers(void) { #endif } -_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) { +_SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame_animation_loop(double time, void* userData) { _SOKOL_UNUSED(userData); _sapp_timing_external(&_sapp.timing, time / 1000.0); @@ -5881,6 +5883,13 @@ _SOKOL_PRIVATE EM_BOOL _sapp_emsc_frame(double time, void* userData) { return EM_TRUE; } +_SOKOL_PRIVATE void _sapp_emsc_frame_main_loop(void) { + const double time = emscripten_performance_now(); + if (!_sapp_emsc_frame_animation_loop(time, 0)) { + emscripten_cancel_main_loop(); + } +} + _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { _sapp_init_state(desc); sapp_js_init(&_sapp.html5_canvas_selector[1]); @@ -5911,8 +5920,11 @@ _SOKOL_PRIVATE void _sapp_emsc_run(const sapp_desc* desc) { sapp_set_icon(&desc->icon); // start the frame loop - emscripten_request_animation_frame_loop(_sapp_emsc_frame, 0); - + if (_sapp.desc.html5_use_emsc_set_main_loop) { + emscripten_set_main_loop(_sapp_emsc_frame_main_loop, 0, _sapp.desc.html5_emsc_set_main_loop_simulate_infinite_loop); + } else { + emscripten_request_animation_frame_loop(_sapp_emsc_frame_animation_loop, 0); + } // NOT A BUG: do not call _sapp_discard_state() here, instead this is // called in _sapp_emsc_frame() when the application is ordered to quit } @@ -6601,7 +6613,7 @@ _SOKOL_PRIVATE void _sapp_wgl_init(void) { SOKOL_ASSERT(_sapp.wgl.GetCurrentDC); _sapp.wgl.MakeCurrent = (PFN_wglMakeCurrent)(void*) GetProcAddress(_sapp.wgl.opengl32, "wglMakeCurrent"); SOKOL_ASSERT(_sapp.wgl.MakeCurrent); - _sapp.wgl.GetIntegerv = (void(*)(uint32_t, int32_t*)) GetProcAddress(_sapp.wgl.opengl32, "glGetIntegerv"); + _sapp.wgl.GetIntegerv = (void(WINAPI*)(uint32_t, int32_t*)) GetProcAddress(_sapp.wgl.opengl32, "glGetIntegerv"); SOKOL_ASSERT(_sapp.wgl.GetIntegerv); _sapp.wgl.msg_hwnd = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, diff --git a/src/sokol/c/sokol_gfx.h b/src/sokol/c/sokol_gfx.h index 5f74d86..598f840 100644 --- a/src/sokol/c/sokol_gfx.h +++ b/src/sokol/c/sokol_gfx.h @@ -141,7 +141,7 @@ object handle is required instead of an sg_swapchain struct. An offscreen pass is started like this (assuming attachments is an sg_attachments handle): - sg_begin_pass(&(sg_pass){ .action = { ... }, .attachments = attachemnts }); + sg_begin_pass(&(sg_pass){ .action = { ... }, .attachments = attachments }); --- set the render pipeline state for the next draw call with: @@ -3566,7 +3566,7 @@ typedef struct sg_frame_stats { _SG_LOGITEM_XMACRO(VALIDATE_ATTACHMENTSDESC_DEPTH_IMAGE_SAMPLE_COUNT, "pass depth attachment sample count must match color attachment sample count") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_CANARY, "sg_begin_pass: pass struct not initialized") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_EXISTS, "sg_begin_pass: attachments object no longer alive") \ - _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_VALID, "sg_begin_pass: attachemnts object not in resource state VALID") \ + _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_ATTACHMENTS_VALID, "sg_begin_pass: attachments object not in resource state VALID") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_COLOR_ATTACHMENT_IMAGE, "sg_begin_pass: one or more color attachment images are not valid") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_RESOLVE_ATTACHMENT_IMAGE, "sg_begin_pass: one or more resolve attachment images are not valid") \ _SG_LOGITEM_XMACRO(VALIDATE_BEGINPASS_DEPTHSTENCIL_ATTACHMENT_IMAGE, "sg_begin_pass: one or more depth-stencil attachment images are not valid") \ @@ -4166,7 +4166,7 @@ inline sg_image sg_make_image(const sg_image_desc& desc) { return sg_make_image( inline sg_sampler sg_make_sampler(const sg_sampler_desc& desc) { return sg_make_sampler(&desc); } inline sg_shader sg_make_shader(const sg_shader_desc& desc) { return sg_make_shader(&desc); } inline sg_pipeline sg_make_pipeline(const sg_pipeline_desc& desc) { return sg_make_pipeline(&desc); } -inline sg_attachments sg_make_attchments(const sg_attachments_desc& desc) { return sg_make_attachments(&desc); } +inline sg_attachments sg_make_attachments(const sg_attachments_desc& desc) { return sg_make_attachments(&desc); } inline void sg_update_image(sg_image img, const sg_image_data& data) { return sg_update_image(img, &data); } inline void sg_begin_pass(const sg_pass& pass) { return sg_begin_pass(&pass); } @@ -12526,12 +12526,14 @@ _SOKOL_PRIVATE void _sg_mtl_begin_pass(const sg_pass* pass) { SOKOL_ASSERT(ds_tex != nil); pass_desc.depthAttachment.texture = ds_tex; pass_desc.depthAttachment.storeAction = MTLStoreActionDontCare; - pass_desc.stencilAttachment.texture = ds_tex; - pass_desc.stencilAttachment.storeAction = MTLStoreActionDontCare; pass_desc.depthAttachment.loadAction = _sg_mtl_load_action(action->depth.load_action); pass_desc.depthAttachment.clearDepth = action->depth.clear_value; - pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action); - pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value; + if (_sg_is_depth_stencil_format(swapchain->depth_format)) { + pass_desc.stencilAttachment.texture = ds_tex; + pass_desc.stencilAttachment.storeAction = MTLStoreActionDontCare; + pass_desc.stencilAttachment.loadAction = _sg_mtl_load_action(action->stencil.load_action); + pass_desc.stencilAttachment.clearStencil = action->stencil.clear_value; + } } } @@ -14475,6 +14477,7 @@ _SOKOL_PRIVATE _sg_image_t* _sg_wgpu_attachments_ds_image(const _sg_attachments_ } _SOKOL_PRIVATE void _sg_wgpu_init_color_att(WGPURenderPassColorAttachment* wgpu_att, const sg_color_attachment_action* action, WGPUTextureView color_view, WGPUTextureView resolve_view) { + wgpu_att->depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; wgpu_att->view = color_view; wgpu_att->resolveTarget = resolve_view; wgpu_att->loadOp = _sg_wgpu_load_op(color_view, action->load_action); From bbc45ed0ba66c5e765a102f40405e8c0af0e0221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Catarino=20Fran=C3=A7a?= Date: Thu, 21 Mar 2024 13:21:03 -0300 Subject: [PATCH 2/2] updated (https://github.com/floooh/sokol/commit/00c9072d40f7d19ae76b31867918a697f1c15ce4) --- src/sokol/c/sokol_gfx.h | 2 +- src/sokol/c/sokol_glue.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sokol/c/sokol_gfx.h b/src/sokol/c/sokol_gfx.h index 598f840..5b8c354 100644 --- a/src/sokol/c/sokol_gfx.h +++ b/src/sokol/c/sokol_gfx.h @@ -2432,7 +2432,7 @@ typedef struct sg_pass_action { as 'type erased' void pointers: GL: on all GL backends, a GL framebuffer object must be provided. This - can be zero for the defaul framebuffer. + can be zero for the default framebuffer. D3D11: - an ID3D11RenderTargetView for the rendering surface, without diff --git a/src/sokol/c/sokol_glue.h b/src/sokol/c/sokol_glue.h index b688a87..a715b17 100644 --- a/src/sokol/c/sokol_glue.h +++ b/src/sokol/c/sokol_glue.h @@ -43,7 +43,7 @@ functions. Use this in the sg_setup() call like this: sg_setup(&(sg_desc){ - .environment = sglue_enviornment(), + .environment = sglue_environment(), ... });