mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-03 07:38:57 +00:00
r600: Add image reading builtins.
Patch by: Zoltan Gilian llvm-svn: 248160
This commit is contained in:
parent
ccc0ec1ddb
commit
9a7d4a940f
@ -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);
|
||||
|
@ -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
|
||||
|
46
libclc/r600/lib/image/read_image_impl.ll
Normal file
46
libclc/r600/lib/image/read_image_impl.ll
Normal file
@ -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
|
||||
}
|
14
libclc/r600/lib/image/read_imagef.cl
Normal file
14
libclc/r600/lib/image/read_imagef.cl
Normal file
@ -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);
|
||||
}
|
23
libclc/r600/lib/image/read_imagei.cl
Normal file
23
libclc/r600/lib/image/read_imagei.cl
Normal file
@ -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));
|
||||
}
|
23
libclc/r600/lib/image/read_imageui.cl
Normal file
23
libclc/r600/lib/image/read_imageui.cl
Normal file
@ -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));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user