Skip to content

Commit 8997825

Browse files
committed
fix
1 parent 75f3ff4 commit 8997825

18 files changed

+262
-47
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <common/command_buffers/gpu/backend_connection.hpp>
2+
3+
namespace commandbuffers::gpu
4+
{
5+
BackendConnection::BackendConnection(GPUInstance *instance, GPUBackendType type)
6+
: instance_(instance)
7+
, type_(type)
8+
{
9+
}
10+
11+
GPUBackendType BackendConnection::type() const
12+
{
13+
return type_;
14+
}
15+
16+
GPUInstance *BackendConnection::getInstance() const
17+
{
18+
return instance_;
19+
}
20+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <common/utility.hpp>
5+
#include <common/non_movable.hpp>
6+
#include <common/command_buffers/gpu/gpu_base.hpp>
7+
#include <common/command_buffers/gpu/gpu_instance.hpp>
8+
#include <common/command_buffers/gpu/gpu_adapter.hpp>
9+
#include <common/command_buffers/gpu/gpu_physical_device.hpp>
10+
11+
namespace commandbuffers::gpu
12+
{
13+
struct RequestAdapterOptions
14+
{
15+
GPUFeatureLevel featureLevel = GPUFeatureLevel::kCore;
16+
GPUPowerPreference powerPreference = GPUPowerPreference::Undefined;
17+
bool forceFallbackAdapter = false;
18+
GPUBackendType backendType = GPUBackendType::kUndefined;
19+
};
20+
21+
class BackendConnection : public NonMovable
22+
{
23+
public:
24+
BackendConnection(GPUInstance *instance, GPUBackendType type);
25+
virtual ~BackendConnection() = default;
26+
27+
GPUBackendType type() const;
28+
GPUInstance *getInstance() const;
29+
30+
virtual std::vector<Ref<GPUPhysicalDeviceBase>> discoverPhysicalDevices(const RequestAdapterOptions &) = 0;
31+
32+
private:
33+
GPUInstance *instance_ = nullptr;
34+
GPUBackendType type_;
35+
};
36+
}

src/common/command_buffers/gpu/gpu_adapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace commandbuffers
7070
rhs.maxComputeWorkgroupsPerDimension);
7171
}
7272

73-
GPUAdapterBase::GPUAdapterBase(shared_ptr<GPUInstanceBase> instance,
73+
GPUAdapterBase::GPUAdapterBase(shared_ptr<GPUInstance> instance,
7474
shared_ptr<GPUPhysicalDeviceBase> physicalDevice,
7575
GPUFeatureLevel level,
7676
GPUPowerPreference powerPreference)

src/common/command_buffers/gpu/gpu_adapter.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace commandbuffers
1111
{
12-
class GPUInstanceBase;
12+
class GPUInstance;
1313
class GPUPhysicalDeviceBase;
1414
struct GPUDeviceDescriptor;
1515

@@ -47,12 +47,12 @@ namespace commandbuffers
4747
class GPUAdapterBase : ErrorMonad
4848
{
4949
public:
50-
GPUAdapterBase(std::shared_ptr<GPUInstanceBase> instance,
50+
GPUAdapterBase(std::shared_ptr<GPUInstance> instance,
5151
std::shared_ptr<GPUPhysicalDeviceBase> physicalDevice,
5252
GPUFeatureLevel level,
5353
GPUPowerPreference powerPreference);
5454

55-
GPUInstanceBase *instance() const;
55+
GPUInstance *instance() const;
5656
const GPUAdapterInfo &info() const;
5757
bool hasFeature(GPUFeatureName) const;
5858
void requestDevice(const GPUDeviceDescriptor *descriptor,
@@ -66,7 +66,7 @@ namespace commandbuffers
6666
const std::string &name() const;
6767

6868
private:
69-
std::shared_ptr<GPUInstanceBase> instance_;
69+
std::shared_ptr<GPUInstance> instance_;
7070
std::shared_ptr<GPUPhysicalDeviceBase> physical_device_;
7171
GPUFeatureLevel feature_level_;
7272
GPUPowerPreference power_preference_;

src/common/command_buffers/gpu/gpu_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace commandbuffers
8888
{
8989
}
9090

91-
GPUInstanceBase *GPUObject::instance() const
91+
GPUInstance *GPUObject::instance() const
9292
{
9393
return device_->getInstance();
9494
}

src/common/command_buffers/gpu/gpu_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,8 @@ namespace commandbuffers
718718
static constexpr uint64_t kInitialized = 0b0;
719719
};
720720

721+
class GPUInstance;
721722
class GPUDeviceBase;
722-
class GPUInstanceBase;
723723

724724
class GPUObject : public ErrorMonad
725725
{
@@ -728,7 +728,7 @@ namespace commandbuffers
728728
GPUObject(std::shared_ptr<GPUDeviceBase> device, ErrorTag tag);
729729
GPUObject(std::shared_ptr<GPUDeviceBase> device, DelayedInitializationTag tag);
730730

731-
GPUInstanceBase *instance() const;
731+
GPUInstance *instance() const;
732732
std::shared_ptr<GPUDeviceBase> device() const;
733733

734734
private:

src/common/command_buffers/gpu/gpu_device.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace commandbuffers
3838

3939
bool validateHandle(const GPUHandle &handle) const;
4040

41-
GPUInstanceBase *getInstance() const;
41+
GPUInstance *getInstance() const;
4242
GPUAdapterBase *getAdapter() const;
4343
GPUPhysicalDeviceBase *getPhysicalDevice() const;
4444

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
11
#include <common/command_buffers/gpu/gpu_instance.hpp>
2+
#include <common/command_buffers/gpu/backend_connection.hpp>
23

34
using namespace std;
45

56
namespace commandbuffers
67
{
7-
unique_ptr<GPUInstanceBase, GPUInstanceBase::Deleter> GPUInstanceBase::Create(const GPUInstanceDescriptor *descriptor)
8+
Ref<GPUInstance> GPUInstance::Create(const GPUInstanceDescriptor *descriptor)
89
{
910
static constexpr GPUInstanceDescriptor kDefaultDesc = {};
1011
if (descriptor == nullptr)
1112
{
1213
descriptor = &kDefaultDesc;
1314
}
1415

15-
auto instance = unique_ptr<GPUInstanceBase, Deleter>(new GPUInstanceBase());
16+
auto instance = Ref<GPUInstance>(new GPUInstance(), [](GPUInstance *ptr)
17+
{ delete ptr; });
1618
instance->initialize(*descriptor);
1719
return instance;
1820
}
1921

20-
void GPUInstanceBase::addDevice(shared_ptr<GPUDeviceBase>)
22+
void GPUInstance::addDevice(shared_ptr<GPUDeviceBase>)
2123
{
2224
}
2325

24-
void GPUInstanceBase::removeDevice(shared_ptr<GPUDeviceBase>)
26+
void GPUInstance::removeDevice(shared_ptr<GPUDeviceBase>)
2527
{
2628
}
2729

28-
bool GPUInstanceBase::hasFeature(GPUFeatureName feature) const
30+
bool GPUInstance::hasFeature(GPUFeatureName feature) const
2931
{
3032
return instance_features_.find(feature) != instance_features_.end();
3133
}
3234

33-
GPUInstanceBase::GPUInstanceBase()
35+
GPUInstance::GPUInstance()
3436
{
3537
}
3638

37-
void GPUInstanceBase::initialize(const GPUInstanceDescriptor &descriptor)
39+
void GPUInstance::initialize(const GPUInstanceDescriptor &descriptor)
3840
{
3941
}
4042
}

src/common/command_buffers/gpu/gpu_instance.hpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,50 @@
33
#include <memory>
44
#include <vector>
55
#include <unordered_set>
6+
#include <common/utility.hpp>
67
#include <common/command_buffers/gpu/gpu_adapter.hpp>
78
#include <common/command_buffers/gpu/gpu_device.hpp>
89

910
namespace commandbuffers
1011
{
12+
namespace gpu
13+
{
14+
class BackendConnection;
15+
}
16+
1117
struct GPUInstanceDescriptor
1218
{
1319
size_t requiredFeatureCount = 0;
1420
GPUFeatureName const *requiredFeatures = nullptr;
1521
GPUSupportedLimits *requiredLimits = nullptr;
1622
};
1723

18-
class GPUInstanceBase
24+
class GPUInstance final
1925
{
20-
private:
21-
// Custom deleter for `unique_ptr<GPUInstanceBase>`
22-
struct Deleter
23-
{
24-
void operator()(GPUInstanceBase *ptr)
25-
{
26-
delete ptr;
27-
}
28-
};
29-
3026
public:
31-
static std::unique_ptr<GPUInstanceBase, Deleter> Create(const GPUInstanceDescriptor *descriptor = nullptr);
27+
static Ref<GPUInstance> Create(const GPUInstanceDescriptor *descriptor = nullptr);
28+
29+
void registerBackend(gpu::BackendConnection *backend);
3230

33-
void addDevice(std::shared_ptr<GPUDeviceBase>);
34-
void removeDevice(std::shared_ptr<GPUDeviceBase>);
31+
void addDevice(Ref<GPUDeviceBase>);
32+
void removeDevice(Ref<GPUDeviceBase>);
3533

3634
bool hasFeature(GPUFeatureName feature) const;
3735

3836
private:
39-
explicit GPUInstanceBase();
40-
virtual ~GPUInstanceBase() = default;
37+
explicit GPUInstance();
38+
virtual ~GPUInstance() = default;
4139

4240
void initialize(const GPUInstanceDescriptor &descriptor);
43-
std::shared_ptr<GPUAdapterBase> createAdapter();
41+
Ref<GPUAdapterBase> createAdapter(Ref<GPUPhysicalDeviceBase> physicalDevice,
42+
GPUFeatureLevel featureLevel,
43+
GPUPowerPreference powerPreference);
44+
45+
gpu::BackendConnection *getBackendConnection() const;
4446

4547
private:
4648
std::unordered_set<GPUFeatureName> instance_features_;
4749
std::vector<std::shared_ptr<GPUDeviceBase>> devices_list_;
50+
Ref<gpu::BackendConnection> backend_ = nullptr;
4851
};
4952
}

src/common/command_buffers/gpu/gpu_physical_device.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace commandbuffers
3737

3838
private:
3939
virtual std::unique_ptr<GPUDeviceBase> createDeviceImpl(std::shared_ptr<GPUAdapterBase> adapter,
40-
GPUDeviceDescriptor &descriptor);
41-
virtual void initializeImpl();
40+
GPUDeviceDescriptor &descriptor) = 0;
41+
virtual void initializeImpl() = 0;
4242
virtual void initializeSupportedFeaturesImpl() = 0;
4343
virtual void initializeVendorArchitectureImpl();
4444

0 commit comments

Comments
 (0)