Jump to content

  • Log In with Google      Sign In   
  • Create Account

Rendering architecture using commands and bitmasks

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 lipsryme   Members   -  Reputation: 985


Posted 06 March 2013 - 03:16 PM

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 ?

Edited by lipsryme, 06 March 2013 - 03:20 PM.


#2 Hodgman   Moderators   -  Reputation: 27458


Posted 06 March 2013 - 03:29 PM

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.

#3 lipsryme   Members   -  Reputation: 985


Posted 06 March 2013 - 03:34 PM

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

#4 blackpawn   Members   -  Reputation: 193


Posted 06 March 2013 - 04:00 PM

switch statements! \m/

#5 lipsryme   Members   -  Reputation: 985


Posted 21 March 2013 - 12:45 PM

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

   // SortCommandList

   // Send Command to low level renderer

void ArbitraryPostEffect(std::vector<UINT64> &commands)
   // Create command for setting the render target here
   // Create command for setting the texture

   // Create command for setting the constant buffer

   // Create command for the actual draw call using a fullscreen quad



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?

Edited by lipsryme, 21 March 2013 - 12:50 PM.

#6 NightCreature83   Crossbones+   -  Reputation: 2669


Posted 22 March 2013 - 07:05 AM

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.

Edited by NightCreature83, 22 March 2013 - 07:08 AM.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#7 lipsryme   Members   -  Reputation: 985


Posted 24 March 2013 - 10:20 AM

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

Edited by lipsryme, 25 March 2013 - 04:29 PM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.