Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在金属中反射着色器统一名称_Ios_Objective C_Macos_Shader_Metal - Fatal编程技术网

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。我可能很快就能自己解决这个问题,如果是的话,我会发布一个答案。