草庐IT

metallic

全部标签

swift - 如何将 16 位图像加载到 Metal 纹理中?

使用MTKTextureLoader.newTexture的推荐方法不适用于16位图像。named:版本默默地将图像转换为8位像素格式cgImage:版本以Imagedecodingfailed结束UIImage和NSImage都支持加载16位图像,并且有它们方便的.cgimage方法,可以在一行中转换为CGImage,因此在两个平台上获取CGImage都得到了解决。我如何编写一个转换CGImage并返回16位Metal纹理的函数? 最佳答案 下面的loadEXRTexture函数加载扩展范围的图像并将其像素转换为半精度float,

ios Metal : limit on number of variables used in a shader

我在为我的着色器添加一些复杂性后,今天开始收到以下错误:Executionofthecommandbufferwasabortedduetoanerrorduringexecution.Discarded(victimofGPUerror/recovery)(IOAFcode5)我发现它与实际添加的代码无关,但实际上我添加了更多变量和函数调用。我尝试从着色器中删除其他复杂性,错误被删除。我发现的另一件事是,当我将fastmath设置为false时,问题也消失了。我的第一个猜测是,当快速数学打开时,变量的数量会有某种限制。有这样的限制吗?还有其他想法为什么会发生这种错误吗?

swift - 使用 Metal Framework 将图像保存到磁盘时命令缓冲区的执行被中止/GPU 错误

我正在开发同时使用ARKit和Metal/MetalKit框架的IOS应用程序(ios12)。我正在捕获图像并将它们压缩并将它们保存到手机的文档目录中。手机每移动10厘米就会捕获图像。但是,大约10分钟后(保存了大约300MB的数据后)应用程序崩溃并吐出错误:"Executionofthecommandbufferwasabortedduetoanerrorduringexecution.Discarded(victimofGPUerror/recovery)(IOAFcode5)"有没有人看到这个或了解可能是什么问题? 最佳答案

ios - 如何使用 Metal 自定义计算着色器并获得非常流畅的性能?

我正在尝试使用苹果提供的默认MPSKernal滤镜和自定义computeShaders通过Metal应用实时相机滤镜。在计算着色器中,我使用MPSImageGaussianBlur进行了就地编码代码在这里funcencode(tocommandBuffer:MTLCommandBuffer,sourceTexture:MTLTexture,destinationTexture:MTLTexture,cropRect:MTLRegion=MTLRegion.init(),offset:CGPoint){letblur=MPSImageGaussianBlur(device:device,

swift - 如何使用 Metal 和 Swift 对 CAMetalLayer 进行深度测试?

最近我决定学习如何将Metal框架与Swift结合使用。我阅读了一些教程,观看了视频,做了一些事情,最后我不得不使用深度测试让事情看起来不错。我以前没有做过如此底层的图形编程,所以我在整个互联网上浏览了深度测试的工作原理以及如何使用CAMetalLayer和Metal实现它。然而,我发现的所有深度测试示例都是使用OpenGL完成的,我无法在Metal中找到此类功能。如何使用Metal和Swift通过CAMetalLayer实现深度测试?提前致谢! 最佳答案 这是一个很好的例子。http://metalbyexample.com/up

ios - Metal Custom CIFilter 不同的返回值

我正在编写CIFilter,但结果像素颜色与Metal函数的返回值不同。内核Metal#includeextern"C"{namespacecoreimage{float4foo(sample_trgb){returnfloat4(0.3f,0.5f,0.7f,1.0f);}}Metal过滤器.swiftimportCoreImageclassMetalFilter:CIFilter{privateletkernel:CIColorKernelvarinputImage:CIImage?overrideinit(){leturl=Bundle.main.url(forResource:

swift - Metal/Metal 2 + swift : How to pass complex Swift structure as shader argument?

我在Metal中有一个结构:structBlurDesc{shortfenceRows;shortoffs;shortsampleCnt;floatmuls[64];};它用作着色器参数:kernelvoidhBlurCompute(constantBlurDesc&blurDesc[[buffer(0)]],texture2dsrcTexture[[texture(0)]],texture2dhBlurTexture[[texture(1)]],ushortgid[[thread_position_in_grid]]){这是相应的Swift结构:structBlurDesc{varf

ios - 相当于 OpenGL 混合的 Metal

我试图了解什么是Metal中的mixOpenGL函数。这是我要转换的OpenGL代码:floatudRoundBox(vec2p,vec2b,floatr){returnlength(max(abs(p)-b+r,0.0))-r;}voidmainImage(outvec4fragColor,invec2fragCoord){//setupfloatt=0.2+0.2*sin(mod(iTime,2.0*PI)-0.5*PI);floatiRadius=min(iResolution.x,iResolution.y)*(0.05+t);vec2halfRes=0.5*iResoluti

ios - 使用 3D 类型初始化 Metal 纹理

最近在玩SceneKit,发现了colorGrading这个属性。医生说Thecontentsvalueforthismaterialpropertymustbea3Dcolorlookuptable,ora2Dtextureimagethatrepresentssuchatablearrangedinahorizontalstrip.并且3D颜色查找表可以从Metal纹理中读取。YoucanprovidedatainthiscubicformatasaMetaltexturewiththetype3Dtexturetype.那么如何设置scnCamera.colorGrading.c

ios - Swift Metal MTLCreateSystemDefaultDevice 返回 nil

我尝试在MetaliOS上开发一些东西并收到以下错误:代码:letdevice=MTLCreateSystemDefaultDevice()!错误:Thread1:Fatalerror:UnexpectedlyfoundnilwhileunwrappinganOptionalvalue我在xcode9.4.1iOSSDK:11.4架构:arm64armv7armv7s有人可以帮忙吗 最佳答案 在真实设备iPhone或iPad上测试它,它不会在模拟器上运行。 关于ios-SwiftMeta