Merge pull request #2883 from pml68/fix/16-byte-padding-wgpu-wasm

Fix WebGL WGPU crash
This commit is contained in:
Héctor 2025-04-09 23:48:39 +02:00 committed by GitHub
commit bd556269ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View file

@ -8,7 +8,7 @@ var<private> uvs: array<vec2<f32>, 6> = array<vec2<f32>, 6>(
);
@group(0) @binding(0) var u_sampler: sampler;
@group(0) @binding(1) var<uniform> u_ratio: vec2<f32>;
@group(0) @binding(1) var<uniform> u_ratio: vec4<f32>;
@group(1) @binding(0) var u_texture: texture_2d<f32>;
struct VertexInput {
@ -25,7 +25,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
let uv = uvs[input.vertex_index];
var out: VertexOutput;
out.uv = uv * u_ratio;
out.uv = uv * u_ratio.xy;
out.position = vec4<f32>(uv * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0);
return out;

View file

@ -254,6 +254,10 @@ impl Targets {
struct Ratio {
u: f32,
v: f32,
// Padding field to make Ratio 16 byte aligned
//
// See https://docs.rs/wgpu/latest/wgpu/struct.DownlevelFlags.html#associatedconstant.BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED
_padding: [f32; 2],
}
pub struct State {
@ -306,6 +310,7 @@ impl State {
let ratio = Ratio {
u: region_size.width as f32 / targets.size.width as f32,
v: region_size.height as f32 / targets.size.height as f32,
_padding: [0.0; 2],
};
if Some(ratio) != self.last_ratio {