MTLTextures with Read and Write Usage

I am getting the following error when running the introductory Accelerated Ray Tracing project ( rewritten in Swift by Marius Horga ):


validateComputeFunctionArguments:831: failed assertion `Compute Function(shadowKernel): Shader uses texture(dstTex[0]) as read-write, but hardware does not support read-write texture of this pixel format.'


The MTLTextureDescriptor is set up as:


let renderTargetDescriptor = MTLTextureDescriptor()

renderTargetDescriptor.pixelFormat = .rgba32Float

renderTargetDescriptor.textureType = .type2D

renderTargetDescriptor.width = Int(size.width)

renderTargetDescriptor.height = Int(size.height)

renderTargetDescriptor.storageMode = .private

renderTargetDescriptor.usage = [.shaderRead, .shaderWrite]

renderTarget = device.makeTexture(descriptor: renderTargetDescriptor)


I am running the project with XCode 11 - Beta 3 on Catalina Beta 3. Apple's Objective C project works fine and the Swift rewrite works fine on Mojave / XCode 10.


Also, the Animated Ray Tracing example ( Objective C ) from this year's WWDC works ( obviously ).


This may be a bug that will be sorted out as the fall approaches, but if I am missing something, please let me know. There are no obvious work arounds for making the textures usable.


Thanks very much,

John Lobe

Replies

Take a look here:
https://developer.apple.com/documentation/metal/mtlreadwritetexturetier?language=objc
rgba32Float read-write textures are an optional feature (r32 should always work on macOS though).
You might get different results on different graphics cards (they changed the delafault device logic in Catalina, so that might explain the difference). Try selecting a specific device using MTLCopyAllDevices() (or whatever function you have in Swift) and testing both cards on both macOS versions (here I assume you have a 2-card setup)

Thanks very much. I will explore the texture tier of my ( internal MacBook Pro ) card. This sounds pretty interesting.


Whatever I find, my naive hope is that, ultimately, more than one channel will be supported as a read/write texture for my system.


Thanks again!