小编Vah*_*yan的帖子

计算金属内核中的平均值

任何人都知道在金属内核中使用随机浮点数计算缓冲区平均值的正确方法吗?

在计算命令编码器上分派工作:

threadsPerGroup = MTLSizeMake(1, 1, inputTexture.arrayLength);
numThreadGroups = MTLSizeMake(1, 1, inputTexture.arrayLength / threadsPerGroup.depth);

[commandEncoder dispatchThreadgroups:numThreadGroups
               threadsPerThreadgroup:threadsPerGroup];
Run Code Online (Sandbox Code Playgroud)

内核代码:

kernel void mean(texture2d_array<float, access::read> inTex [[ texture(0) ]],
             device float *means                            [[ buffer(1) ]],
             uint3 id                                       [[ thread_position_in_grid ]]) {

    if (id.x == 0 && id.y == 0) {
        float mean = 0.0;
        for (uint i = 0; i < inTex.get_width(); ++i) {
            for (uint j = 0; j < inTex.get_height(); ++j) {
                    mean += inTex.read(uint2(i, j), id.z)[0];
            }
        }

        float textureArea …
Run Code Online (Sandbox Code Playgroud)

gpu compute-shader ios metal

5
推荐指数
1
解决办法
1866
查看次数

在 UIScrollView Swift3 中加载 UIViewController

我有 2UIViewController秒。一个UIViewController有很多按钮的视图,高+2000点。另一个UIViewController有一个UIScrollView.

这是我的代码:

import UIKit

 class ViewController: UIViewController {

@IBOutlet weak var scrollView: UIScrollView!


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.


    scrollView.contentSize = CGSize(width: 375, height: 2884)

    DispatchQueue.main.async {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let thumb_vc = storyboard.instantiateViewController(withIdentifier: "thumb") as! ThumbsViewController
        //self.present(vc, animated: true, completion: nil)

    self.addChildViewController(thumb_vc)
    self.scrollView.addSubview(thumb_vc.view)
   }
 } 
Run Code Online (Sandbox Code Playgroud)

尽管拇指UIViewController加载到UIScrollView,但大小错误且不滚动。

任何帮助表示赞赏

ios swift3 xcode8

1
推荐指数
1
解决办法
835
查看次数

标签 统计

ios ×2

compute-shader ×1

gpu ×1

metal ×1

swift3 ×1

xcode8 ×1