You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@LegNeato Perhaps I can assist you with the QPTR, but I require further information. Could you please elaborate on what it is and from where it originates?
I have a simple example with an array that results in the same error:
Details
error: cannot cast between pointer types
from `*[[u32; 4]; 4]`
to `*[u32; 16]`
--> /home/nazar-pc/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/non_null.rs:436:6
|
436 | }
| ^
|
note: used from within `<core::ptr::non_null::NonNull<[[u32; 4]; 4]>>::cast::<[u32; 16]>`
--> /home/nazar-pc/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/non_null.rs:436:6
|
436 | }
| ^
note: called by `<ab_proof_of_space_gpu::shaders::chacha8::ChaCha8Block as core::ops::deref::DerefMut>::deref_mut`
--> src/shaders/chacha8.rs:25:18
|
25 | unsafe { NonNull::from_mut(&mut self.0).cast::<[u32; 16]>().as_mut() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Not sure if the root cause is the same, but it looks similar.
#[repr(C, align(16))]pubstructChaCha8Block(pub[[u32;4];4]);implDerefforChaCha8Block{typeTarget = [u32;16];#[inline(always)]fnderef(&self) -> &Self::Target{// SAFETY: Same size and alignmentunsafe{NonNull::from_ref(&self.0).cast::<[u32;16]>().as_ref()}}}implDerefMutforChaCha8Block{#[inline(always)]fnderef_mut(&mutself) -> &mutSelf::Target{// SAFETY: Same size and alignmentunsafe{NonNull::from_mut(&mutself.0).cast::<[u32;16]>().as_mut()}}}
This issue is one of the largest contributors of ugly non-idiomatic code in my codebase.
For example, I have a dynamic index into a fixed size array. This typically means I can use slice operators on an array, but because of this issue it doesn't work:
error: cannot cast between pointer types
from `*[struct ManuallyDrop<Match> { value: struct Match { .. } }; 288]`
to `*[struct ManuallyDrop<Match> { value: struct Match { .. } }]`
--> src/shader/find_matches_in_buckets.rs:348:35
|
348 | let Some(m) = matches.get_mut(local_matches_offset as usize) else {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So I have to make explicit bounds check separately and then do array indexing and on top of that hope that compiler will be able to see bounds check and not insert conditional panic on array access (which with rust-gpu I don't have 100% confidence in).
P.S. No idea where it found ManuallyDrop, I'm using MaybeUninit there instead 🤔
I think this is a hard blocker for me for now. I can't really use new types until this is fixed because I need to cast arrays of u32s from shared memory to arrays of use-case specific pointers that are just wrappers over u32 for any type safety.
Without pointer casting everything is just u32 and it is very difficult to make sense of anything. I can't write sane misuse resistant code like this, it feels more like writing in assembler without types.
Activity
LegNeato commentedon Apr 23, 2025
Can you try latest master? I landed 2f915a0 which fixed issues with a similar message (#46) and I think this is fixed by it too.
simensgreen commentedon Apr 24, 2025
Nope, even at commit 2f915a0 error still appears
simensgreen commentedon Apr 24, 2025
I tried trick it with
core::mem::transmute:Error:
simensgreen commentedon Apr 24, 2025
I created repo to test this error, but it failed to compile #242
LegNeato commentedon Apr 24, 2025
Ok great, I'll take a look.
LegNeato commentedon May 21, 2025
Wasn't able to find the root cause. This is going to churn shortly with some bigger qptr work so I am hesitant to spend more time until that lands
simensgreen commentedon May 25, 2025
@LegNeato Perhaps I can assist you with the QPTR, but I require further information. Could you please elaborate on what it is and from where it originates?
Fix union field access by representing unions as structs in SPIR-V
Fix union field access by representing unions as structs in SPIR-V
Fix union field access by representing unions as structs
nazar-pc commentedon Jun 25, 2025
I have a simple example with an array that results in the same error:
Details
Not sure if the root cause is the same, but it looks similar.
UPD: Tried #269 in its current state, same issue.
UPD2: Even simpler piece of code:
Fails with:
Both
dataandself.dataare[u32; 16].nazar-pc commentedon Sep 15, 2025
This issue is one of the largest contributors of ugly non-idiomatic code in my codebase.
For example, I have a dynamic index into a fixed size array. This typically means I can use slice operators on an array, but because of this issue it doesn't work:
So I have to make explicit bounds check separately and then do array indexing and on top of that hope that compiler will be able to see bounds check and not insert conditional panic on array access (which with rust-gpu I don't have 100% confidence in).
P.S. No idea where it found
ManuallyDrop, I'm usingMaybeUninitthere instead 🤔nazar-pc commentedon Sep 15, 2025
I think this is a hard blocker for me for now. I can't really use new types until this is fixed because I need to cast arrays of
u32s from shared memory to arrays of use-case specific pointers that are just wrappers overu32for any type safety.Without pointer casting everything is just
u32and it is very difficult to make sense of anything. I can't write sane misuse resistant code like this, it feels more like writing in assembler without types.nazar-pc commentedon Nov 7, 2025
I eventually ended up with an actual union situation myself, needing it for shared memory reuse between two parts of the fused shader.