diff --git a/src/gpu/gpu_core.h b/src/gpu/gpu_core.h index 2ed40d42..e366505e 100644 --- a/src/gpu/gpu_core.h +++ b/src/gpu/gpu_core.h @@ -427,8 +427,8 @@ void G_Bootstrap(void); //~ @hookdecl Arena G_ArenaHandle G_AcquireArena(void); -void G_ReleaseArena(G_CommandListHandle cl_handle, G_ArenaHandle arena); -void G_ResetArena(G_CommandListHandle cl_handle, G_ArenaHandle arena_handle); +void G_ReleaseArena(G_CommandListHandle cl, G_ArenaHandle arena); +void G_ResetArena(G_CommandListHandle cl, G_ArenaHandle arena); //////////////////////////////////////////////////////////// //~ @hookdecl Memory @@ -470,14 +470,13 @@ G_BaseDescriptorIndex G_PushMemory(G_CommandListHandle cl, G_ArenaHandle gpu_are .kind = G_MemoryKind_Texture1D, \ .texture = { \ .format = (_format), \ - .dims = VEC3I32((_dims).x, 1, 1), \ + .dims = VEC3I32((_dims), 1, 1), \ .initial_layout = (_initial_layout), \ __VA_ARGS__ \ } \ } \ )}) - #define G_PushTexture2D(_cl, _arena, _initial_layout, _format, _dims, ...) ( \ (G_TextureRef) { .v = G_PushMemory((_cl), (_arena), (G_MemoryDesc) { \ .kind = G_MemoryKind_Texture2D, \ diff --git a/src/pp/pp_vis/pp_vis_shared.cg b/src/pp/pp_vis/pp_vis_shared.cg index dacf8697..876e33fa 100644 --- a/src/pp/pp_vis/pp_vis_shared.cg +++ b/src/pp/pp_vis/pp_vis_shared.cg @@ -1,29 +1,27 @@ +//////////////////////////////////////////////////////////// +//~ Helpers + V_ParticleDesc V_DescFromParticleKind(V_ParticleKind kind) { + V_ParticleDesc descs[V_ParticleKind_COUNT] = { + #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) \ + { \ + V_ParticleKind_##name, \ + flags, \ + layer, \ + stain_rate, \ + pen_rate, \ + lifetime, \ + prune_speed_threshold, \ + LinearFromSrgb(base_color), \ + LinearFromSrgb(dry_factor) \ + }, + V_ParticlesXList(X) + #undef X + }; if (kind < 0 || kind >= V_ParticleKind_COUNT) { kind = V_ParticleKind_None; } - - V_ParticleDesc result; - { - V_ParticleDesc descs[V_ParticleKind_COUNT] = { - #define X(name, flags, layer, stain_rate, pen_rate, lifetime, prune_speed_threshold, base_color, dry_factor) \ - { \ - V_ParticleKind_##name, \ - flags, \ - layer, \ - stain_rate, \ - pen_rate, \ - lifetime, \ - prune_speed_threshold, \ - LinearFromSrgb(base_color), \ - LinearFromSrgb(dry_factor) \ - }, - V_ParticlesXList(X) - #undef X - }; - result = descs[kind]; - } - return result; + return descs[kind]; } diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 2f7ffe02..92084a91 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -1524,7 +1524,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) ////////////////////////////// //- Render - G_TextureRef draw_target = Zi; + UI_GpuFrame gpu_frame = Zi; { ////////////////////////////// //- Build render data @@ -1703,41 +1703,40 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) ////////////////////////////// //- Upload data to GPU - UI_GpuParams params = Zi; + G_ZoneDF(UI.cl, "UI upload") + { + // Target + gpu_frame.target_size = draw_size; + gpu_frame.target = G_PushTexture2D( + UI.cl, UI.gpu_frame_arena, + G_TextureLayout_Family, + G_Format_R16G16B16A16_Float, + gpu_frame.target_size, + .flags = G_MemoryFlag_AllowTextureDraw, + .name = Lit("UI draw target") + ); - // Target - draw_target = G_PushTexture2D( - UI.cl, UI.gpu_frame_arena, - G_TextureLayout_Family, - G_Format_R16G16B16A16_Float, - monitor_size, - .flags = G_MemoryFlag_AllowTextureDraw, - .name = Lit("UI draw target") - ); + // Rects + gpu_frame.rects_count = ArenaCount(frame->rects_arena, UI_GpuRect); + gpu_frame.rects = G_PushStructsFromCpu( + UI.cl, UI.gpu_frame_arena, + ArenaFirst(frame->rects_arena, UI_GpuRect), gpu_frame.rects_count, + .name = Lit("UI rects") + ); - // Rects - UI_GpuRect *rects = ArenaFirst(frame->rects_arena, UI_GpuRect); - u64 rects_count = ArenaCount(frame->rects_arena, UI_GpuRect); - params.rects = G_PushStructsFromCpu( - UI.cl, UI.gpu_frame_arena, - rects, rects_count, - .name = Lit("UI rects") - ); + // Frame + gpu_frame.sampler = G_BasicSamplerFromKind(G_BasicSamplerKind_PointClamp); + gpu_frame.cursor_pos = frame->cursor_pos; + gpu_frame.anti_aliasing = TweakFloat("UI anti-aliasing", 1, 0, 1); + G_BufferRef gpu_frame_buff = G_PushStructFromCpu( + UI.cl, UI.gpu_frame_arena, + &gpu_frame, + .name = Lit("UI gpu frame") + ); - // Params - params.target = draw_target; - params.target_size = draw_size; - params.sampler = G_BasicSamplerFromKind(G_BasicSamplerKind_PointClamp); - params.cursor_pos = frame->cursor_pos; - params.anti_aliasing = TweakFloat("UI anti-aliasing", 1, 0, 1); - G_BufferRef params_buff = G_PushStructFromCpu( - UI.cl, UI.gpu_frame_arena, - ¶ms, - .name = Lit("UI gpu params") - ); - - // Init constants - G_SetConstant(UI.cl, UI_GpuConst_Params, params_buff); + // Init constants + G_SetConstant(UI.cl, UI_GpuConst_Frame, gpu_frame_buff); + } // Sync G_Sync(UI.cl); @@ -1749,25 +1748,25 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) G_ZoneDF(UI.cl, "UI clear") { - G_ClearRenderTarget(UI.cl, draw_target, VEC4(0, 0, 0, 0), 0); + G_ClearRenderTarget(UI.cl, gpu_frame.target, VEC4(0, 0, 0, 0), 0); } - //- Rect pass + //- Rects pass - // Render rects G_ZoneDF(UI.cl, "UI rects") { G_Draw( UI.cl, UI_DRectVS, UI_DRectPS, - rects_count, G_QuadIndices(), - 1, &G_RT(draw_target, G_BlendMode_CompositePremultipliedAlpha), + gpu_frame.rects_count, G_QuadIndices(), + 1, &G_RT(gpu_frame.target, G_BlendMode_CompositePremultipliedAlpha), draw_viewport, draw_scissor, G_DrawMode_TriangleList ); } - // Render rect wireframes + //- Wireframe rects pass + if (AnyBit(frame->frame_flags, UI_FrameFlag_Debug)) { G_ZoneDF(UI.cl, "UI debug rects") @@ -1776,8 +1775,8 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) G_Draw( UI.cl, UI_DRectVS, UI_DRectPS, - rects_count, G_QuadIndices(), - 1, &G_RT(draw_target, G_BlendMode_CompositePremultipliedAlpha), + gpu_frame.rects_count, G_QuadIndices(), + 1, &G_RT(gpu_frame.target, G_BlendMode_CompositePremultipliedAlpha), draw_viewport, draw_scissor, G_DrawMode_WireTriangleList ); @@ -1790,7 +1789,7 @@ void UI_EndFrame(UI_Frame *frame, i32 vsync) //- End frame G_CommitCommandList(UI.cl); - WND_EndFrame(frame->window_frame, VEC2I32(0, 0), draw_target, RNG2I32(VEC2I32(0, 0), draw_size), vsync); + WND_EndFrame(frame->window_frame, VEC2I32(0, 0), gpu_frame.target, RNG2I32(VEC2I32(0, 0), gpu_frame.target_size), vsync); EndScratch(scratch); } diff --git a/src/ui/ui_gpu.g b/src/ui/ui_gpu.g index b1118e7c..08d60e82 100644 --- a/src/ui/ui_gpu.g +++ b/src/ui/ui_gpu.g @@ -6,8 +6,8 @@ VertexShader(UI_DRectVS, UI_DRectPSInput) { - UI_GpuParams params = G_Deref(UI_GpuConst_Params, StructuredBuffer)[0]; - StructuredBuffer rects = G_Deref(params.rects, StructuredBuffer); + UI_GpuFrame frame = G_Deref(UI_GpuConst_Frame, StructuredBuffer)[0]; + StructuredBuffer rects = G_Deref(frame.rects, StructuredBuffer); UI_GpuRect rect = rects[SV_InstanceID]; Vec2 rect_uv = RectUvFromIdx(SV_VertexID); @@ -16,7 +16,7 @@ VertexShader(UI_DRectVS, UI_DRectPSInput) UI_DRectPSInput result; { - result.sv_position = Vec4(NdcFromPos(target_pos, Vec2(params.target_size).xy), 0, 1); + result.sv_position = Vec4(NdcFromPos(target_pos, Vec2(frame.target_size).xy), 0, 1); result.base_background_premul = Premul(rect.background_lin); result.base_border_premul = Premul(rect.border_lin); result.tint_premul = Premul(rect.tint_lin); @@ -33,8 +33,8 @@ VertexShader(UI_DRectVS, UI_DRectPSInput) PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) { - UI_GpuParams params = G_Deref(UI_GpuConst_Params, StructuredBuffer)[0]; - SamplerState sampler = G_Deref(params.sampler, SamplerState); + UI_GpuFrame frame = G_Deref(UI_GpuConst_Frame, StructuredBuffer)[0]; + SamplerState sampler = G_Deref(frame.sampler, SamplerState); UI_GpuRect rect = input.rect; Vec2 rect_uv = input.rect_uv; @@ -93,7 +93,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input) //- Compute anti-aliased border-over-background color Vec4 composite_premul = 0; { - f32 smoothness = rect_dist_fwidth * params.anti_aliasing * 0.5; + f32 smoothness = rect_dist_fwidth * frame.anti_aliasing * 0.5; f32 border_coverage = smoothstep(smoothness, -smoothness, border_dist); composite_premul = lerp(background_premul, border_premul, border_coverage); } diff --git a/src/ui/ui_shared.cgh b/src/ui/ui_shared.cgh index 6a1211f0..686b2c5a 100644 --- a/src/ui/ui_shared.cgh +++ b/src/ui/ui_shared.cgh @@ -1,22 +1,3 @@ -//////////////////////////////////////////////////////////// -//~ Constant types - -G_DeclConstant(G_BufferRef, UI_GpuConst_Params, 0); -G_DeclConstant(b32, UI_GpuConst_DebugDraw, 1); - -Struct(UI_GpuParams) -{ - f32 anti_aliasing; - - Vec2I32 target_size; - G_TextureRef target; - - Vec2 cursor_pos; - - G_BufferRef rects; - G_SamplerRef sampler; -}; - //////////////////////////////////////////////////////////// //~ Rect types @@ -38,3 +19,23 @@ Struct(UI_GpuRect) f32 br_rounding; f32 bl_rounding; }; + +//////////////////////////////////////////////////////////// +//~ State types + +G_DeclConstant(G_BufferRef, UI_GpuConst_Frame, 0); +G_DeclConstant(b32, UI_GpuConst_DebugDraw, 1); + +Struct(UI_GpuFrame) +{ + f32 anti_aliasing; + + Vec2I32 target_size; + G_TextureRef target; + + Vec2 cursor_pos; + + u64 rects_count; + G_BufferRef rects; + G_SamplerRef sampler; +};