Skip to content

Seeking for a WebGPU integration sample #422

Description

@juj

In WebGPU, to load a PNG/JPG/WebP texture that the browser supports built-in, one will do

function downloadTexture(url, webGpuDevice) {
  return fetch(url)
    .then(r => r.blob())
    .then(blob => createImageBitmap(blob, { colorSpaceConversion: 'none', premultiplyAlpha: 'none' }))
    .then(bmp => {
    var texture = webGpuDevice.createTexture({
      size: [bmp.width, bmp.height],
      format: "rgba8unorm-srgb",
      usage: GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC | GPUTextureUsage.RENDER_ATTACHMENT
    });
    webGpuDevice.queue.copyExternalImageToTexture(
      { source: bmp },
      { texture },
      [bmp.width, bmp.height]
    );
    return texture;
  });
}

I am seeking to find a replacement of the above function, i.e. a downloadBasisTexture(url, webGpuDevice) that would be a drop-in replacement for the above function. Does such a code example exist that would be a breeze to integrate?

What I'd like the function to do, is to encapsulate downloading the basis_transcoder.js/.wasm on demand on first texture download, if the transcoder hasn't been downloaded yet, and then examine the passed webGpuDevice handle to find out what the best target to transcode to is.

Before I start digging to develop such an API, I wonder if this might have been done yet already - that I'd be re-doing something that already exists?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions