Open eliemichel opened 2 months ago
(Will update webgpu.yml and gen script if relevant)
None of us had strong opinions on which way to go, but it's a bit more traditional. It feels too arbitrary to be worth changing, but I don't know.
static const
that might push us toward macros: https://github.com/webgpu-native/webgpu-headers/issues/339 (though I don't think we'll use macros to define all of the flags constants - incidentally Vulkan also uses static const
for 64-bit flags).
- it also turns out there are some limitations with
static const
that might push us toward macros: Latest header does not compile on MSVC due to const expressions #339 (though I don't think we'll use macros to define all of the flags constants - incidentally Vulkan also usesstatic const
for 64-bit flags).
I checked, and this applies to MSVC C but not C++. The pattern this will create problems for is e.g.:
static const uint64_t kMyUsages = WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform;
but users can deal with this, by themselves using a macro:
#define MY_USAGES (WGPUBufferUsage_CopyDst | WGPUBufferUsage_Uniform)
I found a useful series of answers about C here: https://stackoverflow.com/questions/1674032/static-const-vs-define-vs-enum (which was harder to find than the equivalent C++ question here: https://stackoverflow.com/questions/1637332/static-const-vs-define)
Given we probably don't get any significant type safety out of these (they're mostly uint32_t and they're no worse than UINT32_MAX
etc.) I would lean weakly toward just keeping the #defines
.
This may be a naive question, but is there any reason for these constant values to be declared as macro variables using
#define
rather than typed static consts?We already use static const for enum values now so there should be no support issue.