pvr: serialize TA render passes

use enum for renderer type
This commit is contained in:
Flyinghead 2020-12-15 16:27:34 +01:00
parent c03cf8eb45
commit 04cd7db2cd
11 changed files with 65 additions and 47 deletions

View File

@ -18,7 +18,7 @@ static Renderer* fallback_renderer;
cResetEvent rs, re;
static bool do_swap;
std::mutex swap_mutex;
u32 fb_w_cur = 1; // FIXME serialize
u32 fb_w_cur = 1;
// direct framebuffer write detection
static bool render_called = false;
@ -260,20 +260,20 @@ static void rend_create_renderer()
switch (settings.pvr.rend)
{
default:
case 0:
case RenderType::OpenGL:
renderer = rend_GLES2();
break;
#if !defined(GLES) && !defined(__APPLE__)
case 3:
case RenderType::OpenGL_OIT:
renderer = rend_GL4();
fallback_renderer = rend_GLES2();
break;
#endif
#ifdef USE_VULKAN
case 4:
case RenderType::Vulkan:
renderer = rend_Vulkan();
break;
case 5:
case RenderType::Vulkan_OIT:
renderer = rend_OITVulkan();
break;
#endif

View File

@ -246,17 +246,15 @@ void SerializeTAContext(void **data, unsigned int *total_size)
const u32 taSize = ta_tad.thd_data - ta_tad.thd_root;
REICAST_S(taSize);
REICAST_SA(ta_tad.thd_root, taSize);
#if 0
REICAST_S(ta_tad.render_pass_count);
for (u32 i = 0; i < ta_tad.render_pass_count; i++)
{
u32 offset = (u32)(ta_tad.render_passes[i] - ta_tad.thd_root);
REICAST_S(offset);
}
#endif
}
void UnserializeTAContext(void **data, unsigned int *total_size)
void UnserializeTAContext(void **data, unsigned int *total_size, serialize_version_enum version)
{
u32 address;
REICAST_US(address);
@ -267,14 +265,18 @@ void UnserializeTAContext(void **data, unsigned int *total_size)
REICAST_US(size);
REICAST_USA(ta_tad.thd_root, size);
ta_tad.thd_data = ta_tad.thd_root + size;
// FIXME savestate version
#if 0
REICAST_US(ta_tad.render_pass_count);
for (u32 i = 0; i < ta_tad.render_pass_count; i++)
if (version >= V12)
{
u32 offset;
REICAST_US(offset);
ta_tad.render_passes[i] = ta_tad.thd_root + offset;
REICAST_US(ta_tad.render_pass_count);
for (u32 i = 0; i < ta_tad.render_pass_count; i++)
{
u32 offset;
REICAST_US(offset);
ta_tad.render_passes[i] = ta_tad.thd_root + offset;
}
}
else
{
ta_tad.render_pass_count = 0;
}
#endif
}

View File

@ -274,4 +274,4 @@ void FillBGP(TA_context* ctx);
bool UsingAutoSort(int pass_number);
bool rend_framePending();
void SerializeTAContext(void **data, unsigned int *total_size);
void UnserializeTAContext(void **data, unsigned int *total_size);
void UnserializeTAContext(void **data, unsigned int *total_size, serialize_version_enum version);

View File

@ -434,7 +434,7 @@ int reicast_init(int argc, char* argv[])
LogManager::Init();
LoadSettings(false);
}
settings.pvr.rend = cfgLoadInt("config", "pvr.rend", settings.pvr.rend);
settings.pvr.rend = (RenderType)cfgLoadInt("config", "pvr.rend", (int)settings.pvr.rend);
os_CreateWindow();
os_SetupInput();
@ -1011,7 +1011,7 @@ void SaveSettings()
if (!naomi_rotate_screen || !settings.rend.Rotate90)
cfgSaveBool("config", "rend.Rotate90", settings.rend.Rotate90);
cfgSaveInt("config", "ta.skip", settings.pvr.ta_skip);
cfgSaveInt("config", "pvr.rend", settings.pvr.rend);
cfgSaveInt("config", "pvr.rend", (int)settings.pvr.rend);
cfgSaveBool("config", "rend.PerStripSorting", settings.rend.PerStripSorting);
cfgSaveBool("config", "rend.DelayFrameSwapping", settings.rend.DelayFrameSwapping);
cfgSaveBool("config", "rend.WidescreenGameHacks", settings.rend.WidescreenGameHacks);

View File

@ -786,8 +786,8 @@ static void gui_display_settings()
ImGui::NewFrame();
int dynarec_enabled = settings.dynarec.Enable;
int pvr_rend = settings.pvr.rend;
bool vulkan = pvr_rend == 4 || pvr_rend == 5;
RenderType pvr_rend = settings.pvr.rend;
bool vulkan = !settings.pvr.IsOpenGL();
ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(screen_width, screen_height));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0);
@ -1108,7 +1108,7 @@ static void gui_display_settings()
#endif
if (ImGui::CollapsingHeader("Transparent Sorting", ImGuiTreeNodeFlags_DefaultOpen))
{
int renderer = (pvr_rend == 3 || pvr_rend == 5) ? 2 : settings.rend.PerStripSorting ? 1 : 0;
int renderer = (pvr_rend == RenderType::OpenGL_OIT || pvr_rend == RenderType::Vulkan_OIT) ? 2 : settings.rend.PerStripSorting ? 1 : 0;
ImGui::Columns(has_per_pixel ? 3 : 2, "renderers", false);
ImGui::RadioButton("Per Triangle", &renderer, 0);
ImGui::SameLine();
@ -1129,23 +1129,23 @@ static void gui_display_settings()
{
case 0:
if (!vulkan)
pvr_rend = 0; // regular Open GL
pvr_rend = RenderType::OpenGL; // regular Open GL
else
pvr_rend = 4; // regular Vulkan
pvr_rend = RenderType::Vulkan; // regular Vulkan
settings.rend.PerStripSorting = false;
break;
case 1:
if (!vulkan)
pvr_rend = 0;
pvr_rend = RenderType::OpenGL;
else
pvr_rend = 4;
pvr_rend = RenderType::Vulkan;
settings.rend.PerStripSorting = true;
break;
case 2:
if (!vulkan)
pvr_rend = 3;
pvr_rend = RenderType::OpenGL_OIT;
else
pvr_rend = 5;
pvr_rend = RenderType::Vulkan_OIT;
break;
}
}
@ -1528,7 +1528,7 @@ static void gui_display_settings()
}
}
#ifdef USE_VULKAN
else if (settings.pvr.rend == 4 || settings.pvr.rend == 5)
else
{
if (ImGui::CollapsingHeader("Vulkan", ImGuiTreeNodeFlags_DefaultOpen))
{
@ -1562,9 +1562,10 @@ static void gui_display_settings()
ImGui::Render();
ImGui_impl_RenderDrawData(ImGui::GetDrawData(), false);
if (vulkan ^ (settings.pvr.rend == 4 || settings.pvr.rend == 5))
pvr_rend = !vulkan ? 0 : settings.pvr.rend == 3 ? 5 : 4;
renderer_changed = pvr_rend;
if (vulkan != !settings.pvr.IsOpenGL())
pvr_rend = !vulkan ? RenderType::OpenGL
: settings.pvr.rend == RenderType::OpenGL_OIT ? RenderType::Vulkan_OIT : RenderType::Vulkan;
renderer_changed = (int)pvr_rend;
settings.dynarec.Enable = (bool)dynarec_enabled;
}
@ -1709,7 +1710,7 @@ static void systemdir_selected_callback(bool cancelled, std::string selection)
{
LoadSettings(false);
// Make sure the renderer type doesn't change mid-flight
settings.pvr.rend = 0;
settings.pvr.rend = RenderType::OpenGL;
gui_state = Main;
if (settings.dreamcast.ContentPath.empty())
{

View File

@ -63,7 +63,7 @@ void mainui_term()
void mainui_loop()
{
mainui_enabled = true;
renderer_changed = settings.pvr.rend;
renderer_changed = (int)settings.pvr.rend;
mainui_init();
while (mainui_enabled)
@ -78,11 +78,11 @@ void mainui_loop()
#endif
}
if ((u32)renderer_changed != settings.pvr.rend)
if (renderer_changed != (int)settings.pvr.rend)
{
mainui_term();
SwitchRenderApi(renderer_changed == -1 ? settings.pvr.rend : renderer_changed);
renderer_changed = settings.pvr.rend;
SwitchRenderApi(renderer_changed == -1 ? settings.pvr.rend : (RenderType)renderer_changed);
renderer_changed = (int)settings.pvr.rend;
mainui_init();
}
}

View File

@ -110,6 +110,7 @@ extern int modem_sched;
//./core/hw/pvr/Renderer_if.o
extern bool pend_rend;
extern u32 fb_w_cur;
//./core/hw/pvr/pvr_mem.o
extern u32 YUV_tempdata[512/4];//512 bytes
@ -273,7 +274,7 @@ bool dc_serialize(void **data, unsigned int *total_size)
{
int i = 0;
serialize_version_enum version = V11;
serialize_version_enum version = V12;
*total_size = 0 ;
@ -373,6 +374,7 @@ bool dc_serialize(void **data, unsigned int *total_size)
REICAST_S(in_vblank);
REICAST_S(clc_pvr_scanline);
REICAST_S(fb_w_cur);
REICAST_S(ta_fsm[2048]);
REICAST_S(ta_fsm_cl);
@ -653,12 +655,13 @@ static bool dc_unserialize_libretro(void **data, unsigned int *total_size)
REICAST_US(in_vblank);
REICAST_US(clc_pvr_scanline);
fb_w_cur = 1;
REICAST_US(ta_fsm[2048]);
REICAST_US(ta_fsm_cl);
pal_needs_update = true;
UnserializeTAContext(data, total_size);
UnserializeTAContext(data, total_size, VCUR_LIBRETRO);
REICAST_USA(vram.data, vram.size);
@ -973,6 +976,10 @@ bool dc_unserialize(void **data, unsigned int *total_size)
REICAST_SKIP(4 * 256);
REICAST_SKIP(2048); // ta_fsm
}
if (version >= V12)
REICAST_US(fb_w_cur);
else
fb_w_cur = 1;
REICAST_US(ta_fsm[2048]);
REICAST_US(ta_fsm_cl);
@ -986,7 +993,7 @@ bool dc_unserialize(void **data, unsigned int *total_size)
REICAST_SKIP(4);
}
if (version >= V11)
UnserializeTAContext(data, total_size);
UnserializeTAContext(data, total_size, version);
REICAST_USA(vram.data, vram.size);
pal_needs_update = true;

View File

@ -350,6 +350,13 @@ enum class JVS {
WaveRunnerGP,
};
enum class RenderType {
OpenGL = 0,
OpenGL_OIT = 3,
Vulkan = 4,
Vulkan_OIT = 5
};
struct settings_t
{
struct {
@ -465,12 +472,12 @@ struct settings_t
struct
{
u32 ta_skip;
u32 rend; // 0: GLES, GL3, 3: OIT/GL4.3, 4: Vulkan
RenderType rend;
u32 MaxThreads;
bool SynchronousRender;
bool IsOpenGL() { return rend == 0 || rend == 3; }
bool IsOpenGL() { return rend == RenderType::OpenGL || rend == RenderType::OpenGL_OIT; }
} pvr;
struct {
@ -625,4 +632,5 @@ enum serialize_version_enum {
V9 = 804,
V10 = 805,
V11 = 806,
V12 = 807,
} ;

View File

@ -26,6 +26,6 @@
extern VulkanContext theVulkanContext;
#endif
void InitRenderApi();
void SwitchRenderApi(int newApi);
void SwitchRenderApi(RenderType newApi);
void TermRenderApi();

View File

@ -28,20 +28,20 @@ VulkanContext theVulkanContext;
void InitRenderApi()
{
#ifdef USE_VULKAN
if (settings.pvr.rend == 4 || settings.pvr.rend == 5)
if (!settings.pvr.IsOpenGL())
{
if (theVulkanContext.Init())
return;
// Fall back to Open GL
WARN_LOG(RENDERER, "Vulkan init failed. Falling back to Open GL.");
settings.pvr.rend = 0;
settings.pvr.rend = RenderType::OpenGL;
}
#endif
if (!theGLContext.Init())
exit(1);
}
void SwitchRenderApi(int newApi)
void SwitchRenderApi(RenderType newApi)
{
TermRenderApi();
settings.pvr.rend = newApi;

View File

@ -28,7 +28,7 @@ TEST_F(SerializeTest, SizeTest)
unsigned int total_size = 0;
void *data = nullptr;
ASSERT_TRUE(dc_serialize(&data, &total_size));
ASSERT_EQ(28145458u, total_size);
ASSERT_EQ(28145462u, total_size);
}