Skip to content

Use GPUBuffer in GPUBindingResource #514

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions sample/a-buffer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,21 +448,15 @@ const configure = () => {
entries: [
{
binding: 0,
resource: {
buffer: uniformBuffer,
},
resource: uniformBuffer,
},
{
binding: 1,
resource: {
buffer: headsBuffer,
},
resource: headsBuffer,
},
{
binding: 2,
resource: {
buffer: linkedListBuffer,
},
resource: linkedListBuffer,
},
{
binding: 3,
Expand All @@ -484,21 +478,15 @@ const configure = () => {
entries: [
{
binding: 0,
resource: {
buffer: uniformBuffer,
},
resource: uniformBuffer,
},
{
binding: 1,
resource: {
buffer: headsBuffer,
},
resource: headsBuffer,
},
{
binding: 2,
resource: {
buffer: linkedListBuffer,
},
resource: linkedListBuffer,
},
{
binding: 3,
Expand Down
8 changes: 4 additions & 4 deletions sample/blending/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const srcBindGroupUnpremultipliedAlpha = device.createBindGroup({
entries: [
{ binding: 0, resource: sampler },
{ binding: 1, resource: srcTextureUnpremultipliedAlpha.createView() },
{ binding: 2, resource: { buffer: srcUniform.buffer } },
{ binding: 2, resource: srcUniform.buffer },
],
});

Expand All @@ -203,7 +203,7 @@ const dstBindGroupUnpremultipliedAlpha = device.createBindGroup({
entries: [
{ binding: 0, resource: sampler },
{ binding: 1, resource: dstTextureUnpremultipliedAlpha.createView() },
{ binding: 2, resource: { buffer: dstUniform.buffer } },
{ binding: 2, resource: dstUniform.buffer },
],
});

Expand All @@ -212,7 +212,7 @@ const srcBindGroupPremultipliedAlpha = device.createBindGroup({
entries: [
{ binding: 0, resource: sampler },
{ binding: 1, resource: srcTexturePremultipliedAlpha.createView() },
{ binding: 2, resource: { buffer: srcUniform.buffer } },
{ binding: 2, resource: srcUniform.buffer },
],
});

Expand All @@ -221,7 +221,7 @@ const dstBindGroupPremultipliedAlpha = device.createBindGroup({
entries: [
{ binding: 0, resource: sampler },
{ binding: 1, resource: dstTexturePremultipliedAlpha.createView() },
{ binding: 2, resource: { buffer: dstUniform.buffer } },
{ binding: 2, resource: dstUniform.buffer },
],
});

Expand Down
17 changes: 3 additions & 14 deletions sample/cameras/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,9 @@ const sampler = device.createSampler({
const uniformBindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: uniformBuffer,
},
},
{
binding: 1,
resource: sampler,
},
{
binding: 2,
resource: cubeTexture.createView(),
},
{ binding: 0, resource: uniformBuffer },
{ binding: 1, resource: sampler },
{ binding: 2, resource: cubeTexture.createView() },
],
});

Expand Down
25 changes: 3 additions & 22 deletions sample/computeBoids/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,9 @@ for (let i = 0; i < 2; ++i) {
particleBindGroups[i] = device.createBindGroup({
layout: computePipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: simParamBuffer,
},
},
{
binding: 1,
resource: {
buffer: particleBuffers[i],
offset: 0,
size: initialParticleData.byteLength,
},
},
{
binding: 2,
resource: {
buffer: particleBuffers[(i + 1) % 2],
offset: 0,
size: initialParticleData.byteLength,
},
},
{ binding: 0, resource: simParamBuffer },
{ binding: 1, resource: particleBuffers[i] },
{ binding: 2, resource: particleBuffers[(i + 1) % 2] },
],
});
}
Expand Down
12 changes: 2 additions & 10 deletions sample/cornell/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,12 @@ export default class Common {
{
// common_uniforms
binding: 0,
resource: {
buffer: this.uniformBuffer,
offset: 0,
size: this.uniformBuffer.size,
},
resource: this.uniformBuffer,
},
{
// quads
binding: 1,
resource: {
buffer: quads,
offset: 0,
size: quads.size,
},
resource: quads,
},
],
});
Expand Down
10 changes: 2 additions & 8 deletions sample/cornell/radiosity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ export default class Radiosity {
{
// accumulation buffer
binding: 0,
resource: {
buffer: this.accumulationBuffer,
size: this.accumulationBuffer.size,
},
resource: this.accumulationBuffer,
},
{
// lightmap
Expand All @@ -124,10 +121,7 @@ export default class Radiosity {
{
// radiosity_uniforms
binding: 2,
resource: {
buffer: this.uniformBuffer,
size: this.uniformBuffer.size,
},
resource: this.uniformBuffer,
},
],
});
Expand Down
6 changes: 1 addition & 5 deletions sample/cubemap/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,7 @@ const uniformBindGroup = device.createBindGroup({
entries: [
{
binding: 0,
resource: {
buffer: uniformBuffer,
offset: 0,
size: uniformBufferSize,
},
resource: uniformBuffer,
},
{
binding: 1,
Expand Down
53 changes: 11 additions & 42 deletions sample/deferredRendering/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,36 +334,17 @@ const cameraUniformBuffer = device.createBuffer({
const sceneUniformBindGroup = device.createBindGroup({
layout: writeGBuffersPipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: modelUniformBuffer,
},
},
{
binding: 1,
resource: {
buffer: cameraUniformBuffer,
},
},
{ binding: 0, resource: modelUniformBuffer },
{ binding: 1, resource: cameraUniformBuffer },
],
});

const gBufferTexturesBindGroup = device.createBindGroup({
layout: gBufferTexturesBindGroupLayout,
entries: [
{
binding: 0,
resource: gBufferTextureViews[0],
},
{
binding: 1,
resource: gBufferTextureViews[1],
},
{
binding: 2,
resource: gBufferTextureViews[2],
},
{ binding: 0, resource: gBufferTextureViews[0] },
{ binding: 1, resource: gBufferTextureViews[1] },
{ binding: 2, resource: gBufferTextureViews[2] },
],
});

Expand Down Expand Up @@ -431,21 +412,15 @@ const lightsBufferBindGroup = device.createBindGroup({
entries: [
{
binding: 0,
resource: {
buffer: lightsBuffer,
},
resource: lightsBuffer,
},
{
binding: 1,
resource: {
buffer: configUniformBuffer,
},
resource: configUniformBuffer,
},
{
binding: 2,
resource: {
buffer: cameraUniformBuffer,
},
resource: cameraUniformBuffer,
},
],
});
Expand All @@ -454,21 +429,15 @@ const lightsBufferComputeBindGroup = device.createBindGroup({
entries: [
{
binding: 0,
resource: {
buffer: lightsBuffer,
},
resource: lightsBuffer,
},
{
binding: 1,
resource: {
buffer: configUniformBuffer,
},
resource: configUniformBuffer,
},
{
binding: 2,
resource: {
buffer: lightExtentBuffer,
},
resource: lightExtentBuffer,
},
],
});
Expand Down
17 changes: 3 additions & 14 deletions sample/fractalCube/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,9 @@ const sampler = device.createSampler({
const uniformBindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: {
buffer: uniformBuffer,
},
},
{
binding: 1,
resource: sampler,
},
{
binding: 2,
resource: cubeTexture.createView(),
},
{ binding: 0, resource: uniformBuffer },
{ binding: 1, resource: sampler },
{ binding: 2, resource: cubeTexture.createView() },
],
});

Expand Down
18 changes: 7 additions & 11 deletions sample/gameOfLife/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,18 @@ function resetGameData() {
const bindGroup0 = device.createBindGroup({
layout: bindGroupLayoutCompute,
entries: [
{ binding: 0, resource: { buffer: sizeBuffer } },
{ binding: 1, resource: { buffer: buffer0 } },
{ binding: 2, resource: { buffer: buffer1 } },
{ binding: 0, resource: sizeBuffer },
{ binding: 1, resource: buffer0 },
{ binding: 2, resource: buffer1 },
],
});

const bindGroup1 = device.createBindGroup({
layout: bindGroupLayoutCompute,
entries: [
{ binding: 0, resource: { buffer: sizeBuffer } },
{ binding: 1, resource: { buffer: buffer1 } },
{ binding: 2, resource: { buffer: buffer0 } },
{ binding: 0, resource: sizeBuffer },
{ binding: 1, resource: buffer1 },
{ binding: 2, resource: buffer0 },
],
});

Expand Down Expand Up @@ -210,11 +210,7 @@ function resetGameData() {
entries: [
{
binding: 0,
resource: {
buffer: sizeBuffer,
offset: 0,
size: 2 * Uint32Array.BYTES_PER_ELEMENT,
},
resource: sizeBuffer,
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion sample/generateMipmap/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const objects = textures.map(({ texture, viewDimension }) => {
const bindGroup = device.createBindGroup({
layout: pipeline.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: { buffer: uniformBuffer } },
{ binding: 0, resource: uniformBuffer },
{ binding: 1, resource: sampler },
{
binding: 2,
Expand Down
Loading