diff --git a/src/dawn_native/Adapter.h b/src/dawn_native/Adapter.h index afb754619c..bb15e70a92 100644 --- a/src/dawn_native/Adapter.h +++ b/src/dawn_native/Adapter.h @@ -34,6 +34,9 @@ namespace dawn_native { DeviceBase* CreateDevice(); + protected: + PCIInfo mPCIInfo = {}; + private: virtual ResultOrError CreateDeviceImpl() = 0; @@ -41,7 +44,6 @@ namespace dawn_native { InstanceBase* mInstance = nullptr; BackendType mBackend; - PCIInfo mPCIInfo; }; } // namespace dawn_native diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 100b6079fe..c5f6993299 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -14,6 +14,7 @@ #include "dawn_native/Device.h" +#include "dawn_native/Adapter.h" #include "dawn_native/BindGroup.h" #include "dawn_native/BindGroupLayout.h" #include "dawn_native/Buffer.h" @@ -49,7 +50,7 @@ namespace dawn_native { // DeviceBase - DeviceBase::DeviceBase() { + DeviceBase::DeviceBase(AdapterBase* adapter) : mAdapter(adapter) { mCaches = std::make_unique(); mFenceSignalTracker = std::make_unique(this); } @@ -97,6 +98,11 @@ namespace dawn_native { mCaches->bindGroupLayouts.erase(obj); } + const PCIInfo& DeviceBase::GetPCIInfo() const { + ASSERT(mAdapter != nullptr); + return mAdapter->GetPCIInfo(); + } + // Object creation API methods BindGroupBase* DeviceBase::CreateBindGroup(const BindGroupDescriptor* descriptor) { diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index 491ae19957..82e2cf8629 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -29,11 +29,12 @@ namespace dawn_native { using ErrorCallback = void (*)(const char* errorMessage, void* userData); + class AdapterBase; class FenceSignalTracker; class DeviceBase { public: - DeviceBase(); + DeviceBase(AdapterBase* adapter); virtual ~DeviceBase(); void HandleError(const char* message); @@ -108,7 +109,7 @@ namespace dawn_native { return nullptr; } - virtual const PCIInfo& GetPCIInfo() const = 0; + virtual const PCIInfo& GetPCIInfo() const; private: virtual ResultOrError CreateBindGroupImpl( @@ -156,6 +157,8 @@ namespace dawn_native { void ConsumeError(ErrorData* error); + AdapterBase* mAdapter = nullptr; + // The object caches aren't exposed in the header as they would require a lot of // additional includes. struct Caches; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index ac6aca7b56..a72ec89020 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -97,7 +97,7 @@ namespace dawn_native { namespace d3d12 { } // anonymous namespace - Device::Device() { + Device::Device() : DeviceBase(nullptr) { mFunctions = std::make_unique(); { diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index 0bde91731f..f71fe9afc7 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -128,7 +128,8 @@ namespace dawn_native { namespace metal { // Device Device::Device() - : mMtlDevice(MTLCreateSystemDefaultDevice()), + : DeviceBase(nullptr), + mMtlDevice(MTLCreateSystemDefaultDevice()), mMapTracker(new MapRequestTracker(this)), mResourceUploader(new ResourceUploader(this)) { [mMtlDevice retain]; diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index 6efe6f7a0d..7244435371 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -26,12 +26,13 @@ namespace dawn_native { namespace null { class Adapter : public AdapterBase { public: Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::Null) { + mPCIInfo.name = "Null backend"; } virtual ~Adapter() = default; private: ResultOrError CreateDeviceImpl() override { - return {new Device}; + return {new Device(this)}; } }; @@ -55,8 +56,7 @@ namespace dawn_native { namespace null { // Device - Device::Device() { - InitFakePCIInfo(); + Device::Device(Adapter* adapter) : DeviceBase(adapter) { } Device::~Device() { @@ -122,14 +122,6 @@ namespace dawn_native { namespace null { return new TextureView(texture, descriptor); } - void Device::InitFakePCIInfo() { - mPCIInfo.name = "Null backend"; - } - - const dawn_native::PCIInfo& Device::GetPCIInfo() const { - return mPCIInfo; - } - Serial Device::GetCompletedCommandSerial() const { return mCompletedSerial; } diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index dd5029ab2b..03f8967e3c 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -85,7 +85,7 @@ namespace dawn_native { namespace null { class Device : public DeviceBase { public: - Device(); + Device(Adapter* adapter); ~Device(); CommandBufferBase* CreateCommandBuffer(CommandBufferBuilder* builder) override; @@ -98,8 +98,6 @@ namespace dawn_native { namespace null { Serial GetLastSubmittedCommandSerial() const final override; void TickImpl() override; - const dawn_native::PCIInfo& GetPCIInfo() const override; - void AddPendingOperation(std::unique_ptr operation); void SubmitPendingOperations(); @@ -123,12 +121,10 @@ namespace dawn_native { namespace null { ResultOrError CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; - void InitFakePCIInfo(); Serial mCompletedSerial = 0; Serial mLastSubmittedSerial = 0; std::vector> mPendingOperations; - dawn_native::PCIInfo mPCIInfo; }; class Buffer : public BufferBase { diff --git a/src/dawn_native/opengl/BackendGL.cpp b/src/dawn_native/opengl/BackendGL.cpp index d5873d9179..1b80d678e5 100644 --- a/src/dawn_native/opengl/BackendGL.cpp +++ b/src/dawn_native/opengl/BackendGL.cpp @@ -32,6 +32,8 @@ namespace dawn_native { namespace opengl { glEnable(GL_DEPTH_TEST); glEnable(GL_SCISSOR_TEST); glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); + + mPCIInfo.name = reinterpret_cast(glGetString(GL_RENDERER)); } virtual ~Adapter() = default; @@ -39,7 +41,7 @@ namespace dawn_native { namespace opengl { ResultOrError CreateDeviceImpl() override { // There is no limit on the number of devices created from this adapter because they can // all share the same backing OpenGL context. - return {new Device}; + return {new Device(this)}; } }; diff --git a/src/dawn_native/opengl/DeviceGL.cpp b/src/dawn_native/opengl/DeviceGL.cpp index 92b7caf103..934a9b68f3 100644 --- a/src/dawn_native/opengl/DeviceGL.cpp +++ b/src/dawn_native/opengl/DeviceGL.cpp @@ -32,8 +32,7 @@ namespace dawn_native { namespace opengl { - Device::Device() { - CollectPCIInfo(); + Device::Device(AdapterBase* adapter) : DeviceBase(adapter) { } Device::~Device() { @@ -145,12 +144,4 @@ namespace dawn_native { namespace opengl { } } - const dawn_native::PCIInfo& Device::GetPCIInfo() const { - return mPCIInfo; - } - - void Device::CollectPCIInfo() { - mPCIInfo.name = reinterpret_cast(glGetString(GL_RENDERER)); - } - }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/DeviceGL.h b/src/dawn_native/opengl/DeviceGL.h index b32d269e2c..192b9f2d0d 100644 --- a/src/dawn_native/opengl/DeviceGL.h +++ b/src/dawn_native/opengl/DeviceGL.h @@ -34,7 +34,7 @@ namespace dawn_native { namespace opengl { class Device : public DeviceBase { public: - Device(); + Device(AdapterBase* adapter); ~Device(); void SubmitFenceSync(); @@ -50,8 +50,6 @@ namespace dawn_native { namespace opengl { Serial GetLastSubmittedCommandSerial() const final override; void TickImpl() override; - const dawn_native::PCIInfo& GetPCIInfo() const override; - private: ResultOrError CreateBindGroupImpl( const BindGroupDescriptor* descriptor) override; @@ -72,15 +70,12 @@ namespace dawn_native { namespace opengl { ResultOrError CreateTextureViewImpl( TextureBase* texture, const TextureViewDescriptor* descriptor) override; - void CollectPCIInfo(); void CheckPassedFences(); Serial mCompletedSerial = 0; Serial mLastSubmittedSerial = 0; std::queue> mFencesInFlight; - - dawn_native::PCIInfo mPCIInfo; }; }} // namespace dawn_native::opengl diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 6e54e92c94..da23c0ac47 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -57,7 +57,7 @@ namespace dawn_native { namespace vulkan { // Device - Device::Device() { + Device::Device() : DeviceBase(nullptr) { MaybeError maybeError = Initialize(); // In device initialization, the error callback can't have been set yet.