formatting

This commit is contained in:
jacob 2025-07-14 13:50:19 -05:00
parent 66586f9cf5
commit 0a20e3fdd4
4 changed files with 74 additions and 87 deletions

View File

@ -677,12 +677,10 @@ INLINE f64 clamp_f64(f64 v, f64 min, f64 max) { return v < min ? min : v > max ?
#include "prof_tracy.h"
#define PROF_THREAD_GROUP_FIBERS -GIBI(1)
#define PROF_THREAD_GROUP_SCHEDULER -MEBI(6)
#define PROF_THREAD_GROUP_IO -MEBI(5)
#define PROF_THREAD_GROUP_WINDOW -MEBI(4)
#define PROF_THREAD_GROUP_EVICTORS -MEBI(3)
#define PROF_THREAD_GROUP_SCHEDULER -MEBI(5)
#define PROF_THREAD_GROUP_IO -MEBI(4)
#define PROF_THREAD_GROUP_WINDOW -MEBI(3)
#define PROF_THREAD_GROUP_APP -MEBI(2)
#define PROF_THREAD_GROUP_MAIN -MEBI(1)

View File

@ -2252,7 +2252,7 @@ INTERNAL SYS_JOB_DEF(dx12_wait_fence_job, job)
ID3D12Fence *fence = sig->fence;
u64 target = sig->target;
if (ID3D12Fence_GetCompletedValue(fence) < target) {
/* TODO: Reuse events from pool */
/* TODO: Pool events */
HANDLE event = CreateEvent(0, 0, 0, 0);
ID3D12Fence_SetEventOnCompletion(sig->fence, sig->target, event);
WaitForSingleObject(event, INFINITE);

View File

@ -11,7 +11,7 @@
#define PROFILING_CAPTURE_FRAME_IMAGE 0
#define PROFILING_LOCKS 0
#define PROFILING_D3D 1
#define PROFILER_THREAD_AFFINITY_MASK 0
#define PROFILER_THREAD_AFFINITY_MASK 0x000000000000F000ull
#define PROFILER_THREAD_PREFIX_WSTR L"Tracy"
#define PROFILING_FILE_WSTR L".tracy"
#define PROFILING_CMD_WSTR L"cmd /C start \"\" /wait tracy-capture.exe -o .tracy -a 127.0.0.1 && start \"\" tracy-profiler.exe .tracy"

View File

@ -109,7 +109,7 @@ struct win32_window {
i32 current_event_arena_index;
struct arena *event_arenas[2];
struct sys_thread *event_thread;
struct sys_thread *window_thread;
struct atomic32 shutdown;
struct win32_window *next_free;
@ -244,7 +244,7 @@ struct alignas(64) job_pool {
i32 num_worker_threads;
i32 thread_priority;
u64 thread_affinity_mask;
char *thread_mm_characteristics;
b32 thread_is_audio;
struct arena *worker_threads_arena;
struct sys_thread **worker_threads;
struct worker_ctx *worker_contexts;
@ -991,10 +991,10 @@ INTERNAL SYS_THREAD_DEF(job_worker_entry, worker_ctx_arg)
(UNUSED)success;
}
if (pool->thread_mm_characteristics) {
if (pool->thread_is_audio) {
/* https://learn.microsoft.com/en-us/windows/win32/procthread/multimedia-class-scheduler-service#registry-settings */
DWORD task = 0;
HANDLE mmc_handle = AvSetMmThreadCharacteristicsA(pool->thread_mm_characteristics, &task);
HANDLE mmc_handle = AvSetMmThreadCharacteristics(L"Pro Audio", &task);
ASSERT(mmc_handle);
(UNUSED)mmc_handle;
}
@ -1356,41 +1356,40 @@ INTERNAL SYS_THREAD_DEF(test_entry, _)
case SYS_POOL_SIM:
{
name_fmt = LIT("Sim worker #%F");
//pool->thread_affinity_mask = 0x000000000000000Full;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
pool->num_worker_threads = 4;
pool->thread_affinity_mask = 0x000000000000000Full;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
} break;
case SYS_POOL_USER:
{
name_fmt = LIT("User worker #%F");
//pool->thread_affinity_mask = 0x00000000000000F0ull;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
pool->num_worker_threads = 4;
pool->thread_affinity_mask = 0x00000000000000F0ull;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
} break;
case SYS_POOL_AUDIO:
{
name_fmt = LIT("Audio worker #%F");
//pool->thread_affinity_mask = 0x0000000000000300ull;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
pool->thread_mm_characteristics = "Pro Audio";
pool->num_worker_threads = 2;
pool->thread_affinity_mask = 0x0000000000000300ull;
pool->thread_priority = THREAD_PRIORITY_TIME_CRITICAL;
pool->thread_is_audio = 1;
} break;
case SYS_POOL_BACKGROUND:
{
name_fmt = LIT("Background worker #%F");
//pool->thread_affinity_mask = 0x0000000000000C00ull;
pool->num_worker_threads = 2;
pool->thread_affinity_mask = 0x0000000000000C00ull;
} break;
case SYS_POOL_FLOATING:
{
name_fmt = LIT("Floating worker #%F");
//pool->thread_affinity_mask = 0x0000000000000FFFull;
pool->thread_priority = 0;
pool->num_worker_threads = 8;
pool->thread_affinity_mask = 0x0000000000000FFFull;
} break;
}
pool->worker_threads_arena = arena_alloc(GIBI(64));
@ -2214,7 +2213,7 @@ INTERNAL void win32_window_process_event(struct win32_window *window, struct sys
snc_unlock(&lock);
}
INTERNAL HWND win32_create_window(struct win32_window *window)
INTERNAL HWND win32_window_init(struct win32_window *window)
{
/*
* From martins (https://gist.github.com/mmozeiko/5e727f845db182d468a34d524508ad5f#file-win32_d3d11-c-L66-L70):
@ -2251,16 +2250,15 @@ INTERNAL HWND win32_create_window(struct win32_window *window)
return hwnd;
}
INTERNAL SYS_THREAD_DEF(window_event_thread_entry_point, arg)
INTERNAL SYS_THREAD_DEF(window_thread, arg)
{
struct win32_window *window = (struct win32_window *)arg;
/* Win32 limitation: Window must be initialized on same thread that processes events */
window->hwnd = win32_create_window(window);
window->hwnd = win32_window_init(window);
window->tid = sys_thread_id();
win32_update_window_from_system(window);
BringWindowToTop(window->hwnd);
snc_counter_add(&window->ready_fence, -1);
while (!atomic32_fetch(&window->shutdown)) {
@ -2270,65 +2268,9 @@ INTERNAL SYS_THREAD_DEF(window_event_thread_entry_point, arg)
}
{
__profn("Process window message");
if (atomic32_fetch(&window->shutdown)) {
break;
}
/* Update cursor */
if (GetFocus() == window->hwnd) {
u32 cursor_flags = window->cursor_set_flags;
/* Hide cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_HIDE) {
while(ShowCursor(0) >= 0);
}
/* Show cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_SHOW) {
while(ShowCursor(1) < 0);
}
/* Update position */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_POSITION) {
struct v2 window_space_pos = window->cursor_set_position;
POINT p = { window_space_pos.x, window_space_pos.y };
ClientToScreen(window->hwnd, &p);
SetCursorPos(p.x, p.y);
}
/* Stop clipping cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP) {
ClipCursor(0);
}
/* Clip cursor in window window */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP) {
i32 left = window->x + math_round_to_int(window->cursor_clip_bounds.x);
i32 right = left + math_round_to_int(window->cursor_clip_bounds.width);
i32 top = window->y + math_round_to_int(window->cursor_clip_bounds.y);
i32 bottom = top + math_round_to_int(window->cursor_clip_bounds.height);
RECT clip = {
.left = clamp_i32(left, window->x, window->x + window->width),
.right = clamp_i32(right, window->x, window->x + window->width),
.top = clamp_i32(top, window->y, window->y + window->height),
.bottom = clamp_i32(bottom, window->y, window->y + window->height)
};
ClipCursor(&clip);
}
window->cursor_set_flags = 0;
}
/* Process message */
switch (msg.message) {
case WM_QUIT: {
win32_window_process_event(window, (struct sys_event) { .kind = SYS_EVENT_KIND_QUIT });
} break;
default: {
if (!atomic32_fetch(&window->shutdown)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
} break;
}
}
}
@ -2360,7 +2302,7 @@ INTERNAL struct win32_window *win32_window_alloc(void)
* created and receive a HWND, because on Windows a the event proc must run on
* the same thread that created the window. */
snc_counter_add(&window->ready_fence, 1);
window->event_thread = sys_thread_alloc(&window_event_thread_entry_point, window, LIT("Window event thread"), PROF_THREAD_GROUP_WINDOW);
window->window_thread = sys_thread_alloc(&window_thread, window, LIT("Win32 window thread"), PROF_THREAD_GROUP_WINDOW);
snc_counter_wait(&window->ready_fence);
return window;
@ -2371,7 +2313,7 @@ INTERNAL void win32_window_release(struct win32_window *window)
/* Stop window threads */
atomic32_fetch_set(&window->shutdown, 1);
win32_window_wake(window);
sys_thread_wait_release(window->event_thread);
sys_thread_wait_release(window->window_thread);
struct snc_lock lock = snc_lock_e(&G.windows_mutex);
{
@ -2387,6 +2329,7 @@ struct sys_event_array sys_window_pop_events(struct arena *arena, struct sys_win
struct win32_window *window = (struct win32_window *)sys_window;
i32 event_arena_index = 0;
{
/* Swap event buffers */
struct snc_lock lock = snc_lock_e(&window->event_arena_swp_mutex);
event_arena_index = window->current_event_arena_index;
window->current_event_arena_index = 1 - window->current_event_arena_index;
@ -2534,7 +2477,7 @@ INTERNAL void win32_update_window_from_settings(struct win32_window *window, str
INTERNAL void win32_window_wake(struct win32_window *window)
{
/* Post a blank message to the window's thread message queue to wake it. */
PostMessageW(window->hwnd, WM_NULL, 0, 0);
PostMessageW(window->hwnd, 0, 0, 0);
}
INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
@ -2546,9 +2489,55 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
return DefWindowProcW(hwnd, msg, wparam, lparam);
}
/* Update cursor */
if (GetFocus() == window->hwnd) {
u32 cursor_flags = window->cursor_set_flags;
/* Hide cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_HIDE) {
while (ShowCursor(0) >= 0);
}
/* Show cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_SHOW) {
while (ShowCursor(1) < 0);
}
/* Update position */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_POSITION) {
struct v2 window_space_pos = window->cursor_set_position;
POINT p = { window_space_pos.x, window_space_pos.y };
ClientToScreen(window->hwnd, &p);
SetCursorPos(p.x, p.y);
}
/* Stop clipping cursor */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_CLIP) {
ClipCursor(0);
}
/* Clip cursor in window window */
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_CLIP) {
i32 left = window->x + math_round_to_int(window->cursor_clip_bounds.x);
i32 right = left + math_round_to_int(window->cursor_clip_bounds.width);
i32 top = window->y + math_round_to_int(window->cursor_clip_bounds.y);
i32 bottom = top + math_round_to_int(window->cursor_clip_bounds.height);
RECT clip = {
.left = clamp_i32(left, window->x, window->x + window->width),
.right = clamp_i32(right, window->x, window->x + window->width),
.top = clamp_i32(top, window->y, window->y + window->height),
.bottom = clamp_i32(bottom, window->y, window->y + window->height)
};
ClipCursor(&clip);
}
window->cursor_set_flags = 0;
}
LRESULT result = 0;
b32 is_release = 0;
switch (msg) {
case WM_QUIT:
case WM_CLOSE:
case WM_DESTROY: {
win32_window_process_event(window, (struct sys_event) { .kind = SYS_EVENT_KIND_QUIT });