power_play/src/proto/proto.c

76 lines
2.3 KiB
C

void PT_RunForever(WaveLaneCtx *lane)
{
Arena *frame_arena = AcquireArena(Gibi(64));
G_ArenaHandle gpu_frame_arena = G_AcquireArena();
for (;;)
{
ResetArena(frame_arena);
PT_SharedFrame *frame = PushStruct(frame_arena, PT_SharedFrame);
WND_Frame window_frame = WND_BeginFrame(G_Format_R16G16B16A16_Float, WND_BackbufferSizeMode_MatchWindow);
G_BackbufferHandle backbuffer = window_frame.backbuffer;
for (u64 cev_idx = 0; cev_idx < window_frame.controller_events.count; ++cev_idx)
{
ControllerEvent *cev = &window_frame.controller_events.events[cev_idx];
if (cev->kind == ControllerEventKind_Quit || (cev->kind == ControllerEventKind_ButtonDown && cev->button == Button_Escape))
{
SignalExit(0);
}
}
G_CommandListHandle cl = G_PrepareCommandList(G_QueueKind_Direct);
{
// Gpu upload pass
{
G_ResetArena(cl, gpu_frame_arena);
frame->noise_tex = G_BasicNoise3D();
frame->sampler = G_BasicSamplerFromKind(G_BasicSamplerKind_PointClamp);
frame->compute_target = G_PushTexture2D(
cl, gpu_frame_arena,
G_TextureLayout_Family,
G_Format_R16G16B16A16_Float,
window_frame.draw_size,
.flags = G_MemoryFlag_AllowTextureRW
);
frame->screen = G_PushTexture2D(
cl, gpu_frame_arena,
G_TextureLayout_Family,
G_Format_R16G16B16A16_Float,
window_frame.draw_size,
.flags = G_MemoryFlag_AllowTextureRW | G_MemoryFlag_AllowTextureDraw
);
G_SetConstant(cl, PT_ShaderConst_Frame, G_PushStructFromCpu(cl, gpu_frame_arena, frame));
}
G_Sync(cl);
// Test pass
{
G_Compute2D(cl, PT_TestCS, G_Count2D(frame->compute_target));
}
G_Sync(cl);
// Blit pass
G_Draw(
cl,
PT_BlitVS, PT_BlitPS,
1, G_QuadIndices(),
1, &G_RT(frame->screen, G_BlendMode_CompositeStraightAlpha),
G_ViewportFromTexture(frame->screen), G_ScissorFromTexture(frame->screen),
G_DrawMode_TriangleList
);
}
G_CommitCommandList(cl);
WND_EndFrame(window_frame, VEC2I32(0, 0), frame->screen, RNG2I32(VEC2I32(0, 0), G_Count2D(frame->screen)), 1);
}
}
void PT_Bootstrap(void)
{
DispatchWave(Lit("Proto"), 1, PT_RunForever, 0);
}