Exemple #1
0
    private void ConvertDoneRequestToTexture2D()
    {
        var doneJobs = _workingGpuJobs.Where(job => job.request.done);

        foreach (var gpuJob in doneJobs)
        {
            if (gpuJob.request.hasError)
            {
                Debug.Log("Has Error");
                continue;
            }

            _stopwatch.Restart();
            var rgba = gpuJob.request.GetData <byte>();

            _stopwatch.Stop();
            Debug.Log($"GetData {_stopwatch.ElapsedMilliseconds}");
            _stopwatch.Restart();

            var texture = gpuJob.texture2D;

            texture.SetPixelData(rgba, 0);
            texture.Apply(false);

            _stopwatch.Stop();
            Debug.Log($"SetPixelData Apply {_stopwatch.ElapsedMilliseconds}");
            _stopwatch.Restart();

            _decodedQueue.Enqueue(texture);

            GpuJob.Return(gpuJob);
        }

        _workingGpuJobs = _workingGpuJobs.Where(job => !job.request.done).ToList();
    }
Exemple #2
0
    private void DispatchConvertFrame(Av1Frame av1Frame, GpuJob gpuJob, Texture2D texture2D)
    {
        _stopwatch.Restart();
        Marshal.Copy(av1Frame.Picture._data[0], _lumaBytes, 0, 1920 * 1080);
        gpuJob.LumaBuffer.SetData(_lumaBytes);
        computeShader.SetBuffer(_kernel, "lumaBuffer", gpuJob.LumaBuffer);

        Marshal.Copy(av1Frame.Picture._data[1], _uBytes, 0, 1920 * 1080 / 4);
        gpuJob.UBuffer.SetData(_uBytes);
        computeShader.SetBuffer(_kernel, "uBuffer", gpuJob.UBuffer);

        Marshal.Copy(av1Frame.Picture._data[2], _vBytes, 0, 1920 * 1080 / 4);
        gpuJob.VBuffer.SetData(_vBytes);
        computeShader.SetBuffer(_kernel, "vBuffer", gpuJob.VBuffer);

        _stopwatch.Stop();
        Debug.Log($"Copy {_stopwatch.ElapsedMilliseconds}");
        _stopwatch.Restart();

        computeShader.SetBuffer(_kernel, "rgbaBuffer", gpuJob.RgbaBuffer);

        _stopwatch.Stop();
        Debug.Log($"Copy {_stopwatch.ElapsedMilliseconds}");
        _stopwatch.Restart();

        computeShader.Dispatch(_kernel, 1920 / 4 / 8, 1080 / 8, 1);

        _stopwatch.Stop();
        Debug.Log($"Dispatch {_stopwatch.ElapsedMilliseconds}");
        _stopwatch.Restart();

        gpuJob.request   = AsyncGPUReadback.Request(gpuJob.RgbaBuffer);
        gpuJob.texture2D = texture2D;
        _workingGpuJobs.Add(gpuJob);
    }
Exemple #3
0
    void OnDestroy()
    {
        _rawTextures.ForEach(Object.Destroy);
        foreach (var ivfAv1Decoder in _ivfAv1Decoders)
        {
            ivfAv1Decoder?.Dispose();
        }

        foreach (var gpuJob in _workingGpuJobs)
        {
            gpuJob.Dispose();
        }
        GpuJob.DestroyPool();
    }
Exemple #4
0
 public static void Return(GpuJob gpuJob)
 {
     Pool.Enqueue(gpuJob);
 }
Exemple #5
0
 public static bool TryRent(out GpuJob gpuJob)
 {
     gpuJob = Pool.Count > 0 ? Pool.Dequeue() : null;
     return(!(gpuJob is null));
 }