Skip to content

Commit d79e664

Browse files
committed
Revert uint<2> type changes which require a nightly ISPC
1 parent c9ebfba commit d79e664

3 files changed

Lines changed: 57 additions & 102 deletions

File tree

src/ispc/downsample_ispc.rs

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,6 @@
22
pub mod downsample_ispc {
33
/* automatically generated by rust-bindgen 0.61.0 */
44

5-
#[repr(C)]
6-
#[repr(align(16))]
7-
#[derive(Debug, Copy, Clone)]
8-
pub struct uint32_t2 {
9-
pub v: [u32; 2usize],
10-
}
11-
#[test]
12-
fn bindgen_test_layout_uint32_t2() {
13-
const UNINIT: ::std::mem::MaybeUninit<uint32_t2> = ::std::mem::MaybeUninit::uninit();
14-
let ptr = UNINIT.as_ptr();
15-
assert_eq!(
16-
::std::mem::size_of::<uint32_t2>(),
17-
16usize,
18-
concat!("Size of: ", stringify!(uint32_t2))
19-
);
20-
assert_eq!(
21-
::std::mem::align_of::<uint32_t2>(),
22-
16usize,
23-
concat!("Alignment of ", stringify!(uint32_t2))
24-
);
25-
assert_eq!(
26-
unsafe { ::std::ptr::addr_of!((*ptr).v) as usize - ptr as usize },
27-
0usize,
28-
concat!(
29-
"Offset of field: ",
30-
stringify!(uint32_t2),
31-
"::",
32-
stringify!(v)
33-
)
34-
);
35-
}
365
#[repr(C)]
376
#[derive(Debug, Copy, Clone)]
387
pub struct Parameters {
@@ -74,54 +43,15 @@ fn bindgen_test_layout_Parameters() {
7443
)
7544
);
7645
}
77-
#[repr(C)]
78-
#[repr(align(16))]
79-
#[derive(Debug, Copy, Clone)]
80-
pub struct Image {
81-
pub data: *mut u8,
82-
pub __bindgen_padding_0: u64,
83-
pub size: uint32_t2,
84-
}
85-
#[test]
86-
fn bindgen_test_layout_Image() {
87-
const UNINIT: ::std::mem::MaybeUninit<Image> = ::std::mem::MaybeUninit::uninit();
88-
let ptr = UNINIT.as_ptr();
89-
assert_eq!(
90-
::std::mem::size_of::<Image>(),
91-
32usize,
92-
concat!("Size of: ", stringify!(Image))
93-
);
94-
assert_eq!(
95-
::std::mem::align_of::<Image>(),
96-
16usize,
97-
concat!("Alignment of ", stringify!(Image))
98-
);
99-
assert_eq!(
100-
unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize },
101-
0usize,
102-
concat!(
103-
"Offset of field: ",
104-
stringify!(Image),
105-
"::",
106-
stringify!(data)
107-
)
108-
);
109-
assert_eq!(
110-
unsafe { ::std::ptr::addr_of!((*ptr).size) as usize - ptr as usize },
111-
16usize,
112-
concat!(
113-
"Offset of field: ",
114-
stringify!(Image),
115-
"::",
116-
stringify!(size)
117-
)
118-
);
119-
}
12046
extern "C" {
12147
pub fn resample(
12248
params: *const Parameters,
123-
src: *const Image,
124-
dst: *mut Image,
49+
width: u32,
50+
height: u32,
51+
src_data: *const u8,
52+
target_width: u32,
53+
target_height: u32,
54+
dst_data: *mut u8,
12555
num_channels: u8,
12656
);
12757
}

src/ispc/kernels/lanczos3.ispc

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,35 +104,46 @@ static inline uint8<4> resample_internal(const uniform Image src_image, const fl
104104

105105
export void resample(
106106
uniform const Parameters *uniform params,
107-
uniform const Image *uniform src,
108-
uniform Image *uniform dst,
107+
108+
// TODO: Use the builtin type when ISPC 1.22 is released
109+
// https://github.com/ispc/ispc/issues/2650
110+
// https://github.com/ispc/ispc/pull/2654
111+
// uniform const Image &uniform src,
112+
// uniform Image &uniform dst,
113+
uniform uint32 width, uniform uint32 height,
114+
uniform const uint8 src_data[],
115+
uniform uint32 target_width, uniform uint32 target_height,
116+
uniform uint8 dst_data[],
117+
109118
// Passed separately because it should be the same between input and output:
110119
uniform uint8 num_channels
111120
) {
112-
const uniform float<2> inv_target_size = 1.0f / dst->size;
121+
const uniform Image src = {src_data, {width, height}};
122+
const uniform Image dst = {dst_data, {target_width, target_height}};
123+
const uniform float<2> inv_target_size = 1.0f / dst.size;
113124

114125
if (params->degamma) {
115-
foreach_tiled(y = 0 ... src->size.y, x = 0 ... src->size.x)
126+
foreach_tiled(y = 0 ... src.size.y, x = 0 ... src.size.x)
116127
{
117-
uint p = (x + y * src->size.x) * num_channels;
128+
uint p = (x + y * src.size.x) * num_channels;
118129
for (uniform int i = 0; i < num_channels; i++) {
119130
uint c = p + i;
120131
// TODO: This texture should be writeonly!
121-
src->data[c] = float_to_byte(pow(byte_to_float(src->data[c]), GAMMA), false);
132+
src.data[c] = float_to_byte(pow(byte_to_float(src.data[c]), GAMMA), false);
122133
}
123134
}
124135
}
125136

126-
foreach_tiled (y = 0 ... dst->size.y, x = 0 ... dst->size.x) {
137+
foreach_tiled (y = 0 ... dst.size.y, x = 0 ... dst.size.x) {
127138
float<2> uv = {x, y};
128139
// Use the center of each pixel, not the top-left:
129140
uv += 0.5f;
130141
// Convert to uniform space:
131142
uv *= inv_target_size;
132143

133-
const float<4> col = resample_internal(*src, uv, num_channels);
144+
const float<4> col = resample_internal(src, uv, num_channels);
134145

135146
for (uniform int i = 0; i < num_channels; i++)
136-
dst->data[(x + y * dst->size.x) * num_channels + i] = float_to_byte(col[i], params->gamma);
147+
dst.data[(x + y * dst.size.x) * num_channels + i] = float_to_byte(col[i], params->gamma);
137148
}
138149
}

src/lib.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,41 @@ pub fn downsample(
100100

101101
let num_channels = src.format.num_channels();
102102

103-
let src = ispc::downsample_ispc::Image {
104-
data: src.pixels.as_ptr() as *mut _,
105-
__bindgen_padding_0: 0,
106-
// TODO: Use the builtin type when ISPC 1.22 is released
107-
// https://github.com/ispc/ispc/issues/2650
108-
size: ispc::downsample_ispc::uint32_t2 {
109-
v: [src.width, src.height],
110-
},
111-
};
103+
// TODO: Use the builtin type when ISPC 1.22 is released
104+
// https://github.com/ispc/ispc/issues/2650
105+
// let src = ispc::downsample_ispc::Image {
106+
// // Bad const-cast to not have to have two types
107+
// data: src.pixels.as_ptr() as *mut _,
108+
// __bindgen_padding_0: 0,
109+
// size: ispc::downsample_ispc::uint32_t2 {
110+
// v: [src.width, src.height],
111+
// },
112+
// };
112113

113114
let mut output = vec![0; (target_width * target_height * num_channels as u32) as usize];
114115

115-
let mut dst = ispc::downsample_ispc::Image {
116-
data: output.as_mut_ptr(),
117-
__bindgen_padding_0: 0,
118-
size: ispc::downsample_ispc::uint32_t2 {
119-
v: [target_width, target_height],
120-
},
121-
};
116+
// let mut dst = ispc::downsample_ispc::Image {
117+
// data: output.as_mut_ptr(),
118+
// __bindgen_padding_0: 0,
119+
// size: ispc::downsample_ispc::uint32_t2 {
120+
// v: [target_width, target_height],
121+
// },
122+
// };
122123

123-
unsafe { ispc::downsample_ispc::resample(&params.to_ispc(), &src, &mut dst, num_channels) }
124+
// unsafe { ispc::downsample_ispc::resample(&params.to_ispc(), &src, &mut dst, num_channels) }
125+
unsafe {
126+
ispc::downsample_ispc::resample(
127+
&params.to_ispc(),
128+
src.width,
129+
src.height,
130+
src.pixels.as_ptr(),
131+
target_width,
132+
target_height,
133+
// &mut dst,
134+
output.as_mut_ptr(),
135+
num_channels,
136+
)
137+
}
124138

125139
output
126140
}

0 commit comments

Comments
 (0)