parent
e9ad7793f0
commit
de33bc4645
99 changed files with 6060 additions and 2198 deletions
Binary file not shown.
Binary file not shown.
@ -1,2 +0,0 @@ |
||||
src/* |
||||
out/* |
Binary file not shown.
Binary file not shown.
@ -1,122 +0,0 @@ |
||||
#!/usr/bin/env python2.7 |
||||
|
||||
import os |
||||
import sys |
||||
import glob |
||||
import shutil |
||||
import urllib2 |
||||
import hashlib |
||||
import subprocess |
||||
|
||||
|
||||
EXTERNAL_PATH = os.path.dirname(os.path.abspath(__file__)) |
||||
|
||||
if os.path.exists("/init.qcom.rc"): |
||||
# android |
||||
APKPATCH = os.path.join(EXTERNAL_PATH, 'tools/apkpatch_android') |
||||
SIGNAPK = os.path.join(EXTERNAL_PATH, 'tools/signapk_android') |
||||
else: |
||||
APKPATCH = os.path.join(EXTERNAL_PATH, 'tools/apkpatch') |
||||
SIGNAPK = os.path.join(EXTERNAL_PATH, 'tools/signapk') |
||||
|
||||
APKS = { |
||||
'com.waze': { |
||||
'src': 'https://apkcache.s3.amazonaws.com/com.waze_1021278.apk', |
||||
'src_sha256': 'f00957e93e2389f9e30502ac54994b98ac769314b0963c263d4e8baa625ab0c2', |
||||
'patch': 'com.waze.apkpatch', |
||||
'out_sha256': 'fee880a91a44c738442cd05fd1b6d9b5817cbf755aa61c86325ada2bc443d5cf' |
||||
}, |
||||
'com.spotify.music': { |
||||
'src': 'https://apkcache.s3.amazonaws.com/com.spotify.music_24382006.apk', |
||||
'src_sha256': '0610fea68ee7ba5f8e4e0732ad429d729dd6cbb8bc21222c4c99db6cb09fbff4', |
||||
'patch': 'com.spotify.music.apkpatch', |
||||
'out_sha256': '5a3d6f478c7e40403a98ccc8906d7e0ae12b06543b41f5df52149dd09c647c11' |
||||
}, |
||||
} |
||||
|
||||
def sha256_path(path): |
||||
with open(path, 'rb') as f: |
||||
return hashlib.sha256(f.read()).hexdigest() |
||||
|
||||
def remove(path): |
||||
try: |
||||
os.remove(path) |
||||
except OSError: |
||||
pass |
||||
|
||||
def process(download, patch): |
||||
# clean up any junk apks |
||||
for out_apk in glob.glob(os.path.join(EXTERNAL_PATH, 'out/*.apk')): |
||||
app = os.path.basename(out_apk)[:-4] |
||||
if app not in APKS: |
||||
print "remove junk", out_apk |
||||
remove(out_apk) |
||||
|
||||
complete = True |
||||
for k,v in APKS.iteritems(): |
||||
apk_path = os.path.join(EXTERNAL_PATH, 'out', k+'.apk') |
||||
print "checking", apk_path |
||||
if os.path.exists(apk_path) and sha256_path(apk_path) == v['out_sha256']: |
||||
# nothing to do |
||||
continue |
||||
|
||||
complete = False |
||||
|
||||
remove(apk_path) |
||||
|
||||
src_path = os.path.join(EXTERNAL_PATH, 'src', v['src_sha256']) |
||||
if not os.path.exists(src_path) or sha256_path(src_path) != v['src_sha256']: |
||||
if not download: |
||||
continue |
||||
|
||||
print "downloading", v['src'], "to", src_path |
||||
# download it |
||||
resp = urllib2.urlopen(v['src']) |
||||
data = resp.read() |
||||
with open(src_path, 'wb') as src_f: |
||||
src_f.write(data) |
||||
|
||||
if sha256_path(src_path) != v['src_sha256']: |
||||
print "download was corrupted..." |
||||
continue |
||||
|
||||
if not patch: |
||||
continue |
||||
|
||||
# ignoring lots of TOCTTOU here... |
||||
|
||||
apk_temp = "/tmp/"+k+".patched" |
||||
remove(apk_temp) |
||||
apk_temp2 = "/tmp/"+k+".signed" |
||||
remove(apk_temp2) |
||||
|
||||
try: |
||||
print "patching", v['patch'] |
||||
subprocess.check_call([APKPATCH, 'apply', src_path, apk_temp, os.path.join(EXTERNAL_PATH, v['patch'])]) |
||||
print "signing", apk_temp |
||||
subprocess.check_call([SIGNAPK, |
||||
os.path.join(EXTERNAL_PATH, 'tools/certificate.pem'), os.path.join(EXTERNAL_PATH, 'tools/key.pk8'), |
||||
apk_temp, apk_temp2]) |
||||
|
||||
out_sha256 = sha256_path(apk_temp2) if os.path.exists(apk_temp2) else None |
||||
|
||||
if out_sha256 == v['out_sha256']: |
||||
print "done", apk_path |
||||
shutil.move(apk_temp2, apk_path) |
||||
else: |
||||
print "patch was corrupted", apk_temp2, out_sha256 |
||||
finally: |
||||
remove(apk_temp) |
||||
remove(apk_temp2) |
||||
|
||||
return complete |
||||
|
||||
if __name__ == "__main__": |
||||
ret = True |
||||
if len(sys.argv) == 2 and sys.argv[1] == "download": |
||||
ret = process(True, False) |
||||
elif len(sys.argv) == 2 and sys.argv[1] == "patch": |
||||
ret = process(False, True) |
||||
else: |
||||
ret = process(True, True) |
||||
sys.exit(0 if ret else 1) |
Binary file not shown.
@ -1,7 +0,0 @@ |
||||
#!/system/bin/sh |
||||
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)" |
||||
|
||||
export LD_LIBRARY_PATH=/system/lib64 |
||||
export CLASSPATH="$DIR"/ApkPatch.android.jar |
||||
exec app_process "$DIR" ApkPatch "$@" |
@ -1,17 +0,0 @@ |
||||
-----BEGIN CERTIFICATE----- |
||||
MIICtTCCAh4CCQDm79UqF+Dc5zANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMC |
||||
SUQxEzARBgNVBAgTCkphd2EgQmFyYXQxEDAOBgNVBAcTB0JhbmR1bmcxEjAQBgNV |
||||
BAoTCUxvbmRhdGlnYTETMBEGA1UECxMKQW5kcm9pZERldjEaMBgGA1UEAxMRTG9y |
||||
ZW5zaXVzIFcuIEwuIFQxIzAhBgkqhkiG9w0BCQEWFGxvcmVuekBsb25kYXRpZ2Eu |
||||
bmV0MB4XDTEwMDUwNTA5MjEzOFoXDTEzMDEyODA5MjEzOFowgZ4xCzAJBgNVBAYT |
||||
AklEMRMwEQYDVQQIEwpKYXdhIEJhcmF0MRAwDgYDVQQHEwdCYW5kdW5nMRIwEAYD |
||||
VQQKEwlMb25kYXRpZ2ExEzARBgNVBAsTCkFuZHJvaWREZXYxGjAYBgNVBAMTEUxv |
||||
cmVuc2l1cyBXLiBMLiBUMSMwIQYJKoZIhvcNAQkBFhRsb3JlbnpAbG9uZGF0aWdh |
||||
Lm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy2oWtbdVXMHGiS6cA3qi |
||||
3VfZt5Vz9jTlux+TEcGx5h18ZKwclyo+z2B0L/p5bYdnrTdFEiD7IxvX+h3lu0JV |
||||
B9rdXZdyrzXNOw5YFrsn2k7hKvB8KEBaga1gZEwodlc6N14H3FbZdZkIA9V716Pu |
||||
e5CWBZ2VqU03lUJmKnpH8c8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQBpNgXh8dw9 |
||||
uMjZxzLUXovV5ptHd61jAcZlQlffqPsz6/2QNfIShVdGH9jkm0IudfKkbvvOKive |
||||
a77t9c4sDh2Sat2L/rx6BfTuS1+y9wFr1Ee8Rrr7wGHhRkx2qqGrXGVWqXn8aE3E |
||||
P6e7BTPF0ibS+tG8cdDPEisqGFxw36nTNQ== |
||||
-----END CERTIFICATE----- |
Binary file not shown.
Binary file not shown.
@ -1,7 +0,0 @@ |
||||
#!/system/bin/sh |
||||
|
||||
DIR="$(cd "$(dirname "$0")" && pwd)" |
||||
|
||||
export LD_LIBRARY_PATH=/system/lib64 |
||||
export CLASSPATH="$DIR"/signapk.android.jar |
||||
exec app_process "$DIR" com.android.signapk.SignApk "$@" |
@ -0,0 +1,296 @@ |
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project |
||||
* Copyright (c) 2011-2015, The Linux Foundation. All rights reserved. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#ifndef GRALLOC_PRIV_H_ |
||||
#define GRALLOC_PRIV_H_ |
||||
|
||||
#include <stdint.h> |
||||
#include <limits.h> |
||||
#include <sys/cdefs.h> |
||||
#include <hardware/gralloc.h> |
||||
#include <pthread.h> |
||||
#include <errno.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <cutils/native_handle.h> |
||||
|
||||
#include <cutils/log.h> |
||||
|
||||
#define ROUND_UP_PAGESIZE(x) ( (((unsigned long)(x)) + PAGE_SIZE-1) & \ |
||||
(~(PAGE_SIZE-1)) ) |
||||
|
||||
/* Gralloc usage bits indicating the type of allocation that should be used */ |
||||
/* SYSTEM heap comes from kernel vmalloc (ION_SYSTEM_HEAP_ID)
|
||||
* is cached by default and |
||||
* is not secured */ |
||||
|
||||
/* GRALLOC_USAGE_PRIVATE_0 is unused */ |
||||
|
||||
/* Non linear, Universal Bandwidth Compression */ |
||||
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC GRALLOC_USAGE_PRIVATE_1 |
||||
|
||||
/* IOMMU heap comes from manually allocated pages, can be cached/uncached,
|
||||
* is not secured */ |
||||
#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP GRALLOC_USAGE_PRIVATE_2 |
||||
|
||||
/* MM heap is a carveout heap for video, can be secured */ |
||||
#define GRALLOC_USAGE_PRIVATE_MM_HEAP GRALLOC_USAGE_PRIVATE_3 |
||||
|
||||
/* ADSP heap is a carveout heap, is not secured */ |
||||
#define GRALLOC_USAGE_PRIVATE_ADSP_HEAP 0x01000000 |
||||
|
||||
/* Set this for allocating uncached memory (using O_DSYNC),
|
||||
* cannot be used with noncontiguous heaps */ |
||||
#define GRALLOC_USAGE_PRIVATE_UNCACHED 0x02000000 |
||||
|
||||
/* Buffer content should be displayed on an primary display only */ |
||||
#define GRALLOC_USAGE_PRIVATE_INTERNAL_ONLY 0x04000000 |
||||
|
||||
/* Buffer content should be displayed on an external display only */ |
||||
#define GRALLOC_USAGE_PRIVATE_EXTERNAL_ONLY 0x08000000 |
||||
|
||||
/* This flag is set for WFD usecase */ |
||||
#define GRALLOC_USAGE_PRIVATE_WFD 0x00200000 |
||||
|
||||
/* CAMERA heap is a carveout heap for camera, is not secured */ |
||||
#define GRALLOC_USAGE_PRIVATE_CAMERA_HEAP 0x00400000 |
||||
|
||||
/* This flag is used for SECURE display usecase */ |
||||
#define GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY 0x00800000 |
||||
|
||||
/* define Gralloc perform */ |
||||
#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1 |
||||
// This will be used by the graphics drivers to know if certain features
|
||||
// are defined in this display HAL.
|
||||
// Ex: Newer GFX libraries + Older Display HAL
|
||||
#define GRALLOC_MODULE_PERFORM_GET_STRIDE 2 |
||||
#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE 3 |
||||
#define GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE 4 |
||||
#define GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES 5 |
||||
#define GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE 6 |
||||
#define GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO 7 |
||||
#define GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO 8 |
||||
#define GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG 9 |
||||
#define GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS 10 |
||||
#define GRALLOC_MODULE_PERFORM_GET_IGC 11 |
||||
#define GRALLOC_MODULE_PERFORM_SET_IGC 12 |
||||
#define GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE 13 |
||||
|
||||
/* OEM specific HAL formats */ |
||||
|
||||
#define HAL_PIXEL_FORMAT_RGBA_5551 6 |
||||
#define HAL_PIXEL_FORMAT_RGBA_4444 7 |
||||
#define HAL_PIXEL_FORMAT_NV12_ENCODEABLE 0x102 |
||||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS 0x7FA30C04 |
||||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED 0x7FA30C03 |
||||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP 0x109 |
||||
#define HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO 0x7FA30C01 |
||||
#define HAL_PIXEL_FORMAT_YCrCb_422_SP 0x10B |
||||
#define HAL_PIXEL_FORMAT_R_8 0x10D |
||||
#define HAL_PIXEL_FORMAT_RG_88 0x10E |
||||
#define HAL_PIXEL_FORMAT_YCbCr_444_SP 0x10F |
||||
#define HAL_PIXEL_FORMAT_YCrCb_444_SP 0x110 |
||||
#define HAL_PIXEL_FORMAT_YCrCb_422_I 0x111 |
||||
#define HAL_PIXEL_FORMAT_BGRX_8888 0x112 |
||||
#define HAL_PIXEL_FORMAT_NV21_ZSL 0x113 |
||||
#define HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS 0x114 |
||||
#define HAL_PIXEL_FORMAT_BGR_565 0x115 |
||||
#define HAL_PIXEL_FORMAT_INTERLACE 0x180 |
||||
|
||||
//v4l2_fourcc('Y', 'U', 'Y', 'L'). 24 bpp YUYV 4:2:2 10 bit per component
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT 0x4C595559 |
||||
|
||||
//v4l2_fourcc('Y', 'B', 'W', 'C'). 10 bit per component. This compressed
|
||||
//format reduces the memory access bandwidth
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_422_I_10BIT_COMPRESSED 0x43574259 |
||||
|
||||
// UBWC aligned Venus format
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC 0x7FA30C06 |
||||
|
||||
//Khronos ASTC formats
|
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR 0x93D0 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR 0x93D1 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR 0x93D2 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR 0x93D3 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR 0x93D4 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR 0x93D5 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR 0x93D6 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR 0x93D7 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR 0x93D8 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR 0x93D9 |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR 0x93DA |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR 0x93DB |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR 0x93DC |
||||
#define HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR 0x93DD |
||||
|
||||
/* possible values for inverse gamma correction */ |
||||
#define HAL_IGC_NOT_SPECIFIED 0 |
||||
#define HAL_IGC_s_RGB 1 |
||||
|
||||
/* possible formats for 3D content*/ |
||||
enum { |
||||
HAL_NO_3D = 0x0, |
||||
HAL_3D_SIDE_BY_SIDE_L_R = 0x1, |
||||
HAL_3D_SIDE_BY_SIDE_R_L = 0x2, |
||||
HAL_3D_TOP_BOTTOM = 0x4, |
||||
HAL_3D_IN_SIDE_BY_SIDE_L_R = 0x10000, //unused legacy format
|
||||
}; |
||||
|
||||
enum { |
||||
BUFFER_TYPE_UI = 0, |
||||
BUFFER_TYPE_VIDEO |
||||
}; |
||||
|
||||
#ifdef __cplusplus |
||||
struct private_handle_t : public native_handle { |
||||
#else |
||||
struct private_handle_t { |
||||
native_handle_t nativeHandle; |
||||
#endif |
||||
enum { |
||||
PRIV_FLAGS_FRAMEBUFFER = 0x00000001, |
||||
PRIV_FLAGS_USES_ION = 0x00000008, |
||||
PRIV_FLAGS_USES_ASHMEM = 0x00000010, |
||||
PRIV_FLAGS_NEEDS_FLUSH = 0x00000020, |
||||
PRIV_FLAGS_INTERNAL_ONLY = 0x00000040, |
||||
PRIV_FLAGS_NON_CPU_WRITER = 0x00000080, |
||||
PRIV_FLAGS_NONCONTIGUOUS_MEM = 0x00000100, |
||||
PRIV_FLAGS_CACHED = 0x00000200, |
||||
PRIV_FLAGS_SECURE_BUFFER = 0x00000400, |
||||
// Display on external only
|
||||
PRIV_FLAGS_EXTERNAL_ONLY = 0x00002000, |
||||
// Set by HWC for protected non secure buffers
|
||||
PRIV_FLAGS_PROTECTED_BUFFER = 0x00004000, |
||||
PRIV_FLAGS_VIDEO_ENCODER = 0x00010000, |
||||
PRIV_FLAGS_CAMERA_WRITE = 0x00020000, |
||||
PRIV_FLAGS_CAMERA_READ = 0x00040000, |
||||
PRIV_FLAGS_HW_COMPOSER = 0x00080000, |
||||
PRIV_FLAGS_HW_TEXTURE = 0x00100000, |
||||
PRIV_FLAGS_ITU_R_601 = 0x00200000, //Unused from display
|
||||
PRIV_FLAGS_ITU_R_601_FR = 0x00400000, //Unused from display
|
||||
PRIV_FLAGS_ITU_R_709 = 0x00800000, //Unused from display
|
||||
PRIV_FLAGS_SECURE_DISPLAY = 0x01000000, |
||||
// Buffer is rendered in Tile Format
|
||||
PRIV_FLAGS_TILE_RENDERED = 0x02000000, |
||||
// Buffer rendered using CPU/SW renderer
|
||||
PRIV_FLAGS_CPU_RENDERED = 0x04000000, |
||||
// Buffer is allocated with UBWC alignment
|
||||
PRIV_FLAGS_UBWC_ALIGNED = 0x08000000, |
||||
// Buffer allocated will be consumed by SF/HWC
|
||||
PRIV_FLAGS_DISP_CONSUMER = 0x10000000 |
||||
}; |
||||
|
||||
// file-descriptors
|
||||
int fd; |
||||
int fd_metadata; // fd for the meta-data
|
||||
// ints
|
||||
int magic; |
||||
int flags; |
||||
unsigned int size; |
||||
unsigned int offset; |
||||
int bufferType; |
||||
uint64_t base __attribute__((aligned(8))); |
||||
unsigned int offset_metadata; |
||||
// The gpu address mapped into the mmu.
|
||||
uint64_t gpuaddr __attribute__((aligned(8))); |
||||
int format; |
||||
int width; // specifies aligned width
|
||||
int height; // specifies aligned height
|
||||
int real_width; |
||||
int real_height; |
||||
uint64_t base_metadata __attribute__((aligned(8))); |
||||
|
||||
#ifdef __cplusplus |
||||
static const int sNumFds = 2; |
||||
static inline int sNumInts() { |
||||
return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / |
||||
sizeof(int)) - sNumFds; |
||||
} |
||||
static const int sMagic = 'gmsm'; |
||||
|
||||
private_handle_t(int fd, unsigned int size, int flags, int bufferType, |
||||
int format, int aligned_width, int aligned_height, |
||||
int width, int height, int eFd = -1, |
||||
unsigned int eOffset = 0, uint64_t eBase = 0) : |
||||
fd(fd), fd_metadata(eFd), magic(sMagic), |
||||
flags(flags), size(size), offset(0), bufferType(bufferType), |
||||
base(0), offset_metadata(eOffset), gpuaddr(0), |
||||
format(format), width(aligned_width), height(aligned_height), |
||||
real_width(width), real_height(height), base_metadata(eBase) |
||||
{ |
||||
version = (int) sizeof(native_handle); |
||||
numInts = sNumInts(); |
||||
numFds = sNumFds; |
||||
} |
||||
~private_handle_t() { |
||||
magic = 0; |
||||
} |
||||
|
||||
static int validate(const native_handle* h) { |
||||
const private_handle_t* hnd = (const private_handle_t*)h; |
||||
if (!h || h->version != sizeof(native_handle) || |
||||
h->numInts != sNumInts() || h->numFds != sNumFds || |
||||
hnd->magic != sMagic) |
||||
{ |
||||
ALOGD("Invalid gralloc handle (at %p): " |
||||
"ver(%d/%zu) ints(%d/%d) fds(%d/%d)" |
||||
"magic(%c%c%c%c/%c%c%c%c)", |
||||
h, |
||||
h ? h->version : -1, sizeof(native_handle), |
||||
h ? h->numInts : -1, sNumInts(), |
||||
h ? h->numFds : -1, sNumFds, |
||||
hnd ? (((hnd->magic >> 24) & 0xFF)? |
||||
((hnd->magic >> 24) & 0xFF) : '-') : '?', |
||||
hnd ? (((hnd->magic >> 16) & 0xFF)? |
||||
((hnd->magic >> 16) & 0xFF) : '-') : '?', |
||||
hnd ? (((hnd->magic >> 8) & 0xFF)? |
||||
((hnd->magic >> 8) & 0xFF) : '-') : '?', |
||||
hnd ? (((hnd->magic >> 0) & 0xFF)? |
||||
((hnd->magic >> 0) & 0xFF) : '-') : '?', |
||||
(sMagic >> 24) & 0xFF, |
||||
(sMagic >> 16) & 0xFF, |
||||
(sMagic >> 8) & 0xFF, |
||||
(sMagic >> 0) & 0xFF); |
||||
return -EINVAL; |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static private_handle_t* dynamicCast(const native_handle* in) { |
||||
if (validate(in) == 0) { |
||||
return (private_handle_t*) in; |
||||
} |
||||
return NULL; |
||||
} |
||||
#endif |
||||
}; |
||||
|
||||
#endif /* GRALLOC_PRIV_H_ */ |
@ -0,0 +1,211 @@ |
||||
#ifndef _UAPI_MSM_ION_H |
||||
#define _UAPI_MSM_ION_H |
||||
|
||||
#include <linux/ion.h> |
||||
|
||||
enum msm_ion_heap_types { |
||||
ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1, |
||||
ION_HEAP_TYPE_SECURE_DMA = ION_HEAP_TYPE_MSM_START, |
||||
ION_HEAP_TYPE_SYSTEM_SECURE, |
||||
ION_HEAP_TYPE_HYP_CMA, |
||||
/*
|
||||
* if you add a heap type here you should also add it to |
||||
* heap_types_info[] in msm_ion.c |
||||
*/ |
||||
}; |
||||
|
||||
/**
|
||||
* These are the only ids that should be used for Ion heap ids. |
||||
* The ids listed are the order in which allocation will be attempted |
||||
* if specified. Don't swap the order of heap ids unless you know what |
||||
* you are doing! |
||||
* Id's are spaced by purpose to allow new Id's to be inserted in-between (for |
||||
* possible fallbacks) |
||||
*/ |
||||
|
||||
enum ion_heap_ids { |
||||
INVALID_HEAP_ID = -1, |
||||
ION_CP_MM_HEAP_ID = 8, |
||||
ION_SECURE_HEAP_ID = 9, |
||||
ION_SECURE_DISPLAY_HEAP_ID = 10, |
||||
ION_CP_MFC_HEAP_ID = 12, |
||||
ION_CP_WB_HEAP_ID = 16, /* 8660 only */ |
||||
ION_CAMERA_HEAP_ID = 20, /* 8660 only */ |
||||
ION_SYSTEM_CONTIG_HEAP_ID = 21, |
||||
ION_ADSP_HEAP_ID = 22, |
||||
ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */ |
||||
ION_SF_HEAP_ID = 24, |
||||
ION_SYSTEM_HEAP_ID = 25, |
||||
ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */ |
||||
ION_QSECOM_HEAP_ID = 27, |
||||
ION_AUDIO_HEAP_ID = 28, |
||||
|
||||
ION_MM_FIRMWARE_HEAP_ID = 29, |
||||
|
||||
ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */ |
||||
}; |
||||
|
||||
/*
|
||||
* The IOMMU heap is deprecated! Here are some aliases for backwards |
||||
* compatibility: |
||||
*/ |
||||
#define ION_IOMMU_HEAP_ID ION_SYSTEM_HEAP_ID |
||||
#define ION_HEAP_TYPE_IOMMU ION_HEAP_TYPE_SYSTEM |
||||
|
||||
enum ion_fixed_position { |
||||
NOT_FIXED, |
||||
FIXED_LOW, |
||||
FIXED_MIDDLE, |
||||
FIXED_HIGH, |
||||
}; |
||||
|
||||
enum cp_mem_usage { |
||||
VIDEO_BITSTREAM = 0x1, |
||||
VIDEO_PIXEL = 0x2, |
||||
VIDEO_NONPIXEL = 0x3, |
||||
DISPLAY_SECURE_CP_USAGE = 0x4, |
||||
CAMERA_SECURE_CP_USAGE = 0x5, |
||||
MAX_USAGE = 0x6, |
||||
UNKNOWN = 0x7FFFFFFF, |
||||
}; |
||||
|
||||
/**
|
||||
* Flags to be used when allocating from the secure heap for |
||||
* content protection |
||||
*/ |
||||
#define ION_FLAG_CP_TOUCH (1 << 17) |
||||
#define ION_FLAG_CP_BITSTREAM (1 << 18) |
||||
#define ION_FLAG_CP_PIXEL (1 << 19) |
||||
#define ION_FLAG_CP_NON_PIXEL (1 << 20) |
||||
#define ION_FLAG_CP_CAMERA (1 << 21) |
||||
#define ION_FLAG_CP_HLOS (1 << 22) |
||||
#define ION_FLAG_CP_HLOS_FREE (1 << 23) |
||||
#define ION_FLAG_CP_SEC_DISPLAY (1 << 25) |
||||
#define ION_FLAG_CP_APP (1 << 26) |
||||
|
||||
/**
|
||||
* Flag to allow non continguous allocation of memory from secure |
||||
* heap |
||||
*/ |
||||
#define ION_FLAG_ALLOW_NON_CONTIG (1 << 24) |
||||
|
||||
/**
|
||||
* Flag to use when allocating to indicate that a heap is secure. |
||||
*/ |
||||
#define ION_FLAG_SECURE (1 << ION_HEAP_ID_RESERVED) |
||||
|
||||
/**
|
||||
* Flag for clients to force contiguous memort allocation |
||||
* |
||||
* Use of this flag is carefully monitored! |
||||
*/ |
||||
#define ION_FLAG_FORCE_CONTIGUOUS (1 << 30) |
||||
|
||||
/*
|
||||
* Used in conjunction with heap which pool memory to force an allocation |
||||
* to come from the page allocator directly instead of from the pool allocation |
||||
*/ |
||||
#define ION_FLAG_POOL_FORCE_ALLOC (1 << 16) |
||||
|
||||
|
||||
#define ION_FLAG_POOL_PREFETCH (1 << 27) |
||||
|
||||
/**
|
||||
* Deprecated! Please use the corresponding ION_FLAG_* |
||||
*/ |
||||
#define ION_SECURE ION_FLAG_SECURE |
||||
#define ION_FORCE_CONTIGUOUS ION_FLAG_FORCE_CONTIGUOUS |
||||
|
||||
/**
|
||||
* Macro should be used with ion_heap_ids defined above. |
||||
*/ |
||||
#define ION_HEAP(bit) (1 << (bit)) |
||||
|
||||
#define ION_ADSP_HEAP_NAME "adsp" |
||||
#define ION_SYSTEM_HEAP_NAME "system" |
||||
#define ION_VMALLOC_HEAP_NAME ION_SYSTEM_HEAP_NAME |
||||
#define ION_KMALLOC_HEAP_NAME "kmalloc" |
||||
#define ION_AUDIO_HEAP_NAME "audio" |
||||
#define ION_SF_HEAP_NAME "sf" |
||||
#define ION_MM_HEAP_NAME "mm" |
||||
#define ION_CAMERA_HEAP_NAME "camera_preview" |
||||
#define ION_IOMMU_HEAP_NAME "iommu" |
||||
#define ION_MFC_HEAP_NAME "mfc" |
||||
#define ION_WB_HEAP_NAME "wb" |
||||
#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw" |
||||
#define ION_PIL1_HEAP_NAME "pil_1" |
||||
#define ION_PIL2_HEAP_NAME "pil_2" |
||||
#define ION_QSECOM_HEAP_NAME "qsecom" |
||||
#define ION_SECURE_HEAP_NAME "secure_heap" |
||||
#define ION_SECURE_DISPLAY_HEAP_NAME "secure_display" |
||||
|
||||
#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED) |
||||
#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED) |
||||
|
||||
#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED) |
||||
|
||||
/* struct ion_flush_data - data passed to ion for flushing caches
|
||||
* |
||||
* @handle: handle with data to flush |
||||
* @fd: fd to flush |
||||
* @vaddr: userspace virtual address mapped with mmap |
||||
* @offset: offset into the handle to flush |
||||
* @length: length of handle to flush |
||||
* |
||||
* Performs cache operations on the handle. If p is the start address |
||||
* of the handle, p + offset through p + offset + length will have |
||||
* the cache operations performed |
||||
*/ |
||||
struct ion_flush_data { |
||||
ion_user_handle_t handle; |
||||
int fd; |
||||
void *vaddr; |
||||
unsigned int offset; |
||||
unsigned int length; |
||||
}; |
||||
|
||||
struct ion_prefetch_regions { |
||||
unsigned int vmid; |
||||
size_t __user *sizes; |
||||
unsigned int nr_sizes; |
||||
}; |
||||
|
||||
struct ion_prefetch_data { |
||||
int heap_id; |
||||
unsigned long len; |
||||
/* Is unsigned long bad? 32bit compiler vs 64 bit compiler*/ |
||||
struct ion_prefetch_regions __user *regions; |
||||
unsigned int nr_regions; |
||||
}; |
||||
|
||||
#define ION_IOC_MSM_MAGIC 'M' |
||||
|
||||
/**
|
||||
* DOC: ION_IOC_CLEAN_CACHES - clean the caches |
||||
* |
||||
* Clean the caches of the handle specified. |
||||
*/ |
||||
#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \ |
||||
struct ion_flush_data) |
||||
/**
|
||||
* DOC: ION_IOC_INV_CACHES - invalidate the caches |
||||
* |
||||
* Invalidate the caches of the handle specified. |
||||
*/ |
||||
#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \ |
||||
struct ion_flush_data) |
||||
/**
|
||||
* DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches |
||||
* |
||||
* Clean and invalidate the caches of the handle specified. |
||||
*/ |
||||
#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \ |
||||
struct ion_flush_data) |
||||
|
||||
#define ION_IOC_PREFETCH _IOWR(ION_IOC_MSM_MAGIC, 3, \ |
||||
struct ion_prefetch_data) |
||||
|
||||
#define ION_IOC_DRAIN _IOWR(ION_IOC_MSM_MAGIC, 4, \ |
||||
struct ion_prefetch_data) |
||||
|
||||
#endif |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,131 @@ |
||||
/**********************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
**********************************************************************************/ |
||||
|
||||
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ |
||||
|
||||
#ifndef __OPENCL_CL_D3D10_H |
||||
#define __OPENCL_CL_D3D10_H |
||||
|
||||
#include <d3d10.h> |
||||
#include <CL/cl.h> |
||||
#include <CL/cl_platform.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/******************************************************************************
|
||||
* cl_khr_d3d10_sharing */ |
||||
#define cl_khr_d3d10_sharing 1 |
||||
|
||||
typedef cl_uint cl_d3d10_device_source_khr; |
||||
typedef cl_uint cl_d3d10_device_set_khr; |
||||
|
||||
/******************************************************************************/ |
||||
|
||||
/* Error Codes */ |
||||
#define CL_INVALID_D3D10_DEVICE_KHR -1002 |
||||
#define CL_INVALID_D3D10_RESOURCE_KHR -1003 |
||||
#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 |
||||
#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 |
||||
|
||||
/* cl_d3d10_device_source_nv */ |
||||
#define CL_D3D10_DEVICE_KHR 0x4010 |
||||
#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 |
||||
|
||||
/* cl_d3d10_device_set_nv */ |
||||
#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 |
||||
#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 |
||||
|
||||
/* cl_context_info */ |
||||
#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 |
||||
#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C |
||||
|
||||
/* cl_mem_info */ |
||||
#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 |
||||
|
||||
/* cl_image_info */ |
||||
#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 |
||||
|
||||
/* cl_command_type */ |
||||
#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 |
||||
#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 |
||||
|
||||
/******************************************************************************/ |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( |
||||
cl_platform_id platform, |
||||
cl_d3d10_device_source_khr d3d_device_source, |
||||
void * d3d_object, |
||||
cl_d3d10_device_set_khr d3d_device_set, |
||||
cl_uint num_entries, |
||||
cl_device_id * devices, |
||||
cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D10Buffer * resource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D10Texture2D * resource, |
||||
UINT subresource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D10Texture3D * resource, |
||||
UINT subresource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_D3D10_H */ |
||||
|
@ -0,0 +1,131 @@ |
||||
/**********************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
**********************************************************************************/ |
||||
|
||||
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ |
||||
|
||||
#ifndef __OPENCL_CL_D3D11_H |
||||
#define __OPENCL_CL_D3D11_H |
||||
|
||||
#include <d3d11.h> |
||||
#include <CL/cl.h> |
||||
#include <CL/cl_platform.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/******************************************************************************
|
||||
* cl_khr_d3d11_sharing */ |
||||
#define cl_khr_d3d11_sharing 1 |
||||
|
||||
typedef cl_uint cl_d3d11_device_source_khr; |
||||
typedef cl_uint cl_d3d11_device_set_khr; |
||||
|
||||
/******************************************************************************/ |
||||
|
||||
/* Error Codes */ |
||||
#define CL_INVALID_D3D11_DEVICE_KHR -1006 |
||||
#define CL_INVALID_D3D11_RESOURCE_KHR -1007 |
||||
#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 |
||||
#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 |
||||
|
||||
/* cl_d3d11_device_source */ |
||||
#define CL_D3D11_DEVICE_KHR 0x4019 |
||||
#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A |
||||
|
||||
/* cl_d3d11_device_set */ |
||||
#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B |
||||
#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C |
||||
|
||||
/* cl_context_info */ |
||||
#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D |
||||
#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D |
||||
|
||||
/* cl_mem_info */ |
||||
#define CL_MEM_D3D11_RESOURCE_KHR 0x401E |
||||
|
||||
/* cl_image_info */ |
||||
#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F |
||||
|
||||
/* cl_command_type */ |
||||
#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 |
||||
#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 |
||||
|
||||
/******************************************************************************/ |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( |
||||
cl_platform_id platform, |
||||
cl_d3d11_device_source_khr d3d_device_source, |
||||
void * d3d_object, |
||||
cl_d3d11_device_set_khr d3d_device_set, |
||||
cl_uint num_entries, |
||||
cl_device_id * devices, |
||||
cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D11Buffer * resource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D11Texture2D * resource, |
||||
UINT subresource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
ID3D11Texture3D * resource, |
||||
UINT subresource, |
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_D3D11_H */ |
||||
|
@ -0,0 +1,132 @@ |
||||
/**********************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
**********************************************************************************/ |
||||
|
||||
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ |
||||
|
||||
#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H |
||||
#define __OPENCL_CL_DX9_MEDIA_SHARING_H |
||||
|
||||
#include <CL/cl.h> |
||||
#include <CL/cl_platform.h> |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/******************************************************************************/ |
||||
/* cl_khr_dx9_media_sharing */ |
||||
#define cl_khr_dx9_media_sharing 1 |
||||
|
||||
typedef cl_uint cl_dx9_media_adapter_type_khr; |
||||
typedef cl_uint cl_dx9_media_adapter_set_khr; |
||||
|
||||
#if defined(_WIN32) |
||||
#include <d3d9.h> |
||||
typedef struct _cl_dx9_surface_info_khr |
||||
{ |
||||
IDirect3DSurface9 *resource; |
||||
HANDLE shared_handle; |
||||
} cl_dx9_surface_info_khr; |
||||
#endif |
||||
|
||||
|
||||
/******************************************************************************/ |
||||
|
||||
/* Error Codes */ |
||||
#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 |
||||
#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 |
||||
#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 |
||||
#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 |
||||
|
||||
/* cl_media_adapter_type_khr */ |
||||
#define CL_ADAPTER_D3D9_KHR 0x2020 |
||||
#define CL_ADAPTER_D3D9EX_KHR 0x2021 |
||||
#define CL_ADAPTER_DXVA_KHR 0x2022 |
||||
|
||||
/* cl_media_adapter_set_khr */ |
||||
#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 |
||||
#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 |
||||
|
||||
/* cl_context_info */ |
||||
#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 |
||||
#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 |
||||
#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 |
||||
|
||||
/* cl_mem_info */ |
||||
#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 |
||||
#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 |
||||
|
||||
/* cl_image_info */ |
||||
#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A |
||||
|
||||
/* cl_command_type */ |
||||
#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B |
||||
#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C |
||||
|
||||
/******************************************************************************/ |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( |
||||
cl_platform_id platform, |
||||
cl_uint num_media_adapters, |
||||
cl_dx9_media_adapter_type_khr * media_adapter_type, |
||||
void * media_adapters, |
||||
cl_dx9_media_adapter_set_khr media_adapter_set, |
||||
cl_uint num_entries, |
||||
cl_device_id * devices, |
||||
cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( |
||||
cl_context context, |
||||
cl_mem_flags flags, |
||||
cl_dx9_media_adapter_type_khr adapter_type, |
||||
void * surface_info, |
||||
cl_uint plane,
|
||||
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ |
||||
|
@ -0,0 +1,136 @@ |
||||
/*******************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
******************************************************************************/ |
||||
|
||||
#ifndef __OPENCL_CL_EGL_H |
||||
#define __OPENCL_CL_EGL_H |
||||
|
||||
#ifdef __APPLE__ |
||||
|
||||
#else |
||||
#include <CL/cl.h> |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
|
||||
/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ |
||||
#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F |
||||
#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D |
||||
#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E |
||||
|
||||
/* Error type for clCreateFromEGLImageKHR */ |
||||
#define CL_INVALID_EGL_OBJECT_KHR -1093 |
||||
#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 |
||||
|
||||
/* CLeglImageKHR is an opaque handle to an EGLImage */ |
||||
typedef void* CLeglImageKHR; |
||||
|
||||
/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ |
||||
typedef void* CLeglDisplayKHR; |
||||
|
||||
/* CLeglSyncKHR is an opaque handle to an EGLSync object */ |
||||
typedef void* CLeglSyncKHR; |
||||
|
||||
/* properties passed to clCreateFromEGLImageKHR */ |
||||
typedef intptr_t cl_egl_image_properties_khr; |
||||
|
||||
|
||||
#define cl_khr_egl_image 1 |
||||
|
||||
extern CL_API_ENTRY cl_mem CL_API_CALL |
||||
clCreateFromEGLImageKHR(cl_context /* context */, |
||||
CLeglDisplayKHR /* egldisplay */, |
||||
CLeglImageKHR /* eglimage */, |
||||
cl_mem_flags /* flags */, |
||||
const cl_egl_image_properties_khr * /* properties */, |
||||
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( |
||||
cl_context context, |
||||
CLeglDisplayKHR egldisplay, |
||||
CLeglImageKHR eglimage, |
||||
cl_mem_flags flags, |
||||
const cl_egl_image_properties_khr * properties, |
||||
cl_int * errcode_ret); |
||||
|
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, |
||||
cl_uint /* num_objects */, |
||||
const cl_mem * /* mem_objects */, |
||||
cl_uint /* num_events_in_wait_list */, |
||||
const cl_event * /* event_wait_list */, |
||||
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event); |
||||
|
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, |
||||
cl_uint /* num_objects */, |
||||
const cl_mem * /* mem_objects */, |
||||
cl_uint /* num_events_in_wait_list */, |
||||
const cl_event * /* event_wait_list */, |
||||
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( |
||||
cl_command_queue command_queue, |
||||
cl_uint num_objects, |
||||
const cl_mem * mem_objects, |
||||
cl_uint num_events_in_wait_list, |
||||
const cl_event * event_wait_list, |
||||
cl_event * event); |
||||
|
||||
|
||||
#define cl_khr_egl_event 1 |
||||
|
||||
extern CL_API_ENTRY cl_event CL_API_CALL |
||||
clCreateEventFromEGLSyncKHR(cl_context /* context */, |
||||
CLeglSyncKHR /* sync */, |
||||
CLeglDisplayKHR /* display */, |
||||
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( |
||||
cl_context context, |
||||
CLeglSyncKHR sync, |
||||
CLeglDisplayKHR display, |
||||
cl_int * errcode_ret); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_EGL_H */ |
@ -0,0 +1,391 @@ |
||||
/*******************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
******************************************************************************/ |
||||
|
||||
/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ |
||||
|
||||
/* cl_ext.h contains OpenCL extensions which don't have external */ |
||||
/* (OpenGL, D3D) dependencies. */ |
||||
|
||||
#ifndef __CL_EXT_H |
||||
#define __CL_EXT_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifdef __APPLE__ |
||||
#include <OpenCL/cl.h> |
||||
#include <AvailabilityMacros.h> |
||||
#else |
||||
#include <CL/cl.h> |
||||
#endif |
||||
|
||||
/* cl_khr_fp16 extension - no extension #define since it has no functions */ |
||||
#define CL_DEVICE_HALF_FP_CONFIG 0x1033 |
||||
|
||||
/* Memory object destruction
|
||||
* |
||||
* Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR |
||||
* |
||||
* Registers a user callback function that will be called when the memory object is deleted and its resources
|
||||
* freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback
|
||||
* stack associated with memobj. The registered user callback functions are called in the reverse order in
|
||||
* which they were registered. The user callback functions are called and then the memory object is deleted
|
||||
* and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be
|
||||
* notified when the memory referenced by host_ptr, specified when the memory object is created and used as
|
||||
* the storage bits for the memory object, can be reused or freed. |
||||
* |
||||
* The application may not call CL api's with the cl_mem object passed to the pfn_notify. |
||||
* |
||||
* Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) |
||||
* before using. |
||||
*/ |
||||
#define cl_APPLE_SetMemObjectDestructor 1 |
||||
cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */,
|
||||
void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/),
|
||||
void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0;
|
||||
|
||||
|
||||
/* Context Logging Functions
|
||||
* |
||||
* The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). |
||||
* Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) |
||||
* before using. |
||||
* |
||||
* clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger
|
||||
*/ |
||||
#define cl_APPLE_ContextLoggingFunctions 1 |
||||
extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */,
|
||||
const void * /* private_info */,
|
||||
size_t /* cb */,
|
||||
void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; |
||||
|
||||
/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ |
||||
extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */,
|
||||
const void * /* private_info */,
|
||||
size_t /* cb */,
|
||||
void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; |
||||
|
||||
/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ |
||||
extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */,
|
||||
const void * /* private_info */,
|
||||
size_t /* cb */,
|
||||
void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; |
||||
|
||||
|
||||
/************************
|
||||
* cl_khr_icd extension *
|
||||
************************/ |
||||
#define cl_khr_icd 1 |
||||
|
||||
/* cl_platform_info */ |
||||
#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 |
||||
|
||||
/* Additional Error Codes */ |
||||
#define CL_PLATFORM_NOT_FOUND_KHR -1001 |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, |
||||
cl_platform_id * /* platforms */, |
||||
cl_uint * /* num_platforms */); |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( |
||||
cl_uint /* num_entries */, |
||||
cl_platform_id * /* platforms */, |
||||
cl_uint * /* num_platforms */); |
||||
|
||||
|
||||
/* Extension: cl_khr_image2D_buffer
|
||||
* |
||||
* This extension allows a 2D image to be created from a cl_mem buffer without a copy. |
||||
* The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. |
||||
* Both the sampler and sampler-less read_image built-in functions are supported for 2D images |
||||
* and 2D images created from a buffer. Similarly, the write_image built-ins are also supported |
||||
* for 2D images created from a buffer. |
||||
* |
||||
* When the 2D image from buffer is created, the client must specify the width, |
||||
* height, image format (i.e. channel order and channel data type) and optionally the row pitch |
||||
* |
||||
* The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. |
||||
* The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. |
||||
*/ |
||||
|
||||
/*************************************
|
||||
* cl_khr_initalize_memory extension * |
||||
*************************************/ |
||||
|
||||
#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x2030 |
||||
|
||||
|
||||
/**************************************
|
||||
* cl_khr_terminate_context extension * |
||||
**************************************/ |
||||
|
||||
#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x2031 |
||||
#define CL_CONTEXT_TERMINATE_KHR 0x2032 |
||||
|
||||
#define cl_khr_terminate_context 1 |
||||
extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; |
||||
|
||||
|
||||
/*
|
||||
* Extension: cl_khr_spir |
||||
* |
||||
* This extension adds support to create an OpenCL program object from a
|
||||
* Standard Portable Intermediate Representation (SPIR) instance |
||||
*/ |
||||
|
||||
#define CL_DEVICE_SPIR_VERSIONS 0x40E0 |
||||
#define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 |
||||
|
||||
|
||||
/******************************************
|
||||
* cl_nv_device_attribute_query extension * |
||||
******************************************/ |
||||
/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ |
||||
#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 |
||||
#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 |
||||
#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 |
||||
#define CL_DEVICE_WARP_SIZE_NV 0x4003 |
||||
#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 |
||||
#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 |
||||
#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 |
||||
|
||||
/*********************************
|
||||
* cl_amd_device_attribute_query * |
||||
*********************************/ |
||||
#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 |
||||
|
||||
/*********************************
|
||||
* cl_arm_printf extension |
||||
*********************************/ |
||||
#define CL_PRINTF_CALLBACK_ARM 0x40B0 |
||||
#define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 |
||||
|
||||
#ifdef CL_VERSION_1_1 |
||||
/***********************************
|
||||
* cl_ext_device_fission extension * |
||||
***********************************/ |
||||
#define cl_ext_device_fission 1 |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
|
||||
|
||||
typedef CL_API_ENTRY cl_int
|
||||
(CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
|
||||
|
||||
typedef CL_API_ENTRY cl_int
|
||||
(CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; |
||||
|
||||
typedef cl_ulong cl_device_partition_property_ext; |
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clCreateSubDevicesEXT( cl_device_id /*in_device*/, |
||||
const cl_device_partition_property_ext * /* properties */, |
||||
cl_uint /*num_entries*/, |
||||
cl_device_id * /*out_devices*/, |
||||
cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; |
||||
|
||||
typedef CL_API_ENTRY cl_int
|
||||
( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, |
||||
const cl_device_partition_property_ext * /* properties */, |
||||
cl_uint /*num_entries*/, |
||||
cl_device_id * /*out_devices*/, |
||||
cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; |
||||
|
||||
/* cl_device_partition_property_ext */ |
||||
#define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 |
||||
#define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 |
||||
#define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 |
||||
#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 |
||||
|
||||
/* clDeviceGetInfo selectors */ |
||||
#define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 |
||||
#define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 |
||||
#define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 |
||||
#define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 |
||||
#define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 |
||||
|
||||
/* error codes */ |
||||
#define CL_DEVICE_PARTITION_FAILED_EXT -1057 |
||||
#define CL_INVALID_PARTITION_COUNT_EXT -1058 |
||||
#define CL_INVALID_PARTITION_NAME_EXT -1059 |
||||
|
||||
/* CL_AFFINITY_DOMAINs */ |
||||
#define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 |
||||
#define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 |
||||
#define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 |
||||
#define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 |
||||
#define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 |
||||
#define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 |
||||
|
||||
/* cl_device_partition_property_ext list terminators */ |
||||
#define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) |
||||
#define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) |
||||
#define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) |
||||
|
||||
/*********************************
|
||||
* cl_qcom_ext_host_ptr extension |
||||
*********************************/ |
||||
|
||||
#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) |
||||
|
||||
#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 |
||||
#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 |
||||
#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 |
||||
#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 |
||||
#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 |
||||
#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 |
||||
#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 |
||||
#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 |
||||
|
||||
typedef cl_uint cl_image_pitch_info_qcom; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clGetDeviceImageInfoQCOM(cl_device_id device, |
||||
size_t image_width, |
||||
size_t image_height, |
||||
const cl_image_format *image_format, |
||||
cl_image_pitch_info_qcom param_name, |
||||
size_t param_value_size, |
||||
void *param_value, |
||||
size_t *param_value_size_ret); |
||||
|
||||
typedef struct _cl_mem_ext_host_ptr |
||||
{ |
||||
/* Type of external memory allocation. */ |
||||
/* Legal values will be defined in layered extensions. */ |
||||
cl_uint allocation_type; |
||||
|
||||
/* Host cache policy for this external memory allocation. */ |
||||
cl_uint host_cache_policy; |
||||
|
||||
} cl_mem_ext_host_ptr; |
||||
|
||||
/*********************************
|
||||
* cl_qcom_ion_host_ptr extension |
||||
*********************************/ |
||||
|
||||
#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 |
||||
|
||||
typedef struct _cl_mem_ion_host_ptr |
||||
{ |
||||
/* Type of external memory allocation. */ |
||||
/* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ |
||||
cl_mem_ext_host_ptr ext_host_ptr; |
||||
|
||||
/* ION file descriptor */ |
||||
int ion_filedesc; |
||||
|
||||
/* Host pointer to the ION allocated memory */ |
||||
void* ion_hostptr; |
||||
|
||||
} cl_mem_ion_host_ptr; |
||||
|
||||
#endif /* CL_VERSION_1_1 */ |
||||
|
||||
|
||||
#ifdef CL_VERSION_2_0 |
||||
/*********************************
|
||||
* cl_khr_sub_groups extension |
||||
*********************************/ |
||||
#define cl_khr_sub_groups 1 |
||||
|
||||
typedef cl_uint cl_kernel_sub_group_info_khr; |
||||
|
||||
/* cl_khr_sub_group_info */ |
||||
#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033 |
||||
#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034 |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */, |
||||
cl_device_id /*in_device*/, |
||||
cl_kernel_sub_group_info_khr /* param_name */, |
||||
size_t /*input_value_size*/, |
||||
const void * /*input_value*/, |
||||
size_t /*param_value_size*/, |
||||
void* /*param_value*/, |
||||
size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; |
||||
|
||||
typedef CL_API_ENTRY cl_int |
||||
( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */, |
||||
cl_device_id /*in_device*/, |
||||
cl_kernel_sub_group_info_khr /* param_name */, |
||||
size_t /*input_value_size*/, |
||||
const void * /*input_value*/, |
||||
size_t /*param_value_size*/, |
||||
void* /*param_value*/, |
||||
size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0_DEPRECATED; |
||||
#endif /* CL_VERSION_2_0 */ |
||||
|
||||
#ifdef CL_VERSION_2_1 |
||||
/*********************************
|
||||
* cl_khr_priority_hints extension |
||||
*********************************/ |
||||
#define cl_khr_priority_hints 1 |
||||
|
||||
typedef cl_uint cl_queue_priority_khr; |
||||
|
||||
/* cl_command_queue_properties */ |
||||
#define CL_QUEUE_PRIORITY_KHR 0x1096 |
||||
|
||||
/* cl_queue_priority_khr */ |
||||
#define CL_QUEUE_PRIORITY_HIGH_KHR (1<<0) |
||||
#define CL_QUEUE_PRIORITY_MED_KHR (1<<1) |
||||
#define CL_QUEUE_PRIORITY_LOW_KHR (1<<2) |
||||
|
||||
#endif /* CL_VERSION_2_1 */ |
||||
|
||||
#ifdef CL_VERSION_2_1 |
||||
/*********************************
|
||||
* cl_khr_throttle_hints extension |
||||
*********************************/ |
||||
#define cl_khr_throttle_hints 1 |
||||
|
||||
typedef cl_uint cl_queue_throttle_khr; |
||||
|
||||
/* cl_command_queue_properties */ |
||||
#define CL_QUEUE_THROTTLE_KHR 0x1097 |
||||
|
||||
/* cl_queue_throttle_khr */ |
||||
#define CL_QUEUE_THROTTLE_HIGH_KHR (1<<0) |
||||
#define CL_QUEUE_THROTTLE_MED_KHR (1<<1) |
||||
#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) |
||||
|
||||
#endif /* CL_VERSION_2_1 */ |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
|
||||
#endif /* __CL_EXT_H */ |
@ -0,0 +1,167 @@ |
||||
/**********************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
**********************************************************************************/ |
||||
|
||||
#ifndef __OPENCL_CL_GL_H |
||||
#define __OPENCL_CL_GL_H |
||||
|
||||
#ifdef __APPLE__ |
||||
#include <OpenCL/cl.h> |
||||
#else |
||||
#include <CL/cl.h> |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef cl_uint cl_gl_object_type; |
||||
typedef cl_uint cl_gl_texture_info; |
||||
typedef cl_uint cl_gl_platform_info; |
||||
typedef struct __GLsync *cl_GLsync; |
||||
|
||||
/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ |
||||
#define CL_GL_OBJECT_BUFFER 0x2000 |
||||
#define CL_GL_OBJECT_TEXTURE2D 0x2001 |
||||
#define CL_GL_OBJECT_TEXTURE3D 0x2002 |
||||
#define CL_GL_OBJECT_RENDERBUFFER 0x2003 |
||||
#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E |
||||
#define CL_GL_OBJECT_TEXTURE1D 0x200F |
||||
#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 |
||||
#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 |
||||
|
||||
/* cl_gl_texture_info */ |
||||
#define CL_GL_TEXTURE_TARGET 0x2004 |
||||
#define CL_GL_MIPMAP_LEVEL 0x2005 |
||||
#define CL_GL_NUM_SAMPLES 0x2012 |
||||
|
||||
|
||||
extern CL_API_ENTRY cl_mem CL_API_CALL |
||||
clCreateFromGLBuffer(cl_context /* context */, |
||||
cl_mem_flags /* flags */, |
||||
cl_GLuint /* bufobj */, |
||||
int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
extern CL_API_ENTRY cl_mem CL_API_CALL |
||||
clCreateFromGLTexture(cl_context /* context */, |
||||
cl_mem_flags /* flags */, |
||||
cl_GLenum /* target */, |
||||
cl_GLint /* miplevel */, |
||||
cl_GLuint /* texture */, |
||||
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; |
||||
|
||||
extern CL_API_ENTRY cl_mem CL_API_CALL |
||||
clCreateFromGLRenderbuffer(cl_context /* context */, |
||||
cl_mem_flags /* flags */, |
||||
cl_GLuint /* renderbuffer */, |
||||
cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clGetGLObjectInfo(cl_mem /* memobj */, |
||||
cl_gl_object_type * /* gl_object_type */, |
||||
cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clGetGLTextureInfo(cl_mem /* memobj */, |
||||
cl_gl_texture_info /* param_name */, |
||||
size_t /* param_value_size */, |
||||
void * /* param_value */, |
||||
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, |
||||
cl_uint /* num_objects */, |
||||
const cl_mem * /* mem_objects */, |
||||
cl_uint /* num_events_in_wait_list */, |
||||
const cl_event * /* event_wait_list */, |
||||
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, |
||||
cl_uint /* num_objects */, |
||||
const cl_mem * /* mem_objects */, |
||||
cl_uint /* num_events_in_wait_list */, |
||||
const cl_event * /* event_wait_list */, |
||||
cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
|
||||
/* Deprecated OpenCL 1.1 APIs */ |
||||
extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL |
||||
clCreateFromGLTexture2D(cl_context /* context */, |
||||
cl_mem_flags /* flags */, |
||||
cl_GLenum /* target */, |
||||
cl_GLint /* miplevel */, |
||||
cl_GLuint /* texture */, |
||||
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; |
||||
|
||||
extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL |
||||
clCreateFromGLTexture3D(cl_context /* context */, |
||||
cl_mem_flags /* flags */, |
||||
cl_GLenum /* target */, |
||||
cl_GLint /* miplevel */, |
||||
cl_GLuint /* texture */, |
||||
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; |
||||
|
||||
/* cl_khr_gl_sharing extension */ |
||||
|
||||
#define cl_khr_gl_sharing 1 |
||||
|
||||
typedef cl_uint cl_gl_context_info; |
||||
|
||||
/* Additional Error Codes */ |
||||
#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 |
||||
|
||||
/* cl_gl_context_info */ |
||||
#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 |
||||
#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 |
||||
|
||||
/* Additional cl_context_properties */ |
||||
#define CL_GL_CONTEXT_KHR 0x2008 |
||||
#define CL_EGL_DISPLAY_KHR 0x2009 |
||||
#define CL_GLX_DISPLAY_KHR 0x200A |
||||
#define CL_WGL_HDC_KHR 0x200B |
||||
#define CL_CGL_SHAREGROUP_KHR 0x200C |
||||
|
||||
extern CL_API_ENTRY cl_int CL_API_CALL |
||||
clGetGLContextInfoKHR(const cl_context_properties * /* properties */, |
||||
cl_gl_context_info /* param_name */, |
||||
size_t /* param_value_size */, |
||||
void * /* param_value */, |
||||
size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; |
||||
|
||||
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( |
||||
const cl_context_properties * properties, |
||||
cl_gl_context_info param_name, |
||||
size_t param_value_size, |
||||
void * param_value, |
||||
size_t * param_value_size_ret); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_GL_H */ |
@ -0,0 +1,74 @@ |
||||
/**********************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
**********************************************************************************/ |
||||
|
||||
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ |
||||
|
||||
/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ |
||||
/* OpenGL dependencies. */ |
||||
|
||||
#ifndef __OPENCL_CL_GL_EXT_H |
||||
#define __OPENCL_CL_GL_EXT_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifdef __APPLE__ |
||||
#include <OpenCL/cl_gl.h> |
||||
#else |
||||
#include <CL/cl_gl.h> |
||||
#endif |
||||
|
||||
/*
|
||||
* For each extension, follow this template |
||||
* cl_VEN_extname extension */ |
||||
/* #define cl_VEN_extname 1
|
||||
* ... define new types, if any |
||||
* ... define new tokens, if any |
||||
* ... define new APIs, if any |
||||
* |
||||
* If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header |
||||
* This allows us to avoid having to decide whether to include GL headers or GLES here. |
||||
*/ |
||||
|
||||
/*
|
||||
* cl_khr_gl_event extension |
||||
* See section 9.9 in the OpenCL 1.1 spec for more information |
||||
*/ |
||||
#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D |
||||
|
||||
extern CL_API_ENTRY cl_event CL_API_CALL |
||||
clCreateEventFromGLsyncKHR(cl_context /* context */, |
||||
cl_GLsync /* cl_GLsync */, |
||||
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_CL_GL_EXT_H */ |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,59 @@ |
||||
/*******************************************************************************
|
||||
* Copyright (c) 2008-2015 The Khronos Group Inc. |
||||
* |
||||
* Permission is hereby granted, free of charge, to any person obtaining a |
||||
* copy of this software and/or associated documentation files (the |
||||
* "Materials"), to deal in the Materials without restriction, including |
||||
* without limitation the rights to use, copy, modify, merge, publish, |
||||
* distribute, sublicense, and/or sell copies of the Materials, and to |
||||
* permit persons to whom the Materials are furnished to do so, subject to |
||||
* the following conditions: |
||||
* |
||||
* The above copyright notice and this permission notice shall be included |
||||
* in all copies or substantial portions of the Materials. |
||||
* |
||||
* MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS |
||||
* KHRONOS STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS |
||||
* SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT |
||||
* https://www.khronos.org/registry/
|
||||
* |
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
||||
******************************************************************************/ |
||||
|
||||
/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ |
||||
|
||||
#ifndef __OPENCL_H |
||||
#define __OPENCL_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifdef __APPLE__ |
||||
|
||||
#include <OpenCL/cl.h> |
||||
#include <OpenCL/cl_gl.h> |
||||
#include <OpenCL/cl_gl_ext.h> |
||||
#include <OpenCL/cl_ext.h> |
||||
|
||||
#else |
||||
|
||||
#include <CL/cl.h> |
||||
#include <CL/cl_gl.h> |
||||
#include <CL/cl_gl_ext.h> |
||||
#include <CL/cl_ext.h> |
||||
|
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* __OPENCL_H */ |
||||
|
@ -1 +1 @@ |
||||
#define COMMA_VERSION "0.4.7.2-release" |
||||
#define COMMA_VERSION "0.5-release" |
||||
|
@ -0,0 +1,39 @@ |
||||
#ifndef IONBUF_H |
||||
#define IONBUF_H |
||||
|
||||
#ifdef __APPLE__ |
||||
#include <OpenCL/cl.h> |
||||
#else |
||||
#include <CL/cl.h> |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
typedef struct VisionBuf { |
||||
size_t len; |
||||
void* addr; |
||||
int handle; |
||||
int fd; |
||||
|
||||
cl_context ctx; |
||||
cl_device_id device_id; |
||||
cl_mem buf_cl; |
||||
cl_command_queue copy_q; |
||||
} VisionBuf; |
||||
|
||||
#define VISIONBUF_SYNC_FROM_DEVICE 0 |
||||
#define VISIONBUF_SYNC_TO_DEVICE 1 |
||||
|
||||
VisionBuf visionbuf_allocate(size_t len); |
||||
VisionBuf visionbuf_allocate_cl(size_t len, cl_device_id device_id, cl_context ctx, cl_mem *out_mem); |
||||
cl_mem visionbuf_to_cl(const VisionBuf* buf, cl_device_id device_id, cl_context ctx); |
||||
void visionbuf_sync(const VisionBuf* buf, int dir); |
||||
void visionbuf_free(const VisionBuf* buf); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,141 @@ |
||||
#include <stdlib.h> |
||||
#include <stdio.h> |
||||
#include <assert.h> |
||||
#include <sys/mman.h> |
||||
#include <sys/ioctl.h> |
||||
|
||||
#include <linux/ion.h> |
||||
#include <CL/cl_ext.h> |
||||
|
||||
#include <msm_ion.h> |
||||
|
||||
#include "visionbuf.h" |
||||
|
||||
|
||||
// just hard-code these for convenience
|
||||
// size_t device_page_size = 0;
|
||||
// clGetDeviceInfo(device_id, CL_DEVICE_PAGE_SIZE_QCOM,
|
||||
// sizeof(device_page_size), &device_page_size,
|
||||
// NULL);
|
||||
|
||||
// size_t padding_cl = 0;
|
||||
// clGetDeviceInfo(device_id, CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM,
|
||||
// sizeof(padding_cl), &padding_cl,
|
||||
// NULL);
|
||||
#define DEVICE_PAGE_SIZE_CL 4096 |
||||
#define PADDING_CL 0 |
||||
|
||||
static int ion_fd = -1; |
||||
static void ion_init() { |
||||
if (ion_fd == -1) { |
||||
ion_fd = open("/dev/ion", O_RDWR | O_NONBLOCK); |
||||
} |
||||
} |
||||
|
||||
VisionBuf visionbuf_allocate(size_t len) { |
||||
int err; |
||||
|
||||
ion_init(); |
||||
|
||||
struct ion_allocation_data ion_alloc = {0}; |
||||
ion_alloc.len = len + PADDING_CL; |
||||
ion_alloc.align = 4096; |
||||
ion_alloc.heap_id_mask = 1 << ION_IOMMU_HEAP_ID; |
||||
ion_alloc.flags = ION_FLAG_CACHED; |
||||
|
||||
err = ioctl(ion_fd, ION_IOC_ALLOC, &ion_alloc); |
||||
assert(err == 0); |
||||
|
||||
struct ion_fd_data ion_fd_data = {0}; |
||||
ion_fd_data.handle = ion_alloc.handle; |
||||
err = ioctl(ion_fd, ION_IOC_SHARE, &ion_fd_data); |
||||
assert(err == 0); |
||||
|
||||
void *addr = mmap(NULL, ion_alloc.len, |
||||
PROT_READ | PROT_WRITE, |
||||
MAP_SHARED, ion_fd_data.fd, 0); |
||||
assert(addr != MAP_FAILED); |
||||
|
||||
memset(addr, 0, ion_alloc.len); |
||||
|
||||
return (VisionBuf){ |
||||
.len = len, |
||||
.addr = addr, |
||||
.handle = ion_alloc.handle, |
||||
.fd = ion_fd_data.fd, |
||||
}; |
||||
} |
||||
|
||||
VisionBuf visionbuf_allocate_cl(size_t len, cl_device_id device_id, cl_context ctx, cl_mem *out_mem) { |
||||
VisionBuf r = visionbuf_allocate(len); |
||||
*out_mem = visionbuf_to_cl(&r, device_id, ctx); |
||||
return r; |
||||
} |
||||
|
||||
cl_mem visionbuf_to_cl(const VisionBuf* buf, cl_device_id device_id, cl_context ctx) { |
||||
int err = 0; |
||||
|
||||
assert(((uintptr_t)buf->addr % DEVICE_PAGE_SIZE_CL) == 0); |
||||
|
||||
cl_mem_ion_host_ptr ion_cl = {0}; |
||||
ion_cl.ext_host_ptr.allocation_type = CL_MEM_ION_HOST_PTR_QCOM; |
||||
ion_cl.ext_host_ptr.host_cache_policy = CL_MEM_HOST_UNCACHED_QCOM; |
||||
ion_cl.ion_filedesc = buf->fd; |
||||
ion_cl.ion_hostptr = buf->addr; |
||||
|
||||
cl_mem mem = clCreateBuffer(ctx, |
||||
CL_MEM_USE_HOST_PTR | CL_MEM_EXT_HOST_PTR_QCOM, |
||||
buf->len, &ion_cl, &err); |
||||
assert(err == 0); |
||||
|
||||
return mem; |
||||
} |
||||
|
||||
void visionbuf_sync(const VisionBuf* buf, int dir) { |
||||
int err; |
||||
|
||||
struct ion_fd_data fd_data = {0}; |
||||
fd_data.fd = buf->fd; |
||||
err = ioctl(ion_fd, ION_IOC_IMPORT, &fd_data); |
||||
assert(err == 0); |
||||
|
||||
struct ion_flush_data flush_data = {0}; |
||||
flush_data.handle = fd_data.handle; |
||||
flush_data.vaddr = buf->addr; |
||||
flush_data.offset = 0; |
||||
flush_data.length = buf->len; |
||||
|
||||
// ION_IOC_INV_CACHES ~= DMA_FROM_DEVICE
|
||||
// ION_IOC_CLEAN_CACHES ~= DMA_TO_DEVICE
|
||||
// ION_IOC_CLEAN_INV_CACHES ~= DMA_BIDIRECTIONAL
|
||||
|
||||
struct ion_custom_data custom_data = {0}; |
||||
|
||||
switch (dir) { |
||||
case VISIONBUF_SYNC_FROM_DEVICE: |
||||
custom_data.cmd = ION_IOC_INV_CACHES; |
||||
break; |
||||
case VISIONBUF_SYNC_TO_DEVICE: |
||||
custom_data.cmd = ION_IOC_CLEAN_CACHES; |
||||
break; |
||||
default: |
||||
assert(0); |
||||
} |
||||
|
||||
custom_data.arg = (unsigned long)&flush_data; |
||||
err = ioctl(ion_fd, ION_IOC_CUSTOM, &custom_data); |
||||
assert(err == 0); |
||||
|
||||
struct ion_handle_data handle_data = {0}; |
||||
handle_data.handle = fd_data.handle; |
||||
err = ioctl(ion_fd, ION_IOC_FREE, &handle_data); |
||||
assert(err == 0); |
||||
} |
||||
|
||||
void visionbuf_free(const VisionBuf* buf) { |
||||
struct ion_handle_data handle_data = { |
||||
.handle = buf->handle, |
||||
}; |
||||
int ret = ioctl(ion_fd, ION_IOC_FREE, &handle_data); |
||||
assert(ret == 0); |
||||
} |
@ -0,0 +1,111 @@ |
||||
#include <cassert> |
||||
|
||||
#ifdef QCOM |
||||
#include <system/graphics.h> |
||||
#include <ui/GraphicBuffer.h> |
||||
#include <ui/PixelFormat.h> |
||||
#include <gralloc_priv.h> |
||||
|
||||
#include <GLES3/gl3.h> |
||||
#define GL_GLEXT_PROTOTYPES |
||||
#include <GLES2/gl2ext.h> |
||||
|
||||
#include <EGL/egl.h> |
||||
#define EGL_EGLEXT_PROTOTYPES |
||||
#include <EGL/eglext.h> |
||||
|
||||
#endif |
||||
|
||||
#include "common/util.h" |
||||
#include "common/visionbuf.h" |
||||
|
||||
#include "common/visionimg.h" |
||||
|
||||
#ifdef QCOM |
||||
|
||||
using namespace android; |
||||
|
||||
// from libadreno_utils.so
|
||||
extern "C" void compute_aligned_width_and_height(int width, |
||||
int height, |
||||
int bpp, |
||||
int tile_mode, |
||||
int raster_mode, |
||||
int padding_threshold, |
||||
int *aligned_w, |
||||
int *aligned_h); |
||||
#endif |
||||
|
||||
VisionImg visionimg_alloc_rgb24(int width, int height, VisionBuf *out_buf) { |
||||
|
||||
int aligned_w = 0, aligned_h = 0; |
||||
#ifdef QCOM |
||||
compute_aligned_width_and_height(ALIGN(width, 32), ALIGN(height, 32), 3, 0, 0, 512, &aligned_w, &aligned_h); |
||||
#else |
||||
aligned_w = width; aligned_h = height; |
||||
#endif |
||||
|
||||
int stride = aligned_w * 3; |
||||
size_t size = aligned_w * aligned_h * 3; |
||||
|
||||
VisionBuf buf = visionbuf_allocate(size); |
||||
|
||||
*out_buf = buf; |
||||
|
||||
return (VisionImg){ |
||||
.fd = buf.fd, |
||||
.format = VISIONIMG_FORMAT_RGB24, |
||||
.width = width, |
||||
.height = height, |
||||
.stride = stride, |
||||
.size = size, |
||||
.bpp = 3, |
||||
}; |
||||
} |
||||
|
||||
#ifdef QCOM |
||||
|
||||
EGLClientBuffer visionimg_to_egl(const VisionImg *img) { |
||||
assert((img->size % img->stride) == 0); |
||||
assert((img->stride % img->bpp) == 0); |
||||
|
||||
int format = 0; |
||||
if (img->format == VISIONIMG_FORMAT_RGB24) { |
||||
format = HAL_PIXEL_FORMAT_RGB_888; |
||||
} else { |
||||
assert(false); |
||||
} |
||||
|
||||
private_handle_t* hnd = new private_handle_t(img->fd, img->size, |
||||
private_handle_t::PRIV_FLAGS_USES_ION|private_handle_t::PRIV_FLAGS_FRAMEBUFFER, |
||||
0, format, |
||||
img->stride/img->bpp, img->size/img->stride, |
||||
img->width, img->height); |
||||
|
||||
GraphicBuffer* gb = new GraphicBuffer(img->width, img->height, (PixelFormat)format, |
||||
GraphicBuffer::USAGE_HW_TEXTURE, img->stride/img->bpp, hnd, false); |
||||
|
||||
return (EGLClientBuffer) gb->getNativeBuffer(); |
||||
} |
||||
|
||||
GLuint visionimg_to_gl(const VisionImg *img) { |
||||
|
||||
EGLClientBuffer buf = visionimg_to_egl(img); |
||||
|
||||
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
||||
assert(display != EGL_NO_DISPLAY); |
||||
|
||||
EGLint img_attrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE }; |
||||
EGLImageKHR image = eglCreateImageKHR(display, EGL_NO_CONTEXT, |
||||
EGL_NATIVE_BUFFER_ANDROID, buf, img_attrs); |
||||
assert(image != EGL_NO_IMAGE_KHR); |
||||
|
||||
GLuint tex = 0; |
||||
glGenTextures(1, &tex); |
||||
glBindTexture(GL_TEXTURE_2D, tex); |
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image); |
||||
|
||||
return tex; |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,37 @@ |
||||
#ifndef VISIONIMG_H |
||||
#define VISIONIMG_H |
||||
|
||||
#ifdef QCOM |
||||
#include <GLES3/gl3.h> |
||||
#include <EGL/egl.h> |
||||
#include <EGL/eglext.h> |
||||
#endif |
||||
|
||||
#include "common/visionbuf.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#define VISIONIMG_FORMAT_RGB24 1 |
||||
|
||||
typedef struct VisionImg { |
||||
int fd; |
||||
int format; |
||||
int width, height, stride; |
||||
int bpp; |
||||
size_t size; |
||||
} VisionImg; |
||||
|
||||
VisionImg visionimg_alloc_rgb24(int width, int height, VisionBuf *out_buf); |
||||
|
||||
#ifdef QCOM |
||||
EGLClientBuffer visionimg_to_egl(const VisionImg *img); |
||||
GLuint visionimg_to_gl(const VisionImg *img); |
||||
#endif |
||||
|
||||
#ifdef __cplusplus |
||||
} // extern "C"
|
||||
#endif |
||||
|
||||
#endif |
@ -0,0 +1,121 @@ |
||||
import numpy as np |
||||
from common.realtime import sec_since_boot |
||||
from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET |
||||
|
||||
_DT = 0.01 # update runs at 100Hz |
||||
_AWARENESS_TIME = 180 # 3 minutes limit without user touching steering wheels make the car enter a terminal status |
||||
_AWARENESS_PRE_TIME = 20. # a first alert is issued 20s before expiration |
||||
_AWARENESS_PROMPT_TIME = 5. # a second alert is issued 5s before start decelerating the car |
||||
_DISTRACTED_TIME = 6. |
||||
_DISTRACTED_PRE_TIME = 4. |
||||
_DISTRACTED_PROMPT_TIME = 2. |
||||
# measured 1 rad in x FOV. 1152x864 is original image, 160x320 is a right crop for model |
||||
_CAMERA_FOV_X = 1. # rad |
||||
_CAMERA_FOV_Y = 0.75 # 4/3 aspect ratio |
||||
# model output refers to center of cropped image, so need to apply the x displacement offset |
||||
_CAMERA_OFFSET_X = 0.3125 #(1152/2 - 0.5*(160*864/320))/1152 |
||||
_CAMERA_X_CONV = 0.375 # 160*864/320/1152 |
||||
_PITCH_WEIGHT = 1.5 # pitch matters a lot more |
||||
_METRIC_THRESHOLD = 0.4 |
||||
_PITCH_POS_ALLOWANCE = 0.08 # rad, to not be too sensitive on positive pitch |
||||
_DTM = 0.2 # driver monitor runs at 5Hz |
||||
_DISTRACTED_FILTER_F = 0.3 # 0.3Hz |
||||
_DISTRACTED_FILTER_K = 2 * np.pi * _DISTRACTED_FILTER_F * _DTM / (1 + 2 * np.pi * _DISTRACTED_FILTER_F * _DTM) |
||||
_PITCH_NATURAL_OFFSET = 0.1 # people don't seem to look straight when they drive relaxed, rather a bit up |
||||
|
||||
|
||||
class _DriverPose(): |
||||
def __init__(self): |
||||
self.yaw = 0. |
||||
self.pitch = 0. |
||||
self.roll = 0. |
||||
self.yaw_offset = 0. |
||||
self.pitch_offset = 0. |
||||
|
||||
class DriverStatus(): |
||||
def __init__(self, monitor_on): |
||||
self.pose = _DriverPose() |
||||
self.monitor_on = monitor_on |
||||
self.awareness = 1. |
||||
self.driver_distracted = False |
||||
self.driver_distraction_level = 0. |
||||
self.ts_last_check = 0. |
||||
self._set_timers() |
||||
|
||||
def _set_timers(self): |
||||
if self.monitor_on: |
||||
self.threshold_pre = _DISTRACTED_PRE_TIME / _DISTRACTED_TIME |
||||
self.threshold_prompt = _DISTRACTED_PROMPT_TIME / _DISTRACTED_TIME |
||||
self.step_change = _DT / _DISTRACTED_TIME |
||||
else: |
||||
self.threshold_pre = _AWARENESS_PRE_TIME / _AWARENESS_TIME |
||||
self.threshold_prompt = _AWARENESS_PROMPT_TIME / _AWARENESS_TIME |
||||
self.step_change = _DT / _AWARENESS_TIME |
||||
|
||||
def _is_driver_distracted(self, pose): |
||||
# to be tuned and to learn the driver's normal pose |
||||
yaw_error = pose.yaw - pose.yaw_offset |
||||
pitch_error = pose.pitch - pose.pitch_offset - _PITCH_NATURAL_OFFSET |
||||
# add positive pitch allowance |
||||
if pitch_error > 0.: |
||||
pitch_error = max(pitch_error - _PITCH_POS_ALLOWANCE, 0.) |
||||
pitch_error *= _PITCH_WEIGHT |
||||
metric = np.sqrt(yaw_error**2 + pitch_error**2) |
||||
#print "%02.4f" % np.degrees(pose.pitch), "%02.4f" % np.degrees(pitch_error), "%03.4f" % np.degrees(pose.pitch_offset), metric |
||||
return 1 if metric > _METRIC_THRESHOLD else 0 |
||||
|
||||
def get_pose(self, driver_monitoring, params): |
||||
ts = sec_since_boot() |
||||
|
||||
# don's check for param too often as it's a kernel call |
||||
if ts - self.ts_last_check > 1.: |
||||
self.monitor_on = params.get("IsDriverMonitoringEnabled") == "1" |
||||
self._set_timers() |
||||
self.ts_last_check = ts |
||||
|
||||
self.pose.pitch = driver_monitoring.descriptor[0] |
||||
self.pose.yaw = driver_monitoring.descriptor[1] |
||||
self.pose.roll = driver_monitoring.descriptor[2] |
||||
self.pose.yaw_offset = (driver_monitoring.descriptor[3] * _CAMERA_X_CONV + _CAMERA_OFFSET_X) * _CAMERA_FOV_X |
||||
self.pose.pitch_offset = -driver_monitoring.descriptor[4] * _CAMERA_FOV_Y # positive y is down |
||||
self.driver_distracted = self._is_driver_distracted(self.pose) |
||||
# first order filter |
||||
self.driver_distraction_level = (1. - _DISTRACTED_FILTER_K) * self.driver_distraction_level + \ |
||||
_DISTRACTED_FILTER_K * self.driver_distracted |
||||
|
||||
def update(self, events, driver_engaged, ctrl_active, standstill): |
||||
|
||||
driver_engaged |= (self.driver_distraction_level < 0.37 and self.monitor_on) |
||||
|
||||
if (driver_engaged and self.awareness > 0.) or not ctrl_active: |
||||
# always reset if driver is in control (unless we are in red alert state) or op isn't active |
||||
self.awareness = 1. |
||||
|
||||
if (not self.monitor_on or (self.driver_distraction_level > 0.63 and self.driver_distracted)) and \ |
||||
not (standstill and self.awareness - self.step_change <= self.threshold_prompt): |
||||
self.awareness = max(self.awareness - self.step_change, -0.1) |
||||
|
||||
if self.awareness <= 0.: |
||||
# terminal red alert: disengagement required |
||||
events.append(create_event('driverDistracted', [ET.WARNING])) |
||||
elif self.awareness <= self.threshold_prompt: |
||||
# prompt orange alert |
||||
events.append(create_event('promptDriverDistracted', [ET.WARNING])) |
||||
elif self.awareness <= self.threshold_pre: |
||||
# pre green alert |
||||
events.append(create_event('preDriverDistracted', [ET.WARNING])) |
||||
|
||||
return events |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
ds = DriverStatus(True) |
||||
ds.driver_distraction_level = 1. |
||||
ds.driver_distracted = 1 |
||||
for i in range(1000): |
||||
ds.update([], False, True, True) |
||||
print(ds.awareness, ds.driver_distracted, ds.driver_distraction_level) |
||||
ds.update([], True, True, False) |
||||
print(ds.awareness, ds.driver_distracted, ds.driver_distraction_level) |
||||
|
||||
|
@ -1,73 +0,0 @@ |
||||
#!/usr/bin/env python |
||||
import zmq |
||||
from copy import copy |
||||
from selfdrive import messaging |
||||
from selfdrive.services import service_list |
||||
from cereal import log |
||||
|
||||
from common.transformations.coordinates import geodetic2ecef |
||||
|
||||
def main(gctx=None): |
||||
context = zmq.Context() |
||||
poller = zmq.Poller() |
||||
gps_sock = messaging.sub_sock(context, service_list['gpsLocation'].port, poller) |
||||
gps_ext_sock = messaging.sub_sock(context, service_list['gpsLocationExternal'].port, poller) |
||||
app_sock = messaging.sub_sock(context, service_list['applanixLocation'].port, poller) |
||||
loc_sock = messaging.pub_sock(context, service_list['liveLocation'].port) |
||||
|
||||
last_ext, last_gps, last_app = -1, -1, -1 |
||||
# 5 sec |
||||
max_gap = 5*1e9 |
||||
preferred_type = None |
||||
|
||||
while 1: |
||||
for sock, event in poller.poll(500): |
||||
if sock is app_sock: |
||||
msg = messaging.recv_one(sock) |
||||
last_app = msg.logMonoTime |
||||
this_type = 'app' |
||||
if sock is gps_sock: |
||||
msg = messaging.recv_one(sock) |
||||
gps_pkt = msg.gpsLocation |
||||
last_gps = msg.logMonoTime |
||||
this_type = 'gps' |
||||
if sock is gps_ext_sock: |
||||
msg = messaging.recv_one(sock) |
||||
gps_pkt = msg.gpsLocationExternal |
||||
last_ext = msg.logMonoTime |
||||
this_type = 'ext' |
||||
|
||||
last = max(last_gps, last_ext, last_app) |
||||
|
||||
if last_app > last - max_gap: |
||||
new_preferred_type = 'app' |
||||
elif last_ext > last - max_gap: |
||||
new_preferred_type = 'ext' |
||||
else: |
||||
new_preferred_type = 'gps' |
||||
|
||||
if preferred_type != new_preferred_type: |
||||
print "switching from %s to %s" % (preferred_type, new_preferred_type) |
||||
preferred_type = new_preferred_type |
||||
|
||||
if this_type == preferred_type: |
||||
new_msg = messaging.new_message() |
||||
if this_type == 'app': |
||||
# straight proxy the applanix |
||||
new_msg.init('liveLocation') |
||||
new_msg.liveLocation = copy(msg.applanixLocation) |
||||
else: |
||||
new_msg.logMonoTime = msg.logMonoTime |
||||
new_msg.init('liveLocation') |
||||
pkt = new_msg.liveLocation |
||||
pkt.lat = gps_pkt.latitude |
||||
pkt.lon = gps_pkt.longitude |
||||
pkt.alt = gps_pkt.altitude |
||||
pkt.speed = gps_pkt.speed |
||||
pkt.heading = gps_pkt.bearing |
||||
pkt.positionECEF = [float(x) for x in geodetic2ecef([pkt.lat, pkt.lon, pkt.alt])] |
||||
pkt.source = log.LiveLocationData.SensorSource.dummy |
||||
loc_sock.send(new_msg.to_bytes()) |
||||
|
||||
if __name__ == '__main__': |
||||
main() |
Binary file not shown.
@ -1,8 +0,0 @@ |
||||
orbd |
||||
orbd_cpu |
||||
test/turbocv_profile |
||||
test/turbocv_test |
||||
dspout/* |
||||
dumb_test |
||||
bilinear_lut.h |
||||
orb_lut.h |
@ -1,105 +0,0 @@ |
||||
# CPU
|
||||
|
||||
CC = clang
|
||||
CXX = clang++
|
||||
|
||||
WARN_FLAGS = -Werror=implicit-function-declaration \
|
||||
-Werror=incompatible-pointer-types \
|
||||
-Werror=int-conversion \
|
||||
-Werror=return-type \
|
||||
-Werror=format-extra-args
|
||||
|
||||
JSON_FLAGS = -I$(PHONELIBS)/json/src
|
||||
|
||||
CFLAGS = -std=gnu11 -g -O2 -fPIC $(WARN_FLAGS) -Iinclude $(JSON_FLAGS) -I.
|
||||
CXXFLAGS = -std=c++11 -g -O2 -fPIC $(WARN_FLAGS) -Iinclude $(JSON_FLAGS) -I.
|
||||
LDFLAGS =
|
||||
|
||||
# profile
|
||||
# CXXFLAGS += -DTURBOCV_PROFILE=1
|
||||
|
||||
PHONELIBS = ../../phonelibs
|
||||
BASEDIR = ../..
|
||||
EXTERNAL = ../../external
|
||||
PYTHONLIBS =
|
||||
|
||||
UNAME_M := $(shell uname -m)
|
||||
|
||||
ifeq ($(UNAME_M),x86_64) |
||||
# computer
|
||||
|
||||
ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include
|
||||
ZMQ_LIBS = -L$(BASEDIR)/external/zmq/lib/ \
|
||||
-l:libczmq.a -l:libzmq.a -lpthread
|
||||
|
||||
OPENCV_LIBS = -lopencv_core -lopencv_highgui -lopencv_features2d -lopencv_imgproc
|
||||
|
||||
CXXFLAGS += -fopenmp
|
||||
LDFLAGS += -lomp
|
||||
|
||||
else |
||||
# phone
|
||||
ZMQ_FLAGS = -I$(PHONELIBS)/zmq/aarch64/include
|
||||
ZMQ_LIBS = -L$(PHONELIBS)/zmq/aarch64/lib \
|
||||
-l:libczmq.a -l:libzmq.a \
|
||||
-lgnustl_shared
|
||||
|
||||
OPENCV_FLAGS = -I$(PHONELIBS)/opencv/include
|
||||
OPENCV_LIBS = -Wl,--enable-new-dtags -Wl,-rpath,/usr/local/lib/python2.7/site-packages -L/usr/local/lib/python2.7/site-packages -l:cv2.so
|
||||
|
||||
endif |
||||
|
||||
.PHONY: all |
||||
all: orbd |
||||
|
||||
include ../common/cereal.mk |
||||
|
||||
DEP_OBJS = ../common/visionipc.o ../common/swaglog.o $(PHONELIBS)/json/src/json.o
|
||||
|
||||
orbd: orbd_dsp.o $(DEP_OBJS) calculator_stub.o freethedsp.o |
||||
@echo "[ LINK ] $@"
|
||||
$(CXX) -fPIC -o '$@' $^ \
|
||||
$(LDFLAGS) \
|
||||
$(ZMQ_LIBS) \
|
||||
$(CEREAL_LIBS) \
|
||||
-L/usr/lib \
|
||||
-L/system/vendor/lib64 \
|
||||
-ladsprpc \
|
||||
-lm -lz -llog
|
||||
|
||||
%.o: %.c |
||||
@echo "[ CC ] $@"
|
||||
$(CC) $(CFLAGS) \
|
||||
$(ZMQ_FLAGS) \
|
||||
-I../ \
|
||||
-I../../ \
|
||||
-c -o '$@' '$<'
|
||||
|
||||
orbd_dsp.o: orbd.cc |
||||
@echo "[ CXX ] $@"
|
||||
$(CXX) $(CXXFLAGS) \
|
||||
$(CEREAL_CXXFLAGS) \
|
||||
$(ZMQ_FLAGS) \
|
||||
$(OPENCV_FLAGS) \
|
||||
-DDSP \
|
||||
-I../ \
|
||||
-I../../ \
|
||||
-I../../../ \
|
||||
-I./include \
|
||||
-c -o '$@' '$<'
|
||||
|
||||
freethedsp.o: dsp/freethedsp.c |
||||
@echo "[ CC ] $@"
|
||||
$(CC) $(CFLAGS) \
|
||||
-c -o '$@' '$<'
|
||||
|
||||
calculator_stub.o: dsp/gen/calculator_stub.c |
||||
@echo "[ CC ] $@"
|
||||
$(CC) $(CFLAGS) -I./include -c -o '$@' '$<'
|
||||
|
||||
-include internal.mk |
||||
|
||||
.PHONY: clean |
||||
clean: |
||||
rm -f *.o turbocv.so orbd test/turbocv_profile test/turbocv_test test/*.o *_lut.h
|
||||
|
@ -1,119 +0,0 @@ |
||||
// freethedsp by geohot
|
||||
// (because the DSP should be free)
|
||||
// released under MIT License
|
||||
|
||||
// usage instructions:
|
||||
// 1. Compile an example from the Qualcomm Hexagon SDK
|
||||
// 2. Try to run it on your phone
|
||||
// 3. Be very sad when "adsprpc ... dlopen error: ... signature verify start failed for ..." appears in logcat
|
||||
// ...here is where people would give up before freethedsp
|
||||
// 4. Compile freethedsp with 'clang -shared freethedsp.c -o freethedsp.so' (or statically link it to your program)
|
||||
// 5. Run your program with 'LD_PRELOAD=./freethedsp.so ./<your_prog>'
|
||||
// 6. OMG THE DSP WORKS
|
||||
// 7. Be happy.
|
||||
|
||||
// *** patch may have to change for your phone ***
|
||||
|
||||
// this is patching /dsp/fastrpc_shell_0
|
||||
// correct if sha hash of fastrpc_shell_0 is "fbadc96848aefad99a95aa4edb560929dcdf78f8"
|
||||
// patch to return 0xFFFFFFFF from is_test_enabled instead of 0
|
||||
// your fastrpc_shell_0 may vary
|
||||
#define PATCH_ADDR 0x5200c |
||||
#define PATCH_OLD "\x40\x3f\x20\x50" |
||||
#define PATCH_NEW "\x40\x3f\x00\x5a" |
||||
#define PATCH_LEN (sizeof(PATCH_OLD)-1) |
||||
#define _BITS_IOCTL_H_ |
||||
|
||||
// under 100 lines of code begins now
|
||||
#include <stdio.h> |
||||
#include <dlfcn.h> |
||||
#include <assert.h> |
||||
#include <stdlib.h> |
||||
#include <unistd.h> |
||||
|
||||
// ioctl stuff
|
||||
#define IOC_OUT 0x40000000 /* copy out parameters */ |
||||
#define IOC_IN 0x80000000 /* copy in parameters */ |
||||
#define IOC_INOUT (IOC_IN|IOC_OUT) |
||||
#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */ |
||||
|
||||
#define _IOC(inout,group,num,len) \ |
||||
(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)) |
||||
#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t)) |
||||
|
||||
// ion ioctls
|
||||
#include <linux/ion.h> |
||||
#define ION_IOC_MSM_MAGIC 'M' |
||||
#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \ |
||||
struct ion_flush_data) |
||||
|
||||
struct ion_flush_data { |
||||
ion_user_handle_t handle; |
||||
int fd; |
||||
void *vaddr; |
||||
unsigned int offset; |
||||
unsigned int length; |
||||
}; |
||||
|
||||
// fastrpc ioctls
|
||||
#define FASTRPC_IOCTL_INIT _IOWR('R', 6, struct fastrpc_ioctl_init) |
||||
|
||||
struct fastrpc_ioctl_init { |
||||
uint32_t flags; /* one of FASTRPC_INIT_* macros */ |
||||
uintptr_t __user file; /* pointer to elf file */ |
||||
int32_t filelen; /* elf file length */ |
||||
int32_t filefd; /* ION fd for the file */ |
||||
uintptr_t __user mem; /* mem for the PD */ |
||||
int32_t memlen; /* mem length */ |
||||
int32_t memfd; /* ION fd for the mem */ |
||||
}; |
||||
|
||||
int ioctl(int fd, unsigned long request, void *arg) { |
||||
static void *handle = NULL; |
||||
static int (*orig_ioctl)(int, int, void*); |
||||
|
||||
if (handle == NULL) { |
||||
handle = dlopen("/system/lib64/libc.so", RTLD_LAZY); |
||||
assert(handle != NULL); |
||||
orig_ioctl = dlsym(handle, "ioctl"); |
||||
} |
||||
|
||||
int ret = orig_ioctl(fd, request, arg); |
||||
|
||||
// carefully modify this one
|
||||
if (request == FASTRPC_IOCTL_INIT) { |
||||
struct fastrpc_ioctl_init *init = (struct fastrpc_ioctl_init *)arg; |
||||
|
||||
// confirm patch is correct and do the patch
|
||||
assert(memcmp((void*)(init->mem+PATCH_ADDR), PATCH_OLD, PATCH_LEN) == 0); |
||||
memcpy((void*)(init->mem+PATCH_ADDR), PATCH_NEW, PATCH_LEN); |
||||
|
||||
// flush cache
|
||||
int ionfd = open("/dev/ion", O_RDONLY); |
||||
assert(ionfd > 0); |
||||
|
||||
struct ion_fd_data fd_data; |
||||
fd_data.fd = init->memfd; |
||||
int ret = ioctl(ionfd, ION_IOC_IMPORT, &fd_data); |
||||
assert(ret == 0); |
||||
|
||||
struct ion_flush_data flush_data; |
||||
flush_data.handle = fd_data.handle; |
||||
flush_data.vaddr = (void*)init->mem; |
||||
flush_data.offset = 0; |
||||
flush_data.length = init->memlen; |
||||
ret = ioctl(ionfd, ION_IOC_CLEAN_INV_CACHES, &flush_data); |
||||
assert(ret == 0); |
||||
|
||||
struct ion_handle_data handle_data; |
||||
handle_data.handle = fd_data.handle; |
||||
ret = ioctl(ionfd, ION_IOC_FREE, &handle_data); |
||||
assert(ret == 0); |
||||
|
||||
// cleanup
|
||||
close(ionfd); |
||||
} |
||||
|
||||
return ret; |
||||
} |
||||
|
@ -1,39 +0,0 @@ |
||||
#ifndef _CALCULATOR_H |
||||
#define _CALCULATOR_H |
||||
|
||||
#include <stdint.h> |
||||
typedef uint8_t uint8; |
||||
typedef uint32_t uint32; |
||||
|
||||
#ifndef __QAIC_HEADER |
||||
#define __QAIC_HEADER(ff) ff |
||||
#endif //__QAIC_HEADER
|
||||
|
||||
#ifndef __QAIC_HEADER_EXPORT |
||||
#define __QAIC_HEADER_EXPORT |
||||
#endif // __QAIC_HEADER_EXPORT
|
||||
|
||||
#ifndef __QAIC_HEADER_ATTRIBUTE |
||||
#define __QAIC_HEADER_ATTRIBUTE |
||||
#endif // __QAIC_HEADER_ATTRIBUTE
|
||||
|
||||
#ifndef __QAIC_IMPL |
||||
#define __QAIC_IMPL(ff) ff |
||||
#endif //__QAIC_IMPL
|
||||
|
||||
#ifndef __QAIC_IMPL_EXPORT |
||||
#define __QAIC_IMPL_EXPORT |
||||
#endif // __QAIC_IMPL_EXPORT
|
||||
|
||||
#ifndef __QAIC_IMPL_ATTRIBUTE |
||||
#define __QAIC_IMPL_ATTRIBUTE |
||||
#endif // __QAIC_IMPL_ATTRIBUTE
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
__QAIC_HEADER_EXPORT int __QAIC_HEADER(calculator_init)(uint32* leet) __QAIC_HEADER_ATTRIBUTE; |
||||
__QAIC_HEADER_EXPORT int __QAIC_HEADER(calculator_extract_and_match)(const uint8* img, int imgLen, uint8* features, int featuresLen) __QAIC_HEADER_ATTRIBUTE; |
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif //_CALCULATOR_H
|
@ -1,613 +0,0 @@ |
||||
#ifndef _CALCULATOR_STUB_H |
||||
#define _CALCULATOR_STUB_H |
||||
#include "calculator.h" |
||||
|
||||
// remote.h
|
||||
#include <stdint.h> |
||||
#include <sys/types.h> |
||||
|
||||
typedef uint32_t remote_handle; |
||||
typedef uint64_t remote_handle64; |
||||
|
||||
typedef struct { |
||||
void *pv; |
||||
size_t nLen; |
||||
} remote_buf; |
||||
|
||||
typedef struct { |
||||
int32_t fd; |
||||
uint32_t offset; |
||||
} remote_dma_handle; |
||||
|
||||
typedef union { |
||||
remote_buf buf; |
||||
remote_handle h; |
||||
remote_handle64 h64; |
||||
remote_dma_handle dma; |
||||
} remote_arg; |
||||
|
||||
int remote_handle_open(const char* name, remote_handle *ph); |
||||
int remote_handle_invoke(remote_handle h, uint32_t dwScalars, remote_arg *pra); |
||||
int remote_handle_close(remote_handle h); |
||||
|
||||
#define REMOTE_SCALARS_MAKEX(nAttr,nMethod,nIn,nOut,noIn,noOut) \ |
||||
((((uint32_t) (nAttr) & 0x7) << 29) | \
|
||||
(((uint32_t) (nMethod) & 0x1f) << 24) | \
|
||||
(((uint32_t) (nIn) & 0xff) << 16) | \
|
||||
(((uint32_t) (nOut) & 0xff) << 8) | \
|
||||
(((uint32_t) (noIn) & 0x0f) << 4) | \
|
||||
((uint32_t) (noOut) & 0x0f)) |
||||
|
||||
#ifndef _QAIC_ENV_H |
||||
#define _QAIC_ENV_H |
||||
|
||||
#ifdef __GNUC__ |
||||
#ifdef __clang__ |
||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas" |
||||
#else |
||||
#pragma GCC diagnostic ignored "-Wpragmas" |
||||
#endif |
||||
#pragma GCC diagnostic ignored "-Wuninitialized" |
||||
#pragma GCC diagnostic ignored "-Wunused-parameter" |
||||
#pragma GCC diagnostic ignored "-Wunused-function" |
||||
#endif |
||||
|
||||
#ifndef _ATTRIBUTE_UNUSED |
||||
|
||||
#ifdef _WIN32 |
||||
#define _ATTRIBUTE_UNUSED |
||||
#else |
||||
#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) |
||||
#endif |
||||
|
||||
#endif // _ATTRIBUTE_UNUSED
|
||||
|
||||
#ifndef __QAIC_REMOTE |
||||
#define __QAIC_REMOTE(ff) ff |
||||
#endif //__QAIC_REMOTE
|
||||
|
||||
#ifndef __QAIC_HEADER |
||||
#define __QAIC_HEADER(ff) ff |
||||
#endif //__QAIC_HEADER
|
||||
|
||||
#ifndef __QAIC_HEADER_EXPORT |
||||
#define __QAIC_HEADER_EXPORT |
||||
#endif // __QAIC_HEADER_EXPORT
|
||||
|
||||
#ifndef __QAIC_HEADER_ATTRIBUTE |
||||
#define __QAIC_HEADER_ATTRIBUTE |
||||
#endif // __QAIC_HEADER_ATTRIBUTE
|
||||
|
||||
#ifndef __QAIC_IMPL |
||||
#define __QAIC_IMPL(ff) ff |
||||
#endif //__QAIC_IMPL
|
||||
|
||||
#ifndef __QAIC_IMPL_EXPORT |
||||
#define __QAIC_IMPL_EXPORT |
||||
#endif // __QAIC_IMPL_EXPORT
|
||||
|
||||
#ifndef __QAIC_IMPL_ATTRIBUTE |
||||
#define __QAIC_IMPL_ATTRIBUTE |
||||
#endif // __QAIC_IMPL_ATTRIBUTE
|
||||
|
||||
#ifndef __QAIC_STUB |
||||
#define __QAIC_STUB(ff) ff |
||||
#endif //__QAIC_STUB
|
||||
|
||||
#ifndef __QAIC_STUB_EXPORT |
||||
#define __QAIC_STUB_EXPORT |
||||
#endif // __QAIC_STUB_EXPORT
|
||||
|
||||
#ifndef __QAIC_STUB_ATTRIBUTE |
||||
#define __QAIC_STUB_ATTRIBUTE |
||||
#endif // __QAIC_STUB_ATTRIBUTE
|
||||
|
||||
#ifndef __QAIC_SKEL |
||||
#define __QAIC_SKEL(ff) ff |
||||
#endif //__QAIC_SKEL__
|
||||
|
||||
#ifndef __QAIC_SKEL_EXPORT |
||||
#define __QAIC_SKEL_EXPORT |
||||
#endif // __QAIC_SKEL_EXPORT
|
||||
|
||||
#ifndef __QAIC_SKEL_ATTRIBUTE |
||||
#define __QAIC_SKEL_ATTRIBUTE |
||||
#endif // __QAIC_SKEL_ATTRIBUTE
|
||||
|
||||
#ifdef __QAIC_DEBUG__ |
||||
#ifndef __QAIC_DBG_PRINTF__ |
||||
#include <stdio.h> |
||||
#define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) |
||||
#endif |
||||
#else |
||||
#define __QAIC_DBG_PRINTF__( ee ) (void)0 |
||||
#endif |
||||
|
||||
|
||||
#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) |
||||
|
||||
#define _COPY(dst, dof, src, sof, sz) \ |
||||
do {\
|
||||
struct __copy { \
|
||||
char ar[sz]; \
|
||||
};\
|
||||
*(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\
|
||||
} while (0) |
||||
|
||||
#define _COPYIF(dst, dof, src, sof, sz) \ |
||||
do {\
|
||||
if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\
|
||||
_COPY(dst, dof, src, sof, sz); \
|
||||
} \
|
||||
} while (0) |
||||
|
||||
_ATTRIBUTE_UNUSED |
||||
static __inline void _qaic_memmove(void* dst, void* src, int size) { |
||||
int i; |
||||
for(i = 0; i < size; ++i) { |
||||
((char*)dst)[i] = ((char*)src)[i]; |
||||
} |
||||
} |
||||
|
||||
#define _MEMMOVEIF(dst, src, sz) \ |
||||
do {\
|
||||
if(dst != src) {\
|
||||
_qaic_memmove(dst, src, sz);\
|
||||
} \
|
||||
} while (0) |
||||
|
||||
|
||||
#define _ASSIGN(dst, src, sof) \ |
||||
do {\
|
||||
dst = OFFSET(src, sof); \
|
||||
} while (0) |
||||
|
||||
#define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) |
||||
|
||||
#define AEE_SUCCESS 0 |
||||
#define AEE_EOFFSET 0x80000400 |
||||
#define AEE_EBADPARM (AEE_EOFFSET + 0x00E) |
||||
|
||||
#define _TRY(ee, func) \ |
||||
do { \
|
||||
if (AEE_SUCCESS != ((ee) = func)) {\
|
||||
__QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\
|
||||
goto ee##bail;\
|
||||
} \
|
||||
} while (0) |
||||
|
||||
#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) |
||||
|
||||
#define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) |
||||
|
||||
#ifdef __QAIC_DEBUG__ |
||||
#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv)) |
||||
#else |
||||
#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv)) |
||||
#endif |
||||
|
||||
|
||||
#endif // _QAIC_ENV_H
|
||||
|
||||
#ifndef _ALLOCATOR_H |
||||
#define _ALLOCATOR_H |
||||
|
||||
#include <stdlib.h> |
||||
#include <stdint.h> |
||||
|
||||
typedef struct _heap _heap; |
||||
struct _heap { |
||||
_heap* pPrev; |
||||
const char* loc; |
||||
uint64_t buf; |
||||
}; |
||||
|
||||
typedef struct _allocator { |
||||
_heap* pheap; |
||||
uint8_t* stack; |
||||
uint8_t* stackEnd; |
||||
int nSize; |
||||
} _allocator; |
||||
|
||||
_ATTRIBUTE_UNUSED |
||||
static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { |
||||
_heap* pn = 0; |
||||
pn = malloc(size + sizeof(_heap) - sizeof(uint64_t)); |
||||
if(pn != 0) { |
||||
pn->pPrev = *ppa; |
||||
pn->loc = loc; |
||||
*ppa = pn; |
||||
*ppbuf = (void*)&(pn->buf); |
||||
return 0; |
||||
} else { |
||||
return -1; |
||||
} |
||||
} |
||||
#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) |
||||
|
||||
_ATTRIBUTE_UNUSED |
||||
static __inline int _allocator_alloc(_allocator* me, |
||||
const char* loc, |
||||
int size, |
||||
unsigned int al, |
||||
void** ppbuf) { |
||||
if(size < 0) { |
||||
return -1; |
||||
} else if (size == 0) { |
||||
*ppbuf = 0; |
||||
return 0; |
||||
} |
||||
if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size) < (uintptr_t)me->stack + me->nSize) { |
||||
*ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); |
||||
me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; |
||||
return 0; |
||||
} else { |
||||
return _heap_alloc(&me->pheap, loc, size, ppbuf); |
||||
} |
||||
} |
||||
|
||||
_ATTRIBUTE_UNUSED |
||||
static __inline void _allocator_deinit(_allocator* me) { |
||||
_heap* pa = me->pheap; |
||||
while(pa != 0) { |
||||
_heap* pn = pa; |
||||
const char* loc = pn->loc; |
||||
(void)loc; |
||||
pa = pn->pPrev; |
||||
free(pn); |
||||
} |
||||
} |
||||
|
||||
_ATTRIBUTE_UNUSED |
||||
static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { |
||||
me->stack = stack; |
||||
me->stackEnd = stack + stackSize; |
||||
me->nSize = stackSize; |
||||
me->pheap = 0; |
||||
} |
||||
|
||||
|
||||
#endif // _ALLOCATOR_H
|
||||
|
||||
#ifndef SLIM_H |
||||
#define SLIM_H |
||||
|
||||
#include <stdint.h> |
||||
|
||||
//a C data structure for the idl types that can be used to implement
|
||||
//static and dynamic language bindings fairly efficiently.
|
||||
//
|
||||
//the goal is to have a minimal ROM and RAM footprint and without
|
||||
//doing too many allocations. A good way to package these things seemed
|
||||
//like the module boundary, so all the idls within one module can share
|
||||
//all the type references.
|
||||
|
||||
|
||||
#define PARAMETER_IN 0x0 |
||||
#define PARAMETER_OUT 0x1 |
||||
#define PARAMETER_INOUT 0x2 |
||||
#define PARAMETER_ROUT 0x3 |
||||
#define PARAMETER_INROUT 0x4 |
||||
|
||||
//the types that we get from idl
|
||||
#define TYPE_OBJECT 0x0 |
||||
#define TYPE_INTERFACE 0x1 |
||||
#define TYPE_PRIMITIVE 0x2 |
||||
#define TYPE_ENUM 0x3 |
||||
#define TYPE_STRING 0x4 |
||||
#define TYPE_WSTRING 0x5 |
||||
#define TYPE_STRUCTURE 0x6 |
||||
#define TYPE_UNION 0x7 |
||||
#define TYPE_ARRAY 0x8 |
||||
#define TYPE_SEQUENCE 0x9 |
||||
|
||||
//these require the pack/unpack to recurse
|
||||
//so it's a hint to those languages that can optimize in cases where
|
||||
//recursion isn't necessary.
|
||||
#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) |
||||
#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) |
||||
#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) |
||||
#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) |
||||
|
||||
|
||||
typedef struct Type Type; |
||||
|
||||
#define INHERIT_TYPE\ |
||||
int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\
|
||||
union {\
|
||||
struct {\
|
||||
const uintptr_t p1;\
|
||||
const uintptr_t p2;\
|
||||
} _cast;\
|
||||
struct {\
|
||||
uint32_t iid;\
|
||||
uint32_t bNotNil;\
|
||||
} object;\
|
||||
struct {\
|
||||
const Type *arrayType;\
|
||||
int32_t nItems;\
|
||||
} array;\
|
||||
struct {\
|
||||
const Type *seqType;\
|
||||
int32_t nMaxLen;\
|
||||
} seqSimple; \
|
||||
struct {\
|
||||
uint32_t bFloating;\
|
||||
uint32_t bSigned;\
|
||||
} prim; \
|
||||
const SequenceType* seqComplex;\
|
||||
const UnionType *unionType;\
|
||||
const StructType *structType;\
|
||||
int32_t stringMaxLen;\
|
||||
uint8_t bInterfaceNotNil;\
|
||||
} param;\
|
||||
uint8_t type;\
|
||||
uint8_t nativeAlignment\
|
||||
|
||||
typedef struct UnionType UnionType; |
||||
typedef struct StructType StructType; |
||||
typedef struct SequenceType SequenceType; |
||||
struct Type { |
||||
INHERIT_TYPE; |
||||
}; |
||||
|
||||
struct SequenceType { |
||||
const Type * seqType; |
||||
uint32_t nMaxLen; |
||||
uint32_t inSize; |
||||
uint32_t routSizePrimIn; |
||||
uint32_t routSizePrimROut; |
||||
}; |
||||
|
||||
//byte offset from the start of the case values for
|
||||
//this unions case value array. it MUST be aligned
|
||||
//at the alignment requrements for the descriptor
|
||||
//
|
||||
//if negative it means that the unions cases are
|
||||
//simple enumerators, so the value read from the descriptor
|
||||
//can be used directly to find the correct case
|
||||
typedef union CaseValuePtr CaseValuePtr; |
||||
union CaseValuePtr { |
||||
const uint8_t* value8s; |
||||
const uint16_t* value16s; |
||||
const uint32_t* value32s; |
||||
const uint64_t* value64s; |
||||
}; |
||||
|
||||
//these are only used in complex cases
|
||||
//so I pulled them out of the type definition as references to make
|
||||
//the type smaller
|
||||
struct UnionType { |
||||
const Type *descriptor; |
||||
uint32_t nCases; |
||||
const CaseValuePtr caseValues; |
||||
const Type * const *cases; |
||||
int32_t inSize; |
||||
int32_t routSizePrimIn; |
||||
int32_t routSizePrimROut; |
||||
uint8_t inAlignment; |
||||
uint8_t routAlignmentPrimIn; |
||||
uint8_t routAlignmentPrimROut; |
||||
uint8_t inCaseAlignment; |
||||
uint8_t routCaseAlignmentPrimIn; |
||||
uint8_t routCaseAlignmentPrimROut; |
||||
uint8_t nativeCaseAlignment; |
||||
uint8_t bDefaultCase; |
||||
}; |
||||
|
||||
struct StructType { |
||||
uint32_t nMembers; |
||||
const Type * const *members; |
||||
int32_t inSize; |
||||
int32_t routSizePrimIn; |
||||
int32_t routSizePrimROut; |
||||
uint8_t inAlignment; |
||||
uint8_t routAlignmentPrimIn; |
||||
uint8_t routAlignmentPrimROut; |
||||
}; |
||||
|
||||
typedef struct Parameter Parameter; |
||||
struct Parameter { |
||||
INHERIT_TYPE; |
||||
uint8_t mode; |
||||
uint8_t bNotNil; |
||||
}; |
||||
|
||||
#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) |
||||
#define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) |
||||
|
||||
typedef struct Method Method; |
||||
struct Method { |
||||
uint32_t uScalars; //no method index
|
||||
int32_t primInSize; |
||||
int32_t primROutSize; |
||||
int maxArgs; |
||||
int numParams; |
||||
const Parameter * const *params; |
||||
uint8_t primInAlignment; |
||||
uint8_t primROutAlignment; |
||||
}; |
||||
|
||||
typedef struct Interface Interface; |
||||
|
||||
struct Interface { |
||||
int nMethods; |
||||
const Method * const *methodArray; |
||||
int nIIds; |
||||
const uint32_t *iids; |
||||
const uint16_t* methodStringArray; |
||||
const uint16_t* methodStrings; |
||||
const char* strings; |
||||
}; |
||||
|
||||
|
||||
#endif //SLIM_H
|
||||
|
||||
|
||||
#ifndef _CALCULATOR_SLIM_H |
||||
#define _CALCULATOR_SLIM_H |
||||
|
||||
// remote.h
|
||||
|
||||
#include <stdint.h> |
||||
|
||||
#ifndef __QAIC_SLIM |
||||
#define __QAIC_SLIM(ff) ff |
||||
#endif |
||||
#ifndef __QAIC_SLIM_EXPORT |
||||
#define __QAIC_SLIM_EXPORT |
||||
#endif |
||||
|
||||
static const Type types[1]; |
||||
static const Type types[1] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)0}}, 2,0x1}}; |
||||
static const Parameter parameters[3] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)0}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0}}; |
||||
static const Parameter* const parameterArrays[3] = {(&(parameters[1])),(&(parameters[2])),(&(parameters[0]))}; |
||||
static const Method methods[2] = {{REMOTE_SCALARS_MAKEX(0,0,0x0,0x1,0x0,0x0),0x0,0x4,1,1,(&(parameterArrays[2])),0x1,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x1,0x0,0x0),0x8,0x0,5,2,(&(parameterArrays[0])),0x4,0x1}}; |
||||
static const Method* const methodArrays[2] = {&(methods[0]),&(methods[1])}; |
||||
static const char strings[41] = "extract_and_match\0features\0leet\0init\0img\0"; |
||||
static const uint16_t methodStrings[5] = {0,37,18,32,27}; |
||||
static const uint16_t methodStringsArrays[2] = {3,0}; |
||||
__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(calculator_slim) = {2,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; |
||||
#endif //_CALCULATOR_SLIM_H
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#ifndef _const_calculator_handle |
||||
#define _const_calculator_handle ((remote_handle)-1) |
||||
#endif //_const_calculator_handle
|
||||
|
||||
static void _calculator_pls_dtor(void* data) { |
||||
remote_handle* ph = (remote_handle*)data; |
||||
if(_const_calculator_handle != *ph) { |
||||
(void)__QAIC_REMOTE(remote_handle_close)(*ph); |
||||
*ph = _const_calculator_handle; |
||||
} |
||||
} |
||||
|
||||
static int _calculator_pls_ctor(void* ctx, void* data) { |
||||
remote_handle* ph = (remote_handle*)data; |
||||
*ph = _const_calculator_handle; |
||||
if(*ph == (remote_handle)-1) { |
||||
return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
#if (defined __qdsp6__) || (defined __hexagon__) |
||||
#pragma weak adsp_pls_add_lookup |
||||
extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); |
||||
#pragma weak HAP_pls_add_lookup |
||||
extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); |
||||
|
||||
__QAIC_STUB_EXPORT remote_handle _calculator_handle(void) { |
||||
remote_handle* ph; |
||||
if(adsp_pls_add_lookup) { |
||||
if(0 == adsp_pls_add_lookup((uint32_t)_calculator_handle, 0, sizeof(*ph), _calculator_pls_ctor, "calculator", _calculator_pls_dtor, (void**)&ph)) { |
||||
return *ph; |
||||
} |
||||
return (remote_handle)-1; |
||||
} else if(HAP_pls_add_lookup) { |
||||
if(0 == HAP_pls_add_lookup((uint32_t)_calculator_handle, 0, sizeof(*ph), _calculator_pls_ctor, "calculator", _calculator_pls_dtor, (void**)&ph)) { |
||||
return *ph; |
||||
} |
||||
return (remote_handle)-1; |
||||
} |
||||
return(remote_handle)-1; |
||||
} |
||||
|
||||
#else //__qdsp6__ || __hexagon__
|
||||
|
||||
uint32_t _calculator_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); |
||||
|
||||
#ifdef _WIN32 |
||||
#include "Windows.h" |
||||
uint32_t _calculator_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { |
||||
return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); |
||||
} |
||||
#elif __GNUC__ |
||||
uint32_t _calculator_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { |
||||
return __sync_val_compare_and_swap(puDest, uCompare, uExchange); |
||||
} |
||||
#endif //_WIN32
|
||||
|
||||
|
||||
__QAIC_STUB_EXPORT remote_handle _calculator_handle(void) { |
||||
static remote_handle handle = _const_calculator_handle; |
||||
if((remote_handle)-1 != handle) { |
||||
return handle; |
||||
} else { |
||||
remote_handle tmp; |
||||
int nErr = _calculator_pls_ctor("calculator", (void*)&tmp); |
||||
if(nErr) { |
||||
return (remote_handle)-1; |
||||
} |
||||
if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_calculator_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { |
||||
_calculator_pls_dtor(&tmp); |
||||
} |
||||
return handle; |
||||
} |
||||
} |
||||
|
||||
#endif //__qdsp6__
|
||||
|
||||
__QAIC_STUB_EXPORT int __QAIC_STUB(calculator_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_STUB_ATTRIBUTE { |
||||
return __QAIC_REMOTE(remote_handle_invoke)(_calculator_handle(), _sc, _pra); |
||||
} |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
extern int remote_register_dma_handle(int, uint32_t); |
||||
static __inline int _stub_method(remote_handle _handle, uint32_t _mid, uint32_t _rout0[1]) { |
||||
int _numIn[1]; |
||||
remote_arg _pra[1]; |
||||
uint32_t _primROut[1]; |
||||
int _nErr = 0; |
||||
_numIn[0] = 0; |
||||
_pra[(_numIn[0] + 0)].buf.pv = (void*)_primROut; |
||||
_pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); |
||||
_TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); |
||||
_COPY(_rout0, 0, _primROut, 0, 4); |
||||
_CATCH(_nErr) {} |
||||
return _nErr; |
||||
} |
||||
__QAIC_STUB_EXPORT int __QAIC_STUB(calculator_init)(uint32* leet) __QAIC_STUB_ATTRIBUTE { |
||||
uint32_t _mid = 0; |
||||
return _stub_method(_calculator_handle(), _mid, (uint32_t*)leet); |
||||
} |
||||
static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid, char* _in0[1], uint32_t _in0Len[1], char* _rout1[1], uint32_t _rout1Len[1]) { |
||||
int _numIn[1]; |
||||
remote_arg _pra[3]; |
||||
uint32_t _primIn[2]; |
||||
remote_arg* _praIn; |
||||
remote_arg* _praROut; |
||||
int _nErr = 0; |
||||
_numIn[0] = 1; |
||||
_pra[0].buf.pv = (void*)_primIn; |
||||
_pra[0].buf.nLen = sizeof(_primIn); |
||||
_COPY(_primIn, 0, _in0Len, 0, 4); |
||||
_praIn = (_pra + 1); |
||||
_praIn[0].buf.pv = _in0[0]; |
||||
_praIn[0].buf.nLen = (1 * _in0Len[0]); |
||||
_COPY(_primIn, 4, _rout1Len, 0, 4); |
||||
_praROut = (_praIn + _numIn[0] + 0); |
||||
_praROut[0].buf.pv = _rout1[0]; |
||||
_praROut[0].buf.nLen = (1 * _rout1Len[0]); |
||||
_TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 1, 0, 0), _pra)); |
||||
_CATCH(_nErr) {} |
||||
return _nErr; |
||||
} |
||||
__QAIC_STUB_EXPORT int __QAIC_STUB(calculator_extract_and_match)(const uint8* img, int imgLen, uint8* features, int featuresLen) __QAIC_STUB_ATTRIBUTE { |
||||
uint32_t _mid = 1; |
||||
return _stub_method_1(_calculator_handle(), _mid, (char**)&img, (uint32_t*)&imgLen, (char**)&features, (uint32_t*)&featuresLen); |
||||
} |
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
#endif //_CALCULATOR_STUB_H
|
Binary file not shown.
@ -1,37 +0,0 @@ |
||||
#ifndef EXTRACTOR_H |
||||
#define EXTRACTOR_H |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
#include <stdint.h> |
||||
|
||||
#define ORBD_KEYPOINTS 3000 |
||||
#define ORBD_DESCRIPTOR_LENGTH 32 |
||||
#define ORBD_HEIGHT 874 |
||||
#define ORBD_WIDTH 1164 |
||||
|
||||
// matches OrbFeatures from log.capnp
|
||||
struct orb_features { |
||||
// align this
|
||||
uint16_t n_corners; |
||||
uint16_t xy[ORBD_KEYPOINTS][2]; |
||||
uint8_t octave[ORBD_KEYPOINTS]; |
||||
uint8_t des[ORBD_KEYPOINTS][ORBD_DESCRIPTOR_LENGTH]; |
||||
int16_t matches[ORBD_KEYPOINTS]; |
||||
}; |
||||
|
||||
// forward declare this
|
||||
struct pyramid; |
||||
|
||||
// manage the pyramids in extractor.c
|
||||
void init_gpyrs(); |
||||
int extract_and_match_gpyrs(const uint8_t *img, struct orb_features *); |
||||
int extract_and_match(const uint8_t *img, struct pyramid *pyrs, struct pyramid *prev_pyrs, struct orb_features *); |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif // EXTRACTOR_H
|
@ -1,181 +0,0 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <signal.h> |
||||
#include <unistd.h> |
||||
#include <stdint.h> |
||||
#include <assert.h> |
||||
#include <sys/resource.h> |
||||
|
||||
#include "common/visionipc.h" |
||||
#include "common/swaglog.h" |
||||
|
||||
#include "extractor.h" |
||||
|
||||
#ifdef DSP |
||||
#include "dsp/gen/calculator.h" |
||||
#else |
||||
#include "turbocv.h" |
||||
#endif |
||||
|
||||
#include <zmq.h> |
||||
#include <capnp/serialize.h> |
||||
#include "cereal/gen/cpp/log.capnp.h" |
||||
|
||||
#ifndef PATH_MAX |
||||
#include <linux/limits.h> |
||||
#endif |
||||
|
||||
volatile int do_exit = 0; |
||||
|
||||
static void set_do_exit(int sig) { |
||||
do_exit = 1; |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int err; |
||||
setpriority(PRIO_PROCESS, 0, -13); |
||||
printf("starting orbd\n"); |
||||
|
||||
#ifdef DSP |
||||
uint32_t test_leet = 0; |
||||
char my_path[PATH_MAX+1]; |
||||
memset(my_path, 0, sizeof(my_path)); |
||||
|
||||
ssize_t len = readlink("/proc/self/exe", my_path, sizeof(my_path)); |
||||
assert(len > 5); |
||||
my_path[len-5] = '\0'; |
||||
LOGW("running from %s with PATH_MAX %d", my_path, PATH_MAX); |
||||
|
||||
char adsp_path[PATH_MAX+1]; |
||||
snprintf(adsp_path, PATH_MAX, "ADSP_LIBRARY_PATH=%s/dsp/gen", my_path); |
||||
assert(putenv(adsp_path) == 0); |
||||
|
||||
assert(calculator_init(&test_leet) == 0); |
||||
assert(test_leet == 0x1337); |
||||
LOGW("orbd init complete"); |
||||
#else |
||||
init_gpyrs(); |
||||
#endif |
||||
|
||||
signal(SIGINT, (sighandler_t) set_do_exit); |
||||
signal(SIGTERM, (sighandler_t) set_do_exit); |
||||
|
||||
void *ctx = zmq_ctx_new(); |
||||
|
||||
void *orb_features_sock = zmq_socket(ctx, ZMQ_PUB); |
||||
assert(orb_features_sock); |
||||
zmq_bind(orb_features_sock, "tcp://*:8058"); |
||||
|
||||
void *orb_features_summary_sock = zmq_socket(ctx, ZMQ_PUB); |
||||
assert(orb_features_summary_sock); |
||||
zmq_bind(orb_features_summary_sock, "tcp://*:8062"); |
||||
|
||||
struct orb_features *features = (struct orb_features *)malloc(sizeof(struct orb_features)); |
||||
int last_frame_id = 0; |
||||
|
||||
VisionStream stream; |
||||
while (!do_exit) { |
||||
VisionStreamBufs buf_info; |
||||
err = visionstream_init(&stream, VISION_STREAM_YUV, true, &buf_info); |
||||
if (err) { |
||||
printf("visionstream connect fail\n"); |
||||
usleep(100000); |
||||
continue; |
||||
} |
||||
uint64_t timestamp_last_eof = 0; |
||||
while (!do_exit) { |
||||
VIPCBuf *buf; |
||||
VIPCBufExtra extra; |
||||
buf = visionstream_get(&stream, &extra); |
||||
if (buf == NULL) { |
||||
printf("visionstream get failed\n"); |
||||
break; |
||||
} |
||||
|
||||
uint64_t start = nanos_since_boot(); |
||||
#ifdef DSP |
||||
int ret = calculator_extract_and_match((uint8_t *)buf->addr, ORBD_HEIGHT*ORBD_WIDTH, (uint8_t *)features, sizeof(struct orb_features)); |
||||
#else |
||||
int ret = extract_and_match_gpyrs((uint8_t *) buf->addr, features); |
||||
#endif |
||||
uint64_t end = nanos_since_boot(); |
||||
LOGD("total(%d): %6.2f ms to get %4d features on %d", ret, (end-start)/1000000.0, features->n_corners, extra.frame_id); |
||||
assert(ret == 0); |
||||
|
||||
if (last_frame_id+1 != extra.frame_id) { |
||||
LOGW("dropped frame!"); |
||||
} |
||||
|
||||
last_frame_id = extra.frame_id; |
||||
|
||||
if (timestamp_last_eof == 0) { |
||||
timestamp_last_eof = extra.timestamp_eof; |
||||
continue; |
||||
} |
||||
|
||||
int match_count = 0; |
||||
|
||||
// *** send OrbFeatures ***
|
||||
{ |
||||
// create capnp message
|
||||
capnp::MallocMessageBuilder msg; |
||||
cereal::Event::Builder event = msg.initRoot<cereal::Event>(); |
||||
event.setLogMonoTime(nanos_since_boot()); |
||||
|
||||
auto orb_features = event.initOrbFeatures(); |
||||
|
||||
// set timestamps
|
||||
orb_features.setTimestampEof(extra.timestamp_eof); |
||||
orb_features.setTimestampLastEof(timestamp_last_eof); |
||||
|
||||
// init descriptors for send
|
||||
kj::ArrayPtr<capnp::byte> descriptorsPtr = kj::arrayPtr((uint8_t *)features->des, ORBD_DESCRIPTOR_LENGTH * features->n_corners); |
||||
orb_features.setDescriptors(descriptorsPtr); |
||||
|
||||
auto xs = orb_features.initXs(features->n_corners); |
||||
auto ys = orb_features.initYs(features->n_corners); |
||||
auto octaves = orb_features.initOctaves(features->n_corners); |
||||
auto matches = orb_features.initMatches(features->n_corners); |
||||
|
||||
// copy out normalized keypoints
|
||||
for (int i = 0; i < features->n_corners; i++) { |
||||
xs.set(i, features->xy[i][0] * 1.0f / ORBD_WIDTH - 0.5f); |
||||
ys.set(i, features->xy[i][1] * 1.0f / ORBD_HEIGHT - 0.5f); |
||||
octaves.set(i, features->octave[i]); |
||||
matches.set(i, features->matches[i]); |
||||
match_count += features->matches[i] != -1; |
||||
} |
||||
|
||||
auto words = capnp::messageToFlatArray(msg); |
||||
auto bytes = words.asBytes(); |
||||
zmq_send(orb_features_sock, bytes.begin(), bytes.size(), 0); |
||||
} |
||||
|
||||
// *** send OrbFeaturesSummary ***
|
||||
|
||||
{ |
||||
// create capnp message
|
||||
capnp::MallocMessageBuilder msg; |
||||
cereal::Event::Builder event = msg.initRoot<cereal::Event>(); |
||||
event.setLogMonoTime(nanos_since_boot()); |
||||
|
||||
auto orb_features_summary = event.initOrbFeaturesSummary(); |
||||
|
||||
orb_features_summary.setTimestampEof(extra.timestamp_eof); |
||||
orb_features_summary.setTimestampLastEof(timestamp_last_eof); |
||||
orb_features_summary.setFeatureCount(features->n_corners); |
||||
orb_features_summary.setMatchCount(match_count); |
||||
orb_features_summary.setComputeNs(end-start); |
||||
|
||||
auto words = capnp::messageToFlatArray(msg); |
||||
auto bytes = words.asBytes(); |
||||
zmq_send(orb_features_summary_sock, bytes.begin(), bytes.size(), 0); |
||||
} |
||||
|
||||
timestamp_last_eof = extra.timestamp_eof; |
||||
} |
||||
} |
||||
visionstream_destroy(&stream); |
||||
return 0; |
||||
} |
||||
|
Binary file not shown.
Binary file not shown.
@ -1,19 +0,0 @@ |
||||
"""Methods for reading system thermal information.""" |
||||
import selfdrive.messaging as messaging |
||||
|
||||
def read_tz(x): |
||||
with open("/sys/devices/virtual/thermal/thermal_zone%d/temp" % x) as f: |
||||
ret = max(0, int(f.read())) |
||||
return ret |
||||
|
||||
def read_thermal(): |
||||
dat = messaging.new_message() |
||||
dat.init('thermal') |
||||
dat.thermal.cpu0 = read_tz(5) |
||||
dat.thermal.cpu1 = read_tz(7) |
||||
dat.thermal.cpu2 = read_tz(10) |
||||
dat.thermal.cpu3 = read_tz(12) |
||||
dat.thermal.mem = read_tz(2) |
||||
dat.thermal.gpu = read_tz(16) |
||||
dat.thermal.bat = read_tz(29) |
||||
return dat |
@ -0,0 +1,272 @@ |
||||
#!/usr/bin/env python2.7 |
||||
import os |
||||
import zmq |
||||
from smbus2 import SMBus |
||||
|
||||
from selfdrive.version import training_version |
||||
from selfdrive.swaglog import cloudlog |
||||
import selfdrive.messaging as messaging |
||||
from selfdrive.services import service_list |
||||
from selfdrive.loggerd.config import ROOT |
||||
from common.params import Params |
||||
from common.realtime import sec_since_boot |
||||
|
||||
import cereal |
||||
ThermalStatus = cereal.log.ThermalData.ThermalStatus |
||||
|
||||
def read_tz(x): |
||||
with open("/sys/devices/virtual/thermal/thermal_zone%d/temp" % x) as f: |
||||
ret = max(0, int(f.read())) |
||||
return ret |
||||
|
||||
def read_thermal(): |
||||
dat = messaging.new_message() |
||||
dat.init('thermal') |
||||
dat.thermal.cpu0 = read_tz(5) |
||||
dat.thermal.cpu1 = read_tz(7) |
||||
dat.thermal.cpu2 = read_tz(10) |
||||
dat.thermal.cpu3 = read_tz(12) |
||||
dat.thermal.mem = read_tz(2) |
||||
dat.thermal.gpu = read_tz(16) |
||||
dat.thermal.bat = read_tz(29) |
||||
return dat |
||||
|
||||
LEON = False |
||||
def setup_eon_fan(): |
||||
global LEON |
||||
|
||||
os.system("echo 2 > /sys/module/dwc3_msm/parameters/otg_switch") |
||||
|
||||
bus = SMBus(7, force=True) |
||||
try: |
||||
bus.write_byte_data(0x21, 0x10, 0xf) # mask all interrupts |
||||
bus.write_byte_data(0x21, 0x03, 0x1) # set drive current and global interrupt disable |
||||
bus.write_byte_data(0x21, 0x02, 0x2) # needed? |
||||
bus.write_byte_data(0x21, 0x04, 0x4) # manual override source |
||||
except IOError: |
||||
print "LEON detected" |
||||
#os.system("echo 1 > /sys/devices/soc/6a00000.ssusb/power_supply/usb/usb_otg") |
||||
LEON = True |
||||
bus.close() |
||||
|
||||
last_eon_fan_val = None |
||||
def set_eon_fan(val): |
||||
global LEON, last_eon_fan_val |
||||
|
||||
if last_eon_fan_val is None or last_eon_fan_val != val: |
||||
bus = SMBus(7, force=True) |
||||
if LEON: |
||||
i = [0x1, 0x3 | 0, 0x3 | 0x08, 0x3 | 0x10][val] |
||||
bus.write_i2c_block_data(0x3d, 0, [i]) |
||||
else: |
||||
bus.write_byte_data(0x21, 0x04, 0x2) |
||||
bus.write_byte_data(0x21, 0x03, (val*2)+1) |
||||
bus.write_byte_data(0x21, 0x04, 0x4) |
||||
bus.close() |
||||
last_eon_fan_val = val |
||||
|
||||
# temp thresholds to control fan speed - high hysteresis |
||||
_TEMP_THRS_H = [50., 65., 80., 10000] |
||||
# temp thresholds to control fan speed - low hysteresis |
||||
_TEMP_THRS_L = [42.5, 57.5, 72.5, 10000] |
||||
# fan speed options |
||||
_FAN_SPEEDS = [0, 16384, 32768, 65535] |
||||
# max fan speed only allowed if battery if hot |
||||
_BAT_TEMP_THERSHOLD = 45. |
||||
|
||||
def handle_fan(max_temp, bat_temp, fan_speed): |
||||
new_speed_h = next(speed for speed, temp_h in zip(_FAN_SPEEDS, _TEMP_THRS_H) if temp_h > max_temp) |
||||
new_speed_l = next(speed for speed, temp_l in zip(_FAN_SPEEDS, _TEMP_THRS_L) if temp_l > max_temp) |
||||
|
||||
if new_speed_h > fan_speed: |
||||
# update speed if using the high thresholds results in fan speed increment |
||||
fan_speed = new_speed_h |
||||
elif new_speed_l < fan_speed: |
||||
# update speed if using the low thresholds results in fan speed decrement |
||||
fan_speed = new_speed_l |
||||
|
||||
if bat_temp < _BAT_TEMP_THERSHOLD: |
||||
# no max fan speed unless battery is hot |
||||
fan_speed = min(fan_speed, _FAN_SPEEDS[-2]) |
||||
|
||||
set_eon_fan(fan_speed/16384) |
||||
|
||||
return fan_speed |
||||
|
||||
class LocationStarter(object): |
||||
def __init__(self): |
||||
self.last_good_loc = 0 |
||||
def update(self, started_ts, location): |
||||
rt = sec_since_boot() |
||||
|
||||
if location is None or location.accuracy > 50 or location.speed < 2: |
||||
# bad location, stop if we havent gotten a location in a while |
||||
# dont stop if we're been going for less than a minute |
||||
if started_ts: |
||||
if rt-self.last_good_loc > 60. and rt-started_ts > 60: |
||||
cloudlog.event("location_stop", |
||||
ts=rt, |
||||
started_ts=started_ts, |
||||
last_good_loc=self.last_good_loc, |
||||
location=location.to_dict() if location else None) |
||||
return False |
||||
else: |
||||
return True |
||||
else: |
||||
return False |
||||
|
||||
self.last_good_loc = rt |
||||
|
||||
if started_ts: |
||||
return True |
||||
else: |
||||
cloudlog.event("location_start", location=location.to_dict() if location else None) |
||||
return location.speed*3.6 > 10 |
||||
|
||||
def thermald_thread(): |
||||
setup_eon_fan() |
||||
|
||||
# now loop |
||||
context = zmq.Context() |
||||
thermal_sock = messaging.pub_sock(context, service_list['thermal'].port) |
||||
health_sock = messaging.sub_sock(context, service_list['health'].port) |
||||
location_sock = messaging.sub_sock(context, service_list['gpsLocation'].port) |
||||
fan_speed = 0 |
||||
count = 0 |
||||
|
||||
off_ts = None |
||||
started_ts = None |
||||
ignition_seen = False |
||||
started_seen = False |
||||
passive_starter = LocationStarter() |
||||
thermal_status = ThermalStatus.green |
||||
health_sock.RCVTIMEO = 1500 |
||||
|
||||
params = Params() |
||||
|
||||
while 1: |
||||
td = messaging.recv_sock(health_sock, wait=True) |
||||
location = messaging.recv_sock(location_sock) |
||||
location = location.gpsLocation if location else None |
||||
msg = read_thermal() |
||||
|
||||
# loggerd is gated based on free space |
||||
statvfs = os.statvfs(ROOT) |
||||
avail = (statvfs.f_bavail * 1.0)/statvfs.f_blocks |
||||
|
||||
# thermal message now also includes free space |
||||
msg.thermal.freeSpace = avail |
||||
with open("/sys/class/power_supply/battery/capacity") as f: |
||||
msg.thermal.batteryPercent = int(f.read()) |
||||
with open("/sys/class/power_supply/battery/status") as f: |
||||
msg.thermal.batteryStatus = f.read().strip() |
||||
with open("/sys/class/power_supply/usb/online") as f: |
||||
msg.thermal.usbOnline = bool(int(f.read())) |
||||
|
||||
# TODO: add car battery voltage check |
||||
max_temp = max(msg.thermal.cpu0, msg.thermal.cpu1, |
||||
msg.thermal.cpu2, msg.thermal.cpu3) / 10.0 |
||||
bat_temp = msg.thermal.bat/1000. |
||||
fan_speed = handle_fan(max_temp, bat_temp, fan_speed) |
||||
msg.thermal.fanSpeed = fan_speed |
||||
|
||||
# thermal logic here |
||||
|
||||
if max_temp < 70.0: |
||||
thermal_status = ThermalStatus.green |
||||
if max_temp > 85.0: |
||||
cloudlog.warning("over temp: %r", max_temp) |
||||
thermal_status = ThermalStatus.yellow |
||||
|
||||
# from controls |
||||
overtemp_proc = any(t > 950 for t in |
||||
(msg.thermal.cpu0, msg.thermal.cpu1, msg.thermal.cpu2, |
||||
msg.thermal.cpu3, msg.thermal.mem, msg.thermal.gpu)) |
||||
overtemp_bat = msg.thermal.bat > 60000 # 60c |
||||
if overtemp_proc or overtemp_bat: |
||||
# TODO: hysteresis |
||||
thermal_status = ThermalStatus.red |
||||
|
||||
if max_temp > 107.0 or msg.thermal.bat >= 63000: |
||||
thermal_status = ThermalStatus.danger |
||||
|
||||
# **** starting logic **** |
||||
|
||||
# start constellation of processes when the car starts |
||||
ignition = td is not None and td.health.started |
||||
ignition_seen = ignition_seen or ignition |
||||
|
||||
# add voltage check for ignition |
||||
if not ignition_seen and td is not None and td.health.voltage > 13500: |
||||
ignition = True |
||||
|
||||
do_uninstall = params.get("DoUninstall") == "1" |
||||
accepted_terms = params.get("HasAcceptedTerms") == "1" |
||||
completed_training = params.get("CompletedTrainingVersion") == training_version |
||||
|
||||
should_start = ignition |
||||
|
||||
# have we seen a panda? |
||||
passive = (params.get("Passive") == "1") |
||||
|
||||
# start on gps movement if we haven't seen ignition and are in passive mode |
||||
should_start = should_start or (not (ignition_seen and td) # seen ignition and panda is connected |
||||
and passive |
||||
and passive_starter.update(started_ts, location)) |
||||
|
||||
# with 2% left, we killall, otherwise the phone will take a long time to boot |
||||
should_start = should_start and msg.thermal.freeSpace > 0.02 |
||||
|
||||
# require usb power in passive mode |
||||
should_start = should_start and (not passive or msg.thermal.usbOnline) |
||||
|
||||
# confirm we have completed training and aren't uninstalling |
||||
should_start = should_start and accepted_terms and (passive or completed_training) and (not do_uninstall) |
||||
|
||||
# if any CPU gets above 107 or the battery gets above 63, kill all processes |
||||
# controls will warn with CPU above 95 or battery above 60 |
||||
if msg.thermal.thermalStatus >= ThermalStatus.danger: |
||||
# TODO: Add a better warning when this is happening |
||||
should_start = False |
||||
|
||||
if should_start: |
||||
off_ts = None |
||||
if started_ts is None: |
||||
params.car_start() |
||||
started_ts = sec_since_boot() |
||||
started_seen = True |
||||
else: |
||||
started_ts = None |
||||
if off_ts is None: |
||||
off_ts = sec_since_boot() |
||||
|
||||
# shutdown if the battery gets lower than 3%, it's discharging, we aren't running for |
||||
# more than a minute but we were running |
||||
if msg.thermal.batteryPercent < 3 and msg.thermal.batteryStatus == "Discharging" and \ |
||||
started_seen and (sec_since_boot() - off_ts) > 60: |
||||
os.system('LD_LIBRARY_PATH="" svc power shutdown') |
||||
|
||||
msg.thermal.started = started_ts is not None |
||||
msg.thermal.startedTs = int(1e9*(started_ts or 0)) |
||||
|
||||
msg.thermal.thermalStatus = thermal_status |
||||
thermal_sock.send(msg.to_bytes()) |
||||
print msg |
||||
|
||||
# report to server once per minute |
||||
if (count%60) == 0: |
||||
cloudlog.event("STATUS_PACKET", |
||||
count=count, |
||||
health=(td.to_dict() if td else None), |
||||
location=(location.to_dict() if location else None), |
||||
thermal=msg.to_dict()) |
||||
|
||||
count += 1 |
||||
|
||||
|
||||
def main(gctx=None): |
||||
thermald_thread() |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
||||
|
Binary file not shown.
Loading…
Reference in new issue