mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-17 00:47:13 +00:00
Destroy frontend and backend for Textures
Same idea as for buffers, Destroy can be used to free GPU memory associated with resources without waiting for javascript garbage collection to occur. Bug: dawn:46 Change-Id: Ia796b06b5228cbec4cfe8d78a500f967181d8c1f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5540 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Natasha Lee <natlee@microsoft.com>
This commit is contained in:
committed by
Commit Bot service account
parent
889d743baa
commit
cae68ff846
@@ -40,7 +40,8 @@ namespace dawn_native { namespace opengl {
|
||||
return nullptr;
|
||||
}
|
||||
GLuint nativeTexture = next.texture.u32;
|
||||
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture);
|
||||
return new Texture(ToBackend(GetDevice()), descriptor, nativeTexture,
|
||||
TextureBase::TextureState::OwnedExternal);
|
||||
}
|
||||
|
||||
void SwapChain::OnBeforePresent(TextureBase*) {
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace dawn_native { namespace opengl {
|
||||
// Texture
|
||||
|
||||
Texture::Texture(Device* device, const TextureDescriptor* descriptor)
|
||||
: Texture(device, descriptor, GenTexture()) {
|
||||
: Texture(device, descriptor, GenTexture(), TextureState::OwnedInternal) {
|
||||
uint32_t width = GetSize().width;
|
||||
uint32_t height = GetSize().height;
|
||||
uint32_t levels = GetNumMipLevels();
|
||||
@@ -150,14 +150,21 @@ namespace dawn_native { namespace opengl {
|
||||
glTexParameteri(mTarget, GL_TEXTURE_MAX_LEVEL, levels - 1);
|
||||
}
|
||||
|
||||
Texture::Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle)
|
||||
: TextureBase(device, descriptor), mHandle(handle) {
|
||||
Texture::Texture(Device* device,
|
||||
const TextureDescriptor* descriptor,
|
||||
GLuint handle,
|
||||
TextureState state)
|
||||
: TextureBase(device, descriptor, state), mHandle(handle) {
|
||||
mTarget = TargetForDimensionAndArrayLayers(GetDimension(), GetArrayLayers());
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
// TODO(kainino@chromium.org): delete texture (but only when not using the native texture
|
||||
// constructor?)
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Texture::DestroyImpl() {
|
||||
glDeleteTextures(1, &mHandle);
|
||||
mHandle = 0;
|
||||
}
|
||||
|
||||
GLuint Texture::GetHandle() const {
|
||||
|
||||
@@ -32,7 +32,10 @@ namespace dawn_native { namespace opengl {
|
||||
class Texture : public TextureBase {
|
||||
public:
|
||||
Texture(Device* device, const TextureDescriptor* descriptor);
|
||||
Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle);
|
||||
Texture(Device* device,
|
||||
const TextureDescriptor* descriptor,
|
||||
GLuint handle,
|
||||
TextureState state);
|
||||
~Texture();
|
||||
|
||||
GLuint GetHandle() const;
|
||||
@@ -40,6 +43,8 @@ namespace dawn_native { namespace opengl {
|
||||
TextureFormatInfo GetGLFormat() const;
|
||||
|
||||
private:
|
||||
void DestroyImpl() override;
|
||||
|
||||
GLuint mHandle;
|
||||
GLenum mTarget;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user