Skip to content

renderer: rewrite GLimp_LogComment() calls#1608

Merged
illwieckz merged 4 commits intomasterfrom
illwieckz/logcomment
Mar 24, 2025
Merged

renderer: rewrite GLimp_LogComment() calls#1608
illwieckz merged 4 commits intomasterfrom
illwieckz/logcomment

Conversation

@illwieckz
Copy link
Copy Markdown
Member

@illwieckz illwieckz commented Mar 17, 2025

Rewrite GLimp_LogComment() calls.

Also don't require an ending \n on every call.

Also only call GLimp_LogComment() when the function doesn't return early.

No more noisy:

if ( r_logFile->integer )
{
	GLimp_LogComment( va( "bla: %d\n", bla ) );
}

if ( condition )
{
	return;
}

Just this:

if ( condition )
{
	return;
}

GLIMP_LOGCOMMENT( "bla: %d", bla );

Edit: GLIMP_LOGCOMMENT() is a macro wrapping both the if ( r_logFile->integer ) test and a Str::Format() call.

- Turn GLimp_LogComment() into a macro wrapping the test for logging being enabled,
- Wrap the string formatting into the macro too,
- Wrap the endline character writing too,
- Move the GLimp_LogComment() calls after tests doing early returns.
@illwieckz illwieckz added T-Improvement Improvement for an existing feature A-Renderer A-UI labels Mar 17, 2025
@illwieckz illwieckz force-pushed the illwieckz/logcomment branch 2 times, most recently from 259b8d5 to 953b451 Compare March 18, 2025 00:14
@DolceTriade
Copy link
Copy Markdown
Contributor

DolceTriade commented Mar 18, 2025

Hm, maybe reaper and slipher can disagree, but I'm not sure I agree with the premise of the PR.

Keep in mind that your change isn't 1:1 with the old behavior.

GLimp_LogComment("%d", SomeVeryExpensiveCall())

SomeVeryExpensiveCall will now be run unconditionally. We do have DoDebugCode for this reason, but in that case, I'd like to see all calls to GLimp_LogComment wrapped in that function (which from a noisy-ness perspective, does not really get us much).

@illwieckz
Copy link
Copy Markdown
Member Author

@DolceTriade this is the part you look for:

inline bool GLimp_isLogging() {
	return r_logFile.Get() && GLEW_ARB_debug_output;
}

#define GLimp_LogComment( ... ) { \
	if ( GLimp_isLogging() ) \
	{ \
		GLimp_LogComment_( Str::Format( __VA_ARGS__ ) ); \
	} \
}

@illwieckz
Copy link
Copy Markdown
Member Author

Well, I can rename GLimp_LogComment as upper case GLIMP_LOGCOMMENT to hint this is now a macro.

@illwieckz illwieckz force-pushed the illwieckz/logcomment branch from 953b451 to 8d05c89 Compare March 18, 2025 02:31
@illwieckz
Copy link
Copy Markdown
Member Author

Well, I can rename GLimp_LogComment as upper case GLIMP_LOGCOMMENT to hint this is now a macro.

Now done.

@illwieckz
Copy link
Copy Markdown
Member Author

I also added a commit asserting that the GLimp_LogComment() function is never called directly and not wrapped by GLIMP_LOGCOMMENT().

There is actually one place where we can call it directly, but the extra calls of GLimp_isLogging() will be optimized out by the compiler anyway.

So we better make sure GLIMP_LOGCOMMENT() is always used instead.

@DolceTriade
Copy link
Copy Markdown
Contributor

I see. I missed that it was converted into a macro

@illwieckz illwieckz force-pushed the illwieckz/logcomment branch from 2fc3059 to 7faa798 Compare March 18, 2025 11:32
@illwieckz
Copy link
Copy Markdown
Member Author

I see. I missed that it was converted into a macro

My fault, I forgot to mention it in the first post. 😊️

@illwieckz illwieckz force-pushed the illwieckz/logcomment branch from 7faa798 to 4030cdf Compare March 18, 2025 11:52
@illwieckz illwieckz force-pushed the illwieckz/logcomment branch from 4030cdf to 8fb74c8 Compare March 18, 2025 23:28
Copy link
Copy Markdown
Contributor

@VReaperV VReaperV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@illwieckz illwieckz merged commit fcb2195 into master Mar 24, 2025
9 checks passed
@illwieckz illwieckz deleted the illwieckz/logcomment branch March 24, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Renderer A-UI T-Cleanup T-Improvement Improvement for an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants