ctt_intel_texture_compressor/
bc6h.rs1use crate::Rgba16Surface;
26use crate::bindings::kernel;
27
28#[derive(Debug, Copy, Clone)]
29pub struct EncodeSettings {
30 pub slow_mode: bool,
31 pub fast_mode: bool,
32 pub refine_iterations_1p: u32,
33 pub refine_iterations_2p: u32,
34 pub fast_skip_threshold: u32,
35}
36
37#[must_use]
38pub fn calc_output_size(width: u32, height: u32) -> usize {
39 let block_count = (width.div_ceil(4) * height.div_ceil(4)) as usize;
41 block_count * 16
42}
43
44#[must_use]
45pub fn compress_blocks(settings: &EncodeSettings, surface: &Rgba16Surface) -> Vec<u8> {
46 let output_size = calc_output_size(surface.width, surface.height);
47 let mut output = vec![0u8; output_size];
48 compress_blocks_into(settings, surface, &mut output);
49 output
50}
51
52pub fn compress_blocks_into(settings: &EncodeSettings, surface: &Rgba16Surface, blocks: &mut [u8]) {
63 assert_eq!(
64 blocks.len(),
65 calc_output_size(surface.width, surface.height)
66 );
67 let mut surface = kernel::rgba_surface {
70 width: surface.width as i32,
71 height: surface.height as i32,
72 stride: surface.stride as i32,
73 ptr: surface.data.as_ptr() as *mut u8,
74 };
75 let mut settings = kernel::bc6h_enc_settings {
76 slow_mode: settings.slow_mode,
77 fast_mode: settings.fast_mode,
78 refineIterations_1p: settings.refine_iterations_1p as i32,
79 refineIterations_2p: settings.refine_iterations_2p as i32,
80 fastSkipThreshold: settings.fast_skip_threshold as i32,
81 };
82
83 unsafe {
84 kernel::CompressBlocksBC6H_ispc(&mut surface, blocks.as_mut_ptr(), &mut settings);
85 }
86}
87
88pub fn very_fast_settings() -> EncodeSettings {
89 EncodeSettings {
90 slow_mode: false,
91 fast_mode: true,
92 fast_skip_threshold: 0,
93 refine_iterations_1p: 0,
94 refine_iterations_2p: 0,
95 }
96}
97
98pub fn fast_settings() -> EncodeSettings {
99 EncodeSettings {
100 slow_mode: false,
101 fast_mode: true,
102 fast_skip_threshold: 2,
103 refine_iterations_1p: 0,
104 refine_iterations_2p: 1,
105 }
106}
107
108pub fn basic_settings() -> EncodeSettings {
109 EncodeSettings {
110 slow_mode: false,
111 fast_mode: false,
112 fast_skip_threshold: 4,
113 refine_iterations_1p: 2,
114 refine_iterations_2p: 2,
115 }
116}
117
118pub fn slow_settings() -> EncodeSettings {
119 EncodeSettings {
120 slow_mode: true,
121 fast_mode: false,
122 fast_skip_threshold: 10,
123 refine_iterations_1p: 2,
124 refine_iterations_2p: 2,
125 }
126}
127
128pub fn very_slow_settings() -> EncodeSettings {
129 EncodeSettings {
130 slow_mode: true,
131 fast_mode: false,
132 fast_skip_threshold: 32,
133 refine_iterations_1p: 2,
134 refine_iterations_2p: 2,
135 }
136}