From 199be2f4894ccf9dabecde0f0cb10e6a9aea895d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 8 Mar 2025 23:43:24 +1100 Subject: [PATCH] Xbox: Simplify shaders by integrating viewport multiply into matrix multiply --- misc/wiiu/textured_offset.gsh | Bin 1000 -> 1000 bytes misc/xbox/vs_coloured.vs.cg | 9 +-------- misc/xbox/vs_textured.vs.cg | 9 +-------- src/AudioBackend.c | 7 +++++-- src/Graphics_Xbox.c | 17 ++++++++++++----- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/misc/wiiu/textured_offset.gsh b/misc/wiiu/textured_offset.gsh index 72b9ddcde1c48489546a4f6b8704e448a3dbd179..c9e3d65efabfa89bf9337d72f5bdba6d62b68d60 100644 GIT binary patch delta 22 dcmaFC{(^nOPG&9z1_l9!1O{f6hRKJSRRK<_1_}TG delta 22 ecmaFC{(^nOPG+tK1qK0z1P11o1(Odms{#O6Y6l7c diff --git a/misc/xbox/vs_coloured.vs.cg b/misc/xbox/vs_coloured.vs.cg index b4e848f80..44394436a 100644 --- a/misc/xbox/vs_coloured.vs.cg +++ b/misc/xbox/vs_coloured.vs.cg @@ -10,9 +10,7 @@ struct vOut { vOut main( vIn input, - uniform float4x4 mvp, - uniform float4 vp_scale, - uniform float4 vp_offset + uniform float4x4 mvp ) { vOut result; @@ -22,11 +20,6 @@ vOut main( position = mul(position, mvp); position.xyz = position.xyz / position.w; - position.x = position.x * vp_scale.x + vp_offset.x; - position.y = position.y * vp_scale.y + vp_offset.y; - position.z = position.z * vp_scale.z + vp_offset.z; - //position.w = 1.0 / half_viewport.w; - result.pos = position; result.col = input.color; return result; diff --git a/misc/xbox/vs_textured.vs.cg b/misc/xbox/vs_textured.vs.cg index bbad1efb1..a439d1c52 100644 --- a/misc/xbox/vs_textured.vs.cg +++ b/misc/xbox/vs_textured.vs.cg @@ -12,9 +12,7 @@ struct vOut { vOut main( vIn input, - uniform float4x4 mvp, - uniform float4 vp_scale, - uniform float4 vp_offset + uniform float4x4 mvp ) { vOut result; @@ -24,11 +22,6 @@ vOut main( position = mul(position, mvp); position.xyz = position.xyz / position.w; - position.x = position.x * vp_scale.x + vp_offset.x; - position.y = position.y * vp_scale.y + vp_offset.y; - position.z = position.z * vp_scale.z + vp_offset.z; - //position.w = 1.0 / half_viewport.w; - result.pos = position; result.col = input.color; result.tex = input.tex; diff --git a/src/AudioBackend.c b/src/AudioBackend.c index c35eacaa1..157da4bfe 100644 --- a/src/AudioBackend.c +++ b/src/AudioBackend.c @@ -1206,8 +1206,11 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, struct AudioChunk* chunk) { cc_result Audio_Play(struct AudioContext* ctx) { int format = (ctx->channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT; - ASND_SetVoice(ctx->chanID, format, ctx->sampleRate, 0, ctx->bufs[0].samples, ctx->bufs[0].size, ctx->volume, ctx->volume, (ctx->count > 1) ? MusicCallback : NULL); - if (ctx->count == 1) ctx->bufs[0].available = true; + cc_bool music = ctx->count > 1; + + ASND_SetVoice(ctx->chanID, format, ctx->sampleRate, 0, ctx->bufs[0].samples, ctx->bufs[0].size, + ctx->volume, ctx->volume, music ? MusicCallback : NULL); + if (!music) ctx->bufs[0].available = true; return 0; } diff --git a/src/Graphics_Xbox.c b/src/Graphics_Xbox.c index ce9e5dc0f..024aeaa73 100644 --- a/src/Graphics_Xbox.c +++ b/src/Graphics_Xbox.c @@ -555,11 +555,8 @@ static void UpdateVSConstants(void) { p = pb_push1(p, NV097_SET_TRANSFORM_CONSTANT_LOAD, 96); // upload transformation matrix - pb_push(p++, NV097_SET_TRANSFORM_CONSTANT, 4*4 + 4 + 4); - Mem_Copy(p, &_mvp, 16 * 4); p += 16; - // Upload viewport too - Mem_Copy(p, &vp_scale, 4 * 4); p += 4; - Mem_Copy(p, &vp_offset, 4 * 4); p += 4; + pb_push(p++, NV097_SET_TRANSFORM_CONSTANT, 4*4); + Mem_Copy(p, &_mvp, 16 * 4); p += 16; // Upload constants too //struct Vec4 v = { 1, 1, 1, 1 }; //Mem_Copy(p, &v, 4 * 4); p += 4; @@ -573,6 +570,16 @@ void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { *dst = *matrix; Matrix_Mul(&_mvp, &_view, &_proj); + + struct Matrix vp = Matrix_Identity; + vp.row1.x = vp_scale.x; + vp.row2.y = vp_scale.y; + vp.row3.z = 8388608; + vp.row4.x = vp_offset.x; + vp.row4.y = vp_offset.y; + vp.row4.z = 8388608; + + Matrix_Mul(&_mvp, &_mvp, &vp); UpdateVSConstants(); }