Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Fri, 13 Jun 2008 00:35:00 -0700,    group: microsoft.public.win32.programmer.directx.graphics.shaders        back       


How to use SV_Target[n] semantics correctly?   
Hi,
First of all, I'd post the same question at XNA Creators club. I post the 
almost-the-same context here because no one answers me there. Sorry if I make 
you read this long post again and again.

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 3.
//create render target array 
    D3D10_VIEWPORT vp; 
    UINT n = 1; 
    mpDev->RSGetViewports(&n,&vp);   
    D3D10_TEXTURE2D_DESC td; 
    td.ArraySize = 3; 
    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 = 3; 
    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!!!
date: Fri, 13 Jun 2008 00:35:00 -0700   author:   Southp

RE: How to use SV_Target[n] semantics correctly?   
I see no issues with your HLSL code.  

If you enable the debug layer and compile the shader with the debug flag, do 
you get any warnings or errors?
date: Fri, 13 Jun 2008 11:30:00 -0700   author:   Dieter Van Wassenhove

Re: How to use SV_Target[n] semantics correctly?   
[Posted answer in creators.xna.com too]

The problem is what to use MRT (instead 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.


"Southp"  wrote in message 
news:D437E95E-2013-4C19-87D8-679804C1A549@microsoft.com...
>
> Hi,
> First of all, I'd post the same question at XNA Creators club. I post the
> almost-the-same context here because no one answers me there. Sorry if I 
> make
> you read this long post again and again.
>
> 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 3.
> //create render target array
>    D3D10_VIEWPORT vp;
>    UINT n = 1;
>    mpDev->RSGetViewports(&n,&vp);
>    D3D10_TEXTURE2D_DESC td;
>    td.ArraySize = 3;
>    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 = 3;
>    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!!!
>
>
date: Sun, 15 Jun 2008 15:35:55 +0400   author:   Alexey Barkovoy

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us