formatting

This commit is contained in:
jacob 2025-12-07 06:56:33 -06:00
parent 74413ca702
commit 32002c75bb
2 changed files with 64 additions and 52 deletions

View File

@ -1,8 +1,20 @@
#include "meta.h"
Atomic32 g_status = ZI;
////////////////////////////////////////////////////////////
//~ Helpers
i32 GetBuildStatus(void)
{
return Atomic32Fetch(&g_status);
}
void SetBuildStatus(i32 code)
{
Atomic32FetchTestSet(&g_status, 0, code);
}
void EchoLine(String msg)
{
TempArena scratch = BeginScratchNoConflict();
@ -89,6 +101,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
{
Arena *perm = PermArena();
//////////////////////////////
//- Dirty check
@ -263,33 +276,30 @@ void BuildEntryPoint(WaveLaneCtx *lane)
String gpu_out_file = F_GetFull(perm, StringF(perm, "%F_gen_gpu.hlsl", FmtString(cmdline.leaf_layer_name)));
/*
* ## Phase 1
* Phase 1
* - Parse layers
*
* <Parse layers> <Generate C> <Generate HLSL>
* Phase 2
* - Generate final C file
* - Generate final HLSL file
* - Generate resource archive info
*
* <FULL BARRIER> -------------------------------------------------------------
* Phase 3
* - C compiler process
* - HLSL compiler processes
*
* ## Phase 2
* Phase 4
* - Generate shader resource archive
* - Generate embedded resource archives
*
* <C compile oscmd> <shader compile oscmds>
* |
* <FULL BARRIER> -------------------------------------------------------------
* Phase 5
* - Shader resource compilation process
* - Embedded resource compilation processes
*
* ## Phase 3
* <shader resource arcs> <embedded resource arcs>
* | |
* <FULL BARRIER> -------------------------------------------------------------
*
* ## Phase 4
* <shader resource oscmd> <embedded resource oscmds>
* <FULL BARRIER> -------------------------------------------------------------
*
* ## Phase 5
*
* <link oscmd>
* Phase 6
*/
/* TODO: Dispatch OS Cmds asynchronously rather than synchronously waiting on each lane */
/* TODO: Dispatch OS processes asynchronously rather than synchronously waiting on each lane */
BuildData *build = 0;
if (lane->idx == 0)
@ -298,12 +308,10 @@ void BuildEntryPoint(WaveLaneCtx *lane)
}
WaveSyncBroadcast(lane, 0, &build);
i32 ret = 0;
//////////////////////////////
//- Parse layers, generate final C file, generate final HLSL file, and gather resource archive info
//- Parse meta layer info into build data
if (lane->idx == 0 && !ret)
if (lane->idx == 0 && GetBuildStatus() == 0)
{
//- Parse layers
{
@ -319,6 +327,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
StringList starting_layer_names = ZI;
PushStringToList(perm, &starting_layer_names, cmdline.leaf_layer_name);
build->flattened = M_GetFlattenedEntries(perm, parsed, starting_layer_names);
SetBuildStatus(build->flattened.errors.count > 0);
}
//- Generate C file
@ -482,6 +492,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
String c_out = StringFromList(perm, c_out_lines, Lit("\n"));
F_ClearWrite(c_out_file, c_out);
}
SetBuildStatus(build->cgen.errors.count > 0);
}
//- Generate HLSL file
@ -600,6 +612,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
build->gpucomps.count = build->gpugen.shader_entries_count;
build->gpucomps.array = PushStructs(perm, GpuComp, build->gpucomps.count);
SetBuildStatus(build->gpugen.errors.count > 0);
}
//- Generate archive info
@ -657,19 +671,17 @@ void BuildEntryPoint(WaveLaneCtx *lane)
build->rescomps.count = build->arcinfogen.arc_entries_count;
build->rescomps.array = PushStructs(perm, ResComp, build->rescomps.count);
SetBuildStatus(build->arcinfogen.errors.count > 0);
}
}
WaveSync(lane);
if (!ret) ret = build->cgen.errors.count > 0;
if (!ret) ret = build->gpugen.errors.count > 0;
if (!ret) ret = build->arcinfogen.errors.count > 0;
if (!ret) ret = build->flattened.errors.count > 0;
//////////////////////////////
//- Compile C & Shaders
//- Compile
if (!ret)
if (GetBuildStatus() == 0)
{
u64 task_idx = 0;
@ -690,6 +702,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
String cmd_output = TrimWhitespace(cmd_result.output);
build->ccomp.output = cmd_output;
build->ccomp.return_code = cmd_result.code;
SetBuildStatus(build->ccomp.return_code);
}
}
@ -716,12 +730,9 @@ void BuildEntryPoint(WaveLaneCtx *lane)
FmtString(StringFromList(perm, cp.flags_dxc, Lit(" "))));
OS_CommandResult cmd_result = OS_RunCommand(perm, compile_cmd);
if (cmd_result.code == 0)
{
gpucomp->output = cmd_result.output;
gpucomp->return_code = cmd_result.code;
}
gpucomp->output = cmd_result.output;
gpucomp->return_code = cmd_result.code;
SetBuildStatus(gpucomp->return_code);
}
++gpucomp_idx;
}
@ -729,16 +740,11 @@ void BuildEntryPoint(WaveLaneCtx *lane)
}
WaveSync(lane);
if (!ret) ret = build->ccomp.return_code;
for (u32 i = 0; i < build->gpucomps.count; ++i)
{
if (!ret) ret = build->gpucomps.array[i].return_code;
}
//////////////////////////////
//- Generate resource archives
if (!ret)
if (GetBuildStatus() == 0)
{
u32 task_idx = 0;
for (ArcInfoEntry *entry = build->arcinfogen.first_arc_entry; entry; entry = entry->next)
@ -854,7 +860,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
//////////////////////////////
//- Compile resource archives
if (!ret)
if (GetBuildStatus() == 0)
{
if (IsPlatformWindows)
{
@ -889,6 +895,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
rescomp->output = cmd_output;
rescomp->return_code = cmd_result.code;
}
SetBuildStatus(rescomp->return_code);
}
++rescomp_idx;
@ -901,16 +909,12 @@ void BuildEntryPoint(WaveLaneCtx *lane)
}
}
WaveSync(lane);
for (u32 i = 0; i < build->rescomps.count; ++i)
{
if (!ret) ret = build->rescomps.array[i].return_code;
}
//////////////////////////////
//- Link
if (lane->idx == 0 && !ret)
WaveSync(lane);
if (lane->idx == 0 && GetBuildStatus() == 0)
{
String exe_file = StringF(perm, "%F.exe", FmtString(cmdline.leaf_layer_name));
{
@ -945,10 +949,11 @@ void BuildEntryPoint(WaveLaneCtx *lane)
build->link.return_code = result.code;
i64 link_elapsed_ns = TimeNs() - start_ns;
// EchoLine(StringF(perm, ">>>>> Linked in %Fs", FmtFloat(SecondsFromNs(link_elapsed_ns))));
SetBuildStatus(build->link.return_code);
}
WaveSync(lane);
if (!ret) ret = build->link.return_code;
//////////////////////////////
//- Process output & errors
@ -991,7 +996,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
if (lane->idx == 0)
{
EchoLine(StringF(perm, "Runtime: %Fs", FmtFloat(SecondsFromNs(TimeNs()))));
ExitNow(ret);
ExitNow(GetBuildStatus());
}
}

View File

@ -172,9 +172,16 @@ Struct(LineCol)
i64 col;
};
////////////////////////////////////////////////////////////
//~ Globals
extern Atomic32 g_status;
////////////////////////////////////////////////////////////
//~ Helpers
i32 GetBuildStatus(void);
void SetBuildStatus(i32 code);
void EchoLine(String msg);
void EchoLineOrNothing(String msg);
LineCol LineColFromPos(String data, i64 pos);