Sign in to follow this  

Pixel/Vertex Shaders need a restore?

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

If the full screen is lost, or an alt+tab occurs... Do I need to reload vertex and pixel shaders loaded with IDirect3DDevice9::CreatePixelShader()

Share this post


Link to post
Share on other sites
Tough one. The docs state that the following need to be reset:

- RenderTargets
- Depth Surfaces
- Additional Swap Chains
- State Blocks
- Any other D3DPOOL_DEFAULT resources

However, it is not stated whether or not shaders are created in the default pool. My guess is that vertex and pixel shaders do not need to be reset, since other interfaces (like IDirect3DVertexDeclaration9) don't need to be reset, either.

Ahh, I just checked the HLSLWithoutEffects sample, and it doesn't reset the shader objects. This means my guess was lucky - they don't need to be reset.

Share this post


Link to post
Share on other sites
Nope, PS and VS shaders don't need to be released/restored on a device reset. However, if you make the transition to Effects files in the future, those do need to be reset.

Share this post


Link to post
Share on other sites
I actually have to use some of both.
So its good to know, I see I can reset effect files with OnResetDevice and OnLostDevice.



Curious, if I may sidetrack, does Effect->BeginPass() allow me to render with an effect file, thats all I cannot seem to find in an sdk example, is how to actually set a loaded effect file.

Share this post


Link to post
Share on other sites
There's a few things you must do in order to render with an effect file.
First you must set the technique used, using pEffect->SetTechnique(). The parameter may either be a string (ie. "technique1") or a handle returned by pEffect->GetTechniqueByName("technique1"), for example.

Then you must tell the effect you're going to be rendering with it. You do this by
pEffect->Begin(&numPasses, 0)

This also retrieves how many passes are set for the particular chosen technique. You could now do a loop up to this number, and in the loop:

pEffect->BeginPass(pass);
// render your primitives
pEffect->EndPass(pass);


and at the end of the rendering, call pEffect->End();


That's about it for the rendering.. besides setting matrices in the effect (via SetMatrix) and setting textures (SetTexture). The DX SDK has a basic hlsl sample that I used to learn from, and then you work your way up. A good thing to do is to retrieve handles for effect semantics (texture names, constant names, technique names, etc.) rather than always calling the effect interface methods with strings. It saves a lookup. Just store them somewhere and use them for the rest of the duration of the app. You don't need to retrieve them again when you reset the d3d device.

Share this post


Link to post
Share on other sites
Yes, I read that in the SDK example SimpleSample.
It says "It is better to cache the variable names rather than use the string to look them up each time".



So I actually have to call Begin twice?
Once to recieve the number of pass' and once for each pass to set it?

Share this post


Link to post
Share on other sites
Quote:
Original post by skittleo
In DirectX 8 they do. in 9, they don't.


Not sure what "they" is referring to, but if you're talking about the lack of need to call Begin() or BeginPass() in DX9, you are actually required to do both. Otherwise, omitting one or the other results in a D3D error. Try commenting out a pair of either in the BasicHLSL sample.

Share this post


Link to post
Share on other sites

This topic is 4543 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.

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