Sign in to follow this  

hlsl interface/function pointer implementation of pingpong-buffer

Recommended Posts

Hi, my goal is a fairly simple mechanism to implement a ping-ponging buffer within hlsl.

The basic process would be like:

Calculate something in Buffer0.

Use Buffer0 to calculate something in Buffer1.

Use Buffer1 to calculate something in Buffer0.



Since there are no pointers to Buffer datatypes I was searching for another method to generalize this fairly simple code.

Eventually I leraned, that I can abuse interfaces for my purpose made up something like this:

interface PingPongBufferBase
	void Swap ();

class PingPongBuffer : PingPongBufferBase
	bool first;

	void Swap ()
		first = !first;

		if (first)
		{ return PingPongBuffer0[pos]; }
		{ return PingPongBuffer1[pos]; }

By instatiating the PingPongBuffer class in a shader/function I could use the Get() and Swap() to access allways the current Buffer and switch Buffers if I need to.


So are there really no smoother methods toachieve this? I haven't been for too long into the "high level" of hlsl but i was wondering why such an easy task turnes out to be such unintuitive to implement...

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