bkaradzic / bx Goto Github PK
View Code? Open in Web Editor NEWBase library used across multiple projects
License: BSD 2-Clause "Simplified" License
Base library used across multiple projects
License: BSD 2-Clause "Simplified" License
With the latest version of bx, the uniform handling of bgfx breaks. All calls to bgfx::createUniform return a handle of 0 for me.
Reason is the following:
string.h, line 612:
inline uint32_t hashMurmur2A(const char* _data)
{
return hashMurmur2A(StringView(_data) );
}
_data
is set to the name of the uniform here, and hashMurmur2A always returns 0 for me.
The failing part is the strnlen
you wrote in StringView::set
:
string.h, line 559:
inline size_t strnlen(const char* _str, size_t _max)
{
const char* end = _str + _max;
const char* ptr;
for (ptr = _str; ptr < end && *ptr != '\0'; ++ptr) {};
return ptr - _str;
}
As StringView::set
sets _max
to UINT32_MAX
, the end
pointer will actually overflow on a 32-bit system and end up being smaller than _str
, which causes the for-loop to immediately exit.
Failed to build with themake osx
command on macOS Sierra 10.12.6 on master branch (451e30b)
I get the following error:
make -C .build/projects/gmake-osx config=debug32
==== Building bx (debug32) ====
Creating ../../osx32_clang/obj/x32/Debug/bx/src
allocator.cpp
bx.cpp
commandline.cpp
crtnone.cpp
debug.cpp
dtoa.cpp
easing.cpp
file.cpp
filepath.cpp
hash.cpp
math.cpp
mutex.cpp
os.cpp
../../../src/os.cpp:280:10: fatal error: no member named 'chdir' in the global namespace; did you mean simply 'chdir'?
return ::chdir(_path);
^~~~~~~
chdir
../../../src/os.cpp:270:6: note: 'chdir' declared here
int chdir(const char* _path)
^
1 error generated.
make[2]: *** [../../osx32_clang/obj/x32/Debug/bx/src/os.o] Error 1
make[1]: *** [bx] Error 2
make: *** [osx-debug32] Error 2
Originally was trying to build bgfx and got this error, but was able to see that it's coming from the bx library. Thought reverting to an earlier change might help and it did allow me to build bx on it's own, but bgfx failed with other problems due to missing files or other discrepencies.
Android, among other platforms, have really chatty output which makes it difficult to locate debugOutput from bx.
Suggest adding BX_CONFIG_DEBUG_TAG to add a custom prefix, e.g. Android this would be:
__android_log_write(ANDROID_LOG_DEBUG, BX_CONFIG_DEBUG_TAG, _out);
Other platforms it could be a simple string prefix.
The macro BX_UNUSED_1 doesn't work anymore with msvc 2010.
#define BX_UNUSED_1(_a1) do { (void)sizeof(_a1); } while(0)
working alternatives:
//classical way, by may have side effect with volative vars
#define BX_UNUSED_1(_a1) do { (void)(_a1); } while(0)
or
// pbly a better compromise
// work with incomplete struct/class definition
#define BX_UNUSED_1(_a1) ( &reinterpret_cast< const int& >( _a1 ) )
The Env variable contains the "default" version for the SDK for Visual Studio to use. However, for some reason, it has a backslash at the end at least on my installation. That backslash ends up in the generated vcxproj files. Apparently MSBuild has no problem with this, but the devenv IDE complains and fails to load the projects.
This fix removes the backslash if present. In toolchain.lua(183), add the line shown below:
local windowsPlatform = os.getenv("WindowsSDKVersion") or "8.1"
windowsPlatform = string.gsub(windowsPlatform, "\\", "") -- <---
if _OPTIONS["with-windows"] then
I suppose a more sophisticated option would be to remove anything that isn't a digit or '.' (devenv seems to complain about not being able to compare the versions as numbers) but without an actual test case I can't recommend it.
bgfx's geometryc uses commandline for parsing obj lines.
https://github.com/bkaradzic/bgfx/blob/master/tools/geometryc/geometryc.cpp#L504
If there are spaces before end of line, it reads multiple lines instead of only one.
You can test with a simple test string like this:
"X \r\nY Z\r\n" with term='\n' this gives argc == 3, instead of 1.
If have added an extra test here:
https://github.com/bkaradzic/bx/blob/master/src/commandline.cpp#L42
for (; isSpace(*curr) && *curr != _term; ++curr) {}; // skip whitespace
I saw your twitter about is_pow_of_2
. There is a better implementation of uint32_testpow2
.
The current version is
uint32_t uint32_testpow2(uint32_t _a) {
const uint32_t tmp0 = uint32_not(_a);
const uint32_t tmp1 = uint32_inc(tmp0);
const uint32_t tmp2 = uint32_and(_a, tmp1);
const uint32_t tmp3 = uint32_cmpeq(tmp2, _a);
const uint32_t tmp4 = uint32_cmpneq(_a, 0);
const uint32_t result = uint32_and(tmp3, tmp4);
return result;
}
You can use a better version
uint32_t uint32_testpow2(uint32_t _a) {
const uint32_t tmp0 = uint32_dec(_a);
const uint32_t tmp1 = uint32_xor(_a, tmp0);
const uint32_t tmp2 = uint32_srl(tmp1, 1);
const uint32_t result = uint32_cmpeq(tmp2, tmp0);
return result;
}
Or, If you don't care _a is zero (return true when _a is 0) , you can also use
uint32_t uint32_testpow2(uint32_t _a) {
const uint32_t tmp0 = uint32_dec(_a);
const uint32_t tmp1 = uint32_and(_a, tmp0);
const uint32_t result = uint32_cmpeq(tmp1, 0);
return result;
}
As the title says.. bgfx claims to support freebsd but it seem to need genie binary from bx repo...
I've been toying around following the glfw example and found that to make it work a call to "bgfx::renderFrame()" is needed before calling main.
I'm missing out something or is this supposed to work this way? Is there any other considerations to take into account?
Thanks!
I saw dirent_mbstowcs_s
is implement by mbstowcs_s
or mbstowcs
now : https://github.com/bkaradzic/bx/blob/master/include/compat/msvc/dirent.h#L751-L759
These api is dependent on current locale . For a cross platform library, I think using the same one locale like utf-8 would be better (IMO).
We may use MultiByteToWideChar(CP_UTF8, ...)
directly here instead of mbstowcs
.
I saw inside macros.h you have BX_ALIGNOF which is seams only Visual studio macro, how to resolve this one?
inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...)
{
va_list argList;
va_start(argList, _format);
#if defined(__MINGW32__)
int32_t len = swprintf(_out, _format, argList);
#else
int32_t len = swprintf(_out, _count, _format, argList);
#endif // defined(__MINGW__)
va_end(argList);
return len;
}
The problem is swprintf is interpretting argList as a variadic argument not as a pointer to a list of arguments, thus creating garbage (look at example-10-font frame time as example).
The correct function under msvc is _vsnwprintf (or the secure version).
If you target modern compiler you can also use vswprintf.
I get compile error when including strings.h
the alloca.h does not exist. I guess adding msvc protector macro around it fixes it :
#ifndef BX_COMPILER_MSVC
# include <alloca.h>
#endif
This line:
namespace std { namespace tr1 {}; using namespace tr1;
at https://github.com/bkaradzic/bx/blob/master/include/bx/bx.h#L85
breaks compilation on Visual Studio 2051, when using regex. The compiler complains about an ambiguous symbol (error C2872). Commenting the line solves the issue.
Maybe a define to optionally disable the line?
Normally I wouldn't care, but the new constexpr functions in math.inl use a C++14 feature that Visual Studio 14 2015 doesn't support.
Is it really necessary to have custom abs(), IsFinite(), IsNaN(), etc. ? Can I replace those with std::abs(), std::isinf() and std::isnan()?
https://github.com/bkaradzic/bx/blob/master/include/bx/simd128_langext.inl#L58
this should be simd_swizzle128 I guess.
There is a minor build error in the latest bx in mutex.h
you forget to add BX_PLATFORM_IOS
to the posix thread include at line 16:
#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID || BX_PLATFORM_OSX || BX_PLATFORM_IOS
/usr/bin/x86_64-w64-mingw32-g++ -DWIN32 -DMINGW_HAS_SECURE_API=1 -I../../../lib/bx/include/compat/mingw -I../../../lib/bx/include -fomit-frame-pointer -g -m64 -fno-rtti -std=c++11 -MMD -MF ../obj/x64/Release/bx/lib/bx/src/debug.o.d -c -o ../obj/x64/Release/bx/lib/bx/src/debug.o ../../../lib/bx/src/debug.cpp
../../../lib/bx/src/debug.cpp: In function ‘void bx::debugPrintfData(const void*, uint32_t, const char*, ...)’:
../../../lib/bx/src/debug.cpp:93:25: error: expected ‘)’ before ‘PRIxPTR’
#define DBG_ADDRESS "%" PRIxPTR
^
../../../lib/bx/src/debug.cpp:106:26: note: in expansion of macro ‘DBG_ADDRESS’
debugPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
^~~~~~~~~~~
../../../lib/bx/src/debug.cpp:93:25: error: expected ‘)’ before ‘PRIxPTR’
#define DBG_ADDRESS "%" PRIxPTR
^
../../../lib/bx/src/debug.cpp:126:23: note: in expansion of macro ‘DBG_ADDRESS’
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
^~~~~~~~~~~
../../../lib/bx/src/debug.cpp:93:25: error: expected ‘)’ before ‘PRIxPTR’
#define DBG_ADDRESS "%" PRIxPTR
^
../../../lib/bx/src/debug.cpp:136:22: note: in expansion of macro ‘DBG_ADDRESS’
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
^~~~~~~~~~~
mingw version 6.3.1
I'm not terribly familiar with the inttypes.h
and my macro fu needs some work, so hopefully this is legit and I'm not just doing something stupid 👍
update: changing -MMD
to -M
s-MMD
flag! turns out I'm just being dumb.
update: this ticket is a dumpster fire. I just needed to define __STDC_FORMAT_MACROS
, which you already define in your toolchain.lua
setThreadName sets the current calling thread name instead of newly created one in iOS/MacOs.
On those platforms you have to keep the name and call pthread_setname_np
in thread's entry func.
Per my remarks in this thread: bkaradzic/bgfx#1200
MSVC 2015 deprecated the _HAS_ITERATOR_DEBUGGING macro, and its use makes BGFX's generated Visual Studio projects incompatible with standard ones (for debug builds). Otherwise the libraries are fully compatible.
The problem can be worked around by disabling this line: https://github.com/bkaradzic/bx/blob/master/scripts/toolchain.lua#L552
I suggest removing this definition, or making it optional in Genie (and off by default).
{ 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1,35,
0, 0, 0, 1};
{ 0.974278, 0, 0, 0,
0, 1.732050, 0, 0,
0, 0, 1.000101, -0.100100,
0, 0, 1, 0};
float4x4_mul result:
0.974278 , 0 , 0 , 0
0 , 1.73205 , 0 , 0
0 , 0 , 36.0001 , 1
0 , 0 , -0.1001 , 0
OpenGL Mathematics (GLM) result:
0.974278 , 0 , 0 , 0
0 , 1.73205 , 0 , 0
0 , 0 , 1.0001 , 1
0 , 0 , 34.9034 , 35
inline int32_t vsnwprintf(wchar_t* _str, size_t _count, const wchar_t* _format, va_list _argList)
{
#if BX_COMPILER_MSVC
int32_t len = ::_vsnwprintf_s(_str, _count*sizeof(wchar_t), _count, _format, _argList);
return -1 == len ? ::_vscwprintf(_format, _argList) : len;
#elif defined(__MINGW32__)
return ::vsnwprintf(_str, _count, _format, _argList);
#else
return ::vswprintf(_str, _count, _format, _argList);
#endif // BX_COMPILER_MSVC
}
The problem is that _vsnwprintf_s second argument must be in "words" and not in char, the way it is now it corrupts memory.
You can validate that by looking at the definition in msvc stdio.h implementation.
There the second argument is called "size_t _SizeInWords".
Microsoft official online documentation is wrong and the argument is missnamed -_-
http://msdn.microsoft.com/en-us/library/d3xd30zz(v=vs.100).aspx
Someone also pointed this in comments.
so:
int32_t len = ::_vsnwprintf_s(_str, _count*sizeof(wchar_t), _count, _format, _argList);
should be
int32_t len = ::_vsnwprintf_s(_str, _count, _count, _format, _argList);
The toolchain script currently only allows configuring the windowsTargetPlatformVersion project setting if the toolset target is set to "--vs=winstore82". Otherwise the project setting will default to 8.1. It seems this parameter should be settable always. Three suggestions (can't make a pull request right now):
Move the 3 lines that assign the platform, from the "winstore82" subsection up to the enclosing if, right before starting to check specific "--vs" toolsets.
or _ACTION == "vs2013"
or _ACTION == "vs2015"
or _ACTION == "vs2017"
then
local action = premake.action.current()
action.vstudio.windowsTargetPlatformVersion = windowsPlatform
action.vstudio.windowsTargetPlatformMinVersion = windowsPlatform
if (_ACTION .. "-clang") == _OPTIONS["vs"] then
Allow a smarter default for the "--with-windows" argument that sets the "windowsPlatform" variable, based on the standard environment variable "WindowsSDKVersion", and in its absence, default to a more conservative platform of 8.1.
local windowsPlatform = "8.1"
if os.getenv("WindowsSDKVersion") then
windowsPlatform = os.getenv("WindowsSDKVersion")
end
if _OPTIONS["with-windows"] then
windowsPlatform = _OPTIONS["with-windows"]
end
Perhaps the various toolsets may enforce higher values for this setting, so for example if requesting winstore82 then convert 8.1 into the previous default of 10.0.10240.0
Update the newoption for with-windows to describe the new default more accurately.
newoption {
trigger = "with-windows",
value = "#",
description = "Set the Windows target platform version (default: $WindowsSDKVersion or 8.1).",
}
Running action 'xcode4'...
Generating ../.build/projects/xcode4/bx.xcworkspace/contents.xcworkspacedata...
[string "function string.explode(s, pattern, plain)..."]:15: stack overflow
stack traceback:
[string "function string.explode(s, pattern, plain)..."]:15: in function 'string.findlast'
[string "function path.getabsolute(p)..."]:39: in function 'path.getdirectory'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
...
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.project = { }..."]:11: in field 'buildsourcetree'
[string "local xcode = premake.xcode..."]:4: in field 'buildprjtree'
[string "local xcode = premake.xcode..."]:95: in local 'callback'
[string "premake._filelevelconfig = false..."]:5: in field 'generate'
[string "premake.xcode = { }..."]:68: in field 'onproject'
[string "premake.action = { }..."]:23: in field 'call'
[string "_WORKING_DIR = os.getcwd()..."]:82: in function '_premake_main'
I have run into same issue with dtoa.cpp as described here: miloyip/dtoa-benchmark#7
fix: Tencent/rapidjson@fe550f3
To get VS2012 to compile I had to add this to bx/string.h
# include <malloc.h>
# define alloca _alloca
# elif
# include <alloca.h>
# endif
Please see here.
Hay bkaradzic,
first of all, you've done a great work, but I've encountered an error:
If i set my Scale with mtxScale and after that the Translate with mtxTranslate, so my Scale is gone, if i change the order, then it cleans me my Translate in my mtxMesh.
I have a Scons project that I am incorporating BGFX into. It would be great to build BGFX from Scons so I am working on the build scripts. I am getting the following errors. Any ideas?
#define DBG_ADDRESS "%" PRIxPTR
^
F:/LibSources/BGFX/bx/src/debug.cpp:111:14: note: to match this '('
debugPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
^
F:/LibSources/BGFX/bx/src/debug.cpp:131:23: error: expected ')'
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
^
F:/LibSources/BGFX/bx/src/debug.cpp:98:25: note: expanded from macro 'DBG_ADDRESS'
#define DBG_ADDRESS "%" PRIxPTR
^
F:/LibSources/BGFX/bx/src/debug.cpp:131:17: note: to match this '('
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
^
F:/LibSources/BGFX/bx/src/debug.cpp:141:22: error: expected ')'
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
^
F:/LibSources/BGFX/bx/src/debug.cpp:98:25: note: expanded from macro 'DBG_ADDRESS'
#define DBG_ADDRESS "%" PRIxPTR
^
F:/LibSources/BGFX/bx/src/debug.cpp:141:16: note: to match this '('
debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
I have built BGFX with Clang using make successfully so it is probably something I am not setting properly.
ex. using the bx library to reference to that function "bx::CrtFileReader reader;" causes gcc to complain that CrtFileReader is not a part of bx, breaking the compile of things that rely on the class, i.e. OSD bgfx interface.
tested with Alpine Linux edge branch, gcc 6.4.0
Hello,
I am using a G4 PowerMac with OSX 10.5.8 to compile latest SDLmame release, I have set up the makefile to use GCC 7.2 compiler but when I reach the BX libraries here is what happens:
Compiling 3rdparty/bx/src/crtnone.cpp... ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'void* strcpy(char*, const char*)': ../../../../../3rdparty/bx/src/crtnone.cpp:50:18: warning: declaration of 'void* strcpy(char*, const char*)' conflicts with built-in declaration 'char* strcpy(char*, const char*)' [-Wbuiltin-declaration-mismatch] extern "C" void* strcpy(char* _dst, const char* _src) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'void* strncpy(char*, const char*, size_t)': ../../../../../3rdparty/bx/src/crtnone.cpp:56:18: warning: declaration of 'void* strncpy(char*, const char*, size_t)' conflicts with built-in declaration 'char* strncpy(char*, const char*, long unsigned int)' [-Wbuiltin-declaration-mismatch] extern "C" void* strncpy(char* _dst, const char* _src, size_t _num) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'const char* strchr(const char*, int)': ../../../../../3rdparty/bx/src/crtnone.cpp:68:24: warning: declaration of 'const char* strchr(const char*, int)' conflicts with built-in declaration 'char* strchr(const char*, int)' [-Wbuiltin-declaration-mismatch] extern "C" const char* strchr(const char* _str, int _ch) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'const char* strstr(const char*, const char*)': ../../../../../3rdparty/bx/src/crtnone.cpp:83:24: warning: declaration of 'const char* strstr(const char*, const char*)' conflicts with built-in declaration 'char* strstr(const char*, const char*)' [-Wbuiltin-declaration-mismatch] extern "C" const char* strstr(const char* _str, const char* _find) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'int isprint(int)': ../../../../../3rdparty/bx/src/crtnone.cpp:94:16: error: redefinition of 'int isprint(int)' extern "C" int isprint(int _ch) ^~~~~~~ In file included from /usr/include/_wctype.h:63:0, from /usr/include/wchar.h:114, from ../../../../../3rdparty/bx/include/bx/string.h:11, from ../../../../../3rdparty/bx/include/bx/error.h:9, from ../../../../../3rdparty/bx/include/bx/readerwriter.h:10, from ../../../../../3rdparty/bx/src/crtnone.cpp:8: /usr/include/ctype.h:272:1: note: 'int isprint(int)' previously defined here isprint(int _c) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'int toupper(int)': ../../../../../3rdparty/bx/src/crtnone.cpp:99:16: error: redefinition of 'int toupper(int)' extern "C" int toupper (int _ch) ^~~~~~~ In file included from /usr/include/_wctype.h:63:0, from /usr/include/wchar.h:114, from ../../../../../3rdparty/bx/include/bx/string.h:11, from ../../../../../3rdparty/bx/include/bx/error.h:9, from ../../../../../3rdparty/bx/include/bx/readerwriter.h:10, from ../../../../../3rdparty/bx/src/crtnone.cpp:8: /usr/include/ctype.h:315:1: note: 'int toupper(int)' previously defined here toupper(int _c) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'float powf(float)': ../../../../../3rdparty/bx/src/crtnone.cpp:161:18: warning: declaration of 'float powf(float)' conflicts with built-in declaration 'float powf(float, float)' [-Wbuiltin-declaration-mismatch] extern "C" float powf(float _x) ^~~~ ../../../../../3rdparty/bx/src/crtnone.cpp:167:19: warning: declaration of 'double pow(double)' conflicts with built-in declaration 'double pow(double, double)' [-Wbuiltin-declaration-mismatch] extern "C" double pow(double _x) ^~~ make[2]: *** [../../../../osx_clang/obj/x32/Release/3rdparty/bx/src/crtnone.o] Error 1 make[1]: *** [bx] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [macosx_x86] Error 2
As partial workaround to let the compile process to go ahead I have manually deleted the "toUpper" and "isPrint" definitions from crtnone.cpp but I don't know how to fix this issue since I am not strictly a programmer. Can this be fixed in some way? Many thanks in advance.
I think the problem could be that line 103 of toolchain.lua referes to BUILD_DIR that doesn't exist.
Possible fix could be to replace BUILD_DIR with _buildDir.
Here below the console error produced:
[string "function os.executef(cmd, ...)..."]:174: attempt to concatenate a nil value (local 'p')
stack traceback:
[string "function os.executef(cmd, ...)..."]:174: in function 'os.rmdir'
C:/DEV/GITHUB/bx/scripts/toolchain.lua:103: in function 'toolchain'
C:/DEV/GITHUB/bgfx/scripts/genie.lua:89: in main chunk
[C]: in upvalue 'builtin_dofile'
[string "premake = { }..."]:84: in function 'dofile'
[string "_WORKING_DIR = os.getcwd()..."]:41: in function '_premake_main'
Hi,
I would like to do some full-screen 3D programming on the Raspberry Pi using SDL2 (like retropie). I would also like to use imgui as part of the UI. Given the constraints of the rpi platform and my requirements, I think C++ and bgfx is the best way. You have great documentation and your examples look fantastic.
I tried building bgfx, but I suspected ahead of time that this wouldn't work. The configuration wasn't listed in the 'building' section. If this is too far out of scope for bgfx, I will respect that.
Here is what I did.
I downloaded the latest Raspbian and installed that on a microsd.
I cloned the repos in the build instructions. I then rebuilt genie for linux.
This version of Raspbian (Pixel) already had the gcc toolchain, which was nice.
I then ran:
../genie/bin/linux/genie --with-examples --with-sdl --gcc=rpi gmake
then:
make rpi -j4
The compiles are failing on X11 includes. I didn't install those libs because I am going to run this as a fullscreen SDL2 app.
What should I change to get further?
I'd like to add Meson build scripts to bgfx
, bx
and bimg
in order to make them available through Meson's dependency DB (Wrap).
If it's something you'd accept, @bkaradzic, I'd be glad to throw PRs at you :)
Just to give you some background, Meson is a C/C++ focused multiplatform build system slightly similar to Gradle (IMHO).
template<CharFn fn>
inline const char* strFind(const char* _str, int32_t _strMax, const char* _find, int32_t _findMax)
The strFind template function will cause an out of bounds read on _str if _find is an empty string (_findMax == 0). A check should be added at the top of the function, something like:
if (!(_strMax && _findMax)) return NULL;
Basically it doesn't build with GCC 8 and -std=c++11
, i looked into issues and found that similar issue (bkaradzic/bgfx#1567) appeared in VS2015 and indeed constexpr
was disabled for VS2015, so i did the following change to fix build:
diff --git a/include/bx/macros.h b/include/bx/macros.h
index 7a9b643..a603141 100644
--- a/include/bx/macros.h
+++ b/include/bx/macros.h
@@ -115,7 +115,7 @@
/// The return value of the function is solely a function of the arguments.
///
-#if BX_COMPILER_MSVC && (BX_COMPILER_MSVC <= 1900)
+#if (BX_COMPILER_MSVC && (BX_COMPILER_MSVC <= 1900)) || (BX_COMPILER_GCC && (__cplusplus < 201300))
# define BX_CONSTEXPR_FUNC BX_CONST_FUNC
#else
# define BX_CONSTEXPR_FUNC constexpr BX_CONST_FUNC
I think __cplusplus
should work for VS2015 too, but i didn't check so i did this change specifically for GCC, no other changes were required as far as i can see.
Alternatively all those constexpr
parts could be rewritten to fit C++11 requirements, but it won't be pretty.
I know that Genie build enables -std=c++14
on bx, but i use homemade CMake scripts for building bx/bimg/bgfx and i don't really feel like switching C++ revision to 14.
Does that fix look good? I can create PR if needed, or how would you recommend to approach this?
bgfx/bx builds normally for latest android ndk (16.1 at this time). But generated bx library is unusable because of invalid references to stdin/stdout:
../../../../bx/src/file.cpp:0: error: undefined reference to 'stdout'
../../../../bx/src/file.cpp:0: error: undefined reference to 'stdout'
../../../../bx/src/file.cpp:0: error: undefined reference to 'stderr'
I get crashes in android implemnetation on sqrt calls:
I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x9f8dffe4
05-10 14:36:05.528 273-273/? E/DEBUG: AM write failure (32 / Broken pipe)
05-10 14:36:05.528 273-273/? I/DEBUG: backtrace:
05-10 14:36:05.528 273-273/? I/DEBUG: #00 pc 00197af4 /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrtSimd(float)+27)
05-10 14:36:05.528 273-273/? I/DEBUG: #01 pc 00197ad1 /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrt(float)+18)
05-10 14:36:05.528 273-273/? I/DEBUG: #02 pc 00197b69 /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrtSimd(float)+144)
05-10 14:36:05.528 273-273/? I/DEBUG: #03 pc 00197ad1 /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrt(float)+18)
...
It seems like it goes through infinite recursive calls and crashes the program due to this implementation:
BX_SIMD_FORCE_INLINE simd128_langext_t simd_sqrt(simd128_langext_t _a)
{
simd128_langext_t result;
result.vf[0] = sqrt(_a.vf[0]);
result.vf[1] = sqrt(_a.vf[1]);
result.vf[2] = sqrt(_a.vf[2]);
result.vf[3] = sqrt(_a.vf[3]);
return result;
}
https://github.com/fish2000/homebrew-praxa/blob/master/bx.rb
… notes and/or PRs are always welcome. Cheers!
Line 81 in f191b11
Hello,
I'm trying to compile the android version with:
make android-arm
or
make android-x86
with the atest repo's git files.
I alreay tested with:
macOS High Sierra (all updated XCode and files)
Ubuntu 16.04 64-bit (the 32-bit genie does not works :))
Ubuntu 17.04 64-bit as well
With the NDKs versions:
android-ndk-r10e
android-ndk-r16b (latest)
All with the same error.
First, I set the 3 main env:
ANDROID_NDK_ROOT=/dev/android/android-ndk-r16b
ANDROID_NDK_ARM=/dev/android/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
ANDROID_NDK_CLANG=/dev/android/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64
The first error is the:
In file included from ../../../../bx/src/bx_p.h:42:
../../../../bx/include/bx/bx.h:9:10: fatal error: 'alloca.h' file not found
#include <alloca.h> // alloca
^~~~~~~~~~
1 error generated.
bx.make:395: recipe for target '../../android-arm/obj/Debug/bx/bx/src/allocator.o' failed
It seems that android has not a compat/android-arm or compat/android to put alloca.h, so I removed the #include <alloca.h>.
Then goes to next error:
==== Building bx (debug) ====
allocator.cpp
In file included from ../../../../bx/src/allocator.cpp:6:
In file included from ../../../../bx/src/bx_p.h:42:
In file included from ../../../../bx/include/bx/bx.h:11:
In file included from /dev/android/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/stdint.h:102:
/dev/android/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/__config:169:10: fatal error:
'features.h' file not found
#include <features.h>
^~~~~~~~~~~~
1 error generated.
bx.make:395: recipe for target '../../android-arm/obj/Debug/bx/bx/src/allocator.o' failed
Everytime I try to fix some header (deleting it to check), a new error appears.
Which NDK version should I try?
Thanks.
This code demonstrates a mismatch between the definition of "euler" angles used by quatToEuler and the definition (non-explicitly) used by mtxSRT. This created a bit of confusion for me when I was dipping my toes in BGFX.
void CheckBxEulerMath()
{
float eulers[3] = { bx::kPiQuarter, bx::kPiQuarter, bx::kPiQuarter };
float qX[4];
float qY[4];
float qZ[4];
float qXqY[4];
float qZqXqY[4];
bx::quatRotateX(qX, eulers[0]);
bx::quatRotateY(qY, eulers[1]);
bx::quatRotateZ(qZ, eulers[2]);
bx::quatMul(qXqY, qX, qY);
bx::quatMul(qZqXqY, qZ, qXqY);
float mtxFromQuat[16];
bx::mtxQuat(mtxFromQuat, qZqXqY);
float mtxFromSRT[16];
bx::mtxSRT(
mtxFromSRT,
1.0f, 1.0f, 1.0f,
eulers[0], eulers[1], eulers[2],
0.0f, 0.0f, 0.0f);
float eulersFromQuat[3];
bx::quatToEuler(eulersFromQuat, qZqXqY);
for (int idx = 0; idx < 16; idx++)
{
if (!bx::equal(mtxFromQuat[idx], mtxFromSRT[idx], 0.00001f)) {
BX_TRACE("mtxFromQuat does not equal mtxFromSRT");
abort();
}
}
for (int idx = 0; idx < 3; idx++)
{
if (!bx::equal(eulers[idx], eulersFromQuat[idx], 0.1f))
{
BX_TRACE("eulers is way different from eulersFromQuat");
abort();
}
}
}
I know that the historic correct definition for Euler angles is different from what mtxSRT gets passed but it would be nice for this discrepancy to fixed or made explicit.
Perhaps you could add these functions
void quatPitchYawRoll(float* _result, float _pitch, float _yaw, float _roll);
void quatToPitchYawRoll(float* _result, const float* _quat);
and document how to compose the output of mtxSRT using individual transformations?
Thank you for your time and your open source projects.
Hi,
I'm using the SpScBlockingUnboundedQueue in my project a lot and it works great. However, I noticed something strange when I use pop method with wait time. If my wait time is anything over 1000, it seems to be working fine, but when I pass 999 or less, the wait time is very short or nonexistent. So I looked into the semaphore code and found this:
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
ts.tv_sec += _msecs/1000;
ts.tv_nsec += (_msecs%1000)*1000;
Shouldn't it be ts.tv_nsec += (_msecs%1000)*1000000;
instead because nanoseconds? Assuming _msecs means milliseconds. I'm running the code on Android.
Thanks,
Luka
Hey I've been trying to compile my own game engine that uses bgfx for rendering and I keep running into this error that it says is coming from the bx library. The errors are shown below.
Does anybody have any idea what could be causing this? I'm compiling with visual studio 2019. I should note that when I built all of the libraries necessary for bgfx seperately they compiled just fine and the .lib files are included in the project. Also the project that I am trying to build builds a .lib and not a .exe
I see in the toolchain there is no direct support for the PS4 (Orbis) in Visual Studio but just for GMake.
found a bug in bx/commandline.h line 142, findOption using a long name never find the result,
const char* find(const char _short, const char* _long, int _numParams) const
{
for (int ii = 0; ii < m_argc; ++ii)
{
const char* arg = m_argv[ii];
if ('-' == *arg)
{
++arg;
if (_short == *arg)
{
should be :
if ('-' == *arg)
{
if (_short == *(arg + 1))
{
++arg;
I wouldn't even be submitting this bug if I didn't see you were trying to account for musl libc runtimes in your platform.h
with BX_CRT_MUSL
, but due to musl not exposing any sort of identifying #defines
, I'm not quite sure how to deal with this. Simply defining BX_CRT_MUSL=1
in an else
clause seems less than optimal.
Maybe my best solution is just to ditch my Alpine Linux / musl libc test pipeline for something more sensible?
This "works" in bx/include/platform.h
#if !BX_CRT_NONE
// https://sourceforge.net/p/predef/wiki/Libraries/
# if defined(__BIONIC__)
# undef BX_CRT_BIONIC
# define BX_CRT_BIONIC 1
# elif defined(_MSC_VER)
# undef BX_CRT_MSVC
# define BX_CRT_MSVC 1
# elif defined(__GLIBC__)
# undef BX_CRT_GLIBC
# define BX_CRT_GLIBC (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100)
# elif defined(__MINGW32__) || defined(__MINGW64__)
# undef BX_CRT_MINGW
# define BX_CRT_MINGW 1
# elif defined(__apple_build_version__) || defined(__ORBIS__) || defined(__EMSCRIPTEN__)
# undef BX_CRT_LIBCXX
# define BX_CRT_LIBCXX 1
# else
# undef BX_CRT_MUSL // THIS SEEMS LIKE
# define BX_CRT_MUSL 1 // A POOR SOLUTION
# endif //
SDK version:10.0.10240.0
template<>
inline int64_t atomicFetchAndAdd<int64_t>(volatile int64_t* _ptr, int64_t _add)
{
return _InterlockedExchangeAdd64( (volatile int64_t*)_ptr, _add);
....
It seems thar the function not support the Win32 platform.
https://msdn.microsoft.com/zh-cn/library/windows/desktop/191ca0sk(v=vs.85).aspx
https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms683599(v=vs.85).aspx
Hi, since I wanna to compile bx as a shared library, I wrote a CMakeLists.txt file to do it. Here is my file. Pretty simple!
cmake_minimum_required (VERSION 2.8)
project (bx)
include_directories (./include)
include_directories (./3rdparty)
aux_source_directory (./src SRC_DIR)
set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
add_library (bx SHARED ${SRC_DIR})
After use "cmake ." command, and then use "make" command to compile it. I got a problem. The compiler told me that I defined many functions twice in amalgamated.o. I found the file, and opened it. I'm confused. Why do you need to include so many cpp files? when I delete this file, my SHARED library was finished.
I know you must have some reasons to do so, but I can't tell it. So, could you help me ?
Compiling with MinGW produces the error:
alloca.h: No such file or directory
include/string.h:10 should be:
#if defined(WIN32) || defined(__WIN32) || defined(__WIN32__)
#include <malloc.h>
#else
#include <alloca.h>
#endif
Those internal functions change after upgrading gcc (e.g. from 4.9 -> 5.2), and breaks compilation.
At the same time there's a stable, standard & well documented way to use those functions:
https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/ARM-NEON-Intrinsics.html
Why not use these?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.