Added checks to parameters to prevent unneccessary updates

This commit is contained in:
Darth Affe 2023-12-16 15:19:59 +01:00
parent cd62691709
commit 76be341505

View File

@ -20,10 +20,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_negativePrompt != value)
{
_negativePrompt = value; _negativePrompt = value;
Native.stable_diffusion_full_params_set_negative_prompt(ParamPtr, _negativePrompt); Native.stable_diffusion_full_params_set_negative_prompt(ParamPtr, _negativePrompt);
} }
} }
}
private float _cfgScale; private float _cfgScale;
public float CfgScale public float CfgScale
@ -33,10 +36,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (Math.Abs(_cfgScale - value) > 0.0001)
{
_cfgScale = value; _cfgScale = value;
Native.stable_diffusion_full_params_set_cfg_scale(ParamPtr, _cfgScale); Native.stable_diffusion_full_params_set_cfg_scale(ParamPtr, _cfgScale);
} }
} }
}
private int _width; private int _width;
public int Width public int Width
@ -46,10 +52,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_width != value)
{
_width = value; _width = value;
Native.stable_diffusion_full_params_set_width(ParamPtr, _width); Native.stable_diffusion_full_params_set_width(ParamPtr, _width);
} }
} }
}
private int _height; private int _height;
public int Height public int Height
@ -59,10 +68,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_height != value)
{
_height = value; _height = value;
Native.stable_diffusion_full_params_set_height(ParamPtr, _height); Native.stable_diffusion_full_params_set_height(ParamPtr, _height);
} }
} }
}
private Sampler _sampleMethod; private Sampler _sampleMethod;
public Sampler SampleMethod public Sampler SampleMethod
@ -72,10 +84,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_sampleMethod != value)
{
_sampleMethod = value; _sampleMethod = value;
Native.stable_diffusion_full_params_set_sample_method(ParamPtr, _sampleMethod.GetNativeName() ?? "EULER_A"); Native.stable_diffusion_full_params_set_sample_method(ParamPtr, _sampleMethod.GetNativeName() ?? "EULER_A");
} }
} }
}
private int _sampleSteps; private int _sampleSteps;
public int SampleSteps public int SampleSteps
@ -85,10 +100,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_sampleSteps != value)
{
_sampleSteps = value; _sampleSteps = value;
Native.stable_diffusion_full_params_set_sample_steps(ParamPtr, _sampleSteps); Native.stable_diffusion_full_params_set_sample_steps(ParamPtr, _sampleSteps);
} }
} }
}
private long _seed; private long _seed;
public long Seed public long Seed
@ -98,10 +116,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_seed != value)
{
_seed = value; _seed = value;
Native.stable_diffusion_full_params_set_seed(ParamPtr, _seed); Native.stable_diffusion_full_params_set_seed(ParamPtr, _seed);
} }
} }
}
private int _batchCount; private int _batchCount;
public int BatchCount public int BatchCount
@ -111,10 +132,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (_batchCount != value)
{
_batchCount = value; _batchCount = value;
Native.stable_diffusion_full_params_set_batch_count(ParamPtr, _batchCount); Native.stable_diffusion_full_params_set_batch_count(ParamPtr, _batchCount);
} }
} }
}
private float _strength; private float _strength;
public float Strength public float Strength
@ -124,10 +148,13 @@ public sealed unsafe class StableDiffusionParameter : IDisposable
{ {
ObjectDisposedException.ThrowIf(_disposed, this); ObjectDisposedException.ThrowIf(_disposed, this);
if (Math.Abs(_strength - value) > 0.0001)
{
_strength = value; _strength = value;
Native.stable_diffusion_full_params_set_strength(ParamPtr, _strength); Native.stable_diffusion_full_params_set_strength(ParamPtr, _strength);
} }
} }
}
#endregion #endregion