# [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.

## 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 on other sites
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 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 DemirugJust 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 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 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 DemirugWith 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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633703
• Total Posts
3013453
×