- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道如何创建 MTLBuffer 和/或 MTLTexture,但是当不再需要这些资源时如何释放 GPU 内存?
最佳答案
MTLBuffer
和 MTLTexture
是 Objective-C 对象,因此可以进行引用计数。如果您在 Objective-C 项目中使用自动引用计数或通过 Swift 使用 Metal,只需确保不再保留对缓冲区或纹理的引用即可释放任何关联的硬件资源。
let texture: MTLTexture? = device.newTexture(with: descriptor)
texture = nil // <- resources will be released
在将 nil
分配给 texture
时,可以通过单步执行关联的程序集来确认这一点,这首先引导我们到 [MTLDebugTexture dealloc]
MetalTools`-[MTLDebugTexture dealloc]:
...
-> 0x100af569e <+34>: call 0x100af87ee ; symbol stub for: objc_msgSendSuper2
0x100af56a3 <+39>: add rsp, 0x10
0x100af56a7 <+43>: pop rbp
0x100af56a8 <+44>: ret
...并通过[MTLToolsObject dealloc]
MetalTools`-[MTLToolsObject dealloc]:
0x100ac6c7a <+0>: push rbp
0x100ac6c7b <+1>: mov rbp, rsp
0x100ac6c7e <+4>: push r14
...
...并通过 GeForceMTLDriver
GeForceMTLDriver`___lldb_unnamed_symbol1095$$GeForceMTLDriver:
-> 0x7fffd2e57b14 <+0>: push rbp
0x7fffd2e57b15 <+1>: mov rbp, rsp
一路上,通过各种dealloc
方法释放任何资源。
关于textures - 如何释放 MTLBuffer 和 MTLTexture,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39158302/
我正在使用 Metal 来显示相机框架。我将输出的样本缓冲区转换为 id使用 CVMetalTextureCacheCreateTextureFromImage ,效果很好……除了框架顺时针旋转了 9
我关注了this example 从 Apple 缩小非常大的图像我是 downloading from a remote location .我已经用 Swift 重写了代码。它显然有效,但是当我调
我可以创建一个新的 MTLTexture 尺寸 w2/h2 现有 MTLTexture 区域 x1/y1/w1/h1 ? PS:我考虑过使用 MTLTexture.buffer?.makeTextur
我正在尝试获取 MTLTexture 的像素这边走: let pixelCount = compareTexture.width * compareTexture.height let region
我有一个 MTLTexture,它是它出现在 MTLView 中的大小。但是,我正在将纹理写入 AVAssetWriterInputPixelBufferAdaptor 以录制需要纹理的视频标准视频尺
MTLTexture 之间的主要区别是什么?对比 CGImageRef ?我们什么时候需要使用MTLTexture而不是 CGImageRef (反之亦然)? 我有一个应用程序(比如视频游戏),它可以
我使用以下代码创建了一个 MTLTexture 对象(为清楚起见,仅列出了部分代码)。 int tmpbuf[4096] id device = MTLCreateSystemDefaultDevic
我试图通过计算每个像素的所有 R G B 和 A 分量的总和来确定 MTLTexture(bgra8Unorm 格式)是否为空白。 此函数旨在通过在将纹理复制到指针后在内存中添加相邻的 float 来
我知道如何创建 MTLBuffer 和/或 MTLTexture,但是当不再需要这些资源时如何释放 GPU 内存? 最佳答案 MTLBuffer 和 MTLTexture 是 Objective-C
写入IOSurface时需要使用哪些API,以及需要采取哪些预防措施在 XPC 进程中,该进程也被用作 MTLTexture 的后备存储。在主应用程序中? 在我的 XPC 服务中,我有以下内容: IO
我有这个方法 - (id) createTextureFromImage:(UIImage*) image device:(id) device { CGImageRef imageRef = i
我将计算着色器的结果存储在 MTLBuffer 中。 MTLBuffer 的每个元素都是一个 UInt16。我试图将结果传递给片段着色器,该着色器通过将 MTLBuffer 的元素解释为 0 到 25
我是 Metal 新手。我想从 CVImageBufferRef 制作 MTLTexture。我正在使用以下代码示例来执行此操作。 guard let unwrappedImageTe
我有一个之前从 png 文件创建的 UIImage: let strokeUIImage = UIImage(data: pngData) 我想将 strokeImage(具有不透明度)转换为 MTL
MTLTexture 是一种内存分配,用于存储 GPU 可访问的格式化图像数据。我想知道有没有什么方法可以在本地保存 MTLTexture 数据? 如果是这样,在本地保存 MTLTexture 数据的
我目前正在使用 Metal 开发实时过滤器。在定义我的 CIImage 之后,我将图像渲染到 MTLTexture。 下面是我的渲染代码。 context 是由 Metal 支持的 CIContext
生成由 CVPixelBuffer 支持的 MTLTexture 的正确方法是什么? 我有以下代码,但它似乎泄漏了: func PixelBufferToMTLTexture(pixelBuffer:
我有内核函数,它必须将从 pixelBuffer(ARFrame.capturedImage) 创建的 Y 和 CbCr 纹理转换为 RGB 纹理,就像在苹果指南中一样 https://develop
尝试在 SCNRender 对象的每次调用渲染上从 MTLTexture 创建 CVPixelBufferRef: CVPixelBufferLockBaseAddress(pixelBuffer
我有一个(动画)UIView-Hierarchy,我想定期将 UIView 内容渲染到 MTLTexture 中以供进一步处理。 我尝试过的是子类化我的父 UIView 和 override publ
我是一名优秀的程序员,十分优秀!