From 87b43eb36a6c3ad2351681ed465e98642c9f57d2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 21 Sep 2019 21:28:54 +0200 Subject: [PATCH] Fixed a synchronization issue, minor optimization --- .../Translation/ShaderLoader.IL.cs | 14 +++----------- .../Translation/ShaderLoader.cs | 1 + 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs index 0669ae18..0dec029d 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs @@ -51,13 +51,6 @@ namespace ComputeSharp.Shaders.Translation [Pure] public DispatchData GetDispatchData(Action action, int x, int y, int z) { - /* Create the data loader instance, if not available already. - * This will also initialize the other local fields in the shader - * loader class, which are used to rent the buffers used to store - * the captured resources and variables. This is why this call - * has to be the first one in this method, it must NOT be moved */ - DispatchDataLoader loader = _DispatchDataLoader ??= BuildDispatchDataLoader(); - // Resources and variables buffers GraphicsResource[] resources = ArrayPool.Shared.Rent(_ResourcesCount); byte[] variables = ArrayPool.Shared.Rent(_VariablesByteSize); @@ -70,7 +63,7 @@ namespace ComputeSharp.Shaders.Translation Unsafe.Add(ref Unsafe.As(ref r1), 2) = z; // Invoke the dynamic method to extract the captured data - loader(action.Target, ref r0, ref r1); + _DispatchDataLoader!(action.Target, ref r0, ref r1); return new DispatchData(resources, _ResourcesCount, variables, _VariablesByteSize); } @@ -78,8 +71,7 @@ namespace ComputeSharp.Shaders.Translation /// /// Builds a new instance that loads the dispatch data for the current shader type /// - [Pure] - private DispatchDataLoader BuildDispatchDataLoader() + private void BuildDispatchDataLoader() { // Mapping of parent members to index of the relative local variable var map = @@ -96,7 +88,7 @@ namespace ComputeSharp.Shaders.Translation HashSet loaded = new HashSet(new[] { 0 }); // Build the dynamic IL method - return DynamicMethod.New(il => + _DispatchDataLoader = DynamicMethod.New(il => { // Loads a given member on the top of the execution stack void LoadMember(ReadableMember member) diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs index dfc6a2ae..fbf49dc5 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.cs @@ -122,6 +122,7 @@ namespace ComputeSharp.Shaders.Translation @this.LoadFieldsInfo(); @this.LoadMethodSource(); + @this.BuildDispatchDataLoader(); return @this; }