DxilForceEarlyZ.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/DXIL/DxilModule.h"
  12. #include "dxc/DxilPIXPasses/DxilPIXPasses.h"
  13. #include "dxc/HLSL/DxilGenerationPass.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. // This pass adds the force-early-z flag
  26. DxilModule &DM = M.GetOrCreateDxilModule();
  27. DM.m_ShaderFlags.SetForceEarlyDepthStencil(true);
  28. DM.ReEmitDxilResources();
  29. return true;
  30. }
  31. char DxilForceEarlyZ::ID = 0;
  32. ModulePass *llvm::createDxilForceEarlyZPass() { return new DxilForceEarlyZ(); }
  33. INITIALIZE_PASS(
  34. DxilForceEarlyZ, "hlsl-dxil-force-early-z",
  35. "HLSL DXIL Force the early Z global flag, if shader has no discard calls",
  36. false, false)