[libclc] 03/58: r600: Add image reading builtins.

Andreas Boll aboll-guest at moszumanska.debian.org
Thu Oct 6 08:16:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

aboll-guest pushed a commit to branch master
in repository libclc.

commit 125bc9907317f76ada6933826c122594361fc7c3
Author: Tom Stellard <thomas.stellard at amd.com>
Date:   Mon Sep 21 14:59:54 2015 +0000

    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
---
 generic/include/clc/image/image.h | 13 +++++++++++
 r600/lib/SOURCES                  |  4 ++++
 r600/lib/image/read_image_impl.ll | 46 +++++++++++++++++++++++++++++++++++++++
 r600/lib/image/read_imagef.cl     | 14 ++++++++++++
 r600/lib/image/read_imagei.cl     | 23 ++++++++++++++++++++
 r600/lib/image/read_imageui.cl    | 23 ++++++++++++++++++++
 6 files changed, 123 insertions(+)

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));
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/libclc.git



More information about the Pkg-opencl-commits mailing list