From c66a68afeb4abba5581dcbf9079d10164e60de52 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 19 Sep 2019 00:14:33 +0200 Subject: [PATCH] Minor IL optimizations, fixed variables loading --- src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs | 5 +++-- src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs b/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs index 31f9094a..05256421 100644 --- a/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/ILGeneratorExtensions.cs @@ -99,8 +99,7 @@ namespace System.Reflection.Emit public static void EmitAddOffset(this ILGenerator il, int offset) { // Push the offset to the stack - if (offset > 8) il.Emit(OpCodes.Ldc_I4, offset); - else + if (offset <= 8) { il.Emit(offset switch { @@ -111,6 +110,8 @@ namespace System.Reflection.Emit _ => throw new InvalidOperationException("Huh?") }); } + else if (offset <= 127) il.Emit(OpCodes.Ldc_I4_S, (byte)offset); + else il.Emit(OpCodes.Ldc_I4, offset); // Converts the offset to native int and adds to the address il.Emit(OpCodes.Conv_I); diff --git a/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs b/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs index 630b43d5..393a2302 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderLoader.IL.cs @@ -123,6 +123,7 @@ namespace ComputeSharp.Shaders.Translation // Load the target address into the variables buffer il.Emit(OpCodes.Ldarg_2); il.EmitAddOffset(_VariablesByteSize); + _VariablesByteSize += size; // Load the variable and store it in the loaded address LoadMember(member);