Compare commits

...

9 Commits

Author SHA1 Message Date
Josh Pearson
63bfa4c2c6 Merge branch 'ph3nom/fsaa' into ph3nom/fsaa-mr 2025-03-04 11:25:08 -07:00
Josh Pearson
dac22aedf0 FSAA - Explicit typecast for sim-clang build
error: type 'float' cannot be narrowed to 'rw::int32'
2025-03-04 11:09:45 -07:00
Falco Girgis
1fcf0a2338 Fixed v1 and v3 blurs with FSAA enabled.
- Both blurs had hard-coded screen resolution parameters
- FSAA horizontally stretches by 2x
- Made both algorithms now dynamic based on screen resolution
- Verified both work with and without FSAA now
2025-02-28 16:43:26 -06:00
Stefanos Kornilios Mitsis Poiitidis
3a4aa88259 Merge branch 'skmp/oix-emulator-workarounds' into 'main'
Submit via OCR path if emulator is detected with no support for OIX

See merge request skmp/dca3-game!26
2025-02-25 17:07:58 +00:00
Stefanos Kornilios Mitsis Poiitidis
97a4e0d3a4 Merge branch 'skmp/fix-sniper' into 'main'
Fix sniper bug / bulletInfoInUse counting

See merge request skmp/dca3-game!25
2025-02-25 17:01:28 +00:00
Stefanos Kornilios Mitsis Poiitidis
7748c85d6b Submit via OCR path if emulator is detected with no support for OIX 2025-02-25 18:55:51 +02:00
Stefanos Kornilios Mitsis Poiitidis
e5308dea97 Fix sniper bug / bulletInfoInUse counting 2025-02-25 18:54:32 +02:00
Josh Pearson
714f34464e Fix moon and corona aspect ratio with FSAA 2025-01-17 16:41:25 -07:00
Josh Pearson
214d913c4a FSAA Implemented as a Video Mode of 1280x480
Video mode must be set in main menu before starting game.  Changing this setting restarts the video driver which resets the PVR.  Settings persist after shutting down game via INI saves.
2025-01-09 16:40:58 -07:00
7 changed files with 398 additions and 196 deletions

View File

@@ -187,8 +187,8 @@ __always_inline uint32 ldb(uint32 p, uint32 s, uint32 w)
#define SCREEN_HEIGHT ((float)448)
#endif
#else
#define SCREEN_WIDTH ((float)640)
#define SCREEN_HEIGHT ((float)480)
extern float SCREEN_WIDTH;
extern float SCREEN_HEIGHT;
#endif
#define SCREEN_HEIGHT_PAL ((float)512)

View File

@@ -311,7 +311,7 @@ enum Config {
#define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch)
// #define USE_TXD_CDIMAGE // generate and load textures from txd.img
// #define PS2_ALPHA_TEST // emulate ps2 alpha test
#define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number
//#define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number
// #define DISABLE_LOADING_SCREEN // disable the loading screen which vastly improves the loading time
#ifdef DISABLE_LOADING_SCREEN
// enable the PC splash
@@ -327,7 +327,7 @@ enum Config {
//#define NEW_RENDERER // leeds-like world rendering, needs librw
#endif
#define FIX_SPRITES // fix sprites aspect ratio(moon, coronas, particle etc)
// #define FIX_SPRITES // fix sprites aspect ratio(moon, coronas, particle etc) // JP - Disabled this as it produces incorrect aspect ratio with custom screen resolutions and is not needed otherwise
#ifndef EXTENDED_COLOURFILTER
#undef SCREEN_DROPLETS // we need the backbuffer for this effect

View File

@@ -41,7 +41,11 @@ CDraw::FindAspectRatio(void)
#else
switch (FrontEndMenuManager.m_PrefsUseWideScreen) {
case AR_AUTO:
#ifdef DC_SH4
return 4.0f / 3.0f;
#else
return SCREEN_WIDTH / SCREEN_HEIGHT;
#endif
default:
case AR_4_3:
return 4.0f / 3.0f;

View File

@@ -134,7 +134,7 @@ CMBlur::MotionBlurOpen(RwCamera *cam)
return TRUE;
#else
RwRect rect = { 0, 0, 640, 480 };
RwRect rect = { 0, 0, (rw::int32)SCREEN_WIDTH, (rw::int32)SCREEN_HEIGHT };
CreateImmediateModeData(cam, &rect);
return TRUE;
#endif

View File

@@ -877,10 +877,6 @@ psSelectDevice()
/* Get the default selection */
GcurSel = RwEngineGetCurrentSubSystem();
#ifdef IMPROVED_VIDEOMODE
if(FrontEndMenuManager.m_nPrefsSubsystem < GnumSubSystems)
GcurSel = FrontEndMenuManager.m_nPrefsSubsystem;
#endif
}
/* Set the driver to use the correct sub system */
@@ -889,11 +885,6 @@ psSelectDevice()
return FALSE;
}
#ifdef IMPROVED_VIDEOMODE
FrontEndMenuManager.m_nPrefsSubsystem = GcurSel;
#endif
#ifndef IMPROVED_VIDEOMODE
if ( !useDefault )
{
if ( _psGetVideoModeList()[FrontEndMenuManager.m_nDisplayVideoMode] && FrontEndMenuManager.m_nDisplayVideoMode )
@@ -903,97 +894,11 @@ psSelectDevice()
}
else
{
#ifdef DEFAULT_NATIVE_RESOLUTION
// get the native video mode
HDC hDevice = GetDC(NULL);
int w = GetDeviceCaps(hDevice, HORZRES);
int h = GetDeviceCaps(hDevice, VERTRES);
int d = GetDeviceCaps(hDevice, BITSPIXEL);
#else
const int w = 640;
const int h = 480;
const int d = 16;
#endif
while ( !modeFound && GcurSelVM < RwEngineGetNumVideoModes() )
{
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
if ( defaultFullscreenRes && vm.width != w
|| vm.height != h
|| vm.depth != d
|| !(vm.flags & rwVIDEOMODEEXCLUSIVE) )
++GcurSelVM;
else
modeFound = TRUE;
}
if ( !modeFound )
{
#ifdef DEFAULT_NATIVE_RESOLUTION
GcurSelVM = 1;
#else
printf("WARNING: Cannot find 640x480 video mode, selecting device cancelled\n");
return FALSE;
#endif
}
GcurSelVM = 0;
}
}
#else
if ( !useDefault )
{
if(FrontEndMenuManager.m_nPrefsWidth == 0 ||
FrontEndMenuManager.m_nPrefsHeight == 0 ||
FrontEndMenuManager.m_nPrefsDepth == 0){
// Defaults if nothing specified
//const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
FrontEndMenuManager.m_nPrefsWidth = 640; //mode->width;
FrontEndMenuManager.m_nPrefsHeight = 480; //mode->height;
FrontEndMenuManager.m_nPrefsDepth = 16;
FrontEndMenuManager.m_nPrefsWindowed = 0;
}
// Find the videomode that best fits what we got from the settings file
RwInt32 bestFsMode = -1;
RwInt32 bestWidth = -1;
RwInt32 bestHeight = -1;
RwInt32 bestDepth = -1;
for(GcurSelVM = 0; GcurSelVM < RwEngineGetNumVideoModes(); GcurSelVM++){
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
bestWndMode = GcurSelVM;
bestWidth = vm.width;
bestHeight = vm.height;
bestDepth = vm.depth;
bestFsMode = GcurSelVM;
break;
}
if(bestFsMode < 0){
printf("WARNING: Cannot find desired video mode, selecting device cancelled\n");
return FALSE;
}
GcurSelVM = bestFsMode;
FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM;
FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode;
FrontEndMenuManager.m_nSelectedScreenMode = FrontEndMenuManager.m_nPrefsWindowed;
}
#endif
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
#ifdef IMPROVED_VIDEOMODE
if (FrontEndMenuManager.m_nPrefsWindowed)
GcurSelVM = bestWndMode;
// Now GcurSelVM is 0 but vm has sizes(and fullscreen flag) of the video mode we want, that's why we changed the rwVIDEOMODEEXCLUSIVE conditions below
FrontEndMenuManager.m_nPrefsWidth = vm.width;
FrontEndMenuManager.m_nPrefsHeight = vm.height;
FrontEndMenuManager.m_nPrefsDepth = vm.depth;
#endif
#ifndef PS2_MENU
FrontEndMenuManager.m_nCurrOption = 0;
#endif
/* Set up the video mode and set the apps window
* dimensions to match */
@@ -1016,25 +921,6 @@ psSelectDevice()
}
}
*/
#ifndef IMPROVED_VIDEOMODE
if (vm.flags & rwVIDEOMODEEXCLUSIVE)
{
RsGlobal.maximumWidth = vm.width;
RsGlobal.maximumHeight = vm.height;
RsGlobal.width = vm.width;
RsGlobal.height = vm.height;
PSGLOBAL(fullScreen) = TRUE;
}
#else
RsGlobal.maximumWidth = FrontEndMenuManager.m_nPrefsWidth;
RsGlobal.maximumHeight = FrontEndMenuManager.m_nPrefsHeight;
RsGlobal.width = FrontEndMenuManager.m_nPrefsWidth;
RsGlobal.height = FrontEndMenuManager.m_nPrefsHeight;
PSGLOBAL(fullScreen) = !FrontEndMenuManager.m_nPrefsWindowed;
#endif
#ifdef MULTISAMPLING
RwD3D8EngineSetMultiSamplingLevels(1 << FrontEndMenuManager.m_nPrefsMSAALevel);
#endif

View File

@@ -126,6 +126,28 @@ void CBulletInfo::Update(void)
}
pPed->InflictDamage(pBullet->m_pSource, pBullet->m_eWeaponType, pBullet->m_nDamage, (ePedPieceTypes)point.pieceB, pPed->GetLocalDirection(pPed->GetPosition() - point.point));
CEventList::RegisterEvent(pPed->m_nPedType == PEDTYPE_COP ? EVENT_SHOOT_COP : EVENT_SHOOT_PED, EVENT_ENTITY_PED, pPed, (CPed*)pBullet->m_pSource, 1000);
if (CGame::nastyGame) {
CVector vecParticleDirection = (point.point - pPed->GetPosition()) * 0.01f;
vecParticleDirection.z = 0.01f;
if (pPed->GetIsOnScreen()) {
for (int j = 0; j < NUM_PED_BLOOD_PARTICLES; j++)
CParticle::AddParticle(PARTICLE_BLOOD_SMALL, point.point + BLOOD_PARTICLE_OFFSET, vecParticleDirection);
}
if (pPed->GetPedState() == PED_DEAD) {
CAnimBlendAssociation* pAnim;
if (RpAnimBlendClumpGetFirstAssociation(pPed->GetClump(), ASSOC_FRONTAL))
pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR_FRONT, 8.0f);
else
pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR, 8.0f);
if (pAnim) {
pAnim->SetCurrentTime(0.0f);
pAnim->flags |= ASSOC_RUNNING;
pAnim->flags &= ~ASSOC_FADEOUTWHENDONE;
}
}
}
pBullet->m_bInUse = false;
#ifdef SQUEEZE_PERFORMANCE
bulletInfoInUse--;
@@ -136,31 +158,6 @@ void CBulletInfo::Update(void)
bAddSound = false;
}
}
if (CGame::nastyGame) {
CVector vecParticleDirection = (point.point - pPed->GetPosition()) * 0.01f;
vecParticleDirection.z = 0.01f;
if (pPed->GetIsOnScreen()) {
for (int j = 0; j < NUM_PED_BLOOD_PARTICLES; j++)
CParticle::AddParticle(PARTICLE_BLOOD_SMALL, point.point + BLOOD_PARTICLE_OFFSET, vecParticleDirection);
}
if (pPed->GetPedState() == PED_DEAD) {
CAnimBlendAssociation* pAnim;
if (RpAnimBlendClumpGetFirstAssociation(pPed->GetClump(), ASSOC_FRONTAL))
pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR_FRONT, 8.0f);
else
pAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, ANIM_STD_HIT_FLOOR, 8.0f);
if (pAnim) {
pAnim->SetCurrentTime(0.0f);
pAnim->flags |= ASSOC_RUNNING;
pAnim->flags &= ~ASSOC_FADEOUTWHENDONE;
}
}
pBullet->m_bInUse = false;
#ifdef SQUEEZE_PERFORMANCE
bulletInfoInUse--;
#endif
vecNewPos = point.point;
}
}
else if (pHitEntity->IsVehicle()) {
CVehicle* pVehicle = (CVehicle*)pHitEntity;

View File

@@ -29,6 +29,7 @@ extern const char* currentFile;
#include "rwdc.h"
#include "vq.h"
#include "tex-util.h"
#include "common.h"
#include <vector>
#include <set>
@@ -56,6 +57,12 @@ bool doEnvironmentMaps = true;
#define fclamp0_1(n) ((n) > 1.0f ? 1.0f : n < 0.0f ? 0.0f : n)
#define fclamp1(n) ((n) > 1.0f ? 1.0f : n)
const unsigned short VIDEO_MODES = 2;
unsigned short VIDEO_MODE = 0;
rw::VideoMode videoModes[VIDEO_MODES];
float SCREEN_WIDTH = 640;
float SCREEN_HEIGHT = 480;
struct alignas(32) pvr_vertex16_t {
uint32_t flags; /**< \brief TA command (vertex flags) */
float x; /**< \brief X coordinate */
@@ -176,8 +183,6 @@ static pvr_dr_state_t drState;
#if !defined(DC_TEXCONV) && !defined(DC_SIM)
#include <kos.h>
#define VIDEO_MODE_WIDTH vid_mode->width
#define VIDEO_MODE_HEIGHT vid_mode->height
#define mat_trans_nodiv_nomod(x, y, z, x2, y2, z2, w2) do { \
register float __x __asm__("fr12") = (x); \
@@ -288,8 +293,6 @@ void rw_mat_load_4x4(rw::Matrix* mtx) {
}
#include <dc/matrix.h>
#define VIDEO_MODE_WIDTH 640
#define VIDEO_MODE_HEIGHT 480
#define frsqrt(a) (1.0f/sqrt(a))
#define dcache_pref_block(a) __builtin_prefetch(a)
@@ -418,6 +421,66 @@ void leave_oix_() {
#endif
}
void enter_ocr_() {
#if defined(DC_SH4)
auto mask = irq_disable();
dcache_purge_all();
volatile uint32_t * CCN_CCR = (uint32_t *)0xFF00001C;
*CCN_CCR |= (1 << 5); // enable OCR (ORA)
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
irq_restore(mask);
#endif
}
void leave_ocr_() {
#if defined(DC_SH4)
auto mask = irq_disable();
dcache_inval_range(0x92000000, 8192);
dcache_purge_all();
volatile uint32_t * CCN_CCR = (uint32_t *)0xFF00001C;
*CCN_CCR &= ~( 1 << 5); // disable OCR (ORA)
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
__asm__ __volatile__ ("nop");
irq_restore(mask);
#endif
}
#if defined(DC_SH4)
#define FLUSH_TA_DATA(src) do { __asm__ __volatile__("ocbwb @%0" : : "r" (src) : "memory"); } while(0)
#else
@@ -485,7 +548,7 @@ void DCE_MatrixViewport(float x, float y, float width, float height) {
DCE_MAT_SCREENVIEW[1][1] = height * 0.5f;
DCE_MAT_SCREENVIEW[2][2] = 1;
DCE_MAT_SCREENVIEW[3][0] = -DCE_MAT_SCREENVIEW[0][0] + x;
DCE_MAT_SCREENVIEW[3][1] = VIDEO_MODE_HEIGHT - (DCE_MAT_SCREENVIEW[1][1] + y);
DCE_MAT_SCREENVIEW[3][1] = height - (DCE_MAT_SCREENVIEW[1][1] + y);
}
void DCE_InitMatrices() {
@@ -494,7 +557,7 @@ void DCE_InitMatrices() {
mat_store(&DCE_MAT_SCREENVIEW);
DCE_MatrixViewport(0, 0, VIDEO_MODE_WIDTH, VIDEO_MODE_HEIGHT);
DCE_MatrixViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
}
@@ -744,8 +807,9 @@ std::vector<std::function<void()>> blendCallbacks;
std::vector<std::function<void()>> ptCallbacks;
void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
uint32_t col = (a << 24) | (r << 16) | (g << 8) | b;
int strip_width = SCREEN_WIDTH / 320;
int strip_mult = SCREEN_WIDTH / 640;
blendCallbacks.emplace_back([=]() {
pvr_poly_cxt_t cxt;
@@ -761,8 +825,6 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
auto addr2 = (pvr_ptr_t)&emu_vram[addr64b + 640 * 2];
#endif
PVR_SET(PVR_TEXTURE_MODULO, 640/32);
auto doquad = [=](float x, float y, float w, float h, float tx, float ty, float tw, float th) {
@@ -787,23 +849,23 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_dr_commit(vtx);
vtx = reinterpret_cast<pvr_vertex_t *>(pvr_dr_target(drState));
vtx->flags = PVR_CMD_VERTEX;
//vtx->flags = PVR_CMD_VERTEX;
vtx->x = x;
vtx->y = y+h;
vtx->z = 1000000.0f;
//vtx->z = 1000000.0f;
vtx->u = tx/1024.f;
vtx->v = (ty+th)/512.0f;
vtx->argb = col;
//vtx->argb = col;
pvr_dr_commit(vtx);
vtx = reinterpret_cast<pvr_vertex_t *>(pvr_dr_target(drState));
vtx->flags = PVR_CMD_VERTEX_EOL;
vtx->x = x+w;
vtx->y = y+h;
vtx->z = 1000000.0f;
//vtx->z = 1000000.0f;
vtx->u = (tx+tw)/1024.f;
vtx->v = (ty+th)/512.0f;
vtx->argb = col;
//vtx->argb = col;
pvr_dr_commit(vtx);
};
{
@@ -826,7 +888,7 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_dr_commit(hdr);
}
for (int x = 0; x < 320; x+=2) {
doquad(x, 0, 2, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480);
doquad(x*strip_mult, 0, strip_width, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480);
}
{
pvr_poly_cxt_txr(&cxt,
@@ -848,7 +910,7 @@ void dcMotionBlur_v1(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_dr_commit(hdr);
}
for (int x = 0; x < 320; x+=2) {
doquad(320+x, 0, 2, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480);
doquad(SCREEN_WIDTH/2 + x*strip_mult, 0, strip_width, 480, x*2 + (is_bank1 ? 2 : 0), 0, 2, 480);
}
});
}
@@ -891,23 +953,23 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_dr_commit(vtx);
vtx = reinterpret_cast<pvr_vertex_t *>(pvr_dr_target(drState));
vtx->flags = PVR_CMD_VERTEX;
//vtx->flags = PVR_CMD_VERTEX;
vtx->x = x;
vtx->y = y+h;
vtx->z = z;
//vtx->z = z;
vtx->u = umin;
vtx->v = vmax;
vtx->argb = col;
//vtx->argb = col;
pvr_dr_commit(vtx);
vtx = reinterpret_cast<pvr_vertex_t *>(pvr_dr_target(drState));
vtx->flags = PVR_CMD_VERTEX_EOL;
vtx->x = x+w;
vtx->y = y+h;
vtx->z = z;
//vtx->z = z;
vtx->u = umax;
vtx->v = vmax;
vtx->argb = col;
//vtx->argb = col;
pvr_dr_commit(vtx);
};
@@ -926,7 +988,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 1e6f, 640.0f, 480.0f,
doquad(0.0f, 0.0f, 1e6f, SCREEN_WIDTH, 480.0f,
0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, mask_col);
pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY,
@@ -945,10 +1007,10 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 2e6f, 320.0f, 480.0f,
doquad(0.0f, 0.0f, 2e6f, SCREEN_WIDTH / 2.0f, 480.0f,
0.0f, 640.0f / 1024.0f,
0.0f, 960.0f / 1024.0f, col);
doquad(320.0f, 0.0f, 2e6f, 320.0f, 480.0f,
doquad(SCREEN_WIDTH / 2.0f, 0.0f, 2e6f, SCREEN_WIDTH / 2.0f, 480.0f,
0.0f, 640.0f / 1024.0f,
1.0f / 1024.0f, 961.0f / 1024.0f, col);
@@ -959,10 +1021,10 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 3e6f, 320.0f, 480.0f,
doquad(0.0f, 0.0f, 3e6f, SCREEN_WIDTH / 2.0f, 480.0f,
-1.0f / 1024.0f, 639.0f / 1024.0f,
0.0f, 960.0f / 1024.0f, col);
doquad(320.0f, 0.0f, 3e6f, 320.0f, 480.0f,
doquad(SCREEN_WIDTH / 2.0f, 0.0f, 3e6f, SCREEN_WIDTH / 2.0f, 480.0f,
-1.0f / 1024.0f, 639.0f / 1024.0f,
1.0f / 1024.0f, 961.0f / 1024.0f, col);
@@ -978,7 +1040,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f,
doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f,
0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff);
cxt.blend.src = PVR_BLEND_ONE;
@@ -988,7 +1050,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f,
doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f,
0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0x000f0f0f);
cxt.blend.src = PVR_BLEND_INVDESTCOLOR;
@@ -998,7 +1060,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f,
doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f,
0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff);
cxt.blend.dst_enable = PVR_BLEND_DISABLE;
@@ -1010,7 +1072,7 @@ void dcMotionBlur_v3(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
pvr_poly_compile(hdr, &cxt);
pvr_dr_commit(hdr);
doquad(0.0f, 0.0f, 4e6f, 640.0f, 480.0f,
doquad(0.0f, 0.0f, 4e6f, SCREEN_WIDTH, 480.0f,
0.0f, 640.0f / 8.0f, 0.0f, 480.0f / 8.0f, 0xffffffff);
});
}
@@ -2362,6 +2424,36 @@ __attribute__ ((noinline)) void submitMeshlet(uint8_t* OCR, const int8_t* indexD
} while(--indexCount);
}
template<bool textured>
__attribute__ ((noinline)) void submitMeshletFallback(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) {
struct SQBUF {
union {
uint32_t flags;
uint64_t data[4];
uint8_t data8[32];
};
};
SQBUF* sq = (SQBUF*)pvr_dr_target(drState);
static_assert(sizeof(SQBUF) == 32);
do {
auto idx = *indexData++;
auto flags = idx & 0x80 ? PVR_CMD_VERTEX_EOL : PVR_CMD_VERTEX;
auto lookup_idx = idx & 0x7F;
auto src = (SQBUF*)(OCR + lookup_idx * 64);
src[0].flags = flags;
*sq = src[0];
pvr_dr_commit(sq);
if (textured) {
*sq = src[1];
pvr_dr_commit(sq);
}
} while(--indexCount);
}
#if defined(DC_SH4)
template<>
@@ -2441,7 +2533,7 @@ __attribute__ ((noinline)) void submitMeshlet<true>(uint8_t* OCR, const int8_t*
// 8 kb in total
#if defined(DC_SH4)
uint8_t* OCR_SPACE = (uint8_t*)0x92000000;
uint8_t* OCR_SPACE;
#else
uint8_t OCR_SPACE[32 * 256] __attribute__((aligned(32)));
#endif
@@ -2672,6 +2764,159 @@ __attribute__ ((noinline)) void clipAndsubmitMeshlet(uint8_t* vertexData, const
}
};
} while(indexCount != 0);
#undef FILLVERT
#undef SUBMIT_VTX
#undef SUBMIT_INTERPOLATE
}
template<bool textured>
__attribute__ ((noinline)) void clipAndsubmitMeshletFallback(uint8_t* vertexData, const int8_t* indexData, uint32_t indexCount) {
struct SQBUF {
union {
uint32_t flags;
uint64_t data[4];
uint8_t data8[32];
};
};
static_assert(sizeof(SQBUF) == 32);
SQBUF* sq = (SQBUF*)pvr_dr_target(drState);
constexpr int8_t VERTEX = 0;
constexpr int8_t VERTEX_EOL = 0x80;
#define FILLVERT(n) \
do { \
auto idx = *indexData++; \
auto local_idx = idx & 0x7f; \
eol_now = idx & 0x80; \
auto local_ptr = (vertexData + local_idx * 64); \
vpp[n] = local_ptr; \
auto v = (const pvr_vertex64_t*)local_ptr; \
vismask >>= 1; \
if((textured?v->tex_z:v->o_b) >= -v->o_g) vismask |= 0b100; \
indexCount--; \
currentCount++; \
} while(0)
#define SUBMIT_VTX(vid, eolf) \
do { \
auto src = (SQBUF*) vpp[vid]; \
src[0].flags = eolf ? PVR_CMD_VERTEX_EOL : PVR_CMD_VERTEX; \
*sq = src[0]; \
pvr_dr_commit(sq); \
if (textured) { \
*sq = src[1]; \
pvr_dr_commit(sq); \
} \
} while(0)
#define SUBMIT_INTERPOLATE(vid1, vid2, eolf) \
do { \
sq = (SQBUF*)interpolateAndSubmit<textured>(sq, vpp[vid1], vpp[vid2], eolf ? PVR_CMD_VERTEX_EOL : PVR_CMD_VERTEX); \
} while(0)
uint32_t vismask = 0;
uint8_t* vpp[3];
int8_t eol = 0;
int8_t eol_now = 0;
do {
uint32_t currentCount = -1;
FILLVERT(0);
FILLVERT(1);
FILLVERT(2);
if (vismask & 1) {
SUBMIT_VTX(0, VERTEX);
if (vismask & 2) {
// both first verts visible
SUBMIT_VTX(1, VERTEX);
} else {
// 0 visible, 1 hidden
SUBMIT_INTERPOLATE(0, 1, VERTEX);
}
} else if (vismask & 2) {
// 0 hidden, 1 visible
SUBMIT_INTERPOLATE(1, 0, VERTEX);
SUBMIT_VTX(1, VERTEX);
}
eol = 0;
// each remaining vertex of the strip
while(!eol) {
// "ring buffery" indices
uint8_t vertZeroIdx = (currentCount - 2) % 3;
uint8_t vertOneIdx = (currentCount - 1) % 3;
uint8_t vertTwoIdx = currentCount % 3;
//dcache_pref_block(&vph[vertZeroIdx]); not sure where to put this honestly -jaxyn
eol = eol_now;
if (!vismask) {
if (!eol) {
// "ring buffery" filling
FILLVERT(vertZeroIdx);
}
continue;
}
if (vismask == 7) {
// all visible
SUBMIT_VTX(vertTwoIdx, eol);
if (!eol) {
// "ring buffery" filling
FILLVERT(vertZeroIdx);
}
continue;
}
switch (vismask) {
case 1: // 0 visible, 1 and 2 hidden
// pause strip
SUBMIT_INTERPOLATE(vertZeroIdx, vertTwoIdx, VERTEX_EOL);
break;
case 3: // 0 and 1 visible, 2 hidden
SUBMIT_INTERPOLATE(vertZeroIdx, vertTwoIdx, VERTEX);
SUBMIT_VTX(vertOneIdx, VERTEX);
case 2: // 0 hidden, 1 visible, 2 hidden
SUBMIT_INTERPOLATE(vertOneIdx, vertTwoIdx, eol);
break;
case 4: // 0 and 1 hidden, 2 visible
SUBMIT_INTERPOLATE(vertTwoIdx, vertZeroIdx, VERTEX);
if (currentCount & 0x01) { // flip directionality
case 5: // 0 visible, 1 hidden, 2 visible
SUBMIT_VTX(vertTwoIdx, VERTEX);
}
SUBMIT_INTERPOLATE(vertTwoIdx, vertOneIdx, VERTEX);
SUBMIT_VTX(vertTwoIdx, eol);
break;
case 6: // 0 hidden, 1 and 2 visible
SUBMIT_INTERPOLATE(vertTwoIdx, vertZeroIdx, VERTEX);
SUBMIT_VTX(vertOneIdx, VERTEX);
SUBMIT_VTX(vertTwoIdx, eol);
break;
default:
break;
}
if (!eol) {
// "ring buffery" filling
FILLVERT(vertZeroIdx);
}
};
} while(indexCount != 0);
#undef FILLVERT
#undef SUBMIT_VTX
#undef SUBMIT_INTERPOLATE
}
@@ -2938,16 +3183,26 @@ static constexpr void (*tnlMeshletDiffuseColorSelector[8])(uint8_t* dstCol, cons
&tnlMeshletDiffuseColor<4, true>,
};
static constexpr void (*submitMeshletSelector[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
static void (*submitMeshletSelector[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
&submitMeshlet<false>,
&submitMeshlet<true>,
};
static constexpr void (*clipAndsubmitMeshletSelector[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
static void (*submitMeshletSelectorFallback[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
&submitMeshletFallback<false>,
&submitMeshletFallback<true>,
};
static void (*clipAndsubmitMeshletSelector[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
&clipAndsubmitMeshlet<false>,
&clipAndsubmitMeshlet<true>,
};
static void (*clipAndsubmitMeshletSelectorFallback[2])(uint8_t* OCR, const int8_t* indexData, uint32_t indexCount) = {
&clipAndsubmitMeshletFallback<false>,
&clipAndsubmitMeshletFallback<true>,
};
static constexpr void(*tnlMeshletSkinVerticesSelector[4])(uint8_t *OCR, uint8_t *OCR_normal, const uint8_t* vertex, const uint8_t* normals, const uint8_t* skinWeights, const uint8_t* skinIndexes, int vertexCount, int vertexSize, Matrix* skinMatrices) = {
&tnlMeshletSkinVertices<false, false>,
&tnlMeshletSkinVertices<true , false>,
@@ -4268,6 +4523,32 @@ rasterToImage(Raster*)
return nil;
}
static pvr_init_params_t pvr_params = {
.opb_sizes = {
PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_8, PVR_BINSIZE_0,
PVR_BINSIZE_8
},
.vertex_buf_size = (1024 + 1024) * 1024,
.dma_enabled = 0,
.fsaa_enabled = 0,
.autosort_disabled = true,
.opb_overflow_count = 7 // 268800 bytes
};
static void makeVideoModeList() {
videoModes[0].width = 640;
videoModes[0].height = 480;
videoModes[0].depth = 16;
videoModes[0].flags = VIDEOMODEEXCLUSIVE;
videoModes[1].width = 1280;
videoModes[1].height = 480;
videoModes[1].depth = 16;
videoModes[1].flags = VIDEOMODEEXCLUSIVE;
}
int
deviceSystem(DeviceReq req, void *arg0, int32 n)
{
@@ -4296,14 +4577,14 @@ deviceSystem(DeviceReq req, void *arg0, int32 n)
// TODO: implement subsystems
case DEVICEGETVIDEOMODEINFO:{
makeVideoModeList(); // On startup this is not yet called
auto rwmode = (VideoMode*)arg0;
rwmode->width = 640;
rwmode->height = 480;
rwmode->depth = 16;
rwmode->flags = VIDEOMODEEXCLUSIVE;
rwmode->width = videoModes[n].width;
rwmode->height = videoModes[n].height;
rwmode->depth = videoModes[n].depth;
rwmode->flags = videoModes[n].flags;
return 1;
}
}
case DEVICEGETMAXMULTISAMPLINGLEVELS:
{
@@ -4316,11 +4597,21 @@ deviceSystem(DeviceReq req, void *arg0, int32 n)
case DEVICESETSUBSYSTEM:
return 1;
case DEVICEGETNUMVIDEOMODES:
return 1;
return VIDEO_MODES;
case DEVICEGETCURRENTVIDEOMODE:
return 0;
return VIDEO_MODE;
case DEVICESETVIDEOMODE:
return 1;
{
makeVideoModeList(); // On startup this is called before driverOpen
VIDEO_MODE = n;
SCREEN_WIDTH = videoModes[VIDEO_MODE].width;
SCREEN_HEIGHT = videoModes[VIDEO_MODE].height;
pvr_params.fsaa_enabled = n;
return 1;
}
default:
assert(0 && "not implemented");
return 0;
@@ -4348,15 +4639,7 @@ Device renderdevice = {
deviceSystem
};
static pvr_init_params_t pvr_params = {
.opb_sizes = {
PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_8, PVR_BINSIZE_0,
PVR_BINSIZE_8
},
.vertex_buf_size = (1024 + 1024) * 1024,
.autosort_disabled = true,
.opb_overflow_count = 7 // 268800 bytes
};
void defaultInstance(ObjPipeline *pipe, Atomic *atomic) {
#if defined(DC_TEXCONV)
@@ -4382,6 +4665,36 @@ ObjPipeline* makeDefaultPipeline(void)
static void*
driverOpen(void *o, int32, int32)
{
makeVideoModeList();
#if defined(DC_SH4)
OCR_SPACE = (uint8_t*)0x92000000;
bool has_oix = true;
enter_oix();
*(volatile uint8_t*)OCR_SPACE = 1;
if (*(volatile uint8_t*)OCR_SPACE != 1) {
has_oix = false;
}
leave_oix();
if (!has_oix) {
dbglog(DBG_CRITICAL, "You appear to be using an emulator that does not support OIX. Attempting fallback to OCR\n");
OCR_SPACE = (uint8_t*)0x7c001000;
enter_oix = (void(*)())(((uintptr_t)&enter_ocr_) - 0x8c000000 + 0xAc000000);
leave_oix = (void(*)())(((uintptr_t)&leave_ocr_) - 0x8c000000 + 0xAc000000);
for (size_t i = 0; i < ARRAY_SIZE(submitMeshletSelector); i++) {
submitMeshletSelector[i] = submitMeshletSelectorFallback[i];
}
for (size_t i = 0; i < ARRAY_SIZE(clipAndsubmitMeshletSelector); i++) {
clipAndsubmitMeshletSelector[i] = clipAndsubmitMeshletSelectorFallback[i];
}
}
#endif
pvr_init(&pvr_params);
fake_tex = pvr_mem_malloc(sizeof(fake_tex_data));
@@ -4417,6 +4730,8 @@ driverClose(void *o, int32, int32)
{
pvr_mem_free(fake_tex);
pvr_shutdown();
return o;
}