コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
15e0cccdcc
|
||
|
|
b07d5b8937
|
||
|
|
bfc35b3931
|
||
|
|
a2531d96e8
|
||
|
|
4f54851fc5
|
||
|
|
fcb5c87637
|
||
|
|
82ae3e3acd
|
||
|
|
b9e57ffd66
|
||
|
|
c7415baf1b
|
||
|
|
c85592277e
|
||
|
|
0d8e5124a0
|
||
|
|
086557db7f
|
||
|
|
c69f796293
|
||
|
|
1df66b5c28
|
||
|
|
77fca5223a
|
検索条件に一致するファイルはありません
+40
-172
@@ -1,195 +1,63 @@
|
||||
# v1.0.0 - 浮世絵 for YMM4
|
||||
# v1.0.1 - 浮世絵 for YMM4
|
||||
|
||||
YukkuriMovieMaker4向けの浮世絵エフェクトプラグインの初回リリースです。
|
||||
素材を多色木版画の原画とみなし、Kang・Lee・Chuiの「Coherent Line Drawing」(NPAR 2007)のエッジ接線流と流れに沿った差分ガウスで輪郭主線を求め、Bi・Han・Yuの「An L1 Image Transform for Edge-Preserving Smoothing and Scene-Level Intrinsic Decomposition」(SIGGRAPH 2015)のL1局所平坦化で地色を均し、Winnemöllerらの「Real-Time Video Abstraction」(SIGGRAPH 2006)の軟量子化で限定パレットへ寄せ、和紙の繊維とばれん目と版ずれを重ねて刷り上げます。
|
||||
和紙の繊維とばれん目と版ずれの形はシードから決定論的に決まり、同じ設定では常に同じ絵になります。
|
||||
計算はComputeSharpの計算シェーダーがDirect3D 12で実行し、YMM4のDirect3D 11側とは共有テクスチャおよび共有フェンスで接続します。
|
||||
8言語のリソース構成のUIを備えます。
|
||||
浮世絵エフェクトプラグインの改善リリースです。
|
||||
L1平坦化の反復で近傍セルの読み取りをグループ共有メモリへ移し、地色の計算を高速化しました。
|
||||
高品質の1フレームあたりの処理時間は297.8msから177.3msへ短縮しました。
|
||||
この変更は浮動小数点の丸めが変わるため、出力がv1.0.0と完全には一致しません。根拠と影響の範囲は「3. 等価性について」に記載します。
|
||||
|
||||
---
|
||||
|
||||
## 新機能
|
||||
## 改善
|
||||
|
||||
### 1. 浮世絵の計算パイプライン
|
||||
### 1. 平坦化反復のグループ共有メモリによるタイル化
|
||||
|
||||
`UkiyoePipeline`は、シルエット、構造、描画の3段階の計算シェーダーを`ComputeContext`へ記録して実行します。処理格子のバッファーは計算領域の大きさと品質に応じて確保し、サイズが変わらないフレームでは再利用します。処理の流れは次のとおりです。
|
||||
L1平坦化の各反復は、1セルにつき近傍24セルの元の色と勾配強度と反復値を読み取ります。隣り合うセルは読み取る範囲が重なるため、同じ値を何度も大域メモリから取得していました。8×8のスレッドグループごとに12×12セルの領域をグループ共有メモリへ一度だけ読み込み、以降の近傍参照をすべて共有メモリから行うようにしました。
|
||||
|
||||
1. `SilhouetteShader`が、各格子セルに対応する画素の色とアルファ値の平均を調べ、直色と白地の輝度を記録します。
|
||||
2. `GradientShader`が、輝度のソーベル勾配から接線場の初期値と勾配強度を求めます。
|
||||
3. `EtfShader`が、エッジ接線流の非線形ベクトル平滑化を反復します。
|
||||
4. `FlattenShader`が、L1局所平坦化の反復重み付き最小二乗を反復し、色面を均します。
|
||||
5. `DogShader`と`FlowAccumulateShader`が、勾配方向の1次元差分ガウスと流線方向の集計で主線の応答を求め、`SuperimposeShader`が黒画素を重ねて反復します。
|
||||
6. `RenderShader`が、画素ごとに平坦化色を軟量子化し、版ずれ、ばれん目、和紙の繊維、主線を合成して出力します。
|
||||
- 1セルあたりの大域メモリの読み取りは、色と勾配強度と反復値の3種類で最大75回から、グループ内で分担した約7回へ減りました。
|
||||
- 近傍の加算の順序と各項の値は変更していません。変わるのは値を読み出す記憶域の種類だけです。
|
||||
- グループ共有メモリを使うシェーダーは、グループ内のすべてのスレッドが同期に到達する必要があります。ComputeWeaveが生成するシェーダーの入口は`For`へ渡した反復数を上限としてスレッドを間引くため、処理格子の寸法のままディスパッチすると最終グループの一部のスレッドが同期に到達しません。平坦化のディスパッチ範囲は8の倍数へ切り上げています。切り上げで増えたスレッドは格子の範囲外として何も書き込みません。
|
||||
|
||||
| シェーダー | 役割 |
|
||||
|---|---|
|
||||
| `SilhouetteShader` | 画素の色とアルファ値から直色と輝度を求める |
|
||||
| `MaskHashShader` | 素材のハッシュと境界を集計する |
|
||||
| `GradientShader` | ソーベル勾配と接線場の初期値を求める |
|
||||
| `EtfShader` | エッジ接線流を平滑化する |
|
||||
| `FlattenShader` | L1平坦化の1反復を解く |
|
||||
| `CopyColorShader` | 平坦化の反復初期値を用意する |
|
||||
| `DogShader` | 勾配方向の差分ガウスを求める |
|
||||
| `FlowAccumulateShader` | 流線に沿って応答を集計する |
|
||||
| `SuperimposeShader` | 主線を輝度へ重ねて反復する |
|
||||
| `RenderShader` | 版画を描画する |
|
||||
### 2. 性能
|
||||
|
||||
### 2. エッジ接線流と流れに沿った差分ガウス
|
||||
1280×720の素材、検証ハーネス、Releaseビルドによる実測値です。GPUはIntel Iris Xe Graphicsです。1回の実行で10フレームを処理した最小値を取り、新旧のバイナリを交互に3回ずつ実行した最小値を記載します。この環境は実行ごとの変動が大きいため、交互実行で熱状態の影響をそろえています。
|
||||
|
||||
輪郭主線は、Kang・Lee・Chuiの論文「Coherent Line Drawing」(NPAR 2007)に基づきます。
|
||||
| 項目 | v1.0.0 | v1.0.1 |
|
||||
|---|---:|---:|
|
||||
| 標準品質の1フレーム | 115.4ms | 70.2ms |
|
||||
| 高品質の1フレーム | 297.8ms | 177.3ms |
|
||||
| 最高品質の1フレーム | 452.9ms | 256.3ms |
|
||||
| 高品質の構造の再計算 | 311.6ms | 168.6ms |
|
||||
| キャッシュが効いたフレーム | 2.73ms | 2.18ms |
|
||||
|
||||
- エッジ接線流は、論文の式1〜5の核関数に基づく非線形ベクトル平滑化です。空間重みは半径5セルの円盤、強度重みは`(1 + tanh(ĝ(y) − ĝ(x))) / 2`、方向重みは`|t(x)・t(y)|`で、逆向きの接線は符号を反転してから加えます。勾配強度が最大値の2%を下回るセルは方向なしとして扱い、近傍の有意な接線の構造テンソルの主固有ベクトルで充填します。この充填により、素材の内部に境界と直交する緩い勾配があっても、シルエット境界の1〜2セル内側の接線が境界へ沿い、輪郭主線が途切れません。
|
||||
- 差分ガウスは論文の式6〜9を2パスへ分離して求めます。第1パスは各セルの勾配方向へ1次元の`G_σc − 0.99・G_σs`(`σs = 1.6σc`)を畳み込み、第2パスは接線流の流線を両方向へ`⌈2σm⌉`ステップ辿り、`G_σm`の重みで応答を集計します。この分離は流線上の各点の応答を再利用する近似で、Kyprianidisらが実時間実装で用いた構成です。
|
||||
- 二値化は式10の`1 + tanh(gain・H) < τ`で行い、描画では同じ式の連続値を幅0.1の軟しきい値として使い、主線の縁を滑らかにします。
|
||||
- 論文3.2節の反復適用を行い、前回の主線の黒画素を輝度へ重ねてから再度差分ガウスを適用します。エッジ接線流は反復中に更新しません。
|
||||
キャッシュが効いたフレームは平坦化を実行しないため、この行の差は環境の変動によるものです。
|
||||
|
||||
線の太さは中心ガウスの幅`σc`を0.6〜3.0画素、線の流れは流線ガウスの幅`σm`を1〜6セル、線の量はしきい値`τ`を0.1〜0.95へ割り当てます。
|
||||
### 3. 等価性について
|
||||
|
||||
### 3. L1局所平坦化による地色の色面
|
||||
検証ハーネスの`--golden`引数で、品質2段階、シード変更、平坦化の両極、色数2、版ずれ最大、太い主線の8条件について、出力全画素のSHA-256をv1.0.0と比較しました。8条件のうち7条件でハッシュが変わります。平坦化を行わない条件だけが一致します。
|
||||
|
||||
地色は、Bi・Han・Yuの論文「An L1 Image Transform for Edge-Preserving Smoothing and Scene-Level Intrinsic Decomposition」(SIGGRAPH 2015)の局所平坦化項(式2)と画像近似項(式7)のエネルギーを最小化して均します。親和度は平滑化用の式9に従い、輝度を0.3倍へ抑えた色特徴の距離と、隣接セルの勾配の最大値の`η = 0.4`倍の大きいほうを使います。大域疎性項は論文の平滑化の節の記述どおり使用しません。
|
||||
近傍の加算順序と各項の値を変更していないにもかかわらず出力が変わるのは、HLSLコンパイラーが乗算と加算の融合を、グループ共有メモリからの読み取りと大域バッファーからの読み取りとで別々に判断するためです。融合の有無で丸めが1回分変わり、その差が反復の回数だけ積み重なった後、描画の軟量子化のしきい値で可視化されます。差は色の階調1段に満たない範囲にとどまり、絵柄と形状は変わりません。
|
||||
|
||||
論文のSplit-Bregman法による大域の疎行列解法の代わりに、L1項を反復重み付き最小二乗として前向きに解きます。各反復は、近傍24セルについて重み`w_ij / max(|x_i − x_j|_1, ε)`を現在の反復値から求め、`x_i = (β・in_i + Σ w・x_j) / (β + Σ w)`のヤコビ更新を2枚のバッファーで交互に行います。更新は順序に依存しないため、GPU上で決定論的です。分解や推定を伴わない前向きの区分平坦化であり、常に均質な色面が得られます。平坦化のパラメータはデータ項の重み`β`を10⁵〜1の対数尺度で割り当てます。
|
||||
決定論は保たれています。同じ入力からは常に同じ出力が得られることを、テストの同一入力2回の全画素一致で確認しています。テスト34件の成功とビルド警告0も確認しています。
|
||||
|
||||
### 4. 限定パレットと版ずれ・ばれん目・和紙
|
||||
### 4. 効果がなく採用しなかった削減
|
||||
|
||||
描画は`RenderShader`が画素ごとに行います。
|
||||
本リリースの作業では、平坦化のタイル化のほかに6つの削減を実装して測定しました。いずれも性能が改善しないため採用していません。同じ試みを繰り返さないように記録します。測定はすべて1280×720と2560×1440で新旧のバイナリを交互に実行し、10フレームの最小値で比較しました。
|
||||
|
||||
- 階調化は、Winnemöllerらの「Real-Time Video Abstraction」(SIGGRAPH 2006)の輝度の軟量子化に基づきます。プラトーが階調の中心に来るように正規化した遷移幅0.18の軟階段で、暗さを色数の段数へ量子化します。彩度は平坦化とスケール0.9で整え、量子化しません。
|
||||
- 版ずれは、階調の層ごとにシードから決めた方向へ最大10画素まで刷り位置をずらします。各画素で自身より暗い層のずらした標本を調べ、最も暗い層の色を採用するため、階調の境界に多色刷りの見当ずれの色縁が出ます。
|
||||
- ばれん目は、セルごとに中心をずらした同心円模様を低周波の斑と掛け合わせ、中間調の暗さをわずかに明るくします。
|
||||
- 和紙は、3オクターブの値ノイズの繊維場で暗さと主線を削り、かすれを作ります。
|
||||
| 試みた削減 | 内容 | 等価性 | 測定結果 |
|
||||
|---|---|---|---|
|
||||
| 素材ハッシュのグループ内集約 | 大域アトミック演算をグループ内で集約してから1回だけ反映する | 保たれる | 改善なし |
|
||||
| 主線の正規化係数のグループ内共有 | ガウス重みの総和をグループの先頭スレッドが一度だけ求める | 保たれる | 改善なし |
|
||||
| 平坦化の初期コピーの削減 | 元の色のバッファーを直接反復の初期値にしてディスパッチ1回を省く | 保たれる | 改善なし |
|
||||
| 意匠が無効なときの模様計算の省略 | 和紙とばれん目が0%のときに繊維場と同心円模様を計算しない | 保たれる | 改善なし |
|
||||
| エッジ接線流のタイル化 | 半径5セルの近傍参照をグループ共有メモリへ移す | 失われる | 改善なし |
|
||||
| 特徴量と正規化勾配の事前計算 | 平坦化の反復で不変な値を専用バッファーへ一度だけ書き出す | 失われる | 測定せず |
|
||||
|
||||
すべての模様はシードと画素位置のハッシュから決定論的に生成し、乱数と時間値を使用しません。出力はプリマルチプライドアルファで、各チャンネルをアルファ以下へクランプします。
|
||||
前半の4つは、ゴールデン8条件のハッシュが一致する完全な等価変更です。演算量と大域メモリの通信量は確かに減りますが、1280×720と2560×1440のどちらでも処理時間は変わらず、グループ同期を追加する2つはむしろ2%から15%遅くなりました。削減した演算量よりも、追加した同期と先頭スレッドへの集約による並列度の低下が上回るためです。
|
||||
|
||||
### 5. 可視範囲への出力矩形の最小化
|
||||
エッジ接線流のタイル化は、平坦化と同じ手法でありながら効果がありません。平坦化の反復が24回から64回であるのに対して、エッジ接線流は2回から3回しかなく、タイルの読み込み費用がその回数では償却されないためです。加えて近傍参照は円形の範囲に限られ、勾配強度が下限を下回るセルは早期に飛ばすため、読み込んだタイルの多くを使いません。
|
||||
|
||||
シルエットの集計時に、アルファ値を持つセルの境界を`InterlockedMin`と`InterlockedMax`で求め、8個の整数の読み戻しに含めます。表示矩形は素材の境界に主線の到達範囲と版ずれと余白を加えた大きさで、4画素境界へそろえます。出力テクスチャは矩形の大きさで確保し、Direct2Dの`Crop`と`AffineTransform2D`で元の位置へ合成します。画素の読み戻しは行いません。
|
||||
特徴量と正規化勾配の事前計算は、ゴールデンのハッシュが変わった時点で採用の対象から外したため、性能を測定していません。
|
||||
|
||||
### 6. 構造キャッシュ
|
||||
### 5. ハーネスの測定手法の改善
|
||||
|
||||
輪郭と色面を決める入力が変わらないフレームでは、構造の計算を再利用します。
|
||||
|
||||
- 素材は、セル位置と量子化した色とアルファ値のハッシュの総和とXORの2値へ集約し、8個の整数の読み戻しで前フレームと比較します。
|
||||
- 素材のハッシュ、計算領域の大きさ、品質、線の太さ、線の流れ、線の量、平坦化が一致する場合は、構造段階を実行しません。
|
||||
- 構造が同じで、色数、版ずれ、ばれん目、和紙、線の濃さ、主線色、シード、出力矩形も変わらないフレームでは、描画段階も実行せず、前フレームの出力テクスチャを使用します。
|
||||
|
||||
### 7. Direct3D 11・Direct3D 12相互運用
|
||||
|
||||
`UkiyoeGpuInterop`は、YMM4のDirect3D 11・Direct2D側と、ComputeSharpのDirect3D 12側を接続します。ComputeSharpの`GraphicsDevice`は、YMM4が使うDXGIアダプターのLUIDと一致するものを選びます。
|
||||
|
||||
入力と出力は、ComputeSharpで確保した共有テクスチャをDirect3D 11のテクスチャとして開き、Direct2Dのビットマップとして扱います。両デバイスの同期は、Direct3D 12のフェンスを共有フェンスとしてDirect3D 11側で開いて行います。`BeginCompute`は、Direct3D 11のコマンドを送出したうえでDirect3D 12側を待機させ、`EndCompute`は、Direct3D 12側の完了をDirect3D 11側で待ちます。
|
||||
|
||||
Direct3D 12デバイスの取得や共有リソースの作成に失敗した場合は、`TryCreate`が`null`を返し、エフェクトを適用せず入力映像を表示します。
|
||||
|
||||
### 8. カスタムシェーダーによる合成
|
||||
|
||||
`UkiyoeCustomEffect`は、`[CustomEffect(2)]`の2入力エフェクトです。入力0は元映像、入力1は描画した版画です。ピクセルシェーダー`Ukiyoe.hlsl`の`main`は、`amount`が0以下のとき元映像をそのまま返し、そうでないときは版画のRGBをアルファでクランプし、`lerp(source, print, amount)`で元映像と混合します。版画の濃淡と模様は描画段階で画素へ焼き込むため、合成は単純な混合です。
|
||||
|
||||
定数バッファーは`Amount`と3つの詰め物で16バイトです。`MapInputRectsToOutputRect`は2つの入力矩形の和集合を出力矩形とします。主線と版ずれは素材の外側へわずかに広がるため、出力範囲は素材より大きくなります。
|
||||
|
||||
シェーダーリソース: `pack://application:,,,/Ukiyoe;component/Shaders/Ukiyoe.cso`(ps_5_0、`ShaderResourceUri.Get`が生成)
|
||||
|
||||
### 9. エフェクト定義とパラメータ
|
||||
|
||||
`UkiyoeEffect`は、YMM4の映像エフェクトとして宣言されます。
|
||||
|
||||
`[VideoEffect]`属性は以下のパラメーターで宣言されます。
|
||||
|
||||
- 表示名: `Texts.Ukiyoe`(ローカライズキー、日本語では「浮世絵」)
|
||||
- カテゴリー: `VideoEffectCategories.Filtering`・`VideoEffectCategories.Decoration`
|
||||
- 検索タグ: `TagWoodblock`・`TagPrint`・`TagJapanese`
|
||||
- `IsAviUtlSupported = false`によりAviUtl向けEXO出力は非対応
|
||||
- `ResourceType = typeof(Texts)`でローカライズリソースを指定
|
||||
|
||||
公開プロパティは以下のとおりです。基本項目は「基本」グループ、主線項目は「主線」グループ、色面項目は「色面」グループ、意匠項目は「意匠」グループに属します。
|
||||
|
||||
| プロパティ | 型 | デフォルト | 内部範囲 | アニメーション |
|
||||
|---|---|---|---|---|
|
||||
| `Amount` | `Animation` | 100 | 0〜100 | あり |
|
||||
| `Quality` | `UkiyoeQuality` | `High` | — | なし |
|
||||
| `LineWidth` | `Animation` | 50 | 0〜100 | あり |
|
||||
| `Coherence` | `Animation` | 50 | 0〜100 | あり |
|
||||
| `LineDetail` | `Animation` | 50 | 0〜100 | あり |
|
||||
| `LineStrength` | `Animation` | 85 | 0〜100 | あり |
|
||||
| `LineColor` | `Color` | #FF1E1A18 | — | なし |
|
||||
| `Flatten` | `Animation` | 60 | 0〜100 | あり |
|
||||
| `PaletteLevels` | `int` | 6 | 2〜16 | なし |
|
||||
| `Misregistration` | `Animation` | 30 | 0〜100 | あり |
|
||||
| `Baren` | `Animation` | 40 | 0〜100 | あり |
|
||||
| `Paper` | `Animation` | 50 | 0〜100 | あり |
|
||||
| `Seed` | `int` | 0 | 0〜int.MaxValue | なし |
|
||||
|
||||
`GetAnimatables`は`Amount`・`LineWidth`・`Coherence`・`LineDetail`・`LineStrength`・`Flatten`・`Misregistration`・`Baren`・`Paper`を返します。`Seed`は負値を代入すると0へ丸め、`PaletteLevels`は2〜16へ丸めます。
|
||||
|
||||
`CreateExoVideoFilters`は空のシーケンスを返します(EXO非対応)。`CreateVideoEffect`は映像処理用のインスタンスを生成します。エフェクトを最初に生成したときに、更新確認を一度だけ開始します。
|
||||
|
||||
### 10. フレームごとの更新
|
||||
|
||||
各フレームでYMM4の`EffectDescription`からフレーム位置、アイテム長、FPSを取得し、アニメーション値を評価します。値をパイプラインが前提とする範囲へ制限してから転送します。
|
||||
|
||||
| パラメータ | 変換 |
|
||||
|---|---|
|
||||
| `Amount` | `value / 100` をカスタムシェーダーの`Amount`へ |
|
||||
| `LineWidth` | `value / 100` を0〜1へクランプし、中心ガウスの幅0.6〜3.0画素へ |
|
||||
| `Coherence` | `value / 100` を0〜1へクランプし、流線ガウスの幅1〜6セルへ |
|
||||
| `LineDetail` | `value / 100` を0〜1へクランプし、二値化のしきい値0.1〜0.95へ |
|
||||
| `LineStrength` | `value / 100` を0〜1へクランプ |
|
||||
| `Flatten` | `value / 100` を0〜1へクランプし、データ項の重み10⁵〜1へ |
|
||||
| `PaletteLevels` | 2〜16へクランプ |
|
||||
| `Misregistration` | `value / 100` を0〜1へクランプし、刷りずれ0〜10画素へ |
|
||||
| `Baren` | `value / 100` を0〜1へクランプ |
|
||||
| `Paper` | `value / 100` を0〜1へクランプ |
|
||||
| `LineColor` | RGB各成分を0〜1へ |
|
||||
| `Seed` | 0以上へクランプ |
|
||||
|
||||
強さが0以下のときは入力映像をそのまま出力します。入力の範囲が有限でない場合や、計算領域の余白を確保できない場合も、入力映像を表示します。
|
||||
|
||||
### 11. 品質設定
|
||||
|
||||
品質は、処理格子の解像度と各段階の反復回数をまとめて切り替えます。
|
||||
|
||||
| 品質 | 格子解像度 | 接線流反復 | 主線反復 | 平坦化反復 |
|
||||
|---|---:|---:|---:|---:|
|
||||
| 標準 | 1024 | 2回 | 2回 | 24回 |
|
||||
| 高品質 | 1440 | 3回 | 2回 | 40回 |
|
||||
| 最高品質 | 2048 | 3回 | 3回 | 64回 |
|
||||
|
||||
格子解像度は計算領域の長辺のセル数です。短辺のセル数は計算領域の縦横比に合わせ、最小4セルとします。
|
||||
|
||||
### 12. ローカライズ
|
||||
|
||||
`Texts`クラスは`[AutoGenLocalizer]`属性を持つ`partial`クラスとして宣言されます。
|
||||
`YukkuriMovieMaker.Generator`のソースジェネレーターが`Texts.csv`を処理し、各ロケールのリソースファイルを自動生成します。
|
||||
|
||||
対応リソース: 日本語(`ja-jp`)・英語(`en-us`)・中国語簡体字(`zh-cn`)・中国語繁体字(`zh-tw`)・韓国語(`ko-kr`)・スペイン語(`es-es`)・アラビア語(`ar-sa`)・インドネシア語(`id-id`)
|
||||
|
||||
主なローカライズキーは以下のとおりです。
|
||||
|
||||
| キー | ja-jp |
|
||||
|---|---|
|
||||
| `Ukiyoe` | 浮世絵 |
|
||||
| `BasicGroup` | 基本 |
|
||||
| `LineGroup` | 主線 |
|
||||
| `ColorGroup` | 色面 |
|
||||
| `CraftGroup` | 意匠 |
|
||||
| `Amount` | 強さ |
|
||||
| `Quality` | 品質 |
|
||||
| `LineWidth` | 線の太さ |
|
||||
| `Coherence` | 線の流れ |
|
||||
| `LineDetail` | 線の量 |
|
||||
| `LineStrength` | 線の濃さ |
|
||||
| `LineColor` | 主線色 |
|
||||
| `Flatten` | 平坦化 |
|
||||
| `PaletteLevels` | 色数 |
|
||||
| `Misregistration` | 版ずれ |
|
||||
| `Baren` | ばれん目 |
|
||||
| `Paper` | 和紙 |
|
||||
| `Seed` | シード |
|
||||
| `QualityBalanced` | 標準 |
|
||||
| `QualityHigh` | 高品質 |
|
||||
| `QualityUltra` | 最高品質 |
|
||||
| `TagWoodblock` | 木版画 |
|
||||
| `TagPrint` | 版画 |
|
||||
| `TagJapanese` | 和風 |
|
||||
| `UpdateAvailableMessage` | 新しいバージョン {0} が公開されています。 |
|
||||
検証ハーネスの1フレームの測定を、5フレームの平均から10フレームの最小値へ変更しました。構造の再計算の測定も、パラメータを交互に切り替えてGPUの完了待ちを含む12回の最小値へ変更しました。前バージョンの平均値による測定は、GPUのクロック状態の変動と初回のシェーダー構築の影響を受けており、同一のバイナリでも実行ごとに2倍以上ばらつくことがありました。本リリースの性能表は新旧両方のバイナリをこの方法で測定した値です。
|
||||
@@ -1,5 +1,5 @@
|
||||
========================================
|
||||
浮世絵 for YMM4 v1.0.0
|
||||
浮世絵 for YMM4 v1.0.1
|
||||
========================================
|
||||
YukkuriMovieMaker4上で動作する、素材を浮世絵の多色木版画とみなして
|
||||
描画する映像エフェクトプラグインです。
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: リリース
|
||||
name: リリース
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -126,9 +126,7 @@ jobs:
|
||||
New-Item -ItemType Directory -Path $stageRoot -Force | Out-Null
|
||||
New-Item -ItemType Directory -Path "$stageRoot/LICENSE" -Force | Out-Null
|
||||
|
||||
Copy-Item "$outDir/Ukiyoe.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/Ukiyoe.ComputeSharp.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/Ukiyoe.ComputeSharp.Core.dll" "$stageRoot/"
|
||||
Copy-Item "$outDir/plugin/Ukiyoe.dll" "$stageRoot/"
|
||||
|
||||
foreach ($lang in @("ar-sa", "en-us", "es-es", "id-id", "ko-kr", "zh-cn", "zh-tw")) {
|
||||
$src = "$outDir/$lang"
|
||||
|
||||
+1
-4
@@ -1,9 +1,6 @@
|
||||
[submodule "YukkuriMovieMaker.Generator"]
|
||||
[submodule "YukkuriMovieMaker.Generator"]
|
||||
path = YukkuriMovieMaker.Generator
|
||||
url = https://github.com/manju-summoner/YukkuriMovieMaker.Generator.git
|
||||
[submodule "YMM4-GitHubUpdateNotifier"]
|
||||
path = YMM4-GitHubUpdateNotifier
|
||||
url = https://github.com/routersys/YMM4-GitHubUpdateNotifier.git
|
||||
[submodule "ComputeSharp"]
|
||||
path = ComputeSharp
|
||||
url = https://github.com/routersys/ComputeSharp.git
|
||||
-1
サブモジュール ComputeSharp が 7c4145d5f2 から削除されました。
@@ -1,4 +1,4 @@
|
||||
# 浮世絵 for YMM4
|
||||
# 浮世絵 for YMM4
|
||||
|
||||
[](#)
|
||||
[](#)
|
||||
@@ -46,7 +46,7 @@ YukkuriMovieMaker4(YMM4)上で動作する、素材を多色木版画の原
|
||||
|
||||
入力された現在のフレームの色とアルファ値から素材の絵柄を求め、多色木版画の工程になぞらえて3つの層を刷り重ねます。主線の層は、Kang・Lee・Chuiの論文「Coherent Line Drawing」(NPAR 2007)に基づき、エッジ接線流の非線形ベクトル平滑化で絵柄の流れを求め、流れに直交する方向の差分ガウスを流線に沿って集計して、つながりの良い輪郭線を取り出します。色面の層は、Bi・Han・Yuの論文「An L1 Image Transform for Edge-Preserving Smoothing and Scene-Level Intrinsic Decomposition」(SIGGRAPH 2015)のL1局所平坦化を前向きの反復重み付き最小二乗として解き、細部を消しながら際を保った均質な色面を作り、Winnemöllerらの論文「Real-Time Video Abstraction」(SIGGRAPH 2006)の軟量子化で限定パレットの階調へ寄せます。意匠の層は、階調ごとの刷り位置のずれ、ばれんの擦り跡、和紙の繊維のかすれを決定論的なハッシュ模様として重ねます。
|
||||
|
||||
計算はComputeSharpの計算シェーダーがDirect3D 12で実行します。YMM4のDirect3D 11側とComputeSharpのDirect3D 12側は、共有テクスチャと共有フェンスで接続します。通常のフレーム処理では、CPUへの画素の読み戻しを行わず、8個の整数の読み戻しだけで素材の変化を判定します。素材が存在する最小の矩形の範囲だけを描画し、絵柄と構造のパラメータが変わらないフレームでは輪郭と平坦化の計算を再利用します。
|
||||
計算はComputeWeaveの計算シェーダーがDirect3D 12で実行します。YMM4のDirect3D 11側とComputeWeaveのDirect3D 12側は、共有テクスチャと共有フェンスで接続します。通常のフレーム処理では、CPUへの画素の読み戻しを行わず、8個の整数の読み戻しだけで素材の変化を判定します。素材が存在する最小の矩形の範囲だけを描画し、絵柄と構造のパラメータが変わらないフレームでは輪郭と平坦化の計算を再利用します。
|
||||
|
||||
このエフェクトはAviUtl向けのEXO出力には対応していません。
|
||||
|
||||
@@ -187,11 +187,11 @@ YukkuriMovieMaker4(YMM4)上で動作する、素材を多色木版画の原
|
||||
|
||||
## サードパーティライセンス
|
||||
|
||||
本プラグインは以下のサードパーティソフトウェアを同梱・使用しています。ライセンスの全文は、リポジトリの [`.github/LICENSE/ComputeSharp.txt`](.github/LICENSE/ComputeSharp.txt) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
||||
本プラグインは以下のサードパーティソフトウェアを同梱・使用しています。ライセンスの全文は、リポジトリの [`.github/LICENSE/ComputeWeave.txt`](.github/LICENSE/ComputeWeave.txt) と、配布パッケージの `LICENSE` フォルダーに収録しています。
|
||||
|
||||
| ソフトウェア | 用途 | ライセンス | 著作権表示 |
|
||||
|---|---|---|---|
|
||||
| [ComputeSharp](https://github.com/routersys/ComputeSharp) | Direct3D 12計算シェーダーとDirect3D 11・12共有処理 | MIT License | Copyright (c) 2024 Sergio Pedri |
|
||||
| [ComputeWeave](https://github.com/routersys/ComputeWeave) | Direct3D 12計算シェーダーとDirect3D 11・12共有処理 | MIT License | Copyright (c) 2024 Sergio Pedri |
|
||||
|
||||
---
|
||||
|
||||
|
||||
+23
-11
@@ -1,5 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using ComputeSharp;
|
||||
using System.Diagnostics;
|
||||
using ComputeWeave;
|
||||
using Ukiyoe;
|
||||
|
||||
var width = 1280;
|
||||
@@ -46,12 +46,17 @@ foreach (var quality in new[] { UkiyoeQuality.Balanced, UkiyoeQuality.High, Ukiy
|
||||
var parameters = new UkiyoePipeline.Parameters(quality, 0.5f, 0.5f, 0.5f, 0.6f, 6, 0.3f, 0.4f, 0.5f, 0.85f, 0.12f, 0.1f, 0.09f, 0);
|
||||
pipeline.Process(source, destination, width, height, in parameters);
|
||||
pipeline.Process(source, destination, width, height, in parameters);
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
const int frames = 5;
|
||||
var best = double.MaxValue;
|
||||
const int frames = 10;
|
||||
var stopwatch = new Stopwatch();
|
||||
for (var frame = 0; frame < frames; frame++)
|
||||
{
|
||||
stopwatch.Restart();
|
||||
pipeline.Process(source, destination, width, height, in parameters);
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"{quality}: {stopwatch.Elapsed.TotalMilliseconds / frames:F2} ms/frame ({width}x{height}) litPixels={CountLit(destination)}");
|
||||
stopwatch.Stop();
|
||||
best = Math.Min(best, stopwatch.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
Console.WriteLine($"{quality}: {best:F2} ms/frame ({width}x{height}) litPixels={CountLit(destination)}");
|
||||
}
|
||||
|
||||
{
|
||||
@@ -64,11 +69,18 @@ foreach (var quality in new[] { UkiyoeQuality.Balanced, UkiyoeQuality.High, Ukiy
|
||||
var parameters = new UkiyoePipeline.Parameters(UkiyoeQuality.High, 0.5f, 0.5f, 0.5f, 0.6f, 6, 0.3f, 0.4f, 0.5f, 0.85f, 0.12f, 0.1f, 0.09f, 0);
|
||||
|
||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in parameters);
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, parameters with { Flatten = 0.7f });
|
||||
pipeline.WaitForCompletion();
|
||||
stopwatch.Stop();
|
||||
Console.WriteLine($"structure recompute: {stopwatch.Elapsed.TotalMilliseconds:F2} ms");
|
||||
var stopwatch = new Stopwatch();
|
||||
var structureBest = double.MaxValue;
|
||||
for (var round = 0; round < 12; round++)
|
||||
{
|
||||
var recompute = parameters with { Flatten = (round & 1) == 0 ? 0.7f : 0.6f };
|
||||
stopwatch.Restart();
|
||||
pipeline.Simulate(sourceTexture, width, height, 0, 0, width, height, in recompute);
|
||||
pipeline.WaitForCompletion();
|
||||
stopwatch.Stop();
|
||||
structureBest = Math.Min(structureBest, stopwatch.Elapsed.TotalMilliseconds);
|
||||
}
|
||||
Console.WriteLine($"structure recompute: {structureBest:F2} ms");
|
||||
|
||||
if (pipeline.TryGetVisibleBounds(width, height, in parameters, out var rect))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@@ -26,6 +26,5 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Ukiyoe\ComputeSharp.Reference.props" />
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
@@ -63,6 +63,5 @@
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Ukiyoe\ComputeSharp.Reference.props" />
|
||||
|
||||
</Project>
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.Interop;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeWeave;
|
||||
using ComputeWeave.Interop;
|
||||
using Vortice;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.DXGI;
|
||||
@@ -537,18 +537,20 @@ public sealed class UkiyoeEffectTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Direct2DInteropProducesPrintFromOpaqueCore()
|
||||
public void Direct2DInteropProducesPrintAfterGrowingFullHdOutput()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var graphicsContext = devices.CreateContext();
|
||||
using var interop = UkiyoeGpuInterop.TryCreate(graphicsContext);
|
||||
if (interop is null)
|
||||
using var provider = UkiyoeInteropProvider.TryCreate(graphicsContext, out var interopDevice);
|
||||
if (provider is null || interopDevice is null)
|
||||
{
|
||||
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
|
||||
return;
|
||||
}
|
||||
|
||||
using var pipeline = UkiyoePipeline.TryCreate(interop.Device);
|
||||
using var domain = interopDevice.RegisterExternalDomain(provider);
|
||||
using var resourceSet = UkiyoeResourceSet.Create(interopDevice, domain);
|
||||
using var pipeline = UkiyoePipeline.TryCreate(interopDevice);
|
||||
Assert.NotNull(pipeline);
|
||||
|
||||
const int width = 96;
|
||||
@@ -571,24 +573,46 @@ public sealed class UkiyoeEffectTests
|
||||
handle.Free();
|
||||
}
|
||||
|
||||
Assert.True(interop.EnsureResources(width, height));
|
||||
var bounds = new RawRectF(0f, 0f, width, height);
|
||||
Assert.True(resourceSet.TryEnsureSource(width, height, out _));
|
||||
var parameters = CreateParameters();
|
||||
var renderContext = provider.RenderContext;
|
||||
for (var iteration = 0; iteration < 2; iteration++)
|
||||
{
|
||||
interop.RenderInput(inputBitmap, bounds);
|
||||
interop.BeginCompute();
|
||||
try
|
||||
using (var borrow = resourceSet.BeginSourceExternalOperation())
|
||||
{
|
||||
pipeline!.Process(interop.SourceTexture, interop.OutputTexture, width, height, in parameters);
|
||||
var previousTarget = renderContext.Target;
|
||||
renderContext.Target = borrow.DangerousGetView().Bitmap;
|
||||
renderContext.BeginDraw();
|
||||
renderContext.Clear(null);
|
||||
renderContext.DrawImage(
|
||||
inputBitmap,
|
||||
new System.Numerics.Vector2(0f, 0f),
|
||||
null,
|
||||
InterpolationMode.NearestNeighbor,
|
||||
CompositeMode.SourceCopy);
|
||||
renderContext.EndDraw();
|
||||
renderContext.Target = previousTarget;
|
||||
}
|
||||
finally
|
||||
|
||||
pipeline!.Simulate(
|
||||
resourceSet.GetSourceComputeBinding(), width, height, 0, 0, width, height, in parameters);
|
||||
Assert.True(pipeline.TryGetVisibleBounds(width, height, in parameters, out var visible));
|
||||
Assert.True(resourceSet.TryEnsureOutput(
|
||||
iteration == 0 ? width : 1920,
|
||||
iteration == 0 ? height : 1080,
|
||||
out _));
|
||||
pipeline.RenderVisible(
|
||||
resourceSet.GetOutputComputeBinding(), width, height, visible, in parameters);
|
||||
|
||||
if (iteration == 0)
|
||||
{
|
||||
interop.EndCompute();
|
||||
using var retiredLease = resourceSet.AcquireOutputExternalViewLease();
|
||||
Assert.Equal(width, retiredLease.Width);
|
||||
Assert.Equal(height, retiredLease.Height);
|
||||
}
|
||||
}
|
||||
interop.WaitForIdle();
|
||||
|
||||
using var outputLease = resourceSet.AcquireOutputExternalViewLease();
|
||||
using var staging = graphicsContext.DeviceContext.CreateBitmap(
|
||||
new SizeI(width, height),
|
||||
new BitmapProperties1(
|
||||
@@ -596,7 +620,7 @@ public sealed class UkiyoeEffectTests
|
||||
96f,
|
||||
96f,
|
||||
BitmapOptions.CpuRead | BitmapOptions.CannotDraw));
|
||||
staging.CopyFromBitmap(interop.OutputBitmap);
|
||||
staging.CopyFromBitmap(outputLease.DangerousGetView().Bitmap);
|
||||
var mapped = staging.Map(MapOptions.Read);
|
||||
try
|
||||
{
|
||||
|
||||
+1
-9
@@ -1,16 +1,8 @@
|
||||
<Solution>
|
||||
<Solution>
|
||||
<Configurations>
|
||||
<Platform Name="Any CPU" />
|
||||
<Platform Name="x64" />
|
||||
</Configurations>
|
||||
<Project Path="ComputeSharp/src/ComputeSharp.Core/ComputeSharp.Core.csproj">
|
||||
<Platform Solution="*|x64" Project="Any CPU" />
|
||||
</Project>
|
||||
<Project Path="ComputeSharp/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj" />
|
||||
<Project Path="ComputeSharp/src/ComputeSharp/ComputeSharp.csproj">
|
||||
<Platform Solution="*|x64" Project="Any CPU" />
|
||||
</Project>
|
||||
<Project Path="ComputeSharp/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj" />
|
||||
<Project Path="Ukiyoe/Ukiyoe.csproj">
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp' or '$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
||||
<IsPackagedProject>false</IsPackagedProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
||||
<InternalsVisibleTo Include="Ukiyoe.ComputeSharp, PublicKey=$(AssemblySignPublicKey)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,14 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp' or '$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
||||
<BaseOutputPath>$(MSBuildProjectDirectory)\bin\Ukiyoe\</BaseOutputPath>
|
||||
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)\obj\Ukiyoe\</BaseIntermediateOutputPath>
|
||||
<MSBuildProjectExtensionsPath>$(MSBuildProjectDirectory)\obj\</MSBuildProjectExtensionsPath>
|
||||
<DefaultItemExcludes>$(DefaultItemExcludes);$(MSBuildProjectDirectory)\obj\**</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp'">
|
||||
<AssemblyName>Ukiyoe.ComputeSharp</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'ComputeSharp.Core'">
|
||||
<AssemblyName>Ukiyoe.ComputeSharp.Core</AssemblyName>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,9 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<PrivateComputeSharpBuildProperties Condition="'$(BuildingSolutionFile)' != 'true'">CustomBeforeDirectoryBuildProps=$(MSBuildThisFileDirectory)ComputeSharp.Build.props;CustomAfterDirectoryBuildProps=$(MSBuildThisFileDirectory)ComputeSharp.Build.after.props</PrivateComputeSharpBuildProperties>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\ComputeSharp\src\ComputeSharp.Core\ComputeSharp.Core.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" AdditionalProperties="$(PrivateComputeSharpBuildProperties)" GlobalPropertiesToRemove="SkipPluginDeploy" />
|
||||
<ProjectReference Include="$(MSBuildThisFileDirectory)..\ComputeSharp\src\ComputeSharp\ComputeSharp.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" AdditionalProperties="$(PrivateComputeSharpBuildProperties)" GlobalPropertiesToRemove="SkipPluginDeploy" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+10
-7
@@ -5,7 +5,7 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>1.0.0</Version>
|
||||
<Version>1.0.2</Version>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
@@ -83,6 +83,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComputeWeave" Version="1.4.1" />
|
||||
<PackageReference Include="ILRepack" Version="2.0.46" PrivateAssets="all" ExcludeAssets="all" GeneratePathProperty="true" />
|
||||
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.142" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -96,20 +98,21 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputeSharp\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\ComputeSharp\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator\YukkuriMovieMaker.Generator.csproj" SetConfiguration="Configuration=$(Configuration)" SetPlatform="Platform=AnyCPU" GlobalPropertiesToRemove="SkipPluginDeploy" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
<AdditionalFiles Include="**/*.csv" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="ComputeSharp.Reference.props" />
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Shaders\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(SkipPluginDeploy)' != 'true' AND '$(BuildingSolutionFile)' != 'true'">
|
||||
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
copy "$(TargetPath)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)Ukiyoe.ComputeSharp.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
copy "$(TargetDir)Ukiyoe.ComputeSharp.Core.dll" "$(YMM4DirPath)user\plugin\$(ProjectName)\"" />
|
||||
<Target Name="MergePluginAssembly" AfterTargets="PostBuildEvent" Inputs="$(TargetPath);$(TargetDir)ComputeWeave.dll;$(TargetDir)ComputeWeave.Core.dll" Outputs="$(TargetDir)plugin\$(TargetFileName)">
|
||||
<MakeDir Directories="$(TargetDir)plugin" />
|
||||
<Exec Command=""$(PkgILRepack)\tools\ILRepack.exe" /out:"$(TargetDir)plugin\$(TargetFileName)" /lib:"$([System.IO.Path]::GetDirectoryName('$(TargetPath)'))" /lib:"$([System.IO.Path]::GetDirectoryName('$(YMM4DirPath)'))" /internalize "$(TargetPath)" "$(TargetDir)ComputeWeave.dll" "$(TargetDir)ComputeWeave.Core.dll"" />
|
||||
</Target>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="MergePluginAssembly" Condition="'$(SkipPluginDeploy)' != 'true' AND '$(BuildingSolutionFile)' != 'true'">
|
||||
<Exec Command="mkdir "$(YMM4DirPath)user\plugin\$(ProjectName)" > NUL 2>&1
copy "$(TargetDir)plugin\$(TargetFileName)" "$(YMM4DirPath)user\plugin\$(ProjectName)\"
del "$(YMM4DirPath)user\plugin\$(ProjectName)\ComputeWeave.dll" > NUL 2>&1
del "$(YMM4DirPath)user\plugin\$(ProjectName)\ComputeWeave.Core.dll" > NUL 2>&1" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
+131
-55
@@ -1,4 +1,5 @@
|
||||
using System.Numerics;
|
||||
using ComputeWeave;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Direct2D1.Effects;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
@@ -11,7 +12,12 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
{
|
||||
private readonly IGraphicsDevicesAndContext _devices;
|
||||
private readonly UkiyoeEffect _item;
|
||||
private UkiyoeGpuInterop? _interop;
|
||||
private UkiyoeInteropProvider? _interopProvider;
|
||||
private ComputeInteropDomain? _interopDomain;
|
||||
private UkiyoeResourceSet? _resourceSet;
|
||||
private ExternalTextureLease<UkiyoeExternalView>? _outputLease;
|
||||
private int _sourceWidth;
|
||||
private int _sourceHeight;
|
||||
private UkiyoePipeline? _pipeline;
|
||||
private UkiyoeCustomEffect? _effect;
|
||||
private Crop? _outputCrop;
|
||||
@@ -37,7 +43,7 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
|
||||
public override DrawDescription Update(EffectDescription effectDescription)
|
||||
{
|
||||
if (IsPassThroughEffect || _effect is null || _outputCrop is null || _outputTransform is null || _outputTransformOutput is null || _interop is null || _pipeline is null || input is null)
|
||||
if (IsPassThroughEffect || _effect is null || _outputCrop is null || _outputTransform is null || _outputTransformOutput is null || _resourceSet is null || _interopProvider is null || _pipeline is null || input is null)
|
||||
return effectDescription.DrawDescription;
|
||||
|
||||
var frame = effectDescription.ItemPosition.Frame;
|
||||
@@ -109,8 +115,14 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
var itemWidth = (int)widthValue;
|
||||
var itemHeight = (int)heightValue;
|
||||
|
||||
_interop.EnsureSource(itemWidth, itemHeight);
|
||||
_interop.RenderInput(input, new Vortice.RawRectF(bounds.Left, bounds.Top, bounds.Left + itemWidth, bounds.Top + itemHeight));
|
||||
if (!EnsureSource(itemWidth, itemHeight))
|
||||
{
|
||||
_effect.Amount = 0f;
|
||||
_isFirst = true;
|
||||
return effectDescription.DrawDescription;
|
||||
}
|
||||
|
||||
RenderInput(new Vortice.RawRectF(bounds.Left, bounds.Top, bounds.Left + itemWidth, bounds.Top + itemHeight));
|
||||
|
||||
var pipelineParameters = new UkiyoePipeline.Parameters(
|
||||
parameters.Quality,
|
||||
@@ -128,24 +140,15 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
parameters.LineColor.B / 255f,
|
||||
Math.Max(parameters.Seed, 0));
|
||||
|
||||
bool structureChanged;
|
||||
_interop.BeginCompute();
|
||||
try
|
||||
{
|
||||
structureChanged = _pipeline.Simulate(
|
||||
_interop.SourceTexture,
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
margin,
|
||||
margin,
|
||||
itemWidth,
|
||||
itemHeight,
|
||||
in pipelineParameters);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_interop.EndCompute();
|
||||
}
|
||||
var structureChanged = _pipeline.Simulate(
|
||||
_resourceSet.GetSourceComputeBinding(),
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
margin,
|
||||
margin,
|
||||
itemWidth,
|
||||
itemHeight,
|
||||
in pipelineParameters);
|
||||
|
||||
if (!_pipeline.TryGetVisibleBounds(canvasWidth, canvasHeight, in pipelineParameters, out var rect))
|
||||
{
|
||||
@@ -156,9 +159,16 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
return effectDescription.DrawDescription;
|
||||
}
|
||||
|
||||
if (!_interop.OutputCovers(rect.Width, rect.Height))
|
||||
if (!OutputCovers(rect.Width, rect.Height))
|
||||
_outputCrop.SetInput(0, null, true);
|
||||
var outputChanged = _interop.EnsureOutput(rect.Width, rect.Height);
|
||||
if (!EnsureOutput(rect.Width, rect.Height, out var outputChanged))
|
||||
{
|
||||
_effect.Amount = 0f;
|
||||
_parameters = parameters;
|
||||
_isFirst = true;
|
||||
_hasRenderState = false;
|
||||
return effectDescription.DrawDescription;
|
||||
}
|
||||
var renderState = new RenderState(
|
||||
pipelineParameters.LineDetail,
|
||||
pipelineParameters.LineStrength,
|
||||
@@ -173,27 +183,21 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
rect);
|
||||
if (structureChanged || outputChanged || !_hasOutput || !_hasRenderState || _renderState != renderState)
|
||||
{
|
||||
_interop.BeginCompute();
|
||||
try
|
||||
{
|
||||
_pipeline.RenderVisible(
|
||||
_interop.OutputTexture,
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
rect,
|
||||
in pipelineParameters);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_interop.EndCompute();
|
||||
}
|
||||
_pipeline.RenderVisible(
|
||||
_resourceSet.GetOutputComputeBinding(),
|
||||
canvasWidth,
|
||||
canvasHeight,
|
||||
rect,
|
||||
in pipelineParameters);
|
||||
_renderState = renderState;
|
||||
_hasRenderState = true;
|
||||
}
|
||||
|
||||
_outputLease ??= _resourceSet.AcquireOutputExternalViewLease();
|
||||
|
||||
if (outputChanged || !_hasOutput)
|
||||
{
|
||||
_outputCrop.SetInput(0, _interop.OutputBitmap, true);
|
||||
_outputCrop.SetInput(0, _outputLease.DangerousGetView().Bitmap, true);
|
||||
_effect.SetInput(1, _outputTransformOutput, true);
|
||||
}
|
||||
var cropRect = new Vector4(0f, 0f, rect.Width, rect.Height);
|
||||
@@ -216,15 +220,95 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
return effectDescription.DrawDescription;
|
||||
}
|
||||
|
||||
private bool EnsureSource(int width, int height)
|
||||
{
|
||||
if (_sourceWidth == width && _sourceHeight == height)
|
||||
return true;
|
||||
|
||||
_sourceWidth = 0;
|
||||
_sourceHeight = 0;
|
||||
if (!_resourceSet!.TryEnsureSource(width, height, out _))
|
||||
return false;
|
||||
|
||||
_sourceWidth = width;
|
||||
_sourceHeight = height;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool OutputCovers(int width, int height)
|
||||
=> _outputLease is { IsDisposed: false } lease &&
|
||||
lease.Width >= width &&
|
||||
lease.Height >= height;
|
||||
|
||||
private bool EnsureOutput(int width, int height, out bool changed)
|
||||
{
|
||||
changed = false;
|
||||
if (OutputCovers(width, height))
|
||||
return true;
|
||||
|
||||
_outputLease?.Dispose();
|
||||
_outputLease = null;
|
||||
return _resourceSet!.TryEnsureOutput(width, height, out changed);
|
||||
}
|
||||
|
||||
private void RenderInput(Vortice.RawRectF bounds)
|
||||
{
|
||||
var renderContext = _interopProvider!.RenderContext;
|
||||
using var borrow = _resourceSet!.BeginSourceExternalOperation();
|
||||
var previousTarget = renderContext.Target;
|
||||
renderContext.Target = borrow.DangerousGetView().Bitmap;
|
||||
renderContext.BeginDraw();
|
||||
renderContext.Clear(null);
|
||||
renderContext.DrawImage(
|
||||
input,
|
||||
new Vector2(-bounds.Left, -bounds.Top),
|
||||
null,
|
||||
InterpolationMode.NearestNeighbor,
|
||||
CompositeMode.SourceCopy);
|
||||
renderContext.EndDraw();
|
||||
renderContext.Target = previousTarget;
|
||||
}
|
||||
|
||||
private void ReleaseInterop()
|
||||
{
|
||||
_outputLease?.Dispose();
|
||||
_outputLease = null;
|
||||
_pipeline?.Dispose();
|
||||
_pipeline = null;
|
||||
_resourceSet?.Dispose();
|
||||
_resourceSet?.WaitForDisposal();
|
||||
_resourceSet = null;
|
||||
_interopDomain?.Dispose();
|
||||
_interopDomain?.WaitForDisposal();
|
||||
_interopDomain = null;
|
||||
_interopProvider?.Dispose();
|
||||
_interopProvider = null;
|
||||
_sourceWidth = 0;
|
||||
_sourceHeight = 0;
|
||||
}
|
||||
|
||||
protected override ID2D1Image? CreateEffect(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
var interop = UkiyoeGpuInterop.TryCreate(devices);
|
||||
if (interop is null)
|
||||
var interopProvider = UkiyoeInteropProvider.TryCreate(devices, out var interopDevice);
|
||||
if (interopProvider is null || interopDevice is null)
|
||||
return null;
|
||||
var pipeline = UkiyoePipeline.TryCreate(interop.Device);
|
||||
if (pipeline is null)
|
||||
|
||||
try
|
||||
{
|
||||
interop.Dispose();
|
||||
_interopProvider = interopProvider;
|
||||
_interopDomain = interopDevice.RegisterExternalDomain(interopProvider);
|
||||
_resourceSet = UkiyoeResourceSet.Create(interopDevice, _interopDomain);
|
||||
_pipeline = UkiyoePipeline.TryCreate(interopDevice);
|
||||
}
|
||||
catch
|
||||
{
|
||||
ReleaseInterop();
|
||||
throw;
|
||||
}
|
||||
|
||||
if (_pipeline is null)
|
||||
{
|
||||
ReleaseInterop();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -240,8 +324,7 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
if (!effect.IsEnabled)
|
||||
{
|
||||
effect.Dispose();
|
||||
pipeline.Dispose();
|
||||
interop.Dispose();
|
||||
ReleaseInterop();
|
||||
return null;
|
||||
}
|
||||
outputCrop = new Crop(devices.DeviceContext);
|
||||
@@ -253,8 +336,6 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
outputTransform.SetInput(0, outputCropOutput, true);
|
||||
outputTransformOutput = outputTransform.Output;
|
||||
output = effect.Output;
|
||||
_interop = interop;
|
||||
_pipeline = pipeline;
|
||||
_effect = effect;
|
||||
_outputCrop = outputCrop;
|
||||
_outputCropOutput = outputCropOutput;
|
||||
@@ -276,8 +357,7 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
outputCropOutput?.Dispose();
|
||||
outputCrop?.Dispose();
|
||||
effect?.Dispose();
|
||||
pipeline.Dispose();
|
||||
interop.Dispose();
|
||||
ReleaseInterop();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -308,11 +388,7 @@ internal sealed class UkiyoeEffectProcessor : VideoEffectProcessorBase
|
||||
if (disposing)
|
||||
{
|
||||
ClearEffectChain();
|
||||
_interop?.WaitForIdle();
|
||||
_pipeline?.Dispose();
|
||||
_pipeline = null;
|
||||
_interop?.Dispose();
|
||||
_interop = null;
|
||||
ReleaseInterop();
|
||||
}
|
||||
}
|
||||
finally
|
||||
|
||||
+157
-267
@@ -1,7 +1,5 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp;
|
||||
using ComputeSharp.Interop;
|
||||
using Vortice;
|
||||
using System.Threading;
|
||||
using ComputeWeave;
|
||||
using Vortice.Direct2D1;
|
||||
using Vortice.Direct3D11;
|
||||
using Vortice.DXGI;
|
||||
@@ -10,314 +8,206 @@ using PixelFormat = Vortice.DCommon.PixelFormat;
|
||||
|
||||
namespace Ukiyoe;
|
||||
|
||||
internal sealed class UkiyoeGpuInterop : IDisposable
|
||||
internal sealed class UkiyoeQueueScheduler : ComputeExternalQueueScheduler
|
||||
{
|
||||
private static readonly Guid D3D12FenceGuid = new("0a753dcf-c4d8-4b91-adf6-be5a60d95a76");
|
||||
private int _entered;
|
||||
|
||||
private readonly GraphicsDevice _device;
|
||||
private readonly ID3D11Device1 _d3dDevice;
|
||||
private readonly ID3D11DeviceContext4 _d3dContext;
|
||||
private readonly ID3D11Fence _fence;
|
||||
private readonly ID2D1DeviceContext6 _renderContext;
|
||||
private nint _d3d12Fence;
|
||||
private ReadWriteTexture2D<Bgra32, Float4>? _sourceTexture;
|
||||
private ReadWriteTexture2D<Bgra32, Float4>? _outputTexture;
|
||||
private ID3D11Texture2D? _sourceD3D11Texture;
|
||||
private ID3D11Texture2D? _outputD3D11Texture;
|
||||
private ID2D1Bitmap1? _sourceBitmap;
|
||||
private ID2D1Bitmap1? _outputBitmap;
|
||||
private int _sourceWidth;
|
||||
private int _sourceHeight;
|
||||
private int _outputWidth;
|
||||
private int _outputHeight;
|
||||
private ulong _fenceValue;
|
||||
private bool _computeActive;
|
||||
private bool _disposed;
|
||||
|
||||
private UkiyoeGpuInterop(
|
||||
GraphicsDevice device,
|
||||
ID3D11Device1 d3dDevice,
|
||||
ID3D11DeviceContext4 d3dContext,
|
||||
ID3D11Fence fence,
|
||||
ID2D1DeviceContext6 renderContext,
|
||||
nint d3d12Fence)
|
||||
protected override void EnterCore()
|
||||
{
|
||||
_device = device;
|
||||
_d3dDevice = d3dDevice;
|
||||
_d3dContext = d3dContext;
|
||||
_fence = fence;
|
||||
_renderContext = renderContext;
|
||||
_d3d12Fence = d3d12Fence;
|
||||
if (Interlocked.CompareExchange(ref _entered, 1, 0) != 0)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
public GraphicsDevice Device => _device;
|
||||
|
||||
public ReadWriteTexture2D<Bgra32, Float4> SourceTexture => _sourceTexture!;
|
||||
|
||||
public ReadWriteTexture2D<Bgra32, Float4> OutputTexture => _outputTexture!;
|
||||
|
||||
public ID2D1Bitmap1 OutputBitmap => _outputBitmap!;
|
||||
|
||||
public bool SourceMatches(int width, int height)
|
||||
=> _sourceTexture is not null && _sourceWidth == width && _sourceHeight == height;
|
||||
|
||||
public bool OutputCovers(int width, int height)
|
||||
=> _outputTexture is not null && _outputWidth >= width && _outputHeight >= height;
|
||||
|
||||
public static unsafe UkiyoeGpuInterop? TryCreate(IGraphicsDevicesAndContext devices)
|
||||
protected override void ExitCore()
|
||||
{
|
||||
ID3D11Device1? d3dDevice = null;
|
||||
ID3D11DeviceContext4? d3dContext = null;
|
||||
ID3D11Fence? fence = null;
|
||||
if (Interlocked.Exchange(ref _entered, 0) != 1)
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
protected override void DisposeCore()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UkiyoeExternalView(ID3D11Texture2D texture, ID2D1Bitmap1 bitmap) : IDisposable
|
||||
{
|
||||
private readonly ID3D11Texture2D _texture = texture;
|
||||
private readonly ID2D1Bitmap1 _bitmap = bitmap;
|
||||
|
||||
public ID2D1Bitmap1 Bitmap => _bitmap;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bitmap.Dispose();
|
||||
_texture.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UkiyoeInteropProvider : IComputeExternalInteropProvider<UkiyoeExternalView>
|
||||
{
|
||||
private readonly ID3D11Device1 _device;
|
||||
private readonly ID3D11Device5 _device5;
|
||||
private readonly ID3D11DeviceContext4 _context;
|
||||
private readonly ID2D1DeviceContext6 _renderContext;
|
||||
private readonly UkiyoeQueueScheduler _scheduler;
|
||||
private readonly long _adapterLuid;
|
||||
private ID3D11Fence? _fence;
|
||||
private bool _disposed;
|
||||
|
||||
private UkiyoeInteropProvider(
|
||||
ID3D11Device1 device,
|
||||
ID3D11Device5 device5,
|
||||
ID3D11DeviceContext4 context,
|
||||
ID2D1DeviceContext6 renderContext,
|
||||
UkiyoeQueueScheduler scheduler,
|
||||
long adapterLuid)
|
||||
{
|
||||
_device = device;
|
||||
_device5 = device5;
|
||||
_context = context;
|
||||
_renderContext = renderContext;
|
||||
_scheduler = scheduler;
|
||||
_adapterLuid = adapterLuid;
|
||||
}
|
||||
|
||||
public ExternalAdapterIdentity AdapterIdentity => new(_adapterLuid);
|
||||
|
||||
public ComputeExternalQueueScheduler Scheduler => _scheduler;
|
||||
|
||||
public ExternalInteropCapabilities Capabilities =>
|
||||
ExternalInteropCapabilities.SharedFence |
|
||||
ExternalInteropCapabilities.SharedTexture2D |
|
||||
ExternalInteropCapabilities.SingleImmediateContextOrdering |
|
||||
ExternalInteropCapabilities.PersistentExternalViewOrdering;
|
||||
|
||||
public ID2D1DeviceContext6 RenderContext => _renderContext;
|
||||
|
||||
public static UkiyoeInteropProvider? TryCreate(IGraphicsDevicesAndContext devices, out GraphicsDevice? graphicsDevice)
|
||||
{
|
||||
graphicsDevice = null;
|
||||
|
||||
ID3D11Device1? device = null;
|
||||
ID3D11Device5? device5 = null;
|
||||
ID3D11DeviceContext4? context = null;
|
||||
ID2D1DeviceContext6? renderContext = null;
|
||||
nint d3d12Fence = 0;
|
||||
nint fenceHandle = 0;
|
||||
UkiyoeQueueScheduler? scheduler = null;
|
||||
try
|
||||
{
|
||||
var device = GetMatchingDevice(devices);
|
||||
d3dDevice = devices.D3D.Device.QueryInterface<ID3D11Device1>();
|
||||
d3dContext = devices.D3D.DeviceContext.QueryInterface<ID3D11DeviceContext4>();
|
||||
using var d3dDevice5 = devices.D3D.Device.QueryInterface<ID3D11Device5>();
|
||||
var fenceGuid = D3D12FenceGuid;
|
||||
InteropServices.CreateSharedFence(device, &fenceGuid, (void**)&d3d12Fence, &fenceHandle);
|
||||
fence = d3dDevice5.OpenSharedFence(fenceHandle);
|
||||
renderContext = devices.D2D.Device.CreateDeviceContext(DeviceContextOptions.EnableMultithreadedOptimizations);
|
||||
return new UkiyoeGpuInterop(device, d3dDevice, d3dContext, fence, renderContext, d3d12Fence);
|
||||
var adapterLuidText = devices.DXGI.Adapter.Description.Luid.ToString();
|
||||
using var enumerator = GraphicsDevice
|
||||
.QueryDevices(candidate => string.Equals(candidate.Luid.ToString(), adapterLuidText, StringComparison.Ordinal))
|
||||
.GetEnumerator();
|
||||
if (!enumerator.MoveNext())
|
||||
return null;
|
||||
|
||||
graphicsDevice = enumerator.Current;
|
||||
device = devices.D3D.Device.QueryInterface<ID3D11Device1>();
|
||||
device5 = devices.D3D.Device.QueryInterface<ID3D11Device5>();
|
||||
context = devices.D3D.DeviceContext.QueryInterface<ID3D11DeviceContext4>();
|
||||
renderContext = devices.D2D.Device
|
||||
.CreateDeviceContext(DeviceContextOptions.EnableMultithreadedOptimizations)
|
||||
.QueryInterface<ID2D1DeviceContext6>();
|
||||
scheduler = new UkiyoeQueueScheduler();
|
||||
return new UkiyoeInteropProvider(device, device5, context, renderContext, scheduler, graphicsDevice.Luid.ToInt64());
|
||||
}
|
||||
catch
|
||||
{
|
||||
scheduler?.Dispose();
|
||||
renderContext?.Dispose();
|
||||
fence?.Dispose();
|
||||
d3dContext?.Dispose();
|
||||
d3dDevice?.Dispose();
|
||||
if (d3d12Fence != 0)
|
||||
Marshal.Release(d3d12Fence);
|
||||
context?.Dispose();
|
||||
device5?.Dispose();
|
||||
device?.Dispose();
|
||||
graphicsDevice = null;
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (fenceHandle != 0)
|
||||
CloseHandle(fenceHandle);
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnsureResources(int width, int height)
|
||||
public void Initialize(in ExternalTimelineInitialization initialization)
|
||||
{
|
||||
var sourceChanged = EnsureSource(width, height);
|
||||
var outputChanged = EnsureOutput(width, height);
|
||||
return sourceChanged || outputChanged;
|
||||
_fence = _device5.OpenSharedFence<ID3D11Fence>(initialization.SharedFenceHandle.DangerousGetHandle());
|
||||
}
|
||||
|
||||
public bool EnsureSource(int width, int height)
|
||||
public void EnqueueSignal(ulong value)
|
||||
{
|
||||
if (SourceMatches(width, height))
|
||||
return false;
|
||||
|
||||
if (_sourceTexture is not null)
|
||||
WaitForIdle();
|
||||
ReleaseSourceResources();
|
||||
CreateSourceResources(width, height);
|
||||
return true;
|
||||
_context.Signal(_fence!, value);
|
||||
}
|
||||
|
||||
public bool EnsureOutput(int width, int height)
|
||||
public void FlushAfterSignal()
|
||||
{
|
||||
if (OutputCovers(width, height))
|
||||
return false;
|
||||
|
||||
var capacityWidth = Math.Max(width, _outputWidth);
|
||||
var capacityHeight = Math.Max(height, _outputHeight);
|
||||
if (_outputTexture is not null)
|
||||
WaitForIdle();
|
||||
ReleaseOutputResources();
|
||||
CreateOutputResources(capacityWidth, capacityHeight);
|
||||
return true;
|
||||
_context.Flush();
|
||||
}
|
||||
|
||||
public void RenderInput(ID2D1Image source, RawRectF bounds)
|
||||
public void EnqueueWait(ulong value)
|
||||
{
|
||||
_renderContext.BeginDraw();
|
||||
_renderContext.Clear(null);
|
||||
_renderContext.DrawImage(
|
||||
source,
|
||||
new System.Numerics.Vector2(-bounds.Left, -bounds.Top),
|
||||
null,
|
||||
InterpolationMode.NearestNeighbor,
|
||||
CompositeMode.SourceCopy);
|
||||
_renderContext.EndDraw();
|
||||
_context.Wait(_fence!, value);
|
||||
}
|
||||
|
||||
public unsafe void BeginCompute()
|
||||
public UkiyoeExternalView OpenSharedTexture(BorrowedSharedHandle resourceHandle, in ExternalTextureDescriptor descriptor)
|
||||
{
|
||||
if (_computeActive)
|
||||
throw new InvalidOperationException();
|
||||
var value = ++_fenceValue;
|
||||
_d3dContext.Signal(_fence, value);
|
||||
_d3dContext.Flush();
|
||||
InteropServices.WaitForSharedFence(_device, (void*)_d3d12Fence, value);
|
||||
_computeActive = true;
|
||||
}
|
||||
|
||||
public unsafe void EndCompute()
|
||||
{
|
||||
if (!_computeActive)
|
||||
throw new InvalidOperationException();
|
||||
ID3D11Texture2D? texture = null;
|
||||
ID2D1Bitmap1? bitmap = null;
|
||||
try
|
||||
{
|
||||
var value = ++_fenceValue;
|
||||
InteropServices.SignalSharedFence(_device, (void*)_d3d12Fence, value);
|
||||
_d3dContext.Wait(_fence, value);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_computeActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void WaitForIdle()
|
||||
{
|
||||
if (_computeActive)
|
||||
throw new InvalidOperationException();
|
||||
var value = ++_fenceValue;
|
||||
_d3dContext.Signal(_fence, value);
|
||||
_d3dContext.Flush();
|
||||
_fence.SetEventOnCompletion(value, 0);
|
||||
}
|
||||
|
||||
private static GraphicsDevice GetMatchingDevice(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
var adapterLuid = devices.DXGI.Adapter.Description.Luid.ToString();
|
||||
using var enumerator = GraphicsDevice.QueryDevices(
|
||||
device => string.Equals(device.Luid.ToString(), adapterLuid, StringComparison.Ordinal)).GetEnumerator();
|
||||
if (!enumerator.MoveNext())
|
||||
throw new NotSupportedException();
|
||||
return enumerator.Current;
|
||||
}
|
||||
|
||||
private void CreateSourceResources(int width, int height)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, Float4>? sourceTexture = null;
|
||||
ID3D11Texture2D? sourceD3D11Texture = null;
|
||||
ID2D1Bitmap1? sourceBitmap = null;
|
||||
nint sourceHandle = 0;
|
||||
try
|
||||
{
|
||||
sourceTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(_device, width, height);
|
||||
sourceHandle = InteropServices.CreateSharedHandle(sourceTexture);
|
||||
sourceD3D11Texture = _d3dDevice.OpenSharedResource1<ID3D11Texture2D>(sourceHandle);
|
||||
using var sourceSurface = sourceD3D11Texture.QueryInterface<IDXGISurface>();
|
||||
texture = _device.OpenSharedResource1<ID3D11Texture2D>(resourceHandle.DangerousGetHandle());
|
||||
using var surface = texture.QueryInterface<IDXGISurface>();
|
||||
var pixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
||||
sourceBitmap = _renderContext.CreateBitmapFromDxgiSurface(
|
||||
sourceSurface,
|
||||
new BitmapProperties1(pixelFormat, 96f, 96f, BitmapOptions.Target));
|
||||
_renderContext.Target = sourceBitmap;
|
||||
|
||||
_sourceTexture = sourceTexture;
|
||||
_sourceD3D11Texture = sourceD3D11Texture;
|
||||
_sourceBitmap = sourceBitmap;
|
||||
_sourceWidth = width;
|
||||
_sourceHeight = height;
|
||||
sourceTexture = null;
|
||||
sourceD3D11Texture = null;
|
||||
sourceBitmap = null;
|
||||
var options = descriptor.ExternalUsage is ExternalTextureUsage.RenderTarget
|
||||
? BitmapOptions.Target
|
||||
: BitmapOptions.None;
|
||||
bitmap = _renderContext.CreateBitmapFromDxgiSurface(
|
||||
surface,
|
||||
new BitmapProperties1(pixelFormat, 96f, 96f, options));
|
||||
var view = new UkiyoeExternalView(texture, bitmap);
|
||||
texture = null;
|
||||
bitmap = null;
|
||||
return view;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sourceHandle != 0)
|
||||
CloseHandle(sourceHandle);
|
||||
sourceBitmap?.Dispose();
|
||||
sourceD3D11Texture?.Dispose();
|
||||
sourceTexture?.Dispose();
|
||||
bitmap?.Dispose();
|
||||
texture?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateOutputResources(int width, int height)
|
||||
public void OnDeviceTerminal(Exception reason)
|
||||
{
|
||||
ReadWriteTexture2D<Bgra32, Float4>? outputTexture = null;
|
||||
ID3D11Texture2D? outputD3D11Texture = null;
|
||||
ID2D1Bitmap1? outputBitmap = null;
|
||||
nint outputHandle = 0;
|
||||
try
|
||||
{
|
||||
outputTexture = InteropServices.AllocateSharedReadWriteTexture2D<Bgra32, Float4>(_device, width, height);
|
||||
outputHandle = InteropServices.CreateSharedHandle(outputTexture);
|
||||
outputD3D11Texture = _d3dDevice.OpenSharedResource1<ID3D11Texture2D>(outputHandle);
|
||||
using var outputSurface = outputD3D11Texture.QueryInterface<IDXGISurface>();
|
||||
var pixelFormat = new PixelFormat(Format.B8G8R8A8_UNorm, Vortice.DCommon.AlphaMode.Premultiplied);
|
||||
outputBitmap = _renderContext.CreateBitmapFromDxgiSurface(
|
||||
outputSurface,
|
||||
new BitmapProperties1(pixelFormat, 96f, 96f, BitmapOptions.None));
|
||||
|
||||
_outputTexture = outputTexture;
|
||||
_outputD3D11Texture = outputD3D11Texture;
|
||||
_outputBitmap = outputBitmap;
|
||||
_outputWidth = width;
|
||||
_outputHeight = height;
|
||||
outputTexture = null;
|
||||
outputD3D11Texture = null;
|
||||
outputBitmap = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (outputHandle != 0)
|
||||
CloseHandle(outputHandle);
|
||||
outputBitmap?.Dispose();
|
||||
outputD3D11Texture?.Dispose();
|
||||
outputTexture?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReleaseSourceResources()
|
||||
{
|
||||
_renderContext.Target = null;
|
||||
_sourceBitmap?.Dispose();
|
||||
_sourceD3D11Texture?.Dispose();
|
||||
_sourceTexture?.Dispose();
|
||||
_sourceBitmap = null;
|
||||
_sourceD3D11Texture = null;
|
||||
_sourceTexture = null;
|
||||
_sourceWidth = 0;
|
||||
_sourceHeight = 0;
|
||||
}
|
||||
|
||||
private void ReleaseOutputResources()
|
||||
{
|
||||
_outputBitmap?.Dispose();
|
||||
_outputD3D11Texture?.Dispose();
|
||||
_outputTexture?.Dispose();
|
||||
_outputBitmap = null;
|
||||
_outputD3D11Texture = null;
|
||||
_outputTexture = null;
|
||||
_outputWidth = 0;
|
||||
_outputHeight = 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
return;
|
||||
try
|
||||
{
|
||||
WaitForIdle();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_disposed = true;
|
||||
ReleaseOutputResources();
|
||||
ReleaseSourceResources();
|
||||
_renderContext.Dispose();
|
||||
_fence.Dispose();
|
||||
_d3dContext.Dispose();
|
||||
_d3dDevice.Dispose();
|
||||
if (_d3d12Fence != 0)
|
||||
{
|
||||
Marshal.Release(_d3d12Fence);
|
||||
_d3d12Fence = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool CloseHandle(nint handle);
|
||||
_disposed = true;
|
||||
_fence?.Dispose();
|
||||
_renderContext.Dispose();
|
||||
_context.Dispose();
|
||||
_device5.Dispose();
|
||||
_device.Dispose();
|
||||
_scheduler.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[ComputeInteropResourceSet]
|
||||
internal sealed partial class UkiyoeResourceSet
|
||||
{
|
||||
[ComputeSharedTexture(
|
||||
ComputeResourceResizePolicy.Exact,
|
||||
ComputeResourceAccess.ReadWrite,
|
||||
ExternalResourceAccess.Write,
|
||||
ExternalTextureUsage.RenderTarget,
|
||||
ComputeAlphaMode.Premultiplied,
|
||||
ComputeSharedTextureInitialOwner.External,
|
||||
ComputeResourceRecovery.RecreateFromHost)]
|
||||
private readonly SharedTextureSlot<Bgra32, Float4, UkiyoeExternalView> _source;
|
||||
|
||||
[ComputeSharedTexture(
|
||||
ComputeResourceResizePolicy.GrowOnly,
|
||||
ComputeResourceAccess.ReadWrite,
|
||||
ExternalResourceAccess.Read,
|
||||
ExternalTextureUsage.Sampled,
|
||||
ComputeAlphaMode.Premultiplied,
|
||||
ComputeSharedTextureInitialOwner.Compute,
|
||||
ComputeResourceRecovery.Recompute)]
|
||||
private readonly SharedTextureSlot<Bgra32, Float4, UkiyoeExternalView> _output;
|
||||
}
|
||||
+42
-11
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp;
|
||||
using ComputeWeave;
|
||||
|
||||
namespace Ukiyoe;
|
||||
|
||||
@@ -326,7 +326,7 @@ internal readonly partial struct EtfShader(
|
||||
}
|
||||
}
|
||||
|
||||
[ThreadGroupSize(DefaultThreadGroupSizes.XY)]
|
||||
[ThreadGroupSize(8, 8, 1)]
|
||||
[GeneratedComputeShaderDescriptor]
|
||||
internal readonly partial struct FlattenShader(
|
||||
ReadWriteBuffer<Float4> colorIn,
|
||||
@@ -347,19 +347,50 @@ internal readonly partial struct FlattenShader(
|
||||
private readonly int gridHeight = gridHeight;
|
||||
private readonly float beta = beta;
|
||||
|
||||
[GroupShared(144)]
|
||||
private static readonly Float4[] tileColor = null!;
|
||||
|
||||
[GroupShared(144)]
|
||||
private static readonly float[] tileGradient = null!;
|
||||
|
||||
[GroupShared(144)]
|
||||
private static readonly Float4[] tileIterate = null!;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
var originX = GridIds.X * UkiyoeSettings.FlattenGroupDim - UkiyoeSettings.FlattenRadius;
|
||||
var originY = GridIds.Y * UkiyoeSettings.FlattenGroupDim - UkiyoeSettings.FlattenRadius;
|
||||
for (var slot = GroupIds.Index; slot < UkiyoeSettings.FlattenTileCount; slot += UkiyoeSettings.FlattenGroupDim * UkiyoeSettings.FlattenGroupDim)
|
||||
{
|
||||
var tx = originX + slot % UkiyoeSettings.FlattenTileDim;
|
||||
var ty = originY + slot / UkiyoeSettings.FlattenTileDim;
|
||||
if (tx >= 0 && tx < gridWidth && ty >= 0 && ty < gridHeight)
|
||||
{
|
||||
var sampleIndex = ty * gridWidth + tx;
|
||||
tileColor[slot] = colorIn[sampleIndex];
|
||||
tileGradient[slot] = gradientMagnitude[sampleIndex];
|
||||
tileIterate[slot] = iterateIn[sampleIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
tileColor[slot] = new Float4(0f, 0f, 0f, 0f);
|
||||
tileGradient[slot] = 0f;
|
||||
tileIterate[slot] = new Float4(0f, 0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
Hlsl.GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
var gx = ThreadIds.X;
|
||||
var gy = ThreadIds.Y;
|
||||
if (gx >= gridWidth || gy >= gridHeight)
|
||||
return;
|
||||
|
||||
var index = gy * gridWidth + gx;
|
||||
var original = colorIn[index];
|
||||
var current = iterateIn[index];
|
||||
var centerTile = (GroupIds.Y + UkiyoeSettings.FlattenRadius) * UkiyoeSettings.FlattenTileDim + GroupIds.X + UkiyoeSettings.FlattenRadius;
|
||||
var original = tileColor[centerTile];
|
||||
var current = tileIterate[centerTile];
|
||||
var centerFeature = UkiyoeShaderMath.AffinityFeature(original);
|
||||
var maxGradient = Hlsl.Max(Hlsl.AsFloat(scratch[UkiyoeSettings.ScratchMaxGradient]), 1e-6f);
|
||||
var centerGradient = gradientMagnitude[index] / maxGradient;
|
||||
var centerGradient = tileGradient[centerTile] / maxGradient;
|
||||
var invTwoSigmaSquared = 0.5f / (UkiyoeSettings.FlattenSigma * UkiyoeSettings.FlattenSigma);
|
||||
|
||||
var numerator = original * beta;
|
||||
@@ -374,15 +405,15 @@ internal readonly partial struct FlattenShader(
|
||||
var ny = gy + dy;
|
||||
if (nx < 0 || nx >= gridWidth || ny < 0 || ny >= gridHeight)
|
||||
continue;
|
||||
var neighborIndex = ny * gridWidth + nx;
|
||||
var neighborOriginal = colorIn[neighborIndex];
|
||||
var neighborTile = centerTile + dy * UkiyoeSettings.FlattenTileDim + dx;
|
||||
var neighborOriginal = tileColor[neighborTile];
|
||||
var feature = centerFeature - UkiyoeShaderMath.AffinityFeature(neighborOriginal);
|
||||
var alphaDelta = original.W - neighborOriginal.W;
|
||||
var featureDistance = feature.X * feature.X + feature.Y * feature.Y + feature.Z * feature.Z + alphaDelta * alphaDelta;
|
||||
var neighborGradient = gradientMagnitude[neighborIndex] / maxGradient;
|
||||
var neighborGradient = tileGradient[neighborTile] / maxGradient;
|
||||
var edge = Hlsl.Max(centerGradient, neighborGradient);
|
||||
var affinity = Hlsl.Exp(-Hlsl.Max(featureDistance, UkiyoeSettings.FlattenGradientWeight * edge * edge) * invTwoSigmaSquared);
|
||||
var neighborCurrent = iterateIn[neighborIndex];
|
||||
var neighborCurrent = tileIterate[neighborTile];
|
||||
var difference = current - neighborCurrent;
|
||||
var l1 = Hlsl.Abs(difference.X) + Hlsl.Abs(difference.Y) + Hlsl.Abs(difference.Z) + Hlsl.Abs(difference.W);
|
||||
var weight = affinity / Hlsl.Max(l1, UkiyoeSettings.FlattenEpsilon);
|
||||
@@ -391,7 +422,7 @@ internal readonly partial struct FlattenShader(
|
||||
}
|
||||
}
|
||||
|
||||
iterateOut[index] = numerator / denominator;
|
||||
iterateOut[gy * gridWidth + gx] = numerator / denominator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+70
-173
@@ -1,22 +1,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp;
|
||||
using ComputeWeave;
|
||||
|
||||
namespace Ukiyoe;
|
||||
|
||||
internal sealed class UkiyoePipeline : IDisposable
|
||||
{
|
||||
private readonly GraphicsDevice _device;
|
||||
private readonly UkiyoePipelineHost _host;
|
||||
private readonly ReadWriteBuffer<int> _scratch;
|
||||
private readonly ReadBackBuffer<int> _scratchReadBack;
|
||||
private ReadWriteBuffer<Float4>? _colorIn;
|
||||
private ReadWriteBuffer<Float4>? _colorA;
|
||||
private ReadWriteBuffer<Float4>? _colorB;
|
||||
private ReadWriteBuffer<float>? _gray;
|
||||
private ReadWriteBuffer<float>? _gradientMagnitude;
|
||||
private ReadWriteBuffer<float>? _response;
|
||||
private ReadWriteBuffer<float>? _line;
|
||||
private ReadWriteBuffer<Float2>? _tangentA;
|
||||
private ReadWriteBuffer<Float2>? _tangentB;
|
||||
private StructureKey? _structureKey;
|
||||
private int _cachedLitCount;
|
||||
private int _cachedBoundsMinX;
|
||||
@@ -30,9 +22,10 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
private int _packedWidth;
|
||||
private int _packedHeight;
|
||||
|
||||
private UkiyoePipeline(GraphicsDevice device)
|
||||
private UkiyoePipeline(GraphicsDevice device, UkiyoePipelineHost host)
|
||||
{
|
||||
_device = device;
|
||||
_host = host;
|
||||
_scratch = device.AllocateReadWriteBuffer<int>(UkiyoeSettings.ScratchLength);
|
||||
_scratchReadBack = device.AllocateReadBackBuffer<int>(UkiyoeSettings.ScratchLength);
|
||||
}
|
||||
@@ -41,7 +34,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
{
|
||||
try
|
||||
{
|
||||
return new UkiyoePipeline(GraphicsDevice.GetDefault());
|
||||
return TryCreate(GraphicsDevice.GetDefault());
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -51,12 +44,16 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
|
||||
public static UkiyoePipeline? TryCreate(GraphicsDevice device)
|
||||
{
|
||||
UkiyoePipelineHost? host = null;
|
||||
try
|
||||
{
|
||||
return new UkiyoePipeline(device);
|
||||
host = UkiyoePipelineHost.Create(device, UkiyoeSettings.MaximumPendingSubmissions);
|
||||
return new UkiyoePipeline(device, host);
|
||||
}
|
||||
catch
|
||||
{
|
||||
host?.Dispose();
|
||||
host?.WaitForDisposal();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -74,8 +71,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
var sourceTexture = _packedSource!;
|
||||
var outputTexture = _packedOutput!;
|
||||
sourceTexture.CopyFrom(MemoryMarshal.Cast<int, Bgra32>(source[..pixelCount]));
|
||||
using (ComputeContext context = _device.CreateComputeContext())
|
||||
RecordFullPipeline(in context, sourceTexture, outputTexture, width, height, in parameters);
|
||||
SubmitFullPipeline(sourceTexture, outputTexture, width, height, in parameters).Wait();
|
||||
outputTexture.CopyTo(MemoryMarshal.Cast<int, Bgra32>(destination[..pixelCount]));
|
||||
}
|
||||
|
||||
@@ -87,9 +83,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
in Parameters parameters)
|
||||
{
|
||||
EnsureGridFor(width, height, parameters.Quality);
|
||||
using ComputeContext context = _device.CreateComputeContext();
|
||||
RecordFullPipeline(in context, source, destination, width, height, in parameters);
|
||||
context.Submit();
|
||||
_ = SubmitFullPipeline(source, destination, width, height, in parameters);
|
||||
}
|
||||
|
||||
internal void ProcessSharedAndWait(
|
||||
@@ -100,8 +94,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
in Parameters parameters)
|
||||
{
|
||||
EnsureGridFor(width, height, parameters.Quality);
|
||||
using ComputeContext context = _device.CreateComputeContext();
|
||||
RecordFullPipeline(in context, source, destination, width, height, in parameters);
|
||||
SubmitFullPipeline(source, destination, width, height, in parameters).Wait();
|
||||
}
|
||||
|
||||
internal bool Simulate(
|
||||
@@ -113,14 +106,37 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
in Parameters parameters)
|
||||
{
|
||||
var derived = BeginSimulate(canvasWidth, canvasHeight, in parameters);
|
||||
_host.RecordSilhouetteAndMaskHash(
|
||||
source, _scratch, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, in derived).Wait();
|
||||
return CompleteSimulate(canvasWidth, canvasHeight, in parameters, in derived);
|
||||
}
|
||||
|
||||
internal bool Simulate(
|
||||
ComputeResourceBinding<ReadWriteTexture2D<Bgra32, Float4>> source,
|
||||
int canvasWidth,
|
||||
int canvasHeight,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
in Parameters parameters)
|
||||
{
|
||||
var derived = BeginSimulate(canvasWidth, canvasHeight, in parameters);
|
||||
_host.RecordSharedSilhouetteAndMaskHash(
|
||||
source, _scratch, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, in derived).Wait();
|
||||
return CompleteSimulate(canvasWidth, canvasHeight, in parameters, in derived);
|
||||
}
|
||||
|
||||
private DerivedValues BeginSimulate(int canvasWidth, int canvasHeight, in Parameters parameters)
|
||||
{
|
||||
EnsureGridFor(canvasWidth, canvasHeight, parameters.Quality);
|
||||
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
||||
using (ComputeContext context = _device.CreateComputeContext())
|
||||
{
|
||||
RecordSilhouetteStage(in context, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, in derived);
|
||||
RecordMaskHashStage(in context);
|
||||
}
|
||||
return Derive(canvasWidth, canvasHeight, in parameters);
|
||||
}
|
||||
|
||||
private bool CompleteSimulate(int canvasWidth, int canvasHeight, in Parameters parameters, in DerivedValues derived)
|
||||
{
|
||||
_scratchReadBack.CopyFrom(_scratch);
|
||||
var hashed = _scratchReadBack.Span;
|
||||
_cachedLitCount = hashed[UkiyoeSettings.ScratchLitCount];
|
||||
@@ -141,8 +157,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
if (_structureKey == key)
|
||||
return false;
|
||||
|
||||
using (ComputeContext context = _device.CreateComputeContext())
|
||||
RecordStructureStage(in context, in derived);
|
||||
_host.RecordStructure(_scratch, _gridWidth, _gridHeight, in derived).Wait();
|
||||
_structureKey = key;
|
||||
return true;
|
||||
}
|
||||
@@ -177,12 +192,21 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
in Parameters parameters)
|
||||
{
|
||||
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
||||
using ComputeContext context = _device.CreateComputeContext();
|
||||
RecordRenderStage(in context, output, rect, in derived, in parameters);
|
||||
_host.RecordRender(output, in rect, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||
}
|
||||
|
||||
private void RecordFullPipeline(
|
||||
in ComputeContext context,
|
||||
internal void RenderVisible(
|
||||
ComputeResourceBinding<ReadWriteTexture2D<Bgra32, Float4>> output,
|
||||
int canvasWidth,
|
||||
int canvasHeight,
|
||||
PixelRect rect,
|
||||
in Parameters parameters)
|
||||
{
|
||||
var derived = Derive(canvasWidth, canvasHeight, in parameters);
|
||||
_host.RecordSharedRender(output, in rect, _gridWidth, _gridHeight, in derived, in parameters).Wait();
|
||||
}
|
||||
|
||||
private ComputeSubmission SubmitFullPipeline(
|
||||
ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
int width,
|
||||
@@ -191,105 +215,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
{
|
||||
_structureKey = null;
|
||||
var derived = Derive(width, height, in parameters);
|
||||
RecordSilhouetteStage(in context, source, 0, 0, width, height, in derived);
|
||||
RecordStructureStage(in context, in derived);
|
||||
RecordRenderStage(in context, output, new PixelRect(0, 0, width, height), in derived, in parameters);
|
||||
}
|
||||
|
||||
private void RecordSilhouetteStage(
|
||||
in ComputeContext context,
|
||||
ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
in DerivedValues derived)
|
||||
{
|
||||
context.For(_gridWidth, _gridHeight, new SilhouetteShader(
|
||||
source, _colorIn!, _gray!, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, _gridWidth, _gridHeight, derived.CellSize));
|
||||
context.Barrier(_colorIn!);
|
||||
context.Barrier(_gray!);
|
||||
}
|
||||
|
||||
private void RecordMaskHashStage(in ComputeContext context)
|
||||
{
|
||||
context.For(1, new MaskHashResetShader(_scratch));
|
||||
context.Barrier(_scratch);
|
||||
context.For(_gridWidth, _gridHeight, new MaskHashShader(_colorIn!, _scratch, _gridWidth, _gridHeight));
|
||||
context.Barrier(_scratch);
|
||||
}
|
||||
|
||||
private void RecordStructureStage(in ComputeContext context, in DerivedValues derived)
|
||||
{
|
||||
var gridWidth = _gridWidth;
|
||||
var gridHeight = _gridHeight;
|
||||
|
||||
context.For(1, new InitScratchShader(_scratch));
|
||||
context.Barrier(_scratch);
|
||||
context.For(gridWidth, gridHeight, new GradientShader(_gray!, _tangentA!, _gradientMagnitude!, _scratch, gridWidth, gridHeight));
|
||||
context.Barrier(_tangentA!);
|
||||
context.Barrier(_gradientMagnitude!);
|
||||
context.Barrier(_scratch);
|
||||
|
||||
var tangentIn = _tangentA!;
|
||||
var tangentOut = _tangentB!;
|
||||
for (var iteration = 0; iteration < derived.EtfIterations; iteration++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new EtfShader(tangentIn, tangentOut, _gradientMagnitude!, _scratch, gridWidth, gridHeight));
|
||||
context.Barrier(tangentOut);
|
||||
(tangentIn, tangentOut) = (tangentOut, tangentIn);
|
||||
}
|
||||
var tangent = tangentIn;
|
||||
|
||||
context.For(gridWidth, gridHeight, new CopyColorShader(_colorIn!, _colorA!, gridWidth, gridHeight));
|
||||
context.Barrier(_colorA!);
|
||||
var iterateIn = _colorA!;
|
||||
var iterateOut = _colorB!;
|
||||
for (var iteration = 0; iteration < derived.FlattenIterations; iteration++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new FlattenShader(
|
||||
_colorIn!, iterateIn, iterateOut, _gradientMagnitude!, _scratch, gridWidth, gridHeight, derived.FlattenBeta));
|
||||
context.Barrier(iterateOut);
|
||||
(iterateIn, iterateOut) = (iterateOut, iterateIn);
|
||||
}
|
||||
|
||||
for (var iteration = 0; iteration < derived.FdogIterations; iteration++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new DogShader(
|
||||
_gray!, tangent, _response!, gridWidth, gridHeight, derived.LineSigmaCells, derived.DogExtent));
|
||||
context.Barrier(_response!);
|
||||
context.For(gridWidth, gridHeight, new FlowAccumulateShader(
|
||||
_response!, tangent, _line!, gridWidth, gridHeight, derived.FlowSigma, derived.FlowExtent));
|
||||
context.Barrier(_line!);
|
||||
if (iteration < derived.FdogIterations - 1)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new SuperimposeShader(_line!, _gray!, gridWidth, gridHeight, derived.LineThreshold));
|
||||
context.Barrier(_gray!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RecordRenderStage(
|
||||
in ComputeContext context,
|
||||
ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
PixelRect rect,
|
||||
in DerivedValues derived,
|
||||
in Parameters parameters)
|
||||
{
|
||||
context.For(rect.Width, rect.Height, new RenderShader(
|
||||
_colorA!, _line!, output,
|
||||
rect.X, rect.Y, rect.Width, rect.Height, _gridWidth, _gridHeight,
|
||||
derived.CellSize,
|
||||
UkiyoeSettings.ClampPaletteLevels(parameters.PaletteLevels),
|
||||
derived.ShiftPixels,
|
||||
Math.Clamp(parameters.Baren, 0f, 1f),
|
||||
Math.Clamp(parameters.Paper, 0f, 1f),
|
||||
derived.LineThreshold,
|
||||
Math.Clamp(parameters.LineStrength, 0f, 1f),
|
||||
parameters.LineColorR,
|
||||
parameters.LineColorG,
|
||||
parameters.LineColorB,
|
||||
parameters.Seed));
|
||||
return _host.RecordFullPipeline(source, output, _scratch, width, height, _gridWidth, _gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
private DerivedValues Derive(int width, int height, in Parameters parameters)
|
||||
@@ -326,22 +252,19 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
if (_gridWidth == gridWidth && _gridHeight == gridHeight)
|
||||
return;
|
||||
|
||||
DisposeGridBuffers();
|
||||
var gridLength = gridWidth * gridHeight;
|
||||
_colorIn = _device.AllocateReadWriteBuffer<Float4>(gridLength);
|
||||
_colorA = _device.AllocateReadWriteBuffer<Float4>(gridLength);
|
||||
_colorB = _device.AllocateReadWriteBuffer<Float4>(gridLength);
|
||||
_gray = _device.AllocateReadWriteBuffer<float>(gridLength);
|
||||
_gradientMagnitude = _device.AllocateReadWriteBuffer<float>(gridLength);
|
||||
_response = _device.AllocateReadWriteBuffer<float>(gridLength);
|
||||
_line = _device.AllocateReadWriteBuffer<float>(gridLength);
|
||||
_tangentA = _device.AllocateReadWriteBuffer<Float2>(gridLength);
|
||||
_tangentB = _device.AllocateReadWriteBuffer<Float2>(gridLength);
|
||||
if (!_host.TryEnsureGrid(
|
||||
new UkiyoeGridResources.Plan(
|
||||
gridLength, gridLength, gridLength, gridLength, gridLength, gridLength, gridLength, gridLength, gridLength),
|
||||
out _))
|
||||
throw new InvalidOperationException();
|
||||
|
||||
_cachedLitCount = 0;
|
||||
_cachedBoundsMinX = int.MaxValue;
|
||||
_cachedBoundsMinY = int.MaxValue;
|
||||
_cachedBoundsMaxX = int.MinValue;
|
||||
_cachedBoundsMaxY = int.MinValue;
|
||||
_structureKey = null;
|
||||
_gridWidth = gridWidth;
|
||||
_gridHeight = gridHeight;
|
||||
}
|
||||
@@ -359,45 +282,19 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
_packedHeight = height;
|
||||
}
|
||||
|
||||
private void DisposeGridBuffers()
|
||||
{
|
||||
_colorIn?.Dispose();
|
||||
_colorA?.Dispose();
|
||||
_colorB?.Dispose();
|
||||
_gray?.Dispose();
|
||||
_gradientMagnitude?.Dispose();
|
||||
_response?.Dispose();
|
||||
_line?.Dispose();
|
||||
_tangentA?.Dispose();
|
||||
_tangentB?.Dispose();
|
||||
_colorIn = null;
|
||||
_colorA = null;
|
||||
_colorB = null;
|
||||
_gray = null;
|
||||
_gradientMagnitude = null;
|
||||
_response = null;
|
||||
_line = null;
|
||||
_tangentA = null;
|
||||
_tangentB = null;
|
||||
_cachedLitCount = 0;
|
||||
_cachedBoundsMinX = int.MaxValue;
|
||||
_cachedBoundsMinY = int.MaxValue;
|
||||
_cachedBoundsMaxX = int.MinValue;
|
||||
_cachedBoundsMaxY = int.MinValue;
|
||||
_structureKey = null;
|
||||
_gridWidth = 0;
|
||||
_gridHeight = 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeGridBuffers();
|
||||
_host.Dispose();
|
||||
_host.WaitForDisposal();
|
||||
_packedSource?.Dispose();
|
||||
_packedOutput?.Dispose();
|
||||
_packedSource = null;
|
||||
_packedOutput = null;
|
||||
_packedWidth = 0;
|
||||
_packedHeight = 0;
|
||||
_structureKey = null;
|
||||
_gridWidth = 0;
|
||||
_gridHeight = 0;
|
||||
_scratchReadBack.Dispose();
|
||||
_scratch.Dispose();
|
||||
}
|
||||
@@ -415,7 +312,7 @@ internal sealed class UkiyoePipeline : IDisposable
|
||||
float LineDetail,
|
||||
float Flatten);
|
||||
|
||||
private readonly record struct DerivedValues(
|
||||
internal readonly record struct DerivedValues(
|
||||
float CellSize,
|
||||
int EtfIterations,
|
||||
int FdogIterations,
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
using ComputeWeave;
|
||||
|
||||
namespace Ukiyoe;
|
||||
|
||||
[ComputeResourceGroup]
|
||||
internal sealed partial class UkiyoeGridResources
|
||||
{
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<Float4> ColorIn { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<Float4> ColorA { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<Float4> ColorB { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<float> Gray { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<float> GradientMagnitude { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<float> Response { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<float> Line { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<Float2> TangentA { get; }
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite)]
|
||||
internal ReadWriteBuffer<Float2> TangentB { get; }
|
||||
}
|
||||
|
||||
[ComputePipelineHost("_device", 1)]
|
||||
internal sealed partial class UkiyoePipelineHost
|
||||
{
|
||||
private readonly GraphicsDevice _device;
|
||||
|
||||
[ComputePipelineResource(ComputeResourceAccess.ReadWrite, ComputeResourceRecovery.Recompute)]
|
||||
private readonly ComputeResourceGroupSlot<UkiyoeGridResources> _grid = new();
|
||||
|
||||
[ComputePipeline]
|
||||
private void RecordFullPipeline(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||
int width,
|
||||
int height,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived,
|
||||
in UkiyoePipeline.Parameters parameters)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordSilhouetteStage(in context, grid, source, 0, 0, width, height, gridWidth, gridHeight, in derived);
|
||||
RecordStructureStage(in context, grid, scratch, gridWidth, gridHeight, in derived);
|
||||
RecordRenderStage(in context, grid, output, new UkiyoePipeline.PixelRect(0, 0, width, height), gridWidth, gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
private void RecordSilhouetteAndMaskHash(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordSilhouetteStage(in context, grid, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, in derived);
|
||||
RecordMaskHashStage(in context, grid, scratch, gridWidth, gridHeight);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
[ComputeInterop]
|
||||
private void RecordSharedSilhouetteAndMaskHash(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite, Sharing = ComputeResourceSharing.External)] ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordSilhouetteStage(in context, grid, source, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, in derived);
|
||||
RecordMaskHashStage(in context, grid, scratch, gridWidth, gridHeight);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
[ComputeInterop]
|
||||
private void RecordSharedRender(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite, Sharing = ComputeResourceSharing.External)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
in UkiyoePipeline.PixelRect rect,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived,
|
||||
in UkiyoePipeline.Parameters parameters)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordRenderStage(in context, grid, output, rect, gridWidth, gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
private void RecordStructure(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteBuffer<int> scratch,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordStructureStage(in context, grid, scratch, gridWidth, gridHeight, in derived);
|
||||
}
|
||||
|
||||
[ComputePipeline]
|
||||
private void RecordRender(
|
||||
in ComputeContext context,
|
||||
[ComputeOwnedResource(nameof(_grid))] UkiyoeGridResources grid,
|
||||
[ComputeResource(ComputeResourceAccess.ReadWrite)] ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
in UkiyoePipeline.PixelRect rect,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived,
|
||||
in UkiyoePipeline.Parameters parameters)
|
||||
{
|
||||
_ = _device;
|
||||
|
||||
RecordRenderStage(in context, grid, output, rect, gridWidth, gridHeight, in derived, in parameters);
|
||||
}
|
||||
|
||||
private static void RecordSilhouetteStage(
|
||||
in ComputeContext context,
|
||||
UkiyoeGridResources grid,
|
||||
ReadWriteTexture2D<Bgra32, Float4> source,
|
||||
int sourceOffsetX,
|
||||
int sourceOffsetY,
|
||||
int sourceWidth,
|
||||
int sourceHeight,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new SilhouetteShader(
|
||||
source, grid.ColorIn, grid.Gray, sourceOffsetX, sourceOffsetY, sourceWidth, sourceHeight, gridWidth, gridHeight, derived.CellSize));
|
||||
context.Barrier(grid.ColorIn);
|
||||
context.Barrier(grid.Gray);
|
||||
}
|
||||
|
||||
private static void RecordMaskHashStage(
|
||||
in ComputeContext context,
|
||||
UkiyoeGridResources grid,
|
||||
ReadWriteBuffer<int> scratch,
|
||||
int gridWidth,
|
||||
int gridHeight)
|
||||
{
|
||||
context.For(1, new MaskHashResetShader(scratch));
|
||||
context.Barrier(scratch);
|
||||
context.For(gridWidth, gridHeight, new MaskHashShader(grid.ColorIn, scratch, gridWidth, gridHeight));
|
||||
context.Barrier(scratch);
|
||||
}
|
||||
|
||||
private static void RecordStructureStage(
|
||||
in ComputeContext context,
|
||||
UkiyoeGridResources grid,
|
||||
ReadWriteBuffer<int> scratch,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived)
|
||||
{
|
||||
context.For(1, new InitScratchShader(scratch));
|
||||
context.Barrier(scratch);
|
||||
context.For(gridWidth, gridHeight, new GradientShader(grid.Gray, grid.TangentA, grid.GradientMagnitude, scratch, gridWidth, gridHeight));
|
||||
context.Barrier(grid.TangentA);
|
||||
context.Barrier(grid.GradientMagnitude);
|
||||
context.Barrier(scratch);
|
||||
|
||||
var tangentIn = grid.TangentA;
|
||||
var tangentOut = grid.TangentB;
|
||||
for (var iteration = 0; iteration < derived.EtfIterations; iteration++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new EtfShader(tangentIn, tangentOut, grid.GradientMagnitude, scratch, gridWidth, gridHeight));
|
||||
context.Barrier(tangentOut);
|
||||
(tangentIn, tangentOut) = (tangentOut, tangentIn);
|
||||
}
|
||||
var tangent = tangentIn;
|
||||
|
||||
context.For(gridWidth, gridHeight, new CopyColorShader(grid.ColorIn, grid.ColorA, gridWidth, gridHeight));
|
||||
context.Barrier(grid.ColorA);
|
||||
var flattenDispatchWidth = (gridWidth + UkiyoeSettings.FlattenGroupDim - 1) & ~(UkiyoeSettings.FlattenGroupDim - 1);
|
||||
var flattenDispatchHeight = (gridHeight + UkiyoeSettings.FlattenGroupDim - 1) & ~(UkiyoeSettings.FlattenGroupDim - 1);
|
||||
var iterateIn = grid.ColorA;
|
||||
var iterateOut = grid.ColorB;
|
||||
for (var iteration = 0; iteration < derived.FlattenIterations; iteration++)
|
||||
{
|
||||
context.For(flattenDispatchWidth, flattenDispatchHeight, new FlattenShader(
|
||||
grid.ColorIn, iterateIn, iterateOut, grid.GradientMagnitude, scratch, gridWidth, gridHeight, derived.FlattenBeta));
|
||||
context.Barrier(iterateOut);
|
||||
(iterateIn, iterateOut) = (iterateOut, iterateIn);
|
||||
}
|
||||
|
||||
for (var iteration = 0; iteration < derived.FdogIterations; iteration++)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new DogShader(
|
||||
grid.Gray, tangent, grid.Response, gridWidth, gridHeight, derived.LineSigmaCells, derived.DogExtent));
|
||||
context.Barrier(grid.Response);
|
||||
context.For(gridWidth, gridHeight, new FlowAccumulateShader(
|
||||
grid.Response, tangent, grid.Line, gridWidth, gridHeight, derived.FlowSigma, derived.FlowExtent));
|
||||
context.Barrier(grid.Line);
|
||||
if (iteration < derived.FdogIterations - 1)
|
||||
{
|
||||
context.For(gridWidth, gridHeight, new SuperimposeShader(grid.Line, grid.Gray, gridWidth, gridHeight, derived.LineThreshold));
|
||||
context.Barrier(grid.Gray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RecordRenderStage(
|
||||
in ComputeContext context,
|
||||
UkiyoeGridResources grid,
|
||||
ReadWriteTexture2D<Bgra32, Float4> output,
|
||||
in UkiyoePipeline.PixelRect rect,
|
||||
int gridWidth,
|
||||
int gridHeight,
|
||||
in UkiyoePipeline.DerivedValues derived,
|
||||
in UkiyoePipeline.Parameters parameters)
|
||||
{
|
||||
context.For(rect.Width, rect.Height, new RenderShader(
|
||||
grid.ColorA, grid.Line, output,
|
||||
rect.X, rect.Y, rect.Width, rect.Height, gridWidth, gridHeight,
|
||||
derived.CellSize,
|
||||
UkiyoeSettings.ClampPaletteLevels(parameters.PaletteLevels),
|
||||
derived.ShiftPixels,
|
||||
Math.Clamp(parameters.Baren, 0f, 1f),
|
||||
Math.Clamp(parameters.Paper, 0f, 1f),
|
||||
derived.LineThreshold,
|
||||
Math.Clamp(parameters.LineStrength, 0f, 1f),
|
||||
parameters.LineColorR,
|
||||
parameters.LineColorG,
|
||||
parameters.LineColorB,
|
||||
parameters.Seed));
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,9 @@ internal static class UkiyoeSettings
|
||||
public const float FlattenLumaScale = 0.3f;
|
||||
public const float FlattenGradientWeight = 0.4f;
|
||||
public const int FlattenRadius = 2;
|
||||
public const int FlattenGroupDim = 8;
|
||||
public const int FlattenTileDim = FlattenGroupDim + 2 * FlattenRadius;
|
||||
public const int FlattenTileCount = FlattenTileDim * FlattenTileDim;
|
||||
public const float QuantizeEdgeWidth = 0.18f;
|
||||
public const float ChromaScale = 0.9f;
|
||||
public const float MaximumShiftPixels = 10f;
|
||||
@@ -46,6 +49,7 @@ internal static class UkiyoeSettings
|
||||
public const int ScratchBoundsMaxY = 5;
|
||||
public const int ScratchMaskHashSum = 6;
|
||||
public const int ScratchMaskHashMix = 7;
|
||||
public const int MaximumPendingSubmissions = 32;
|
||||
|
||||
public static QualitySettings GetQuality(UkiyoeQuality quality)
|
||||
=> quality switch
|
||||
|
||||
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 400 KiB |
新しいイシューから参照
ユーザーをブロックする