SpawnDev.ILGPU.WebGPU 1.0.0-preview.3

This is a prerelease version of SpawnDev.ILGPU.WebGPU.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SpawnDev.ILGPU.WebGPU --version 1.0.0-preview.3
                    
NuGet\Install-Package SpawnDev.ILGPU.WebGPU -Version 1.0.0-preview.3
                    
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="SpawnDev.ILGPU.WebGPU" Version="1.0.0-preview.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpawnDev.ILGPU.WebGPU" Version="1.0.0-preview.3" />
                    
Directory.Packages.props
<PackageReference Include="SpawnDev.ILGPU.WebGPU" />
                    
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 SpawnDev.ILGPU.WebGPU --version 1.0.0-preview.3
                    
#r "nuget: SpawnDev.ILGPU.WebGPU, 1.0.0-preview.3"
                    
#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 SpawnDev.ILGPU.WebGPU@1.0.0-preview.3
                    
#: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=SpawnDev.ILGPU.WebGPU&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=SpawnDev.ILGPU.WebGPU&version=1.0.0-preview.3&prerelease
                    
Install as a Cake Tool

SpawnDev.ILGPU.WebGPU

NuGet

Run ILGPU kernels directly in the browser using WebGPU!

SpawnDev.ILGPU.WebGPU is a WebGPU backend for ILGPU that enables GPU-accelerated compute in Blazor WebAssembly applications. Write your GPU kernels once in C# and run them on any WebGPU-capable browser.

Features

  • ILGPU-compatible - Use familiar ILGPU APIs (ArrayView, Index1D/2D/3D, math intrinsics, etc.)
  • WGSL transpilation - C# kernels are automatically compiled to WebGPU Shading Language (WGSL)
  • Blazor WebAssembly - Seamless integration via SpawnDev.BlazorJS
  • Shared memory & atomics - Supports workgroup shared memory, barriers, and atomic operations
  • No native dependencies - Entirely written in C#

Installation

dotnet add package SpawnDev.ILGPU.WebGPU

Quick Start

using ILGPU;
using ILGPU.Runtime;
using SpawnDev.ILGPU.WebGPU;

// Initialize ILGPU context with WebGPU backend
var builder = Context.Create();
await builder.WebGPUAsync();
using var context = builder.ToContext();

// Get WebGPU device and create accelerator
var devices = context.GetWebGPUDevices();
var device = devices[0];
using var accelerator = await device.CreateAcceleratorAsync(context);

// Allocate buffers
int length = 64;
var a = Enumerable.Range(0, length).Select(i => (float)i).ToArray();
var b = Enumerable.Range(0, length).Select(i => (float)i * 2.0f).ToArray();

using var bufA = accelerator.Allocate1D(a);
using var bufB = accelerator.Allocate1D(b);
using var bufC = accelerator.Allocate1D<float>(length);

// Load and execute kernel
var kernel = accelerator.LoadAutoGroupedStreamKernel<Index1D, ArrayView<float>, ArrayView<float>, ArrayView<float>>(VectorAddKernel);
kernel((Index1D)length, bufA.View, bufB.View, bufC.View);

// Wait for GPU to complete (async required in Blazor WASM)
await accelerator.SynchronizeAsync();

// Define the kernel
static void VectorAddKernel(Index1D index, ArrayView<float> a, ArrayView<float> b, ArrayView<float> c)
{
    c[index] = a[index] + b[index];
}

Demo Application

The demo application is located in SpawnDev.ILGPU.WebGPU.Demo and showcases:

  • GPU compute tasks running in Blazor WebAssembly
  • Interactive Mandelbrot renderer
  • Comprehensive unit tests at /tests

Running the Demo

cd SpawnDev.ILGPU.WebGPU.Demo
dotnet run

Navigate to https://localhost:5181 in a WebGPU-capable browser (Chrome, Edge, or Firefox Nightly).

Testing

Browser Tests

Start the demo app and navigate to /tests to run the unit test suite.

Automated Tests (Playwright)

# Windows
_test.bat

# Linux/macOS
./_test.sh

The PlaywrightTestRunner runs tests in a headless browser. To view the browser during tests, uncomment Environment.SetEnvironmentVariable("HEADED", "1"); in PlaywrightTestRunner/GlobalSetup.cs.

Browser Requirements

WebGPU is required. Supported browsers:

  • Chrome 113+
  • Edge 113+
  • Firefox Nightly (with dom.webgpu.enabled flag)

Known Limitations

  • Some advanced ILGPU features may not yet be supported
  • Subgroups extension not available in all browsers
  • Dynamic shared memory requires Pipeline Overridable Constants (not yet implemented)

Async Synchronization

In Blazor WebAssembly, the main thread cannot block. Use SynchronizeAsync() instead of Synchronize():

// ❌ Don't use - non-blocking in Blazor WASM
accelerator.Synchronize();

// ✅ Use async version
await accelerator.SynchronizeAsync();

The standard Synchronize() method will log a warning and return immediately without waiting.

License

This project is licensed under the same terms as ILGPU. See LICENSE for details.

Resources

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 82 2/7/2026
1.2.0 75 2/6/2026
1.1.0 70 2/6/2026
1.0.0 78 2/6/2026
1.0.0-preview.5 47 2/6/2026
1.0.0-preview.4 35 2/6/2026
1.0.0-preview.3 33 2/5/2026
1.0.0-preview.2 39 2/5/2026
1.0.0-preview.1 39 2/5/2026