Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. GPUDevice
  4. createCommandEncoder()

GPUDevice: createCommandEncoder() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

ThecreateCommandEncoder() method of theGPUDevice interface creates aGPUCommandEncoder, used to encode commands to be issued to the GPU.

Syntax

js
createCommandEncoder()createCommandEncoder(descriptor)

Parameters

descriptorOptional

An object containing the following properties:

labelOptional

A string providing a label that can be used to identify the object, for example inGPUError messages or console warnings.

Return value

AGPUCommandEncoder object instance.

Examples

In ourbasic render demo, several commands are recorded via aGPUCommandEncoder created viacreateCommandEncoder():

js
// …// Create GPUCommandEncoderconst commandEncoder = device.createCommandEncoder();// Create GPURenderPassDescriptor to tell WebGPU which texture to draw into, then initiate render passconst renderPassDescriptor = {  colorAttachments: [    {      clearValue: clearColor,      loadOp: "clear",      storeOp: "store",      view: context.getCurrentTexture().createView(),    },  ],};const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);// Draw a trianglepassEncoder.setPipeline(renderPipeline);passEncoder.setVertexBuffer(0, vertexBuffer);passEncoder.draw(3);// End the render passpassEncoder.end();// …

The commands encoded by theGPUCommandEncoder are recoded into aGPUCommandBuffer using theGPUCommandEncoder.finish() method. The command buffer is then passed into the queue via asubmit() call, ready to be processed by the GPU.

js
device.queue.submit([commandEncoder.finish()]);

Note:Study theWebGPU samples to find more command encoding examples.

Specifications

Specification
WebGPU
# dom-gpudevice-createcommandencoder

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp