KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
1.96k stars 549 forks source link

MSL: Support ConstOffsets on image gather. #2325

Closed billhollings closed 1 month ago

billhollings commented 1 month ago

@cdavis5e Please review too.

billhollings commented 1 month ago

I still think doing four separate gathers feels like too much work, since 75% of the work will be thrown away. But, I don't see a better way forward here.

I agree. It seems a waste. But as you've pointed out elsewhere, it needs to be a sample, rather than a read, to get the behavior at the edges right. FWIW...CTS actually uses direct reads when creating the reference image on the CPU, but has logic to handle the address modes, and -0.5-pixel skew when determining the correct pixel to read.

I supposed spvGatherConstOffsets() could do a bounds check on the coord value, and, if it's within bounds, use 4 reads, instead of gathers. Perhaps a future enhancement. But, on the other hand, gathers should be fairly efficient, cache-wise, so it might not cost much more to pull in 4 pixel values compared to 1. And functionally, we're in pretty niche-territory anyway.