ComputeWeave 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ComputeWeave --version 1.0.0
                    
NuGet\Install-Package ComputeWeave -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ComputeWeave" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ComputeWeave" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ComputeWeave" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ComputeWeave --version 1.0.0
                    
#r "nuget: ComputeWeave, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ComputeWeave@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ComputeWeave&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ComputeWeave&version=1.0.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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