Skip to content

Commit 94ef63d

Browse files
committed
[ET-VK] Fake u16vecn for devserver
## Context Copy-pasted from the newly added `maybe_fake_u16vec3` function in the codegen script: > There is a latency benefit to using u16vecn variables to store texture position variables instead of ivecn, likely due to reduced register pressure. However, SwiftShader does not support 16 bit integer types in shaders, so this is a crude way to fallback to using ivecn to store texture positions so that testing with SwiftShader is still possible. Differential Revision: [D65501674](https://our.internmc.facebook.com/intern/diff/D65501674/) ghstack-source-id: 251970874 Pull Request resolved: #6675
1 parent d99d26e commit 94ef63d

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

backends/vulkan/runtime/gen_vulkan_spv.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ def __init__(
540540
env: Dict[Any, Any],
541541
glslc_path: Optional[str],
542542
glslc_flags: str = "",
543+
fake_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.fake_u16vecn = fake_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_fake_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.fake_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_fake_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("--fake-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,
1083+
fake_u16vecn=options.fake_u16vecn,
10601084
)
10611085
output_spv_files = shader_generator.generateSPV(options.tmp_dir_path)
10621086

backends/vulkan/runtime/graph/ops/glsl/q_8w_linear.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9+
// codegen-nosub
10+
911
#version 450 core
1012

1113
#define PRECISION ${PRECISION}

backends/vulkan/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False):
2727
select({
2828
"DEFAULT": "",
2929
"ovr_config//os:android": "--optimize",
30+
"ovr_config//os:linux": "--fake-u16vecn",
3031
})
3132
)
3233

0 commit comments

Comments
 (0)