Skip to content

Commit 009a864

Browse files
committed
added R16G16B16A16_SFLOAT
1 parent cdd40dc commit 009a864

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

src/dfd.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,50 @@ impl BasicDataFormatDescriptor {
4545
samples,
4646
}
4747
}
48+
VkFormat::R16G16B16A16_SFLOAT => {
49+
let samples = vec![
50+
// R
51+
DFDSampleType {
52+
row_0: 15 << 16,
53+
row_1: 0u32,
54+
row_2: 0xBF800000u32, // IEEE 754 floating-point representation for -1.0f
55+
row_3: 0x3F800000u32, // IEEE 754 floating-point representation for 1.0f
56+
},
57+
// G
58+
DFDSampleType {
59+
row_0: 16 | 15 << 16 | 0b0000_0001 << 24,
60+
row_1: 0u32,
61+
row_2: 0xBF800000u32, // IEEE 754 floating-point representation for -1.0f
62+
row_3: 0x3F800000u32, // IEEE 754 floating-point representation for 1.0f
63+
},
64+
// B
65+
DFDSampleType {
66+
row_0: 32 | 15 << 16 | 0b0000_0010 << 24,
67+
row_1: 0u32,
68+
row_2: 0xBF800000u32, // IEEE 754 floating-point representation for -1.0f
69+
row_3: 0x3F800000u32, // IEEE 754 floating-point representation for 1.0f
70+
},
71+
// A
72+
DFDSampleType {
73+
row_0: 48 | 15 << 16 | 0b0000_1111 << 24,
74+
row_1: 0u32,
75+
row_2: 0xBF800000u32, // IEEE 754 floating-point representation for -1.0f
76+
row_3: 0x3F800000u32, // IEEE 754 floating-point representation for 1.0f
77+
},
78+
];
79+
let descriptor_block_size =
80+
(24 + std::mem::size_of::<DFDSampleType>() * samples.len()) as u32;
81+
BasicDataFormatDescriptor {
82+
dfd_total_size: descriptor_block_size + 4,
83+
row_0: 0u32,
84+
row_1: 2 | descriptor_block_size << 16,
85+
row_2: 1 << 0 | 1 << 8 | 1 << 16,
86+
row_3: 0u32,
87+
row_4: get_format_pixel_size_bytes(vk_format) as u32,
88+
row_5: 0u32,
89+
samples,
90+
}
91+
}
4892
VkFormat::R8G8B8A8_UNORM => {
4993
let samples = vec![
5094
// R

src/pixel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use half::f16;
33
#[allow(non_camel_case_types)]
44
pub enum Pixel {
55
R16_SFLOAT(f16),
6+
R16G16B16A16_SFLOAT([f16; 4]),
67
R8G8B8A8_UNORM([u8; 4]),
7-
BC1_RGB_UNORM_BLOCK
8-
}
8+
BC1_RGB_UNORM_BLOCK,
9+
}

src/texture.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ impl TextureKtx2 {
156156
self.level_images[index] = data[0];
157157
self.level_images[index + 1] = data[1];
158158
}
159+
Pixel::R16G16B16A16_SFLOAT(value) => {
160+
data.write_u16::<LittleEndian>(f16::to_bits(value[0]))
161+
.unwrap();
162+
data.write_u16::<LittleEndian>(f16::to_bits(value[1]))
163+
.unwrap();
164+
data.write_u16::<LittleEndian>(f16::to_bits(value[2]))
165+
.unwrap();
166+
data.write_u16::<LittleEndian>(f16::to_bits(value[3]))
167+
.unwrap();
168+
self.level_images[index] = data[0];
169+
self.level_images[index + 1] = data[1];
170+
self.level_images[index + 2] = data[2];
171+
self.level_images[index + 3] = data[3];
172+
}
159173
Pixel::R8G8B8A8_UNORM(data) => {
160174
self.level_images[index] = data[0];
161175
self.level_images[index + 1] = data[1];

src/vk_format.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,27 @@ pub enum VkFormat {
277277
ASTC_6x6x6_SFLOAT_BLOCK_EXT = 1000288029,
278278
A4R4G4B4_UNORM_PACK16_EXT = 1000340000,
279279
A4B4G4R4_UNORM_PACK16_EXT = 1000340001,
280-
MAX_ENUM = 0x7FFFFFFF
280+
MAX_ENUM = 0x7FFFFFFF,
281281
}
282282

283283
#[inline(always)]
284284
pub const fn get_format_type_size_bytes(format: VkFormat) -> u32 {
285285
match format {
286286
VkFormat::R16_SFLOAT => 2,
287+
VkFormat::R16G16B16A16_SFLOAT => 2,
287288
VkFormat::R8G8B8A8_UNORM => 1,
288289
VkFormat::BC1_RGB_UNORM_BLOCK => 1,
289-
_ => panic!("Unsupported format")
290+
_ => panic!("Unsupported format"),
290291
}
291292
}
292293

293294
#[inline(always)]
294295
pub const fn get_format_pixel_size_bytes(format: VkFormat) -> f32 {
295296
match format {
296297
VkFormat::R16_SFLOAT => 2.0,
298+
VkFormat::R16G16B16A16_SFLOAT => 8.0,
297299
VkFormat::R8G8B8A8_UNORM => 4.0,
298300
VkFormat::BC1_RGB_UNORM_BLOCK => 0.5,
299-
_ => panic!("Unsupported format")
301+
_ => panic!("Unsupported format"),
300302
}
301-
}
303+
}

0 commit comments

Comments
 (0)