Code Monkey home page Code Monkey logo

asynccapturetest's Introduction

AsyncCaptureTest

screenshot

This Unity sample project shows how to use the asynchronous GPU readback API to capture render outputs without blocking the main thread.

Note that there is a trade-off between performance and latency. It's only applicable when a small amount of latency is acceptable. Screen capture is one of the best-fit cases for the feature.

Unity 2023 Update

I updated this project to use the Awaitable class introduced in Unity 2023.1. Now you can use the GPU readback API with the C# asynchronous programming features (async/await).

asynccapturetest's People

Contributors

keijiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asynccapturetest's Issues

Make SaveBitmap async

Hi!
Is it possible to make the SaveBitmap() method async?
I need to encode the Color32/Byte array to JPG in another thread so that it doesn't create any micro-lag on the main thread.
Thanks a lot in advance!

Crash after about 10 min

Hi there,

i have tried this project with different Unity Versions (2019.4.14f1 , 2020.3.25f1 and 2021.2.8f1) and have a problem. Hope someone can help me.

The application crashes after about 10 minutes.

I have also tried the same test while deactivating this line "System.IO.File.WriteAllBytes("test.png", encoded.ToArray());"
It still crashed in editor or standalone mode after running for about 10 minutes.
I have tried the tool "Log Viewer" to see in Standalone Mode if there is a Memory Leak. Everything looked normal. Maybe there are better tools to analyse?

Is this a Unity Bug?

Is it maybe better to replace this "yield return new WaitForSeconds(1);" with something like a request done to have maximum speed?

I would like to create a video stream application which is stable and fast. Is it wise to use AsyncGPUReadback or is there a better and more stable option?

Thank you, hope you have some advises!

About HDR support

Hi Keijiro, thank you so much for the demo code, it is very informative.
I have been playing with asyncGPUReadback and it is very useful however I am wondering if it supports HDR. I have tried using GetData with and I tried putting RenderTexture using both ARGBHalf a.k.a. DefaultHDR and ARGBFloat. Neither work, I just get an empty array, i.e. array of zeroes. And quite peculiar if I use ARGBHalf I get exactly half the pixels I should from GetData method, I guess it just combines two ARGBHalf into one ARGBFloat.

SetPixels() called with invalid # of pixels in the array - Scaling?

Hi! This is awesome, and I thank you for providing such a succinct and clear example. I've been playing with it a bit for the last day or two and have it running great when cloned directly and on a minimal project -- but when running the exact same code on our game's camera I end up with unexpected resolution / pixel counts.

The code here is completely unchanged from your repo, and admittedly it works fine when run in a project by itself. When run in our main project, the exact same code on the exact same computer & unity version, ends up producing the error.

Here's a link that contains screenshots:
https://imgur.com/a/aKxc3Sh

Screenshots show:

  1. the output of the logging
  2. the only code change -- simple addition of size/resolution logging
  3. our camera config

I'm guessing that there is something dumb and/or obvious that I'm just completely missing here, but after 2+ hours playing with it I'm at a loss as to what/why this would occur.

Does anything jump out at you as being wrong or incompatible?

FWIW, I've also tried using a separate camera -- both active, and inactive while manually calling Render(), both of which produced similar unexpected resolution/array size results too.

Apologies in advance for what is probably a stupid/obvious mistake on my part!!! =D

My Setup:

  • Unity Editor version is 2018.3.11f1
  • Running editor on macOS 10.13.6
  • Single external monitor at 4K resolution with the OS setting set to "Default for Display"
  • I know macOS plays tricks with reported/actual resolution (has been a PITA before), perhaps is culprit here? Or is there a DPI-ish number I need to be multiplying against?
  • In editor I have resolution emulation setting set to 'Standalone (1920x1080)'.
  • If I change the res-emulation then the vars update proportionately, ex: Changing to "Free Aspect" right now provides me with:
    buffer.Length=5610480 || buffer.ToArray().Length=5610480 || Screen: 2410x1164 || Camera: 2410x1164 || scaledCamera: 2410x1164 || Args: 2410x1164
    Thanks in advance for any guidance and/or educational schooling you may be able to provide me! :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.