コミットを比較

...
10 コミット
作成者 SHA1 メッセージ 日付
routersys b0a0c5cc8f バージョンをv1.20.3へ更新
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.20.3 のコミットから作成しました
2026-07-05 19:52:33 +09:00
routersys 40f1322042 [fast]に小処理時の低速化リスクの注意書きを追加 2026-07-05 19:37:27 +09:00
routersys d1b0439611 バージョンをv1.20.2へ更新
リリース / build-and-release (workflow_dispatch) Actions がタグ v1.20.2 のコミットから作成しました
2026-07-05 19:19:02 +09:00
routersys 30d6f62d15 READMEを[fast]強制委譲の仕様へ更新 2026-07-05 19:17:52 +09:00
routersys ac3a1e350e サイトを[fast]強制委譲の仕様へ更新 2026-07-05 19:17:45 +09:00
routersys 0a7a2c7d40 全言語ドキュメントを[fast]強制委譲の仕様へ更新 2026-07-05 19:17:39 +09:00
routersys 1a97536bc5 テストへ[fast]の強制委譲を検証する項目を追加 2026-07-05 19:17:29 +09:00
routersys 8f954c7a2e 従来エンジンにもforce引数を復元 2026-07-05 19:17:21 +09:00
routersys 20509b19c9 ワーカーにforce引数を復元し[fast]で強制委譲 2026-07-05 19:17:13 +09:00
routersys e4bdf0df19 GPU処理にforce引数を追加しきい値を無視可能に 2026-07-05 19:17:06 +09:00
31個のファイルの変更、250行の追加、131行の削除

検索条件に一致するファイルはありません

+10 -26
ファイルの表示
@@ -1,44 +1,28 @@
# v1.20.1 - Lua スクリプト for YMM4
# v1.20.3 - Lua スクリプト for YMM4
画像加工の GPU 委譲を自動判定へ変更したリリースです。v1.20.0 では obj.fill / obj.convolve / obj.resize は [fast] マーカーを付けたときだけ GPU へ委譲していましたが、本バージョンからは標準の呼び出しでも、処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲します。マーカーを知らなくても大きな処理は速くなり、成立しない場合は従来どおり CPU で実行するため結果は変わりません。[fast] は構文・診断ともそのまま残り、委譲の意図を明示する補助マーカーになりました。置いても動作は変わりません。
[fast] マーカーの注意書きを補うドキュメント更新リリースです。v1.20.2 で [fast] は obj.fill / obj.convolve / obj.resize の処理量のしきい値を無視して GPU へ委譲する仕様になりましたが、処理量が小さいときは GPU への委譲自体の往復コストが CPU 実行を上回り、かえって遅くなる場合があることを明記しました。動作に関わる実装、API、実行結果、エラーの扱いに変更はありません。
---
## 変更
### 画像加工の GPU 委譲を自動判定へ
### [fast] は小さな処理で遅くなる場合があることを明記
obj.fill / obj.convolve / obj.resize は書き方を変えることなく、条件が成立したとき自動で GPU へ委譲します。委譲が成立する条件は v1.20.0 の [fast] と同じで、いずれかを満たさない場合は自動で CPU 実行になり、処理は失敗しません。
[fast] は obj.fill / obj.convolve / obj.resize のしきい値を無視しますが、GPU への委譲には往復コストがあります。処理量が小さいときは CPU 実行のほうが速い場合があるため、README、サイト、付属ドキュメントに注意書きを追加しました。
- Direct3D 11 のハードウェアデバイスが利用できること。ソフトウェアラスタライザ(WARP)へは委譲しません。CPU 実装より遅くなるためです。
- 処理量がしきい値以上であること。fill は画像全体で 1,048,576 画素以上、矩形指定では同じ画素数に加えて塗り面積が画像の 3/4 以上、resize は出力が 262,144 画素以上、convolve は画素数×係数の個数が 262,144 以上です。小さな処理は委譲の往復コストが上回るため CPU で実行します。
- convolve のカーネルは 31×31 までです。それを超えるサイズは CPU で実行します。
- 初回に小さな検証画像で GPU の結果を CPU 基準とバイト単位で比較し、一致した組み合わせだけを GPU へ委譲すること。不一致の環境やカーネルでは CPU 実行へ戻ります。
### [fast] マーカーは補助的な明示へ
判定が自動になったため、[fast] は委譲の意図を明示する補助マーカーになりました。
- 構文・置ける位置(単独の行または同じ行)・内部プリミティブへの書き換えは v1.20.0 から変わりません。
- 3 関数以外へ付けたときのエラー表示もそのまま機能します。
- [fast] を付けた呼び出しと付けない呼び出しは同じ判定を通るため、動作の差はありません。既存の [fast] 付きスクリプトはそのまま動きます。
- 付属の 8 言語ドキュメントの [fast] の節へ、同じ注意書きを追加しました。
---
## 互換性・後方互換
- しきい値未満の小さな処理、GPU が使えない環境、検証に通らないカーネルでは、実行結果は v1.20.0 と同一です。
- GPU 委譲は事前の検証で CPU 基準とバイト単位まで一致した組み合わせに限って行い、成立しない場合は常に CPU 実装が結果を保証します。
- 関数の引数・戻り値・エラーの扱いに変更はありません。スクリプトの書き換えは不要です。
- エンジンの自動振り分け、エンジン指定ディレクティブの仕様と優先順位、カーネル化の対象、v1.20.0 までの構文拡張と既存の API に変更はありません。
- 動作に関わる実装の変更はありません。
- API、構文、エンジンの自動振り分け、GPU 検証、CPU への自動フォールバックに変更はありません。
- v1.20.2 の [fast] の強制委譲仕様に変更はありません。
---
## 内部実装
- 3 実行系(MoonSharp・LuaJIT ワーカー・コンテキスト契約)から委譲の明示フラグ accelerate を削除しました。[fast] の書き換え先である __fast_fill / __fast_convolve / __fast_resize は標準の関数と同じ実装の別名になり、マーカーの有無で経路が分かれることは構造的にありません。
- 従来エンジンは AviUtlScriptContext の fill / convolve / resize が常にプロセッサへ照会し、不成立なら CPU 実装へ落ちます。しきい値の判定は GPU 演算側(GpuFillOperation / GpuConvolveOperation / GpuResizeOperation)が持ちます。
- 高速ランタイムは worker.lua がしきい値の成立時のみホストへ往復し、しきい値未満は往復せず Lua 内で完結します。成立し得ない委譲のプロセス間往復コストは発生しません。
- GPU 基盤(専用プロジェクト・事前 DXBC コンパイル・検証キャッシュ・再生成予算)は v1.20.0 のまま変更していません。
- ドキュメントは付属の 8 言語の [fast] の節、サイトの構文拡張と obj の関数のページ、README を自動判定の仕様へ更新しました。
- テストは 3400 件です。v1.20.0 の 3396 件から、標準呼び出しがホストプロセッサへ委譲されることの検証へ両レーンの既定経路テストを反転し、しきい値未満では委譲しないことの検証 3 件と、従来エンジンの委譲と CPU フォールバックの検証 1 件を追加しました。ソリューションは x64 で 0 個の警告、0 個のエラーです。
- 動作に関わるコード変更はありません。
- リリース対象のバージョン表記を v1.20.3 へ更新しました。
+1 -1
ファイルの表示
@@ -1,5 +1,5 @@
========================================
Luaスクリプト for YMM4 v1.20.1
Luaスクリプト for YMM4 v1.20.3
========================================
YukkuriMovieMaker4(YMM4)上で動作する、Luaスクリプトで映像エフェクトのパラメータや
ピクセルを直接制御できるプラグインです。
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
</PropertyGroup>
+1 -1
ファイルの表示
@@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
+2 -2
ファイルの表示
@@ -15,13 +15,13 @@ namespace LuaScript.Engine.Processing
private readonly float[] _constants = new float[1024];
private readonly List<ConvolveValidation> _validations = [];
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset)
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false)
{
if (!IsTextureSupported(target, width, height) || !IsSupported(kernel, size, divisor, offset))
return false;
long work = (long)width * height * size * size;
if (work < ConvolveWorkThreshold || !EnsureValidated(target, width, height, kernel, size, divisor, offset))
if (!force && work < ConvolveWorkThreshold || !EnsureValidated(target, width, height, kernel, size, divisor, offset))
return false;
SetConstants(width, height, kernel, size, divisor, offset);
+3 -3
ファイルの表示
@@ -16,7 +16,7 @@ namespace LuaScript.Engine.Processing
private bool? _fullValidated;
private bool? _partialValidated;
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight)
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false)
{
if (!IsTextureSupported(target, width, height) || !AreFinite(r, g, b, a))
return false;
@@ -25,14 +25,14 @@ namespace LuaScript.Engine.Processing
bool full = x == 0 && y == 0 && fillWidth == width && fillHeight == height;
if (full)
{
if (pixels < FillFullThreshold || !EnsureFullValidated())
if (!force && pixels < FillFullThreshold || !EnsureFullValidated())
return false;
SetConstants(r, g, b, a);
return RunFillFull(_constants.AsSpan(0, 4), target, width, height);
}
long area = (long)fillWidth * fillHeight;
if (pixels < FillPartialThreshold || area * 4L < pixels * 3L || !EnsurePartialValidated())
if (!force && (pixels < FillPartialThreshold || area * 4L < pixels * 3L) || !EnsurePartialValidated())
return false;
SetConstants(r, g, b, a);
+6 -6
ファイルの表示
@@ -9,22 +9,22 @@ namespace LuaScript.Engine.Processing
private readonly GpuConvolveOperation _convolve = new(runner);
private readonly GpuResizeOperation _resize = new(runner);
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight)
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false)
{
lock (_gate)
return _fill.TryFill(target, width, height, r, g, b, a, x, y, fillWidth, fillHeight);
return _fill.TryFill(target, width, height, r, g, b, a, x, y, fillWidth, fillHeight, force);
}
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset)
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false)
{
lock (_gate)
return _convolve.TryConvolve(target, width, height, kernel, size, divisor, offset);
return _convolve.TryConvolve(target, width, height, kernel, size, divisor, offset, force);
}
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target)
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false)
{
lock (_gate)
return _resize.TryResize(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target);
return _resize.TryResize(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target, force);
}
}
}
+2 -2
ファイルの表示
@@ -16,14 +16,14 @@ namespace LuaScript.Engine.Processing
private bool? _nearestValidated;
private bool? _linearValidated;
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target)
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false)
{
target = null;
if (!IsTextureSupported(source, sourceWidth, sourceHeight) || !IsTextureSizeSupported(targetWidth, targetHeight))
return false;
long pixels = (long)targetWidth * targetHeight;
if (pixels < ResizeThreshold || !(linear ? EnsureLinearValidated(source, sourceWidth, sourceHeight) : EnsureNearestValidated(source, sourceWidth, sourceHeight)))
if (!force && pixels < ResizeThreshold || !(linear ? EnsureLinearValidated(source, sourceWidth, sourceHeight) : EnsureNearestValidated(source, sourceWidth, sourceHeight)))
return false;
return RunShader(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target);
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
</PropertyGroup>
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+6 -6
ファイルの表示
@@ -511,7 +511,7 @@ namespace LuaScript
private byte[]? _resizeSource;
private byte[]? _resizeBuffer;
public unsafe void FillBuffer(double r, double g, double b, double a, int x, int y, int w, int h)
public unsafe void FillBuffer(double r, double g, double b, double a, int x, int y, int w, int h, bool force = false)
{
EnsurePixelBuffer();
if (_pixelBuffer is null)
@@ -526,7 +526,7 @@ namespace LuaScript
if (x1 <= x0 || y1 <= y0)
return;
if (PixelProcessor?.TryFill(_pixelBuffer, cw, ch, r, g, b, a, x0, y0, x1 - x0, y1 - y0) == true)
if (PixelProcessor?.TryFill(_pixelBuffer, cw, ch, r, g, b, a, x0, y0, x1 - x0, y1 - y0, force) == true)
{
_isPixelsDirty = true;
return;
@@ -621,7 +621,7 @@ namespace LuaScript
}
}
public unsafe void Convolve(double[] kernel, int size, double divisor, double offset)
public unsafe void Convolve(double[] kernel, int size, double divisor, double offset, bool force = false)
{
EnsurePixelBuffer();
if (_pixelBuffer is null)
@@ -629,7 +629,7 @@ namespace LuaScript
int cw = ImageWidth;
int ch = ImageHeight;
if (PixelProcessor?.TryConvolve(_pixelBuffer, cw, ch, kernel, size, divisor, offset) == true)
if (PixelProcessor?.TryConvolve(_pixelBuffer, cw, ch, kernel, size, divisor, offset, force) == true)
{
_isPixelsDirty = true;
return;
@@ -639,7 +639,7 @@ namespace LuaScript
PixelBufferSoftwareProcessor.Convolve(_pixelBuffer, cw, ch, kernel, size, divisor, offset, ref _convolveSource);
}
public unsafe void Resize(int newWidth, int newHeight, bool linear)
public unsafe void Resize(int newWidth, int newHeight, bool linear, bool force = false)
{
EnsurePixelBuffer();
if (_pixelBuffer is null)
@@ -650,7 +650,7 @@ namespace LuaScript
int cw = ImageWidth;
int ch = ImageHeight;
if (PixelProcessor?.TryResize(_pixelBuffer, cw, ch, newWidth, newHeight, linear, out var processed) == true && processed is not null)
if (PixelProcessor?.TryResize(_pixelBuffer, cw, ch, newWidth, newHeight, linear, out var processed, force) == true && processed is not null)
{
ReplaceBuffer(processed, newWidth, newHeight);
return;
+3 -3
ファイルの表示
@@ -2,10 +2,10 @@ namespace LuaScript
{
internal interface IPixelBufferProcessor
{
bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight);
bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false);
bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset);
bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false);
bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target);
bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false);
}
}
+10 -9
ファイルの表示
@@ -411,11 +411,12 @@ namespace LuaScript.Engine
_pixelProcessTarget = new byte[pixelLength];
int operation = (int)view.ReadDouble(NativeProtocol.CallbackResultOffset);
bool force = view.ReadDouble(NativeProtocol.CallbackResultOffset + 9 * 8) != 0d;
processed = operation switch
{
NativeProtocol.PixelProcessFill => TryProcessFill(view, pixelProcessor, width, height, pixelLength),
NativeProtocol.PixelProcessConvolve => TryProcessConvolve(view, pixelProcessor, width, height, pixelLength),
NativeProtocol.PixelProcessResize => TryProcessResize(view, pixelProcessor, pixelLength),
NativeProtocol.PixelProcessFill => TryProcessFill(view, pixelProcessor, width, height, pixelLength, force),
NativeProtocol.PixelProcessConvolve => TryProcessConvolve(view, pixelProcessor, width, height, pixelLength, force),
NativeProtocol.PixelProcessResize => TryProcessResize(view, pixelProcessor, pixelLength, force),
_ => false,
};
}
@@ -424,7 +425,7 @@ namespace LuaScript.Engine
view.Write(NativeProtocol.OffCallbackFound, processed ? 1 : pixelProcessor is null ? -1 : 0);
}
private bool TryProcessFill(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int width, int height, int pixelLength)
private bool TryProcessFill(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int width, int height, int pixelLength, bool force)
{
long offset = NativeProtocol.CallbackResultOffset;
double r = view.ReadDouble(offset + 1 * 8);
@@ -437,13 +438,13 @@ namespace LuaScript.Engine
int fillHeight = (int)view.ReadDouble(offset + 8 * 8);
if (x != 0 || y != 0 || fillWidth != width || fillHeight != height)
ReadRegion(_pixelOffset, _pixelProcessTarget, pixelLength);
if (!pixelProcessor.TryFill(_pixelProcessTarget, width, height, r, g, b, a, x, y, fillWidth, fillHeight))
if (!pixelProcessor.TryFill(_pixelProcessTarget, width, height, r, g, b, a, x, y, fillWidth, fillHeight, force))
return false;
WriteRegion(_pixelOffset, _pixelProcessTarget, pixelLength);
return true;
}
private bool TryProcessConvolve(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int width, int height, int pixelLength)
private bool TryProcessConvolve(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int width, int height, int pixelLength, bool force)
{
long offset = NativeProtocol.CallbackResultOffset;
int size = (int)view.ReadDouble(offset + 1 * 8);
@@ -458,13 +459,13 @@ namespace LuaScript.Engine
_pixelProcessKernel = new double[taps];
ReadRegion(_pixelOffset, _pixelProcessTarget, pixelLength);
view.ReadArray(NativeProtocol.CallbackTagOffset, _pixelProcessKernel, 0, taps);
if (!pixelProcessor.TryConvolve(_pixelProcessTarget, width, height, _pixelProcessKernel, size, divisor, kernelOffset))
if (!pixelProcessor.TryConvolve(_pixelProcessTarget, width, height, _pixelProcessKernel, size, divisor, kernelOffset, force))
return false;
WriteRegion(_pixelOffset, _pixelProcessTarget, pixelLength);
return true;
}
private bool TryProcessResize(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int sourceLength)
private bool TryProcessResize(MemoryMappedViewAccessor view, IPixelBufferProcessor pixelProcessor, int sourceLength, bool force)
{
long offset = NativeProtocol.CallbackResultOffset;
int targetWidth = (int)view.ReadDouble(offset + 1 * 8);
@@ -476,7 +477,7 @@ namespace LuaScript.Engine
if (targetWidth <= 0 || targetHeight <= 0 || length > PixelRegionCapacity || length > int.MaxValue)
return false;
ReadRegion(_pixelOffset, _pixelProcessTarget, sourceLength);
if (!pixelProcessor.TryResize(_pixelProcessTarget, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out var target) || target is null)
if (!pixelProcessor.TryResize(_pixelProcessTarget, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out var target, force) || target is null)
return false;
WriteRegion(_pixelOffset, target, (int)length);
view.Write(NativeProtocol.OffWidth, targetWidth);
+12 -12
ファイルの表示
@@ -187,9 +187,9 @@ namespace LuaScript
private void RegisterFastPrimitives(Script script)
{
script.Globals.Set("__fast_fill", DynValue.NewCallback((_, args) => FillCore(args)));
script.Globals.Set("__fast_convolve", DynValue.NewCallback((_, args) => ConvolveCore(args)));
script.Globals.Set("__fast_resize", DynValue.NewCallback((_, args) => ResizeCore(args)));
script.Globals.Set("__fast_fill", DynValue.NewCallback((_, args) => FillCore(args, true)));
script.Globals.Set("__fast_convolve", DynValue.NewCallback((_, args) => ConvolveCore(args, true)));
script.Globals.Set("__fast_resize", DynValue.NewCallback((_, args) => ResizeCore(args, true)));
}
private void EnsureScriptIntegrity()
@@ -1015,9 +1015,9 @@ namespace LuaScript
}
[LuaFunction("fill")]
private DynValue Fill(CallbackArguments args) => FillCore(args);
private DynValue Fill(CallbackArguments args) => FillCore(args, false);
private DynValue FillCore(CallbackArguments args)
private DynValue FillCore(CallbackArguments args, bool force)
{
_activeCancellation.ThrowIfCancellationRequested();
if (_activeContext is null)
@@ -1033,7 +1033,7 @@ namespace LuaScript
int w = args.Count > 6 ? (int)(args[6].CastToNumber() ?? 0d) : ctx.ImageWidth;
int h = args.Count > 7 ? (int)(args[7].CastToNumber() ?? 0d) : ctx.ImageHeight;
ctx.FillBuffer(r, g, b, a, x, y, w, h);
ctx.FillBuffer(r, g, b, a, x, y, w, h, force);
return DynValue.Void;
}
@@ -1086,9 +1086,9 @@ namespace LuaScript
}
[LuaFunction("convolve")]
private DynValue Convolve(CallbackArguments args) => ConvolveCore(args);
private DynValue Convolve(CallbackArguments args) => ConvolveCore(args, false);
private DynValue ConvolveCore(CallbackArguments args)
private DynValue ConvolveCore(CallbackArguments args, bool force)
{
_activeCancellation.ThrowIfCancellationRequested();
if (_activeContext is null || args.Count < 2 || args[0].Type != DataType.Table)
@@ -1115,14 +1115,14 @@ namespace LuaScript
divisor = 1d;
double offset = args.Count > 3 ? args[3].CastToNumber() ?? 0d : 0d;
_activeContext.Convolve(_kernelScratch, size, divisor, offset);
_activeContext.Convolve(_kernelScratch, size, divisor, offset, force);
return DynValue.Void;
}
[LuaFunction("resize")]
private DynValue Resize(CallbackArguments args) => ResizeCore(args);
private DynValue Resize(CallbackArguments args) => ResizeCore(args, false);
private DynValue ResizeCore(CallbackArguments args)
private DynValue ResizeCore(CallbackArguments args, bool force)
{
_activeCancellation.ThrowIfCancellationRequested();
if (_activeContext is null || args.Count < 2)
@@ -1134,7 +1134,7 @@ namespace LuaScript
return DynValue.Void;
bool linear = !(args.Count > 2 && args[2].Type == DataType.String && args[2].String == "nearest");
_activeContext.Resize(w, h, linear);
_activeContext.Resize(w, h, linear, force);
RefreshObjDimensions();
return DynValue.Void;
}
+1 -1
ファイルの表示
@@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+30 -3
ファイルの表示
@@ -57,22 +57,28 @@ namespace LuaScript.Tests
public int FillCalls;
public int ConvolveCalls;
public int ResizeCalls;
public bool LastFillForce;
public bool LastConvolveForce;
public bool LastResizeForce;
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight)
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false)
{
FillCalls++;
LastFillForce = force;
return false;
}
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset)
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false)
{
ConvolveCalls++;
LastConvolveForce = force;
return false;
}
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target)
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false)
{
ResizeCalls++;
LastResizeForce = force;
target = null;
return false;
}
@@ -93,6 +99,27 @@ namespace LuaScript.Tests
Assert.Equal(1, processor.ResizeCalls);
Assert.Equal(4, ctx.ImageWidth);
Assert.Equal(4, ctx.ImageHeight);
Assert.False(processor.LastFillForce);
Assert.False(processor.LastConvolveForce);
Assert.False(processor.LastResizeForce);
}
[Fact]
public void FastMarker_ForcesPixelProcessorRegardlessOfSize()
{
using var engine = CreateEngine();
var ctx = NewContext(new byte[2 * 2 * 4], 2, 2);
var processor = new RecordingProcessor();
ctx.PixelProcessor = processor;
engine.Execute("__fast_fill(200, 100, 50, 255) __fast_convolve({1,1,1,1,1,1,1,1,1}, 3) __fast_resize(4, 4)", ctx);
Assert.Equal(1, processor.FillCalls);
Assert.Equal(1, processor.ConvolveCalls);
Assert.Equal(1, processor.ResizeCalls);
Assert.True(processor.LastFillForce);
Assert.True(processor.LastConvolveForce);
Assert.True(processor.LastResizeForce);
}
[Fact]
+75 -3
ファイルの表示
@@ -1926,6 +1926,7 @@ namespace LuaScript.Tests
Assert.True(ok, error);
Assert.True(dirty);
Assert.Equal(1, processor.FillCalls);
Assert.True(processor.LastFillForce);
Assert.Equal(0x41, pixels[0]);
Assert.Equal(0x41, pixels[^1]);
}
@@ -1952,6 +1953,7 @@ namespace LuaScript.Tests
Assert.Equal(45d, processor.Divisor);
Assert.Equal(6d, processor.Offset);
Assert.Equal(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, processor.Kernel);
Assert.True(processor.LastConvolveForce);
Assert.Equal(0x42, pixels[0]);
Assert.Equal(0x42, pixels[^1]);
}
@@ -1985,6 +1987,7 @@ namespace LuaScript.Tests
Assert.NotNull(result);
Assert.Equal(0x43, result![0]);
Assert.Equal(0x43, result[^1]);
Assert.True(processor.LastResizeForce);
}
[Fact]
@@ -2005,6 +2008,7 @@ namespace LuaScript.Tests
Assert.True(ok, error);
Assert.True(dirty);
Assert.Equal(1, processor.FillCalls);
Assert.False(processor.LastFillForce);
Assert.Equal(0x41, pixels[0]);
Assert.Equal(0x41, pixels[^1]);
}
@@ -2031,6 +2035,7 @@ namespace LuaScript.Tests
Assert.Equal(45d, processor.Divisor);
Assert.Equal(6d, processor.Offset);
Assert.Equal(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, processor.Kernel);
Assert.False(processor.LastConvolveForce);
}
[Fact]
@@ -2053,6 +2058,7 @@ namespace LuaScript.Tests
Assert.Equal(1, processor.ResizeCalls);
Assert.Equal(512, rw);
Assert.Equal(512, rh);
Assert.False(processor.LastResizeForce);
}
[Fact]
@@ -2112,6 +2118,66 @@ namespace LuaScript.Tests
Assert.Equal(0, processor.ResizeCalls);
}
[Fact]
public void PixelProcess_ForcedFastFill_BelowThresholdUsesHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 64, h = 64;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { FillResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"__fast_fill(10, 20, 30, 40)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(1, processor.FillCalls);
Assert.True(processor.LastFillForce);
}
[Fact]
public void PixelProcess_ForcedFastConvolve_BelowThresholdUsesHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 8, h = 8;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { ConvolveResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"__fast_convolve({1, 1, 1, 1, 1, 1, 1, 1, 1}, 3)",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(1, processor.ConvolveCalls);
Assert.True(processor.LastConvolveForce);
}
[Fact]
public void PixelProcess_ForcedFastResize_BelowThresholdUsesHostProcessor()
{
Assert.True(LuaJitWorker.IsAvailable(NativeDir), "native/luajit.exe must be present");
const int w = 2, h = 2;
var pixels = new byte[w * h * 4];
var processor = new RecordingPixelProcessor { ResizeResult = true };
_pixelProcessor = processor;
bool ok = RunWorker(
"__fast_resize(4, 4, 'nearest')",
Fields(w, h, 0d), NoStringParams, () => pixels, w, h, 5000, NoResolver, NoLoadFigure, NoLoadText, NoLoadImage, NoLoadMovie, NoAddEffect, NoAddDraw, NoSetAnchor,
out _, out _, out _, out _, out _, out string? error);
Assert.True(ok, error);
Assert.Equal(1, processor.ResizeCalls);
Assert.True(processor.LastResizeForce);
}
[Fact]
public void HostCallbackTime_DoesNotConsumeScriptTimeout()
{
@@ -2363,35 +2429,41 @@ namespace LuaScript.Tests
public int TargetWidth { get; private set; }
public int TargetHeight { get; private set; }
public bool Linear { get; private set; }
public bool LastFillForce { get; private set; }
public bool LastConvolveForce { get; private set; }
public bool LastResizeForce { get; private set; }
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight)
public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false)
{
FillCalls++;
LastFillForce = force;
if (!FillResult)
return false;
Array.Fill(target, (byte)0x41, 0, width * height * 4);
return true;
}
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset)
public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false)
{
ConvolveCalls++;
Size = size;
Divisor = divisor;
Offset = offset;
Kernel = kernel.AsSpan(0, size * size).ToArray();
LastConvolveForce = force;
if (!ConvolveResult)
return false;
Array.Fill(target, (byte)0x42, 0, width * height * 4);
return true;
}
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target)
public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false)
{
ResizeCalls++;
TargetWidth = targetWidth;
TargetHeight = targetHeight;
Linear = linear;
LastResizeForce = force;
target = null;
if (!ResizeResult)
return false;
+1 -1
ファイルの表示
@@ -4,7 +4,7 @@
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
<UseWPF>true</UseWPF>
<ImplicitUsings>enable</ImplicitUsings>
<Version>1.20.1</Version>
<Version>1.20.3</Version>
<Platforms>AnyCPU;x64</Platforms>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+7 -3
ファイルの表示
@@ -977,13 +977,17 @@
○ [fast] (علامة التسريع) * امتداد خاص بـ YMM4
تُفوَّض obj.fill / obj.convolve / obj.resize إلى وحدة معالجة الرسوميات
تلقائيًا عندما يتجاوز حجم المعالجة حدًا معينًا ويتم التحقق من تطابق نتيجة
وحدة معالجة الرسوميات مع نتيجة المعالج. [fast] علامة مساعدة تصرّح
بالنية صراحةً، وإضافتها لا تغيّر السلوك. يمكن وضع العلامة في سطر
مستقل أو في السطر نفسه.
وحدة معالجة الرسوميات مع نتيجة المعالج. تتجاهل [fast] هذا الحد وتفرض
التفويض إلى وحدة معالجة الرسوميات. عند عدم توفر وحدة معالجة الرسوميات
أو عدم تطابق نتيجتها مع المعالج، ترجع [fast] تلقائيًا إلى المعالج. يمكن
وضع العلامة في سطر مستقل أو في السطر نفسه.
مثال: [fast]
obj.convolve(kernel, 5)
* يظهر خطأ عندما يسبق [fast] أي شيء غير هذه الدوال الثلاث.
* يعمل في محرك MoonSharp والمحرك الأصلي على حد سواء.
* عند أحمال المعالجة الصغيرة، قد تتجاوز تكلفة الذهاب والإياب
الخاصة بتفويض وحدة معالجة الرسوميات تكلفة التنفيذ على المعالج،
فقد تجعل [fast] الأداء أبطأ بدلاً من أسرع.
- أمثلة على النصوص البرمجية -
+8 -3
ファイルの表示
@@ -1016,13 +1016,18 @@
o [fast] (acceleration marker) * YMM4 extension
obj.fill / obj.convolve / obj.resize are delegated to the GPU
automatically when the workload exceeds a threshold and the GPU
result is verified to match the CPU. [fast] is an auxiliary marker
that states the intent explicitly; adding it does not change the
behavior. The marker may be on its own line or on the same line.
result is verified to match the CPU. [fast] ignores that
workload threshold and forces GPU delegation. When no GPU is
available or the GPU result does not match the CPU, [fast]
still falls back to the CPU automatically. The marker may be
on its own line or on the same line.
Example: [fast]
obj.convolve(kernel, 5)
* An error is shown when [fast] precedes anything other than those three functions.
* Works in both the MoonSharp and native engines.
* For small workloads, the round-trip cost of delegating to the GPU
can exceed plain CPU execution, so [fast] may make things slower
rather than faster.
- Script Examples -
+8 -3
ファイルの表示
@@ -1037,13 +1037,18 @@
o [fast] (marcador de aceleración) * extensión de YMM4
obj.fill / obj.convolve / obj.resize se delegan automáticamente a la
GPU cuando la carga supera un umbral y el resultado de la GPU se
verifica como idéntico al de la CPU. [fast] es un marcador auxiliar
que declara la intención de forma explícita; añadirlo no cambia el
comportamiento. El marcador puede ir en su propia línea o en la misma.
verifica como idéntico al de la CPU. [fast] ignora ese umbral de
carga y fuerza la delegación a la GPU. Cuando no hay GPU disponible
o el resultado de la GPU no coincide con el de la CPU, [fast]
sigue recayendo automáticamente en la CPU. El marcador puede ir
en su propia línea o en la misma.
Ejemplo: [fast]
obj.convolve(kernel, 5)
* Se muestra un error cuando [fast] precede a algo distinto de esas tres funciones.
* Funciona tanto en el motor MoonSharp como en el nativo.
* En cargas pequeñas, el costo de ida y vuelta de delegar a la GPU
puede superar al de ejecutar en CPU, por lo que [fast] puede
hacer las cosas más lentas en vez de más rápidas.
- Ejemplos de script -
+8 -3
ファイルの表示
@@ -1027,13 +1027,18 @@
o [fast] (penanda akselerasi) * ekstensi YMM4
obj.fill / obj.convolve / obj.resize didelegasikan ke GPU secara
otomatis ketika beban kerja melebihi ambang batas dan hasil GPU
terverifikasi sama dengan CPU. [fast] adalah penanda tambahan yang
menyatakan niat secara eksplisit; menambahkannya tidak mengubah
perilaku. Penanda boleh di baris tersendiri atau di baris yang sama.
terverifikasi sama dengan CPU. [fast] mengabaikan ambang batas
beban kerja tersebut dan memaksa delegasi ke GPU. Saat GPU tidak
tersedia atau hasil GPU tidak sama dengan CPU, [fast] tetap
otomatis kembali ke CPU. Penanda boleh di baris tersendiri atau
di baris yang sama.
Contoh: [fast]
obj.convolve(kernel, 5)
* Kesalahan ditampilkan jika [fast] mendahului selain ketiga fungsi tersebut.
* Berfungsi pada mesin MoonSharp maupun native.
* Untuk beban kerja kecil, biaya bolak-balik pendelegasian ke GPU
bisa melebihi eksekusi CPU biasa, sehingga [fast] justru bisa
membuat lebih lambat, bukan lebih cepat.
- Contoh Skrip -
+7 -3
ファイルの表示
@@ -984,13 +984,17 @@
○[fast](高速化マーカー) ※YMM4独自拡張
obj.fill / obj.convolve / obj.resize は、処理量がしきい値以上で
GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲
します。[fast] は委譲の意図を明示する補助マーカーで、置いても
動作は変わりません。マーカーは単独の行に置いても、同じ行に
続けて書いても構いません。
します。[fast] を付けると、この処理量のしきい値を無視して強制的
に GPU へ委譲します。GPU が使えない環境や GPU の結果が CPU と
一致しない環境では、[fast] を付けても CPU へ自動的に戻ります。
マーカーは単独の行に置いても、同じ行に続けて書いても構いません。
例:[fast]
obj.convolve(kernel, 5)
※ [fast] を付けた対象が上記 3 関数以外のときはエラーを表示します。
※ 従来エンジンと高速ランタイムの両方で動作します。
※ 処理量が小さいときは、GPU への委譲自体の往復コストが CPU 実行
を上回ることがあり、[fast] を付けるとかえって遅くなる場合が
あります。
- スクリプト例 -
+6 -3
ファイルの表示
@@ -973,13 +973,16 @@
○ [fast] (가속 마커) ※YMM4 고유 확장
obj.fill / obj.convolve / obj.resize는 처리량이 임계값 이상이고
GPU 결과가 CPU와 일치함이 확인되면 자동으로 GPU에 위임합니다.
[fast]는 위임 의도를 명시하는 보조 마커이며, 붙여도 동작은
변하지 않습니다. 마커는 단독 행에 두어도, 같은 행에 이어 써도
됩니다.
[fast]를 붙이면 이 처리량 임계값을 무시하고 강제로 GPU에
위임합니다. GPU를 사용할 수 없거나 GPU 결과가 CPU와 일치하지
않는 환경에서는 [fast]를 붙여도 자동으로 CPU로 되돌아갑니다.
마커는 단독 행에 두어도, 같은 행에 이어 써도 됩니다.
예: [fast]
obj.convolve(kernel, 5)
※ [fast]를 붙인 대상이 위 3개 함수가 아니면 오류를 표시합니다.
※ 기존 엔진과 고속 런타임 양쪽에서 동작합니다.
※ 처리량이 작을 때는 GPU 위임 자체의 왕복 비용이 CPU 실행보다
커서, [fast]를 붙이면 오히려 느려질 수 있습니다.
- 스크립트 예 -
+5 -2
ファイルの表示
@@ -930,13 +930,16 @@
○ [fast](加速标记) ※YMM4专有扩展
当处理量达到阈值且 GPU 结果经验证与 CPU 一致时,obj.fill /
obj.convolve / obj.resize 会自动委托给 GPU。[fast] 是显式表明
委托意图的辅助标记,加上它不会改变行为。标记可以单独占一行,
obj.convolve / obj.resize 会自动委托给 GPU。加上 [fast] 会
无视处理量阈值,强制委托给 GPU。若环境没有 GPU,或 GPU 结果
与 CPU 不一致,[fast] 仍会自动回退到 CPU。标记可以单独占一行,
也可以写在同一行。
例:[fast]
obj.convolve(kernel, 5)
※ 若 [fast] 修饰的目标不是上述 3 个函数,则显示错误。
※ 在传统引擎和高速运行时上均可运行。
※ 处理量较小时,委托给 GPU 本身的往返开销可能超过 CPU 执行,
加上 [fast] 反而可能更慢。
- 脚本示例 -
+5 -2
ファイルの表示
@@ -931,13 +931,16 @@
○ [fast](加速標記) ※YMM4專有擴充
當處理量達到閾值且 GPU 結果經驗證與 CPU 一致時,obj.fill /
obj.convolve / obj.resize 會自動委派給 GPU。[fast] 是明示
委派意圖的輔助標記,加上它不會改變行為。標記可以單獨佔一行,
obj.convolve / obj.resize 會自動委派給 GPU。加上 [fast] 會
無視處理量閾值,強制委派給 GPU。若環境沒有 GPU,或 GPU 結果
與 CPU 不一致,[fast] 仍會自動回退到 CPU。標記可以單獨佔一行,
也可以寫在同一行。
例:[fast]
obj.convolve(kernel, 5)
※ 若 [fast] 修飾的目標不是上述 3 個函式,則顯示錯誤。
※ 在傳統引擎與高速執行環境上皆可運行。
※ 處理量較小時,委派給 GPU 本身的往返成本可能超過 CPU 執行,
加上 [fast] 反而可能更慢。
- 腳本範例 -
+1 -1
ファイルの表示
@@ -261,7 +261,7 @@ AviUtl のアニメーション効果スクリプト(`.anm` 系)のうち、
- **パイプ**: `x |> f`(`f((x))`。左辺を第 1 引数に渡す)、`x |> clamp(0, 255)`(`clamp((x), 0, 255)`)
- **補間文字列**: `` `x={a}` ``(`("x=" .. tostring(a))`。`{ }` の中に式を書く。拡張構文も使える)
- **範囲判定**: `x in <1..5>`(`1 <= x and x <= 5`)、`<1..<5>`(上限を含まない)
- **高速化マーカー**(YMM4 独自拡張): `obj.fill` / `obj.convolve` / `obj.resize` は処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき自動で GPU へ委譲する。`[fast]` は委譲の意図を明示する補助マーカーで、呼び出しの直前(単独行でも同一行でも可)に置ける。動作は変わらない。文の先頭でのみ働くため `t[fast]` のような添字アクセスには影響しない
- **高速化マーカー**(YMM4 独自拡張): `obj.fill` / `obj.convolve` / `obj.resize` は処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき自動で GPU へ委譲する。呼び出しの直前(単独行でも同一行でも可)に `[fast]` を置くと、このしきい値を無視して強制的に GPU へ委譲する。GPU が使えない環境や GPU の結果が CPU と一致しない環境では、`[fast]` を付けても CPU へ自動的に戻る。処理量が小さいときは GPU への委譲自体の往復コストが CPU 実行を上回ることがあり、`[fast]` を付けるとかえって遅くなる場合がある。文の先頭でのみ働くため `t[fast]` のような添字アクセスには影響しない
各記法の詳しい説明と例はドキュメント(`LuaScript/docs`)およびサイトの「構文拡張」を参照してください。
+1 -1
ファイルの表示
@@ -383,7 +383,7 @@ obj.convolve({ -1,-1,-1, -1,8,-1, -1,-1,-1 }, 3, 1, 0) -- 輪郭抽出</code></
</p>
<p>
<code>obj.fill</code>・<code>obj.convolve</code>・<code>obj.resize</code> は、処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲します。呼び出しの直前(単独行でも同一行でも可)に <code>[fast]</code> を置くと委譲の意図を明示できます(動作は変わりません)。詳細は <a href="syntax.html">拡張構文</a> を参照してください。
<code>obj.fill</code>・<code>obj.convolve</code>・<code>obj.resize</code> は、処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲します。呼び出しの直前(単独行でも同一行でも可)に <code>[fast]</code> を置くと、このしきい値を無視して強制的に GPU へ委譲します。GPU が使えない環境や GPU の結果が CPU と一致しない環境では、<code>[fast]</code> を付けても CPU へ自動的に戻ります。処理量が小さいときは、GPU への委譲自体の往復コストが CPU 実行を上回ることがあり、<code>[fast]</code> を付けるとかえって遅くなる場合があります。詳細は <a href="syntax.html">拡張構文</a> を参照してください。
</p>
<h3>アンカーポイント</h3>
+5 -5
ファイルの表示
@@ -252,17 +252,17 @@ end</code></pre>
<h2>[fast] 高速化マーカー</h2>
<p>
<code>obj.fill</code> <code>obj.convolve</code> <code>obj.resize</code> は、処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲します。<code>[fast]</code> は委譲の意図を明示する補助マーカーで、置いても動作は変わりません。<strong>YMM4 独自拡張</strong>です。
<code>obj.fill</code> <code>obj.convolve</code> <code>obj.resize</code> は、処理量がしきい値以上で GPU の結果が CPU と一致すると確認できたとき、自動で GPU へ委譲します。<code>[fast]</code> を付けると、このしきい値を無視して強制的に GPU へ委譲します。<strong>YMM4 独自拡張</strong>です。
</p>
<table>
<tr><th>書き方</th><th>意味</th></tr>
<tr><td><code>[fast]</code> の次の行に <code>obj.convolve(k, 5)</code></td><td>GPU への委譲を明示する(動作は下と同じ)</td></tr>
<tr><td><code>obj.convolve(k, 5)</code></td><td>自動で GPU / CPU を判定する</td></tr>
<tr><td><code>[fast]</code> の次の行に <code>obj.convolve(k, 5)</code></td><td>しきい値を無視して GPU へ委譲を強制する</td></tr>
<tr><td><code>obj.convolve(k, 5)</code></td><td>処理量に応じて自動で GPU / CPU を判定する</td></tr>
</table>
<p>
マーカーは単独の行に置いても、同じ行に続けて書いても構いません。処理が小さいときや GPU が使えないときは自動で CPU 実行になります。
マーカーは単独の行に置いても、同じ行に続けて書いても構いません。GPU が使えない環境や GPU の結果が CPU と一致しない環境では、<code>[fast]</code> を付けても自動で CPU 実行に戻ります。
</p>
<pre><code>--track@size:Size,1,15,3,2
@@ -274,7 +274,7 @@ for i = 1, n * n do k[i] = 1 end
obj.convolve(k, n)</code></pre>
<div class="note">
文の先頭でのみマーカーとして働くため、<code>t[fast]</code> のような添字アクセスは変換しません。<code>[fast]</code> を付けた対象が上記 3 関数以外のときはエラーを表示します。従来エンジンと高速ランタイムの両方で動作します。
文の先頭でのみマーカーとして働くため、<code>t[fast]</code> のような添字アクセスは変換しません。<code>[fast]</code> を付けた対象が上記 3 関数以外のときはエラーを表示します。GPU 側の検証(ハードウェア対応と CPU との一致確認)は変わらず行われるため、結果が変わることはありません。従来エンジンと高速ランタイムの両方で動作します。処理量が小さいときは、GPU への委譲自体の往復コストが CPU 実行を上回ることがあり、<code>[fast]</code> を付けるとかえって遅くなる場合があります。
</div>
<div class="pager">
+22 -19
ファイルの表示
@@ -160,9 +160,10 @@ local function flushDraws()
k32.WaitForSingleObject(workEvent, INFINITE)
end
local function tryPixelProcess(kind)
local function tryPixelProcess(kind, force)
if not pixelProcessAvailable then return false end
cbResult[0] = kind
cbResult[9] = force and 1 or 0
i32[OFF_CB_FOUND] = 0
i32[OFF_CB_KIND] = CB_KIND_PIXELPROCESS
i32[OFF_STATUS] = STATUS_CALLBACK
@@ -864,7 +865,7 @@ function obj.copybuffer(dst, src)
end
end
local function fillImpl(r, g, b, a, x, y, w, h)
local function fillImpl(force, r, g, b, a, x, y, w, h)
ensurePixels()
flushPixelData()
r = r or 0; g = g or 0; b = b or 0; a = a or 255
@@ -878,11 +879,13 @@ local function fillImpl(r, g, b, a, x, y, w, h)
local imageArea = width * height
local fillArea = (x1 - x0) * (y1 - y0)
local fullFill = x0 == 0 and y0 == 0 and x1 == width and y1 == height
local usePixelProcess = false
if fullFill then
usePixelProcess = imageArea >= PIXEL_PROCESS_FILL_FULL_THRESHOLD
else
usePixelProcess = imageArea >= PIXEL_PROCESS_FILL_PARTIAL_THRESHOLD and fillArea * 4 >= imageArea * 3
local usePixelProcess = force
if not usePixelProcess then
if fullFill then
usePixelProcess = imageArea >= PIXEL_PROCESS_FILL_FULL_THRESHOLD
else
usePixelProcess = imageArea >= PIXEL_PROCESS_FILL_PARTIAL_THRESHOLD and fillArea * 4 >= imageArea * 3
end
end
cbResult[1] = r
cbResult[2] = g
@@ -892,7 +895,7 @@ local function fillImpl(r, g, b, a, x, y, w, h)
cbResult[6] = y0
cbResult[7] = x1 - x0
cbResult[8] = y1 - y0
if usePixelProcess and tryPixelProcess(PIXEL_PROCESS_FILL) then
if usePixelProcess and tryPixelProcess(PIXEL_PROCESS_FILL, force) then
dirty = true
pdValid = false
pdDirty = false
@@ -913,8 +916,8 @@ local function fillImpl(r, g, b, a, x, y, w, h)
pdValid = false
end
obj.fill = fillImpl
__fast_fill = fillImpl
function obj.fill(r, g, b, a, x, y, w, h) fillImpl(false, r, g, b, a, x, y, w, h) end
function __fast_fill(r, g, b, a, x, y, w, h) fillImpl(true, r, g, b, a, x, y, w, h) end
function obj.getpixelregion(x, y, w, h)
x = math.floor(x or 0); y = math.floor(y or 0)
@@ -977,7 +980,7 @@ function obj.putpixelregion(x, y, w, h, data)
pdValid = false
end
local function convolveImpl(kernel, size, divisor, offset)
local function convolveImpl(force, kernel, size, divisor, offset)
if type(kernel) ~= "table" then return end
size = math.floor(size or 0)
if size < 1 or size % 2 == 0 then return end
@@ -994,7 +997,7 @@ local function convolveImpl(kernel, size, divisor, offset)
local inv = divisor or sum
if inv == 0 then inv = 1 end
offset = offset or 0
if taps * 8 <= CB_TAG_MAX and width * height * taps >= PIXEL_PROCESS_CONVOLVE_WORK_THRESHOLD then
if taps * 8 <= CB_TAG_MAX and (force or width * height * taps >= PIXEL_PROCESS_CONVOLVE_WORK_THRESHOLD) then
cbResult[1] = size
cbResult[2] = inv
cbResult[3] = offset
@@ -1002,7 +1005,7 @@ local function convolveImpl(kernel, size, divisor, offset)
cbTagD[i - 1] = k[i]
end
i32[OFF_CB_TAGLEN] = taps * 8
if tryPixelProcess(PIXEL_PROCESS_CONVOLVE) then
if tryPixelProcess(PIXEL_PROCESS_CONVOLVE, force) then
dirty = true
pdValid = false
pdDirty = false
@@ -1061,10 +1064,10 @@ local function convolveImpl(kernel, size, divisor, offset)
pdValid = false
end
obj.convolve = convolveImpl
__fast_convolve = convolveImpl
function obj.convolve(kernel, size, divisor, offset) convolveImpl(false, kernel, size, divisor, offset) end
function __fast_convolve(kernel, size, divisor, offset) convolveImpl(true, kernel, size, divisor, offset) end
local function resizeImpl(newW, newH, mode)
local function resizeImpl(force, newW, newH, mode)
newW = math.floor(newW or 0); newH = math.floor(newH or 0)
if newW < 1 then newW = 1 end
if newH < 1 then newH = 1 end
@@ -1077,7 +1080,7 @@ local function resizeImpl(newW, newH, mode)
cbResult[1] = newW
cbResult[2] = newH
cbResult[3] = linear and 1 or 0
if newW * newH >= PIXEL_PROCESS_RESIZE_THRESHOLD and tryPixelProcess(PIXEL_PROCESS_RESIZE) then
if (force or newW * newH >= PIXEL_PROCESS_RESIZE_THRESHOLD) and tryPixelProcess(PIXEL_PROCESS_RESIZE, force) then
width = newW; height = newH
i32[OFF_WIDTH] = newW; i32[OFF_HEIGHT] = newH
dirty = true
@@ -1142,8 +1145,8 @@ local function resizeImpl(newW, newH, mode)
obj.diagonal = math.sqrt(newW * newW + newH * newH)
end
obj.resize = resizeImpl
__fast_resize = resizeImpl
function obj.resize(newW, newH, mode) resizeImpl(false, newW, newH, mode) end
function __fast_resize(newW, newH, mode) resizeImpl(true, newW, newH, mode) end
local SCENE_VALUE_MAX = 4095
local SCENE_NIL = {}