XNA Creators Club Online
Page 1 of 1 (3 items)
Sort Posts: Previous Next

How to use SV_Target[n] semantics?

Last post 6/16/2008 11:54 AM by XVincentX. 2 replies.
  • 6/11/2008 3:44 PM

    How to use SV_Target[n] semantics?

    Hi,

    Recently, I'm working on a project requiring MRT functional. I tried to implement my algorithm with  MRT controlled at primitive level in a geometry shader. The program works fine.

    However, for comparing performace, I want to implement a version with MRT controlled at pixel level in a pixel shader. In the old days, we set multiple render targets, and set COLOR[n] semantics in the output of a pixel shaders. With DX10, I guess I should do the task by setting a render target array, and set SV_Target[n] semantics:

    So here is the code where I create a render target array in size of ATTR_COUNT.

    //create render target array 
        D3D10_VIEWPORT vp; 
        UINT n = 1; 
        mpDev->RSGetViewports(&n,&vp);   
        D3D10_TEXTURE2D_DESC td; 
        td.ArraySize = ATTR_COUNT; 
        td.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; 
        td.CPUAccessFlags = 0; 
        td.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 
        td.Height = vp.Height; 
        td.Width = vp.Width; 
        td.MipLevels = 1; 
        td.MiscFlags = 0; 
        td.SampleDesc.Count = 1; 
        td.SampleDesc.Quality = 0; 
        td.Usage = D3D10_USAGE_DEFAULT; 
        VALI_RN(mpDev->CreateTexture2D(&td,NULL,&mpMidRenderTarget),E_FAIL); 
         
        D3D10_RENDER_TARGET_VIEW_DESC rtv; 
        rtv.Format = td.Format; 
        rtv.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY; 
        rtv.Texture2DArray.ArraySize = ATTR_COUNT; 
        rtv.Texture2DArray.FirstArraySlice = 0; 
        rtv.Texture2DArray.MipSlice = 0; 
        mpDev->CreateRenderTargetView(mpMidRenderTarget,&rtv,&mpMidRenderTargetView); 
     
        //create mid shader resource view 
        memset(&srv_desc,0,sizeof(srv_desc)); 
        srv_desc.Format = td.Format; 
        srv_desc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DARRAY; 
        srv_desc.Texture2DArray.ArraySize = ATTR_COUNT; 

     

        srv_desc.Texture2DArray.FirstArraySlice = 0; 
        srv_desc.Texture2DArray.MipLevels = td.MipLevels; 
        srv_desc.Texture2DArray.MostDetailedMip = 0; 
        mpDev->CreateShaderResourceView(mpMidRenderTarget,&srv_desc,&mpsrvMid);  

    In fact, this code works fine in my geometry-shader version of code. I render what I want to each render target without pain!

    However, with pixel shader I just can't render anything to the render targets besides the first one.

    The following is a simplified version of what I wrote, there must be something wrong...

     

     

    struct
     PSOut{ 
        float4 color0 : SV_Target0; 
        float4 color1 : SV_Target1; 
        float4 color2 : SV_Target2; 
    }; 
     
    PSOut PS(PSIn input){ 
       PSOut output = (PSOut)output; 
       output.color0 = input.color0; 
       output.color1 = input.color1; 
       outpur.color2 = input.color2; 
       return output; 
     

    Simple enough, I just want to pass different attributes to different render targets, and I failed.

    Any help is welcome!

    Thanks!!!

     

     

  • 6/15/2008 11:35 AM In reply to

    Re: How to use SV_Target[n] semantics?

    The problem is what to use MRT (inistead on render target array and deciding where to render in GS) you have to use the same pattern as in DX9, i.e. set multiple rendertarget views in call to ID3D10Device::OMSetRenderTargets(). You can use your existing Texture2DArray, you just need to query for each separate slice of array and set these slices in SRT() call as separate surfaces.
  • 6/16/2008 11:54 AM In reply to

    Re: How to use SV_Target[n] semantics?

    You are making mistakes with targets.

     If you need that your pixel shader must return a float4 struct, you can't use the TEXTURE2DARRAY pattern.

    You have to create a REAL texture array

    ID3D10Texture2D     *textures[10];

    So you will create 10 RenderTargets view and 10 DepthStencil view, and you will set all 10 with OMSetRenderTargets.

    You can use TEXTURE2DARRAY flag in resources creation, only if you want to use the indexed multiple rendertargets.
    The rendertarget will be only 1, but there will be an index that will understand where your draw will go (the uint SV_RenderTargetArrayIndex).

    You are forced to use GeometryShader in order to set primitive index, and set another index to decide what index you want to render. In HLSL, the Texture2DArray object, has got a Sample() method, that takes a float 3 as texcoord: 2 for coords, another for the index.

    If you need more informations....

     

     

Page 1 of 1 (3 items) Previous Next