diff --git a/src/gpu/gpu_core.h b/src/gpu/gpu_core.h index 3e86ed9d..e0652856 100644 --- a/src/gpu/gpu_core.h +++ b/src/gpu/gpu_core.h @@ -629,21 +629,21 @@ u32 G_PushRef(G_ArenaHandle arena, G_ResourceHandle resource, G_RefDesc desc); #define G_PushTexture1DRef(arena, resource, ...) (G_Texture1DRef) { \ .v = G_PushRef( \ (arena), (resource), \ - (G_RefDesc) { .kind = G_RefKind_Texture1D, .mips.max = 64, __VA_ARGS__ } \ + (G_RefDesc) { .kind = G_RefKind_Texture1D, .mips.max = G_MaxMips, __VA_ARGS__ } \ ) \ } #define G_PushTexture2DRef(arena, resource, ...) (G_Texture2DRef) { \ .v = G_PushRef( \ (arena), (resource), \ - (G_RefDesc) { .kind = G_RefKind_Texture2D, .mips.max = 64, __VA_ARGS__ } \ + (G_RefDesc) { .kind = G_RefKind_Texture2D, .mips.max = G_MaxMips, __VA_ARGS__ } \ ) \ } #define G_PushTexture3DRef(arena, resource, ...) (G_Texture3DRef) { \ .v = G_PushRef( \ (arena), (resource), \ - (G_RefDesc) { .kind = G_RefKind_Texture3D, .mips.max = 64, __VA_ARGS__ } \ + (G_RefDesc) { .kind = G_RefKind_Texture3D, .mips.max = G_MaxMips, __VA_ARGS__ } \ ) \ } @@ -695,7 +695,7 @@ void G_MemorySyncEx(G_CommandListHandle cl, G_MemoryBarrierDesc desc); .access_prev = _access_prev, \ .stage_next = _stage_next, \ .access_next = _access_next, \ - .mips.max = 64, \ + .mips.max = G_MaxMips, \ __VA_ARGS__ \ }) @@ -707,7 +707,7 @@ void G_MemorySyncEx(G_CommandListHandle cl, G_MemoryBarrierDesc desc); .stage_next = _stage_next, \ .access_next = _access_next, \ .layout = _layout, \ - .mips.max = 64, \ + .mips.max = G_MaxMips, \ __VA_ARGS__ \ }) @@ -718,7 +718,7 @@ void G_MemorySyncEx(G_CommandListHandle cl, G_MemoryBarrierDesc desc); .access_prev = _access_prev, \ .stage_next = _stage_next, \ .access_next = _access_next, \ - .mips.max = 64, \ + .mips.max = G_MaxMips, \ __VA_ARGS__ \ }) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index f8c8cc7b..d4013c68 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -20,12 +20,12 @@ void V_Shutdown(void) V_Frame *V_CurrentFrame(void) { - return &V.frames[V.current_frame_tick % countof(V.frames)]; + return &V.frames[V.cur_frame_tick % countof(V.frames)]; } V_Frame *V_PrevFrame(void) { - return &V.frames[(V.current_frame_tick - 1) % countof(V.frames)]; + return &V.frames[(V.cur_frame_tick - 1) % countof(V.frames)]; } V_Cmd *V_PushVisCmd(String name) @@ -362,7 +362,13 @@ void V_TickForever(WaveLaneCtx *lane) P_SimStatistics sim_stats = Zi; P_World *sim_world = P_AcquireWorld(); - P_World *predict_world = P_AcquireWorld(); + + i64 cur_predict_world_seq = 0; + P_World *predict_worlds[2] = Zi; + for (i64 predict_world_idx = 0; predict_world_idx < countof(predict_worlds); ++predict_world_idx) + { + predict_worlds[predict_world_idx] = P_AcquireWorld(); + } i64 local_controls_cap = NextPow2U64(SIM_MAX_PING * SIM_TICKS_PER_SECOND); P_Control *local_controls = PushStructs(perm, P_Control, local_controls_cap); @@ -378,6 +384,7 @@ void V_TickForever(WaveLaneCtx *lane) i64 ack = 0; i64 ack_mirror = 0; i64 ack_received_at_ns = 0; + i64 ack_dt_ns = 0; f64 most_recent_rtt = 0; // i64 smoothed_rtt_ns = 0; @@ -569,7 +576,7 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Begin frame - V.current_frame_tick += 1; + V.cur_frame_tick += 1; V_Frame *prev_frame = V_PrevFrame(); V_Frame *frame = V_CurrentFrame(); @@ -586,12 +593,12 @@ void V_TickForever(WaveLaneCtx *lane) frame->dvert_idxs_arena = old_dvert_idxs_arena; frame->local_world = old_local_world; } - frame->cl = G_PrepareCommandList(G_QueueKind_Direct); + G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct); ResetArena(frame->arena); ResetArena(frame->quads_arena); ResetArena(frame->dverts_arena); ResetArena(frame->dvert_idxs_arena); - G_ResetArena(frame->cl, gpu_frame_arena); + G_ResetArena(cl, gpu_frame_arena); // Persist state CopyBytes(frame->held_buttons, prev_frame->held_buttons, sizeof(frame->held_buttons)); @@ -612,7 +619,7 @@ void V_TickForever(WaveLaneCtx *lane) frame->predict_tick_accum = prev_frame->predict_tick_accum; frame->af = prev_frame->af; - frame->tick = V.current_frame_tick; + frame->tick = V.cur_frame_tick; frame->time_ns = TimeNs(); frame->dt_ns = ClampI64(frame->time_ns - prev_frame->time_ns, 1, NsFromSeconds(1.0 / 50)); frame->dt = SecondsFromNs(frame->dt_ns); @@ -1293,6 +1300,7 @@ void V_TickForever(WaveLaneCtx *lane) if (dst_frame->received_fragments_count >= dst_frame->fragments_count) { ack = dst_tick; + ack_dt_ns = ack_received_at_ns - frame->time_ns; ack_received_at_ns = frame->time_ns; } } @@ -1626,6 +1634,7 @@ void V_TickForever(WaveLaneCtx *lane) // Predict + P_World *predict_world = predict_worlds[cur_predict_world_seq % countof(predict_worlds)]; P_Frame *predict_frame = predict_world->last_frame; { if (predict_world->tiles_hash != sim_world->tiles_hash) @@ -5002,7 +5011,7 @@ void V_TickForever(WaveLaneCtx *lane) { // LogDebugF("Uploading tiles to gpu"); G_CopyCpuToTexture( - frame->cl, + cl, gpu_tiles_res, VEC3I32(0, 0, 0), frame->local_world->tiles, VEC3I32(tiles_dims.x, tiles_dims.y, 1), RNG3I32(VEC3I32(0, 0, 0), VEC3I32(tiles_dims.x, tiles_dims.y, 1)) @@ -5011,7 +5020,7 @@ void V_TickForever(WaveLaneCtx *lane) // Screen texture G_ResourceHandle screen_target = G_PushTexture2D( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, G_Format_R16G16B16A16_Float, frame->screen_dims, G_Layout_DirectQueue_General, @@ -5022,24 +5031,9 @@ void V_TickForever(WaveLaneCtx *lane) Rng2 screen_scissor = RNG2(VEC2(screen_viewport.p0.x, screen_viewport.p0.y), VEC2(screen_viewport.p1.x, screen_viewport.p1.y)); frame->screen = G_PushTexture2DRef(gpu_frame_arena, screen_target); - // Bloom texture - G_ResourceHandle bloom_target = G_PushTexture2D( - gpu_frame_arena, frame->cl, - G_Format_R16G16B16A16_Float, - G_DimsFromMip2D(G_Count2D(screen_target), 1), - G_Layout_DirectQueue_General, - .flags = G_ResourceFlag_AllowShaderReadWrite, - .name = StringF(frame->arena, "Bloom target [%F]", FmtSint(frame->tick)), - .max_mips = 64 - ); - for (i32 mip_idx = 0; mip_idx < G_CountMips(bloom_target); ++mip_idx) - { - frame->bloom_mips[mip_idx] = G_PushTexture2DRef(gpu_frame_arena, bloom_target, .mips = RNGI32(mip_idx, mip_idx)); - } - // Albedo texture G_ResourceHandle albedo_target = G_PushTexture2D( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, G_Format_R16G16B16A16_Float, frame->screen_dims, G_Layout_DirectQueue_RenderTarget, @@ -5050,7 +5044,7 @@ void V_TickForever(WaveLaneCtx *lane) // Backdrop texture G_ResourceHandle backdrop_target = G_PushTexture2D( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, G_Format_R16G16B16A16_Float, G_DimsFromMip2D(G_Count2D(screen_target), 1), G_Layout_DirectQueue_General, @@ -5058,14 +5052,30 @@ void V_TickForever(WaveLaneCtx *lane) .name = StringF(frame->arena, "Backdrop target [%F]", FmtSint(frame->tick)), .max_mips = 4 ); - for (i32 mip_idx = 0; mip_idx < G_CountMips(bloom_target); ++mip_idx) + for (i32 mip_idx = 0; mip_idx < G_CountMips(backdrop_target); ++mip_idx) { frame->backdrop_mips[mip_idx] = G_PushTexture2DRef(gpu_frame_arena, backdrop_target, .mips = RNGI32(mip_idx, mip_idx)); } + // Bloom texture + // TODO: We can re-use backdrop mip chain for this + G_ResourceHandle bloom_target = G_PushTexture2D( + gpu_frame_arena, cl, + G_Format_R16G16B16A16_Float, + G_DimsFromMip2D(G_Count2D(screen_target), 1), + G_Layout_DirectQueue_General, + .flags = G_ResourceFlag_AllowShaderReadWrite, + .name = StringF(frame->arena, "Bloom target [%F]", FmtSint(frame->tick)), + .max_mips = G_MaxMips + ); + for (i32 mip_idx = 0; mip_idx < G_CountMips(bloom_target); ++mip_idx) + { + frame->bloom_mips[mip_idx] = G_PushTexture2DRef(gpu_frame_arena, bloom_target, .mips = RNGI32(mip_idx, mip_idx)); + } + // Shade texture G_ResourceHandle shade_target = G_PushTexture2D( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, G_Format_R16G16B16A16_Float, frame->shade_dims, G_Layout_DirectQueue_General, @@ -5078,7 +5088,7 @@ void V_TickForever(WaveLaneCtx *lane) // Quad buffers G_ResourceHandle quads_buff = G_PushBufferFromCpuCopy( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, StringFromArena(frame->quads_arena), .name = StringF(frame->arena, "quads [%F]", FmtSint(frame->tick)) ); @@ -5086,12 +5096,12 @@ void V_TickForever(WaveLaneCtx *lane) // Debug shape buffers G_ResourceHandle dverts_buff = G_PushBufferFromCpuCopy( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, StringFromArena(frame->dverts_arena), .name = StringF(frame->arena, "dverts [%F]", FmtSint(frame->tick)) ); G_ResourceHandle dvert_idxs_buff = G_PushBufferFromCpuCopy( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, StringFromArena(frame->dvert_idxs_arena), .name = StringF(frame->arena, "dvert idxs [%F]", FmtSint(frame->tick)) ); @@ -5112,7 +5122,7 @@ void V_TickForever(WaveLaneCtx *lane) } } gpu_emitters = G_PushBufferFromCpuCopy( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, StringFromStructs(flattened_emitters, frame->emitters_count), .name = StringF(frame->arena, "emitters [%F]", FmtSint(frame->tick)) ); @@ -5121,7 +5131,7 @@ void V_TickForever(WaveLaneCtx *lane) // Upload gpu frame G_ResourceHandle gpu_frame_res = G_PushBufferFromCpuCopy( - gpu_frame_arena, frame->cl, + gpu_frame_arena, cl, StringFromStruct(&frame->shared_frame), .name = StringF(frame->arena, "Gpu frame [%F]", FmtSint(frame->tick)) ); @@ -5129,44 +5139,44 @@ void V_TickForever(WaveLaneCtx *lane) // Set initial constants V_GpuFlag gpu_flags = V_GpuFlag_None; - G_SetConstant(frame->cl, V_GpuConst_Flags, gpu_flags); - G_SetConstant(frame->cl, V_GpuConst_Frame, gpu_frame); - G_SetConstant(frame->cl, V_GpuConst_NoiseTex, G_BasicNoiseTexture()); + G_SetConstant(cl, V_GpuConst_Flags, gpu_flags); + G_SetConstant(cl, V_GpuConst_Frame, gpu_frame); + G_SetConstant(cl, V_GpuConst_NoiseTex, G_BasicNoiseTexture()); // Sync - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); ////////////////////////////// //- Initialization pass { // Prepare shade - G_Compute(frame->cl, V_PrepareShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims)); + G_Compute(cl, V_PrepareShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims)); // Prepare cells - G_Compute(frame->cl, V_PrepareCellsCS, V_ThreadGroupSizeFromTexSize(cells_dims)); + G_Compute(cl, V_PrepareCellsCS, V_ThreadGroupSizeFromTexSize(cells_dims)); // Clear particles if (frame->should_clear_particles) { - G_Compute(frame->cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap)); + G_Compute(cl, V_ClearParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap)); V.particle_seq = 0; } // Backdrop passes { i32 mips_count = G_CountMips(backdrop_target); - G_SetConstant(frame->cl, V_GpuConst_MipsCount, mips_count); + G_SetConstant(cl, V_GpuConst_MipsCount, mips_count); //- Downsample for (i32 mip_idx = 0; mip_idx < mips_count; ++mip_idx) { Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(backdrop_target), mip_idx); - G_SetConstant(frame->cl, V_GpuConst_MipIdx, mip_idx); - G_Compute(frame->cl, V_BackdropDownCS, V_ThreadGroupSizeFromTexSize(down_dims)); + G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); + G_Compute(cl, V_BackdropDownCS, V_ThreadGroupSizeFromTexSize(down_dims)); - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } //- Upsample passes @@ -5174,24 +5184,25 @@ void V_TickForever(WaveLaneCtx *lane) { Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(backdrop_target), mip_idx); - G_SetConstant(frame->cl, V_GpuConst_MipIdx, mip_idx); - G_Compute(frame->cl, V_BackdropUpCS, V_ThreadGroupSizeFromTexSize(up_dims)); + G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); + G_Compute(cl, V_BackdropUpCS, V_ThreadGroupSizeFromTexSize(up_dims)); - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } } - // Prepare RTs - G_ClearRenderTarget(frame->cl, albedo_target, VEC4(0, 0, 0, 0), 0); + G_DumbGlobalMemorySync(cl); } ////////////////////////////// //- Quads & emitters pass { + G_ClearRenderTarget(cl, albedo_target, VEC4(0, 0, 0, 0), 0); + // Draw quads G_Rasterize( - frame->cl, + cl, V_QuadVS, V_QuadPS, G_CountBuffer(quads_buff, V_Quad), G_QuadIndices(), 1, &G_Rt(albedo_target, G_BlendMode_CompositeStraightAlpha), @@ -5200,13 +5211,11 @@ void V_TickForever(WaveLaneCtx *lane) ); // Emit particles - G_Compute(frame->cl, V_EmitParticlesCS, V_ThreadGroupSizeFromBufferSize(frame->emitters_count)); + G_Compute(cl, V_EmitParticlesCS, V_ThreadGroupSizeFromBufferSize(frame->emitters_count)); - // Sync particles & occluders - G_DumbGlobalMemorySync(frame->cl); - - // Transition albedo - G_DumbMemoryLayoutSync(frame->cl, albedo_target, G_Layout_DirectQueue_General); + // Sync particles, occluders, & albedo + G_DumbGlobalMemorySync(cl); + G_DumbMemoryLayoutSync(cl, albedo_target, G_Layout_DirectQueue_General); } ////////////////////////////// @@ -5214,10 +5223,10 @@ void V_TickForever(WaveLaneCtx *lane) { // Simulate particles - G_Compute(frame->cl, V_SimParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap)); + G_Compute(cl, V_SimParticlesCS, V_ThreadGroupSizeFromBufferSize(V_ParticlesCap)); // Sync cells - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } ////////////////////////////// @@ -5225,18 +5234,21 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: Remove this + if (0) { - G_Compute(frame->cl, V_ShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims)); + G_Compute(cl, V_ShadeCS, V_ThreadGroupSizeFromTexSize(frame->shade_dims)); + + G_DumbGlobalMemorySync(cl); } ////////////////////////////// //- Composite pass { - G_Compute(frame->cl, V_CompositeCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims)); + G_Compute(cl, V_CompositeCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims)); // Sync screen tex - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } ////////////////////////////// @@ -5244,7 +5256,7 @@ void V_TickForever(WaveLaneCtx *lane) { i32 mips_count = G_CountMips(bloom_target) + 1; - G_SetConstant(frame->cl, V_GpuConst_MipsCount, mips_count); + G_SetConstant(cl, V_GpuConst_MipsCount, mips_count); // NOTE: Because bloom mip chain starts at half screen size, mip_idx 0 // actually represents the screen texture, while mip_idx - 1 represents @@ -5255,10 +5267,10 @@ void V_TickForever(WaveLaneCtx *lane) { Vec2I32 down_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx); - G_SetConstant(frame->cl, V_GpuConst_MipIdx, mip_idx); - G_Compute(frame->cl, V_BloomDownCS, V_ThreadGroupSizeFromTexSize(down_dims)); + G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); + G_Compute(cl, V_BloomDownCS, V_ThreadGroupSizeFromTexSize(down_dims)); - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } //- Upsample passes @@ -5266,10 +5278,10 @@ void V_TickForever(WaveLaneCtx *lane) { Vec2I32 up_dims = G_DimsFromMip2D(G_Count2D(screen_target), mip_idx); - G_SetConstant(frame->cl, V_GpuConst_MipIdx, mip_idx); - G_Compute(frame->cl, V_BloomUpCS, V_ThreadGroupSizeFromTexSize(up_dims)); + G_SetConstant(cl, V_GpuConst_MipIdx, mip_idx); + G_Compute(cl, V_BloomUpCS, V_ThreadGroupSizeFromTexSize(up_dims)); - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } } @@ -5277,9 +5289,9 @@ void V_TickForever(WaveLaneCtx *lane) //- Finalization pass { - G_Compute(frame->cl, V_FinalizeCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims)); + G_Compute(cl, V_FinalizeCS, V_ThreadGroupSizeFromTexSize(frame->screen_dims)); - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(cl); } ////////////////////////////// @@ -5287,10 +5299,10 @@ void V_TickForever(WaveLaneCtx *lane) if (dvert_idxs_ib.count > 0) { - G_DumbMemoryLayoutSync(frame->cl, screen_target, G_Layout_DirectQueue_RenderTarget); + G_DumbMemoryLayoutSync(cl, screen_target, G_Layout_DirectQueue_RenderTarget); G_Rasterize( - frame->cl, + cl, V_DVertVS, V_DVertPS, 1, dvert_idxs_ib, 1, &G_Rt(screen_target, G_BlendMode_CompositeStraightAlpha), @@ -5298,11 +5310,12 @@ void V_TickForever(WaveLaneCtx *lane) G_RasterMode_TriangleList ); - G_DumbMemoryLayoutSync(frame->cl, screen_target, G_Layout_DirectQueue_General); + G_DumbMemoryLayoutSync(cl, screen_target, G_Layout_DirectQueue_General); } + ////////////////////////////// - //- Finalize screen target + //- Set UI box texture { Rng2 uv = Zi; @@ -5381,7 +5394,7 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- End frame - G_CommitCommandList(frame->cl); + G_CommitCommandList(cl); i32 vsync = !!TweakBool("Vsync", 1); vsync = 1; diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index f91e87d3..a5a53ed1 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -224,7 +224,6 @@ Struct(V_Frame) Arena *quads_arena; Arena *dverts_arena; Arena *dvert_idxs_arena; - G_CommandListHandle cl; Embed(V_SharedFrame, shared_frame); @@ -277,7 +276,7 @@ Struct(V_Ctx) Atomic32 shutdown; Fence shutdown_complete; - i64 current_frame_tick; + i64 cur_frame_tick; V_Frame frames[2]; }; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index f27e79b1..e236b355 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -577,7 +577,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) ////////////////////////////// //- Begin frame - UI.current_frame_tick += 1; + UI.cur_frame_tick += 1; UI_Frame *prev_frame = UI_PrevFrame(); UI_Frame *frame = UI_CurrentFrame(); @@ -589,10 +589,10 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) frame->rects_arena = old_rects_arena; } frame->window_frame = WND_BeginFrame(G_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchMonitor); - frame->cl = G_PrepareCommandList(G_QueueKind_Direct); + UI.cl = G_PrepareCommandList(G_QueueKind_Direct); ResetArena(frame->arena); ResetArena(frame->rects_arena); - G_ResetArena(frame->cl, UI.gpu_frame_arena); + G_ResetArena(UI.cl, UI.gpu_frame_arena); { i64 now_ns = TimeNs(); @@ -600,7 +600,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) frame->time_ns = now_ns; frame->dt_ns = dt_ns; frame->dt = SecondsFromNs(frame->dt_ns); - frame->tick = UI.current_frame_tick; + frame->tick = UI.cur_frame_tick; } // Init style stack @@ -847,12 +847,12 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) UI_Frame *UI_CurrentFrame(void) { - return &UI.frames[UI.current_frame_tick % countof(UI.frames)]; + return &UI.frames[UI.cur_frame_tick % countof(UI.frames)]; }; UI_Frame *UI_PrevFrame(void) { - return &UI.frames[(UI.current_frame_tick - 1) % countof(UI.frames)]; + return &UI.frames[(UI.cur_frame_tick - 1) % countof(UI.frames)]; }; Arena *UI_FrameArena(void) @@ -1698,7 +1698,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) // Target G_ResourceHandle draw_target = G_PushTexture2D( - UI.gpu_frame_arena, frame->cl, + UI.gpu_frame_arena, UI.cl, G_Format_R16G16B16A16_Float, monitor_size, G_Layout_DirectQueue_RenderTarget, @@ -1710,7 +1710,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) // Rects u64 rects_count = ArenaCount(frame->rects_arena, UI_GpuRect); G_ResourceHandle rects_buff = G_PushBufferFromCpuCopy( - UI.gpu_frame_arena, frame->cl, + UI.gpu_frame_arena, UI.cl, StringFromArena(frame->rects_arena), .name = Lit("UI rects") ); @@ -1727,17 +1727,17 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) params.aa = TweakFloat("UI anti-aliasing", 1, 0, 1); } G_ResourceHandle params_buff = G_PushBufferFromCpuCopy( - UI.gpu_frame_arena, frame->cl, + UI.gpu_frame_arena, UI.cl, StringFromStruct(¶ms), .name = Lit("UI gpu params") ); G_StructuredBufferRef params_ro = G_PushStructuredBufferRef(UI.gpu_frame_arena, params_buff, UI_GpuParams); // Initial constants - G_SetConstant(frame->cl, UI_GpuConst_Params, params_ro); + G_SetConstant(UI.cl, UI_GpuConst_Params, params_ro); // Sync - G_DumbGlobalMemorySync(frame->cl); + G_DumbGlobalMemorySync(UI.cl); ////////////////////////////// //- Dispatch shaders @@ -1745,7 +1745,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) //- Clear pass { - G_ClearRenderTarget(frame->cl, draw_target, VEC4(0, 0, 0, 0), 0); + G_ClearRenderTarget(UI.cl, draw_target, VEC4(0, 0, 0, 0), 0); } //- Rect pass @@ -1754,7 +1754,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) { // Render rects G_Rasterize( - frame->cl, + UI.cl, UI_DRectVS, UI_DRectPS, rects_count, G_QuadIndices(), 1, &G_Rt(draw_target, G_BlendMode_CompositePremultipliedAlpha), @@ -1765,9 +1765,9 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) // Render rect wireframes if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug)) { - G_SetConstant(frame->cl, UI_GpuConst_DebugDraw, 1); + G_SetConstant(UI.cl, UI_GpuConst_DebugDraw, 1); G_Rasterize( - frame->cl, + UI.cl, UI_DRectVS, UI_DRectPS, rects_count, G_QuadIndices(), 1, &G_Rt(draw_target, G_BlendMode_CompositePremultipliedAlpha), @@ -1779,12 +1779,12 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) //- Backbuffer blit pass - G_DumbMemoryLayoutSync(frame->cl, draw_target, G_Layout_DirectQueue_Read); - G_DumbMemoryLayoutSync(frame->cl, backbuffer, G_Layout_DirectQueue_RenderTarget); + G_DumbMemoryLayoutSync(UI.cl, draw_target, G_Layout_DirectQueue_Read); + G_DumbMemoryLayoutSync(UI.cl, backbuffer, G_Layout_DirectQueue_RenderTarget); { G_Rasterize( - frame->cl, + UI.cl, UI_BlitVS, UI_BlitPS, 1, G_QuadIndices(), 1, &G_Rt(backbuffer, G_BlendMode_Opaque), @@ -1793,13 +1793,13 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) ); } - G_DumbMemoryLayoutSync(frame->cl, backbuffer, G_Layout_Common); + G_DumbMemoryLayoutSync(UI.cl, backbuffer, G_Layout_Common); } ////////////////////////////// //- End frame - G_CommitCommandList(frame->cl); + G_CommitCommandList(UI.cl); WND_EndFrame(frame->window_frame, vsync); EndScratch(scratch); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index fc36e5eb..99526e06 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -380,7 +380,6 @@ Struct(UI_Frame) WND_Frame window_frame; G_ResourceHandle backbuffer; - G_CommandListHandle cl; // Time i64 tick; @@ -420,10 +419,11 @@ Struct(UI_Ctx) RandState rand; - i64 current_frame_tick; - UI_Frame frames[2]; - G_ArenaHandle gpu_frame_arena; + G_CommandListHandle cl; + + i64 cur_frame_tick; + UI_Frame frames[2]; }; extern UI_Ctx UI;