Depth Stencil Texture array to render cube depth map in one pass

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Aug 29, 2012 at 15:20

Hi all,

I’m wondering if it’s possible to create 6 depth stencil surfaces for a cube depth map and then render

into them in the geometry shader in one pass using SV_RenderTargetArrayIndex.

I want to just bind the depth stencil part and not the render target part, since I’d like to disable color writes during shadow map generation, so there’s no point in passing any render target.

I would do deviceContext->OMSetRenderTargets( …,…, cubeDepthStencilMapView );

I would expect that if I do something like this in the geometry shader:

struct GS_OUTPUT{
      float4 Pos : SV_Position;
      uint  cubeDepthMapIndex : SV_RenderTargetArrayIndex;
};

...
for( uint i=0;i<6;++i){
cubeDepthMapIndex = i;
    
}
...

It will index the correct depth stencil surface even if there is no render target bound ? …
I can’t think that I have to create 6 depth stencil view and 6 render target view when the only thing that I need is just depth (moreover, color writes disabled make the rendering faster).

Can anyone confirm this possibility ?
thanks a lot in advance :P

7 Replies

Please log in or register to post a reply.

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Aug 30, 2012 at 17:51

Obviously I need to disable color writes on all the 6 depth stencil buffer (I bind one depthstencilview created as a texture2Darray resource, I assume that will be mapped on the first 6 slot like if I was setting 6 render targets … am I correct in assuming this ?) …

should I create a blend state with color writes disabled on all the 6 render target ? currently I do somehting like:

fdkGfxSetRenderTarget(device,NULL,mDeferredData->mPointLightShadowMapBufferId);

//set shaders
fdkGfxSetVertexShader(device,mDeferredData->mShadowMapOmniVS);
fdkGfxSetGeometryShader(device,mDeferredData->mShadowMapOmniGS);
fdkGfxSetPixelShader(device,NULL);

and the blend state created like:

//additive blend state desc
FdkGfxBlendStateDesc bsDesc;
ZeroMemory(&bsDesc,sizeof(FdkGfxBlendStateDesc));
bsDesc.independentBlendEnable               = false;
bsDesc.alphaToCoverageEnable                 = false;
bsDesc.renderTarget[0].blendEnable         = true;
bsDesc.renderTarget[0].srcBlend           = FDK_BLEND_ONE;
bsDesc.renderTarget[0].destBlend             = FDK_BLEND_ONE;
bsDesc.renderTarget[0].srcBlendAlpha         = FDK_BLEND_ONE;
bsDesc.renderTarget[0].destBlendAlpha       = FDK_BLEND_ZERO;
bsDesc.renderTarget[0].renderTargetWriteMask = FDK_COLOR_WRITE_ENABLE_ALL;
bsDesc.renderTarget[0].blendOp             = FDK_BLEND_OP_ADD;
bsDesc.renderTarget[0].blendOpAlpha       = FDK_BLEND_OP_ADD;
mDeferredData->bsId                        = fdkGfxCreateBlendState(device,&bsDesc);
//create
bsDesc.renderTarget[0].destBlend             = FDK_BLEND_ZERO;
bsDesc.renderTarget[0].renderTargetWriteMask = 0x00;
mDeferredData->bsNoColorWritesId          = fdkGfxCreateBlendState(device,&bsDesc);

should I disable blending as well ? I dont set the other renderTarget[1],renderTarget[2] … up to 5 becaouse I ZeroMemory the structure so I expect that blend enable is 0 and renderTargetWriteMask too.
However my application is damn slow ! So something strange happens and I think I did something wrong … If I try debug in pix the app crashes … :/

Any Idea ?

Thanks in advance

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Sep 03, 2012 at 14:21

Any hint ? I can’t think that I need a render target array of color along with the depth stencil one if I have to just render shadow data…

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Sep 03, 2012 at 16:18

Well, either nobody knows, or they are on vacation! I sure don’t know the answer.

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Sep 04, 2012 at 07:20

@Alienizer

Well, either nobody knows, or they are on vacation! I sure don’t know the answer.

It’s quite a simple question, I guess there is just some messiness concerning the parameters setting somewhere. In general I just wanted to verify that the basic creation process was correct.

The question is: Is it possible to create depthStencilView created as an array resource to render into its array element using SV_RenderTargetArrayIndex, without the need of a render target view (so render target view is set to null).
I need this to render a simple shadow cube map and I need obviously just depth (so color writes are disabled -> faster rendering :)).

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Sep 04, 2012 at 09:49

From “Programming Vertex, Geometry and Pixel shaders”:

There are some things to keep in mind though: As of Direct3D 10, you can
only set one depth stencil surface to the device at any given time. This
means that you need to store the depth values in the color data of the
render targets. Fortunately, D3D10 pixel shaders let us to handle
arbitrary values (including colors) as depth via views to typeless
resources, so this isn’t a problem.

I’m actually using DX10.1 so I think that might depend on that.

If that is the problem: Isn’t slower generating the shadow map with color writes on ? Maybe in dx11 I can bound more than one depth stencil view …

tbh on the internet I’ve found some people outputting linear depth in world space or view space to get more precision out of it and in that case a color buffer was compulsory if you don’t want z/w hiperbolic falloff

Any thoughts on this ?

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Sep 05, 2012 at 02:51

Sorry, but I am not an expect at this at all. I too ask questions on this board and there are a few very knowledgeable guys who answer, but I think they are not around right now, back to school etc. you know! I just thought to reply since nobody else did so you don’t think you are getting ignored!

Cd586a7130b6cb95bed9ae57223fad5c
0
SuperPixel 101 Sep 05, 2012 at 09:43

@Alienizer

Sorry, but I am not an expect at this at all. I too ask questions on this board and there are a few very knowledgeable guys who answer, but I think they are not around right now, back to school etc. you know! I just thought to reply since nobody else did so you don’t think you are getting ignored!

Hi,

no probs, the thing is that I made a mistake myself :). When we use a cubemap we output radial distance from the light not depth (which we could if we decide to not to go for cubemaps but for 6 spot lights :) to approximate the environment surrounding the point light).

So, my question was wrong in the first place.

Since I decided to use cubemaps for spot light then I MUST use render target in order to write color along with depthstencil to have depth test.

So sorry for my question :)