re-enable ui & vis rendering

This commit is contained in:
jacob 2025-12-11 15:41:31 -06:00
parent eeec7e7191
commit ad359c8495
11 changed files with 228 additions and 206 deletions

View File

@ -73,7 +73,7 @@
#define GPU_DEBUG_VALIDATION 0
#define GPU_SHADER_PRINT 1
#define GPU_SHADER_PRINT_BUFFER_SIZE Kibi(1);
#define GPU_SHADER_PRINT_BUFFER_SIZE Kibi(64);
#define GPU_SHADER_PRINT_LOG 1
/* If enabled, bitbuffs will insert/verify magic numbers & length for each read & write */

View File

@ -307,6 +307,12 @@ void G_Bootstrap(void)
queue->print_buffer_size,
.flags = G_ResourceFlag_AllowShaderReadWrite
);
queue->print_readback_buffer = G_PushBuffer(
gpu_perm,
u8,
queue->print_buffer_size,
.flags = G_ResourceFlag_HostMemory
);
queue->print_buffer_ref = G_PushRWByteAddressBufferRef(gpu_perm, queue->print_buffer);
}
}
@ -2837,29 +2843,20 @@ void G_CommitBackbuffer(G_ResourceHandle backbuffer_handle, i32 vsync)
void G_D12_CollectionWorkerEntry(WaveLaneCtx *lane)
{
G_QueueKind queue_kind = G_QueueKind_Direct;
G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind);
// if (queue->print_buffer_size > 0)
G_ArenaHandle gpu_perm = G_PermArena();
G_ResourceHandle readback_buff = G_PushBuffer(
gpu_perm,
u8,
queue->print_buffer_size,
.flags = G_ResourceFlag_HostMemory
);
for (;;)
{
/* FIXME: Remove this */
Sleep(100);
P_SleepSeconds(0.100);
/* Copy print-buffers to readback */
for (G_QueueKind queue_kind = 0; queue_kind < G_NumQueues; ++queue_kind)
{
G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind);
if (!G_IsResourceNil(queue->print_buffer))
{
G_CommandListHandle cl = G_PrepareCommandList(queue_kind);
{
/* Copy print buffer to readback buffer */
G_CopyBufferToBuffer(cl, readback_buff, 0, queue->print_buffer, RNGU64(0, queue->print_buffer_size));
G_CopyBufferToBuffer(cl, queue->print_readback_buffer, 0, queue->print_buffer, RNGU64(0, queue->print_buffer_size));
/* Reset counters to 0 */
G_MemorySync(cl, queue->print_buffer,
G_Stage_Copy, G_Access_CopyRead,
@ -2869,13 +2866,21 @@ void G_D12_CollectionWorkerEntry(WaveLaneCtx *lane)
G_CopyCpuToBuffer(cl, queue->print_buffer, 0, zero, RNGU64(0, sizeof(zero)));
}
G_CommitCommandList(cl);
}
}
G_SyncCpu(G_MaskFromQueue(queue_kind));
/* TODO: Collect asynchronously */
G_SyncCpu(G_QueueMask_Direct | G_QueueMask_AsyncCompute);
u32 attempted_print_bytes_count = *(G_StructFromResource(readback_buff, u32) + 0); /* The number of bytes shaders attempted to write */
u32 prints_count = *(G_StructFromResource(readback_buff, u32) + 1); /* The number of shader prints that are in the buffer */
u32 overflows_count = *(G_StructFromResource(readback_buff, u32) + 2); /* The number of shader prints that could not fit in the buffer */
u8 *start = G_StructFromResource(readback_buff, u8) + 12;
for (G_QueueKind queue_kind = 0; queue_kind < G_NumQueues; ++queue_kind)
{
G_D12_Queue *queue = G_D12_QueueFromKind(queue_kind);
if (!G_IsResourceNil(queue->print_buffer))
{
u32 attempted_print_bytes_count = *(G_StructFromResource(queue->print_readback_buffer, u32) + 0); /* The number of bytes shaders attempted to write */
u32 prints_count = *(G_StructFromResource(queue->print_readback_buffer, u32) + 1); /* The number of shader prints that are in the buffer */
u32 overflows_count = *(G_StructFromResource(queue->print_readback_buffer, u32) + 2); /* The number of shader prints that could not fit in the buffer */
u8 *start = G_StructFromResource(queue->print_readback_buffer, u8) + 12;
/* Deserialize */
if (GPU_SHADER_PRINT_LOG)
@ -3027,7 +3032,7 @@ void G_D12_CollectionWorkerEntry(WaveLaneCtx *lane)
}
EndScratch(scratch);
}
DEBUGBREAKABLE;
}
}
}
}

View File

@ -222,6 +222,7 @@ Struct(G_D12_Queue)
/* Global resources */
u64 print_buffer_size;
G_ResourceHandle print_buffer;
G_ResourceHandle print_readback_buffer;
G_RWByteAddressBufferRef print_buffer_ref;
/* Raw command lists */

View File

@ -137,5 +137,6 @@ i64 P_GetCurrentTimerPeriodNs(void);
////////////////////////////////////////////////////////////
//~ @hookdecl Sleep
void P_SleepSeconds(f64 seconds);
void P_SleepPrecise(i64 sleep_time_ns);
void P_SleepFrame(i64 last_frame_time_ns, i64 target_dt_ns);

View File

@ -978,6 +978,11 @@ i64 P_GetCurrentTimerPeriodNs(void)
////////////////////////////////////////////////////////////
//~ @hookimpl Sleep
void P_SleepSeconds(f64 seconds)
{
Sleep(seconds / 1000.0);
}
void P_SleepPrecise(i64 sleep_time_ns)
{
i64 now_ns = TimeNs();

View File

@ -585,6 +585,7 @@ void V_TickForever(WaveLaneCtx *lane)
params.target_rw = draw_target_rw;
params.shape_verts = dverts_ro;
params.world_to_draw_xf = world_to_draw_xf;
params.target_cursor_pos = draw_cursor;
}
G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(&params));
G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, V_DParams);
@ -598,7 +599,6 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Backdrop pass
/* Backdrop pass */
{
G_Compute(frame->cl, V_BackdropCS, V_BackdropCSThreadSizeFromTexSize(draw_size));
@ -623,7 +623,11 @@ void V_TickForever(WaveLaneCtx *lane)
//- Finalize draw target
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_ShaderRead);
UI_SetRawTexture(vis_box, draw_target_ro, VEC2(0, 0), VEC2(1, 1));
{
Vec2 uv0 = DivVec2Vec2(Vec2FromVec(viewport.p0), Vec2FromVec(window_frame.monitor_size));
Vec2 uv1 = DivVec2Vec2(Vec2FromVec(viewport.p1), Vec2FromVec(window_frame.monitor_size));
UI_SetRawTexture(vis_box, draw_target_ro, uv0, uv1);
}
}
//////////////////////////////

View File

@ -8,8 +8,11 @@ Struct(V_DParams)
Vec2I32 target_size;
G_Texture2DRef target_ro;
G_RWTexture2DRef target_rw;
G_StructuredBufferRef quads;
G_StructuredBufferRef shape_verts;
Vec2 target_cursor_pos;
Xform world_to_draw_xf;
};

View File

@ -10,7 +10,8 @@ ComputeShader2D(V_BackdropCS, 8, 8)
Vec2I32 target_size = params.target_size;
if (target_pos.x < target_size.x && target_pos.y < target_size.y)
{
Vec4 result = Color_Blue;
Vec4 result = Vec4(0.05, 0.05, 0.05, 1);
target[target_pos] = result;
}
}

View File

@ -483,7 +483,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags, Vec4 swapchain_color)
{
Arena *old_arena = frame->arena;
Arena *old_rects_arena = frame->arena;
Arena *old_rects_arena = frame->rects_arena;
G_ArenaHandle old_gpu_arena = frame->gpu_arena;
ZeroStruct(frame);
frame->arena = old_arena;
@ -691,6 +691,8 @@ void UI_EndFrame(UI_Frame *frame)
UI_State *g = &UI_state;
Vec2I32 monitor_size = frame->window_frame.monitor_size;
Rng3 monitor_viewport = RNG3(VEC3(0, 0, 0), VEC3(monitor_size.x, monitor_size.y, 1));
Rng2 monitor_scissor = RNG2(VEC2(0, 0), VEC2(monitor_size.x, monitor_size.y));
Vec2I32 draw_size = frame->window_frame.draw_size;
Rng3 draw_viewport = RNG3(VEC3(0, 0, 0), VEC3(draw_size.x, draw_size.y, 1));
@ -1386,6 +1388,7 @@ void UI_EndFrame(UI_Frame *frame)
G_Texture2DRef draw_target_ro = G_PushTexture2DRef(frame->gpu_arena, draw_target);
/* Rects */
u64 rects_count = ArenaCount(frame->rects_arena, UI_DRect);
G_ResourceHandle rects_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromArena(frame->rects_arena));
G_StructuredBufferRef rects_ro = G_PushStructuredBufferRef(frame->gpu_arena, rects_buff, UI_DRect);
@ -1396,6 +1399,7 @@ void UI_EndFrame(UI_Frame *frame)
params.target_ro = draw_target_ro;
params.rects = rects_ro;
params.sampler = G_BasicSampler();
params.cursor_pos = frame->cursor_pos;
}
G_ResourceHandle params_buff = G_PushBufferFromString(frame->gpu_arena, frame->cl, StringFromStruct(&params));
G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(frame->gpu_arena, params_buff, UI_DParams);
@ -1410,19 +1414,19 @@ void UI_EndFrame(UI_Frame *frame)
//- Clear pass
{
G_ClearRenderTarget(frame->cl, draw_target, VEC4(1, 0, 0, 1));
G_ClearRenderTarget(frame->cl, draw_target, VEC4(0, 0, 0, 1));
}
//- Rect pass
G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_RenderTargetWrite);
if (G_CountBufferBytes(rects_buff) > 0)
if (rects_count > 0)
{
/* Render rects */
G_Rasterize(frame->cl,
UI_DRectVS, UI_DRectPS,
1, G_QuadIndices(),
rects_count, G_QuadIndices(),
1, &draw_target,
draw_viewport, draw_scissor,
G_RasterMode_TriangleList);
@ -1433,7 +1437,7 @@ void UI_EndFrame(UI_Frame *frame)
G_SetConstant(frame->cl, UI_ShaderConst_DebugDraw, 1);
G_Rasterize(frame->cl,
UI_DRectVS, UI_DRectPS,
1, G_QuadIndices(),
rects_count, G_QuadIndices(),
1, &draw_target,
draw_viewport, draw_scissor,
G_RasterMode_WireTriangleList);
@ -1450,7 +1454,7 @@ void UI_EndFrame(UI_Frame *frame)
UI_BlitVS, UI_BlitPS,
1, G_QuadIndices(),
1, &backbuffer,
draw_viewport, draw_scissor,
monitor_viewport, monitor_scissor,
G_RasterMode_TriangleList);
}

View File

@ -8,6 +8,9 @@ Struct(UI_DParams)
{
Vec2I32 target_size;
G_Texture2DRef target_ro;
Vec2 cursor_pos;
G_StructuredBufferRef rects;
G_SamplerStateRef sampler;
};

View File

@ -130,6 +130,7 @@ VertexShader(UI_BlitVS, UI_BlitPSInput)
UI_BlitPSInput result;
result.sv_position = Vec4(NdcFromUv(uv).xy, 0, 1);
result.src_uv = uv;
return result;
}
@ -145,12 +146,6 @@ PixelShader(UI_BlitPS, UI_BlitPSOutput, UI_BlitPSInput input)
Vec2 uv = input.src_uv;
Vec4 result = tex.Sample(sampler, uv);
G_PrintF(
"Bla: %F %F",
G_Fmt(input.sv_position),
G_Fmt(uv)
);
UI_BlitPSOutput output;
output.SV_Target0 = result;
return output;