compressonator icon indicating copy to clipboard operation
compressonator copied to clipboard

Using Compressonator Core from C

Open zopsicle opened this issue 3 years ago • 3 comments

The header file cmp_core.h contains the following:

#ifdef __cplusplus
#define CMP_DEFAULTNULL = NULL
#else
#define CMP_DEFAULTNULL
#endif

This suggests that the Compressonator Core library can be used from C. However, the corresponding translation units, such as bc1_encode_kernel.cpp, are written in C++. As the functions aren’t defined with extern "C", their symbol names get mangled, which can be confirmed by looking at the symbol table of libCMP_Core.a:

$ objdump --syms libCMP_Core.a | grep CompressBlockBC1
0000000000010810 g     F .text	0000000000006b92 _Z25CompressBlockBC1_InternalPK5Vec4TIhEPjP15CMP_BC15Options
0000000000017580 g     F .text	00000000000004c1 _Z16CompressBlockBC1PKhjPhPKv

Additionally, some functions take arguments of type bool, which isn’t available in C.

This means that the library cannot actually be used from C, only from C++. Or is there a way to compile the library for use with C? I’m fine with using C++, but just wondering. :smile:

zopsicle avatar Dec 08 '22 17:12 zopsicle

@chloekek The core code should run in C also, sources with _kernel in shader folder is intended to work on CPU as well as on GPU's using a common header that defines variable types in "common_def.h" appropriate for multiple compilers for (CPU, GPU, GLS, HLSL, GCC, OPENCL, etc.) The cmp_core.h header will work in "C" for c99 or newer when #include <stdbool.h> is added. One quick fix for bool would be to add a typedef int bool and enum {false, true}. As you mentioned this should not be an issue when working on C++

NPCompress avatar Jan 05 '23 15:01 NPCompress

I had to do a lot of changes to the public header compressonator.h in order to make it compite with a C99 compiler. E.g. it has a namespace keyword, #include <vector>, structs without typedefs, etc. Am I doing something wrong in that case?

leavittx avatar Jan 07 '23 15:01 leavittx

After reading more, I see that cmp_core.h is recommended for plain C, although it seems like it's not possible to use a GPU based encoder with it. Or is there an example of that somewhere?

leavittx avatar Jan 07 '23 15:01 leavittx