Jump to content
  • Advertisement
Sign in to follow this  
MysteryX

Running Shader in DX9 Returns Previous Frame

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

I finally got the code to run a HLSL pixel shader in DX9 almost working.

https://github.com/mysteryx93/AviSynthShader/blob/master/VideoPresenter/D3D9RenderImpl.cpp

 

Here's a weird issue I'm still having. As I load the script, the first frame is black, which is OK. Then, the first time I seek towards a different frame, the frame remains black. The second time I seek to another frame, the first frame is returned. It seems to always returns the frame data of the previous call.

 

So if I make a diff between the input and output frames of the shader, it looks totally wrong; because it's a diff between two different frames.

 

Why is it not returning me the current frame data right away?

 

... just a thought ... could it be that the frame isn't done being processed when I call to get the result?

Share this post


Link to post
Share on other sites
Advertisement

Shaders don’t “return frames”—they don’t run on anything but the frame they are given.
 

could it be that the frame isn't done being processed when I call to get the result?

That’s what double-buffering is. You draw to the current frame while the previous frame is being displayed to the viewer.


L. Spiro

Share this post


Link to post
Share on other sites

Delay the audio of your video by 1 frame?

 

I have no idea what you can do about it.  That’s up to your project.  You’re the only one who can decide which frame from the video to grab based on what is being displayed through your shader system in such a way that they are synchronized.  Since I expect your video to be played through Direct3D and through your system/shaders, I am not sure why you need to specifically synchronize them other than for debug purposes (validate your output), and for that, again, you can just grab the previous video frame instead of the current.

 

A 1-frame delay never hurt anyone singing karaoke.

 

And…???????????????????

 

 

L. Spiro

Share this post


Link to post
Share on other sites

I don't display anything to the user and I don't use any audio data. The library takes a video frame in, passes it through the shader and returns the frame data back. It has no graphical interface.

Share this post


Link to post
Share on other sites

I'm simply using a Render Target texture. The code is simple and is attached to the post.

 

I asked someone very knowledgeable in this and he answered this

 

 

You may have to flush the GPU to make sure rendering is complete. This is just a guess, maybe flushing won't help, in that case there is probably a bug in your code. There are various ways to flush, from what I remember:

1) You can lock the surface by using LockRect. But only some types of surfaces can be locked, so this might not work.
2) You can StretchRect to another surface, but I'm not sure if this is really reliable, you'd have to try.
3) Use IDirect3DQuery9 to manually flush the GPU. You should find some code via google.

 

I'll need time to explore those options. Do you guys have anything else to add to put me on the right track?

 

After calling GetRenderTargetData, I do call LockRect, so shouldn't that be flushing it already?

Edited by MysteryX

Share this post


Link to post
Share on other sites

There is no way I could be passing an incorrect frame. On each call to ProcessFrame, I have no access to data of any other frame.

 

Most likely cause is that the GPU isn't being flushed and "pending work" isn't being returned.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!