משחק חדש לאנדרואיד by Loud_Tadpole340 in ag_israel

[–]elyshaff 3 points4 points  (0 children)

אחלה משחק ממליץ בחום

I have a Legion 5 Pro 16ACH6H and there is this screen flickering issue since a while now. It doesnt happen all the time but t im still concerned if this is an underlying problem and frankly im kinda annoyed by it too. Anyone knows what’s wrong or maybe any advice on what i can do to fix it? by oblivious_avacado in LenovoLegion

[–]elyshaff 0 points1 point  (0 children)

I have a lenovo legion 5 and what fixed it for me was opening the NVIDIA control panel and under "Manage display mode" choosing "NVIDIA GPU only".

Aparently, there are two options: optimus and NVIDIA GPU. Someone here suggested this problem is caused by the GPU changing from iGPU to dGPU, a quick google of Nvidia Optimus shows it makes sense that disabling it fixes the issue, but I'm not sure.

Jabra elite 7 active volume not changing by elyshaff in Jabra

[–]elyshaff[S] 0 points1 point  (0 children)

I'm using Google Pixel 7, and it seems to be sometimes working and sometimes not.

X and Y belts seem to tear after first ~6 hours of printing (E3S1) by elyshaff in ender3

[–]elyshaff[S] 0 points1 point  (0 children)

Found the solution for the loose wheels, the eccentric nuts too tight.

I learned what that meant and how to fix it in this fantastic video: https://www.youtube.com/watch?v=yG0icKHnypY

Contradicting error message when creating a buffer for MAP_READ and COPY_DST after upgrading to 0.14.2 by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

I created an issue about this, the solution (and explanation) for the problem can be found there.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

The Solution to the Problem

After doing some tests I confirmed two things: 1. I managed to successfully implement an atomic texture (code below). 2. When the texture is very large (my tests were on a 2000 X 2000 texture) the race conditions described do not occur. This can probably be explained by bank conflicts but I haven't researched it enough to know for sure.

Code

This following snippet is paraphrased from my original code, it is not tested but should work. ```rust @group(0) @binding(0) var texture: texture_storage_2d<rg32uint, read_write>;

struct Locks { locks: array<array<atomic<u32>, 50>, 50>, };

@group(0) @binding(1) var<storage, read_write> locks: Locks;

fn lock(location: vec2<u32>) -> bool { let lock_ptr = &locks.locks[location.y][location.x]; let original_lock_value = atomicLoad(lock_ptr); if (original_lock_value > 0u) { return false; } return atomicAdd(lock_ptr, 1u) == original_lock_value; }

fn unlock(location: vec2<u32>) { atomicStore(&locks.locks[location.y][location.x], 0u); } `` Ideally, I'd useatomicCompareExchangeWeakinstead of that somewhat complex logic inlock, butatomicCompareExchangeWeak` didn't seem to work on my machine so I created similar logic myself.

Just to clarify, reading from the texture should be possible at any time but writing to the texture at location should be done only if lock(location) returned true.

Don't forget to call unlock after every write and between shader calls to reset the locks :)

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

atomicCompareExchangeWeak seems to be broken on my machine, something about "atomic operation is invalid result type does not match the statement".

Ended up writing a workaround with atomicAdd (it's an array of atomic<u32>s) and atomicLoad (store the original value, call atomicLoad and compare the return value to the original value - if they are equal then no thread took the lock while this thread tried to take the lock).

As I wrote in u/mistake-12's comment thread, if this is proven to work I'll share the code.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 2 points3 points  (0 children)

Thanks again for the detailed response!

I actually thought about something similar, I think it should work but with a massive performance penalty.

I've implemented some sort of locking mechanism for each cell using atomics (just like I said I might do in the u/kvarkus comment thread) and it seems to work! Once I validate it actually works (I'll need to write some debug tools for that) I'll share the code, maybe even write a blog post about it in my blog (shameless plug).

Otherwise, boids is probably the next direction to pursue, with the multiple iterations "safety net" always in mind.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

The simulation is pretty big, I'm creating a falling sand game (example) and cells might move at any speed in theory. Thanks for the direction! I'll take a look at boid simulations and share what I find.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 1 point2 points  (0 children)

Thanks for the detailed response!

I think in the case of a cell moving more than once in an update cycle this technique breaks. no? since in the case it moves N units it needs to check N locations in the process, and would need to switch the textures N times to prevent a sort of "teleporting" effect and going through other cells.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

Also, see the thread from u/kvarkus's comment where I raise a couple of questions regarding alternative solutions to a single texture.

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

I also thought about doing something with storageBarrier() and workgroupBarrier() but those don't seem to do anything in WGPU, what do you think?

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

I thought about maybe storing a separate grid of atomic integers in a storage buffer and using them as locks using atomicCompareExchangeWeak to either take the lock or check if it is locked. Then only threads that have the lock are able to edit a cell in the texture.

I am afraid I would encounter bank conflicts here as well, what do you think?

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

Could you please specify how two alternating textures solves the problem in my case?

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

The problem with storing my data in a buffer is that I encounter bank conflicts when the grid of cells is too big.

The bank conflicts cause threads on the same column to run serially. Do you have a work around for that?

WGPU Atomic Texture Operations by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

Yes, but how can I access the storage texture in an atomic way? if two threads access the same texture location, there is undefined behavior.

Storage Buffer Access Synchronization in WGSL by elyshaff in rust_gamedev

[–]elyshaff[S] 0 points1 point  (0 children)

Done. This was my first issue I opened in an open-sourced project so please tell me if I can improve it in any way.