Southp
2008-06-13 07:35:00 UTC
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!!!
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!!!