hal/gles: Fix compressed texture stride calculations

This commit is contained in:
Connor Fitzgerald 2022-02-25 01:28:21 -05:00 committed by Dzmitry Malyshau
parent 3f30a8011f
commit 926bf848cf
2 changed files with 31 additions and 23 deletions

View File

@ -139,7 +139,7 @@ jobs:
- name: caching
uses: Swatinem/rust-cache@v1
with:
key: ${{ matrix.target }}-a # suffix for cache busting
key: ${{ matrix.target }}-b # suffix for cache busting
- name: download nextest
if: matrix.kind == 'local'

View File

@ -463,12 +463,18 @@ impl super::Queue {
.map_or(copy.size.width * format_info.block_size as u32, |bpr| {
bpr.get()
});
let rows_per_image = copy.buffer_layout.rows_per_image.map_or(
copy.size.height / format_info.block_dimensions.1 as u32,
|rpi| rpi.get(),
);
let block_height = format_info.block_dimensions.1 as u32;
let minimum_rows_per_image = (copy.size.height + block_height - 1)
/ format_info.block_dimensions.1 as u32;
let rows_per_image = copy
.buffer_layout
.rows_per_image
.map_or(minimum_rows_per_image, |rpi| rpi.get());
let bytes_per_image = bytes_per_row * rows_per_image;
let minimum_bytes_per_image = bytes_per_row * minimum_rows_per_image;
let bytes_in_upload =
(bytes_per_image * (copy.size.depth - 1)) + minimum_bytes_per_image;
let offset = copy.buffer_layout.offset as u32;
let buffer_data;
@ -477,18 +483,35 @@ impl super::Queue {
gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, Some(buffer));
unbind_unpack_buffer = true;
glow::CompressedPixelUnpackData::BufferRange(
offset..offset + bytes_per_image,
offset..offset + bytes_in_upload,
)
}
None => {
buffer_data = src.data.as_ref().unwrap().lock().unwrap();
let src_data = &buffer_data.as_slice()
[(offset as usize)..(offset + bytes_per_image) as usize];
[(offset as usize)..(offset + bytes_in_upload) as usize];
glow::CompressedPixelUnpackData::Slice(src_data)
}
};
log::error!(
"bytes_per_row: {}, \
minimum_rows_per_image: {}, \
rows_per_image: {}, \
bytes_per_image: {}, \
minimum_bytes_per_image: {}, \
bytes_in_upload: {}\
",
bytes_per_row,
minimum_rows_per_image,
rows_per_image,
bytes_per_image,
minimum_bytes_per_image,
bytes_in_upload
);
match dst_target {
glow::TEXTURE_3D | glow::TEXTURE_2D_ARRAY => {
glow::TEXTURE_3D
| glow::TEXTURE_CUBE_MAP_ARRAY
| glow::TEXTURE_2D_ARRAY => {
gl.compressed_tex_sub_image_3d(
dst_target,
copy.texture_base.mip_level as i32,
@ -526,21 +549,6 @@ impl super::Queue {
unpack_data,
);
}
glow::TEXTURE_CUBE_MAP_ARRAY => {
//Note: not sure if this is correct!
gl.compressed_tex_sub_image_3d(
dst_target,
copy.texture_base.mip_level as i32,
copy.texture_base.origin.x as i32,
copy.texture_base.origin.y as i32,
copy.texture_base.origin.z as i32,
copy.size.width as i32,
copy.size.height as i32,
copy.size.depth as i32,
format_desc.internal,
unpack_data,
);
}
_ => unreachable!(),
}
}