gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.1k stars 652 forks source link

Custom functions called in kernel loop always return same value #681

Closed andrewbrg closed 3 years ago

andrewbrg commented 3 years ago

What is wrong?

This is a weird one, if i create a function and attach it to the main GPU object and call this function from within a kernel inside a for loop the function seems to keep returning the same value through each iteration. The value it returns is the value it returned on the first iteration.

Where does it happen?

I'm using non graphical kernels with pipelining.

How do we replicate the issue?

Try create a function that returns some value based on some parameters you pass it, place it in a for loop where the parameters are changing through each iteration and you should see that the function seems to cache the first value and keep returning that through each iteration.

How important is this (1-5)?

4-5

andrewbrg commented 3 years ago

Ok, you can disregard this ticket, the actual issue was in the for loop. For some reason iterating over a variable number of times was causing this, no idea why.

e.g. for (let i = 0; i < x; i++)

Replacing x with a fixed number or a constant then works :/