Skip to content

Commit

Permalink
DOOM3: Phobos fix
Browse files Browse the repository at this point in the history
  • Loading branch information
glKarin committed Nov 19, 2024
1 parent 133ae99 commit 76e49ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.changelog
Original file line number Diff line number Diff line change
@@ -1 +1 @@
doom3bfg, thedarkmod on mali GPU, phobos
doom3bfg, thedarkmod on mali GPU, phobos fix
8 changes: 8 additions & 0 deletions Q3E/src/main/jni/doom3/neo/idlib/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ int idLexer::ReadWhiteSpace(void)
{
while (1) {
// skip white space
#if defined(__arm__) || defined(__aarch64__) //karin: char is unsigned on arm. Or compile with -fsigned-char option
while (*(signed char *)idLexer::script_p <= ' ') {
#else
while (*idLexer::script_p <= ' ') {
#endif
if (!*idLexer::script_p) {
return 0;
}
Expand Down Expand Up @@ -1389,7 +1393,11 @@ const char *idLexer::ReadRestOfLine(idStr &out)
break;
}

#if defined(__arm__) || defined(__aarch64__) //karin: char is unsigned on arm. Or compile with -fsigned-char option
if (*(signed char *)idLexer::script_p <= ' ') {
#else
if (*idLexer::script_p <= ' ') {
#endif
out += " ";
} else {
out += *idLexer::script_p;
Expand Down
15 changes: 15 additions & 0 deletions Q3E/src/main/jni/doom3/neo/renderer/ModelOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,19 @@ void idRenderModelOverlay::CreateOverlay(const idRenderModel *model, const idPla
}

// make temporary buffers for the building process
#ifdef _DYNAMIC_ALLOC_STACK_OR_HEAP
overlayVertex_t *overlayVerts;
glIndex_t *overlayIndexes;

const int overlayVerts_size = maxVerts * sizeof(*overlayVerts);
const int overlayIndexes_size = maxIndexes * sizeof(*overlayIndexes);

_DROID_ALLOC(overlayVertex_t, overlayVerts_size, overlayVerts, 0);
_DROID_ALLOC16(glIndex_t, overlayIndexes_size, overlayIndexes, 1);
#else
overlayVertex_t *overlayVerts = (overlayVertex_t *)_alloca(maxVerts * sizeof(*overlayVerts));
glIndex_t *overlayIndexes = (glIndex_t *)_alloca16(maxIndexes * sizeof(*overlayIndexes));
#endif

// pull out the triangles we need from the base surfaces
for (surfNum = 0; surfNum < model->NumBaseSurfaces(); surfNum++) {
Expand Down Expand Up @@ -253,6 +264,10 @@ void idRenderModelOverlay::CreateOverlay(const idRenderModel *model, const idPla
materials[i]->surfaces.RemoveIndex(0);
}
}
#ifdef _DYNAMIC_ALLOC_STACK_OR_HEAP
_DROID_FREE(overlayVerts, 0)
_DROID_FREE(overlayIndexes, 1)
#endif
}

/*
Expand Down
24 changes: 19 additions & 5 deletions Q3E/src/main/jni/doom3/neo/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2178,26 +2178,40 @@ struct idAllocAutoHeap {
// alloc in heap memory
#define _alloca16_heap( x ) ((void *)((((intptr_t)calloc( (x)+15 ,1 )) + 15) & ~15))

// Using heap memory. Also reset RLIMIT_STACK by call `setrlimit`.
// Using heap memory. Also reset RLIMIT_STACK by call `setrlimit`.
#define _DROID_ALLOC16_DEF(T, alloc_size, varname, x) \
idAllocAutoHeap _allocAutoHeap##x; \
T *varname = (T *) (HARM_MAX_STACK_ALLOC_SIZE == 0 || (HARM_MAX_STACK_ALLOC_SIZE > 0 && (alloc_size) >= HARM_MAX_STACK_ALLOC_SIZE) ? _allocAutoHeap##x.Alloc16(alloc_size) : _alloca16(alloc_size)); \
if(_allocAutoHeap##x.IsAlloc()) { \
_ALLOC_DEBUG(common->Printf("[Harmattan]: Alloca on heap memory %s %p(%zu bytes)\n", #varname, varname, (size_t)alloc_size)); \
_ALLOC_DEBUG(common->Printf("[Harmattan]: Alloca16 on heap memory %s %p(%zu bytes)\n", #varname, varname, (size_t)alloc_size)); \
}

#define _DROID_ALLOC16(T, alloc_size, varname, x) \
idAllocAutoHeap _allocAutoHeap##x; \
varname = (T *) (HARM_MAX_STACK_ALLOC_SIZE == 0 || (HARM_MAX_STACK_ALLOC_SIZE > 0 && (alloc_size) >= HARM_MAX_STACK_ALLOC_SIZE) ? _allocAutoHeap##x.Alloc16(alloc_size) : _alloca16(alloc_size)); \
if(_allocAutoHeap##x.IsAlloc()) { \
_ALLOC_DEBUG(common->Printf("[Harmattan]: Alloca16 on heap memory %s %p(%zu bytes)\n", #varname, varname, (size_t)alloc_size)); \
}

#define _DROID_ALLOC_DEF(T, alloc_size, varname, x) \
idAllocAutoHeap _allocAutoHeap##x; \
T *varname = (T *) (HARM_MAX_STACK_ALLOC_SIZE == 0 || (HARM_MAX_STACK_ALLOC_SIZE > 0 && (alloc_size) >= HARM_MAX_STACK_ALLOC_SIZE) ? _allocAutoHeap##x.Alloc(alloc_size) : _alloca(alloc_size)); \
if(_allocAutoHeap##x.IsAlloc()) { \
_ALLOC_DEBUG(common->Printf("[Harmattan]: Alloca on heap memory %s %p(%zu bytes)\n", #varname, varname, (size_t)alloc_size)); \
}

#define _DROID_ALLOC(T, alloc_size, varname, x) \
idAllocAutoHeap _allocAutoHeap##x; \
varname = (T *) (HARM_MAX_STACK_ALLOC_SIZE == 0 || (HARM_MAX_STACK_ALLOC_SIZE > 0 && (alloc_size) >= HARM_MAX_STACK_ALLOC_SIZE) ? _allocAutoHeap##x.Alloc(alloc_size) : _alloca(alloc_size)); \
if(_allocAutoHeap##x.IsAlloc()) { \
_ALLOC_DEBUG(common->Printf("[Harmattan]: Alloca on heap memory %s %p(%zu bytes)\n", #varname, varname, (size_t)alloc_size)); \
}

// free memory when not call alloca()
#define _DROID_FREE(varname, x)/* \
#define _DROID_FREE(varname, x) \
{ \
common->Printf("[Harmattan]: Free alloca heap memory %p\n", varname); \
}*/
_ALLOC_DEBUG(common->Printf("[Harmattan]: Free alloca heap memory %p\n", varname)); \
}

#endif

Expand Down
5 changes: 3 additions & 2 deletions Q3E/src/main/jni/tdm/renderer/backend/GLSLProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ GLuint GLSLProgram::CompileShader( GLint shaderType, const char *sourceFile, con
}

#ifdef _GLES //karin: force use medium precision in GLSL shader
const std::string nameStr(sourceFile);
const bool IsInteractionShader = nameStr.find("interaction") == 0;
idStr nameStr(sourceFile);
nameStr.StripPath();
const bool IsInteractionShader = nameStr.Find("interaction") == 0;
if(!IsInteractionShader && harm_r_useMediumPrecision.GetBool())
{
const std::string highp("precision highp float;");
Expand Down
4 changes: 2 additions & 2 deletions idTech4Amm/src/main/java/com/n0n3m4/DIII4A/GameLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ public void onClick(DialogInterface dialog, int which)

private void OpenRuntimeErrorLog()
{
String path = KStr.AppendPath(V.edt_path.getText().toString(), Q3EUtils.q3ei.GetGameDataDirectoryPath("stderr.txt"));
String path = Q3EUtils.q3ei.GetGameDataDirectoryPath("stderr.txt");
String text = Q3EUtils.file_get_contents(path);

AlertDialog.Builder builder = ContextUtility.CreateMessageDialogBuilder(this, Q3ELang.tr(this, R.string.last_runtime_log) + ": stderr.txt", text);
Expand All @@ -2165,7 +2165,7 @@ public void onClick(DialogInterface dialog, int which)

private void OpenRuntimeLog()
{
String path = KStr.AppendPath(V.edt_path.getText().toString(), Q3EUtils.q3ei.GetGameDataDirectoryPath("stdout.txt"));
String path = Q3EUtils.q3ei.GetGameDataDirectoryPath("stdout.txt");
String text = Q3EUtils.file_get_contents(path);

AlertDialog.Builder builder = ContextUtility.CreateMessageDialogBuilder(this, Q3ELang.tr(this, R.string.last_runtime_log), text);
Expand Down

0 comments on commit 76e49ba

Please sign in to comment.