Compute kernel fails to compile when calling texture.read()

If I compile a compute kernel with a call to texture.read(), it fails with the following error: "Error Domain=AGXMetalG13X Code=3 "Encountered unlowered function call to air.get_read_sampler" UserInfo={NSLocalizedDescription=Encountered unlowered function call to air.get_read_sampler}."

This error occurs on both macOS and iOS 26 Beta 5, but not when running on a simulator or in a playground. It does not occur on a macOS Sequoia VM. It occurs whether I use the old metal 3 or new metal 4 compilation method.

A workaround would be to use a sampler, but according to the feature tables, all platforms support reading from textures of all formats.

Below is a minimal example which produces the error:

let device = MTLCreateSystemDefaultDevice()!
let library = device.makeDefaultLibrary()!
let computeFunction = library.makeFunction(name: "compute_test")!
do {
    let pipeline = try device.makeComputePipelineState(function: computeFunction)
    debugPrint(pipeline)
} catch {
    debugPrint("Metal 3 failed with error:\n\(error)")
}
#import <metal_stdlib>
using namespace metal;

kernel void compute_test(uint2 gid [[thread_position_in_grid]],
                         texture2d<float, access::read> in [[texture(0)]],
                         texture2d<float, access::write> out [[texture(1)]]) {
    out.write(in.read(gid), gid);
}

I filed feedback FB19530049.

Answered by cmarrero in 853009022

I was running Tahoe beta 4. It is fixed upon updating to Tahoe beta 5

Accepted Answer

I was running Tahoe beta 4. It is fixed upon updating to Tahoe beta 5

Compute kernel fails to compile when calling texture.read()
 
 
Q