金属中的阵列纹理(不与纹理数组混淆)可同时将等维纹理的非编译时间常量传递给GPU。到目前为止,我所知道的创建这些数据的唯一方法是使用自定义MTLTextureDescriptor
,然后手动复制数据。目前,我使用for循环一次复制一个切片:
let descriptor = MTLTextureDescriptor()
descriptor.width = 32
descriptor.height = 32
descriptor.mipmapLevelCount = 5
descriptor.storageMode = .private
descriptor.textureType = .type2DArray
descriptor.pixelFormat = .rgba8Unorm
descriptor.arrayLength = NUM_TEXTURES
if let texture = device.makeTexture(descriptor: descriptor) {
for i in 0..<NUM_TEXTURES {
commandEncoder.copy(from: sharedBufferWithTextureData, sourceOffset: i<<4096, sourceBytesPerRow: 128, sourceBytesPerImage: 4096, to: texture, destinationSlice: i, destinationLevel: 0, destinationOrigin: MTLOrigin())
}
}
commandEncoder.generateMipmaps(for: texture)
然而,是否有一种方法可以同时复制所有的切片?OpenGL似乎提供了一种方法来做到这一点,但我如何在金属中做到这一点呢?创建MTLTexture
对象的最佳方法是什么,其中textureType
是type2DArray
,storageMode
是private
,然后填充纹理数据?
注意:storageMode
是private
,因为MTLTexture
不支持shared
,managed
导致数据的单独副本,这是不必要的内存使用。
发布于 2022-10-23 21:58:51
在单个blit命令中无法填充多个切片,因为没有任何copy()
方法可以一次处理多个切片。
也不可能使用切片数据创建缓冲区,并使用MTLBuffer.makeTexture()
创建共享缓冲区内存的纹理,因为此函数显式禁止与数组纹理一起使用。
同时复制纹理数据的“多”纹理值的唯一方法是将多个纹理组合成单个纹理,例如,使用纹理地图集。
https://stackoverflow.com/questions/74157074
复制相似问题