Rework dawn/native/ProcTable.cpp's template to better handle functions.

This is a small rework to try to make the template better handle
functions that aren't associated with an object, when during an
unrelated patch I got confused that APICreateInstance didn't appear in
dawn::native.

Change-Id: If5a2aa3f9e348d1847e48fec4e90e5966ddd489d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86530
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2022-04-12 16:46:01 +00:00
committed by Dawn LUCI CQ
parent a5f5f5a1aa
commit b2fdd6402d
5 changed files with 71 additions and 43 deletions

View File

@@ -188,7 +188,7 @@ namespace dawn::native {
// Instance
Instance::Instance(const WGPUInstanceDescriptor* desc)
: mImpl(InstanceBase::Create(reinterpret_cast<const InstanceDescriptor*>(desc))) {
: mImpl(APICreateInstance(reinterpret_cast<const InstanceDescriptor*>(desc))) {
}
Instance::~Instance() {

View File

@@ -93,10 +93,14 @@ namespace dawn::native {
} // anonymous namespace
InstanceBase* APICreateInstance(const InstanceDescriptor* descriptor) {
return InstanceBase::Create().Detach();
}
// InstanceBase
// static
InstanceBase* InstanceBase::Create(const InstanceDescriptor* descriptor) {
Ref<InstanceBase> InstanceBase::Create(const InstanceDescriptor* descriptor) {
Ref<InstanceBase> instance = AcquireRef(new InstanceBase);
static constexpr InstanceDescriptor kDefaultDesc = {};
if (descriptor == nullptr) {
@@ -105,7 +109,7 @@ namespace dawn::native {
if (instance->ConsumedError(instance->Initialize(descriptor))) {
return nullptr;
}
return instance.Detach();
return instance;
}
// TODO(crbug.com/dawn/832): make the platform an initialization parameter of the instance.

View File

@@ -39,11 +39,13 @@ namespace dawn::native {
using BackendsBitset = ityp::bitset<wgpu::BackendType, kEnumCount<wgpu::BackendType>>;
InstanceBase* APICreateInstance(const InstanceDescriptor* descriptor);
// This is called InstanceBase for consistency across the frontend, even if the backends don't
// specialize this class.
class InstanceBase final : public RefCounted {
public:
static InstanceBase* Create(const InstanceDescriptor* descriptor = nullptr);
static Ref<InstanceBase> Create(const InstanceDescriptor* descriptor = nullptr);
void APIRequestAdapter(const RequestAdapterOptions* options,
WGPURequestAdapterCallback callback,