mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-12 21:38:45 +00:00
Added checks to parameters to prevent unneccessary updates
This commit is contained in:
parent
cd62691709
commit
76be341505
@ -20,10 +20,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_negativePrompt != value)
|
||||
{
|
||||
_negativePrompt = value;
|
||||
Native.stable_diffusion_full_params_set_negative_prompt(ParamPtr, _negativePrompt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float _cfgScale;
|
||||
public float CfgScale
|
||||
@ -33,10 +36,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (Math.Abs(_cfgScale - value) > 0.0001)
|
||||
{
|
||||
_cfgScale = value;
|
||||
Native.stable_diffusion_full_params_set_cfg_scale(ParamPtr, _cfgScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _width;
|
||||
public int Width
|
||||
@ -46,10 +52,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_width != value)
|
||||
{
|
||||
_width = value;
|
||||
Native.stable_diffusion_full_params_set_width(ParamPtr, _width);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _height;
|
||||
public int Height
|
||||
@ -59,10 +68,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_height != value)
|
||||
{
|
||||
_height = value;
|
||||
Native.stable_diffusion_full_params_set_height(ParamPtr, _height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Sampler _sampleMethod;
|
||||
public Sampler SampleMethod
|
||||
@ -72,10 +84,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_sampleMethod != value)
|
||||
{
|
||||
_sampleMethod = value;
|
||||
Native.stable_diffusion_full_params_set_sample_method(ParamPtr, _sampleMethod.GetNativeName() ?? "EULER_A");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _sampleSteps;
|
||||
public int SampleSteps
|
||||
@ -85,10 +100,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_sampleSteps != value)
|
||||
{
|
||||
_sampleSteps = value;
|
||||
Native.stable_diffusion_full_params_set_sample_steps(ParamPtr, _sampleSteps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private long _seed;
|
||||
public long Seed
|
||||
@ -98,10 +116,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_seed != value)
|
||||
{
|
||||
_seed = value;
|
||||
Native.stable_diffusion_full_params_set_seed(ParamPtr, _seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _batchCount;
|
||||
public int BatchCount
|
||||
@ -111,10 +132,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (_batchCount != value)
|
||||
{
|
||||
_batchCount = value;
|
||||
Native.stable_diffusion_full_params_set_batch_count(ParamPtr, _batchCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float _strength;
|
||||
public float Strength
|
||||
@ -124,10 +148,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
|
||||
if (Math.Abs(_strength - value) > 0.0001)
|
||||
{
|
||||
_strength = value;
|
||||
Native.stable_diffusion_full_params_set_strength(ParamPtr, _strength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user