Browse Source

Integrate a test for option rank cost

Signed-off-by: Vivien Oddou <[email protected]>
Vivien Oddou 2 years ago
parent
commit
c274dff1a2
2 changed files with 73 additions and 0 deletions
  1. 27 0
      tests/Advanced/mae-methodcall.azsl
  2. 46 0
      tests/Advanced/mae-methodcall.py

+ 27 - 0
tests/Advanced/mae-methodcall.azsl

@@ -0,0 +1,27 @@
+ShaderResourceGroupSemantic slot0
+{
+    FrequencyId = 1;
+    ShaderVariantFallback = 128;
+};
+ShaderResourceGroup srg0 : slot0{}
+
+class C
+{
+    void f(double) { f(0) + f(0) * f(0) / f(0); f(0) - f(0) % f(0); }  // cost 7*7+2
+    void f(int) { ;;;;;;; }  // cost 7
+};
+
+option bool o;
+
+float4 main()
+{
+    if (o)  // unnamed block $bk0
+    {
+        C c;
+        {   // unnamed block $bk1 to verify lookup capability to find `/main/$bk0/c` from `/main/$bk0/$bk1/`
+            // understand that `c`'s type is `/C`, and use /C scope to lookup the f() method.
+            // also deep expression on LHS of MAE to give no break to the typeof system
+            (c).f(2 * 5.0l);   // double promotion in binary expression that resolves to double overload method call
+        }
+    }
+}

+ 46 - 0
tests/Advanced/mae-methodcall.py

@@ -0,0 +1,46 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+Copyright (c) Contributors to the Open 3D Engine Project.
+For complete copyright and license terms please see the LICENSE at the root of this distribution.
+
+SPDX-License-Identifier: Apache-2.0 OR MIT
+"""
+import sys
+import os
+sys.path.append("..")
+sys.path.append("../..")
+from clr import *
+import testfuncs
+
+
+def verifyOptionCosts(thefile, compilerPath, silent):
+    j, ok = testfuncs.buildAndGetJson(thefile, compilerPath, silent, ["--options"])
+    if ok:
+        predicates = []
+        # check all references of func()
+        predicates.append(lambda: j["ShaderOptions"][0]["name"] == "o")
+        predicates.append(lambda: j["ShaderOptions"][0]["costImpact"] == 54)
+
+        if not silent: print (fg.CYAN+ style.BRIGHT+ "option expected cost check..."+ style.RESET_ALL)
+        ok = testfuncs.verifyAllPredicates(predicates, j)
+    return ok
+
+result = 0  # to define for sub-tests
+resultFailed = 0
+
+def doTests(compiler, silent, azdxcpath):
+    global result
+    global resultFailed
+
+    # Working directory should have been set to this script's directory by the calling parent
+    # You can get it once doTests() is called, but not during initialization of the module,
+    #  because at that time it will still be set to the working directory of the calling script
+    workDir = os.getcwd()
+
+    if verifyOptionCosts(os.path.join(workDir, "mae-methodcall.azsl"), compiler, silent): result += 1
+    else: resultFailed += 1
+
+
+if __name__ == "__main__":
+    print ("please call from testapp.py")