gpujs / gpujs/gpu.js

Math.max and Math.min only accept two parameters

Offen
#618 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
15.5k
Forks
663
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

![A GIF or MEME to give some spice of the internet](https://pics.me.me/mess-with-octopus-you-get-theglocktopus-31173669.png)

## *What* is wrong?
Using `Math.max` with more than two parameters causes the GPU kernel build to fail.

## *How* do we replicate the issue?
```
const gpu = new GPU({ mode: 'gpu' });
const kernel = gpu.createKernel(function() {
return Math.max(0, 1, 2);
}).setOutput([1]);
kernel();
```
And observe the output error
`gpu-browser.js:14913 Uncaught Error: Error compiling fragment shader: ERROR: 0:457: 'max' : no matching overloaded function found`. Replacing `0, 1, 2` with `0, 1` (or any other two numbers) leads to the function behaving as expected. The same is true of `Math.min`.
JS Fiddle: [https://jsfiddle.net/TomWyllie/opdg95kb/](https://jsfiddle.net/TomWyllie/opdg95kb/)

GPU.js 2.9.4
GPU: NVIDIA GeForce GTX 1060 3GB
Nvidia Driver 446.14
Google Chrome Version 83.0.4103.97 (Official Build) (64-bit)
Windows 10

## *How* important is this (1-5)?
2, it's very easy (but pretty messy) to workaround by using `Math.max(x, Math.max(y, Math.max(z, t)));` or similar, but that is pretty ugly. My understanding is that the [spec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max) allows arbitrarily many parameters.

## Other Comments
I'm beginning to think there might be something deeper wrong with GPU.js on my machine given this issue and the other I filed several days ago (#617) must be very common use cases and surely lots of other people would be having these same problems... any thoughts appreciated.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, das bereitgestellte GPU.js-Kernel-Beispiel mit Math.max und Math.min unter Verwendung von drei oder mehr Argumenten zu reproduzieren, und untersuche anschließend, wie diese Aufrufe in den GPU-Shader übersetzt werden. Als erledigt gilt die Aufgabe, wenn Aufrufe mit mehreren Argumenten kompiliert werden und das erwartete Ergebnis liefern, ohne verschachtelte Workarounds zu erfordern; überprüfe das ursprüngliche Beispiel und den Fall mit zwei Argumenten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
computer-graphics
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.