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?
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)]])
{ ... }