Skip to content

Commit ffb070e

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
Adding hitgroups to ModuleMetaData
This change is to add a hitgroup definition in llvm metadata.
1 parent 6234cd2 commit ffb070e

File tree

6 files changed

+129
-47
lines changed

6 files changed

+129
-47
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2020-2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#pragma once
10+
11+
#include <stdint.h>
12+
13+
namespace RTStackFormat
14+
{
15+
enum class HIT_GROUP_TYPE
16+
{
17+
TRIANGLES = 0x0,
18+
PROCEDURAL_PRIMITIVE = 0x1,
19+
};
20+
21+
enum struct RayTracingShaderType
22+
{
23+
ANY_HIT = 0b0000,
24+
CLOSEST_HIT = 0b0001,
25+
MISS = 0b0010,
26+
INTERSECTION = 0b0011,
27+
RESERVED = 0b0100
28+
};
29+
30+
enum HIT_KIND
31+
{
32+
HIT_KIND_TRIANGLE_FRONT_FACE = 254,
33+
HIT_KIND_TRIANGLE_BACK_FACE = 255
34+
};
35+
36+
constexpr static uint32_t RAYTRACING_MAX_DECLARABLE_TRACE_RECURSION_DEPTH = 31;
37+
constexpr static uint32_t RAYTRACING_MAX_ATTRIBUTE_SIZE_IN_BYTES = 32;
38+
constexpr static uint32_t RAYTRACING_SHADER_RECORD_BYTE_ALIGNMENT = 32;
39+
constexpr static uint32_t RAYTRACING_SHADER_TABLE_BYTE_ALIGNMENT = 64;
40+
41+
constexpr static uint32_t SHADER_IDENTIFIER_SIZE_IN_BYTES = 32;
42+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2021 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
#pragma once
10+
11+
#include <string>
12+
#include <optional>
13+
14+
#include "ConstantsEnums.h"
15+
16+
#include "common/LLVMWarningsPush.hpp"
17+
#include "common/LLVMWarningsPop.hpp"
18+
19+
namespace IGC {
20+
21+
struct HitGroupInfo
22+
{
23+
std::string HitGroupName;
24+
RTStackFormat::HIT_GROUP_TYPE Type;
25+
std::string ClosestHit;
26+
std::string Intersection;
27+
std::string AnyHit;
28+
};
29+
30+
} // namespace IGC

IGC/AdaptorCommon/RayTracing/RTStackFormat.h

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SPDX-License-Identifier: MIT
1515
#pragma once
1616

1717
#include "API/RayDispatchGlobalData.h"
18+
#include "ConstantsEnums.h"
1819

1920
#include <stdint.h>
2021
#include <stddef.h>

IGC/DriverInterface/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ set(IGC_BUILD__HDR__DriverInterface
112112
)
113113

114114
set(IGC_BUILD__HDR__RAYTRACING
115+
"${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/RayTracing/ConstantsEnums.h"
116+
"${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/RayTracing/HitGroups.h"
115117
"${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/RayTracing/MemRegionAnalysis.h"
116118
"${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/RayTracing/RayTracingAddressSpaceAliasAnalysis.h"
117119
"${CMAKE_CURRENT_SOURCE_DIR}/../AdaptorCommon/RayTracing/RayTracingMemoryStyle.h"

IGC/common/MDFrameWork.h

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ SPDX-License-Identifier: MIT
2222
#include <llvm/ADT/SetVector.h>
2323
#include "common/LLVMWarningsPop.hpp"
2424

25+
#include "AdaptorCommon/RayTracing/HitGroups.h" // ^MDFramework^: ../AdaptorCommon/RayTracing
26+
#include "AdaptorCommon/RayTracing/ConstantsEnums.h" // ^MDFramework^: ../AdaptorCommon/RayTracing
2527
#include "AdaptorCommon/RayTracing/API/MemoryStyleEnum.h" // ^MDFramework^: ../AdaptorCommon/RayTracing/API
2628

2729
namespace llvm
@@ -815,6 +817,8 @@ enum class ShaderTypeMD
815817

816818
llvm::MapVector<llvm::Value*, llvm::Value*> predicationMap;
817819
llvm::MapVector<llvm::Value*, llvm::Value*> lifeTimeStartMap;
820+
821+
std::vector<HitGroupInfo> HitGroups;
818822
};
819823

820824
void serialize(const IGC::ModuleMetaData &moduleMD, llvm::Module* module);

IGC/common/autogen.py

+50-47
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ class DeclHeader:
1717
line: str
1818
# declName is just the identifier name
1919
declName: str
20+
# declName is just the identifier name
21+
namespace: str
2022
# fields contains a list of all the names of the fields in the structure
2123
fields: List[str]
2224

23-
def __init__(self, line: str, declName: str, fields: List[str]):
24-
self.line = line
25-
self.declName = declName
26-
self.fields = fields
25+
def __init__(self, line: str, namespace: str, declName: str, fields: List[str]):
26+
self.line = line
27+
self.namespace = namespace
28+
self.declName = declName
29+
self.fields = fields
2730

2831
enumNames: List[DeclHeader] = []
2932
structureNames: List[DeclHeader] = []
@@ -73,45 +76,45 @@ def lines(s: str) -> Generator[str, None, None]:
7376
yield line
7477

7578
def parseHeader(fileContents: str):
76-
insideIGCNameSpace = False
79+
namespace = ""
7780
pcount = 0
7881
file = lines(fileContents)
7982
for line in file:
8083
line = line.split("//")[0]
81-
if "namespace IGC" in line:
84+
if "namespace" in line:
85+
words = line.split()
8286
while "{" not in line:
8387
line = next(file, None)
8488
if line is None:
8589
sys.exit('missing opening brace!')
86-
insideIGCNameSpace = True
90+
namespace = words[1] if len(words) > 1 else ""
8791
pcount += 1
88-
if insideIGCNameSpace:
89-
blockType = re.search("struct|enum", line)
90-
if blockType:
91-
words = line.split()
92-
idx = 2 if 'class' in words else 1
93-
foundDecl = DeclHeader(line, words[idx], [])
94-
opcount = pcount
95-
namesList = structureNames
96-
extractFunc = extractStructField
97-
if blockType[0] == 'enum':
98-
namesList = enumNames
99-
extractFunc = extractEnumVal
100-
while True:
101-
line = next(file, None)
102-
if line is None:
103-
sys.exit(f"EOF reached with unclosed enum or struct, check formatting")
104-
line = line.split("//")[0]
105-
pcount += line.count("{") - line.count("}")
106-
if pcount <= opcount:
107-
break
108-
extractFunc(re.sub("{|}","", line), foundDecl)
109-
assert pcount == opcount, f"Unexpected struct/enum ending, check formatting"
110-
namesList.append(foundDecl)
111-
elif "}" in line and "};" not in line:
112-
insideIGCNameSpace = False
113-
pcount -= 1
114-
assert pcount == 0, f"EOF reached, with unclosed IGC namespace, check formatting"
92+
blockType = re.search("struct|enum", line)
93+
if blockType:
94+
words = line.split()
95+
idx = 2 if blockType[0] == 'enum' and ('class' in words or 'struct' in words) else 1
96+
foundDecl = DeclHeader(line, namespace, words[idx], [])
97+
opcount = pcount
98+
namesList = structureNames
99+
extractFunc = extractStructField
100+
if blockType[0] == 'enum':
101+
namesList = enumNames
102+
extractFunc = extractEnumVal
103+
while True:
104+
line = next(file, None)
105+
if line is None:
106+
sys.exit(f"EOF reached with unclosed enum or struct, check formatting")
107+
line = line.split("//")[0]
108+
pcount += line.count("{") - line.count("}")
109+
if pcount <= opcount:
110+
break
111+
extractFunc(re.sub("{|}","", line), foundDecl)
112+
assert pcount == opcount, f"Unexpected struct/enum ending, check formatting"
113+
namesList.append(foundDecl)
114+
elif "}" in line and "};" not in line:
115+
insideIGCNameSpace = False
116+
pcount -= 1
117+
assert pcount == 0, f"EOF reached, with unclosed namespace, check formatting"
115118

116119
def stripBlockComments(text: str) -> str:
117120
return re.sub(r'/\*(.|\s)*?\*/', '', text)
@@ -164,7 +167,7 @@ def printEnumCalls(enumDecl: DeclHeader, outputFile: TextIO):
164167
outputFile.write(f" switch({enumDecl.declName}Var)\n")
165168
outputFile.write(" {\n")
166169
for item in enumDecl.fields:
167-
outputFile.write(f" case IGC::{enumDecl.declName}::{item}:\n")
170+
outputFile.write(f" case {enumDecl.namespace}::{enumDecl.declName}::{item}:\n")
168171
outputFile.write(" enumName = ")
169172
outputFile.write(f'"{item}"')
170173
outputFile.write(";\n")
@@ -193,41 +196,41 @@ def printEnumReadCalls(enumDecl: DeclHeader, outputFile: TextIO):
193196
outputFile.write(f'"{item}"')
194197
outputFile.write(") == 0)\n")
195198
outputFile.write(" {\n")
196-
outputFile.write(f" {enumDecl.declName}Var = IGC::{enumDecl.declName}::{item};\n")
199+
outputFile.write(f" {enumDecl.declName}Var = {enumDecl.namespace}::{enumDecl.declName}::{item};\n")
197200
outputFile.write(" }\n")
198201
first = False
199202

200203
outputFile.write(" else\n")
201204
outputFile.write(" {\n")
202-
outputFile.write(f" {enumDecl.declName}Var = (IGC::{enumDecl.declName})(0);\n")
205+
outputFile.write(f" {enumDecl.declName}Var = ({enumDecl.namespace}::{enumDecl.declName})(0);\n")
203206
outputFile.write(" }\n")
204207

205208

206-
def emitCodeBlock(names: List[DeclHeader], fmtFn: Callable[[str], str], printFn: Callable[[DeclHeader, TextIO], None], outputFile: TextIO):
209+
def emitCodeBlock(names: List[DeclHeader], fmtFn: Callable[[str, str], str], printFn: Callable[[DeclHeader, TextIO], None], outputFile: TextIO):
207210
for item in names:
208-
outputFile.write(fmtFn(item.declName))
211+
outputFile.write(fmtFn(item.namespace, item.declName))
209212
outputFile.write("{\n")
210213
printFn(item, outputFile)
211214
outputFile.write("}\n\n")
212215

213216
def emitEnumCreateNode(outputFile: TextIO):
214-
def fmtFn(item: str):
215-
return f"MDNode* CreateNode(IGC::{item} {item}Var, Module* module, StringRef name)\n"
217+
def fmtFn(namespace:str, item: str):
218+
return f"MDNode* CreateNode({namespace}::{item} {item}Var, Module* module, StringRef name)\n"
216219
emitCodeBlock(enumNames, fmtFn, printEnumCalls, outputFile)
217220

218221
def emitStructCreateNode(outputFile: TextIO):
219-
def fmtFn(item: str):
220-
return f"MDNode* CreateNode(const IGC::{item}& {item}Var, Module* module, StringRef name)\n"
222+
def fmtFn(namespace:str, item: str):
223+
return f"MDNode* CreateNode(const {namespace}::{item}& {item}Var, Module* module, StringRef name)\n"
221224
emitCodeBlock(structureNames, fmtFn, printStructCalls, outputFile)
222225

223226
def emitEnumReadNode(outputFile: TextIO):
224-
def fmtFn(item: str):
225-
return f"void readNode(IGC::{item}& {item}Var, MDNode* node)\n"
227+
def fmtFn(namespace:str, item: str):
228+
return f"void readNode({namespace}::{item}& {item}Var, MDNode* node)\n"
226229
emitCodeBlock(enumNames, fmtFn, printEnumReadCalls, outputFile)
227230

228231
def emitStructReadNode(outputFile: TextIO):
229-
def fmtFn(item: str):
230-
return f"void readNode(IGC::{item}& {item}Var, MDNode* node)\n"
232+
def fmtFn(namespace:str, item: str):
233+
return f"void readNode({namespace}::{item}& {item}Var, MDNode* node)\n"
231234
emitCodeBlock(structureNames, fmtFn, printStructReadCalls, outputFile)
232235

233236
def genCode(fileName: str):

0 commit comments

Comments
 (0)