英文:
Do I need to put shader uniforms into the Vertex function signature?
问题
顶点着色器应接受宽度、高度、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的uniforms?
英文:
I have a shader that should accept width, height, u offset and v offset and a color.
the signature looks like this:
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)]])
This looks ugly and not scalable at all.
Is it possible to have the values be declared separately, something like in OpenGL's uniforms?
答案1
得分: 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)]])
{ ... }
英文:
Argument Buffers - an argument buffer represents a group of resources that can be collectively assigned as an argument to a graphics or compute function. You use argument buffers to reduce CPU overhead, simplify resource management, and implement GPU-driven pipelines.
The following example shows an argument buffer structure named My_AB
that specifies resources for a kernel function named 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)]])
{ ... }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论