Skip to content

rc5-72/opencl: Fix Intel Xe Graphics compatibility #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions common/logstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,23 +493,41 @@ static void InternalLogMail( const char *msgbuffer, unsigned int msglen, int /*f
// a (va_list *) instead to avoid this problem
void LogWithPointer( int loggingTo, const char *format, va_list *arglist )
{
char msgbuffer[1024]; //min 1024!!, but also think of other OSs stack!!
int scrwidth = ASSUMED_SCREEN_WIDTH; /* assume this for consistency */
ConGetSize(&scrwidth,NULL); /* sets to 80 or does not touch if not supported */

char fixed_msgbuffer[1024]; //min 1024!!, but also think of other OSs stack!!
char *msgbuffer = &fixed_msgbuffer[0];

//the code below may insert some characters
unsigned extra_bytes = scrwidth > 4 ? scrwidth : 4;

unsigned int msglen = 0, sel;
char *buffptr, *obuffptr;
int old_loggingTo = loggingTo;

msgbuffer[0]=0;
loggingTo &= (logstatics.loggingTo|LOGTO_RAWMODE);

if ( !format || !*format )
loggingTo = LOGTO_NONE;

if ( loggingTo != LOGTO_NONE )
{
if ( arglist == NULL )
strcat( msgbuffer, format );
else
vsprintf( msgbuffer, format, *arglist );
if ( arglist == NULL ) {
const size_t len = strlen(format);
if (len >= sizeof(fixed_msgbuffer) - extra_bytes) {
msgbuffer = (char *)malloc(len + 1 + extra_bytes);
if (msgbuffer) {
memcpy(msgbuffer, format, len + 1);
} else {
msgbuffer = &fixed_msgbuffer[0];
memcpy(msgbuffer, format, sizeof(fixed_msgbuffer) - 1 - extra_bytes);
msgbuffer[sizeof(fixed_msgbuffer) - 1 - extra_bytes] = 0;
}
} else
memcpy(msgbuffer, format, len + 1);
} else
vsnprintf(msgbuffer, sizeof(fixed_msgbuffer) - extra_bytes, format, *arglist);
msglen = strlen( msgbuffer );

if ( msglen == 0 )
Expand Down Expand Up @@ -571,9 +589,6 @@ void LogWithPointer( int loggingTo, const char *format, va_list *arglist )

if (( loggingTo & LOGTO_SCREEN ) != 0)
{
int scrwidth = ASSUMED_SCREEN_WIDTH; /* assume this for consistancy */
ConGetSize(&scrwidth,NULL); /* gets set to 80 or untouched, if not supported */

#ifdef ASSERT_WIDTH_80 //"show" where badly formatted lines are cropping up
//if (logstatics.stdoutisatty)
{
Expand Down Expand Up @@ -645,6 +660,10 @@ void LogWithPointer( int loggingTo, const char *format, va_list *arglist )
}
}

if (msgbuffer != &fixed_msgbuffer[0]) {
free(msgbuffer);
}

return;
}

Expand Down Expand Up @@ -716,6 +735,11 @@ void LogRaw( const char *format, ... )
return;
}

void LogRawString( const char *str )
{
LogWithPointer( LOGTO_RAWMODE | LOGAS_LOG, str, NULL);
}

void LogTo( int towhat, const char *format, ... )
{
va_list argptr;
Expand Down
3 changes: 3 additions & 0 deletions common/logstuff.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ extern void LogScreenRaw( const char *format, ... ) __CHKFMT_PRINTF;
//Log to mail+file+screen. No adjustments.
extern void LogRaw( const char *format, ... ) __CHKFMT_PRINTF;

//Log to mail+file+screen. No adjustments. Supports very long strings but not formatting.
extern void LogRawString( const char *str );

//Log to LOGTO_* flags (RAW implies screen)
extern void LogTo( int towhat, const char *format, ... ) __CHKFMT_LOGTO;

Expand Down
19 changes: 13 additions & 6 deletions rc5-72/opencl/ocl_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,14 @@ bool BuildCLProgram(ocl_context_t *cont, const char* programText, const char *ke
free(decompressed_src);
if (status == CL_SUCCESS)
{
//status = clBuildProgram(cont->program, 1, &cont->deviceID, NULL, NULL, NULL);
status = clBuildProgram(cont->program, 1, &cont->deviceID, "-cl-std=CL1.1", NULL, NULL);
//"-cl-std=CL1.1" does not work for some devices (e. g. Intel Xe Graphics family)
if (CL_BUILD_PROGRAM_FAILURE == status) {
status = clBuildProgram(cont->program, 1, &cont->deviceID, NULL, NULL, NULL);
}
}
if (ocl_diagnose(status, "building cl program", cont) != CL_SUCCESS)
{
//static char buf[0x10001]={0};
size_t log_size;

clGetProgramBuildInfo( cont->program,
Expand All @@ -254,18 +256,23 @@ bool BuildCLProgram(ocl_context_t *cont, const char* programText, const char *ke
NULL,
&log_size );

char *buf = (char *) malloc(log_size);
Log("Build log returned %ld bytes\n", (long)log_size);
char *buf = (char *) malloc(log_size + 1);
if (!buf) {
LogRaw("Unable to print build log (not enough memory)\n");
return false;
}
clGetProgramBuildInfo( cont->program,
cont->deviceID,
CL_PROGRAM_BUILD_LOG,
log_size,
buf,
NULL );

buf[log_size - 1] = '\0';
Log("Build log returned %ld bytes\n", (long)log_size);
buf[log_size - 1] = '\n';
buf[log_size] = '\0';
LogRaw("Build Log:\n");
LogRaw("%s\n", buf);
LogRawString(buf);

free(buf);

Expand Down