spacehamster / DXDecompiler

Other
57 stars 16 forks source link

Improved handling of DX9 constant declarations #4

Closed lanyizi closed 3 years ago

lanyizi commented 3 years ago

Added two methods in DXDecompiler.DX9Shader.Bytecode.Declaration's ConstantDeclaration (GetRegisterTypeByOffset() and GetMemberNameByOffset()) which allow us to get register information and member variable name from a DX9 constant declaration, by using an offset.

It can be used figure out the member variable type, or the register full length (DXDecompiler.DX9Shader's RegisterState.GetRegisterFullLength()), or the member variable name (RegisterState.GetRegisterName()).

DXDecompiler.Tests/TestFixtures/TestDX9Effects.cs contains some sample code on how they can be used.

Example (took from test case): it's now able to figure out that the constant register c19 is actually u[2].t[1].v

float4 HakureiReimuAliceMargatroid;

struct
{
    row_major float2x3 f;
    struct
{
        float f;
        float4 v;
    } t[2];
    float g;
} u[3];

float4 VertexMain(float4 position : POSITION) : POSITION
{
    float4 position;
    float4 temp0;
return HakureiReimuAliceMargatroid.wwww * position * u[2].t[1].v;
}

PS: I've added a tab size = 4 in .editorconfig, because it's used by Github too, so Github can correctly display tabs with width of 4 spaces. I'm not sure if that's your preference, if you prefer something like 8 or 2 as tab size, just tell me (or you can just change it yourself 😄)