Sign in to follow this  
undead

[SOLVED] D3D10 RT/Texture already in use weird behaviour

Recommended Posts

undead    368
Hi, I've lost a couple of hours yesterday because of the inability to set a RT while the texture was bound to a shader variable. The problem is I experienced a weird behaviour and I would like to know if you had similar issues or if you can shed some light. I fixed it, but I don't know why it works and I don't like this. The premise is the following: I have two render targets, each with his depthstencil surface. I have a two-stage rendering pipeline. The first pass (the PrePass) renders objects to the render targets (they are separated, so if I have a cube I draw it in the first RT then draw it again in the second) The second pipeline stage renders the scene and uses the render targets as textures. In brief: First stage ============ Set first RT Clear Render stuff Set second RT Clear Render Stuff Reset original RT Second stage ============= Clear For each object -Set first RT as texture input 1 -Set second RT as texture input 2 -draw -Unset first RT -Unset second RT end of object for Ok, it's not optimized. I know. In my implementation I have this code to set/unset textures, a function called SetShaderResource:
return m_pEffect->GetVariableByName(i_szHandle)->AsShaderResource()->SetResource(i_pRV) == S_OK;
If i_pRV is null, the texture should be unbound. If I call the function this way it doesn't work:
SetShaderResource(sSamplerName,NULL);
If I change my code, everything is fine:
ID3D10ShaderResourceView * pSRV[1] = {NULL};
SetShaderResource(sSamplerName,pSRV[0]);
Is there a reason why the second is ok and the first doesn't unbound my textures?????????????????????????????????????????????????????????? [Edited by - undead on November 10, 2009 5:06:58 AM]

Share this post


Link to post
Share on other sites
Nik02    4348
Your SetResource call doesn't actually modify the device state. Instead, state changes are applied when you call the Apply method of the effect pass.

As for the (PS/VS/GS)SetShaderResources(/**/, null) issue, the function expects a valid array of variables. In order for an array to be valid, the address of its first element must be inequal to zero. The values of the elements in the array have absolutely nothing to do with their addresses.

[Edited by - Nik02 on November 10, 2009 4:41:27 AM]

Share this post


Link to post
Share on other sites
undead    368
Quote:
Original post by Nik02
Your SetResource call doesn't actually modify the device state. Instead, state changes are applied when you call the Apply method of the effect pass.

Thank you very much, I completely forgot to apply the changes. Now it works!
Thank you again!

Quote:

As for the SetShaderResource(/**/, null) issue, the function expects a valid array of variables. In order for an array to be valid, the address of its first element must be inequal to zero. The values of the elements in the array have absolutely nothing to do with their addresses.

Correct me if I'm wrong, but it's PSSetShaderResources() who expects an array, while SetResource() just needs a pointer.

Actually by passing pArray[0] I'm passing it's value, so for an array of pointers I'm passing the pointed address, which is NULL/0. It would be different if I passed "pArray" or "&pArray[0]". After applying changes it also works with "NULL".

Share this post


Link to post
Share on other sites
Nik02    4348
Correct, SetResource deals with one resource pointer at a time.

There was an ambiguity in your original post about whether you tried to use that or PSSetShaderResources, since there doesn't exist a function called "SetShaderResource" even though you use that symbol in your last two example code pieces.

That said, you don't need to use *SetShaderResources method manually if you let the effect system apply all the states. It may be the case that PSSetShaderResources will just silently fail if you pass zero as an argument to it. I'm not at my own machine to test this right now.

Share this post


Link to post
Share on other sites
undead    368
Quote:
Original post by Nik02
Correct, SetResource deals with one resource pointer at a time.

There was an ambiguity in your original post about whether you tried to use that or PSSetShaderResources, since there doesn't exist a function called "SetShaderResource" even though you use that symbol in your last two example code pieces.

Yes, it was my mistake. There is no "SetShaderResource" because the correct line is "pShader->SetShaderResource". :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this