3Dmigoto icon indicating copy to clipboard operation
3Dmigoto copied to clipboard

Incorrect Decompiler Output

Open BlueAmulet opened this issue 2 years ago • 3 comments

I'm investigating the shaders of EARTH DEFENSE FORCE 5 and found that 3Dmigoto's decompiler leads to incorrect shaders if RDEF is present. Some of the shaders do the following: mov o0.xy, cb2[5].xyxx, where cb2[5].x is a float , and cb2[5].y is a different float. The decompiler outputs the following: o0.xy = _broken_; I've confirmed this isn't right with RenderDoc, as the render target receives different values in its red and green channels. HLSLcc outputs: SV_TARGET0.xy = hdn_user_paramPS.vec2(_broken_, _missing_); which contains the missing float.

I've attached the shader from the game but with the unimportant parts of the RDEF gutted out. broken.zip

BlueAmulet avatar Dec 16 '21 23:12 BlueAmulet

The Decompiler has some known defects, and will do this sort of thing for a bunch of opcodes. That's why it's putting in the broken and missing tags to indicate it doesn't know what to do. It works very well for SM 3.0, mostly OK for SM 4.0, and mostly broken for SM 5.0.

The Decompiler is not getting any attention nowadays, because I gave up playing whack-a-mole on the opcodes, and also it has some fundamental errors like putting variables into floats that should be ints, which can cause runtime errors on occasion. Mostly we use Flugan's assembler now, as DarkStarSword has made it complete and handles errors. There is a standalone comand-line version of that in our build artifacts if that helps.

You can fix those manually by editing the file, and adding what you think is the correct code.

bo3b avatar Dec 17 '21 01:12 bo3b

The _broken_ and _missing_ names are just names I came up with to highlight the issue. They were originally metallic and roughness, and the issue manifested itself by making it so after decompiling, the more metallic something was the rougher the reflections got. If the decompiler isn't expected to be looked into at all then feel free to close the issue, I'll just use HLSLcc -> MSL instead.

BlueAmulet avatar Dec 17 '21 02:12 BlueAmulet

Ah, OK. I thought maybe DarkStarSword had added those. There are some commands where I know I return a 'needs manual fix' result.

We can leave it open, there is a non-zero chance I'll pick it up again.

bo3b avatar Dec 17 '21 04:12 bo3b