File: RTArgs.cpp

package info (click to toggle)
intel-graphics-compiler2 2.16.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 106,644 kB
  • sloc: cpp: 805,640; lisp: 287,672; ansic: 16,414; python: 3,952; yacc: 2,588; lex: 1,666; pascal: 313; sh: 186; makefile: 35
file content (112 lines) | stat: -rw-r--r-- 3,290 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*========================== begin_copyright_notice ============================

Copyright (C) 2020-2025 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

//===----------------------------------------------------------------------===//
///
/// This contains a collection of methods to inspect the positions/existence
/// of arguments in a shader as well as methods to compute the types of the
/// argument portion of a stack frame.
///
//===----------------------------------------------------------------------===//

#include "RTStackFormat.h"
#include "RTArgs.h"
#include "MDFrameWork.h"
#include "Probe/Assertion.h"
#include "llvmWrapper/IR/IRBuilder.h"
#include <optional>
#include "Compiler/CISACodeGen/getCacheOpts.h"

using namespace llvm;
using namespace IGC;
using namespace RTStackFormat;

void ArgQuery::init(CallableShaderTypeMD FuncType, const FunctionMetaData &FMD) {
  ShaderTy = FuncType;
  uint32_t Idx = 0;
  switch (FuncType) {
  case RayGen:
  case CallStackHandler:
    break;
  case Miss:
    if (FMD.rtInfo.hasTraceRayPayload)
      TraceRayPayloadIdx = Idx++;
    break;
  case Callable:
    if (FMD.rtInfo.hasCallableData)
      CallableShaderPayloadIdx = Idx++;
    break;
  case ClosestHit:
  // For any-hit shaders, there are two cases:
  // 1. procedural hit-group: call will be inlined and will use no
  // stack (args just passed as normal function args).
  // 2. triangle hit-group: ray payload passed, hit attributes will
  // come from potentialHit portion of stack.
  // TODO: in the procedural case we should have already deleted
  // the shader by this point.
  case AnyHit:
    if (FMD.rtInfo.hasTraceRayPayload)
      TraceRayPayloadIdx = Idx++;
    if (FMD.rtInfo.hasHitAttributes)
      HitAttributeIdx = Idx++;
    break;
  case Intersection:
    break;
  default:
    IGC_ASSERT_MESSAGE(0, "unknown func type!");
    break;
  }
}

ArgQuery::ArgQuery(const Function &F, const CodeGenContext &Ctx) {
  auto *MMD = Ctx.getModuleMetaData();
  auto &FuncMD = MMD->FuncMD;
  auto I = FuncMD.find(const_cast<Function *>(&F));
  IGC_ASSERT_MESSAGE(I != FuncMD.end(), "Missing metadata?");
  auto &FMD = I->second;

  init(FMD.rtInfo.callableShaderType, FMD);
}

ArgQuery::ArgQuery(const FunctionMetaData &FMD) { init(FMD.rtInfo.callableShaderType, FMD); }

ArgQuery::ArgQuery(CallableShaderTypeMD FuncType, const FunctionMetaData &FMD) { init(FuncType, FMD); }

Argument *ArgQuery::getPayloadArg(const Function *F) const {
  return const_cast<Argument *>(getArg(F, getPayloadArgNo()));
}

Argument *ArgQuery::getHitAttribArg(const Function *F) const {
  return const_cast<Argument *>(getArg(F, getHitAttribArgNo()));
}

std::optional<uint32_t> ArgQuery::getPayloadArgNo() const {
  if (ShaderTy == Callable)
    return CallableShaderPayloadIdx;
  else
    return TraceRayPayloadIdx;

  return std::nullopt;
}

const Argument *ArgQuery::getArg(const Function *F, std::optional<uint32_t> ArgNo) const {
  // Not specified
  if (!ArgNo)
    return nullptr;

  auto *Arg = F->arg_begin();
  if (F->arg_size() <= *ArgNo)
    return nullptr;

  std::advance(Arg, *ArgNo);

  return Arg;
}

std::optional<uint32_t> ArgQuery::getHitAttribArgNo() const { return HitAttributeIdx; }