diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-08-17 01:41:16 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-08-17 02:07:34 -0700 |
| commit | b52d1be4302e452a45a03595f8c70411a061f920 (patch) | |
| tree | 27af0086f681df583389cfadafd65d7067d26fb2 /src/graphics/texture.rs | |
| parent | db64249ce8108439ada78a2d23d67d2c573a1688 (diff) | |
move the texture binding to a push descriptor
with a descriptor update template, even yay this also moves us to a minimum Vulkan version of 1.4, which we understand to be widely deployed. in theory, push descriptors and update templates were available via extensions in earlier versions, but it doesn't seem worth doing the work to switch out whether we use the extensions based on the version, so we don't. Force-Push: yes Change-Id: I26db8771abf5626d9614630c66e019ea99babcac
Diffstat (limited to 'src/graphics/texture.rs')
| -rw-r--r-- | src/graphics/texture.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/graphics/texture.rs b/src/graphics/texture.rs index b28d540..da40387 100644 --- a/src/graphics/texture.rs +++ b/src/graphics/texture.rs @@ -1,13 +1,18 @@ #![deny(unsafe_code)] use crate::error::*; -use crate::graphics::Permanent; +use crate::graphics::{ Permanent, Render }; use crate::graphics::util::{ stage_in_buffer, allocate_image, init_image_view, begin_transient_commands, end_transient_commands }; +use crate::shader_data::TexturePushBlock; + +use std::ffi::c_void; use vulkanalia::{ Device, Instance }; -use vulkanalia::vk::{ self, HasBuilder, InstanceV1_0, DeviceV1_0 }; +use vulkanalia::vk::{ + self, HasBuilder, InstanceV1_0, DeviceV1_0, DeviceV1_4 +}; #[derive(Debug)] @@ -47,6 +52,32 @@ impl Texture { unsafe { device.free_memory(self.image_memory, None) }; unsafe { device.destroy_image_view(self.image_view, None) }; } + + #[allow(unsafe_code)] + pub fn make_active(&self, device: &Device, render: &Render, + command_buffer: &vk::CommandBuffer) + { + let template = &render.texture_descriptor_update_template; + let layout = &render.pipeline_layout; + + // Constructing this every time may appear slow, but it's all CPU-side + // work, and the real cost we're trying to avoid with push descriptors is + // excessive CPU-GPU synchronziation. + let image_info = vk::DescriptorImageInfo::builder() + .image_view(self.image_view) + .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL) + .build(); + let push_block = TexturePushBlock { image_info }; + let push_block_bytes = &raw const push_block as *const c_void; + + // Please notice the magic constant 1. This is a one-based index into + // the array of descriptor set layouts passed to create_pipeline_layout() + // in init_pipeline() in render.rs. + unsafe { + device.cmd_push_descriptor_set_with_template( + *command_buffer, *template, *layout, 1, push_block_bytes) + }; + } } |