Productivity and Scale MTLTexture

Is it possible to create new MTLTexturedimensions of an w2/h2existing area MTLTexture x1/y1/w1/h1?

PS: I was thinking about using MTLTexture.buffer?.makeTexture, but the offset should be 64 bytes. Why?

+4
source share
1 answer

Here is an example of how you can do this with MPSImageLanczosScale. Note that it sourceRegionis expressed in the pixel coordinate system of the source texture, and destRegionshould be equal to the full area of ​​the destination texture (note that it does not specifically take into account the origin of the destination area):

let scaleX = Double(destRegion.size.width) / Double(sourceRegion.size.width)
let scaleY = Double(destRegion.size.height) / Double(sourceRegion.size.height)
let translateX = Double(-sourceRegion.origin.x) * scaleX
let translateY = Double(-sourceRegion.origin.y) * scaleY
let filter = MPSImageLanczosScale(device: device)
var transform = MPSScaleTransform(scaleX: scaleX, scaleY: scaleY, translateX: translateX, translateY: translateY)
let commandBuffer = commandQueue.makeCommandBuffer()
withUnsafePointer(to: &transform) { (transformPtr: UnsafePointer<MPSScaleTransform>) -> () in
    filter.scaleTransform = transformPtr
    filter.encode(commandBuffer: commandBuffer, sourceTexture: sourceTexture, destinationTexture: destTexture)
}
commandBuffer.commit()
commandBuffer.waitUntilCompleted()

CPU, , , . . , MPSImageLanczosScale , .

+2

Source: https://habr.com/ru/post/1662820/


All Articles