shader: validate texture mip ranges and channel selectors

This commit is contained in:
nmzik
2026-10-15 17:58:14 +02:00
parent 2caf2f7e4e
commit bcf13e101e
4 changed files with 81 additions and 28 deletions
+12
View File
@@ -66,6 +66,18 @@ inline uint8_t GetDstSel(uint32_t swizzle, uint32_t channel) {
return (swizzle >> (channel * 3u)) & 0x7u;
}
[[nodiscard]] inline bool IsValidImageSwizzle(uint32_t swizzle,
uint32_t component_count = 4) noexcept {
if ((swizzle & ~0xfffu) != 0) {
return false;
}
for (uint32_t channel = 0; channel < 4; channel++) {
const auto selector = GetDstSel(swizzle, channel);
if (selector > 1 && (selector < 4 || selector >= 4 + component_count)) return false;
}
return true;
}
struct ShaderClipSpaceTransform {
float scale[2] = {};
float offset[2] = {};