Skip to content

Commit

Permalink
Release (#37)
Browse files Browse the repository at this point in the history
* Fix scissor (#35)

* fix: size in storage bindings can be undefined

* chore: commit changeset

* chore(release): bump version (#36)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent 173aa2e commit afa93c4
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-device-api

## 1.2.2

### Patch Changes

- d627fe8: Size in storage bindings can be undefined.

## 1.2.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ It is implemented using WebGL1/2 & WebGPU underneath and inspired by [noclip](ht

- [API](#api)
- [Shader Language](#shader-language)
- [Observable Examples](https://observablehq.com/@strawberry-vis/gallery)
- [Observable Examples](https://observablehq.com/@antv/g-device-api)

## Installing

Expand Down
102 changes: 102 additions & 0 deletions examples/demos/add-2-vectors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import {
DeviceContribution,
VertexStepMode,
Format,
TransparentWhite,
Buffer,
Bindings,
BufferUsage,
} from '../../src';
import { initExample } from './utils';

/**
* Use Compute Shader with WebGPU
* @see https://webgpu.github.io/webgpu-samples/samples/computeBoids#main.ts
*/

export async function render(
deviceContribution: DeviceContribution,
$canvas: HTMLCanvasElement,
useRAF = true,
) {
// create swap chain and get device
const swapChain = await deviceContribution.createSwapChain($canvas);
swapChain.configureSwapChain($canvas.width, $canvas.height);
const device = swapChain.getDevice();

const computeProgram = device.createProgram({
compute: {
wgsl: `
`,
},
});

const program = device.createProgram({
compute: {
wgsl: `
@binding(0) @group(0) var<storage, read_write> input : array<i32>;
@binding(1) @group(0) var<storage, read_write> output : array<i32>;
@compute @workgroup_size(8, 8)
fn main(
@builtin(global_invocation_id) global_id : vec3<u32>
) {
var index = global_id.x;
output[index] = input[index] + output[index];
}
`,
},
});

const inputBuffer = device.createBuffer({
usage: BufferUsage.STORAGE | BufferUsage.COPY_SRC,
viewOrSize: new Int32Array([1, 2, 3, 4]),
});
const outputBuffer = device.createBuffer({
usage: BufferUsage.STORAGE | BufferUsage.COPY_SRC,
viewOrSize: new Int32Array([1, 2, 3, 4]),
});

const pipeline = device.createComputePipeline({
inputLayout: null,
program,
});
const bindings = device.createBindings({
pipeline,
storageBufferBindings: [
{
binding: 0,
buffer: inputBuffer,
},
{
binding: 1,
buffer: outputBuffer,
},
],
});

const computePass = device.createComputePass();
computePass.setPipeline(pipeline);
computePass.setBindings(bindings);
computePass.dispatchWorkgroups(1);
device.submitPass(computePass);

const readback = device.createReadback();
const output = await readback.readBuffer(outputBuffer);
console.log(output);

return () => {
program.destroy();
device.destroy();

// For debug.
device.checkForLeaks();
};
}

export async function Add2Vectors($container: HTMLDivElement) {
return initExample($container, render, {
targets: ['webgpu'],
default: 'webgpu',
});
}
1 change: 1 addition & 0 deletions examples/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export { TexturedCube } from './textured-cube';
export { Sampler } from './sampler';
export { InstancedCubes } from './instanced-cubes';
export { Cubemap } from './cubemap';
export { Add2Vectors } from './add-2-vectors';
export { ComputeBoids } from './compute-boids';
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-device-api",
"version": "1.2.1",
"version": "1.2.2",
"description": "A Device API references WebGPU implementations",
"keywords": [
"antv",
Expand Down
3 changes: 1 addition & 2 deletions src/webgpu/Bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ export class Bindings_WebGPU extends ResourceBase_WebGPU implements Bindings {
for (let i = 0; i < storageBufferBindings.length; i++) {
const { binding, size, offset, buffer } =
descriptor.storageBufferBindings[i];
assert(size > 0);
const gpuBufferBinding: GPUBufferBinding = {
buffer: getPlatformBuffer(buffer),
offset: offset ?? 0,
size: size,
size,
};
gpuBindGroupEntries[0].push({
binding: binding ?? numBindings++,
Expand Down

0 comments on commit afa93c4

Please sign in to comment.