Skip to content

Commit 434bd5b

Browse files
committed
[AMDGPU] Add builtin functions image_bvh_intersect_ray
Reviewed by: Stanislav Mekhanoshin, Matt Arsenault Differential Revision: https://reviews.llvm.org/D104946
1 parent f6db885 commit 434bd5b

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

clang/include/clang/Basic/BuiltinsAMDGPU.def

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ TARGET_BUILTIN(__builtin_amdgcn_permlane16, "UiUiUiUiUiIbIb", "nc", "gfx10-insts
215215
TARGET_BUILTIN(__builtin_amdgcn_permlanex16, "UiUiUiUiUiIbIb", "nc", "gfx10-insts")
216216
TARGET_BUILTIN(__builtin_amdgcn_mov_dpp8, "UiUiIUi", "nc", "gfx10-insts")
217217

218+
//===----------------------------------------------------------------------===//
219+
// Raytracing builtins.
220+
// By default the 1st argument is i32 and the 4/5-th arguments are float4.
221+
// Postfix l indicates the 1st argument is i64.
222+
// Postfix h indicates the 4/5-th arguments are half4.
223+
//===----------------------------------------------------------------------===//
224+
TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray, "V4UiUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
225+
TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_h, "V4UiUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
226+
TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_l, "V4UiWUifV4fV4fV4fV4Ui", "nc", "gfx10-insts")
227+
TARGET_BUILTIN(__builtin_amdgcn_image_bvh_intersect_ray_lh, "V4UiWUifV4fV4hV4hV4Ui", "nc", "gfx10-insts")
228+
218229
//===----------------------------------------------------------------------===//
219230
// Special builtins.
220231
//===----------------------------------------------------------------------===//

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15850,6 +15850,23 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1585015850
CI->setConvergent();
1585115851
return CI;
1585215852
}
15853+
case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
15854+
case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
15855+
case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
15856+
case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
15857+
llvm::Value *NodePtr = EmitScalarExpr(E->getArg(0));
15858+
llvm::Value *RayExtent = EmitScalarExpr(E->getArg(1));
15859+
llvm::Value *RayOrigin = EmitScalarExpr(E->getArg(2));
15860+
llvm::Value *RayDir = EmitScalarExpr(E->getArg(3));
15861+
llvm::Value *RayInverseDir = EmitScalarExpr(E->getArg(4));
15862+
llvm::Value *TextureDescr = EmitScalarExpr(E->getArg(5));
15863+
15864+
Function *F = CGM.getIntrinsic(Intrinsic::amdgcn_image_bvh_intersect_ray,
15865+
{NodePtr->getType(), RayDir->getType()});
15866+
return Builder.CreateCall(F, {NodePtr, RayExtent, RayOrigin, RayDir,
15867+
RayInverseDir, TextureDescr});
15868+
}
15869+
1585315870
// amdgcn workitem
1585415871
case AMDGPU::BI__builtin_amdgcn_workitem_id_x:
1585515872
return emitRangedBuiltin(*this, Intrinsic::amdgcn_workitem_id_x, 0, 1024);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S \
3+
// RUN: -emit-llvm -cl-std=CL2.0 -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1030 -S \
5+
// RUN: -cl-std=CL2.0 -o - %s | FileCheck -check-prefix=ISA %s
6+
7+
// Test llvm.amdgcn.image.bvh.intersect.ray intrinsic.
8+
9+
// The clang builtin functions __builtin_amdgcn_image_bvh_intersect_ray* use
10+
// postfixes to indicate the types of the 1st, 4th, and 5th arguments.
11+
// By default, the 1st argument is i32, the 4/5-th arguments are float4.
12+
// Postfix l indicates the 1st argument is i64 and postfix h indicates
13+
// the 4/5-th arguments are half4.
14+
15+
typedef unsigned int uint;
16+
typedef unsigned long ulong;
17+
typedef float float4 __attribute__((ext_vector_type(4)));
18+
typedef double double4 __attribute__((ext_vector_type(4)));
19+
typedef half half4 __attribute__((ext_vector_type(4)));
20+
typedef uint uint4 __attribute__((ext_vector_type(4)));
21+
22+
// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f32
23+
// ISA: image_bvh_intersect_ray
24+
void test_image_bvh_intersect_ray(global uint4* out, uint node_ptr,
25+
float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
26+
uint4 texture_descr)
27+
{
28+
*out = __builtin_amdgcn_image_bvh_intersect_ray(node_ptr, ray_extent,
29+
ray_origin, ray_dir, ray_inv_dir, texture_descr);
30+
}
31+
32+
// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i32.v4f16
33+
// ISA: image_bvh_intersect_ray
34+
void test_image_bvh_intersect_ray_h(global uint4* out, uint node_ptr,
35+
float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
36+
uint4 texture_descr)
37+
{
38+
*out = __builtin_amdgcn_image_bvh_intersect_ray_h(node_ptr, ray_extent,
39+
ray_origin, ray_dir, ray_inv_dir, texture_descr);
40+
}
41+
42+
// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f32
43+
// ISA: image_bvh_intersect_ray
44+
void test_image_bvh_intersect_ray_l(global uint4* out, ulong node_ptr,
45+
float ray_extent, float4 ray_origin, float4 ray_dir, float4 ray_inv_dir,
46+
uint4 texture_descr)
47+
{
48+
*out = __builtin_amdgcn_image_bvh_intersect_ray_l(node_ptr, ray_extent,
49+
ray_origin, ray_dir, ray_inv_dir, texture_descr);
50+
}
51+
52+
// CHECK: call <4 x i32> @llvm.amdgcn.image.bvh.intersect.ray.i64.v4f16
53+
// ISA: image_bvh_intersect_ray
54+
void test_image_bvh_intersect_ray_lh(global uint4* out, ulong node_ptr,
55+
float ray_extent, float4 ray_origin, half4 ray_dir, half4 ray_inv_dir,
56+
uint4 texture_descr)
57+
{
58+
*out = __builtin_amdgcn_image_bvh_intersect_ray_lh(node_ptr, ray_extent,
59+
ray_origin, ray_dir, ray_inv_dir, texture_descr);
60+
}
61+

0 commit comments

Comments
 (0)