From 9283b69c00785f7414f85debad6313e98b00fa6c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 16 Sep 2025 07:34:35 +1000 Subject: [PATCH] Xbox: Keep generated vs/ps ASM files --- misc/ps3/Makefile | 4 ++ misc/xbox/Makefile | 24 ++++++---- misc/xbox/README.md | 4 ++ misc/xbox/ps_coloured.asm | 14 ++++++ .../{ps_coloured.ps.cg => ps_coloured.cg} | 0 misc/xbox/ps_textured.asm | 30 ++++++++++++ .../{ps_textured.ps.cg => ps_textured.cg} | 0 misc/xbox/vs_coloured.asm | 24 ++++++++++ .../{vs_coloured.vs.cg => vs_coloured.cg} | 0 misc/xbox/vs_offset.asm | 29 ++++++++++++ misc/xbox/{vs_offset.vs.cg => vs_offset.cg} | 0 misc/xbox/vs_offset.inl | 2 +- misc/xbox/vs_textured.asm | 27 +++++++++++ .../{vs_textured.vs.cg => vs_textured.cg} | 0 third_party/citro3d.c | 47 ++++--------------- 15 files changed, 157 insertions(+), 48 deletions(-) create mode 100644 misc/xbox/ps_coloured.asm rename misc/xbox/{ps_coloured.ps.cg => ps_coloured.cg} (100%) create mode 100644 misc/xbox/ps_textured.asm rename misc/xbox/{ps_textured.ps.cg => ps_textured.cg} (100%) create mode 100644 misc/xbox/vs_coloured.asm rename misc/xbox/{vs_coloured.vs.cg => vs_coloured.cg} (100%) create mode 100644 misc/xbox/vs_offset.asm rename misc/xbox/{vs_offset.vs.cg => vs_offset.cg} (100%) create mode 100644 misc/xbox/vs_textured.asm rename misc/xbox/{vs_textured.vs.cg => vs_textured.cg} (100%) diff --git a/misc/ps3/Makefile b/misc/ps3/Makefile index 9064a20e3..370863e02 100644 --- a/misc/ps3/Makefile +++ b/misc/ps3/Makefile @@ -139,6 +139,10 @@ $(BUILD_DIR)/%.o: src/ps3/%.S $(BUILD_DIR)/%.o: third_party/bearssl/%.c $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ + +# prevent the .asm files from being deleted +.PRECIOUS: $(BUILD_DIR)/%.vpo $(BUILD_DIR)/%.fpo + $(BUILD_DIR)/%.vpo: $(SHADERS)/%.vcg $(CGCOMP) -v $(CGCFLAGS) $^ $@ $(BUILD_DIR)/%.fpo: $(SHADERS)/%.fcg diff --git a/misc/xbox/Makefile b/misc/xbox/Makefile index 3f006f719..c996ef87a 100644 --- a/misc/xbox/Makefile +++ b/misc/xbox/Makefile @@ -82,7 +82,7 @@ $(BUILD_DIR): #--------------------------------------------------------------------------------- # Executable generation #--------------------------------------------------------------------------------- -$(OBJS) : $(SHADER_OBJS) +$(BUILD_DIR)/Graphics_Xbox.o : $(SHADER_OBJS) $(TARGET).iso: $(TARGET).xbe mkdir -p $(BUILD_DIR)/cd @@ -111,15 +111,21 @@ $(BUILD_DIR)/%.o: src/xbox/%.S $(BUILD_DIR)/%.o: third_party/bearssl/%.c nxdk-cc $(NXDK_CFLAGS) $(CFLAGS) -c $< -o $@ -%.inl: %.vs.cg - $(CGC) -profile vp20 -o $@.$$$$ $< && \ - $(VP20COMPILER) $@.$$$$ > $@ && \ - rm -rf $@.$$$$ -%.inl: %.ps.cg - $(CGC) -profile fp20 -o $@.$$$$ $< && \ - $(FP20COMPILER) $@.$$$$ > $@ && \ - rm -rf $@.$$$$ +# prevent the .asm files from being deleted +.PRECIOUS: vs_%.asm ps_%.asm + +vs_%.inl: vs_%.asm + $(VP20COMPILER) $< > $@ + +vs_%.asm: vs_%.cg + $(CGC) -profile vp20 $< -o $@ + +ps_%.inl: ps_%.asm + $(FP20COMPILER) $< > $@ + +ps_%.asm: ps_%.cg + $(CGC) -profile fp20 $< -o $@ #--------------------------------------------------------------------------------- diff --git a/misc/xbox/README.md b/misc/xbox/README.md index f5da3eb2f..a813c938b 100644 --- a/misc/xbox/README.md +++ b/misc/xbox/README.md @@ -5,3 +5,7 @@ To see debug log messages in Xemu: ---- To launch directly, `-dvd_path cc-xbox.iso` + +#### + +The .asm files are auto generated from the .cg files, and shouldn't be manually edited. diff --git a/misc/xbox/ps_coloured.asm b/misc/xbox/ps_coloured.asm new file mode 100644 index 000000000..756815cbe --- /dev/null +++ b/misc/xbox/ps_coloured.asm @@ -0,0 +1,14 @@ +// nvparse 1.0 output generated by NVIDIA Cg compiler +// cgc version 3.1.0013, build date Apr 24 2012 +// command line args: -profile fp20 +// source file: misc/xbox/ps_coloured.cg +//vendor NVIDIA Corporation +//version 3.1.0.13 +//profile fp20 +//program main +//var float4 input.color : $vin.COLOR : COLOR0 : 0 : 1 +//var float4 main : $vout.COLOR : COLOR : -1 : 1 +!!RC1.0 +out.rgb = unsigned(col0.rgb); +out.a = unsigned(col0.a); +// 0 instructions diff --git a/misc/xbox/ps_coloured.ps.cg b/misc/xbox/ps_coloured.cg similarity index 100% rename from misc/xbox/ps_coloured.ps.cg rename to misc/xbox/ps_coloured.cg diff --git a/misc/xbox/ps_textured.asm b/misc/xbox/ps_textured.asm new file mode 100644 index 000000000..99fc0c06e --- /dev/null +++ b/misc/xbox/ps_textured.asm @@ -0,0 +1,30 @@ +// nvparse 1.0 output generated by NVIDIA Cg compiler +// cgc version 3.1.0013, build date Apr 24 2012 +// command line args: -profile fp20 +// source file: misc/xbox/ps_textured.cg +//vendor NVIDIA Corporation +//version 3.1.0.13 +//profile fp20 +//program main +//semantic main.tex +//var sampler2D tex : : 0 : 1 : 1 +//var float4 input.color : $vin.COLOR : COLOR0 : 0 : 1 +//var float2 input.tex0 : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1 +//var float4 main : $vout.COLOR : COLOR : -1 : 1 +!!TS1.0 +texture_2d(); +// End of program +!!RC1.0 +{ + rgb + { + col0 = tex0.rgb * col0.rgb; + } + alpha + { + col0 = tex0.a * col0.a; + } +} +out.rgb = unsigned(col0.rgb); +out.a = unsigned(col0.a); +// 3 instructions diff --git a/misc/xbox/ps_textured.ps.cg b/misc/xbox/ps_textured.cg similarity index 100% rename from misc/xbox/ps_textured.ps.cg rename to misc/xbox/ps_textured.cg diff --git a/misc/xbox/vs_coloured.asm b/misc/xbox/vs_coloured.asm new file mode 100644 index 000000000..f3b4462df --- /dev/null +++ b/misc/xbox/vs_coloured.asm @@ -0,0 +1,24 @@ +!!VP1.1 +# cgc version 3.1.0013, build date Apr 24 2012 +# command line args: -profile vp20 +# source file: misc/xbox/vs_coloured.cg +#vendor NVIDIA Corporation +#version 3.1.0.13 +#profile vp20 +#program main +#semantic main.mvp +#var float4 input.col : $vin.DIFFUSE : ATTR3 : 0 : 1 +#var float4 input.pos : $vin.POSITION : ATTR0 : 0 : 1 +#var float4x4 mvp : : c[0], 4 : 1 : 1 +#var float4 main.col : $vout.COLOR : COL0 : -1 : 1 +#var float4 main.pos : $vout.POSITION : HPOS : -1 : 1 +MUL R0, v[0].y, c[1]; +MAD R0, v[0].x, c[0], R0; +MAD R0, v[0].z, c[2], R0; +ADD R0, R0, c[3]; +RCP R1.x, R0.w; +MUL o[HPOS].xyz, R0, R1.x; +MOV o[COL0], v[3]; +MOV o[HPOS].w, R0; +END +# 8 instructions, 0 R-regs diff --git a/misc/xbox/vs_coloured.vs.cg b/misc/xbox/vs_coloured.cg similarity index 100% rename from misc/xbox/vs_coloured.vs.cg rename to misc/xbox/vs_coloured.cg diff --git a/misc/xbox/vs_offset.asm b/misc/xbox/vs_offset.asm new file mode 100644 index 000000000..fc0a6d64b --- /dev/null +++ b/misc/xbox/vs_offset.asm @@ -0,0 +1,29 @@ +!!VP1.1 +# cgc version 3.1.0013, build date Apr 24 2012 +# command line args: -profile vp20 +# source file: misc/xbox/vs_offset.cg +#vendor NVIDIA Corporation +#version 3.1.0.13 +#profile vp20 +#program main +#semantic main.mvp +#semantic main.tex_offset +#var float4 input.tex : $vin.TEXCOORD : TEXCOORD0 : 0 : 1 +#var float4 input.col : $vin.DIFFUSE : ATTR3 : 0 : 1 +#var float4 input.pos : $vin.POSITION : ATTR0 : 0 : 1 +#var float4x4 mvp : : c[0], 4 : 1 : 1 +#var float4 tex_offset : : c[4] : 2 : 1 +#var float4 main.pos : $vout.POSITION : HPOS : -1 : 1 +#var float4 main.col : $vout.COLOR : COL0 : -1 : 1 +#var float4 main.tex : $vout.TEXCOORD0 : TEX0 : -1 : 1 +MUL R0, v[0].y, c[1]; +MAD R0, v[0].x, c[0], R0; +MAD R0, v[0].z, c[2], R0; +ADD R0, R0, c[3]; +RCP R1.x, R0.w; +MUL o[HPOS].xyz, R0, R1.x; +MOV o[HPOS].w, R0; +MOV o[COL0], v[3]; +ADD o[TEX0], v[8], c[4]; +END +# 9 instructions, 0 R-regs diff --git a/misc/xbox/vs_offset.vs.cg b/misc/xbox/vs_offset.cg similarity index 100% rename from misc/xbox/vs_offset.vs.cg rename to misc/xbox/vs_offset.cg diff --git a/misc/xbox/vs_offset.inl b/misc/xbox/vs_offset.inl index a2395317b..135f1576d 100644 --- a/misc/xbox/vs_offset.inl +++ b/misc/xbox/vs_offset.inl @@ -1,6 +1,6 @@ // cgc version 3.1.0013, build date Apr 24 2012 // command line args: -profile vp20 -// source file: misc/xbox/vs_offset.vs.cg +// source file: misc/xbox/vs_offset.cg //vendor NVIDIA Corporation //version 3.1.0.13 //profile vp20 diff --git a/misc/xbox/vs_textured.asm b/misc/xbox/vs_textured.asm new file mode 100644 index 000000000..aaa6b3740 --- /dev/null +++ b/misc/xbox/vs_textured.asm @@ -0,0 +1,27 @@ +!!VP1.1 +# cgc version 3.1.0013, build date Apr 24 2012 +# command line args: -profile vp20 +# source file: misc/xbox/vs_textured.cg +#vendor NVIDIA Corporation +#version 3.1.0.13 +#profile vp20 +#program main +#semantic main.mvp +#var float4 input.tex : $vin.TEXCOORD : TEXCOORD0 : 0 : 1 +#var float4 input.col : $vin.DIFFUSE : ATTR3 : 0 : 1 +#var float4 input.pos : $vin.POSITION : ATTR0 : 0 : 1 +#var float4x4 mvp : : c[0], 4 : 1 : 1 +#var float4 main.pos : $vout.POSITION : HPOS : -1 : 1 +#var float4 main.col : $vout.COLOR : COL0 : -1 : 1 +#var float4 main.tex : $vout.TEXCOORD0 : TEX0 : -1 : 1 +MUL R0, v[0].y, c[1]; +MAD R0, v[0].x, c[0], R0; +MAD R0, v[0].z, c[2], R0; +ADD R0, R0, c[3]; +RCP R1.x, R0.w; +MUL o[HPOS].xyz, R0, R1.x; +MOV o[HPOS].w, R0; +MOV o[COL0], v[3]; +MOV o[TEX0], v[8]; +END +# 9 instructions, 0 R-regs diff --git a/misc/xbox/vs_textured.vs.cg b/misc/xbox/vs_textured.cg similarity index 100% rename from misc/xbox/vs_textured.vs.cg rename to misc/xbox/vs_textured.cg diff --git a/third_party/citro3d.c b/third_party/citro3d.c index b0e08d1ce..9d658e0a8 100644 --- a/third_party/citro3d.c +++ b/third_party/citro3d.c @@ -250,10 +250,8 @@ enum static bool C3D_FrameBegin(u8 flags); static bool C3D_FrameDrawOn(C3D_RenderTarget* target); -static void C3D_FrameSplit(u8 flags); static void C3D_FrameEnd(u8 flags); -static void C3D_RenderTargetDelete(C3D_RenderTarget* target); static void C3D_RenderTargetSetOutput(C3D_RenderTarget* target, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags); static inline void C3D_RenderTargetDetachOutput(C3D_RenderTarget* target) @@ -832,8 +830,6 @@ static C3D_RenderTarget *linkedTarget[3]; static bool inFrame, inSafeTransfer; static bool swapPending, isTopStereo; -static void C3Di_RenderTargetDestroy(C3D_RenderTarget* target); - static void onQueueFinish(gxCmdQueue_s* queue) { if (inSafeTransfer) @@ -907,20 +903,15 @@ static bool C3D_FrameDrawOn(C3D_RenderTarget* target) return true; } -static void C3D_FrameSplit(u8 flags) -{ - u32 *cmdBuf, cmdBufSize; - if (!inFrame) return; - if (C3Di_SplitFrame(&cmdBuf, &cmdBufSize)) - GX_ProcessCommandList(cmdBuf, cmdBufSize*4, flags); -} - static void C3D_FrameEnd(u8 flags) { C3D_Context* ctx = C3Di_GetContext(); if (!inFrame) return; - C3D_FrameSplit(flags); + u32 *cmdBuf, cmdBufSize; + if (C3Di_SplitFrame(&cmdBuf, &cmdBufSize)) + GX_ProcessCommandList(cmdBuf, cmdBufSize*4, flags); + GPUCMD_SetBuffer(NULL, 0, 0); inFrame = false; @@ -984,23 +975,6 @@ static void C3D_RenderTargetDepth(C3D_RenderTarget* target, GPU_DEPTHBUF depthFm C3D_FrameBufDepth(fb, depthBuf, depthFmt); } -static void C3Di_RenderTargetDestroy(C3D_RenderTarget* target) -{ - vramFree(target->frameBuf.colorBuf); - vramFree(target->frameBuf.depthBuf); -} - -static void C3D_RenderTargetDelete(C3D_RenderTarget* target) -{ - if (inFrame) - svcBreak(USERBREAK_PANIC); // Shouldn't happen. - if (target->linked) - C3D_RenderTargetDetachOutput(target); - else - C3Di_WaitAndClearQueue(-1); - C3Di_RenderTargetDestroy(target); -} - static void C3D_RenderTargetSetOutput(C3D_RenderTarget* target, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags) { int id = 0; @@ -1079,6 +1053,9 @@ static void C3Di_OnRestore(void) ctx->flags |= C3DiF_FogLut; } +#define GXQUEUE_MAX_ENTRIES 32 +static gxCmdEntry_s queue_entries[GXQUEUE_MAX_ENTRIES]; + static bool C3D_Init(size_t cmdBufSize) { int i; @@ -1093,13 +1070,8 @@ static bool C3D_Init(size_t cmdBufSize) if (!ctx->cmdBuf) return false; - ctx->gxQueue.maxEntries = 32; - ctx->gxQueue.entries = (gxCmdEntry_s*)malloc(ctx->gxQueue.maxEntries*sizeof(gxCmdEntry_s)); - if (!ctx->gxQueue.entries) - { - linearFree(ctx->cmdBuf); - return false; - } + ctx->gxQueue.maxEntries = GXQUEUE_MAX_ENTRIES; + ctx->gxQueue.entries = queue_entries; ctx->flags = C3DiF_Active | C3DiF_TexEnvBuf | C3DiF_Effect | C3DiF_TexStatus | C3DiF_TexAll | C3DiF_Reset; @@ -1308,7 +1280,6 @@ static void C3D_Fini(void) return; C3Di_RenderQueueExit(); - free(ctx->gxQueue.entries); linearFree(ctx->cmdBuf); ctx->flags = 0; }