HLSLExtensionsCodegenHelper.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // HLSLExtensionsCodegenHelper.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Codegen support for hlsl extensions. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/DXIL/DxilOperations.h"
  13. #include <vector>
  14. #include <string>
  15. namespace llvm {
  16. class CallInst;
  17. class Value;
  18. class Module;
  19. }
  20. namespace hlsl {
  21. // Provide DXIL codegen support for private HLSL extensions.
  22. // The HLSL extension mechanism has hooks for two cases:
  23. //
  24. // 1. You can mark certain defines as "semantic" defines which
  25. // will be preserved as metadata in the final DXIL.
  26. // 2. You can add new HLSL intrinsic functions.
  27. // 3. You can read a root signature from a custom define.
  28. //
  29. // This class provides an interface for generating the DXIL bitcode
  30. // needed for the types of extensions above.
  31. //
  32. class HLSLExtensionsCodegenHelper {
  33. public:
  34. // Used to indicate a semantic define was used incorrectly.
  35. // Since semantic defines have semantic meaning it is possible
  36. // that a programmer can use them incorrectly. This class provides
  37. // a way to signal the error to the programmer. Semantic define
  38. // errors will be propagated as errors to the clang frontend.
  39. class SemanticDefineError {
  40. public:
  41. enum class Level { Warning, Error };
  42. SemanticDefineError(unsigned location, Level level, const std::string &message)
  43. : m_location(location)
  44. , m_level(level)
  45. , m_message(message)
  46. { }
  47. unsigned Location() const { return m_location; }
  48. bool IsWarning() const { return m_level == Level::Warning; }
  49. const std::string &Message() const { return m_message; }
  50. private:
  51. unsigned m_location; // Use an encoded clang::SourceLocation to avoid a clang include dependency.
  52. Level m_level;
  53. std::string m_message;
  54. };
  55. typedef std::vector<SemanticDefineError> SemanticDefineErrorList;
  56. // Write semantic defines as metadata in the module.
  57. virtual SemanticDefineErrorList WriteSemanticDefines(llvm::Module *M) = 0;
  58. // Query the named option enable
  59. // Needed because semantic defines may have set it since options were copied
  60. virtual bool IsOptionEnabled(std::string option) = 0;
  61. // Get the name to use for the dxil intrinsic function.
  62. virtual std::string GetIntrinsicName(unsigned opcode) = 0;
  63. // Get the dxil opcode the extension should use when lowering with
  64. // dxil lowering strategy.
  65. //
  66. // Returns true if the opcode was successfully mapped to a dxil opcode.
  67. virtual bool GetDxilOpcode(unsigned opcode, OP::OpCode &dxilOpcode) = 0;
  68. // Struct to hold a root signature that is read from a define.
  69. struct CustomRootSignature {
  70. std::string RootSignature;
  71. unsigned EncodedSourceLocation;
  72. enum Status { NOT_FOUND = 0, FOUND };
  73. };
  74. // Get custom defined root signature.
  75. virtual CustomRootSignature::Status GetCustomRootSignature(CustomRootSignature *out) = 0;
  76. // Virtual destructor.
  77. virtual ~HLSLExtensionsCodegenHelper() {};
  78. };
  79. }