d3d9-reader 0.12.0

Direct3D 9 shader bytecode parser: reads vs/ps 1.x, 2.x and 3.0 token streams into typed declarations, definitions and instructions, with the CTAB constant table
Documentation
�

�d�jB5���SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKr/SQr
\"S1\
kS\R"\
S55k\"\
5i5rSr/SQ/SQ/S	Q/S
Q/SQ/SQ/S
Q/SQS.rSSSSSSSSSSSS.r0\R-/SQS5E\R-/SQS5E\R-/S QS!5E\R-S"S#/S$5E\R-/S%QS&5E\R-/S'QS(5E\R-/S)QS*5ES+S,0ErS-rS7S.jrS/rS0r\R95H"urr\"\5\S1\3'\"\5\S2\3'M$ S3rS4r S5r!\"S6:Xa\RF"\!"55 gg)8a�Compile the Direct3D 9 fixtures here with Microsoft's fxc and record D3DDisassemble's listings of them (a Windows
Python: on Windows, or under Wine).

Each `.hlsl` states its builds as `// fxc: <arguments> /Fo <name>.bin` lines. Every build's program is written here
and its listings to `listings/`: `<name>.asm` with no flags and `<name>.flag<hex>.asm` with each other flags word of
FLAGS; `../disasm.rs` compares the disassembler with them. fxc no longer compiles Shader Model 1, so the programs of
SM1 are written from the tokens in HAND_BUILT.

Sources are compiled from copies in `C:\dx9-fixtures` (see STAGE), with the `.hlsli` files they include.

    python -I generate.py --fxc PATH --dll PATH

Give the fxc and d3dcompiler_47 builds the listings were made with (10.0.26100.4654); under Wine as Wine paths
(Z:\...), in a pseudo-terminal, since Windows Python needs a console there
(`script -qec "wine python.exe generate.py ..." /dev/null`).
�N)���� �@�c#�.# �UHupX-v� M
 g7f)N�)�.0�a�bs   �SC:/Users/kalmarv/modding/crates/dx/.wt/outside/d3d9-reader/tests/disasm/generate.py�	<genexpr>rs���!Z�4Y�D�A�!�%�4Y�s�rzC:\dx9-fixtures)
���B�`����ar���A�@���!���)
��rrrrrrrl�!r)��rrrrrr)��rrr����r��rrrrrrrr)r�Q�@��?i?rr$rrr�`r ll�irrl>r!l�m�Prl�rrr)����� r�rr)r'r(r)r*�r+rrrl`l rl l �Ar)rrrrr%r rrri@l��arrrr!r-i@l0r!rrlr!r)zsm1.coissue.ps11zsm1.coissue.ps12zsm1.plain.ps13zsm1.coissue.ps14zsm1.modifiers.ps11zsm1.plain.vs11zsm1.relative.vs11zsm1.pairs.ps11r'l�l�l�rrrrl�l�l�)�vs11�vs20�vs2x�vs30�ps11�ps12�ps13�ps14�ps20�ps2x�ps30)r���'�*�+�,)Fr)���&�(�`)Fr)���)�-)Fr�A�W)Tr)r����r��#�$�.�N�O�[�\�C�D�E�F�G�H�I�J�M�R�S�T�U�V)Tr)r�r ��	�
���
�r,����r�!�L�Y�^�_)Tr)r�r&�X�Z)Trd�])Trc��US-	S-US-p2US:XaSUS:XaUS:XaS4$S4$S4$US	:Xa
SUS:XaS4$S4$US
;a
SUS:aS4$S4$[U$)Nre��rTrrrrr)�"�%rd)�OPERANDS)�op�version�major�minors    r�operandsr�Ws����q�L�D�(�'�D�.�5�	�R�x��%�1�*�E�Q�J�q�D�D�A�D�D�!�D�D�	�R�x��5�A�:�a�-�-�1�-�-�	�X�~��5�1�9�a�,�,�!�,�,��B�<��c�v�UbU/O/[U5-nUS-	S-S:XaSO
[U5nX-US--/UQ$)zcAn instruction's tokens: its token (with its length from Shader Model 2 on) and its operand tokens.rerzrrro)�list�len)rr~�destination�sources�flags�words�lengths       r�instructionr�bsM��)�5�k�]�2��g��N�E��a�<�4�'�1�,�Q�#�e�*�F��J�&�B�,�'�0�%�0�0r�c��/n/[SS5QSP[SS5QSPSP[SS5Q[SS	5QS	P[S
S5QSPH�nUS:XaU[USS
SS/5-
nMUS	:XaU[US	S
/SQ5-
nM9US:XaU[USS
/SQ5-
nMTUS:XaU[USS
SS/5-
nMoUS:XaURS5 M�[X 5up4US;aSOSnU[XU(aSOS
[U5Vs/sHnSU-PM
 snU5-
nM� U[USS
SS/5-
nU/UQSP$s snf)aEEvery Direct3D 9 instruction once, in opcode order, whatever the version's own list: r0 written and r1 to r4
read, the comparison of if_comp, break_comp and setp_comp `gt`, and dcl, def, defi, defb and phase with their own
operands; then a dcl, which like the definitions after `if` is inside the `if` that no `endif` closes.rr(r�/�0r�Krqr"r_�arNlr*)r#r$rrr$)l`rrrdrl@r)rFrGrsir��ll r)�ranger��appendr�)r�bodyr~r��count�control�ns       r�every_opcoder�is����D�u��a���u�b�u�5��R�=�u�"�u�b�u�5��R�=�u�5�QS�UW�=�u�Z\�u�_d�eg�ik�_l�u�nt�u��
��8��K���T�J�
�3K�L�L�D�
�2�X��K���T�3]�^�^�D�
�2�X��K���T�3K�L�L�D�
�2�X��K���T�J��?�C�C�D�
�6�\��K�K���!)�"�!6��K�!#�|�!3�g��G��K��;�Z�D�9>�u�� F��A��a��� F��Q�
Q�D�v�"	�K���T�J�
�+C�D�D�D��#�d�#�F�#�#��!Gs�D?c�.�SnUS-	S-S:Hn[USSS/S5n[S5Vs/sHoDS	:wdM
US
/4PM snS	/SQ4SS
S/4S
S
/4SS
/4/-HJupEUH?nU[USSSU"U5-U-/5-
nU[USSU"U5-U-S/5-
nMA ML [S5H1nSH(nU[USSSU-US--SUS-U--/5-
nM* M3 SHn	U[USSU	S--S/5-
nM U(a/OS/n
U[USS/U
QSP5-
nU[USSS/U
Q5-
nU[USSS/5-
nU[USSS/S5-
nU[USSS S/S!5-
nU[USS/S"QS!5-
nU/UQS#P$s snf)$aSA co-issued first instruction; every register type as the source of `mov r0, X` and the destination of
`mov X, r1` (the three rasterizer outputs, vPos and vFace each); a dcl of every usage at index 0 and 1; and the
flags of other versions: each result shift, relative destinations and sources, co-issue, and predication, plain and
negated.c�$�US-S-US-S--$)NrKr9rorer
)�ts r�<lambda>� every_register.<locals>.<lambda>�s��q�1�u��m��T��a��8r�rerzrrri@rrr)rrrrkrurNrr!r�rL)rrr(Nr)r*r)rrrdrjrLrMrol`l l �Al��!l�ai)lzrr�r)r�r�)r�kind�sm1r�r��numbersr��usage�index�shift�addresss           r�every_registerr��s,��
9�D��a�<�4�
�1�
$�C��w��:�
�|�Z�H�D�).�r��=��A�1�f�x��A�3�x��=�!�Y��RT�WX�Z[�V\�Q]�`b�ef�dg�_h�km�pq�or�js�@t�t�
���A��K���J��d�1�g�9M�PQ�9Q�8R�S�S�D��K���J��a��,@�1�,D�z�l�S�S�D��u��r����E��K���T�J��4F��RT��4T�V`�ch�kl�cl�ot�ct�Vt�3u�v�v�D���'����G�Q�
�U�b�[�(@�:�,�O�O��'��b�j�\�G��K���J�0F�'�0F�:�0F�G�G�D��K���J��0F�g�0F�G�G�D��K���J���=�=�D��K���J���j�I�I�D��K���J��Z�0H�*�U�U�D��K���J�0T�V`�a�a�D��#�d�#�F�#�#��!>s
�	F�	Fzversions.opcodes.zversions.registers.c�J^�[R"U5Rm[R[R[R
[R[R"[R5/Tl[RTl
U4SjnU$)Nc	�D>�[R"5nT"[R"U[U55[U5US[R"U55nUS:waSUS-4$[R
"U[R"[R"[R555Rn[R"[R[R5"US5"U5n[R"[R[R5"US5"U5n[R"XV5n[R"[R[R5"US5"U5 US4$)Nrl��rdrr)�ctypes�c_void_p�create_string_bufferr��byref�cast�POINTER�contents�WINFUNCTYPE�c_size_t�	string_at�c_ulong)	�datar��out�hr�vt�ptr�size�text�fns	        �r�call�disassembler.<locals>.call�s����o�o���
��+�+�D�#�d�)�<�c�$�i��PT�V\�Vb�Vb�cf�Vg�
h��
��7���j��(�(�
�[�[��f�n�n�V�^�^�F�O�O�-L�M�
N�
W�
W��� � ����&�/�/�B�2�a�5�I�#�N���!�!�&�/�/�6�?�?�C�B�q�E�J�3�O������*�����6�>�>�6�?�?�;�B�q�E�B�3�G��Q�w�r�)r��WinDLL�D3DDisassembler�r��c_uint�c_char_pr��argtypes�c_long�restype)�pathr�r�s  @r�disassemblerr��sc���	���t�	�	+�	+�B��?�?�F�O�O�V�]�]�F�O�O�U[�Uc�Uc�dj�ds�ds�Ut�u�B�K����B�J�
��Kr�c�z�[R"[US5R55R	5$)N�rb)�hashlib�sha256�open�read�	hexdigest)r�s rr�r��s*���>�>�$�t�T�*�/�/�1�2�<�<�>�>r�c�j�[R"5nURSSS9 URSSS9 UR5n[R
R
[R
R[55n[R
RUS5n[R"USS9 [UR5n[SURS[UR535 [S	URS[UR535 /S
pe[R"[ SS9 [#[$R$"[R
RUS555HYn[&R("U[R
R[ [R
R+U555 M[ [#[$R$"[R
RUS555GH�n[R
R[ [R
R+U55n	[&R("X�5 [-US
S9GHHn
[.R0"SU
5nU(dM$[2R4"UR7S5SS9n[R
RX,UR9S5S-5n
X�UR9S5S-'[:R<"URS/UQU	PSSS9nUR>S
:waoUS-
n[S[R
R+U
5SUR@RC5=(d URDRC535 GM7URGU
5 GMK GM� [HRK5Hvunn[R
RX/S-5n
[-U
S5RM[NRP"S[SU5S3/UQ765 URGU
5 Mx UGH%n[-US5RU5n[R
RU[R
R+U5S[SS5*5n[VH�nU"UU5unnUc:US-
n[S[R
R+U5SUSS US!35 MLUUS
:XaS"OS#US$S"3-n[-US5RMURYS%55 M� [S&[R
R+U535 GM( [U5S'US(35 U(aS$S
$))Nz--fxcT)�requiredz--dll�listings)�exist_okzfxc � zdll rz*.hlsliz*.hlslzutf-8)�encodingz//\s*fxc:\s*(.*)rF)�posixz/Foz/nologo)�capture_outputr�zFAIL z: z.bin�wb�<�Ir�zD3DDisassemble z flags z#xz: hr z#010xz.asmz.flag�02x�zok z built, z failed)-�argparse�ArgumentParser�add_argument�
parse_args�osr��dirname�abspath�__file__�join�makedirsr��dll�print�fxcr��STAGE�sorted�glob�shutil�copyfile�basenamer��re�match�shlex�split�groupr��
subprocess�run�
returncode�stderr�strip�stdoutr��
HAND_BUILT�items�write�struct�packr�r��FLAGS�rstrip)�apr�herer��disasm�built�failed�include�original�src�line�m�argsr��r�namer�r�r��stemr�r�r�s                       r�mainr�s/��	�	 �	 �	"�B��O�O�G�d�O�+��O�O�G�d�O�+�
�
�
��A�
�7�7�?�?�2�7�7�?�?�8�4�5�D��w�w�|�|�D�*�-�H��K�K��4�(�
�!�%�%�
 �F�	�D�����q�������
(�)�	�D�����q�������
(�)���6��K�K���%��$�)�)�B�G�G�L�L��y�$A�B�C�����������e�R�W�W�5E�5E�g�5N�!O�P�D��4�9�9�R�W�W�\�\�$��%A�B�C���g�g�l�l�5�"�'�'�"2�"2�8�"<�=������&���G�4�D����,�d�3�A����;�;�q�w�w�q�z��7�D��'�'�,�,�t�$�*�*�U�*;�a�*?�%@�A�C�*-����E�"�Q�&�'�������y�=�4�=��=�d�Y]�^�A��|�|�q� ��!�����b�g�g�.�.�s�3�4�B�q�x�x�~�~�7G�7[�1�8�8�>�>�K[�6\�]�^���L�L���5�D� "�'�'�)���e��g�g�l�l�4���/���S�$����f�k�k�A�c�%�j�\��*;�D�e�D�E�
���S��*����D�$��$�$�&���w�w�|�|�H�b�g�g�&6�&6�t�&<�^��F��|�&L�M���E��d�E�*�H�D�"��|��!��������(8�(8��(>�'?�w�u�R�j�PU�VX�Y^�U_�`�a���U�a�Z�6�u�U�3�K�t�5L�M�D���t��"�"�4�;�;�u�#5�6��	��B�G�G�$�$�T�*�+�,�-��
�S��Z�L�����
0�1��1��A�r��__main__)r)$�__doc__r�r�r�r��	itertoolsr�r�r�r�r�r��sys�
TEXT_FLAGSr��combinations�sumr�r�r��VERSIONS�dict�fromkeysr}r�r�r�r�r��_name�_versionr�r�r�__name__�exitr
r�r�<module>rs���� b�a�a�a�a�a�0�
���l�J�l�!Z�I�4J�4J�:�WX�4Y�!Z�l�\_�`j�\k�l�m��
	��a�=�k�1�K�
#�&�
G�7�
�H�
�J�PZ�dn��
�J�PZ�dn�� ��
�
�m�m�/��<�
�
�m�m�(�*�5�
��m�m�$�j�1�
��m�m�R��H�i�(�	
�
�m�m�!�"+�-�
��m�m�c�en�o�
��m�m�'��3�
��	�
���1�$�4$�8 �~�~�'�O�E�8�.:�8�.D�J�"�5�'�*�+�0>�x�0H�J�$�U�G�,�-�(�
�(?�0�f�z���H�H�T�V��r�