• Advertisement
Sign in to follow this  

[DX10] TextureArray as rendertarget

This topic is 2294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got the hang of binding several resources as rendertargets (by passing an array of them to OMSetRenderTargets) and writing to them simultaneously by outputting a struct from the pixel shader with the SV_Target[n] semantic applied to each field in the struct.

To stop me having to pass each resource individually to the next shader which needs them, I'd like to use a texturearray to keep them all in a single resource (as they all get passed to the same place anyway) instead of separate resources. I've googled around and it seems like it's possible, but I've not been able to find any explanation of how to implement it.

I'm guessing I create a texture array resource as many clices deep as I need, then pass that single resource into OMSetRenderTargets instead of defining an array of resources and passing that (as I am currently doing), but how do I address each slice in the shader code? Do I just output a struct from the pixel shader and use SV_Target[n] again?

Share this post


Link to post
Share on other sites
Advertisement
Not sure if this works (haven't tried myself), but instead of using only one render target view, you could again bind several targets, but let each one select a different slice from the same array by configuring D3D10_TEX2D_ARRAY_RTV appropriately. Would really be interesting to know if this works (and helps performance).

Alternatively you could use SV_RenderTargetArrayIndex. This only seems to apply to geometry shaders, though.

Share this post


Link to post
Share on other sites
Yeah, after a bit more research, I've seen a couple of articles mention SV_RenderTargetArrayIndex, but they seem to disagree as to whether it can be used in a pixel shader. I suppose I'll just try it and see.

Share this post


Link to post
Share on other sites
Small update: I just did a quick check with the multiple RTV. It works :D ! Tried it on DX 11, but feature level 10, so you should be fine. Make sure your subresources don't overlap. It's pretty straight forward, but here is some SlimDX code anyway (tex1 being a Texture2DArray):

RenderTargetView target1 = new RenderTargetView(device, tex1,
new RenderTargetViewDescription()
{
Dimension = RenderTargetViewDimension.Texture2DArray,
ArraySize = 1,
FirstArraySlice = 0,
MipSlice = 0
});
RenderTargetView target2 = new RenderTargetView(device, tex1,
new RenderTargetViewDescription()
{
Dimension = RenderTargetViewDimension.Texture2DArray,
ArraySize = 1,
FirstArraySlice = 1,
MipSlice = 0
});
RenderTargetView target3 = new RenderTargetView(device, tex1,
new RenderTargetViewDescription()
{
Dimension = RenderTargetViewDimension.Texture2DArray,
ArraySize = 1,
FirstArraySlice = 2,
MipSlice = 0
});
RenderTargetView target4 = new RenderTargetView(device, tex1,
new RenderTargetViewDescription()
{
Dimension = RenderTargetViewDimension.Texture2DArray,
ArraySize = 1,
FirstArraySlice = 3,
MipSlice = 0
});

With this approach you don't need a geometry shader.

Share this post


Link to post
Share on other sites
You can't use SV_Target to control which array slice you render to, that controls which render target texture you render to (if you have multiple render targets bound). The only way to make it shader driven is to use SV_RenderTargetArrayIndex, which is output by the geometry shader.

Alternatively you can make a render target view that controls which slice you render to, which is is what ubird is suggesting. But this only works if you need all triangles in a draw call to go to the same slice.

Share this post


Link to post
Share on other sites
Right, so I'm stuck drawing to an array of separate resources then?

It's not the end of the world, it just would have been nice to pass round the outputs as a single resource rather than having to set each one separately in the next stage.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement