aleksigron / kokko

Simple cross-platform game engine using OpenGL.
MIT License
22 stars 2 forks source link

Separate render and dispatch stages in Renderer #29

Closed aleksigron closed 1 year ago

aleksigron commented 2 years ago

The render and dispatch stages, as I will call them here, are currently combined into one procedure. I will give short description of what I mean with the stages.

There is also an earlier stage in Renderer, where objects and control commands are added to a command list to be sorted in the right order relating to viewports and render passes. This stage does not need to change to complete this task.

Here are some notes for the technical implementation.

Any information coming back from the render command calls are a complication. For example creating any resources (buffers, textures, framebuffers, samplers), return the IDs of the created resources. These IDs need to be able to be used immediately after encoding the command. The normal use case is to create a resource, and immediately update its properties and data. This means that we need to create some kind of ID immediately when the command is encoded and then map that ID to the actual ID assigned by the driver.

Another issue are shader compilation and uniform location retrieval. It might be necessary to have a method of running GPU commands synchronously, since these tasks would otherwise be incredibly hard to accomplish. For now, it is possible to just use existing RenderDevice interface for that. In the future, though, we would need a way to run these synchronous command blocks on the correct thread.

Separating the render and dispatch stages is a prerequisite to moving rendering to another thread. The data can be built on multiple threads if needed, since we are not yet calling any GPU commands. Then we can move the data to a separate render thread where it is a very simple job to submit the actual GPU calls from the command data. Using multiple threads to build or execute the data is not part of this task.