Ensure Bevy's rendering byte usage is little-endian (#15750)

# Objective

- Fixes (partially) #15701.

## Solution

- Use little-endian bytes over native-endian bytes where applicable.

## Testing

- Ran CI.

## Open Questions

- Should we config-gate these for big-endian targets? It looks like
there are [very few
targets](https://doc.rust-lang.org/nightly/rustc/platform-support.html)
that use big-endian.
This commit is contained in:
Antony 2024-10-08 23:43:35 +01:00 committed by GitHub
parent 700123ec64
commit 0837ade0fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -54,10 +54,10 @@ impl AssetLoader for HdrTextureLoader {
for rgb in image_buffer.pixels() {
let alpha = 1.0f32;
rgba_data.extend_from_slice(&rgb.0[0].to_ne_bytes());
rgba_data.extend_from_slice(&rgb.0[1].to_ne_bytes());
rgba_data.extend_from_slice(&rgb.0[2].to_ne_bytes());
rgba_data.extend_from_slice(&alpha.to_ne_bytes());
rgba_data.extend_from_slice(&rgb.0[0].to_le_bytes());
rgba_data.extend_from_slice(&rgb.0[1].to_le_bytes());
rgba_data.extend_from_slice(&rgb.0[2].to_le_bytes());
rgba_data.extend_from_slice(&alpha.to_le_bytes());
}
Ok(Image::new(

View File

@ -119,10 +119,10 @@ impl Image {
let b = pixel[2];
let a = 1f32;
local_data.extend_from_slice(&r.to_ne_bytes());
local_data.extend_from_slice(&g.to_ne_bytes());
local_data.extend_from_slice(&b.to_ne_bytes());
local_data.extend_from_slice(&a.to_ne_bytes());
local_data.extend_from_slice(&r.to_le_bytes());
local_data.extend_from_slice(&g.to_le_bytes());
local_data.extend_from_slice(&b.to_le_bytes());
local_data.extend_from_slice(&a.to_le_bytes());
}
data = local_data;

View File

@ -474,14 +474,14 @@ impl FrameData {
let timestamps = data[..(self.num_timestamps * 8) as usize]
.chunks(8)
.map(|v| u64::from_ne_bytes(v.try_into().unwrap()))
.map(|v| u64::from_le_bytes(v.try_into().unwrap()))
.collect::<Vec<u64>>();
let start = self.pipeline_statistics_buffer_offset as usize;
let len = (self.num_pipeline_statistics as usize) * 40;
let pipeline_statistics = data[start..start + len]
.chunks(8)
.map(|v| u64::from_ne_bytes(v.try_into().unwrap()))
.map(|v| u64::from_le_bytes(v.try_into().unwrap()))
.collect::<Vec<u64>>();
let mut diagnostics = Vec::new();