如何在金属中使用一系列纹理

时间:2018-10-17 07:18:08

标签: ios metal

我想在金属着色器中使用纹理数组,但是崩溃  当运行我的应用程序(iPhone6,A8)时,以下是错误日志:public Ssl ssl() { Ssl ssl = new Ssl(); ssl.setProtocol("TLS"); ssl.setClientAuth(Ssl.ClientAuth.valueOf("need".toUpperCase())); // Other SSL stuff return ssl; } // Not sure where this function is for 1.5.6 spring boot, but for 1.5.2 it is a method of the container factory which you need to override protected void customizeConnector(Connector aConnector) { final Ssl theSsl = ssl(); // .. Other stuff to enable disable based on condition // turn on SSL for our connector theSsl.setEnabled(true); this.setSsl(theSsl); this.setPort(myConnector.getPort()); //otherwise customizeConnector will override port }

我已经尝试过Google,但是找不到有用的信息,任何人都可以给我一些建议,谢谢。

这是我的代码:

Failed to created pipeline state, error Error Domain=AGXMetalA8 Code=3 "Could not resolve texture/sampler references" UserInfo={NSLocalizedDescription=Could not resolve texture/sampler references}

在我的应用代码中:

fragment float4 fragment_texture (ShaderInput vert [[stage_in]],
                        array<texture2d<float>, 2> u_texture [[texture(0)]],
                        sampler _mtlsmp_u_texture [[sampler(0)]])
{
    float4 srcColor = u_texture[0].sample(_mtlsmp_u_texture, vert.v_texCoord);
    float4 materialColor = u_texture[1].sample(_mtlsmp_u_texture, vert.v_texCoord);
    float4 mixColor = mix(srcColor, materialColor, 0.5);
    return mixColor;
}

更新问题

我尝试使用参数缓冲区处理纹理数组,但是在iOS 11.4版的iPhone6上仍然崩溃,并得到相同的错误信息: [renderEncoder setFragmentTexture:_textureDemo atIndex:0]; [renderEncoder setFragmentTexture:_textureBlend atIndex:1]; [renderEncoder setFragmentSamplerState:_sampler atIndex:0];

以下是一些关键步骤:

在我的应用程序代码中,Failed to create pipeline state, error Could not resolve texture/sampler references是MTLArgumentEncoder类型的对象,我通过调用setTexture:atIndex:

将纹理资源编码到参数缓冲区中。
argumentEncoder

调用useResource:usage:方法使纹理资源可供GPU访问:

 [argumentEncoder setArgumentBuffer:_fragmentShaderArgumentBuffer offset:0];
 [argumentEncoder setTexture:_texture[0] atIndex:0];
 [argumentEncoder setTexture:_texture[1] atIndex:1];

并将参数缓冲区_fragmentShaderArgumentBuffer设置为片段函数的参数:

[renderEncoder useResource:_texture[0] usage:MTLResourceUsageSample];
[renderEncoder useResource:_texture[1] usage:MTLResourceUsageSample];

在我的片段着色器中:

[renderEncoder setFragmentBuffer:_fragmentShaderArgumentBuffer
                              offset:0
                             atIndex:0];

衷心希望有人能为我提供想法,谢谢!

1 个答案:

答案 0 :(得分:0)

我升级到iOS 12.0.1,并且运行良好。