我想在顶点着色中修改带有纹理的地理网格。
我有一条正在工作的金属管道。
我通过了
MTLTexture
就这样:
commandEncoder.setVertexTexture(texture, index: 0)
commandEncoder.setVertexSamplerState(sampler, index: 0)
我的顶点着色功能:
vertex VertexOut distort3DVTX(const device VertexIn* vertecies [[ buffer(0) ]],
unsigned int vid [[ vertex_id ]],
texture2d<float> inTex [[ texture(0) ]],
sampler s [[ sampler(0) ]]) {
VertexIn vtxIn = vertecies[vid];
float x = vtxIn.position[0];
float y = vtxIn.position[1];
float u = x / 2 + 0.5;
float v = y / 2 + 0.5;
float2 uv = float2(u, v);
float4 c = inTex.sample(s, uv);
VertexOut vtxOut;
vtxOut.position = float4(x + (c.r - 0.5), y + (c.g - 0.5), 0, 1);
vtxOut.texCoord = vtxIn.texCoord;
return vtxOut;
}
这是我看到的错误:
由于执行期间出错,命令缓冲区的执行被中止。丢弃(GPU错误/恢复的受害者)(IOAF代码5)
如果我替换
float4 c = inTex.sample(s, uv);
具有
float4 c = 0.5;
我看不出错误。所以这绝对是对纹理取样的一种方法…
知道怎么解决吗
IOAF code 5
?
更新1:
错误代码似乎与纹理无关,当我试图通过一个统一的缓冲区时,也会发生同样的事情…
const device Uniforms& in [[ buffer(1) ]]
更新2:
编辑方案->运行->选项->GPU帧捕获->金属
以前我把它设置为
Automatically Enabled
.
现在我得到相关的错误日志:
线程1:信号SIGABRT
validateFunctionArguments:3469:断言失败'Vertex function(particle3dvtx):在[0]中的索引1处缺少缓冲区绑定。
但是我在前面撞了
drawPrimitives
或
endEncoding
…
更新3:
下面是我传递统一值的方法:
var vertexUnifroms: [Float] = ...
let size = MemoryLayout<Float>.size * vertexUnifroms.count
guard let uniformsBuffer = metalDevice.makeBuffer(length: size, options: []) else {
commandEncoder.endEncoding()
throw RenderError.uniformsBuffer
}
let bufferPointer = uniformsBuffer.contents()
memcpy(bufferPointer, &vertexUnifroms, size)
commandEncoder.setVertexBuffer(uniformsBuffer, offset: 0, index: 1)
更新4:
清洁有帮助。我现在看到它在哪里崩溃了;
DrawPrimitives(绘图原语)
。我的
vertexUnifroms
是空的,修理了虫子,现在我有制服了!