Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ok, I believe this is finally ready to check in. This has a few different updates in it, but the biggest change is the code to convert to ps_1_4. Let me describe the other changes first.
Sorry for the wall of text!
Code Changes:
1. Added some spaces to make the code more readable
See here and here for an example.
2. Changed the way Instruction/Arithmetic count is computed:
This is a realitivly small update but I changed from using
int
to usingsize_t
and I changed from usingatoi
to usingstrtoul
. This also changes from using a pointer and instead usessubstr
andc_str
. See here and here.3. Checks the destination register before updating the constant modifier:
Some games use a pixel shader that uses the same register for both the source and destination register along with a modifier on the constant. Example:
Notice how
r0
is used for both the source and destination.The code used to change it to:
This is obviously wrong, and I think it was part of the contributor to issue #44. Updated to fix this here.
4. Added code to convert to ps_1_4:
The logic here is fairly straight forward. Rather than describing it all (since you can just review the code), let me put a few notes about the logic:
texbem
,texcoord
,texm3x3
,texreg2rgb
, etc.SourceCode
string. If assembly fails it keeps the previous logic.SourceCode
andArithmeticCount
variables used for ps_1_4 are created before the constant modifiers are updated because the ps_1_4 conversion has better logic. However the check to see if ps_1_4 conversion is needed is done after the constant modifiers are updated because there is no reason to convert to ps_1_4 if the modifiers can be fixed without it. The ps_1_4 conversion code is more complex and has a higher change of causing an issue.texld
type functions so some of the temporary registers need to be use for the texture registers.texld
instruction or themov
instruction is put in the first phase it will not assemble. So the code prefers to add all these functions to the second phase.def
instruction with an unused constant to ensure that there is at least one instruction in the first phase.def
instructions must be in the first phase.texld
instructions must come before any instruction that uses any arithmetic count, but only in that phase.t1
is used thanr1
would need to be changed to something liker2
orr3
.r0
is always used to hold texturet0
, ift0
exists.Basic conversion logic:
SourceCode
up line-by-line and evaluate each line independently.ps_x_x
lines and thedef
andtex
instructions.ps_x_x
lines are ignored.def
lines are added to phase 1.tex
lines are converted totexld
.Testing:
I tested this with the following games:
However because ps_1_4 conversion is only attempted if an exact conversion cannot be done without it, only three of the games actually use this code. All other games either don't use pixel shaders or can do exact conversion without needing ps_1_4.
1. Silent Hill 2
This should be a complete fix for Silent Hill 2 pixel shader issues. I was able to do an exact conversion. It also fixes issue #56.
Here is what the conversion looks like for one of the pixel shaders:
Previous d3d8to9 conversion
ENBSeries conversion
Updated d3d8to9 conversion
2. True Crime New York City
This update also fixes True Crime New York City pixel shader issues. Previous fixes for #44 would simply remove constant modifiers.
The ENBSeries converter also tries to convert pixel shaders to ps_1_4, but seems to crash with this game.
Previous d3d8to9 conversion
Updated d3d8to9 conversion
3. Star Wars Republic Commando
Unfortunately the code is not able to convert Star Wars Republic Commando to ps_1_4 because the pixel shaders here are already using 8 arithmetic instructions in phase 2 but they also require the
mov
instruction to be in phase 2. In addition the pixel shaders here use more than one texture register in the same instruction, which I am not sure how to covert to ps_1_4. Any attempted conversion here seems to cause incorrect texture lighting.The pixel shader ps_1_4 conversion errors out here for this game and it continues using the previous logic. However, the game is fully playable and has no ill side effects (that I could find), other than the modifier is removed from a constant. See below pixel shader code.
The ENBSeries converter also crashes with this game. It seems that there is no easy way to convert these pixel shaders to ps_1_4.
Note: This is the only game of the ones above I tested that I am unable to do exact conversion from the d3d8 pixel shader to the d3d9 pixel shader.
Previous/current d3d8to9 conversion
Error when trying to convert to ps_1_4