Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Renderqueue design theory and implementation


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
5 replies to this topic

#1 phr34k9   Members   -  Reputation: 155

Like
0Likes
Like

Posted 27 June 2011 - 02:09 PM

I have a rough render queue implementation. However I am struggling with the implementation of spatial meta-data i.e. world-matrices of the command queue but there doesn't seem to be much literature about the subject. My implementation is based on bit-packing the necessary information in as tiny data-structures as possible to achieve narrow command streams/queue. An example of this would be packing a 24-bit fixed-point-math depth-key for including depth-sorting. Prior to rendering the stream(s) are sorted based on the packed data structures allowing for a flexible render system design.

There are several routes i can go with my implementation: 1) Embed the spatial meta-data in the command stream itself, by reserving a portion of the stream in the stride i.e. struct { int sortkey, matrix4x4 worldpos }; 2) Refer to the matrix by id i.e. struct { int sortkey, int matrixId }; 3) Embed the spatial information into a parameter set of the material.

No 1. Is my current implementation since it's straight forward, however this creates quite a wide command stream again, and every shader-pass I apply is added as a separate command. So this solution has possibilities for quite a bit of memory consumption/overhead i.e. 64 bytes extra per call. Deferred rendering in this situation will help somewhat since it minimizes the amount of time the geometry has to be reprocessed and therefor added to the queue, but i estimate you'd have at-least 2 to 3 passes (special effects, shadow mapping etc).

No 2. Seems rather appealing since you have an integer which would makes the command stream narrow again, 60 bytes gained per call. Which would allow for quicker sorting, less memory copying/swapping. However after sorting there is a chance that matrices are accessed in random order i.e. unpredictable fashion and making the algorithm cache hostile in comparison.

No. 3. Seems far from ideal since essentially if we treat the world matrix as another shader parameter the render pipeline has a tendency to be be 'unaware' of it. And my parameter set is optimized for storing their respective parameters for data efficiency rather than lookup efficiency i.e. using homogeneous arrays. Hence forth this solution in my opinion disables interesting instancing concepts with dx11/gl4 hardware i.e. pumping all world matrices into a uniform buffer and unpack them at shader level.

For now solution no. 1 is implemented and suffices for the time being, i also don't anticipate that to change in the foreseeable future, but i would like to orientate/educate myself on what would be considered the 'better' approach to meet the demands for 'scalable, stream-able, massive worlds rendering'. So I would like to know what experience you guys have with various implementations (regarding render queue's, I'm not interested in hearing about visitor patterns for scene-graph traversal) maybe you got something better that I've never considered.

Sponsor:

#2 smasherprog   Members   -  Reputation: 432

Like
0Likes
Like

Posted 27 June 2011 - 03:29 PM

maybe someone else understands what you are trying to do --I don't

What exactly are you attempting to do? You never state that in your post. What is your dilemma?
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#3 phr34k9   Members   -  Reputation: 155

Like
0Likes
Like

Posted 27 June 2011 - 04:16 PM

maybe someone else understands what you are trying to do --I don't
What exactly are you attempting to do? You never state that in your post. What is your dilemma?


Well the last paragraph did state what I'm trying do. It however assumes you comprehended the paragraphs above and have some background information on the subject in general. But to summarize: for now I'm not attempting to do anything; I'm trying to educate myself with the perspectives / experiences other people might have had on the same subject. The subject I'm interested in is what's considered the 'best' way to organize world-matrices in conjunction with a render queue. They could be adjacent to an individual command as a supplementary argument (making each command say 96 bytes fixed size), or they could be resolved by an indirection ((pointers or index of a well known array) making each command 12 bytes fixed size), or another solution to your liking.

Hope that helps you understand the essence of this post/topic.

#4 Hodgman   Moderators   -  Reputation: 31926

Like
3Likes
Like

Posted 27 June 2011 - 06:14 PM

IMHO, special cases in any design are usually a flaw, hence the idea of treating your world-matrix as a special case really irks me.

What about static meshes that don't need a world matrix? What about shaders that want a pre-multiplied world-view-proj? What about skinned materials that want an array of world-matrices (one per bone instead of one per model)?

Maybe some more details about what stuff goes into your queue would help make it clearer which is the best design for you?


In my submission queue, each item contains:
* a 32-bit sorting key -- could be depth, could be a state hash, could be both. The low-level renderer just treats it as 32 bits. Higher up systems can fill it with whatever bits they want.
* a draw-call (e.g. a structure that maps to DrawIndexedPrimitive etc, and an enum saying which one it's mapping to)
* a variable number of pointers to state groups (which means the items in the queue are variable sized).

A state group is a resource that contains a variable number of state-change commands, e.g. bind this shader, bind this texture, bind this cbuffer.
A cbuffer is a resource that contains shader constants, such as matrices.

So when submitting a group of objects, their updated matrices are put into the associated cbuffers (could be one cbuffer per object, or an indexed/shared one like you mention), and then their draw-calls are put into the queue paired with a state-group that contains a command to bind the associated cbuffer for that draw-call.


When sorting, you don't necessarily have to copy/swap the items around. To sort my items, I make a new array and copy pairs of sort-keys and item indices into it. I then sort this 'key/index' array instead.
Afterwards, I can use this sorted array to re-order the queue, OR, I can leave the queue as-is, and use the sorted indices during processing of the queue.
On x86, I've found it's usually faster to not re-order the queue, and simply process it in an indexed manner.

#5 phr34k9   Members   -  Reputation: 155

Like
0Likes
Like

Posted 27 June 2011 - 09:41 PM

Maybe some more details about what stuff goes into your queue would help make it clearer which is the best design for you?


Well the main reason why I'm treating world matrices as a special type is to take advantage of hardware instancing ( i.e. glAttribDivisor ) as introduced in dx11/gl4 hardware. My queue simply exists out { sort_key, mesh, material, matrix4x4 } and only aims to support drawing materials/shaders that are compatible with render-pipeline. The shader-passes that collectively represent a 'material' all have a common structures, mainly this is because the shaders are generated from text-transform-templates this allows me to assume various optimisations: all material based shader can share a 'pipeline based semantic set' (think view-/projection- matrices and viewport settings), all shader-passes and their respective features are implemented in a consistent manner. For instance if the pipeline detected instancing is available for the next sequence of elements, supporting instancing would be as simple as selecting/generating the shader with instancing flag turned on, and generate a cbuffer/bindable uniform buffer with an array of world matrices.

So in short the pipeline is somewhat more restrictive in comparison to your method as it expects a shader-pass to implement a certain contract / behaviour, but it also gains lot of grounds on newly gained heuristics and possible optimizations. Regarding pre-multipled world matrices, i think that could simply be solvable with a boolean to conditionally pre-multiply the matrices. Objects that don't need a world matrix use the identity matrix (but how many of those do really exist?). Skinning similar to instancing could be solved by generating render-pass(es) with skinning support, and uploading the bones into a supplementary cbuffer/bind-able uniform buffer.

Still think reserving the world-matrix as a special purpose semantic is irky? :)

#6 Hodgman   Moderators   -  Reputation: 31926

Like
1Likes
Like

Posted 27 June 2011 - 11:35 PM

OT - How do you deal with other per-mesh-instance states at the moment (besides world transform)? e.g. a per-model colour, or making a particular model fade out, etc... Do you clone it's material and apply the change to the material?

Still think reserving the world-matrix as a special purpose semantic is irky? :)

Yeah, sorry!
You've just added a whole bunch more special cases (pre-multiply flag, skinned flag, etc) to deal with the fact that there's a special case. I'm sure there's a clean, general system hidden somewhere in that design that just wants to be set free Posted Image
As another 'what if' -- what about items that require data other than (or as well as) a world-matrix per instance (e.g. a colour, or a texture offset, etc)?
Regarding identity world-transforms, all static level meshes in the game I'm currently working on have their matrices pre-baked into the vertex data. The static level geo probably makes up over half of the draw-calls.

In my system, I'd perform instance-grouping (and updating of any instance-cbuffers) in the layer above the render queue. E.g. the thing submitting the 'groupable' models would copy all their world matrices into the instance buffer and submit the instanced batch to the queue.
It's also valid to put the instance-grouping on the other side of the queue like you have -- I'd just prefer to do it in a way that doesn't hard-code the type of the per-instance data (i.e. the assumption that instance data == world matrices).

Your pipeline stuff sounds pretty much the same as what I'm working with at the moment -- a state group can bind a "shader", and a shader is a collection of "passes". Each pass is designed to be used by a certain stage of the pipeline. Each pass also has many different permutations (actual shader programs) depending on the currently set options.
e.g. when submitting a model, if you enable the 'instanced' option, then it would select the appropriately generated shader programs like you descirbe.
When submitting a model, it will only be queued up for the pipeline stages that it's shader supports.




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.



PARTNERS