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" #include "meta.h"
Atomic32 g_status = ZI;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Helpers //~ Helpers
i32 GetBuildStatus(void)
{
return Atomic32Fetch(&g_status);
}
void SetBuildStatus(i32 code)
{
Atomic32FetchTestSet(&g_status, 0, code);
}
void EchoLine(String msg) void EchoLine(String msg)
{ {
TempArena scratch = BeginScratchNoConflict(); TempArena scratch = BeginScratchNoConflict();
@ -89,6 +101,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
{ {
Arena *perm = PermArena(); Arena *perm = PermArena();
////////////////////////////// //////////////////////////////
//- Dirty check //- 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))); 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> * Phase 5
* | * - Shader resource compilation process
* <FULL BARRIER> ------------------------------------------------------------- * - Embedded resource compilation processes
* *
* ## Phase 3 * Phase 6
* <shader resource arcs> <embedded resource arcs>
* | |
* <FULL BARRIER> -------------------------------------------------------------
*
* ## Phase 4
* <shader resource oscmd> <embedded resource oscmds>
* <FULL BARRIER> -------------------------------------------------------------
*
* ## Phase 5
*
* <link oscmd>
*/ */
/* 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; BuildData *build = 0;
if (lane->idx == 0) if (lane->idx == 0)
@ -298,12 +308,10 @@ void BuildEntryPoint(WaveLaneCtx *lane)
} }
WaveSyncBroadcast(lane, 0, &build); 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 //- Parse layers
{ {
@ -319,6 +327,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
StringList starting_layer_names = ZI; StringList starting_layer_names = ZI;
PushStringToList(perm, &starting_layer_names, cmdline.leaf_layer_name); PushStringToList(perm, &starting_layer_names, cmdline.leaf_layer_name);
build->flattened = M_GetFlattenedEntries(perm, parsed, starting_layer_names); build->flattened = M_GetFlattenedEntries(perm, parsed, starting_layer_names);
SetBuildStatus(build->flattened.errors.count > 0);
} }
//- Generate C file //- Generate C file
@ -482,6 +492,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
String c_out = StringFromList(perm, c_out_lines, Lit("\n")); String c_out = StringFromList(perm, c_out_lines, Lit("\n"));
F_ClearWrite(c_out_file, c_out); F_ClearWrite(c_out_file, c_out);
} }
SetBuildStatus(build->cgen.errors.count > 0);
} }
//- Generate HLSL file //- Generate HLSL file
@ -600,6 +612,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
build->gpucomps.count = build->gpugen.shader_entries_count; build->gpucomps.count = build->gpugen.shader_entries_count;
build->gpucomps.array = PushStructs(perm, GpuComp, build->gpucomps.count); build->gpucomps.array = PushStructs(perm, GpuComp, build->gpucomps.count);
SetBuildStatus(build->gpugen.errors.count > 0);
} }
//- Generate archive info //- Generate archive info
@ -657,19 +671,17 @@ void BuildEntryPoint(WaveLaneCtx *lane)
build->rescomps.count = build->arcinfogen.arc_entries_count; build->rescomps.count = build->arcinfogen.arc_entries_count;
build->rescomps.array = PushStructs(perm, ResComp, build->rescomps.count); build->rescomps.array = PushStructs(perm, ResComp, build->rescomps.count);
SetBuildStatus(build->arcinfogen.errors.count > 0);
} }
} }
WaveSync(lane); 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; u64 task_idx = 0;
@ -690,6 +702,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
String cmd_output = TrimWhitespace(cmd_result.output); String cmd_output = TrimWhitespace(cmd_result.output);
build->ccomp.output = cmd_output; build->ccomp.output = cmd_output;
build->ccomp.return_code = cmd_result.code; 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(" ")))); FmtString(StringFromList(perm, cp.flags_dxc, Lit(" "))));
OS_CommandResult cmd_result = OS_RunCommand(perm, compile_cmd); OS_CommandResult cmd_result = OS_RunCommand(perm, compile_cmd);
gpucomp->output = cmd_result.output;
if (cmd_result.code == 0) gpucomp->return_code = cmd_result.code;
{ SetBuildStatus(gpucomp->return_code);
gpucomp->output = cmd_result.output;
gpucomp->return_code = cmd_result.code;
}
} }
++gpucomp_idx; ++gpucomp_idx;
} }
@ -729,16 +740,11 @@ void BuildEntryPoint(WaveLaneCtx *lane)
} }
WaveSync(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 //- Generate resource archives
if (!ret) if (GetBuildStatus() == 0)
{ {
u32 task_idx = 0; u32 task_idx = 0;
for (ArcInfoEntry *entry = build->arcinfogen.first_arc_entry; entry; entry = entry->next) for (ArcInfoEntry *entry = build->arcinfogen.first_arc_entry; entry; entry = entry->next)
@ -854,7 +860,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
////////////////////////////// //////////////////////////////
//- Compile resource archives //- Compile resource archives
if (!ret) if (GetBuildStatus() == 0)
{ {
if (IsPlatformWindows) if (IsPlatformWindows)
{ {
@ -889,6 +895,8 @@ void BuildEntryPoint(WaveLaneCtx *lane)
rescomp->output = cmd_output; rescomp->output = cmd_output;
rescomp->return_code = cmd_result.code; rescomp->return_code = cmd_result.code;
} }
SetBuildStatus(rescomp->return_code);
} }
++rescomp_idx; ++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 //- 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)); 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; build->link.return_code = result.code;
i64 link_elapsed_ns = TimeNs() - start_ns; i64 link_elapsed_ns = TimeNs() - start_ns;
// EchoLine(StringF(perm, ">>>>> Linked in %Fs", FmtFloat(SecondsFromNs(link_elapsed_ns)))); // EchoLine(StringF(perm, ">>>>> Linked in %Fs", FmtFloat(SecondsFromNs(link_elapsed_ns))));
SetBuildStatus(build->link.return_code);
} }
WaveSync(lane); WaveSync(lane);
if (!ret) ret = build->link.return_code;
////////////////////////////// //////////////////////////////
//- Process output & errors //- Process output & errors
@ -991,7 +996,7 @@ void BuildEntryPoint(WaveLaneCtx *lane)
if (lane->idx == 0) if (lane->idx == 0)
{ {
EchoLine(StringF(perm, "Runtime: %Fs", FmtFloat(SecondsFromNs(TimeNs())))); EchoLine(StringF(perm, "Runtime: %Fs", FmtFloat(SecondsFromNs(TimeNs()))));
ExitNow(ret); ExitNow(GetBuildStatus());
} }
} }

View File

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