Rendering architecture using commands and bitmasks

Started by
5 comments, last by lipsryme 11 years ago

I've been going through threads and other useful pages like this http://realtimecollisiondetection.net/blog/?p=86 but there's something I'd like to get a confirmation on that I'm not going to do something wrong...

So how does this work in praxis...I've got my scene where I define what I want to draw and what material should be put on it...etc...

But is this already where I create the corresponding command for the render queue ?

Let's say I've defined this command and sent it (either alone or as an array of commands) to the render queue (a higher level class that processes and sorts this). For this to work don't I need to have a multiple pages long if/else branch to basically parse this information first ? How else would I translate the bitmask to their corresponding commands. E.g. I want to clear the screen, so I set my bitmask to something predefined that defines the specific action and send this command to the render queue. But now I need to process this command and see which corresponds to what.

Is this correct or is there a small thing that I'm missing that makes this a little more elegant ?

Advertisement
Yeah you're basically implementing a VM. So, when you've extracted a command ID (e.g. "clear"), you then feed that value into a giant switch statement, or you use it to index an array of function pointers.

Alright thanks, wasn't sure since it's a little untidy ;)

switch statements! \m/

I'm still having problems understanding how I would build a specific process using these commands in praxis.

E.g. defining an ID for a few API calls isn't a problem but if I wanted to make a Clear() call I'd also need to fuel it with additional information that might even be unavailable at the time the command is being made. How would I do that?

Then for example I'm doing post processing (would I even do that using commands?) and wanted to do bloom where there's a lot of render target swapping and temporary render targets involved...I'm curious how that would look inside the code.

My idea would be to define a method in my higher level renderer that looks something like this:


void RenderQueue()
{
   std::vector<UINT64> commands;

   foreach Entity
   {
      // Frustum Cull      

      // Create Command (Draw call)
   }

   // Create PostProcessing commands
   DoArbitaryPostEffect(commands);

   // SortCommandList

   // Send Command to low level renderer
}


void ArbitraryPostEffect(std::vector<UINT64> &commands)
{
   // Create command for setting the render target here
   commands.push_back(SetRTCommand);
   
   // Create command for setting the texture
   commands.push_back(SetSRVCommand);

   // Create command for setting the constant buffer
   commands.push_back(SetCBCommand);

   // Create command for the actual draw call using a fullscreen quad
   commands.push_back(FSQDrawCallCommand);
}

The guy in the blog (link in my post above) says he's using a single bit to know if the last part was depth or a command.

I'm having a hard time imagining how this would be sorted in a correct way.

For example in a deferred renderer I'd have a specific order of doing things.

I was thinking of having the first sort criteria (MSB) being my pass (e.g. GBuffer = 0, Lighting = 1) so it is sorted and executed in that order.

But now if I were to mix my draw calls with commands how would I still get a correct ordering of those things in the end?

You can feed your own equality and compare functions to the STD sort algorithm, so you can implement the way it does the compare in the sort how you see fit. So that means the in the compare you could ignore that part of the key to sort on for example. And that is also what he is expressing with the fact that you sometimes want to order on depth instead of shader instance.

The order of post and gbuffer construction can all be dealt with in the lower level renderer all this feature allows you is a way to control how (read in what order) the render data flows through your render calls. In the DiRT series a similar technique is used in the generation of the render data, the render queue then takes this flag into account when inserting the render data into the renderqueue. After that the render just takes the queue and renders it.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

Okay so when inserting the depth values to the bitmask how do I do that ?

If I use the object's Z value it could be negative which wouldn't work, right ?

What I need in the end is just the correct order so like [0,1,2,3,...] either front-to-back or back-to-front sorted but I'm not sure how to express that inside parts of the bitmask.

I'm not used to working with bitmasks...

edit: Oh I see I use the distance from the object to the camera as depth value tongue.png

This topic is closed to new replies.

Advertisement