Pixel/Vertex Shaders need a restore?

Started by
6 comments, last by sordid 18 years, 9 months ago
If the full screen is lost, or an alt+tab occurs... Do I need to reload vertex and pixel shaders loaded with IDirect3DDevice9::CreatePixelShader()
Advertisement
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.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
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.
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.
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.
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?
Yeah.. so if you plan on not having multiple passes, you could always just use '0' as your pass number and forego the loop.
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.

This topic is closed to new replies.

Advertisement