Add device reference counting
This commit is contained in:
parent
563e9e253e
commit
f9c39d021e
|
@ -138,4 +138,17 @@ namespace backend {
|
||||||
// TODO(cwallez@chromium.org): update state tracking then call the backend
|
// TODO(cwallez@chromium.org): update state tracking then call the backend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeviceBase::Reference() {
|
||||||
|
ASSERT(refCount != 0);
|
||||||
|
refCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceBase::Release() {
|
||||||
|
ASSERT(refCount != 0);
|
||||||
|
refCount--;
|
||||||
|
if (refCount == 0) {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace backend {
|
||||||
class DeviceBase {
|
class DeviceBase {
|
||||||
public:
|
public:
|
||||||
DeviceBase();
|
DeviceBase();
|
||||||
~DeviceBase();
|
virtual ~DeviceBase();
|
||||||
|
|
||||||
void HandleError(const char* message);
|
void HandleError(const char* message);
|
||||||
|
|
||||||
|
@ -90,6 +90,8 @@ namespace backend {
|
||||||
void Tick();
|
void Tick();
|
||||||
void CopyBindGroups(uint32_t start, uint32_t count, BindGroupBase* source, BindGroupBase* target);
|
void CopyBindGroups(uint32_t start, uint32_t count, BindGroupBase* source, BindGroupBase* target);
|
||||||
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
|
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
|
||||||
|
void Reference();
|
||||||
|
void Release();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The object caches aren't exposed in the header as they would require a lot of
|
// The object caches aren't exposed in the header as they would require a lot of
|
||||||
|
@ -99,6 +101,7 @@ namespace backend {
|
||||||
|
|
||||||
nxt::DeviceErrorCallback errorCallback = nullptr;
|
nxt::DeviceErrorCallback errorCallback = nullptr;
|
||||||
nxt::CallbackUserdata errorUserdata = 0;
|
nxt::CallbackUserdata errorUserdata = 0;
|
||||||
|
uint32_t refCount = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,12 +252,6 @@ namespace d3d12 {
|
||||||
return new TextureView(builder);
|
return new TextureView(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::Reference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::Release() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// DepthStencilState
|
// DepthStencilState
|
||||||
|
|
||||||
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)
|
||||||
|
|
|
@ -132,10 +132,6 @@ namespace d3d12 {
|
||||||
|
|
||||||
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
|
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
|
||||||
|
|
||||||
// NXT API
|
|
||||||
void Reference();
|
|
||||||
void Release();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t serial = 0;
|
uint64_t serial = 0;
|
||||||
ComPtr<ID3D12Fence> fence;
|
ComPtr<ID3D12Fence> fence;
|
||||||
|
|
|
@ -117,10 +117,6 @@ namespace metal {
|
||||||
MapReadRequestTracker* GetMapReadTracker() const;
|
MapReadRequestTracker* GetMapReadTracker() const;
|
||||||
ResourceUploader* GetResourceUploader() const;
|
ResourceUploader* GetResourceUploader() const;
|
||||||
|
|
||||||
// NXT API
|
|
||||||
void Reference();
|
|
||||||
void Release();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnCompletedHandler();
|
void OnCompletedHandler();
|
||||||
|
|
||||||
|
|
|
@ -241,12 +241,6 @@ namespace metal {
|
||||||
return resourceUploader;
|
return resourceUploader;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::Reference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::Release() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind Group
|
// Bind Group
|
||||||
|
|
||||||
BindGroup::BindGroup(BindGroupBuilder* builder)
|
BindGroup::BindGroup(BindGroupBuilder* builder)
|
||||||
|
|
|
@ -101,12 +101,6 @@ namespace null {
|
||||||
return std::move(pendingOperations);
|
return std::move(pendingOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::Reference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::Release() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Buffer
|
// Buffer
|
||||||
|
|
||||||
struct BufferMapReadOperation : PendingOperation {
|
struct BufferMapReadOperation : PendingOperation {
|
||||||
|
|
|
@ -112,10 +112,6 @@ namespace null {
|
||||||
void AddPendingOperation(std::unique_ptr<PendingOperation> operation);
|
void AddPendingOperation(std::unique_ptr<PendingOperation> operation);
|
||||||
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
|
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
|
||||||
|
|
||||||
// NXT API
|
|
||||||
void Reference();
|
|
||||||
void Release();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<PendingOperation>> pendingOperations;
|
std::vector<std::unique_ptr<PendingOperation>> pendingOperations;
|
||||||
};
|
};
|
||||||
|
|
|
@ -100,12 +100,6 @@ namespace opengl {
|
||||||
void Device::TickImpl() {
|
void Device::TickImpl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::Reference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void Device::Release() {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind Group
|
// Bind Group
|
||||||
|
|
||||||
BindGroup::BindGroup(BindGroupBuilder* builder)
|
BindGroup::BindGroup(BindGroupBuilder* builder)
|
||||||
|
|
|
@ -98,10 +98,6 @@ namespace opengl {
|
||||||
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
|
||||||
|
|
||||||
void TickImpl() override;
|
void TickImpl() override;
|
||||||
|
|
||||||
// NXT API
|
|
||||||
void Reference();
|
|
||||||
void Release();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class BindGroup : public BindGroupBase {
|
class BindGroup : public BindGroupBase {
|
||||||
|
|
Loading…
Reference in New Issue