Added logging; Updated stable-diffusion.cpp to 7cb41b1

This commit is contained in:
Darth Affe 2024-01-02 23:39:56 +01:00
parent a7ccbe8ef2
commit c277e9c830
5 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,11 @@
namespace StableDiffusion.NET;
public class StableDiffusionLogEventArgs(LogLevel level, string text)
{
#region Properties & Fields
public LogLevel Level { get; } = level;
public string Text { get; } = text;
#endregion
}

View File

@ -21,6 +21,12 @@ internal unsafe partial class Native
#endregion
#region Delegates
internal delegate void sd_log_cb_t(sd_log_level_t level, [MarshalAs(UnmanagedType.LPStr)] string text, void* data);
#endregion
#region DLL-Import
internal struct sd_ctx_t;
@ -98,5 +104,8 @@ internal unsafe partial class Native
sd_image_t input_image,
int upscale_factor);
[LibraryImport(LIB_NAME, EntryPoint = "sd_set_log_callback")]
internal static partial void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
#endregion
}

View File

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=attributes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enums/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=eventargs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -18,8 +18,19 @@ public sealed unsafe class StableDiffusionModel : IDisposable
#endregion
#region Events
public static event EventHandler<StableDiffusionLogEventArgs>? Log;
#endregion
#region Constructors
static StableDiffusionModel()
{
Native.sd_set_log_callback(OnNativeLog, null);
}
public StableDiffusionModel(string modelPath, ModelParameter parameter, UpscalerModelParameter? upscalerParameter = null)
{
this._modelPath = modelPath;
@ -177,5 +188,14 @@ public sealed unsafe class StableDiffusionModel : IDisposable
public static int GetNumPhysicalCores() => Native.get_num_physical_cores();
private static void OnNativeLog(LogLevel level, string text, void* data)
{
try
{
Log?.Invoke(null, new StableDiffusionLogEventArgs(level, text));
}
catch { /**/ }
}
#endregion
}

View File

@ -4,7 +4,7 @@ if not exist stable-diffusion.cpp (
cd stable-diffusion.cpp
git fetch
git checkout 2c5f3fc53a040a0f97ff8f359e8f8d1385bfd154
git checkout 7cb41b190fb9b4703f1737171cefd0abec861154
git submodule init
git submodule update