Texture queue in a volume texture (dx11)

Hello my dear shader friends,

i recently came up with the idea of a queue (texture) completely done by a shader.

in theory, this could work like that:

  • First, we create a volume texture with a defined depth (= Frame Count)
  • every frame, each slice of this volume-texture slides one position “down”. the first slice 0 becomes empty
  • the first slice gets filled with a Texture2D

what i don’t know:

  • what is the most appropriate way to start?
  • should this be a TFX? Or a Shader > Renderer (DX11 Volume)?

what do you think? Any more or better ideas?


It’s pretty easy (actually got that already in my personal lib) ;)

Doing Queue is not ideal tho, since you need to rewrite the whole volume every frame, RingBuffer is much more efficient (requires a little bit more work on sampling side after, but still major performance gain)

I have that as a plugin with embedded shader, but could actually be patched.

TFX won’t work since it only operates on 2d texture, but Renderer (DX11 Volume) with clear pin set to false should work.

2 ways to do it:

  • VS (full screen quad) -> GS (use SV_RenderTargetArrayIndex as gs output to specify which slice to write to) -> PS (sample as a passtrough). This is the one I use, it’s easy and fast
  • CS -> Dispatch enough threads so you can fill a single slice, and use scattered write to only write to the slice (i’d say it’s prolly a bit slower, but less code)

If you really need queue you can do a second CS pass (on another volume) to reorder all that lot, didn’t tried but should be easy ;)

I’ll post a sample once done with beta30 update (will be nice new girlpower addition ;)

ok, i did not completely understand your answer, but bravely started coding something.

as a first step, i rebuilt the FullscreenQuad thingy for DX11. I tried to make it as similar as possible to the dx9 one. (Only differences i found are depth buffering which behaves bit different. and i didn’t implement all those useless blend modes).

Perhaps, you can point out that part a bit more: GS (use SV_RenderTargetArrayIndex as gs output to specify which slice to write to)

As i understood it, you use a geometry shader to place the 2d-texture to a given slice in a 3d texture?

Second thing you mentioned is that ringbuffer vs. queue argument, which i can comprehend but have to state, that a queue is much more easy to use imo. but, one thing at a time :)

FullScreenQuad DX11.rar (54.6 kB)

ok, i started the geometry-shader. there’s still missing the vertex-shader from the post before. but maybe other quirks in there…

VolumeQueue.rar (3.2 kB)

ok, it’s kinda not looking right now
what vux told, you should try with a compute shader since it’s less complicated on my taste, like sampling in to a buffer then access to array

i’ve seen somewhere you can do red/write buffers on ps also btw

the explanation is as usual:

Render-target array index. Applied to geometry shader output and indicates the render target array slice that the primitive will be drawn to by the pixel shader. SV_RenderTargetArrayIndex is only valid if the render target is an array resource. This semantic applies only to primitives, if a primitive has more than one vertex the value from the leading vertex will be used.
This value also indicates which array slice of a depthstencilview is used for read/write purposes.
Can be written from the geometry shader and read by the pixel shader.

vs in 
   uint   InstanceID		: SV_INSTANCEID; 
gs in    


// send us to the right render target 
	output.RTIndex = input[0](0).InstanceID;

this part you prob missing, but that not gonna work copy paste
and prob need something more then that

ok, i’ve tackled the next step - a working ringbuffer via geometry-shader.

only one part is still missing: the sorting of the volume-texture, so it becomes a queue (like mentioned by vux above).

Is there any trick to do this efficiently? perhaps a similar way like we’ve done this in 2d and ex9?

i attached two files: the current development and the old but fast 2d-method

VolumeQueue2.rar (6.4 kB)
Texturequeue2D.v4p (31.2 kB)

this is awesome!!!

yea cool stuff sebl gratis!

i’m done

any extensions or improvements?