Skip to content

Commit

Permalink
Merge pull request #1034 from cloudflare/webgpu_label
Browse files Browse the repository at this point in the history
  • Loading branch information
edevil authored Aug 22, 2023
2 parents 7e6ecdc + 77ce700 commit f0d9642
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/workerd/api/gpu/gpu-command-encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ namespace workerd::api::gpu {

class GPUCommandEncoder : public jsg::Object {
public:
explicit GPUCommandEncoder(wgpu::CommandEncoder e) : encoder_(kj::mv(e)){};
explicit GPUCommandEncoder(wgpu::CommandEncoder e, kj::String label)
: encoder_(kj::mv(e)), label_(kj::mv(label)){};
JSG_RESOURCE_TYPE(GPUCommandEncoder) {
JSG_READONLY_PROTOTYPE_PROPERTY(label, getLabel);
JSG_METHOD(beginComputePass);
JSG_METHOD(copyBufferToBuffer);
JSG_METHOD(finish);
}

private:
wgpu::CommandEncoder encoder_;
kj::String label_;
kj::StringPtr getLabel() {
return label_;
}

jsg::Ref<GPUComputePassEncoder>
beginComputePass(jsg::Optional<GPUComputePassDescriptor> descriptor);
jsg::Ref<GPUCommandBuffer> finish(jsg::Optional<GPUCommandBufferDescriptor>);
Expand Down
8 changes: 5 additions & 3 deletions src/workerd/api/gpu/gpu-device.c++
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,16 @@ jsg::Ref<GPUCommandEncoder>
GPUDevice::createCommandEncoder(jsg::Optional<GPUCommandEncoderDescriptor> descriptor) {
wgpu::CommandEncoderDescriptor desc{};

kj::String label = kj::str("");
KJ_IF_MAYBE (d, descriptor) {
KJ_IF_MAYBE (label, d->label) {
desc.label = label->cStr();
KJ_IF_MAYBE (l, d->label) {
label = kj::mv(*l);
desc.label = label.cStr();
}
}

auto encoder = device_.CreateCommandEncoder(&desc);
return jsg::alloc<GPUCommandEncoder>(kj::mv(encoder));
return jsg::alloc<GPUCommandEncoder>(kj::mv(encoder), kj::mv(label));
}

wgpu::ComputePipelineDescriptor
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/gpu/webgpu-compute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ export class DurableObjectExample {
ok(bindGroupAutoLayout);

// Commands submission
const commandEncoder = device.createCommandEncoder();
const commandEncoder = device.createCommandEncoder({ label: "label1" });
ok(commandEncoder);
equal(commandEncoder.label, "label1");

const passEncoder = commandEncoder.beginComputePass();
ok(passEncoder);
Expand Down

0 comments on commit f0d9642

Please sign in to comment.