Skip to content

Commit 61e2289

Browse files
committed
Demo update
1 parent d4a35fd commit 61e2289

File tree

3 files changed

+18
-47
lines changed

3 files changed

+18
-47
lines changed

BlazorWASMWebGPUComputeDemo/Layout/NavMenu.razor

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,7 @@
1111
<nav class="flex-column">
1212
<div class="nav-item px-3">
1313
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
14-
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
15-
</NavLink>
16-
</div>
17-
<div class="nav-item px-3">
18-
<NavLink class="nav-link" href="counter">
19-
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
20-
</NavLink>
21-
</div>
22-
<div class="nav-item px-3">
23-
<NavLink class="nav-link" href="weather">
24-
<span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
14+
<span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Compute 1
2515
</NavLink>
2616
</div>
2717
</nav>

BlazorWASMWebGPUComputeDemo/Pages/ComputeTutorial01.razor

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
<div style="padding: 1rem;">
99
<p>This demo is based off the tutorial linked below.</p>
1010
<a href="https://webgpufundamentals.org/webgpu/lessons/webgpu-fundamentals.html#run-computations-on-the-gpu">Run computations on the GPU</a>
11+
<p>
12+
This basic example demonstrates a very basiccompute shader that simple multiplies the input data by 2 and returns the result.
13+
</p>
1114
</div>
1215
<div style="padding: 1rem;">
13-
<button class="btn btn-primary" disabled="@_running" @onclick="Run">Click me</button>
16+
<button class="btn btn-primary" disabled="@_running" @onclick="Run">Run</button>
1417
</div>
1518
<div style="padding: 1rem;">
1619
<pre>
@@ -77,8 +80,13 @@
7780
}
7881
});
7982

80-
using var input = new Float32Array(new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
81-
var inputByteLength = input.ByteLength;
83+
// input data
84+
var input = new float[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
85+
Log($@"Input: {string.Join(", ", input)}");
86+
87+
88+
using var inputFloatArray = new Float32Array(input);
89+
var inputByteLength = inputFloatArray.ByteLength;
8290

8391
// create a buffer on the GPU to hold our computation
8492
// input and output
@@ -88,8 +96,9 @@
8896
Size = (ulong)inputByteLength,
8997
Usage = GPUBufferUsage.Storage | GPUBufferUsage.CopySrc | GPUBufferUsage.CopyDst,
9098
});
99+
91100
// Copy our input data to that buffer
92-
device.Queue.WriteBuffer(workBuffer, 0, input);
101+
device.Queue.WriteBuffer(workBuffer, 0, inputFloatArray);
93102

94103
using var resultBuffer = device.CreateBuffer(new GPUBufferDescriptor
95104
{
@@ -135,18 +144,17 @@
135144

136145
// Read the results
137146
await resultBuffer.MapAsync(GPUMapMode.Read);
138-
using var result = new Float32Array(resultBuffer.GetMappedRange());
139-
140-
float[] resultF = result.ToArray();
147+
using var outputFloatArray = new Float32Array(resultBuffer.GetMappedRange());
141148

142-
Log($@"Input: {string.Join(", ", input.ToArray())}");
143-
Log($@"Result: {string.Join(", ", resultF)}");
149+
float[] output = outputFloatArray.ToArray();
150+
Log($@"Result: {string.Join(", ", output)}");
144151

145152
resultBuffer.Unmap();
146153
}
147154
finally
148155
{
149156
_running = false;
157+
StateHasChanged();
150158
}
151159
}
152160
}

BlazorWASMWebGPUComputeDemo/wwwroot/sample-data/weather.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)