MikalDev

Are there plans for adding webgpu runtime support? Our current game engine Construct 3 has webgpu on their roadmap and are starting to implement support. For the Construct 3 runtime to be compatible, we would want to use a spine-ts runtime with webgpu support.
MikalDev
  • Postovi: 70

Mario

We'll add support once WebGPU ie widely supported by browsers. It will be a new backend similarly to spine-webgl. At the moment, browser support is pretty lackluster, and iirc, the spec isn't finalized yet. https://caniuse.com/?search=webgpu
Avatar
Mario

Mario
  • Postovi: 2827

MikalDev

Thanks for the reply, from what I see, it's been enabled as a trail feature in a number of browsers, so early development can start, but yes has not been released yet. Ok, good to know it's on the roadmap when browser support is widespread.

---

I am also discussing this with Ashley, the lead C3 dev. He is encouraging me use the C3 SDK as a shim between Spine-ts and C3, so we don't get exposed to web GPU directly. However at least one issue I am aware, that won't support two color tint well (or perhaps at all), because C3 shaders must use uniforms, I can't use vertex parameters like the Spine-ts WebGL shader does. If I use uniforms, it will break the batch whenever two color tint changes on a slot, etc. So, we are still discussing.

If you are interested, the thread is here:
https://www.construct.net/en/forum/construct-3/plugin-sdk-10/webgpu-renderer-allow-webgpu-164365
MikalDev
  • Postovi: 70

Mario

I think it makes sense to port the 150+ lines of SkeletonRenderer reponsible for drawing to Construct's renderer interface. OTOH, I can't imagine it being hard to allow custom vertex formats in C3 if they also allow custom shaders. But I have no insight into the C3 code base, and they likely have bigger fish to fry. Ashley is the expert on that. I do have a feeling he's not quite understanding what two color tint does, and how the renderables of a single skeleton using that feature would look like.

--

OK, I just checked the IWebGLRenderer interface. That is very limited, and I don't think it would be easy to have a performant skeleton renderer implemented on top of it. It appears to only be able to render quads. I wonder how hard it would be to add a method that allows rendering (indexed) triangle lists. Something like an expert mode function for plugin writers. That would make it easy to port SkeletonRenderer to their API (together with texture loading using their API). It would still not solve the two color tint issue, unless the vertex format of the triangle list plus a shader could be provided.

--

I've replied extensively on the C3 forum: https://www.construct.net/en/forum/construct-3/plugin-sdk-10/webgpu-renderer-allow-webgpu-164365#forumPost1054581
Avatar
Mario

Mario
  • Postovi: 2827

MikalDev

Mario, thanks so much for chiming in on the C3 forum, very much appreciated.

Hmm, I actually don't see your post. I know the C3 forum has been having problems recently, I hope your post did not get lost...
MikalDev
  • Postovi: 70

Mario

Oh, it's pending approval by an admin. Here it is in full:

--
Hey, Ashley, Mario from Spine here. Sorry for bursting into this thread. Mikal asked me to chime in.

I think your suggestion of going through IWebGLRenderer (and IWebGLTexture) is spot on. That will ensure future compatibility, and allow the underlying C3 renderer to do its best batching renderables.

That said, for the renderables that need to be rendered for Spine skeletons, the current IWebGLRenderer interface is not ideal. There are two issues:

1. IWebGLRenderer only supports rendering individual (textured) quads. Spine skeletons are rendered as textured triangles. A single skeleton may consist of a few dozen to thousands of (indexed) triangles. Going through IWebGLRenderer would thus require us to use degenrate quads to render triangles, and also looses us the more performant indexed triangle rendering. I assume that methods like IWebGLRender.Quad() and consorts add vertices to an underlying vertex buffer with a fixed vertex format, i.e. x/y,u/v,rgba.

Maybe it would be possible to add an "expert" method like IWebGLRenderer.triangles()? The parameter would be a array of vertices in C3's vertex format. Each consecutive 3 vertices would make up one triangle. Ideally the array contents could be directly copied to the renderer's vertex buffer (which may require the parameter to be an ArrayBuffer instead of a vanilla JS array). This would still not allow for indexed triangle rendering, but would remove all the overhead of issuing individual calls to IWebGLRenderer.Quad().

2. Spine's two color tinting (aka tint black, see esotericsoftware.com/spine-slots) requires a custom vertex format (x,y,u,v,color,dark color) and shader. Why the custom vertex format with the additional attribute? Batching. A Spine skeleton consists of many attachments, e.g. one for the head, one for the torso, etc. Each attachment is essentially a textured triangle mesh. There may be dozens of attachments in a single skeleton (amd hence dozens of meshes). Each attachment can apply two color tinting to its mesh. This could be implemented by setting the dark color as a shader uniform, but that would break batching of attachments. Instead, the dark color of an attachment is written as an additional vertex attribute to each of its mesh' vertices. While that may seem expensive, it's actually orders of magnitude faster, as it allows batching. The additional data that needs uploading to the GPU is negligible.

In order for this to work in C3, IWebGLRenderer would have to expose a way to specify the vertex format (and the two color tint shader, which seems possible). I see two ways to accomplish this.

One way would be to allow extending the vertex format C3 is using. The vertex format would always have the default C3 attributes. A plugin could then tell C3 to add additional attributes to the defaults. The C3 renderer would just write a default value for those additional attributes, while the plugin can set whatever is necessary when rendering renderables it controls. The plugin would still go through the proposed IWebGLRenderer.triangles() above, so the C3 renderer could still batch everything as the vertex format is constant across all renderables.

Now, changing the default C3 vertex format is a big ask imo, as it may ripple through the entire C3 rendering code base I'd assume. I could imagine another method on IWebGLRenderer, i.e. IWebGLRenderer.customTriangles(triangles, vertexFormat, shader). That would allow a plugin to implement its own batching with a custom vertexFormat and shader for a single renderable, i.e. one Spine skeleton consisting of dozens of meshes. That renderable could of course no longer be batched with other C3 quads. I think this could be a good compromise between performance, extensibility, and the amount of changes needed in C3 itself.
Avatar
Mario

Mario
  • Postovi: 2827

MikalDev

Great post, Ashley responded in his normal way which is to push back. However, in my experience, he does listen to different points of view and can be collaborative in terms of coming to a solution. I responded with comments about our use of the plug-in, but you have more details about the typical use of a two-color tint. In general, I imagine it's very project/game specific.
MikalDev
  • Postovi: 70

Mario

You've already outlined it perfectly in your reply imo. We've been in contact with Ashley in 2017 when they did their C3 SDK. Back then we also hit reluctance to change anything. I think that's fair. Only he knows their internals, and as a 3rd party, we can't expect them to change their internals for us. I've tried to add more info in the thread.
Avatar
Mario

Mario
  • Postovi: 2827


Natrag na Runtimes