Skip to main content

qualia_core_db/render/gpu/
texture_precomputed.rs

1//! Universe-admitted coarse and precomputed texture upload adapters.
2use super::{
3    texture_mips::{AlphaCoverageDiagnostics, TextureMipSemantic},
4    texture_residency::{TextureColorSpace, TextureUploadError},
5    PortalGpu,
6};
7fn reserve(
8    class: etalon_render::texture_residency::TextureAllocation,
9    bytes: u64,
10) -> Option<crate::gpu_context::VramReservation<'static>> {
11    let class = match class {
12        etalon_render::texture_residency::TextureAllocation::TextureResidency => {
13            crate::gpu_context::VramResourceClass::TextureResidency
14        }
15        etalon_render::texture_residency::TextureAllocation::UploadStaging => {
16            crate::gpu_context::VramResourceClass::UploadStaging
17        }
18    };
19    crate::gpu_context::global_vram_ledger()
20        .try_reserve_graphics(class, bytes)
21        .ok()
22}
23impl PortalGpu {
24    pub fn upload_resident_texture_rgba8_at_mip_with_mips(
25        &mut self,
26        source_digest: [u8; 32],
27        color_space: TextureColorSpace,
28        mip_semantic: TextureMipSemantic,
29        source_width: u32,
30        source_height: u32,
31        first_resident_mip: u32,
32        coarse_rgba8: &[u8],
33    ) -> Result<Option<AlphaCoverageDiagnostics>, TextureUploadError> {
34        etalon_render::texture_precomputed::TextureUploader {
35            device: &self.device,
36            queue: &self.queue,
37            mip_generator: &self.mip_generator,
38            resident_textures: &mut self.resident_textures,
39            reserve,
40        }
41        .upload_resident_texture_rgba8_at_mip_with_mips(
42            source_digest,
43            color_space,
44            mip_semantic,
45            source_width,
46            source_height,
47            first_resident_mip,
48            coarse_rgba8,
49        )
50    }
51    pub fn upload_resident_texture_mip_chain_rgba8(
52        &mut self,
53        source_digest: [u8; 32],
54        color_space: TextureColorSpace,
55        mip_semantic: TextureMipSemantic,
56        width: u32,
57        height: u32,
58        levels: &[&[u8]],
59    ) -> Result<Option<AlphaCoverageDiagnostics>, TextureUploadError> {
60        self.upload_resident_texture_mip_window_rgba8(
61            source_digest,
62            color_space,
63            mip_semantic,
64            width,
65            height,
66            levels,
67            0,
68        )
69    }
70    pub fn upload_resident_texture_mip_window_rgba8(
71        &mut self,
72        source_digest: [u8; 32],
73        color_space: TextureColorSpace,
74        mip_semantic: TextureMipSemantic,
75        width: u32,
76        height: u32,
77        levels: &[&[u8]],
78        first_resident_mip: u32,
79    ) -> Result<Option<AlphaCoverageDiagnostics>, TextureUploadError> {
80        etalon_render::texture_precomputed::TextureUploader {
81            device: &self.device,
82            queue: &self.queue,
83            mip_generator: &self.mip_generator,
84            resident_textures: &mut self.resident_textures,
85            reserve,
86        }
87        .upload_resident_texture_mip_window_rgba8(
88            source_digest,
89            color_space,
90            mip_semantic,
91            width,
92            height,
93            levels,
94            first_resident_mip,
95        )
96    }
97}