Jump to content
  • Advertisement
Sign in to follow this  
yk_cadcg

[solved] [hlsl 10] ps can't read newly CopyResource()ed texture

This topic is 4230 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

This is solved. Problem is z-culling. I was rendering to the same z each pass, and my zFunc is less, so all later passes are culled.. ///// Hi, I use the suggestion of sdk "Choosing a Resource (Direct3D 10)" bottom para: after render, CopyResource(texShaderResource, texRendertarget), i test by CopyResource(texTestStaging, texShaderResource) and checked that texStaging *has* the rendered result from texRendertarget. but the shader of the next pass can't read the value. It just reads 0's. the tex type is _R32_FlOAT. How's that? Thanks! [Edited by - yk_cadcg on May 15, 2007 8:47:35 PM]

Share this post


Link to post
Share on other sites
Advertisement
Just a wild guess:
Is it possible that you call XYSetShaderResources before you call OMSetRenderTargets? XYSetShaderResources will reset a slot if the subresource is already bound as target. As you have just rendered to it you have to set another target first before you can set it as input.

Share this post


Link to post
Share on other sites
Thank you very much!
what is XYSetShaderResources? @@ I haven't used it.
I think CopyResource is common for many coders, since it's a must in multipass render to texture, isn't it?

My whole framework is below, hope seniors give a hint or wild guess, thanks!
step1:

descTex.Width = texW;
descTex.Height = texH;
descTex.MipLevels = 1;
descTex.ArraySize = 1;
descTex.Format = DXGI_FORMAT_R32_FLOAT;
descTex.SampleDesc.Count = 1;
descTex.SampleDesc.Quality = 0;
descTex.Usage = D3D10_USAGE_DEFAULT;
descTex.CPUAccessFlags = 0;
descTex.MiscFlags = 0;
//pTexR
descTex.BindFlags = D3D10_BIND_SHADER_RESOURCE;
V(g_pd3dDevice->CreateTexture2D(&descTex, NULL, &pTexR));
//pTexW
descTex.BindFlags = D3D10_BIND_RENDER_TARGET;
V(g_pd3dDevice->CreateTexture2D(&descTex, NULL, &pTexW));

//pViewTexR
descResView.Format = descTex.Format;
descResView.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
descResView.Texture2D.MipLevels = 1;
descResView.Texture2D.MostDetailedMip = 0;
V(g_pd3dDevice->CreateShaderResourceView(pTexR, &descResView, &pViewTexR));

//pViewTexW
descRTView.Format = descTex.Format;
descRTView.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
descRTView.Texture2D.MipSlice = 0;
V(g_pd3dDevice->CreateRenderTargetView(pTexW, &descRTView, &pViewTexW));

V((g_pEffect->GetVariableByName("texR")->AsShaderResource())->SetResource(pViewTexR));


step2:

int pass = 0;
for(; pass < _maxPasses; ++pass)
{
D3D10_TECHNIQUE_DESC techDesc;
g_pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
g_pTechnique->GetPassByIndex(p)->Apply(0);
g_pd3dDevice->Draw(6, 0);
}
g_pSwapChain->Present(0, 0);
g_pd3dDevice->CopyResource(pTexR, pTexW);
}

step3,.fx:

Texture2D <float> texR;
..
float R = texR.SampleLevel(samp, vsOuput.texCoord, 0);
output.W = (R + 1); //write the modified texR value to rendertarget,i.e.texW

Quote:
Original post by Demirug
Just a wild guess:
Is it possible that you call XYSetShaderResources before you call OMSetRenderTargets? XYSetShaderResources will reset a slot if the subresource is already bound as target. As you have just rendered to it you have to set another target first before you can set it as input.


[Edited by - yk_cadcg on May 14, 2007 9:44:52 PM]

Share this post


Link to post
Share on other sites
With XY I was refereing the three difrent shader prefixes VS, GS, PS. But as you use two different textures here this could not be the reason anyway.

Have you enabled the debug layer and checked if it report anything?

Normmaly you would not use CopyResource to do what you want. The common approch is to play “ping pong” with two textures that can both used for shader reads and as render targets. After every pass you will set the former output as input and the input as output. As I have written before for Direct3D 10 you have to first set the target and then set the input texture.

Share this post


Link to post
Share on other sites
Thank a lot!
I'm doing gpgpu thing, this requires to copy back to system memory, so i think CopyResource is a must?
This is solved. Problem is z-culling. I was rendering to the same z each pass, and my zFunc is less, so all later passes are culled..

Quote:
Original post by Demirug
With XY I was refereing the three difrent shader prefixes VS, GS, PS. But as you use two different textures here this could not be the reason anyway.

Have you enabled the debug layer and checked if it report anything?

Normmaly you would not use CopyResource to do what you want. The common approch is to play “ping pong” with two textures that can both used for shader reads and as render targets. After every pass you will set the former output as input and the input as output. As I have written before for Direct3D 10 you have to first set the target and then set the input texture.


Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!