Ios 在金属中反射着色器统一名称
假设我的着色器中有以下统一缓冲区:Ios 在金属中反射着色器统一名称,ios,objective-c,macos,shader,metal,Ios,Objective C,Macos,Shader,Metal,假设我的着色器中有以下统一缓冲区: typedef struct { matrix_float4x4 modelview_projection_matrix; float someValue; } uniforms_t; 如何在C++或ObjuleC中获取SealVeUE的位置?我想这样做: void Shader::SetFloat( const char* name, float value ) 其中的名称应该是“someValue”。看看苹果公司的部分 作为一个非常基本
typedef struct
{
matrix_float4x4 modelview_projection_matrix;
float someValue;
} uniforms_t;
如何在C++或ObjuleC中获取SealVeUE的位置?我想这样做:
void Shader::SetFloat( const char* name, float value )
其中的名称应该是“someValue”。看看苹果公司的部分
作为一个非常基本的解释
uniforms\u t
结构(通常是包含特定着色器函数的所有uniforms的单个结构)作为金属着色器函数的参数,并将其与特定缓冲区索引(例如[[buffer(0)]]
)关联,作为着色器函数声明的一部分制服
结构的内容复制到MTLBuffer
中的某个偏移位置MTLRenderCommandEncoder
setVertexBuffer:offset:atIndex:或setFragmentBuffer:offset:atIndex:
方法来关联MTLBuffer
的内容(在复制制服的偏移处)使用着色器函数中声明的缓冲区索引。这基本上告诉着色器函数哪个MTLBuffer
查找该函数参数的值(以及在该缓冲区中的位置)
uniforms\u t
结构(通常是包含特定着色器函数的所有uniforms的单个结构)作为金属着色器函数的参数,并将其与特定缓冲区索引(例如[[buffer(0)]]
)关联,作为着色器函数声明的一部分制服
结构的内容复制到MTLBuffer
中的某个偏移位置MTLRenderCommandEncoder
setVertexBuffer:offset:atIndex:或setFragmentBuffer:offset:atIndex:
方法来关联MTLBuffer
的内容(在复制制服的偏移处)使用着色器函数中声明的缓冲区索引。这基本上告诉着色器函数哪个MTLBuffer
查找该函数参数的值(以及在该缓冲区中的位置)
我通过检查的源代码找到了一个解决方案:
NSError* error = NULL;
MTLRenderPipelineReflection* reflectionObj;
MTLPipelineOption option = MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
id <MTLRenderPipelineState> pso = [device newRenderPipelineStateWithDescriptor:pipelineStateDescriptor options:option reflection:&reflectionObj error:&error];
for (MTLArgument *arg in reflectionObj.vertexArguments)
{
NSLog(@"Found arg: %@\n", arg.name);
if (arg.bufferDataType == MTLDataTypeStruct)
{
for( MTLStructMember* uniform in arg.bufferStructType.members )
{
NSLog(@"uniform: %@ type:%lu, location: %lu", uniform.name, (unsigned long)uniform.dataType, (unsigned long)uniform.offset);
}
}
}
NSError*error=NULL;
MTLRenderPipelineReflection*reflectionObj;
MTLPipelineOption=MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
id pso=[设备newRenderPipelineStateWithDescriptor:pipelineStateDescriptor选项:选项反射:&反射对象错误:&错误];
用于(反射率顶点参数中的MTLArgument*arg)
{
NSLog(@“找到参数:%@\n”,参数名称);
if(arg.bufferDataType==MTLDataTypeStruct)
{
用于(arg.bufferStructType.members中的MTLStructMember*统一)
{
NSLog(@“uniform:%@类型:%lu,位置:%lu”,uniform.name,(unsigned long)uniform.dataType,(unsigned long)uniform.offset);
}
}
}
我通过检查的源代码找到了一个解决方案:
NSError* error = NULL;
MTLRenderPipelineReflection* reflectionObj;
MTLPipelineOption option = MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
id <MTLRenderPipelineState> pso = [device newRenderPipelineStateWithDescriptor:pipelineStateDescriptor options:option reflection:&reflectionObj error:&error];
for (MTLArgument *arg in reflectionObj.vertexArguments)
{
NSLog(@"Found arg: %@\n", arg.name);
if (arg.bufferDataType == MTLDataTypeStruct)
{
for( MTLStructMember* uniform in arg.bufferStructType.members )
{
NSLog(@"uniform: %@ type:%lu, location: %lu", uniform.name, (unsigned long)uniform.dataType, (unsigned long)uniform.offset);
}
}
}
NSError*error=NULL;
MTLRenderPipelineReflection*reflectionObj;
MTLPipelineOption=MTLPipelineOptionBufferTypeInfo | MTLPipelineOptionArgumentInfo;
id pso=[设备newRenderPipelineStateWithDescriptor:pipelineStateDescriptor选项:选项反射:&反射对象错误:&错误];
用于(反射率顶点参数中的MTLArgument*arg)
{
NSLog(@“找到参数:%@\n”,参数名称);
if(arg.bufferDataType==MTLDataTypeStruct)
{
用于(arg.bufferStructType.members中的MTLStructMember*统一)
{
NSLog(@“uniform:%@类型:%lu,位置:%lu”,uniform.name,(unsigned long)uniform.dataType,(unsigned long)uniform.offset);
}
}
}
这不能回答问题,因为我的渲染器无法预先知道缓冲区布局。我正在编写一个游戏引擎,无法将缓冲区硬编码到引擎中,因为每个应用程序都可以使用不同类型的缓冲区。这就是为什么我必须从着色器代码中反射缓冲区,并找到MTLRenderPipelineReflection、MTLArgument和friends。我可能很快就能自己解决这个问题,如果是的话,我会发布一个答案。这并不能回答这个问题,因为我的渲染器无法事先知道缓冲区的布局。我正在编写一个游戏引擎,无法将缓冲区硬编码到引擎中,因为每个应用程序都可以使用不同类型的缓冲区。这就是为什么我必须从着色器代码中反射缓冲区,并找到MTLRenderPipelineReflection、MTLArgument和friends。我可能很快就能自己解决这个问题,如果是的话,我会发布一个答案。