Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to implement feedback buffer #137

Open
mikeoliphant opened this issue Sep 20, 2021 · 3 comments
Open

Best way to implement feedback buffer #137

mikeoliphant opened this issue Sep 20, 2021 · 3 comments
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage

Comments

@mikeoliphant
Copy link

First off, thanks for creating ComputeSharp and making it available!

I've been messing around with the SwapChainAppliation examples, and I'd like to implement something like this ShaderToy reaction-diffusion shader:

https://www.shadertoy.com/view/XsG3z1

Any suggestions on the best way to modify the SwapChainAppliation framework to allow for this type of shader? I'm assuming I'd need another ReadWriteTexture2D buffer the size of the viewport? Or two - read from one and write to the other and then swap them each frame?

Thanks!

@mikeoliphant mikeoliphant added question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage labels Sep 20, 2021
@hawkerm
Copy link
Contributor

hawkerm commented Nov 10, 2021

Just tried to do this in the WinUI 3 branch with the IShaderRunner to facilitate creating a ReadWriteTexture2D to copy the result in each frame and also pass to the shader to run on in-between...

Ran into some interface vs. concrete type issues though with being able to easily copy the texture back into the buffer. Think an extra ComputeShader could do the copy, but that's more work... 🤣

I know @Sergio0694's working on aligning all his branches, so hopefully this feedback can help align to a shader runner to be shared across all the runtimes or something... 🤷‍♂️

I'll keep tinkering and share if I get anything working.

@hawkerm
Copy link
Contributor

hawkerm commented Nov 10, 2021

Ah, figured I'd at least try the ComputeShader approach, but feel like I'm missing something with how those work still in this context... almost got something though:

image

Didn't cover the whole image and shouldn't be moving pixels down though...

Ah, also thinking I'm running into issues with the texture size changing dynamically in the sample app and how to handle that with the buffer as I only allocate its size on the first frame... Not sure how to handle that at all in this scenario...

My broken experiments are here: https://github.com/hawkerm/ComputeSharp/tree/feature/winui3-extra-samples

        // Copy result into back buffer.
        backBuffer.CopyFrom(texture); // Want
        Gpu.Default.For(texture.Width, texture.Height, new BufferCopier(texture, backBuffer)); // Used

Would be nice to be able to just copy between the buffers though with the IShaderRunner setup, but that doesn't account for the texture changing sizes with dynamic resolution, at least not with how the copy methods work today as I think they'd expect the same size textures...

I suppose we could use UV coordinates for the buffer in the Shader, and then if the texture size != back buffer size re-allocate the Back Buffer, and then use the ComputeShader to map the UVs from the current frame texture when writing back to the Back Buffer???

@hawkerm
Copy link
Contributor

hawkerm commented Nov 10, 2021

Well, with my brainstorm I tried it out... and it kind of worked:

image

Not sure why it's constantly falling and pushing pixels down as I haven't tried to program movement yet... also going to the top is causing permanent streaks... (Edit: Ah, think the streaks are a side-effect of my currently bad decay equation I had as a place-holder, and so since it's pulling down if the top pixel is filled it'll constantly perpetuate that value.)

This was referenced Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❓ Further information is requested untriaged 🧰 A new issue that needs initial triage
Projects
None yet
Development

No branches or pull requests

2 participants