summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2015-09-21 14:59:54 +0000
committerTom Stellard <thomas.stellard@amd.com>2015-09-21 14:59:54 +0000
commit125bc9907317f76ada6933826c122594361fc7c3 (patch)
tree95e2230069baa629ddf1f22cd9304d3c07b876b1
parenta559dddbf117e7601e4330c1527267c9e462854c (diff)
r600: Add image reading builtins.
Patch by: Zoltan Gilian git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@248160 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--generic/include/clc/image/image.h13
-rw-r--r--r600/lib/SOURCES4
-rw-r--r--r600/lib/image/read_image_impl.ll46
-rw-r--r--r600/lib/image/read_imagef.cl14
-rw-r--r--r600/lib/image/read_imagei.cl23
-rw-r--r--r600/lib/image/read_imageui.cl23
6 files changed, 123 insertions, 0 deletions
diff --git a/generic/include/clc/image/image.h b/generic/include/clc/image/image.h
index 9c97563..8c9a444 100644
--- a/generic/include/clc/image/image.h
+++ b/generic/include/clc/image/image.h
@@ -14,3 +14,16 @@ _CLC_OVERLOAD _CLC_DECL int get_image_channel_order (image3d_t image);
_CLC_OVERLOAD _CLC_DECL int2 get_image_dim (image2d_t image);
_CLC_OVERLOAD _CLC_DECL int4 get_image_dim (image3d_t image);
+
+_CLC_OVERLOAD _CLC_DECL float4
+read_imagef(image2d_t image, sampler_t sampler, int2 coord);
+_CLC_OVERLOAD _CLC_DECL float4
+read_imagef(image2d_t image, sampler_t sampler, float2 coord);
+_CLC_OVERLOAD _CLC_DECL int4
+read_imagei(image2d_t image, sampler_t sampler, int2 coord);
+_CLC_OVERLOAD _CLC_DECL int4
+read_imagei(image2d_t image, sampler_t sampler, float2 coord);
+_CLC_OVERLOAD _CLC_DECL uint4
+read_imageui(image2d_t image, sampler_t sampler, int2 coord);
+_CLC_OVERLOAD _CLC_DECL uint4
+read_imageui(image2d_t image, sampler_t sampler, float2 coord);
diff --git a/r600/lib/SOURCES b/r600/lib/SOURCES
index 349df7e..706c879 100644
--- a/r600/lib/SOURCES
+++ b/r600/lib/SOURCES
@@ -16,3 +16,7 @@ image/get_image_depth.cl
image/get_image_channel_data_type.cl
image/get_image_channel_order.cl
image/get_image_attributes_impl.ll
+image/read_imagef.cl
+image/read_imagei.cl
+image/read_imageui.cl
+image/read_image_impl.ll
diff --git a/r600/lib/image/read_image_impl.ll b/r600/lib/image/read_image_impl.ll
new file mode 100644
index 0000000..229a252
--- /dev/null
+++ b/r600/lib/image/read_image_impl.ll
@@ -0,0 +1,46 @@
+%opencl.image2d_t = type opaque
+
+declare <4 x float> @llvm.R600.tex(<4 x float>, i32, i32, i32, i32, i32, i32,
+ i32, i32, i32) readnone
+declare i32 @llvm.OpenCL.image.get.resource.id.2d(
+ %opencl.image2d_t addrspace(1)*) nounwind readnone
+declare i32 @llvm.OpenCL.sampler.get.resource.id(i32) readnone
+
+define <4 x float> @__clc_v4f_from_v2f(<2 x float> %v) alwaysinline {
+ %e0 = extractelement <2 x float> %v, i32 0
+ %e1 = extractelement <2 x float> %v, i32 1
+ %res.0 = insertelement <4 x float> undef, float %e0, i32 0
+ %res.1 = insertelement <4 x float> %res.0, float %e1, i32 1
+ %res.2 = insertelement <4 x float> %res.1, float 0.0, i32 2
+ %res.3 = insertelement <4 x float> %res.2, float 0.0, i32 3
+ ret <4 x float> %res.3
+}
+
+define <4 x float> @__clc_read_imagef_tex(
+ %opencl.image2d_t addrspace(1)* nocapture %img,
+ i32 %sampler, <2 x float> %coord) alwaysinline {
+entry:
+ %coord_v4 = call <4 x float> @__clc_v4f_from_v2f(<2 x float> %coord)
+ %smp_id = call i32 @llvm.OpenCL.sampler.get.resource.id(i32 %sampler)
+ %img_id = call i32 @llvm.OpenCL.image.get.resource.id.2d(
+ %opencl.image2d_t addrspace(1)* %img)
+ %tex_id = add i32 %img_id, 2 ; First 2 IDs are reserved.
+
+ %coord_norm = and i32 %sampler, 1
+ %is_norm = icmp eq i32 %coord_norm, 1
+ br i1 %is_norm, label %NormCoord, label %UnnormCoord
+NormCoord:
+ %data.norm = call <4 x float> @llvm.R600.tex(
+ <4 x float> %coord_v4,
+ i32 0, i32 0, i32 0, ; Offset.
+ i32 2, i32 %smp_id,
+ i32 1, i32 1, i32 1, i32 1) ; Normalized coords.
+ ret <4 x float> %data.norm
+UnnormCoord:
+ %data.unnorm = call <4 x float> @llvm.R600.tex(
+ <4 x float> %coord_v4,
+ i32 0, i32 0, i32 0, ; Offset.
+ i32 %tex_id, i32 %smp_id,
+ i32 0, i32 0, i32 0, i32 0) ; Unnormalized coords.
+ ret <4 x float> %data.unnorm
+}
diff --git a/r600/lib/image/read_imagef.cl b/r600/lib/image/read_imagef.cl
new file mode 100644
index 0000000..af80ada
--- /dev/null
+++ b/r600/lib/image/read_imagef.cl
@@ -0,0 +1,14 @@
+#include <clc/clc.h>
+
+_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2);
+
+_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler,
+ int2 coord) {
+ float2 coord_float = (float2)(coord.x, coord.y);
+ return __clc_read_imagef_tex(image, sampler, coord_float);
+}
+
+_CLC_OVERLOAD _CLC_DEF float4 read_imagef(image2d_t image, sampler_t sampler,
+ float2 coord) {
+ return __clc_read_imagef_tex(image, sampler, coord);
+}
diff --git a/r600/lib/image/read_imagei.cl b/r600/lib/image/read_imagei.cl
new file mode 100644
index 0000000..b973aae
--- /dev/null
+++ b/r600/lib/image/read_imagei.cl
@@ -0,0 +1,23 @@
+#include <clc/clc.h>
+
+_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2);
+
+int4 __clc_reinterpret_v4f_to_v4i(float4 v) {
+ union {
+ int4 v4i;
+ float4 v4f;
+ } res = { .v4f = v};
+ return res.v4i;
+}
+
+_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler,
+ int2 coord) {
+ float2 coord_float = (float2)(coord.x, coord.y);
+ return __clc_reinterpret_v4f_to_v4i(
+ __clc_read_imagef_tex(image, sampler, coord_float));
+}
+_CLC_OVERLOAD _CLC_DEF int4 read_imagei(image2d_t image, sampler_t sampler,
+ float2 coord) {
+ return __clc_reinterpret_v4f_to_v4i(
+ __clc_read_imagef_tex(image, sampler, coord));
+}
diff --git a/r600/lib/image/read_imageui.cl b/r600/lib/image/read_imageui.cl
new file mode 100644
index 0000000..ec9836e
--- /dev/null
+++ b/r600/lib/image/read_imageui.cl
@@ -0,0 +1,23 @@
+#include <clc/clc.h>
+
+_CLC_DECL float4 __clc_read_imagef_tex(image2d_t, sampler_t, float2);
+
+uint4 __clc_reinterpret_v4f_to_v4ui(float4 v) {
+ union {
+ uint4 v4ui;
+ float4 v4f;
+ } res = { .v4f = v};
+ return res.v4ui;
+}
+
+_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler,
+ int2 coord) {
+ float2 coord_float = (float2)(coord.x, coord.y);
+ return __clc_reinterpret_v4f_to_v4ui(
+ __clc_read_imagef_tex(image, sampler, coord_float));
+}
+_CLC_OVERLOAD _CLC_DEF uint4 read_imageui(image2d_t image, sampler_t sampler,
+ float2 coord) {
+ return __clc_reinterpret_v4f_to_v4ui(
+ __clc_read_imagef_tex(image, sampler, coord));
+}