bo3b / 3Dmigoto

Chiri's DX11 wrapper to enable fixing broken stereoscopic effects.
Other
772 stars 122 forks source link

Decompiler ignores [precise] modifiers #85

Open Nukem9 opened 6 years ago

Nukem9 commented 6 years ago

I didn't see this anywhere so I'm hoping it's not a duplicate. Game: TES: Skyrim Special Edition.

Incorrect code: https://gist.github.com/Nukem9/46166358785a3502bb7887792b85a8c0 image

Corrected code: (Change float4 r0,r1,r2; to precise float4 r0,r1,r2;) image

It completely ignores the [precise] modifier in the disassembly. I checked the compiled shader and it gets optimized to mad instead of mul + add.

vs_5_0
dcl_globalFlags refactoringAllowed
dcl_constantbuffer CB2[5], immediateIndexed
dcl_constantbuffer CB12[12], immediateIndexed
dcl_input v0.xyz
dcl_output_siv o0.xyzw, position
dcl_temps 2
mul r0.xyzw, cb2[1].xyzw, cb12[8].xxxx
mad r0.xyzw, cb2[2].xyzw, cb12[8].yyyy, r0.xyzw
mad r0.xyzw, cb2[3].xyzw, cb12[8].zzzz, r0.xyzw
mad r0.xyzw, cb2[4].xyzw, cb12[8].wwww, r0.xyzw
mov r1.xyz, v0.xyzx
mov r1.w, l(1.000000)
dp4 o0.x, r0.xyzw, r1.xyzw
mul r0.xyzw, cb2[1].xyzw, cb12[9].xxxx
mad r0.xyzw, cb2[2].xyzw, cb12[9].yyyy, r0.xyzw
mad r0.xyzw, cb2[3].xyzw, cb12[9].zzzz, r0.xyzw
mad r0.xyzw, cb2[4].xyzw, cb12[9].wwww, r0.xyzw
dp4 o0.y, r0.xyzw, r1.xyzw
mul r0.xyzw, cb2[1].xyzw, cb12[10].xxxx
mad r0.xyzw, cb2[2].xyzw, cb12[10].yyyy, r0.xyzw
mad r0.xyzw, cb2[3].xyzw, cb12[10].zzzz, r0.xyzw
mad r0.xyzw, cb2[4].xyzw, cb12[10].wwww, r0.xyzw
dp4 o0.z, r0.xyzw, r1.xyzw
mul r0.xyzw, cb2[1].xyzw, cb12[11].xxxx
mad r0.xyzw, cb2[2].xyzw, cb12[11].yyyy, r0.xyzw
mad r0.xyzw, cb2[3].xyzw, cb12[11].zzzz, r0.xyzw
mad r0.xyzw, cb2[4].xyzw, cb12[11].wwww, r0.xyzw
dp4 o0.w, r0.xyzw, r1.xyzw
ret 
// Approximately 23 instruction slots used
bo3b commented 6 years ago

That is correct, it presently just drops the 'precise' keyword, and is something we should pass through.

However, if you really need the precision, you are probably better off to use our Assembler instead of the Decompiler. The Decompiler also generates a lot of ftoi and itof instructions, as the types are not well defined at ASM level. This can lead to shaders compiling successfully, but failing when in use.

bo3b commented 6 years ago

Let me also add here that is ignoring 'linear centroid' modifiers as well.