@@ -540,6 +540,7 @@ def __init__(
540
540
env : Dict [Any , Any ],
541
541
glslc_path : Optional [str ],
542
542
glslc_flags : str = "" ,
543
+ replace_u16vecn : bool = False ,
543
544
) -> None :
544
545
if isinstance (src_dir_paths , str ):
545
546
self .src_dir_paths = [src_dir_paths ]
@@ -549,6 +550,7 @@ def __init__(
549
550
self .env = env
550
551
self .glslc_path = glslc_path
551
552
self .glslc_flags = glslc_flags
553
+ self .replace_u16vecn = replace_u16vecn
552
554
553
555
self .glsl_src_files : Dict [str , str ] = {}
554
556
self .template_yaml_files : List [str ] = []
@@ -705,6 +707,22 @@ def constructOutputMap(self) -> None:
705
707
self .create_shader_params (),
706
708
)
707
709
710
+ def maybe_replace_u16vecn (self , input_text : str ) -> str :
711
+ """
712
+ There is a latency benefit to using u16vecn variables to store texture position
713
+ variables instead of ivecn, likely due to reduced register pressure. However,
714
+ SwiftShader does not support 16 bit integer types in shaders, so this is a crude
715
+ way to fallback to using ivecn to store texture positions so that testing with
716
+ SwiftShader is still possible.
717
+ """
718
+ if not self .replace_u16vecn :
719
+ return input_text
720
+ if "codegen-nosub" in input_text :
721
+ return input_text
722
+
723
+ input_text = input_text .replace ("u16vec" , "ivec" )
724
+ return input_text
725
+
708
726
def generateSPV (self , output_dir : str ) -> Dict [str , str ]:
709
727
output_file_map = {}
710
728
@@ -716,6 +734,7 @@ def process_shader(shader_paths_pair):
716
734
717
735
with codecs .open (source_glsl , "r" , encoding = "utf-8" ) as input_file :
718
736
input_text = input_file .read ()
737
+ input_text = self .maybe_replace_u16vecn (input_text )
719
738
output_text = preprocess (input_text , shader_params )
720
739
721
740
glsl_out_path = os .path .join (output_dir , f"{ shader_name } .glsl" )
@@ -1029,6 +1048,7 @@ def main(argv: List[str]) -> int:
1029
1048
parser .add_argument ("-c" , "--glslc-path" , required = True , help = "" )
1030
1049
parser .add_argument ("-t" , "--tmp-dir-path" , required = True , help = "/tmp" )
1031
1050
parser .add_argument ("-o" , "--output-path" , required = True , help = "" )
1051
+ parser .add_argument ("--replace-u16vecn" , action = "store_true" , default = False )
1032
1052
parser .add_argument ("--optimize_size" , action = "store_true" , help = "" )
1033
1053
parser .add_argument ("--optimize" , action = "store_true" , help = "" )
1034
1054
parser .add_argument (
@@ -1056,7 +1076,11 @@ def main(argv: List[str]) -> int:
1056
1076
glslc_flags += "-O"
1057
1077
1058
1078
shader_generator = SPVGenerator (
1059
- options .glsl_paths , env , options .glslc_path , glslc_flags
1079
+ options .glsl_paths ,
1080
+ env ,
1081
+ options .glslc_path ,
1082
+ glslc_flags = glslc_flags ,
1083
+ replace_u16vecn = options .replace_u16vecn ,
1060
1084
)
1061
1085
output_spv_files = shader_generator .generateSPV (options .tmp_dir_path )
1062
1086
0 commit comments