What's the recommended use of `dispose` method and `Aux` type?

(Duncan Fairbanks) #1

I’ve been messing around with rendy lately, really loving it so far, and I’m wondering about the intended use of dispose methods w.r.t. the Aux type. I see in the examples that the render graphs are manually disposed for some reason (this destroys semaphores and disposes the DynNodes in the graph, which seems very important for cleaning up render passes). I presume this is done manually since pipelines are supposed to define their own dispose methods, and the graph will call these in the correct order relative to internal state.

Now to my particular question. I’m thinking I want to allow users of my renderer to own their own Meshes, since they will decide when the mesh should be dropped. But the meshes must also be part of the Aux type so the renderer can use them. This means I want my Aux to be ephemeral, created once each draw call. It would only have a reference to each mesh. But the graph dispose method takes an Aux parameter. I was planning on having my renderer dispose the graph in a Drop impl, where the meshes would not be accessible. This seems to force me into having Aux with a field of type Option<& ...> to only reference my meshes during a draw call, but be None for dispose.

Does this seem like an anti-pattern? What am I expected to do in dispose for a pipeline? I see some of the examples do nothing. I can’t think of anything I should do there. I guess it just seems a little awkward to have to pass my Aux type to graph dispose in order to do nothing with it.

EDIT: Upon trying to give my Aux type a reference field, I needed to add a lifetime, and it seems that GraphBuilder::add_node requires 'static lifetime for the added NodeBuilder, which seems to thwart my plans, since my NodeBuilder is a RenderPassNodeBuilder<Backend, Aux<'s, Backend>> :frowning:. Guess I’m going with Rc for now.

1 Like

(Paweł Grabarz) #2

Think of the aux as a gateway to your game world. In amethyst, we use specs::Resources as the aux type. This allows us to reference all meshes on any entities in the world during rendering. This isn’t ephermal at all, but instead it’s mutable (in case of Resources, it has interior mutability). Disposal is mostly needed for cases where your passes decide to allocate GPU resources manually, as opposed to taking everything from rendy’s factory, where it’s guaranteed to be disposed after dropping once GPU doesn’t need it anymore. When you create the resources on your own, you have to also dispose them on your own. This might need a reference to your world for whatever reason (your aux type may have a custom allocator on it for example, and say you want to release something from it).

As it turns out, after we’ve incremenatally added automatic resource management to rendy, most dispose methods ended up being empty. This might be true in your case as well, and it isn’t a bad thing. If you want to have some kind of ephermal storage that’s being completely replaced every frame, make it a PART of your aux type, replace it without replacing the shell.

3 Likes