Sign in to follow this  

hlsl interface/function pointer implementation of pingpong-buffer

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

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 ();
	BUFFER_TYPE Get (BUFFER_POS_TYPE pos);
};

class PingPongBuffer : PingPongBufferBase
{
	bool first;

	void Swap ()
	{
		first = !first;
	}

	BUFFER_TYPE Get (BUFFER_POS_TYPE pos)
	{
		if (first)
		{ return PingPongBuffer0[pos]; }
		else
		{ 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

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