Fixed it! I was writing colorAttachments[1].storeAction = .store where I should have written depthAttachment.storeAction = .store. So the depth attachment was on the default mode for depth attachments, .dontCare. It worked on the GPU frame capture because it stores all textures, but not on the real app because it was being discarded before the next render pass.
Post
Replies
Boosts
Views
Activity
Things I've tried so far:
Calling waitUntilCompleted() on the command encoder does not change anything.
Setting the shadow depth texture to compressed/non-compressed (using allowsGPUOptimizations) does not change anything.
I've checked that the shadow depth texture has a MTLPurgeableState of .nonVolatile so it's not being discarded.
Passing a fully 'white' (1.0) texture, which should always return true when sampled from the sample_compare with compare_func::less_equal. Same for a fully 'black' (0.0) texture, for what is worth...
Here are the shadow depth texture settings, anyway, in case any of it helps:
some : <CaptureMTLTexture: 0x600001b17e80> -> <AGXG13XFamilyTexture: 0x149e514c0>
label = Shadow Depth Texture
textureType = MTLTextureType2D
pixelFormat = MTLPixelFormatDepth32Float
width = 1024
height = 1024
depth = 1
arrayLength = 1
mipmapLevelCount = 1
sampleCount = 1
cpuCacheMode = MTLCPUCacheModeDefaultCache
storageMode = MTLStorageModePrivate
hazardTrackingMode = MTLHazardTrackingModeTracked
resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModePrivate MTLResourceHazardTrackingModeTracked
usage = MTLTextureUsageShaderRead MTLTextureUsageRenderTarget
shareable = 0
framebufferOnly = 0
purgeableState = MTLPurgeableStateNonVolatile
swizzle = [MTLTextureSwizzleRed, MTLTextureSwizzleGreen, MTLTextureSwizzleBlue, MTLTextureSwizzleAlpha]
isCompressed = 1
parentTexture = <null>
parentRelativeLevel = 0
parentRelativeSlice = 0
buffer = <null>
bufferOffset = 0
bufferBytesPerRow = 0
iosurface = 0x0
iosurfacePlane = 0
allowGPUOptimizedContents = YES
label = Shadow Depth Texture
label = Shadow Depth Texture
Passing down a fully white texture makes the sampler work as expected on the GPU Frame Capture (the model is lit) but still keeps returning 0.0 on the real view (the whole model is unlit). Only exception, if the sample falls outside the texture, and the sampler is set to clamp_to_border with border_color::opaque_white.
If I set it to clamp_to_edge, for example, samples outside the texture return 0.0 (unlit) too. So it's as if the texture was fully black on the real view, for some reason...