From ef762c828a12a04fb1e3fd5ef6a1a6593fad2eb7 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Tue, 23 Nov 2021 10:18:16 -0800 Subject: [PATCH 1/8] pbkit: Expose ramin context registration. --- lib/pbkit/pbkit.c | 40 ++++++++++++---------------------------- lib/pbkit/pbkit.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index 656abfa0e..5d2ddc8c6 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -42,15 +42,6 @@ #define ADDR_FBMEM 2 #define ADDR_AGPMEM 3 -#define DMA_CLASS_2 2 -#define DMA_CLASS_3 3 -#define DMA_CLASS_3D 0x3D - -#define GR_CLASS_30 0x30 -#define GR_CLASS_39 0x39 -#define GR_CLASS_62 0x62 -#define GR_CLASS_97 0x97 -#define GR_CLASS_9F 0x9F #define GPU_IRQ 3 @@ -69,14 +60,6 @@ #define PB_SETNOISE 0xBAA #define PB_FINISHED 0xFAB -struct s_CtxDma -{ - DWORD ChannelID; - DWORD Inst; //Addr in PRAMIN area, unit=16 bytes blocks, baseaddr=VIDEO_BASE+NV_PRAMIN - DWORD Class; - DWORD isGr; -}; - static unsigned int pb_ColorFmt = NV097_SET_SURFACE_FORMAT_COLOR_LE_A8R8G8B8; static unsigned int pb_DepthFmt = NV097_SET_SURFACE_FORMAT_ZETA_Z24S8; @@ -1344,7 +1327,7 @@ static void pb_prepare_tiles(void) -static void pb_create_dma_ctx( DWORD ChannelID, +void pb_create_dma_ctx( DWORD ChannelID, DWORD Class, DWORD Base, DWORD Limit, @@ -1393,7 +1376,7 @@ static void pb_create_dma_ctx( DWORD ChannelID, -static void pb_bind_channel(struct s_CtxDma *pCtxDmaObject) +void pb_bind_channel(struct s_CtxDma *pCtxDmaObject) { DWORD entry; DWORD *p; @@ -1628,7 +1611,7 @@ static void pb_3D_init(void) -static void pb_create_gr_ctx( int ChannelID, +void pb_create_gr_ctx( int ChannelID, int Class, struct s_CtxDma *pGrObject ) { @@ -3109,6 +3092,7 @@ int pb_init(void) pb_create_dma_ctx(8,DMA_CLASS_3D,(DWORD)pb_DmaBuffer8,0x20,&sDmaObject8); pb_create_dma_ctx(6,DMA_CLASS_2,0,MAXRAM,&sDmaObject6); + //we initialized channel 0 first, that will match graphic context 0 pb_FifoChannelID=0; pb_FifoChannelsMode=NV_PFIFO_MODE_ALL_PIO; @@ -3253,14 +3237,14 @@ int pb_init(void) //These commands assign DMA channels to push buffer subchannels //and associate some specific GPU parts to specific Dma channels p=pb_begin(); - p=pb_push1_to(SUBCH_2,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,14); - p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,16); - p=pb_push1_to(SUBCH_4,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,17); - p=pb_push1_to(SUBCH_3D,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,13); - p=pb_push1_to(SUBCH_2,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT0,7); - p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT5,17); - p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT_UNKNOWN,3); - p=pb_push2_to(SUBCH_4,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT1,3,11); + p=pb_push1_to(SUBCH_2,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,14); // Class 39 + p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,16); // Class 9F + p=pb_push1_to(SUBCH_4,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,17); // Class 62 + p=pb_push1_to(SUBCH_3D,p,NV20_TCL_PRIMITIVE_SET_MAIN_OBJECT,13); // Class 97 + p=pb_push1_to(SUBCH_2,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT0,7); // NV039_SET_CONTEXT_DMA_NOTIFIES + p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT5,17); // NV09F_SET_CONTEXT_SURFACES + p=pb_push1_to(SUBCH_3,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT_UNKNOWN,3); // Set operation to SRCCOPY + p=pb_push2_to(SUBCH_4,p,NV20_TCL_PRIMITIVE_3D_SET_OBJECT1,3,11); // Source ch 3, Dest ch 11 pb_end(p); //calls pb_start() which will trigger the reading and sending to GPU (asynchronous, no waiting) //setup needed for color computations diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index 08446808a..cdf44d3ef 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -51,6 +51,24 @@ extern "C" #define SUBCH_3 3 #define SUBCH_4 4 +//DMA and graphics classes +#define DMA_CLASS_2 0x02 +#define DMA_CLASS_3 0x03 +#define DMA_CLASS_3D 0x3D +#define GR_CLASS_19 0x19 +#define GR_CLASS_30 0x30 +#define GR_CLASS_39 0x39 +#define GR_CLASS_62 0x62 +#define GR_CLASS_97 0x97 +#define GR_CLASS_9F 0x9F + +struct s_CtxDma +{ + DWORD ChannelID; + DWORD Inst; //Addr in PRAMIN area, unit=16 bytes blocks, baseaddr=VIDEO_BASE+NV_PRAMIN + DWORD Class; + DWORD isGr; +}; void pb_show_front_screen(void); //shows scene (allows VBL synced screen swapping) void pb_show_debug_screen(void); //shows debug screen (default openxdk+SDL buffer) @@ -116,6 +134,16 @@ void pb_set_viewport(int dwx,int dwy,int width,int height,float zmin,float zm int pb_busy(void); +void pb_create_dma_ctx(DWORD ChannelID, + DWORD Class, + DWORD Base, + DWORD Limit, + struct s_CtxDma *pDmaObject ); +void pb_create_gr_ctx( int ChannelID, + int Class, + struct s_CtxDma *pGrObject ); +void pb_bind_channel(struct s_CtxDma *pCtxDmaObject); + #ifdef __cplusplus } #endif From 741fa1323b64b12ed99ecfe8a12023b6a7e74bd1 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Wed, 1 Dec 2021 13:54:14 -0800 Subject: [PATCH 2/8] pbkit: Expose depth buffer. --- lib/pbkit/pbkit.c | 13 +++++++++++++ lib/pbkit/pbkit.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index 5d2ddc8c6..cf45c9d4e 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -3712,3 +3712,16 @@ static NTAPI VOID pb_shutdown_notification_routine (PHAL_SHUTDOWN_REGISTRATION S { pb_kill(); } + +uint8_t* pb_depth_stencil_buffer() +{ + return (uint8_t*)pb_DepthStencilAddr; +} + +DWORD pb_depth_stencil_pitch() { + return pb_DepthStencilPitch; +} + +DWORD pb_depth_stencil_size() { + return pb_DSSize; +} diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index cdf44d3ef..41ef02f2d 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -144,6 +144,10 @@ void pb_create_gr_ctx( int ChannelID, struct s_CtxDma *pGrObject ); void pb_bind_channel(struct s_CtxDma *pCtxDmaObject); +uint8_t *pb_depth_stencil_buffer(); +DWORD pb_depth_stencil_pitch(); +DWORD pb_depth_stencil_size(); + #ifdef __cplusplus } #endif From ff765f76cca57944819e33dbc8af534bc68b9294 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Wed, 1 Dec 2021 17:35:39 -0800 Subject: [PATCH 3/8] Expose context registration. --- lib/pbkit/pbkit.c | 39 +++++++++++++++++++++++++-------------- lib/pbkit/pbkit.h | 8 ++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index cf45c9d4e..ad430006f 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -1607,9 +1607,32 @@ static void pb_3D_init(void) #endif } +DWORD pb_reserve_instance(DWORD size) { + DWORD ret = pb_FreeInst; + pb_FreeInst += (size>>4); + return ret; +} +void pb_create_gr_instance(int ChannelID, + int Class, + DWORD instance, + DWORD flags, + DWORD flags3D, + struct s_CtxDma *pGrObject) +{ + DWORD offset = instance << 4; + VIDEOREG(NV_PRAMIN + offset + 0x00) = flags; + VIDEOREG(NV_PRAMIN + offset + 0x04) = flags3D; + VIDEOREG(NV_PRAMIN + offset + 0x08) = 0; + VIDEOREG(NV_PRAMIN + offset + 0x0C) = 0; + memset(pGrObject,0,sizeof(struct s_CtxDma)); + pGrObject->ChannelID = ChannelID; + pGrObject->Class = Class; + pGrObject->isGr = 1; + pGrObject->Inst = instance; +} void pb_create_gr_ctx( int ChannelID, int Class, @@ -1643,7 +1666,7 @@ void pb_create_gr_ctx( int ChannelID, } } - Inst=pb_FreeInst; pb_FreeInst+=(size>>4); + Inst = pb_reserve_instance(size); if (flags3D) { @@ -1651,7 +1674,6 @@ void pb_create_gr_ctx( int ChannelID, pb_3D_init(); } - flags=Class&0x000000FF; flags3D=0x00000000; @@ -1659,18 +1681,7 @@ void pb_create_gr_ctx( int ChannelID, if (Class==GR_CLASS_97) flags3D=0x00000A00; - VIDEOREG(NV_PRAMIN+(Inst<<4)+0x00)=flags; - VIDEOREG(NV_PRAMIN+(Inst<<4)+0x04)=flags3D; - VIDEOREG(NV_PRAMIN+(Inst<<4)+0x08)=0; - VIDEOREG(NV_PRAMIN+(Inst<<4)+0x0C)=0; - - - memset(pGrObject,0,sizeof(struct s_CtxDma)); - - pGrObject->ChannelID=ChannelID; - pGrObject->Class=Class; - pGrObject->isGr=1; - pGrObject->Inst=Inst; + pb_create_gr_instance(ChannelID, Class, Inst, flags, flags3D, pGrObject); } diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index 41ef02f2d..f6f48ae2d 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -50,6 +50,7 @@ extern "C" #define SUBCH_2 2 #define SUBCH_3 3 #define SUBCH_4 4 +#define NEXT_SUBCH 5 //DMA and graphics classes #define DMA_CLASS_2 0x02 @@ -148,6 +149,13 @@ uint8_t *pb_depth_stencil_buffer(); DWORD pb_depth_stencil_pitch(); DWORD pb_depth_stencil_size(); +DWORD pb_reserve_instance(DWORD size); +void pb_create_gr_instance(int ChannelID, + int Class, + DWORD instance, + DWORD flags, + DWORD flags3D, + struct s_CtxDma *pGrObject); #ifdef __cplusplus } #endif From edaffee007520da1c2f683e7a656b35e9c52628e Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Mon, 20 Dec 2021 08:26:46 -0800 Subject: [PATCH 4/8] Exposes pb_print_char to allow use of a full featured printf lib. --- lib/pbkit/pbkit.c | 2 +- lib/pbkit/pbkit.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index ad430006f..e03220855 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -370,7 +370,7 @@ static void pb_scrollup(void) memset(&pb_text_screen[ROWS-1][0],0,COLS); } -static void pb_print_char(char c) +void pb_print_char(char c) { if (c=='\n') { diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index f6f48ae2d..fb77a3fdf 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -156,6 +156,10 @@ void pb_create_gr_instance(int ChannelID, DWORD flags, DWORD flags3D, struct s_CtxDma *pGrObject); + +// Exposed so pb_print can be overridden using a version of vsprintf that +// supports floats. +void pb_print_char(char c); #ifdef __cplusplus } #endif From 02d7524e19899df4bd7feda8ed4c184bf138387f Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Tue, 3 May 2022 15:56:55 -0700 Subject: [PATCH 5/8] Enables flip stall in pbkit. --- lib/pbkit/pbkit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index e03220855..4b0a0659e 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -2468,7 +2468,7 @@ int pb_finished(void) p=pb_push1(p,NV20_TCL_PRIMITIVE_3D_WAIT_MAKESPACE,0); //wait/makespace (obtains null status) p=pb_push1(p,NV20_TCL_PRIMITIVE_3D_PARAMETER_A,pb_back_index); //set param=back buffer index to show up p=pb_push1(p,NV20_TCL_PRIMITIVE_3D_FIRE_INTERRUPT,PB_FINISHED); //subprogID PB_FINISHED: gets frame ready to show up soon -// p=pb_push1(p,NV20_TCL_PRIMITIVE_3D_STALL_PIPELINE,0); //stall gpu pipeline (not sure it's needed in triple buffering technic) + p=pb_push1(p,NV20_TCL_PRIMITIVE_3D_STALL_PIPELINE,0); //stall gpu pipeline (not sure it's needed in triple buffering technic) pb_end(p); //insert in push buffer the commands to trigger selection of next back buffer From 83073d8abc3ff1ec5e78580692c459eb071d2159 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Wed, 11 May 2022 15:44:55 -0700 Subject: [PATCH 6/8] Adds sleep in pbkit exception handler to keep XBDM responsive. --- lib/pbkit/pbkit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index 4b0a0659e..1d5136347 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "pbkit.h" #include "outer.h" @@ -673,7 +674,9 @@ static DWORD pb_gr_handler(void) //calling XReboot() from here doesn't work well. - while(1) {}; + while(1) { + Sleep(2000); + }; } } } From c05399a9a54f2abf4457f693d82a9f74391cb46d Mon Sep 17 00:00:00 2001 From: Antonio Abbatangelo Date: Sun, 26 Feb 2023 21:00:13 -0500 Subject: [PATCH 7/8] pbkit: Support setting FB size multiplier --- lib/pbkit/pbkit.c | 13 +++++++++---- lib/pbkit/pbkit.h | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index 1d5136347..fe6ce388a 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -149,6 +149,7 @@ static DWORD pb_FBVFlag; static DWORD pb_GPUFrameBuffersFormat;//encoded format for GPU static DWORD pb_EXAddr[8]; //extra buffers addresses static DWORD pb_ExtraBuffersCount=0; +static DWORD pb_FBSizeMultiplier = 1; static DWORD pb_DepthStencilAddr; static DWORD pb_DepthStencilPitch; @@ -2630,6 +2631,11 @@ void pb_set_color_format(unsigned int fmt, bool swizzled) { assert(swizzled == false); } +void pb_set_fb_size_multiplier(unsigned int multiplier) { + assert(multiplier > 0); + pb_FBSizeMultiplier = multiplier; +} + int pb_init(void) { DWORD old; @@ -2739,7 +2745,6 @@ int pb_init(void) pb_FrameBuffersAddr=0; - pb_DmaBuffer8=MmAllocateContiguousMemoryEx(32,0,MAXRAM,0,4); pb_DmaBuffer2=MmAllocateContiguousMemoryEx(32,0,MAXRAM,0,4); pb_DmaBuffer7=MmAllocateContiguousMemoryEx(32,0,MAXRAM,0,4); @@ -3391,7 +3396,7 @@ int pb_init(void) } } - Size=Pitch*VSize; + Size=Pitch*VSize*pb_FBSizeMultiplier; //verify 64 bytes alignment for size of a frame buffer if (Size&(64-1)) debugPrint("pb_init: FBSize is not well aligned.\n"); @@ -3464,7 +3469,7 @@ int pb_init(void) } } - Size=Pitch*VSize; + Size=Pitch*VSize*pb_FBSizeMultiplier; //verify 64 bytes alignment for size of a frame buffer if (Size&(64-1)) debugPrint("pb_init: DSSize is not well aligned.\n"); @@ -3518,7 +3523,7 @@ int pb_init(void) } } - Size=Pitch*VSize; + Size=Pitch*VSize*pb_FBSizeMultiplier; //verify 64 bytes alignment for size of a frame buffer if (Size&(64-1)) debugPrint("pb_init: EXSize is not well aligned.\n"); diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index fb77a3fdf..54ae3fce0 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -132,6 +132,8 @@ void pb_fill(int x,int y,int w,int h, DWORD color); //rectangle fill void pb_set_viewport(int dwx,int dwy,int width,int height,float zmin,float zmax); +void pb_set_fb_size_multiplier(unsigned int multiplier); + int pb_busy(void); From ec990833d36e42f9714c3863d600eb05f8f2dd57 Mon Sep 17 00:00:00 2001 From: Antonio Abbatangelo Date: Wed, 1 Mar 2023 20:44:25 -0500 Subject: [PATCH 8/8] Fix brace formatting --- lib/pbkit/pbkit.c | 19 ++++++++++++------- lib/pbkit/pbkit.h | 8 +++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/pbkit/pbkit.c b/lib/pbkit/pbkit.c index fe6ce388a..910f67dd3 100644 --- a/lib/pbkit/pbkit.c +++ b/lib/pbkit/pbkit.c @@ -1331,11 +1331,11 @@ static void pb_prepare_tiles(void) -void pb_create_dma_ctx( DWORD ChannelID, +void pb_create_dma_ctx(DWORD ChannelID, DWORD Class, DWORD Base, DWORD Limit, - struct s_CtxDma *pDmaObject ) + struct s_CtxDma *pDmaObject) { DWORD Addr; DWORD AddrSpace; @@ -1611,7 +1611,8 @@ static void pb_3D_init(void) #endif } -DWORD pb_reserve_instance(DWORD size) { +DWORD pb_reserve_instance(DWORD size) +{ DWORD ret = pb_FreeInst; pb_FreeInst += (size>>4); return ret; @@ -2626,12 +2627,14 @@ void pb_kill(void) } -void pb_set_color_format(unsigned int fmt, bool swizzled) { +void pb_set_color_format(unsigned int fmt, bool swizzled) +{ pb_ColorFmt = fmt; assert(swizzled == false); } -void pb_set_fb_size_multiplier(unsigned int multiplier) { +void pb_set_fb_size_multiplier(unsigned int multiplier) +{ assert(multiplier > 0); pb_FBSizeMultiplier = multiplier; } @@ -3737,10 +3740,12 @@ uint8_t* pb_depth_stencil_buffer() return (uint8_t*)pb_DepthStencilAddr; } -DWORD pb_depth_stencil_pitch() { +DWORD pb_depth_stencil_pitch() +{ return pb_DepthStencilPitch; } -DWORD pb_depth_stencil_size() { +DWORD pb_depth_stencil_size() +{ return pb_DSSize; } diff --git a/lib/pbkit/pbkit.h b/lib/pbkit/pbkit.h index 54ae3fce0..6f00d7212 100644 --- a/lib/pbkit/pbkit.h +++ b/lib/pbkit/pbkit.h @@ -141,10 +141,10 @@ void pb_create_dma_ctx(DWORD ChannelID, DWORD Class, DWORD Base, DWORD Limit, - struct s_CtxDma *pDmaObject ); -void pb_create_gr_ctx( int ChannelID, + struct s_CtxDma *pDmaObject); +void pb_create_gr_ctx(int ChannelID, int Class, - struct s_CtxDma *pGrObject ); + struct s_CtxDma *pGrObject); void pb_bind_channel(struct s_CtxDma *pCtxDmaObject); uint8_t *pb_depth_stencil_buffer(); @@ -159,8 +159,6 @@ void pb_create_gr_instance(int ChannelID, DWORD flags3D, struct s_CtxDma *pGrObject); -// Exposed so pb_print can be overridden using a version of vsprintf that -// supports floats. void pb_print_char(char c); #ifdef __cplusplus }