I'm trying to implement a bicubic interpolation warping shader for Elite: Dangerous, and while I have the basic effect worked out, I'm having issues with optimization. I'm trying to create a lookup texture for each channel, to avoid calculating warp each frame. I have the texture storage working (I think) but I'm unable, so far, to use it, because I'm unable to figure out how to write to the texture, then read. I'm getting internal error: invalid access of unbound variable which is, as far as I can tell, from reading and writing simultaneously. Is there any way to toggle the state of one technique off another? Or to delay the start of a technique? Or unbind the rendertarget after the first write?
PS: As a side note, why would you ever want to use toggleTime?
The administrator has disabled public write access.
Need help with technique setup
2 years 4 months ago #2
There is no compiler error when reading and writing to the same texture. It will produce (invisible to the normal user) runtime errors, you can watch when the D3D debug runtime is active. So that internal error is something else, and not something that should happen. Could you post some context code to that error?
Anyway, here's some info on your questions:
A texture is only bound as rendertarget as long as in a pass where it was set as rendertarget. It's automatically unbound on the next pass and can be read from there again.
In the following example MyFunction1 would write its result to MyTexture (and thus cannot read from it). MyFunction2 then writes to the backbuffer again and may read the content of MyTexture, which was filled in the previous pass.
However, if I read your post right, you actually want to execute a technique only once. So to create the lookup texture at startup for later use. You could achieve that with the following. This way the technique is only executed for 100ms after compilation finished. It still runs multiple times, but after those short 100ms are over it will never run again and not bring down performance every frame. So you may do some heavy processing in here, write the result to some texture and then later use that texture.
A full example. Techniques are guaranteed to execute in the order they were defined in the shader file, so "PSPostProcessing" will always recieve valid data from "lookupTexture", since "PSInitLookupTexture" must have executed before at least once.