Struct demo_vk::graphics::BindlessTextureAtlas
source · pub struct BindlessTextureAtlas { /* private fields */ }Expand description
Maintains descriptors for a list of texture images. Textures can be accessed by their index in shaders when the descriptor is bound. e.g. “bindless” textures.
The descriptor set provided by the atlas expects the following bindings in shader code for descriptor set 0:
[vk_binding(0, 0)] SamplerState samplers[3];[vk_binding(1, 0)] texture2D textures[];
Samplers have the following properties (by index):
samplers[0]- Linear filtering, linear mipmaps, no anisotropic filteringsamplers[1]- Linear filtering, linear mipmaps, with anisotropic filteringsamplers[2]- Nearest filtering, nearest mipmap, no anisotropic filtering
§Why Descriptor Set 0?
Because the BindlessTextureAtlas can be bound a single time at the beginning of the renderpass for the frame and ignored after that. If a higher index is used, then switching to different graphics pipelines could require rebinding.
This works only so long as any subsequently bound pipelines have a compatible layout (e.g. they use the BindlessTextureAtlas’s descriptor_set_layout as descriptor 0).
Implementations§
source§impl BindlessTextureAtlas
impl BindlessTextureAtlas
sourcepub fn new(
ctx: Arc<VulkanContext>,
max_textures: u32,
frames_in_flight: &FramesInFlight,
) -> Result<Self>
pub fn new( ctx: Arc<VulkanContext>, max_textures: u32, frames_in_flight: &FramesInFlight, ) -> Result<Self>
Creates a new atlas that can hold up to max_textures total textures.
sourcepub fn add_texture(&mut self, texture: Arc<Texture>) -> u32
pub fn add_texture(&mut self, texture: Arc<Texture>) -> u32
Adds a texture to the atlas. The returned texture number can be used to index in to the textures array in a shader.
This function is safe to call at any time. The new texture will be available in the shader in the next frame.
sourcepub fn descriptor_set_layout(&self) -> &DescriptorSetLayout
pub fn descriptor_set_layout(&self) -> &DescriptorSetLayout
Borrows the descriptor set layout for the atlas. Useful when creating pipelines.
sourcepub fn bind_frame_descriptor(&mut self, frame: &Frame) -> Result<()>
pub fn bind_frame_descriptor(&mut self, frame: &Frame) -> Result<()>
Binds the descriptor for the given frame.
Conditionally updates the descriptor if any new textures have been added since the last frame.
Auto Trait Implementations§
impl Freeze for BindlessTextureAtlas
impl !RefUnwindSafe for BindlessTextureAtlas
impl Send for BindlessTextureAtlas
impl Sync for BindlessTextureAtlas
impl Unpin for BindlessTextureAtlas
impl !UnwindSafe for BindlessTextureAtlas
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.