icculus / mojoshader

Use Direct3D shaders with other 3D rendering APIs.
https://icculus.org/mojoshader/
zlib License
150 stars 37 forks source link

Shader that works with spir-v output fails with glsl output #41

Closed thatcosmonaut closed 3 years ago

thatcosmonaut commented 3 years ago

https://gist.github.com/thatcosmonaut/ea211fddaeba4c5f7541cb583bde945e

This palette crush shader works fine with spir-v output, but it only samples the leftmost pixel on glsl output. As you can see, in the glsl output the loop never increments the texcoord.

flibitijibibo commented 3 years ago

Seems like it gets incremented here?

https://gist.github.com/thatcosmonaut/ea211fddaeba4c5f7541cb583bde945e#file-mojoshader_glsl_output-L34

r1.x is (1 / PaletteWidth) and r1.y is set to 0, then gets incremented by 1 at the end of the block. So each texture2D() should be sampling at the correct spot for each iteration.

thatcosmonaut commented 3 years ago

You are right... there must be some reason why the shader isn't working though...

flibitijibibo commented 3 years ago

Check it with something like LLVMpipe, if it fails there too it's probably the shader, otherwise it's probably radeonsi.

thatcosmonaut commented 3 years ago

Fails on Windows D3D11 too so I must be doing something bad.

thatcosmonaut commented 3 years ago

#define FLT_MAX 3.402823466e+38

This was the culprit. Don't do this.