未使用 Mipmap

Mipmaps aren't being used

在 Metal 中,我想出了如何生成和填充 MTLTexture 的 mipmap 级别。然而,当我渲染数以千计的这些 mipmapped 纹理并缩小时,我得到了独特的闪光。我已使用 Xcode 的调试器确定这些 mipmap 级别已填充,因此 代码有效。

let CommandBuffer = CommandQue.makeCommandBuffer()!, CommandEncoder =  CommandBuffer.makeBlitCommandEncoder()!
    CommandEncoder.generateMipmaps(for: BlockTextures!)
    CommandEncoder.endEncoding()
    CommandBuffer.commit()

创建并填充了 mipmap 级别,但闪烁仍然存在,这意味着它们没有被渲染和使用。我如何配置渲染管线或片段着色器,无论哪个使用 mipmap,我如何告诉它们使用 创建的mipmap?

在设置 mip_filter 的着色器中创建一个 sampler 对象。 有关参考,请参阅 metal shading language specification.

中的 2.9 采样器
constexpr sampler s(filter::linear, mip_filter::linear)

或者,创建一个 MTLSamplerDescriptor。 有关详细信息,请参阅 https://developer.apple.com/documentation/metal/textures/improving_filtering_quality_and_sampling_performance/adding_mipmap_filtering_to_samplers?language=objc