crosire / d3d8to9

A D3D8 pseudo-driver which converts API calls and bytecode shaders to equivalent D3D9 ones.
BSD 2-Clause "Simplified" License
911 stars 83 forks source link

Update Shader swizzle and debug support #71

Closed elishacloud closed 6 years ago

elishacloud commented 6 years ago

Overview:

This pull fixes #64 and #70. There are basically 4 changes in here:

  1. Minor update of QualityLevels.

I just moved the ternary operator out of the CreateRenderTarget and CreateDepthStencilSurface functions and hid it behind the if statement to clean up the code slightly.

  1. Modified the PixelShader code to ensure that the swizzle comes at the end. See comments here.

This modifies two regex functions that remove modifiers on constants. It adds a new regex group by changing (r[0-9][\\.wxyz]*) into (r[0-9])([\\.wxyz]*). This allows the swizzle to be in its own group so that we can ensure the swizzle comes last.

Note: since a new group is added all the references to the regex groups need to be updated.

  1. Removes the debug lines in shaders.

If the shader was compiled with debugging on there will be extra lines in it.

Example:

> Disassembling shader and translating assembly to Direct3D 9 compatible code ...
> Dumping translated shader assembly:

    vs_1_1

#line 2 "D:\Games\True Crime® New York City\memory"
    dcl_position v0
    dcl_blendweight v1
    dcl_blendindices v2
    mov r1, c0
    mov r0, c0
    mov oD0, c0
    mov oT1, c0
    mov oT0, c0
    dp3 r0.x, v1, c86
    dp4 oPos.x, v0, c92
    max r0.w, r0.x, c83.x

#line 13
    mul r0.xyz, r0.w, c87
    dp3 r1.x, v1, c84
    max r0.w, r1.x, c83.x
    dp3 r1.x, v1, c88
    mad r0.xyz, r0.w, c85, r0
    max r0.w, r1.x, c83.x
    dp4 oPos.y, v0, c93
    mad r0.xyz, r0.w, c89, r0
    dp4 oPos.z, v0, c94
    add r0.xyz, r0, c90
    dp4 oPos.w, v0, c95

#line 24
    mul r0.xyz, r0, c91
    dp4 oFog, v0, c81
    min oD0.xyz, r0, c83.y
    mov oD0.w, c90.w
    mov r0.xyz, c83
    mad r0, v2, r0.zzxy, c70
    mov oT0, r0
    mov oT1, r0

// approximately 27 instruction slots used

I added two new regex statements to remove these debugging lines.

  1. Enable the D3DXASM_DEBUG flag when generating the debug build.

I set the D3DXAssembleShader function to automatically enable the D3DXASM_DEBUG flag when creating a debug build of d3d8to9.

Testing:

This is a pretty small change so it should have no affect on most games. This mainly effects PixelShaders so I tested with games that are sensitive to PixelShaders.

Tested with:

elishacloud commented 6 years ago

Good idea. Done!

PatrickvL commented 6 years ago

Yeah, it's in! Thanks guys!