- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在努力更好地理解使用 Metal Performance Shaders
时的同步要求和一个 MTLBlitCommandEncoder
.
我有一个 MTLCommandBuffer
设置如下:
使用 MTLBlitCommandEncoder
将纹理 A 的区域复制到纹理 B。纹理 A 比纹理 B 大。我正在从纹理 A 中提取“图 block ”并将其复制到纹理 B。
使用MPSImageBilinearScale
Metal 性能着色器,纹理 B 作为源纹理,第三个纹理纹理 C 作为目标。此 Metal 性能着色器将缩放并可能将纹理 B 的内容转换为纹理 C。
在 Metal 性能着色器开始尝试缩放纹理 B 之前,如何确保 blit 编码器完全完成将数据从纹理 A 复制到纹理 B?我是否还需要为此担心,或者命令缓冲区的串行特性是否已经为我解决了这个问题?
Metal 有栅栏的概念使用 MTLFence
用于同步对资源的访问,但无论如何我都看不到 Metal 性能着色器在栅栏上等待。 (而 waitForFence:
出现在编码器上。)
如果我不能使用 fences 而我确实需要同步,推荐的做法是将 blit 编码器加入队列,然后调用 waitUntilCompleted
在将着色器加入队列并调用之前在命令缓冲区上 waitUntilCompleted
第二次?例如:
id<MTLCommandBuffer> commandBuffer;
// Enqueue blit encoder to copy Texture A -> Texture B
id<MTLBlitCommandEncoder> blitEncoder = [commandBuffer blitCommandEncoder];
[blitEncoder copyFromTexture:...];
[blitEncoder endEncoding];
// Wait for blit encoder to complete.
[commandBuffer commit];
[commandBuffer waitUntilCompleted];
// Scale Texture B -> Texture C
MPSImageBilinearScale *imageScaleShader = [[MPSImageBilinearScale alloc] initWithDevice:...];
[imageScaleShader encodeToCommandBuffer:commandBuffer...];
// Wait for scaling shader to complete.
[commandBuffer commit];
[commandBuffer waitUntilCompleted];
我认为我需要将中间副本复制到纹理 B 的原因是因为 忽略这个脚注,因为我忘记了一些基本的数学原理,并且从那以后想出了如何使缩放变换的平移属性与 clipRect 一起工作。MPSImageBilinearScale
似乎缩放其整个源纹理。 clipOffset
对输出很有用,但不适用于实际的缩放或变换。因此,需要将图 block 从纹理 A 提取到与图 block 本身大小相同的纹理 B 中。然后缩放和变换将“有意义”。
最佳答案
Metal 会为您处理这件事。驱动程序和 GPU 以串行方式在命令缓冲区中执行命令。 (“好像”允许并行运行或乱序运行以提高效率,但前提是结果与串行运行时相同。)
当 CPU 和 GPU 处理相同的对象时,就会出现同步问题。还可以在屏幕上呈现纹理。 (您不应该渲染到屏幕上显示的纹理。)
有一个 section of the Metal Programming Guide它处理着色器对资源的读写访问,这并不完全相同,但应该让你放心:
Memory Barriers
Between Command Encoders
All resource writes performed in a given command encoder are visible in the next command encoder. This is true for both render and compute command encoders.
Within a Render Command Encoder
For buffers, atomic writes are visible to subsequent atomic reads across multiple threads.
For textures, the
textureBarrier
method ensures that writes performed in a given draw call are visible to subsequent reads in the next draw call.Within a Compute Command Encoder
All resource writes performed in a given kernel function are visible in the next kernel function.
关于objective-c - 如何将 Metal Performance Shader 与 MTLBlitCommandEncoder 同步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52007588/
在 Metal 中,在着色器内部(进出)使用什么坐标系?当我们渲染到纹理时是一样的吗?也有z缓冲区?有没有不一致的地方?最后 Metal ,opengl和directX有什么区别? 最佳答案 Meta
我正在尝试在 Mac 上的 Apple metal 中开发我自己的迷你游戏引擎,但我被困在我想在 GPU 上渲染文本的地方。我没有太多的图形编程经验,因此我不知道该怎么做。我偶然发现了 Warren
我找不到答案的简单问题,在 openGL 上有一个 glDeleteTextures(1, &t) 显然模型有很大的不同,但我想知道 Metal 是否有相同的需要或要求。 MTLTexture 是通过
我是 Metal 新手。我想使用 Metal 计算来做一些数学运算,所以我创建了一个内核函数(着色器?),比方说 kernel void foo(device float *data1,
我假设除了 Metal 之外的其他 API 中存在颜色附件(我肯定知道 OpenGL),但我是图形编程的新手,我想知道颜色附件在概念上到底是什么。我所做的所有绘图都涉及在颜色附件数组中的第一个设置属性
在计算着色器中,我可以看到双三次是一个选项,但前提是定义了 __HAVE_BICUBIC_FILTERING__。当我将 bicubic 设置为过滤选项时,出现语法错误。 Linear 或Neares
这是一个绝对的初学者问题。 背景:我并不是真正的游戏开发者,但我正在努力学习底层 3D 编程的基础知识,因为这是一个有趣且有趣的话题。我选择了 Apple 的 Metal 作为图形框架。我知道 Sce
在 GLSL 中,我只需使用 out vec3 array[10]; 将数组从顶点着色器传递到片段着色器。然而,在 Metal 中,我想这样做: struct FragmentIn { flo
我看到 Apple GPU 硬件和 iOS/MacOS 版本的组合决定了一个功能集。我可以使用下面的快速代码片段查询我的 MTLDevice 支持哪些功能集。 device.supportsFeatu
我想将深度缓冲区保存到 Metal 纹理中,但我尝试过的任何方法似乎都不起作用。 _renderPassDesc.colorAttachments[1].clearColor = MTLClearCo
我想在我的 Metal 应用程序中实现一个 A-Buffer 算法来实现与订单无关的透明度。该技术的描述提到使用原子计数器。我从未使用过其中之一,甚至没有听说过。我刚刚阅读了 Metal Shadin
假设我有一个 N channel MPSImage 或基于 MTLTexture 的纹理数组。 我如何从中裁剪一个区域,复制所有 N 个 channel ,但改变“像素大小”? 最佳答案 我将只讨论裁
TL;DR:Metal 似乎没有检测到我的顶点着色器返回的内容 我有这两个用 MSL 编写的函数: vertex float4 base_image_rect(constant float4 *pos
如何在目标设置为 iOS 模拟器的情况下在 Xcode 6 中编译 iOS «Metal» 游戏? error: can't exec 'metal' (No such file or directo
将一些基本的 OpenGL ES 2.0 着色器移植到 Metal 着色器时,我不知道如何将 glsl 中的 in/inout/out 限定符转换为 Metal 着色器语言 (MSL)。例如, //O
我不想使用texture1d_array。我可以简单地传递一个 float 组吗?我将把它写入我的内核函数中。 最佳答案 为了写入内核函数内的 float 组,您需要向内核提供一个缓冲区参数。该参数应
我不想使用texture1d_array。我可以简单地传递一个 float 组吗?我将把它写入我的内核函数中。 最佳答案 为了写入内核函数内的 float 组,您需要向内核提供一个缓冲区参数。该参数应
我有一组 Metal 纹理作为纹理集存储在 Xcode Assets 目录中。我正在使用 MTKTextureLoader.newTexture(name:scaleFactor:bundle:opt
Apple 系统中似乎至少有六个矩阵库。其中之一是 simd 库,其类型在 CPU 和 GPU 代码中的工作方式相同。 import simd let mat = float3x3(...) let
有谁知道 Apple 的旧版本 Metal Feature Set Table 的可用性?文件? 当前的 Metal 3.0 文档仅引用 beta MTLGPUFamily 和 MTLSoftware
我是一名优秀的程序员,十分优秀!