-
-
Notifications
You must be signed in to change notification settings - Fork 52
feat: Add @typegpu/sort scaffolding with simple bitonic sort implementation
#2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2aedf7e
31949f1
c1ee033
5d4080f
2733e82
cb1ae64
355c073
15b863c
7993706
a37a8af
9fc46ad
f64584d
d95317d
f7d1ec3
c43b383
366cfc4
d14a742
3b43ae0
a728984
57b6e07
fa324ad
63794d3
c15fa83
313d1ef
c39bc77
3b27efb
390e507
eaa4538
4d16af0
ab986e4
96edde4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <canvas></canvas> | ||
| <div id="sort-overlay" hidden> | ||
| <div id="sort-spinner"></div> | ||
| <span id="sort-status"></span> | ||
| </div> | ||
| <style> | ||
| #sort-overlay { | ||
| position: absolute; | ||
| inset: 0; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| gap: 12px; | ||
| backdrop-filter: blur(8px); | ||
| background: rgba(23, 23, 36, 0.5); | ||
| opacity: 0; | ||
| transition: opacity 0.3s ease-in-out; | ||
| } | ||
|
|
||
| #sort-overlay:not([hidden]) { | ||
| display: flex; | ||
| } | ||
|
|
||
| #sort-overlay.visible { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| #sort-spinner { | ||
| width: 40px; | ||
| height: 40px; | ||
| border: 3px solid #2e295f; | ||
| border-top-color: #6453d2; | ||
| border-radius: 50%; | ||
| animation: spin 0.8s linear infinite; | ||
| } | ||
|
|
||
| #sort-status { | ||
| color: #c3c4f1; | ||
| font-size: 0.875rem; | ||
| font-family: 'Aeonik', sans-serif; | ||
| } | ||
|
|
||
| @keyframes spin { | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| } | ||
| </style> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,282 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import tgpu, { d, std } from 'typegpu'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type BitonicSorter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type BitonicSorterOptions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createBitonicSorter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| decomposeWorkgroups, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from '@typegpu/sort'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { randf } from '@typegpu/noise'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { fullScreenTriangle } from 'typegpu/common'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defineControls } from '../../common/defineControls.ts'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const maxBufferSize = await navigator.gpu.requestAdapter().then((adapter) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!adapter) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new Error('No GPU adapter found'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const limits = adapter.limits; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Math.min(limits.maxStorageBufferBindingSize, limits.maxBufferSize); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const root = await tgpu.init({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optionalFeatures: ['timestamp-query'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| requiredLimits: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxStorageBufferBindingSize: maxBufferSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| maxBufferSize: maxBufferSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+28
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const maxBufferSize = await navigator.gpu.requestAdapter().then((adapter) => { | |
| if (!adapter) { | |
| throw new Error('No GPU adapter found'); | |
| } | |
| const limits = adapter.limits; | |
| return Math.min(limits.maxStorageBufferBindingSize, limits.maxBufferSize); | |
| }); | |
| const root = await tgpu.init({ | |
| device: { | |
| optionalFeatures: ['timestamp-query'], | |
| requiredLimits: { | |
| maxStorageBufferBindingSize: maxBufferSize, | |
| maxBufferSize: maxBufferSize, | |
| }, | |
| }, | |
| }); | |
| const adapter = await navigator.gpu.requestAdapter(); | |
| if (!adapter) { | |
| throw new Error('No GPU adapter found'); | |
| } | |
| const limits = adapter.limits; | |
| const maxBufferSize = Math.min( | |
| limits.maxStorageBufferBindingSize, | |
| limits.maxBufferSize, | |
| ); | |
| const requiredFeatures: GPUFeatureName[] = []; | |
| if (adapter.features.has('timestamp-query' as GPUFeatureName)) { | |
| requiredFeatures.push('timestamp-query'); | |
| } | |
| const device = await adapter.requestDevice({ | |
| requiredLimits: { | |
| maxStorageBufferBindingSize: maxBufferSize, | |
| maxBufferSize: maxBufferSize, | |
| }, | |
| requiredFeatures, | |
| }); | |
| const root = await tgpu.initFromDevice(device); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "title": "Bitonic Sort", | ||
| "category": "algorithms", | ||
| "tags": ["experimental", "compute"] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.