Ejemplo n.º 1
0
        public void CanUseGraphValueResolver_ToResolveValues_InAJob(NodeSet.RenderExecutionModel computeType)
        {
            using (var results = new NativeArray <float>(1, Allocator.Persistent))
                using (var set = new RenderGraphTests.PotentiallyJobifiedNodeSet(computeType))
                {
                    var root = set.Create <RenderPipe>();

                    GraphValue <float> rootValue = set.CreateGraphValue(root, RenderPipe.KernelPorts.Output);

                    for (int i = 0; i < 100; ++i)
                    {
                        set.SendMessage(root, RenderPipe.SimulationPorts.Input, i);

                        set.Update();

                        GraphValueReadbackJob job;

                        job.Value    = rootValue;
                        job.Result   = results;
                        job.Resolver = set.GetGraphValueResolver(out var valueResolverDependency);

                        set.InjectDependencyFromConsumer(job.Schedule(valueResolverDependency));

                        // Automatically fences before CopyWorlds. Results is accessible now.
                        set.Update();

                        Assert.AreEqual(i, results[0]);
                        Assert.AreEqual(i, set.GetValueBlocking(rootValue));
                    }

                    set.Destroy(root);
                    set.ReleaseGraphValue(rootValue);
                }
        }
Ejemplo n.º 2
0
        public void ResolvedGraphBuffers_AreReadOnly()
        {
            using (var results = new NativeArray <int>(1, Allocator.Persistent))
                using (var set = new RenderGraphTests.PotentiallyJobifiedNodeSet(NodeSet.RenderExecutionModel.MaximallyParallel))
                {
                    var root = set.Create <RenderPipeAggregate>();

                    GraphValue <Aggregate> rootValue = set.CreateGraphValue(root, RenderPipeAggregate.KernelPorts.Output);

                    Aggregate aggr = default;
                    aggr.InputPlusOneI = Buffer <int> .SizeRequest(1);

                    set.SetBufferSize(root, RenderPipeAggregate.KernelPorts.Output, aggr);

                    set.Update();

                    CheckReadOnlyNess_OfResolvedGraphBuffer job;

                    job.Value    = rootValue;
                    job.Result   = results;
                    job.Resolver = set.GetGraphValueResolver(out var valueResolverDependency);

                    set.InjectDependencyFromConsumer(job.Schedule(valueResolverDependency));

                    set.Update();

                    Assert.AreEqual(1, results[0]);

                    set.Destroy(root);
                    set.ReleaseGraphValue(rootValue);
                }
        }
Ejemplo n.º 3
0
        public void CanUseGraphValueResolver_ToResolveAggregate_WithBuffers_InAJob(int bufferLength)
        {
            using (var results = new NativeArray <int>(bufferLength + 1, Allocator.Persistent))
                using (var set = new RenderGraphTests.PotentiallyJobifiedNodeSet(NodeSet.RenderExecutionModel.MaximallyParallel))
                {
                    var root = set.Create <RenderPipeAggregate>();

                    GraphValue <Aggregate> rootValue = set.CreateGraphValue(root, RenderPipeAggregate.KernelPorts.Output);

                    for (int i = 0; i < 20; ++i)
                    {
                        set.SetData(root, RenderPipeAggregate.KernelPorts.Input, i);

                        Aggregate aggr = default;
                        aggr.InputPlusOneI = Buffer <int> .SizeRequest(bufferLength);

                        set.SetBufferSize(root, RenderPipeAggregate.KernelPorts.Output, aggr);

                        set.Update();

                        GraphAggregateReadbackJob job;

                        job.Value    = rootValue;
                        job.Result   = results;
                        job.Resolver = set.GetGraphValueResolver(out var valueResolverDependency);

                        set.InjectDependencyFromConsumer(job.Schedule(valueResolverDependency));

                        // Automatically fences before CopyWorlds. Results is accessible now.
                        set.Update();

                        for (int z = 0; z < bufferLength + 1; ++z)
                        {
                            Assert.AreEqual(i + z, results[z]);
                        }
                    }

                    set.Destroy(root);
                    set.ReleaseGraphValue(rootValue);
                }
        }
Ejemplo n.º 4
0
        public void UpdatedBufferSize_InAggregate_ReflectsInDependent_ReadbackJob()
        {
            const int k_MaxBufferLength = 20;

            using (var results = new NativeArray <int>(1, Allocator.Persistent))
                using (var set = new RenderGraphTests.PotentiallyJobifiedNodeSet(NodeSet.RenderExecutionModel.MaximallyParallel))
                {
                    var root = set.Create <RenderPipeAggregate>();

                    GraphValue <Aggregate> rootValue = set.CreateGraphValue(root, RenderPipeAggregate.KernelPorts.Output);

                    // Test increasing buffer sizes, then decreasing
                    foreach (var i in Enumerable.Range(0, k_MaxBufferLength).Concat(Enumerable.Range(0, k_MaxBufferLength).Reverse()))
                    {
                        Aggregate aggr = default;
                        aggr.InputPlusOneI = Buffer <int> .SizeRequest(i);

                        set.SetBufferSize(root, RenderPipeAggregate.KernelPorts.Output, aggr);

                        set.Update();

                        GraphBufferSizeReadbackJob job;

                        job.Value    = rootValue;
                        job.Result   = results;
                        job.Resolver = set.GetGraphValueResolver(out var valueResolverDependency);

                        set.InjectDependencyFromConsumer(job.Schedule(valueResolverDependency));

                        // Automatically fences before CopyWorlds. Results is accessible now.
                        set.Update();

                        Assert.AreEqual(i, results[0], "Buffer size mismatch between expected and actual");
                    }

                    set.Destroy(root);
                    set.ReleaseGraphValue(rootValue);
                }
        }