Skip to content

Flag enum types and flags typedefs #159

Closed as not planned
Closed as not planned
@kainino0x

Description

@kainino0x

Originally posted by @mrshannon in #158 (comment):

Any idea on how to improve WGPUBufferUsage vs. WGPUBufferUsageFlags?

You technically don't need WGPUBufferUsageFlags as WGPUBufferUsage will > always be wide enough for the bitwise combination because we have WGPUBufferUsage_Force32 = 0x7FFFFFFF which is effectively doing what is done for the C++ headers with:

enum class BufferUsage : uint32_t {

This is strictly true, but in Dawn's C++ bindings we also have operator overloads, so when you do wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst you get a wgpu::BufferUsage value. In C WGPUBufferUsage_CopySrc | WGPUBufferUsage_CopyDst will give you an int of some kind. So this would force callers of the API to cast back to the appropriate type.

desc.usage = static_cast<WGPUBufferUsage>(WGPUBufferUsage_CopySrc | WGPUBufferUsage_CopyDst);

Apparently, the cast is only needed in C++. C seems happy without a cast. So I guess we could define operator overloads for these types behind #ifdef __cplusplus...?

Metadata

Metadata

Assignees

No one assigned

    Labels

    has resolutionIssue is resolved, just needs to be done

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions