From: Karol Herbst Date: Wed, 4 May 2022 17:43:26 +0000 (+0200) Subject: rusticl/kernel: fix local buffers X-Git-Tag: upstream/22.3.5~3246 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a438533181a8f977fa70821fefe2a2dc9df35dec;p=platform%2Fupstream%2Fmesa.git rusticl/kernel: fix local buffers Signed-off-by: Karol Herbst Acked-by: Alyssa Rosenzweig Part-of: --- diff --git a/src/gallium/frontends/rusticl/core/kernel.rs b/src/gallium/frontends/rusticl/core/kernel.rs index 2e693cb..1e36bd7 100644 --- a/src/gallium/frontends/rusticl/core/kernel.rs +++ b/src/gallium/frontends/rusticl/core/kernel.rs @@ -749,7 +749,7 @@ impl Kernel { let offsets = create_kernel_arr::(offsets, 0); let mut input: Vec = Vec::new(); let mut resource_info = Vec::new(); - let mut local_size: u32 = nir.shared_size(); + let mut local_size: u64 = nir.shared_size() as u64; let printf_size = q.device.printf_buffer_size() as u32; let mut samplers = Vec::new(); let mut iviews = Vec::new(); @@ -804,8 +804,10 @@ impl Kernel { } KernelArgValue::LocalMem(size) => { // TODO 32 bit - input.extend_from_slice(&[0; 8]); - local_size += *size as u32; + let pot = cmp::min(*size, 0x80); + local_size = align(local_size, pot.next_power_of_two() as u64); + input.extend_from_slice(&local_size.to_ne_bytes()); + local_size += *size as u64; } KernelArgValue::Sampler(sampler) => { samplers.push(sampler.pipe()); @@ -900,7 +902,7 @@ impl Kernel { init_data.len() as u32, ); } - let cso = ctx.create_compute_state(nir, input.len() as u32, local_size); + let cso = ctx.create_compute_state(nir, input.len() as u32, local_size as u32); ctx.bind_compute_state(cso); ctx.bind_sampler_states(&samplers); diff --git a/src/gallium/frontends/rusticl/util/math.rs b/src/gallium/frontends/rusticl/util/math.rs index 08ff883..f6e8d96 100644 --- a/src/gallium/frontends/rusticl/util/math.rs +++ b/src/gallium/frontends/rusticl/util/math.rs @@ -1,4 +1,6 @@ +use std::ops::Add; use std::ops::Rem; +use std::ops::Sub; pub fn gcd(mut a: T, mut b: T) -> T where @@ -14,3 +16,20 @@ where b } + +pub fn align(val: T, a: T) -> T +where + T: Add, + T: Copy, + T: Default, + T: PartialEq, + T: Rem, + T: Sub, +{ + let tmp = val % a; + if tmp == T::default() { + val + } else { + val + (a - tmp) + } +}