Skip to main content

concinnity_render/uniforms/
bindless.rs

1//! The bindless texture pool's capacity, shared by every backend that declares
2//! the pool as a fixed-size array.
3//!
4//! Metal has always sized its pool this way (`BINDLESS_TEXTURE_COUNT`), and
5//! DirectX declares an unbounded array so it needs no ceiling at all. Vulkan
6//! used to size the pool to each world's texture table, which made the shader's
7//! `POOL_SIZE` a property of the world rather than of the build -- and a shader
8//! whose text depends on the world cannot be compiled ahead of that world. This
9//! constant is what lets the Vulkan programs be compiled at build time like
10//! every other one.
11//!
12//! A device that cannot seat the ceiling falls back to sizing the pool to the
13//! world, exactly as before. That shader text then differs from the one the
14//! build script compiled, so the precompiled artifact simply does not match and
15//! the renderer compiles -- which is the same content check that governs every
16//! other artifact, with no special case for it.
17
18/// Slots in the bindless texture pool. The shader's `POOL_SIZE` define is
19/// injected from this value, so the array and the descriptor binding cannot
20/// drift.
21///
22/// Matches Metal's `BINDLESS_TEXTURE_COUNT`. A world with more textures than
23/// this has its pool indices clamped into range, so an over-cap index samples a
24/// valid texture rather than reading past the array.
25pub const BINDLESS_POOL_SIZE: usize = 1024;
26
27// The ceiling has to leave room for the reserved fallbacks (flat-normal and
28// white) every world appends past its own textures.
29const _: () = assert!(BINDLESS_POOL_SIZE > crate::render_types::FALLBACK_TEXTURE_COUNT);
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    // Matching Metal's pool keeps one texture budget across the backends, so a
36    // world that fits on one fits on the others.
37    #[test]
38    fn the_ceiling_matches_the_metal_pool() {
39        assert_eq!(BINDLESS_POOL_SIZE, 1024);
40    }
41}