ui gpu 'params' -> 'frame'

This commit is contained in:
jacob 2026-03-14 18:45:15 -05:00
parent 06bea119ff
commit 065aedccc3
5 changed files with 90 additions and 93 deletions

View File

@ -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, \

View File

@ -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];
}

View File

@ -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,
&params,
.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);
}

View File

@ -6,8 +6,8 @@
VertexShader(UI_DRectVS, UI_DRectPSInput)
{
UI_GpuParams params = G_Deref(UI_GpuConst_Params, StructuredBuffer<UI_GpuParams>)[0];
StructuredBuffer<UI_GpuRect> rects = G_Deref(params.rects, StructuredBuffer<UI_GpuRect>);
UI_GpuFrame frame = G_Deref(UI_GpuConst_Frame, StructuredBuffer<UI_GpuFrame>)[0];
StructuredBuffer<UI_GpuRect> rects = G_Deref(frame.rects, StructuredBuffer<UI_GpuRect>);
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<UI_GpuParams>)[0];
SamplerState sampler = G_Deref(params.sampler, SamplerState);
UI_GpuFrame frame = G_Deref(UI_GpuConst_Frame, StructuredBuffer<UI_GpuFrame>)[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);
}

View File

@ -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;
};