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);

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

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

이를 활용하려면 WGSL 코드에서 enable chromium_experimental_read_write_storage_texture을 사용하여 이 확장 프로그램을 명시적으로 사용 설정해야 합니다. 사용 설정하면 저장소 텍스처에 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에서 일관성을 위해 다음 필드의 이름이 변경되었습니다. requiredFeaturesCountrequiredFeatureCount로, pipelineStatisticsCountpipelineStatisticCount로, colorFormatsCountcolorFormatCount로 변경되었습니다. 문제 dawn:146040을 참고하세요.

새로운 DawnInfo 프로그램 (vulkaninfo와 유사)을 사용하면 전환, 어댑터, 어댑터 기능, 어댑터 제한을 나열할 수 있습니다. dawn 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 140

Chrome 139

Chrome 138

Chrome 137

Chrome 136

Chrome 135

Chrome 134

Chrome 133

Chrome 132

Chrome 131

Chrome 130

Chrome 129

Chrome 128

Chrome 127

Chrome 126

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