Destroy backend implementation for Buffers

Destroy can be used to free the GPU memory associated with resources
without waiting for javascript garbage collection to occur.
The buffer is validated at submission to the queue.
So any buffer that has been destroyed before submission, will then
invalidate the submit and result in an error.

Bug: dawn:46
Change-Id: I40df56ce97baef01deea7552d7a6d40b558fc985
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5320
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
Natasha Lee
2019-03-07 19:56:14 +00:00
committed by Commit Bot service account
parent aa9d6ad09d
commit b6a80b321e
14 changed files with 179 additions and 11 deletions

View File

@@ -27,6 +27,10 @@ namespace dawn_native { namespace opengl {
glBufferData(GL_ARRAY_BUFFER, GetSize(), nullptr, GL_STATIC_DRAW);
}
Buffer::~Buffer() {
DestroyImpl();
}
GLuint Buffer::GetHandle() const {
return mBuffer;
}
@@ -58,4 +62,9 @@ namespace dawn_native { namespace opengl {
glUnmapBuffer(GL_ARRAY_BUFFER);
}
void Buffer::DestroyImpl() {
glDeleteBuffers(1, &mBuffer);
mBuffer = 0;
}
}} // namespace dawn_native::opengl

View File

@@ -26,6 +26,7 @@ namespace dawn_native { namespace opengl {
class Buffer : public BufferBase {
public:
Buffer(Device* device, const BufferDescriptor* descriptor);
~Buffer();
GLuint GetHandle() const;
@@ -34,6 +35,7 @@ namespace dawn_native { namespace opengl {
void MapReadAsyncImpl(uint32_t serial) override;
void MapWriteAsyncImpl(uint32_t serial) override;
void UnmapImpl() override;
void DestroyImpl() override;
GLuint mBuffer = 0;
};