1010#include < fcntl.h>
1111#include < unistd.h>
1212#include < linux/ion.h>
13- #include < CL/cl_ext.h>
1413
1514#include < msm_ion.h>
1615
2726 ret; \
2827 })
2928
30- // just hard-code these for convenience
31- // size_t device_page_size = 0;
32- // clGetDeviceInfo(device_id, CL_DEVICE_PAGE_SIZE_QCOM,
33- // sizeof(device_page_size), &device_page_size,
34- // NULL);
35-
36- // size_t padding_cl = 0;
37- // clGetDeviceInfo(device_id, CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM,
38- // sizeof(padding_cl), &padding_cl,
39- // NULL);
40- #define DEVICE_PAGE_SIZE_CL 4096
41- #define PADDING_CL 0
42-
4329struct IonFileHandle {
4430 IonFileHandle () {
4531 fd = open (" /dev/ion" , O_RDWR | O_NONBLOCK);
@@ -58,7 +44,7 @@ int ion_fd() {
5844
5945void VisionBuf::allocate (size_t length) {
6046 struct ion_allocation_data ion_alloc = {0 };
61- ion_alloc.len = length + PADDING_CL + sizeof (uint64_t );
47+ ion_alloc.len = length + sizeof (uint64_t );
6248 ion_alloc.align = 4096 ;
6349 ion_alloc.heap_id_mask = 1 << ION_IOMMU_HEAP_ID;
6450 ion_alloc.flags = ION_FLAG_CACHED;
@@ -83,7 +69,7 @@ void VisionBuf::allocate(size_t length) {
8369 this ->addr = mmap_addr;
8470 this ->handle = ion_alloc.handle ;
8571 this ->fd = ion_fd_data.fd ;
86- this ->frame_id = (uint64_t *)((uint8_t *)this ->addr + this ->len + PADDING_CL );
72+ this ->frame_id = (uint64_t *)((uint8_t *)this ->addr + this ->len );
8773}
8874
8975void VisionBuf::import (){
@@ -100,27 +86,19 @@ void VisionBuf::import(){
10086 this ->addr = mmap (NULL , this ->mmap_len , PROT_READ | PROT_WRITE, MAP_SHARED, this ->fd , 0 );
10187 assert (this ->addr != MAP_FAILED);
10288
103- this ->frame_id = (uint64_t *)((uint8_t *)this ->addr + this ->len + PADDING_CL );
89+ this ->frame_id = (uint64_t *)((uint8_t *)this ->addr + this ->len );
10490}
10591
106- void VisionBuf::init_cl (cl_device_id device_id, cl_context ctx) {
107- int err;
108-
109- assert (((uintptr_t )this ->addr % DEVICE_PAGE_SIZE_CL) == 0 );
92+ void VisionBuf::init_yuv (size_t init_width, size_t init_height, size_t init_stride, size_t init_uv_offset){
93+ this ->width = init_width;
94+ this ->height = init_height;
95+ this ->stride = init_stride;
96+ this ->uv_offset = init_uv_offset;
11097
111- cl_mem_ion_host_ptr ion_cl = {0 };
112- ion_cl.ext_host_ptr .allocation_type = CL_MEM_ION_HOST_PTR_QCOM;
113- ion_cl.ext_host_ptr .host_cache_policy = CL_MEM_HOST_UNCACHED_QCOM;
114- ion_cl.ion_filedesc = this ->fd ;
115- ion_cl.ion_hostptr = this ->addr ;
116-
117- this ->buf_cl = clCreateBuffer (ctx,
118- CL_MEM_USE_HOST_PTR | CL_MEM_EXT_HOST_PTR_QCOM,
119- this ->len , &ion_cl, &err);
120- assert (err == 0 );
98+ this ->y = (uint8_t *)this ->addr ;
99+ this ->uv = this ->y + this ->uv_offset ;
121100}
122101
123-
124102int VisionBuf::sync (int dir) {
125103 struct ion_flush_data flush_data = {0 };
126104 flush_data.handle = this ->handle ;
@@ -143,14 +121,7 @@ int VisionBuf::sync(int dir) {
143121}
144122
145123int VisionBuf::free () {
146- int err = 0 ;
147-
148- if (this ->buf_cl ){
149- err = clReleaseMemObject (this ->buf_cl );
150- if (err != 0 ) return err;
151- }
152-
153- err = munmap (this ->addr , this ->mmap_len );
124+ int err = munmap (this ->addr , this ->mmap_len );
154125 if (err != 0 ) return err;
155126
156127 err = close (this ->fd );
@@ -159,3 +130,11 @@ int VisionBuf::free() {
159130 struct ion_handle_data handle_data = {.handle = this ->handle };
160131 return HANDLE_EINTR (ioctl (ion_fd (), ION_IOC_FREE, &handle_data));
161132}
133+
134+ uint64_t VisionBuf::get_frame_id () {
135+ return *frame_id;
136+ }
137+
138+ void VisionBuf::set_frame_id (uint64_t id) {
139+ *frame_id = id;
140+ }
0 commit comments