srg-inlineconsts.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Copyright (c) Contributors to the Open 3D Engine Project.
  5. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. SPDX-License-Identifier: Apache-2.0 OR MIT
  7. """
  8. import sys
  9. import os
  10. sys.path.append("..")
  11. sys.path.append("../..")
  12. from clr import *
  13. import testfuncs
  14. def verifyOK(thefile, compilerPath, silent):
  15. j, ok = testfuncs.buildAndGetJson(thefile, compilerPath, silent, ["--srg", "--root-const=52"])
  16. if ok:
  17. predicates = []
  18. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["count"] == 1)
  19. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["index"] == 0)
  20. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["space"] == 0)
  21. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["usage"] == "Read")
  22. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["sizeInBytes"] == 60)
  23. predicates.append(lambda: j["RootConstantBuffer"]["bufferForRootConstants"]["id"] == "Root_Constants")
  24. if not silent: print (fg.CYAN+ style.BRIGHT+ "inline const verification..."+ style.RESET_ALL)
  25. ok = testfuncs.verifyAllPredicates(predicates, j)
  26. return True if ok else False
  27. def verifyZeroOK(thefile, compilerPath, silent):
  28. j, ok = testfuncs.buildAndGetJson(thefile, compilerPath, silent, ["--srg", "--root-const=0"])
  29. return True if ok else False
  30. def verifyZeroFails(thefile, compilerPath, silent):
  31. j, ok = testfuncs.buildAndGetJson(thefile, compilerPath, silent, ["--srg", "--root-const=0"])
  32. return True if not ok else False
  33. result = 0 # to define for sub-tests
  34. resultFailed = 0
  35. def doTests(compiler, silent, azdxcpath):
  36. global result
  37. global resultFailed
  38. # Working directory should have been set to this script's directory by the calling parent
  39. # You can get it once doTests() is called, but not during initialization of the module,
  40. # because at that time it will still be set to the working directory of the calling script
  41. workDir = os.getcwd()
  42. if verifyOK(os.path.join(workDir, "srg-inlineconsts.azsl"), compiler, silent) : result += 1
  43. else: resultFailed += 1
  44. if verifyZeroOK(os.path.join(workDir, "simple.azsl"), compiler, silent) : result += 1
  45. else: resultFailed += 1
  46. if verifyZeroFails(os.path.join(workDir, "srg-inlineconsts.azsl"), compiler, silent) : result += 1
  47. else: resultFailed += 1
  48. if __name__ == "__main__":
  49. print ("please call from testapp.py")