Repository: google/filament
File: filament/backend/src/webgpu/WebGPUHandles.cpp (C++)

Code before:
    wgpu::BindGroupLayoutDescriptor layoutDescriptor{
        // TODO: layoutDescriptor has a "Label". Ideally we can get info on what this layout is for
        // debugging. For now, hack an incrementing value.
        .label{ "layout_" + std::to_string(++layoutNum) },
        .entryCount = wEntries.size(),
        .entries = wEntries.data()
    };
    // TODO Do we need to defer this until we have more info on textures and samplers??
    mLayoutSize = wEntries.size();
    mLayout = device.CreateBindGroupLayout(&layoutDescriptor);
}
WebGPUDescriptorSetLayout::~WebGPUDescriptorSetLayout() {}
WebGPUDescriptorSet::WebGPUDescriptorSet(const wgpu::BindGroupLayout& layout, uint layoutSize)
    : mLayout(layout) {
    // Establish the size of entries based on the layout. This should be reliable and efficient.
    entries.resize(layoutSize);
}
WebGPUDescriptorSet::~WebGPUDescriptorSet() {}
wgpu::BindGroup WebGPUDescriptorSet::lockAndReturn(const wgpu::Device& device) {
    if (mIsLocked) {
        return mBindGroup;
    }
    // TODO label? Should we just copy layout label?
    wgpu::BindGroupDescriptor desc{ .layout = mLayout,
        .entryCount = entries.size(),
        .entries = entries.data() };
    mBindGroup = device.CreateBindGroup(&desc);
    mIsLocked = true;
    return mBindGroup;
}
void WebGPUDescriptorSet::addEntry(uint index, wgpu::BindGroupEntry entry) {
    if (mIsLocked) {
        // We will keep getting hits from future updates, but shouldn't do anything
        // Filament guarantees this won't change after things have locked.
        return;
    }
    // TODO: Putting some level of trust that Filament is not going to reuse indexes or go past the
    // layout index for efficiency. Add guards if wrong.
    entries[index] = entry;
}
}// namespace filament::backend


Review comment (bug):
yeah, tough to say. Ultimately, we just want to make our lives easier to debug. Maybe that little extra bit of info could be helpful.

Code after:
    wgpu::BindGroupLayoutDescriptor layoutDescriptor{
        // TODO: layoutDescriptor has a "Label". Ideally we can get info on what this layout is for
        // debugging. For now, hack an incrementing value.
        .label{ "layout_" + std::to_string(++layoutNum) },
        .entryCount = wEntries.size(),
        .entries = wEntries.data()
    };
    // TODO Do we need to defer this until we have more info on textures and samplers??
    mLayoutSize = wEntries.size();
    mLayout = device.CreateBindGroupLayout(&layoutDescriptor);
}

WebGPUDescriptorSetLayout::~WebGPUDescriptorSetLayout() {}

WebGPUDescriptorSet::WebGPUDescriptorSet(const wgpu::BindGroupLayout& layout, uint layoutSize)
    : mLayout(layout),
      entries(layoutSize, wgpu::BindGroupEntry{}) {
    // Establish the size of entries based on the layout. This should be reliable and efficient.
}
WebGPUDescriptorSet::~WebGPUDescriptorSet() {}

wgpu::BindGroup WebGPUDescriptorSet::lockAndReturn(const wgpu::Device& device) {
    if (mBindGroup) {
        return mBindGroup;
    }
    // TODO label? Should we just copy layout label?
    wgpu::BindGroupDescriptor desc{ .layout = mLayout,
        .entryCount = entries.size(),
        .entries = entries.data() };
    mBindGroup = device.CreateBindGroup(&desc);
    return mBindGroup;
}

void WebGPUDescriptorSet::addEntry(uint index, wgpu::BindGroupEntry&& entry) {
    if (mBindGroup) {
        // We will keep getting hits from future updates, but shouldn't do anything
        // Filament guarantees this won't change after things have locked.
        return;
    }
    // TODO: Putting some level of trust that Filament is not going to reuse indexes or go past the
    // layout index for efficiency. Add guards if wrong.
    entries[index] = std::move(entry);
}
}// namespace filament::backend