2
2
3
3
import re
4
4
from itertools import groupby
5
- from typing import TYPE_CHECKING , List , Optional , Tuple
5
+ from typing import TYPE_CHECKING , List , Optional , Tuple , TypeVar , Union
6
6
7
7
from ..enums import (
8
8
PassType ,
35
35
///////////////////////////////////////////
36
36
""" [1 :]
37
37
38
+ T = TypeVar ("T" )
39
+
38
40
39
41
def export_shader (m_Shader : Shader ) -> str :
40
42
if m_Shader .m_SubProgramBlob : # 5.3 - 5.4
@@ -58,21 +60,27 @@ def ConvertSerializedShader(m_Shader: Shader) -> str:
58
60
59
61
platformNumber = len (m_Shader .platforms )
60
62
compressed_blob = bytes (m_Shader .compressedBlob )
63
+
64
+ def get_entry (array : Union [List [T ], List [List [T ]]], index : int ) -> T :
65
+ item = array [index ]
66
+ if isinstance (item , List ):
67
+ return item [0 ]
68
+ return item
69
+
61
70
for i in range (platformNumber ):
62
71
if i >= len (m_Shader .compressedLengths ) or i >= len (
63
72
m_Shader .decompressedLengths
64
73
):
65
74
# m_Shader.platforms shouldn't be longer than m_shader.[de]compressedLengths, but it is
66
75
break
67
- compressedSize = m_Shader .compressedLengths [i ]
68
- decompressedSize = m_Shader .decompressedLengths [i ]
69
76
70
- compressedBytes = compressed_blob [
71
- int (m_Shader .offsets [i ][0 ]) : int (m_Shader .offsets [i ][0 ])
72
- + compressedSize [0 ]
73
- ]
77
+ compressedSize = get_entry (m_Shader .compressedLengths , i )
78
+ decompressedSize = get_entry (m_Shader .decompressedLengths , i )
79
+ offset = get_entry (m_Shader .offsets , i )
80
+
81
+ compressedBytes = compressed_blob [offset : offset + compressedSize ]
74
82
decompressedBytes = CompressionHelper .decompress_lz4 (
75
- compressedBytes , decompressedSize [ 0 ]
83
+ compressedBytes , decompressedSize
76
84
)
77
85
78
86
shaderPrograms .append (
@@ -654,7 +662,10 @@ def Export(self) -> str:
654
662
655
663
sb .append ("}\n " )
656
664
657
- if hasattr (self , "m_LocalKeywords" ) and len (self .m_LocalKeywords ) > 0 :
665
+ if (
666
+ getattr (self , "m_LocalKeywords" ) is not None
667
+ and len (self .m_LocalKeywords ) > 0
668
+ ):
658
669
sb .append ("Local Keywords { " )
659
670
for keyword in self .m_LocalKeywords :
660
671
sb .append ('"{0}" ' .format (keyword ))
0 commit comments