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

Code before:
    // Recreate some of the info (Sampler in slot X with the actual sampler) so letting Dawn confirm
    // there isn't a mismatch may be easiest.
    // Also storing the wgpu ObjectBase takes care of ownership challenges in theory
    wgpu::BindGroupLayout mLayout = nullptr;
    static constexpr uint8_t INVALID_INDEX = MAX_DESCRIPTOR_COUNT + 1;
    std::array<uint8_t, MAX_DESCRIPTOR_COUNT> mEntryIndexByBinding {};
    std::vector<wgpu::BindGroupEntry> mEntriesSortedByBinding;
    std::bitset<MAX_DESCRIPTOR_COUNT> mEntriesByBindingWithDynamicOffsets {};
    std::bitset<MAX_DESCRIPTOR_COUNT> mEntriesByBindingAdded {};
    std::vector<uint32_t> mDynamicOffsets;
    wgpu::BindGroup mBindGroup = nullptr;
};

class WGPUTexture : public HwTexture {
public:
    WGPUTexture(SamplerType target, uint8_t levels, TextureFormat format, uint8_t samples,
            uint32_t width, uint32_t height, uint32_t depth, TextureUsage usage,
            wgpu::Device const& device) noexcept;

    WGPUTexture(WGPUTexture* src, uint8_t baseLevel, uint8_t levelCount) noexcept;

    const wgpu::Texture& getTexture() const { return mTexture; }
    const wgpu::TextureView& getTexView() const { return mTexView; }

    static wgpu::TextureFormat fToWGPUTextureFormat(const filament::backend::TextureFormat& fUsage);
    static wgpu::TextureAspect inferWGPUTextureViewAspect(const wgpu::TextureFormat& format, const wgpu::TextureUsage& usage);

private:
    wgpu::TextureView makeTextureView(const uint8_t& baseLevel, const uint8_t& levelCount,
            SamplerType target);
    // CreateTextureR has info for a texture and sampler. Texture Views are needed for binding,
    // along with a sampler Current plan: Inherit the sampler and Texture to always exist (It is a
    // ref counted pointer) when making views. View is optional
    wgpu::Texture mTexture = nullptr;
    wgpu::TextureUsage mUsage = wgpu::TextureUsage::None;
    wgpu::TextureFormat mFormat = wgpu::TextureFormat::Undefined;
    uint32_t mArrayLayerCount = 1;
    wgpu::TextureView mTexView = nullptr;
    wgpu::TextureUsage fToWGPUTextureUsage(const filament::backend::TextureUsage& fUsage);

};

struct WGPURenderPrimitive : public HwRenderPrimitive {

    WGPUVertexBuffer* vertexBuffer = nullptr;
    WGPUIndexBuffer* indexBuffer = nullptr;
};

class WGPURenderTarget : public HwRenderTarget {
public:
    class Attachment {

Review comment (refactor):
nit: formatting: line is too long.

tip _(if you don't already know)_: in CLion you can select text and perform the "Reformat File..." action _(where you can optionally reformat just what you selected, which is what I would recommend and I do, or the whole file, which is HIGHLY not recommended in our case. The action opens a quick dialog where you can select between these, but you can hit enter for the default, which I have as just the selected text)_. There are number of ways to perform this action, where my preferred is the shortcut keys _(which is mapped to CMD+OPT+SHIFT+L on my machine, but you can also see what the key mapping is with the other methods)_. Alternatively, you can find it in the menu with `Code > Reformat File...` _(which will show the shortcut keys)_. Another way is to search actions via `Help > Find Action...` or CMD+SHIFT+A _(at least that's the key mapping on my machine)_ and search for "reformat" or something like that. When you reformat, make sure your IDE is configured to use "ClangFormat" _(which will honor the .clang-format file checked into the root of the project)_. You should see in the bottom right of your IDE "ClangFormat" selected instead of something like "4 spaces". If you see something like "4 spaces", select it and click "Enable ClangFormat".

Code after:
    // Recreate some of the info (Sampler in slot X with the actual sampler) so letting Dawn confirm
    // there isn't a mismatch may be easiest.
    // Also storing the wgpu ObjectBase takes care of ownership challenges in theory
    wgpu::BindGroupLayout mLayout = nullptr;
    static constexpr uint8_t INVALID_INDEX = MAX_DESCRIPTOR_COUNT + 1;
    std::array<uint8_t, MAX_DESCRIPTOR_COUNT> mEntryIndexByBinding{};
    std::vector<wgpu::BindGroupEntry> mEntriesSortedByBinding;
    std::bitset<MAX_DESCRIPTOR_COUNT> mEntriesByBindingWithDynamicOffsets{};
    std::bitset<MAX_DESCRIPTOR_COUNT> mEntriesByBindingAdded{};
    std::vector<uint32_t> mDynamicOffsets;
    wgpu::BindGroup mBindGroup = nullptr;
};

class WGPUTexture : public HwTexture {
public:
    WGPUTexture(SamplerType target, uint8_t levels, TextureFormat format, uint8_t samples,
            uint32_t width, uint32_t height, uint32_t depth, TextureUsage usage,
            wgpu::Device const& device) noexcept;

    WGPUTexture(WGPUTexture* src, uint8_t baseLevel, uint8_t levelCount) noexcept;

    [[nodiscard]] const wgpu::Texture& getTexture() const { return mTexture; }
    [[nodiscard]] const wgpu::TextureView& getTexView() const { return mTexView; }

    static wgpu::TextureFormat fToWGPUTextureFormat(
            filament::backend::TextureFormat const& fFormat);
    static wgpu::TextureAspect fToWGPUTextureViewAspect(
            filament::backend::TextureUsage const& fUsage,
            filament::backend::TextureFormat const& fFormat);

private:
    wgpu::TextureView makeTextureView(const uint8_t& baseLevel, const uint8_t& levelCount,
            SamplerType target);
    // CreateTextureR has info for a texture and sampler. Texture Views are needed for binding,
    // along with a sampler Current plan: Inherit the sampler and Texture to always exist (It is a
    // ref counted pointer) when making views. View is optional
    wgpu::Texture mTexture = nullptr;
    wgpu::TextureUsage mUsage = wgpu::TextureUsage::None;
    wgpu::TextureFormat mFormat = wgpu::TextureFormat::Undefined;
    wgpu::TextureAspect mAspect = wgpu::TextureAspect::Undefined;
    uint32_t mArrayLayerCount = 1;
    wgpu::TextureView mTexView = nullptr;
    wgpu::TextureUsage fToWGPUTextureUsage(filament::backend::TextureUsage const& fUsage);
};

struct WGPURenderPrimitive : public HwRenderPrimitive {

    WGPUVertexBuffer* vertexBuffer = nullptr;
    WGPUIndexBuffer* indexBuffer = nullptr;
};