DxilForceEarlyZ.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilOutputColorBecomesConstant.cpp //
  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. // Provides a pass to turn on the early-z flag //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "dxc/HLSL/DxilGenerationPass.h"
  12. #include "dxc/HLSL/DxilModule.h"
  13. #include "dxc/HLSL/DxilPIXPasses.h"
  14. #include "llvm/IR/Module.h"
  15. using namespace llvm;
  16. using namespace hlsl;
  17. class DxilForceEarlyZ : public ModulePass {
  18. public:
  19. static char ID; // Pass identification, replacement for typeid
  20. explicit DxilForceEarlyZ() : ModulePass(ID) {}
  21. const char *getPassName() const override { return "DXIL Force Early Z"; }
  22. bool runOnModule(Module &M) override;
  23. };
  24. bool DxilForceEarlyZ::runOnModule(Module &M)
  25. {
  26. // This pass adds the force-early-z flag
  27. DxilModule &DM = M.GetOrCreateDxilModule();
  28. DM.m_ShaderFlags.SetForceEarlyDepthStencil(true);
  29. DM.ReEmitDxilResources();
  30. return true;
  31. }
  32. char DxilForceEarlyZ::ID = 0;
  33. ModulePass *llvm::createDxilForceEarlyZPass() {
  34. return new DxilForceEarlyZ();
  35. }
  36. INITIALIZE_PASS(DxilForceEarlyZ, "hlsl-dxil-force-early-z", "HLSL DXIL Force the early Z global flag, if shader has no discard calls", false, false)