Yo dawg, I heard you liked refactoring…

Published by leon on

You know that thing you do when you’re learning something new, so you make every mistake under the sun and / or massively over complicate / engineer things? Yeah, I did that.

As I mentioned in my last post, I did get textures working – but there was a large caveat. I only had a single shared descriptor set, which meant all meshes shared the same textures.

So I did a bit of refactoring, I moved the descriptor set creation to the model component of the Game Object so my render system could grab them. I then decided I wanted a UBO for certain shared properties for debugging purposes (I already had a “GlobalUBO” for things like the cameras projection matrix etc.). So I moved the descriptor set creation to the render system itself, which meant I then had to cache the these descriptor sets in the render system. This didn’t feel right, even at the time, but I went and forged ahead anyway.

This was obviously the wrong decision, and for a number of reasons.

  • Having to cache in the render system means a cached descriptor set per Game Object, so if I have multiple instances of the same Game Object (like my 3 T-Roys above), You have multiple copies of the same descriptor sets that could and should be shared. This is a solvable problem, you could just cache a bit cleverer, but it is extra work unnecessary work.
  • You have to keep track of this cache when Game Objects are destroyed so you can free the descriptor sets.
  • The properties I needed to pass are actually per model, not shared for all Game Objects and the shared properties made sense to go into the GlobalUBO. I don’t know what I was thinking honestly.

Moving the descriptor set creation back to the model class makes the most sense I think, it means there is no need for a cache, the descriptor sets will be per model and they can be freed when there is no longer any references to the model (they’re a shared pointer on a Game Object currently). It does mean that the model class is tied explicitly to the render system (or at least the pipeline layout of the render system), but I can’t see why that would be a problem (until I have more render systems that use the same models? I’ll cross that bridge…)

So yeah, more refactoring needed… I think it would pay to plot out the engine architecture while it’s still nice and simple. That way I could potentially see the impact of my bad decisions before I make them… maybe?

On a more positive note, I did get a couple of debug drawing modes hooked up to hotkeys which is nice, when I have a text overlay system implemented I’ll be able to see what kind of impact my shaders are having on the FPS and other fun stuff.

Debug Mode: No Lighting
Debug Mode: No textures

I have finished the Vulkan Cookbook, I suspect I’ll go back to it here and there when needed.

Oh and lastly, I learnt about memory alignment after banging my head against a wall for a while trying to figure out why a couple of bools I was trying to pass through push constants / uniform buffer objects were spontaneously changing state.

Anyway, back to refactoring.

Categories: Game Dev

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *