【问题标题】:Do I need to put shader uniforms into the Vertex function signature?我是否需要将着色器制服放入 Vertex 函数签名中?
【发布时间】:2020-01-03 12:24:38
【问题描述】:

我有一个应该接受宽度、高度、u 偏移量和 v 偏移量以及颜色的着色器。

签名如下:

vertex VertexOut texturedVertex(constant packed_float3* pPosition   [[ buffer(0) ]],
                            constant packed_float2*        pTexCoords  [[ buffer(2) ]],
                            constant float&         pWidth      [[buffer(4)]],
                            constant float&         pHeight     [[buffer(5)]],
                            uint                    vid         [[ vertex_id ]],
                            constant packed_float4&        pColor      [[buffer(3)]])

这看起来很难看,而且根本无法扩展。 是否可以单独声明这些值,就像在 OpenGL 的制服中一样?

【问题讨论】:

  • 为什么不像为 CPU 编程那样使用结构数组?

标签: shader metal vertex-shader


【解决方案1】:

Argument Buffers - 参数缓冲区表示一组资源,可以作为参数共同分配给图形或计算函数。您可以使用参数缓冲区来减少 CPU 开销、简化资源管理并实现 GPU 驱动的管道。

以下示例显示了一个名为 My_AB 的参数缓冲区结构,它为名为 my_kernel 的内核函数指定资源:

struct My_AB {
    texture2d<float, access::write> a;
    depth2d<float> b;
    sampler c;
    texture2d<float> d;
    device float4* e;
    texture2d<float> f;
    int g;
};
kernel void my_kernel(constant My_AB & my_AB [[buffer(0)]])
{ ... }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多