Quantcast
Channel: Questions in topic: "compute shader"
Viewing all articles
Browse latest Browse all 287

When reading back asynchronously from compute shaders, can I reset buffer halfway?

$
0
0
Hope there will be nothing confusing in what I'm going to talk about, because my mother tongue is not English and my grammar is poor:p I'm working on a mipmap analyzing tool which need to calculate with pixels from the render texture. Here's a part of the C# code: private IEnumerator CSGroupColor(RenderTexture rt, GroupColor[] groupColors) { var outputBuffer = new ComputeBuffer(groupColors.Length, 8); csKernelID = cs.FindKernel("CSGroupColor"); cs.SetTexture(csKernelID, "rt", rt); cs.SetBuffer(csKernelID, "groupColorOut", outputBuffer); cs.Dispatch(csKernelID, rt.width / 8, rt.height / 8, 1); var req = AsyncGPUReadback.Request(outputBuffer); yield return new WaitUntil(() => req.done); req.GetData().CopyTo(groupColors); foreach (var color in groupColors) { if (!m_staticsDatas.TryGetValue(color.groupindex, out var vl)) continue; if (color.value > 0) vl.allColors.Add(color.value); } } And what I want to implement next, is to make every buffer smaller(e.g.with a length of 4096), like we usually do in other asynchronous communications. Maybe I can pass the first buffer to CPU right away when it's full, and then replace it with the second buffer, and so on. As I see it, using SetBuffer() again after req.done must be permitted to make that viable. I have been finding on Internet all day for a sample usage, but still found nothing. Is there anyone who would give some help? Thx very much.

Viewing all articles
Browse latest Browse all 287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>