Milepost UI demo #18

Merged
MartinFouilleul merged 7 commits from ilidemi/orca:ui into main 2023-07-16 15:19:09 +00:00
Collaborator

Closes #7, porting UI demo from Milepost with minor adjustments. Nitpicks are welcome.

Notes:

  • Raw events can come one at a time so we're writing them into a static variable on the guest side. This looks like the simplest solution to me. Alternatives are introducing init/deinit functions for safety at a cost of extra calls, doing the same with an arena instead of a static, or exposing a generic malloc/free (like wasm demos usually do but we're handmade).
  • I couldn't find an API to write to memory offset so had to make one. Lmk if I glossed over something.
  • Supporting big endian hosts requires manual marshalling of the event struct. Lmk if that's desired and whether it should be struct-specific or generic in some way.
  • No icon

Just getting an example running, widgets will come separately.

Closes #7, porting UI demo from Milepost with minor adjustments. Nitpicks are welcome. Notes: * Raw events can come one at a time so we're writing them into a static variable on the guest side. This looks like the simplest solution to me. Alternatives are introducing init/deinit functions for *safety* at a cost of extra calls, doing the same with an arena instead of a static, or exposing a generic malloc/free (like wasm demos usually do but we're handmade). * I couldn't find an API to write to memory offset so had to make one. Lmk if I glossed over something. * Supporting big endian hosts requires manual marshalling of the event struct. Lmk if that's desired and whether it should be struct-specific or generic in some way. * No icon Just getting an example running, widgets will come separately.
ilidemi added 1 commit 2023-07-14 04:51:34 +00:00
ilidemi added 1 commit 2023-07-14 04:54:07 +00:00
Author
Collaborator

Also, the Open Sans font is duplicated in /data. Seems silly but not sure if there's a way to reference resources within wasm

Also, the Open Sans font is duplicated in /data. Seems silly but not sure if there's a way to reference resources within wasm
MartinFouilleul reviewed 2023-07-14 10:12:27 +00:00
MartinFouilleul left a comment
Collaborator

Since mp_clock_init() is called by the host, we can remove _OrcaClockInit() and the G_EXPORT_CLOCK_INIT descriptor.

Your _OrcaGetRawEventPtr() solution works, although we could also just have a global and get its offset with m3_FindGlobal.

We're only targeting little-endian platforms for the mvp, but marshalling seems to be kind of inevitable at some point when passing structs to/from wasm. (For now we wing it by relying on struct layout being consistent between the host and the guest. This won't necessarily be the case once we want to support other languages).

I tend to prefer prefixing include directives with the folder of the included file if it's not in the same folder of the file including it, so ideally we can just pass -I../../milepost/src to the compiler, rather than all the subdirectories of milepost/src.

Since `mp_clock_init()` is called by the host, we can remove `_OrcaClockInit()` and the G_EXPORT_CLOCK_INIT descriptor. Your `_OrcaGetRawEventPtr()` solution works, although we could also just have a global and get its offset with `m3_FindGlobal`. We're only targeting little-endian platforms for the mvp, but marshalling seems to be kind of inevitable at some point when passing structs to/from wasm. (For now we wing it by relying on struct layout being consistent between the host and the guest. This won't necessarily be the case once we want to support other languages). I tend to prefer prefixing include directives with the folder of the included file if it's not in the same folder of the file including it, so ideally we can just pass `-I../../milepost/src` to the compiler, rather than all the subdirectories of `milepost/src`.
Collaborator

Could you also add a call to the binding generation script for clock_api.json in the macos build script?

Could you also add a call to the binding generation script for `clock_api.json` in the macos build script?
ilidemi added 1 commit 2023-07-15 07:19:16 +00:00
ilidemi added 1 commit 2023-07-15 07:21:01 +00:00
ilidemi added 1 commit 2023-07-15 07:49:53 +00:00
Author
Collaborator

Just FYI, I'm getting GL errors and a black screen with the current version of milepost:

Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281
Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281
Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281
Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281
Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281
Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281

The last commits don't touch graphics so I'm assuming it's unrelated. Verified raw events and clock via logging.

Just FYI, I'm getting GL errors and a black screen with the current version of milepost: ``` Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 Error: mg_gl_render_batch() in C:\Users\ilia\Projects\orca\milepost\src\gl_canvas.c:1131: gl error 1281 ``` The last commits don't touch graphics so I'm assuming it's unrelated. Verified raw events and clock via logging.
Collaborator

Ok, there's a problem with gl buffers alignment, which is driver dependent. I'll get that fixed soon.

But there's also I think a problem with how you get the raw event slot. If I'm not mistaken, right now you get the address of _OrcaRawEventPtr and you write events to that location, which has the size of a pointer, not an event struct. The location you write to should really be _OrcaRawEvent, and you shouldn't need _OrcaRawEventPtr right?

(Btw, I kinda liked the way you changed the naming convention of event handlers to export, since we'll probably have exported functions that are not really handlers. I think you can keep this even if we remove GetRawEventPtr())

Ok, there's a problem with gl buffers alignment, which is driver dependent. I'll get that fixed soon. But there's also I think a problem with how you get the raw event slot. If I'm not mistaken, right now you get the address of `_OrcaRawEventPtr` and you write events to that location, which has the size of a pointer, not an event struct. The location you write to should really be `_OrcaRawEvent`, and you shouldn't need `_OrcaRawEventPtr` right? (Btw, I kinda liked the way you changed the naming convention of `event handlers` to `export`, since we'll probably have exported functions that are not really handlers. I think you can keep this even if we remove GetRawEventPtr())
ilidemi added 2 commits 2023-07-15 22:56:11 +00:00
Author
Collaborator

m3_FindGlobal indeed returns the address and not the value, I got confused by the .f64Value and .f32Value in the union. Memory corruption from writing to the pointer of pointer was also the cause for black screen - shows how interconnected raw C is. Now rendering is at 80% on the NVidia GPU :)

image

`m3_FindGlobal` indeed returns the address and not the value, I got confused by the .f64Value and .f32Value in the union. Memory corruption from writing to the pointer of pointer was also the cause for black screen - shows how interconnected raw C is. Now rendering is at 80% on the NVidia GPU :) ![image](/attachments/4ec8bb39-4864-4feb-86f0-99100029240f)
Collaborator

Hey! Looks great (tiling bug thanks to opengl alignment rules and my own stupidity. I'm fixing that right after merging this one).

Hey! Looks great (tiling bug thanks to opengl alignment rules and my own stupidity. I'm fixing that right after merging this one).
MartinFouilleul merged commit a95de7902f into main 2023-07-16 15:19:09 +00:00
Sign in to join this conversation.
No reviewers
No Label
macOS
windows
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: hmn/orca#18
No description provided.