Add device reference counting

This commit is contained in:
Austin Eng 2017-07-10 11:16:51 -04:00 committed by Austin Eng
parent 563e9e253e
commit f9c39d021e
10 changed files with 17 additions and 41 deletions

View File

@ -138,4 +138,17 @@ namespace 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;
}
}
}

View File

@ -27,7 +27,7 @@ namespace backend {
class DeviceBase {
public:
DeviceBase();
~DeviceBase();
virtual ~DeviceBase();
void HandleError(const char* message);
@ -90,6 +90,8 @@ namespace backend {
void Tick();
void CopyBindGroups(uint32_t start, uint32_t count, BindGroupBase* source, BindGroupBase* target);
void SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata);
void Reference();
void Release();
private:
// 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::CallbackUserdata errorUserdata = 0;
uint32_t refCount = 1;
};
}

View File

@ -252,12 +252,6 @@ namespace d3d12 {
return new TextureView(builder);
}
void Device::Reference() {
}
void Device::Release() {
}
// DepthStencilState
DepthStencilState::DepthStencilState(Device* device, DepthStencilStateBuilder* builder)

View File

@ -132,10 +132,6 @@ namespace d3d12 {
void ExecuteCommandLists(std::initializer_list<ID3D12CommandList*> commandLists);
// NXT API
void Reference();
void Release();
private:
uint64_t serial = 0;
ComPtr<ID3D12Fence> fence;

View File

@ -117,10 +117,6 @@ namespace metal {
MapReadRequestTracker* GetMapReadTracker() const;
ResourceUploader* GetResourceUploader() const;
// NXT API
void Reference();
void Release();
private:
void OnCompletedHandler();

View File

@ -241,12 +241,6 @@ namespace metal {
return resourceUploader;
}
void Device::Reference() {
}
void Device::Release() {
}
// Bind Group
BindGroup::BindGroup(BindGroupBuilder* builder)

View File

@ -101,12 +101,6 @@ namespace null {
return std::move(pendingOperations);
}
void Device::Reference() {
}
void Device::Release() {
}
// Buffer
struct BufferMapReadOperation : PendingOperation {

View File

@ -112,10 +112,6 @@ namespace null {
void AddPendingOperation(std::unique_ptr<PendingOperation> operation);
std::vector<std::unique_ptr<PendingOperation>> AcquirePendingOperations();
// NXT API
void Reference();
void Release();
private:
std::vector<std::unique_ptr<PendingOperation>> pendingOperations;
};

View File

@ -100,12 +100,6 @@ namespace opengl {
void Device::TickImpl() {
}
void Device::Reference() {
}
void Device::Release() {
}
// Bind Group
BindGroup::BindGroup(BindGroupBuilder* builder)

View File

@ -98,10 +98,6 @@ namespace opengl {
TextureViewBase* CreateTextureView(TextureViewBuilder* builder) override;
void TickImpl() override;
// NXT API
void Reference();
void Release();
};
class BindGroup : public BindGroupBase {