ComputeWeave 1.0.0
See the version list below for details.
dotnet add package ComputeWeave --version 1.0.0
NuGet\Install-Package ComputeWeave -Version 1.0.0
<PackageReference Include="ComputeWeave" Version="1.0.0" />
<PackageVersion Include="ComputeWeave" Version="1.0.0" />
<PackageReference Include="ComputeWeave" />
paket add ComputeWeave --version 1.0.0
#r "nuget: ComputeWeave, 1.0.0"
#:package ComputeWeave@1.0.0
#addin nuget:?package=ComputeWeave&version=1.0.0
#tool nuget:?package=ComputeWeave&version=1.0.0
ComputeWeave
DirectX 12 の計算シェーダーを C# だけで記述して GPU 上で実行するための .NET ライブラリです。GPU デバイスの取得、バッファとテクスチャの確保、メインメモリとの転送、シェーダー本体の記述までを C# で完結でき、HLSL はソースジェネレーターが生成します。
公開 API の入口は GraphicsDevice 型です。GraphicsDevice.GetDefault() が現在の環境の主 GPU デバイスを返します。DirectX 12 に対応した GPU が無い環境では WARP デバイスへ自動的に切り替わり、シェーダーは CPU 上のエミュレーションで動作します。フォールバック経路を自分で書く必要はありません。
使い方
バッファの全要素を 2 倍にするシェーダーを例にします。まず GPU バッファを確保し、データを転送します。
int[] array = [.. Enumerable.Range(1, 100)];
using ReadWriteBuffer<int> buffer = GraphicsDevice.GetDefault().AllocateReadWriteBuffer(array);
AllocateReadWriteBuffer は入力配列と同じ長さの ReadWriteBuffer<T> を確保し、内容を転送します。要素型や長さの異なるオーバーロードも用意しています。
次にシェーダーを定義します。IComputeShader を実装する partial struct として宣言し、[ThreadGroupSize] でディスパッチ構成を、[GeneratedComputeShaderDescriptor] でコード生成の対象であることを指定します。partial はコード生成に必要なので省略できません。フィールドはそのまま GPU へ渡す値になります。
[ThreadGroupSize(DefaultThreadGroupSizes.X)]
[GeneratedComputeShaderDescriptor]
public readonly partial struct MultiplyByTwo(ReadWriteBuffer<int> buffer) : IComputeShader
{
public void Execute()
{
buffer[ThreadIds.X] *= 2;
}
}
この例ではプライマリコンストラクターを使っていますが、フィールドを明示して通常のコンストラクターで設定しても構いません。ThreadIds はシェーダー本体からディスパッチ情報を参照するための特別な型で、ここでは for 文の添字に相当する値を返します。
最後にシェーダーを実行し、結果を読み戻します。
GraphicsDevice.GetDefault().For(buffer.Length, new MultiplyByTwo(buffer));
buffer.CopyTo(array);
詳細
その他の機能は GitHub リポジトリを参照してください。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- ComputeWeave.Core (>= 1.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on ComputeWeave:
| Package | Downloads |
|---|---|
|
ComputeWeave.D3D12MemoryAllocator
An extension library for ComputeWeave that uses D3D12MA for graphics resource allocation. |
|
|
ComputeWeave.Dxc
An extension library for ComputeWeave that includes the DXC compiler and enables shader reflection. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.4.1 | 84 | 8/11/2026 |
| 1.4.0 | 98 | 8/10/2026 |
| 1.3.0 | 95 | 8/8/2026 |
| 1.2.4 | 98 | 8/7/2026 |
| 1.2.3 | 99 | 8/7/2026 |
| 1.2.2 | 102 | 8/6/2026 |
| 1.2.1 | 106 | 8/6/2026 |
| 1.2.0 | 122 | 8/3/2026 |
| 1.1.4 | 124 | 8/2/2026 |
| 1.1.3 | 118 | 8/2/2026 |
| 1.1.2 | 131 | 8/2/2026 |
| 1.1.1 | 126 | 8/2/2026 |
| 1.1.0 | 134 | 8/1/2026 |
| 1.0.3 | 118 | 8/1/2026 |
| 1.0.2 | 116 | 8/1/2026 |
| 1.0.1 | 113 | 8/1/2026 |
| 1.0.0 | 123 | 8/1/2026 |