다음은 동일한 똑같은 2D 쿼드를 렌더링하는 metal
의 간단한 정점 및 조각 셰이더 콤보입니다. uv 좌표를 변경하여 예기치 않은 성능의 금속을 맞 춥니 다
vertex VertexOut vertexMain(uint k [[ vertex_id ]],
uint ii [[instance_id]],
device float2* tex [[buffer(2)]],
device float2* position [[buffer(1)]],
device float* state [[buffer(0)]]){
VertexOut output;
int i = 4*ii+1;
float2 pos = position[k];
pos *= float2(state[i+2],state[i+3]);
pos += float2(state[i],state[i+1]);
pos.x *= state[0];
output.position = float4(pos,0,1);
output.tex = tex[k]*float2(du,dv);
return output;
};
fragment float4 fragmentMain(VertexOut input [[stage_in]],
texture2d<float> texture [[texture(0)]],
sampler sam [[sampler(0)]]){
return texture.sample(sam, input.tex);
};
샘플러
는 0 내지 1 범위 및 왼쪽 하단부터 샘플링 방법 질감의 클립의 큰 정규화 좌표 제어 할 수 있으므로du
및
dv
를 사용한다.
금속에서 샘플링이 어떻게 작동하는지에 대한 오해가있는 것 같습니다. 나는 계산 값이 어떤 값 du
과 dv
에 상관없이 일정하게 유지 될 것으로 기대한다. 그러나 du
과 dv
을 1로 늘리면 프레임 속도가 떨어집니다. mipmapping을 사용하지 않고 화면에서 래스터 화 된 쿼드의 크기를 변경합니다. 영향은 선형 필터링에서는 더욱 극적이지만 가장 근접한 필터링에서도 발생합니다. 화면에 그려지는 픽셀 수가 동일하기 때문에 GPU의 부하는 du
및 dv
에 의존해서는 안됩니다. 내가 뭘 놓치고 있니?
편집 : 당신이 du
증가로
let samplerDescriptor = MTLSamplerDescriptor()
samplerDescriptor.normalizedCoordinates = true
samplerDescriptor.minFilter = .linear
samplerDescriptor.magFilter = .linear
let sampler = device.makeSamplerState(descriptor: samplerDescriptor)
let attachment = pipelineStateDescriptor.colorAttachments[0]
attachment?.isBlendingEnabled = true
attachment?.sourceRGBBlendFactor = .one
attachment?.destinationRGBBlendFactor = .oneMinusSourceAlpha
얼마나 많은 프레임 속도 드롭을 경험할 수 있습니까? – warrenm
선형 샘플링이 가능한 60에서 40까지. 가장 가까운 샘플링과 함께 60에서 50. – gloo
어떤 장치 및 OS 버전입니까? – warrenm