From 76a08ae06f20bbc87d70ab821ce1a0fc4f7aed07 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 7 Nov 2022 16:40:19 +0800 Subject: [PATCH 1/3] Add support for reflection-free mode --- .../Backend/Win32ApplicationRunner.cs | 16 ++++++++++++++-- samples/ComputeSharp.SwapChain/Program.cs | 2 +- src/ComputeSharp/ComputeSharp.csproj | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 6856b27f..03b2b226 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -45,12 +45,24 @@ internal static unsafe class Win32ApplicationRunner /// The input application instance to run. /// The exit code for the application. public static int Run(Win32Application application) + { + return Run(application, Assembly.GetExecutingAssembly().FullName ?? "ComputeSharp"); + } + + /// + /// Runs a specified application and starts the main loop to update its state. This is the entry point for a given application, + /// and it should be called as soon as the process is launched, excluding any other additional initialization needed. + /// + /// The input application instance to run. + /// Name of the input application instance to run. + /// The exit code for the application. + public static int Run(Win32Application application, string applicatioName) { Win32ApplicationRunner.application = application; HMODULE hInstance = Windows.GetModuleHandleW(null); - fixed (char* name = Assembly.GetExecutingAssembly().FullName) + fixed (char* name = applicatioName) fixed (char* windowTitle = application.GetType().ToString()) { // Initialize the window class @@ -162,7 +174,7 @@ internal static unsafe class Win32ApplicationRunner } /// - /// Processes incoming messages for a window. + /// Processes incoming messages for a window. /// /// A handle to the window. /// The message. diff --git a/samples/ComputeSharp.SwapChain/Program.cs b/samples/ComputeSharp.SwapChain/Program.cs index d1606b2a..feae0e7d 100644 --- a/samples/ComputeSharp.SwapChain/Program.cs +++ b/samples/ComputeSharp.SwapChain/Program.cs @@ -61,7 +61,7 @@ class Program Console.WriteLine(); Console.WriteLine($"Starting {Samples[index].ShaderName}..."); - _ = Win32ApplicationRunner.Run(Samples[index].Application); + _ = Win32ApplicationRunner.Run(Samples[index].Application, "ComputeSharp.SwapChain"); } } while (index >= 0 && index < Samples.Length); diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 3f6df968..cdcb576b 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -41,7 +41,7 @@ - + From 066165f957dfb00936547a89afbcd29fd75fd4f2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 7 Nov 2022 23:09:23 +0100 Subject: [PATCH 2/3] Remove unnecessary method --- .../Backend/Win32ApplicationRunner.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 03b2b226..04a35bed 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.Drawing; -using System.Reflection; using System.Runtime.InteropServices; using System.Threading; using TerraFX.Interop.Windows; @@ -38,17 +37,6 @@ internal static unsafe class Win32ApplicationRunner /// private static Thread renderThread = null!; - /// - /// Runs a specified application and starts the main loop to update its state. This is the entry point for a given application, - /// and it should be called as soon as the process is launched, excluding any other additional initialization needed. - /// - /// The input application instance to run. - /// The exit code for the application. - public static int Run(Win32Application application) - { - return Run(application, Assembly.GetExecutingAssembly().FullName ?? "ComputeSharp"); - } - /// /// Runs a specified application and starts the main loop to update its state. This is the entry point for a given application, /// and it should be called as soon as the process is launched, excluding any other additional initialization needed. From d3d904149ae23b3c4c49d687088897d8b5ca1e16 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 7 Nov 2022 23:31:55 +0100 Subject: [PATCH 3/3] Fix window title in reflection disabled mode --- .../Backend/Win32ApplicationRunner.cs | 11 ++++++----- samples/ComputeSharp.SwapChain/Program.cs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs index 04a35bed..e6dd3c90 100644 --- a/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs +++ b/samples/ComputeSharp.SwapChain/Backend/Win32ApplicationRunner.cs @@ -42,16 +42,17 @@ internal static unsafe class Win32ApplicationRunner /// and it should be called as soon as the process is launched, excluding any other additional initialization needed. /// /// The input application instance to run. - /// Name of the input application instance to run. + /// Name of the input application instance to run. + /// The title to use for the window being opened. /// The exit code for the application. - public static int Run(Win32Application application, string applicatioName) + public static int Run(Win32Application application, string applicationName, string windowTitle) { Win32ApplicationRunner.application = application; HMODULE hInstance = Windows.GetModuleHandleW(null); - fixed (char* name = applicatioName) - fixed (char* windowTitle = application.GetType().ToString()) + fixed (char* name = applicationName) + fixed (char* title = windowTitle) { // Initialize the window class WNDCLASSEXW windowClassEx = new() @@ -79,7 +80,7 @@ internal static unsafe class Win32ApplicationRunner hwnd = Windows.CreateWindowExW( 0, windowClassEx.lpszClassName, - (ushort*)windowTitle, + (ushort*)title, WS.WS_OVERLAPPEDWINDOW, Windows.CW_USEDEFAULT, Windows.CW_USEDEFAULT, diff --git a/samples/ComputeSharp.SwapChain/Program.cs b/samples/ComputeSharp.SwapChain/Program.cs index feae0e7d..faf777c3 100644 --- a/samples/ComputeSharp.SwapChain/Program.cs +++ b/samples/ComputeSharp.SwapChain/Program.cs @@ -61,7 +61,7 @@ class Program Console.WriteLine(); Console.WriteLine($"Starting {Samples[index].ShaderName}..."); - _ = Win32ApplicationRunner.Run(Samples[index].Application, "ComputeSharp.SwapChain"); + _ = Win32ApplicationRunner.Run(Samples[index].Application, "ComputeSharp.SwapChain", Samples[index].ShaderName); } } while (index >= 0 && index < Samples.Length);