Update Converter.swift

This commit is contained in:
markpmlim 2021-01-26 09:50:46 +08:00 committed by GitHub
parent 4399c39bae
commit 9011a279b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 6 deletions

View File

@ -212,13 +212,19 @@ public class MetalViewRenderer: NSObject, MTKViewDelegate {
offset: 0, offset: 0,
at: 2) at: 2)
let threadGroupCount = MTLSizeMake(8, 8, 1) // Use the max # of threads available for parallel processing.
let threadGroups = MTLSizeMake(texture.width / threadGroupCount.width, let w = cps.threadExecutionWidth
texture.height / threadGroupCount.height, let h = cps.maxTotalThreadsPerThreadgroup / w
1) let threadsPerThreadgroup = MTLSizeMake(w, h, 1)
let threadgroupsPerGrid = MTLSizeMake((texture.width + w - 1) / w,
(texture.height + h - 1) / h,
1)
// Execute the kernel function // Execute the kernel function
commandComputeEncoder.dispatchThreadgroups(threadGroups, // Note: boundary checks are necessary in the compute shader
threadsPerThreadgroup: threadGroupCount) // unless we use the alternative method
// dispatchThreads:threadsPerThreadgroup:
commandComputeEncoder.dispatchThreadgroups(threadgroupsPerGrid,
threadsPerThreadgroup: threadsPerThreadgroup)
commandComputeEncoder.endEncoding() commandComputeEncoder.endEncoding()
commandBuffer.commit() commandBuffer.commit()
} }