[libclc] r248160 - r600: Add image reading builtins.
Tom Stellard via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 21 07:59:54 PDT 2015
Author: tstellar
Date: Mon Sep 21 09:59:54 2015
New Revision: 248160
URL: http://llvm.org/viewvc/llvm-project?rev=248160&view=rev
Log:
r600: Add image reading builtins.
Patch by: Zoltan Gilian
Added:
libclc/trunk/r600/lib/image/read_image_impl.ll
libclc/trunk/r600/lib/image/read_imagef.cl
libclc/trunk/r600/lib/image/read_imagei.cl
libclc/trunk/r600/lib/image/read_imageui.cl
Modified:
libclc/trunk/generic/include/clc/image/image.h
libclc/trunk/r600/lib/SOURCES
Modified: libclc/trunk/generic/include/clc/image/image.h
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/image/image.h?rev=248160&r1=248159&r2=248160&view=diff
==============================================================================
--- libclc/trunk/generic/include/clc/image/image.h (original)
+++ libclc/trunk/generic/include/clc/image/image.h Mon Sep 21 09:59:54 2015
@@ -14,3 +14,16 @@ _CLC_OVERLOAD _CLC_DECL int get_image_ch
_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);
Modified: libclc/trunk/r600/lib/SOURCES
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/SOURCES?rev=248160&r1=248159&r2=248160&view=diff
==============================================================================
--- libclc/trunk/r600/lib/SOURCES (original)
+++ libclc/trunk/r600/lib/SOURCES Mon Sep 21 09:59:54 2015
@@ -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
Added: libclc/trunk/r600/lib/image/read_image_impl.ll
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/image/read_image_impl.ll?rev=248160&view=auto
==============================================================================
--- libclc/trunk/r600/lib/image/read_image_impl.ll (added)
+++ libclc/trunk/r600/lib/image/read_image_impl.ll Mon Sep 21 09:59:54 2015
@@ -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
+}
Added: libclc/trunk/r600/lib/image/read_imagef.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/image/read_imagef.cl?rev=248160&view=auto
==============================================================================
--- libclc/trunk/r600/lib/image/read_imagef.cl (added)
+++ libclc/trunk/r600/lib/image/read_imagef.cl Mon Sep 21 09:59:54 2015
@@ -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);
+}
Added: libclc/trunk/r600/lib/image/read_imagei.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/image/read_imagei.cl?rev=248160&view=auto
==============================================================================
--- libclc/trunk/r600/lib/image/read_imagei.cl (added)
+++ libclc/trunk/r600/lib/image/read_imagei.cl Mon Sep 21 09:59:54 2015
@@ -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));
+}
Added: libclc/trunk/r600/lib/image/read_imageui.cl
URL: http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/image/read_imageui.cl?rev=248160&view=auto
==============================================================================
--- libclc/trunk/r600/lib/image/read_imageui.cl (added)
+++ libclc/trunk/r600/lib/image/read_imageui.cl Mon Sep 21 09:59:54 2015
@@ -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));
+}
More information about the cfe-commits
mailing list