@@ -540,6 +540,7 @@ def __init__(
540540 env : Dict [Any , Any ],
541541 glslc_path : Optional [str ],
542542 glslc_flags : str = "" ,
543+ replace_u16vecn : bool = False ,
543544 ) -> None :
544545 if isinstance (src_dir_paths , str ):
545546 self .src_dir_paths = [src_dir_paths ]
@@ -549,6 +550,7 @@ def __init__(
549550 self .env = env
550551 self .glslc_path = glslc_path
551552 self .glslc_flags = glslc_flags
553+ self .replace_u16vecn = replace_u16vecn
552554
553555 self .glsl_src_files : Dict [str , str ] = {}
554556 self .template_yaml_files : List [str ] = []
@@ -705,6 +707,22 @@ def constructOutputMap(self) -> None:
705707 self .create_shader_params (),
706708 )
707709
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+
708726 def generateSPV (self , output_dir : str ) -> Dict [str , str ]:
709727 output_file_map = {}
710728
@@ -716,6 +734,7 @@ def process_shader(shader_paths_pair):
716734
717735 with codecs .open (source_glsl , "r" , encoding = "utf-8" ) as input_file :
718736 input_text = input_file .read ()
737+ input_text = self .maybe_replace_u16vecn (input_text )
719738 output_text = preprocess (input_text , shader_params )
720739
721740 glsl_out_path = os .path .join (output_dir , f"{ shader_name } .glsl" )
@@ -1029,6 +1048,7 @@ def main(argv: List[str]) -> int:
10291048 parser .add_argument ("-c" , "--glslc-path" , required = True , help = "" )
10301049 parser .add_argument ("-t" , "--tmp-dir-path" , required = True , help = "/tmp" )
10311050 parser .add_argument ("-o" , "--output-path" , required = True , help = "" )
1051+ parser .add_argument ("--replace-u16vecn" , action = "store_true" , default = False )
10321052 parser .add_argument ("--optimize_size" , action = "store_true" , help = "" )
10331053 parser .add_argument ("--optimize" , action = "store_true" , help = "" )
10341054 parser .add_argument (
@@ -1056,7 +1076,11 @@ def main(argv: List[str]) -> int:
10561076 glslc_flags += "-O"
10571077
10581078 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 ,
10601084 )
10611085 output_spv_files = shader_generator .generateSPV (options .tmp_dir_path )
10621086
0 commit comments