WebGPU의 새로운 기능 (Chrome 118)

François Beaufort
François Beaufort

copyExternalImageToTexture()에서 HTMLImageElement 및 ImageData 지원

GPUQueuecopyExternalImageToTexture() 메서드를 사용하면 소스 이미지, 동영상 또는 캔버스에서 가져온 스냅샷을 지정된 GPUTexture에 복사할 수 있습니다. 이제 HTMLImageElementImageData 객체를 소스로 전달할 수 있습니다. 다음 예와 chromium:1471372 문제를 참고하세요.

// Fetch and decode image.
const source = document.createElement("img");
source.src = "my-image.png";
await source.decode();

// Create destination texture.
const size = [source.width, source.height];
const texture = myDevice.createTexture({
 size,
 format: "rgba8unorm",
 usage:
   GPUTextureUsage.COPY_DST |
   GPUTextureUsage.RENDER_ATTACHMENT |
   GPUTextureUsage.TEXTURE_BINDING,
});

// Copies a snapshot taken from the source image into a texture.
myDevice.queue.copyExternalImageToTexture({ source }, { texture }, size);

읽기-쓰기 및 읽기 전용 저장소 텍스처 실험 지원

스토리지 텍스처 바인딩 유형을 사용하면 샘플링 없이 텍스처 읽기를 수행하고 셰이더의 임의의 위치에 저장할 수 있습니다. GPUAdapter에서 "chromium-experimental-read-write-storage-texture" 기능을 사용할 수 있는 경우 이제 이 기능을 사용하여 GPUDevice를 요청하고 바인드 그룹 레이아웃을 만들 때 GPUStorageTexture 액세스를 "read-write" 또는 "read-only"로 설정할 수 있습니다. 이전에는 "write-only"로 제한되었습니다.

이를 활용하려면 enable chromium_experimental_read_write_storage_texture를 사용하여 WGSL 코드에서 이 확장 프로그램을 명시적으로 사용 설정해야 합니다. 사용 설정하면 저장소 텍스처에 read_writeread 액세스 한정자를 사용할 수 있고, textureLoad()textureStore() 내장 함수가 적절하게 작동하며, 새로운 textureBarrier() 내장 함수를 사용하여 작업 그룹의 텍스처 메모리 액세스를 동기화할 수 있습니다. 다음 예와 issue dawn:1972를 참고하세요.

이 기능은 아직 실험 단계이며 변경될 수 있습니다. 표준화 중이지만 --enable-dawn-features=allow_unsafe_apis 플래그와 함께 Chrome을 실행하여 사용할 수 있도록 하세요.

const feature = "chromium-experimental-read-write-storage-texture";
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has(feature)) {
  throw new Error("Read-write storage texture support is not available");
}
// Explicitly request read-write storage texture support.
const device = await adapter.requestDevice({
  requiredFeatures: [feature],
});

const bindGroupLayout = device.createBindGroupLayout({
  entries: [{
    binding: 0,
    visibility: GPUShaderStage.COMPUTE,
    storageTexture: {
      access: "read-write", // <-- New!
      format: "r32uint",
    },
  }],
});

const shaderModule = device.createShaderModule({ code: `
  enable chromium_experimental_read_write_storage_texture;
  @group(0) @binding(0) var tex : texture_storage_2d<r32uint, read_write>;

  @compute @workgroup_size(1, 1)
  fn main(@builtin(local_invocation_id) local_id: vec3u) {
    var data = textureLoad(tex, vec2i(local_id.xy));
    data.x *= 2;
    textureStore(tex, vec2i(local_id.xy), data);
  }`,
});

// You can now create a compute pipeline with this shader module and
// send the appropriate commands to the GPU.

여명 업데이트

일관성을 위해 webgpu.h C API의 이름이 requiredFeaturesCount에서 requiredFeatureCount으로, pipelineStatisticsCount에서 pipelineStatisticCount로, colorFormatsCount에서 colorFormatCount로 이름이 변경되었습니다. 문제 dawn:146040을 참조하세요.

DawnInfo 프로그램 (vulkaninfo와 유사)을 사용하면 전환 스위치, 어댑터, 어댑터 기능 및 어댑터 제한을 나열할 수 있습니다. 여명 samples 빌드 시 사용할 수 있습니다. 다음은 간결성을 위해 크게 다듬은 출력입니다. change dawn:149020을 참조하세요.

./out/Debug/DawnInfo
Toggles
=======
  Name: allow_unsafe_apis
    Suppresses validation errors on API entry points or parameter combinations
    that aren't considered secure yet.
    http://crbug.com/1138528
[…]

Adapter
=======
VendorID: 0x106B
Vendor: apple
Architecture: common-3
DeviceID: 0x0000
Name: Apple M1 Pro
Driver description: Metal driver on macOS Version 13.5.1 (Build 22G90)
Adapter Type: discrete GPU
Backend Type: Metal
Power: <undefined>

  Features
  ========
   * depth_clip_control
      Disable depth clipping of primitives to the clip volume
      https://bugs.chromium.org/p/dawn/issues/detail?id=1178
[…]

  Adapter Limits
  ==============
    maxTextureDimension1D: 16,384
    maxTextureDimension2D: 16,384
[…]

여기에서는 주요 특징 중 일부만 다루었습니다. 전체 커밋 목록을 확인하세요.

WebGPU의 새로운 기능

WebGPU의 새로운 기능 시리즈에서 다룬 모든 사항의 목록

Chrome 125

Chrome 124

Chrome 123

Chrome 122

Chrome 121

Chrome 120

Chrome 119

Chrome 118

Chrome 117

Chrome 116

Chrome 115

Chrome 114

Chrome 113