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); } }
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); } }
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); } }
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); } }
public void CanResolveGraphValues_OnMainThread_AfterFencing_ResolverDependencies() { const int k_BufferSize = 5; 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(k_BufferSize); set.SetBufferSize(root, RenderPipeAggregate.KernelPorts.Output, aggr); set.Update(); var resolver = set.GetGraphValueResolver(out var valueResolverDependency); valueResolverDependency.Complete(); var renderGraphAggr = /* ref readonly */ resolver.Resolve(rootValue); var array = renderGraphAggr.InputPlusOneI.ToNative(resolver); Assert.AreEqual(k_BufferSize, array.Length); int readback = 0; Assert.DoesNotThrow(() => readback = array[k_BufferSize - 1]); // After this, secondary invalidation should make all operations impossible on current resolver // and anything that has been resolved from it set.Update(); Assert.Throws <InvalidOperationException>(() => resolver.Resolve(rootValue)); Assert.Throws <InvalidOperationException>(() => readback = array[k_BufferSize - 1]); set.Destroy(root); set.ReleaseGraphValue(rootValue); } }