Commit ea3137c3 authored by Flyinghead's avatar Flyinghead
Browse files

Merge OIT and non-OIT renderers

parent b8017b5d
......@@ -18,11 +18,7 @@ HAVE_OPENMP := 1
HAVE_CHD := 1
ifeq ($(HAVE_OIT), 1)
TARGET_NAME := reicast_oit
else
TARGET_NAME := reicast
endif
TARGET_NAME := reicast
CXX = ${CC_PREFIX}g++
CC = ${CC_PREFIX}gcc
......
......@@ -133,15 +133,14 @@ endif
ifeq ($(HAVE_GL), 1)
SOURCES_CXX += $(CORE_DIR)/core/rend/gles/gles.cpp \
$(CORE_DIR)/core/rend/gles/gldraw.cpp \
$(CORE_DIR)/core/rend/gles/gltex.cpp
ifeq ($(HAVE_OIT), 1)
SOURCES_CXX += $(CORE_DIR)/core/rend/gl4/gles.cpp \
$(CORE_DIR)/core/rend/gl4/gldraw.cpp \
$(CORE_DIR)/core/rend/gl4/gltex.cpp \
$(CORE_DIR)/core/rend/gl4/abuffer.cpp
else
SOURCES_CXX += $(CORE_DIR)/core/rend/gles/gles.cpp \
$(CORE_DIR)/core/rend/gles/gldraw.cpp \
$(CORE_DIR)/core/rend/gles/gltex.cpp
endif
SOURCES_C += $(LIBRETRO_COMM_DIR)/glsym/rglgen.c \
$(LIBRETRO_COMM_DIR)/glsm/glsm.c
......
......@@ -67,6 +67,8 @@ u32 VertexCount=0;
u32 FrameCount=1;
Renderer* renderer;
static Renderer* fallback_renderer;
bool renderer_changed = false; // Signals the renderer interface to switch renderer
#if !defined(TARGET_NO_THREADS)
cResetEvent rs(false,true);
......@@ -86,8 +88,66 @@ bool fb_dirty;
TA_context* _pvrrc;
void SetREP(TA_context* cntx);
void rend_create_renderer()
{
#ifdef NO_REND
renderer = rend_norend();
#else
switch (settings.pvr.rend)
{
default:
case 0:
printf("Creating per-triangle/strip renderer\n");
renderer = rend_GLES2();
break;
#if defined(HAVE_OIT)
case 3:
printf("Creating per-pixel renderer\n");
renderer = rend_GL4();
fallback_renderer = rend_GLES2();
break;
#endif
}
#endif
}
void rend_init_renderer()
{
if (!renderer->Init())
{
delete renderer;
if (fallback_renderer == NULL || !fallback_renderer->Init())
{
if (fallback_renderer != NULL)
delete fallback_renderer;
die("Renderer initialization failed\n");
}
printf("Selected renderer initialization failed. Falling back to default renderer.\n");
renderer = fallback_renderer;
}
}
void rend_term_renderer()
{
renderer->Term();
delete renderer;
renderer = NULL;
if (fallback_renderer != NULL)
{
delete fallback_renderer;
fallback_renderer = NULL;
}
}
bool rend_frame(TA_context* ctx, bool draw_osd)
{
if (renderer_changed)
{
renderer_changed = false;
rend_term_renderer();
rend_create_renderer();
rend_init_renderer();
}
bool proc = renderer->Process(ctx);
#if !defined(TARGET_NO_THREADS)
......@@ -143,17 +203,17 @@ void *rend_thread(void* p)
printf("WARNING: Could not set CPU Affinity, continuing...\n");
#endif
if (!renderer->Init())
die("rend->init() failed\n");
rend_init_renderer();
//we don't know if this is true, so let's not speculate here
//renderer->Resize(640, 480);
while(rend_en)
{
if (rend_single_frame())
renderer->Present();
if (rend_single_frame())
renderer->Present();
}
rend_term_renderer();
return 0;
}
......@@ -251,22 +311,15 @@ void rend_cancel_emu_wait()
bool rend_init(void)
{
#ifdef NO_REND
renderer = rend_norend();
#elif defined(HAVE_GL4)
renderer = rend_GL4();
#else
renderer = rend_GLES2();
#endif
rend_create_renderer();
#if !defined(TARGET_NO_THREADS)
if (!settings.rend.ThreadedRendering)
#endif
{
if (!renderer->Init())
die("rend->init() failed\n");
rend_init_renderer();
renderer->Resize(screen_width, screen_height);
renderer->Resize(screen_width, screen_height);
}
#if SET_AFNT
......
......@@ -50,6 +50,7 @@ struct Renderer
};
extern Renderer* renderer;
extern bool renderer_changed;
Renderer* rend_D3D11();
......@@ -65,3 +66,7 @@ extern u32 fb2_watch_addr_end;
extern bool fb_dirty;
void check_framebuffer_write();
void rend_create_renderer();
void rend_init_renderer();
void rend_term_renderer();
......@@ -70,10 +70,8 @@ List<PolyParam>* CurrentPPlist;
//TA state vars
DECL_ALIGN(4) u8 FaceBaseColor[4];
DECL_ALIGN(4) u8 FaceOffsColor[4];
#ifdef HAVE_OIT
DECL_ALIGN(4) u8 FaceBaseColor1[4];
DECL_ALIGN(4) u8 FaceOffsColor1[4];
#endif
DECL_ALIGN(4) u32 SFaceBaseColor;
DECL_ALIGN(4) u32 SFaceOffsColor;
......@@ -724,9 +722,7 @@ public:
CurrentPP=&nullPP;
CurrentPPlist=0;
if ( ListType == ListType_Opaque_Modifier_Volume
#ifdef HAVE_OIT
|| ListType == ListType_Translucent_Modifier_Volume
#endif
)
EndModVol();
}
......@@ -766,11 +762,9 @@ public:
if (d_pp->pcw.Texture) {
d_pp->texid = renderer->GetTexture(d_pp->tsp,d_pp->tcw);
}
#ifdef HAVE_OIT
d_pp->tsp1.full = -1;
d_pp->tsp1.full = -1;
d_pp->tcw1.full = -1;
d_pp->texid1 = -1;
#endif
}
}
......@@ -824,12 +818,10 @@ public:
glob_param_bdc(pp);
#ifdef HAVE_OIT
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tcw1.full = pp->tcw1.full;
if (pp->pcw.Texture)
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
#endif
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
}
__forceinline
static void TACALL AppendPolyParam4A(void* vpp)
......@@ -838,12 +830,10 @@ public:
glob_param_bdc(pp);
#ifdef HAVE_OIT
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tsp1.full = pp->tsp1.full;
CurrentPP->tcw1.full = pp->tcw1.full;
if (pp->pcw.Texture)
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
#endif
CurrentPP->texid1 = renderer->GetTexture(pp->tsp1, pp->tcw1);
}
__forceinline
static void TACALL AppendPolyParam4B(void* vpp)
......@@ -851,9 +841,7 @@ public:
TA_PolyParam4B* pp=(TA_PolyParam4B*)vpp;
poly_float_color(FaceBaseColor,FaceColor0);
#ifdef HAVE_OIT
poly_float_color(FaceBaseColor1, FaceColor1);
#endif
poly_float_color(FaceBaseColor1, FaceColor1);
}
//Poly Strip handling
......@@ -864,8 +852,6 @@ public:
{
CurrentPP->count=vdrc.idx.used() - CurrentPP->first;
#ifdef HAVE_OIT
#if STRIPS_AS_PPARAMS
if (CurrentPPlist==&vdrc.global_param_tr)
{
PolyParam* d_pp =CurrentPPlist->Append();
......@@ -875,36 +861,15 @@ public:
d_pp->count=0;
}
else
#endif
{
int vbase=vdrc.verts.used();
int vbase=vdrc.verts.used();
*vdrc.idx.Append()=vbase-1;
*vdrc.idx.Append()=vbase;
if (CurrentPP->count&1)
*vdrc.idx.Append()=vbase;
*vdrc.idx.Append()=vbase;
}
#else
int vbase=vdrc.verts.used();
*vdrc.idx.Append()=vbase-1;
*vdrc.idx.Append()=vbase;
if (CurrentPP->count&1)
*vdrc.idx.Append()=vbase;
#if STRIPS_AS_PPARAMS
if (CurrentPPlist==&vdrc.global_param_tr)
{
PolyParam* d_pp =CurrentPPlist->Append();
*d_pp=*CurrentPP;
CurrentPP=d_pp;
d_pp->first=vdrc.idx.used();
d_pp->count=0;
}
#endif
#endif
}
......@@ -1135,9 +1100,7 @@ public:
vert_cvt_base;
vert_packed_color(col,BaseCol0);
#ifdef HAVE_OIT
vert_packed_color(col1, BaseCol1);
#endif
vert_packed_color(col1, BaseCol1);
}
//(Non-Textured, Intensity, with Two Volumes)
......@@ -1147,9 +1110,7 @@ public:
vert_cvt_base;
vert_face_base_color(BaseInt0);
#ifdef HAVE_OIT
vert_face_base_color1(BaseInt1);
#endif
vert_face_base_color1(BaseInt1);
}
//(Textured, Packed Color, with Two Volumes)
......@@ -1168,12 +1129,10 @@ public:
{
vert_res_base;
#ifdef HAVE_OIT
vert_packed_color(col1, BaseCol1);
vert_packed_color(col1, BaseCol1);
vert_packed_color(spc1, OffsCol1);
vert_uv1_32(u1, v1);
#endif
}
//(Textured, Packed Color, 16bit UV, with Two Volumes)
......@@ -1192,12 +1151,10 @@ public:
{
vert_res_base;
#ifdef HAVE_OIT
vert_packed_color(col1, BaseCol1);
vert_packed_color(col1, BaseCol1);
vert_packed_color(spc1, OffsCol1);
vert_uv1_16(u1, v1);
#endif
}
//(Textured, Intensity, with Two Volumes)
......@@ -1216,12 +1173,10 @@ public:
{
vert_res_base;
#ifdef HAVE_OIT
vert_face_base_color1(BaseInt1);
vert_face_base_color1(BaseInt1);
vert_face_offs_color1(OffsInt1);
vert_uv1_32(u1,v1);
#endif
}
//(Textured, Intensity, 16bit UV, with Two Volumes)
......@@ -1240,12 +1195,10 @@ public:
{
vert_res_base;
#ifdef HAVE_OIT
vert_face_base_color1(BaseInt1);
vert_face_base_color1(BaseInt1);
vert_face_offs_color1(OffsInt1);
vert_uv1_16(u1, v1);
#endif
}
//Sprites
......@@ -1273,11 +1226,9 @@ public:
if (d_pp->pcw.Texture) {
d_pp->texid = renderer->GetTexture(d_pp->tsp,d_pp->tcw);
}
#ifdef HAVE_OIT
d_pp->tcw1.full = -1;
d_pp->tcw1.full = -1;
d_pp->tsp1.full = -1;
d_pp->texid1 = -1;
#endif
SFaceBaseColor=spr->BaseCol;
SFaceOffsColor=spr->OffsCol;
......@@ -1435,10 +1386,8 @@ public:
List<ModifierVolumeParam> *list = NULL;
if (CurrentList == ListType_Opaque_Modifier_Volume)
list = &vdrc.global_param_mvo;
#ifdef HAVE_OIT
else if (CurrentList == ListType_Translucent_Modifier_Volume)
list = &vdrc.global_param_mvo_tr;
#endif
else
return;
if (list->used() > 0)
......@@ -1456,10 +1405,8 @@ public:
ModifierVolumeParam *p = NULL;
if (CurrentList == ListType_Opaque_Modifier_Volume)
p = vdrc.global_param_mvo.Append();
#ifdef HAVE_OIT
else if (CurrentList == ListType_Translucent_Modifier_Volume)
p = vdrc.global_param_mvo_tr.Append();
#endif
else
return;
p->isp.full = param->isp.full;
......@@ -1469,11 +1416,7 @@ public:
__forceinline
static void AppendModVolVertexA(TA_ModVolA* mvv)
{
#ifdef HAVE_OIT
if (CurrentList != ListType_Opaque_Modifier_Volume && CurrentList != ListType_Translucent_Modifier_Volume)
#else
if (CurrentList!=ListType_Opaque_Modifier_Volume)
#endif
if (CurrentList != ListType_Opaque_Modifier_Volume && CurrentList != ListType_Translucent_Modifier_Volume)
return;
lmr=vdrc.modtrig.Append();
......@@ -1493,15 +1436,11 @@ public:
__forceinline
static void AppendModVolVertexB(TA_ModVolB* mvv)
{
#ifdef HAVE_OIT
if (CurrentList != ListType_Opaque_Modifier_Volume && CurrentList != ListType_Translucent_Modifier_Volume)
#else
if (CurrentList!=ListType_Opaque_Modifier_Volume)
#endif
return;
lmr->y2=mvv->y2;
lmr->z2=mvv->z2;
//update_fz(mvv->z2);
if (CurrentList != ListType_Opaque_Modifier_Volume && CurrentList != ListType_Translucent_Modifier_Volume)
return;
lmr->y2=mvv->y2;
lmr->z2=mvv->z2;
//update_fz(mvv->z2);
}
static void VDECInit()
......@@ -1564,10 +1503,8 @@ bool ta_parse_vdrc(TA_context* ctx)
render_pass->pt_count = vd_rc.global_param_pt.used();
render_pass->tr_count = vd_rc.global_param_tr.used();
render_pass->autosort = UsingAutoSort(pass);
render_pass->z_clear = ClearZBeforePass(pass);
#ifdef HAVE_OIT
render_pass->z_clear = ClearZBeforePass(pass);
render_pass->mvo_tr_count = vd_rc.global_param_mvo_tr.used();
#endif
}
bool empty_context = true;
......@@ -1720,11 +1657,9 @@ void FillBGP(TA_context* ctx)
bgpp->isp.full=vri(strip_base);
bgpp->tsp.full=vri(strip_base+4);
bgpp->tcw.full=vri(strip_base+8);
#ifdef HAVE_OIT
bgpp->tcw1.full = -1;
bgpp->tcw1.full = -1;
bgpp->tsp1.full = -1;
bgpp->texid1 = -1;
#endif
bgpp->count=4;
bgpp->first=0;
bgpp->tileclip=0;//disabled ! HA ~
......
......@@ -324,11 +324,10 @@ void retro_set_environment(retro_environment_t cb)
"Internal resolution (restart); 640x480|320x240|1280x960|1920x1440|2560x1920|3200x2400|3840x2880|4480x3360|5120x3840|5760x4320|6400x4800|7040x5280|7680x5760|8320x6240|8960x6720|9600x7200|10240x7680|10880x8160|11520x8640|12160x9120|12800x9600",
},
{
"reicast_alpha_sorting",
#ifdef HAVE_OIT
"reicast_oit_alpha_sorting",
"Alpha sorting; per-pixel (accurate)",
"Alpha sorting; per-pixel (accurate)|per-triangle (normal)|per-strip (fast, least accurate)",
#else
"reicast_alpha_sorting",
"Alpha sorting; per-triangle (normal)|per-strip (fast, least accurate)",
#endif
},
......@@ -392,12 +391,6 @@ void retro_set_environment(retro_environment_t cb)
"reicast_enable_dsp",
"Enable DSP; enabled|disabled",
},
#ifndef HAVE_OIT
{
"reicast_precompile_shaders",
"Precompile shaders; disabled|enabled",
},
#endif
#ifdef HAVE_TEXUPSCALE
{
"reicast_texupscale",
......@@ -608,24 +601,34 @@ static void update_variables(bool first_startup)
else
GDROM_TICK = 1500000;
#ifdef HAVE_OIT
var.key = "reicast_oit_alpha_sorting";
#else
var.key = "reicast_alpha_sorting";
#endif
int previous_renderer = settings.pvr.rend;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "per-strip (fast, least accurate)"))
{
settings.pvr.rend = 0;
settings.pvr.Emulation.AlphaSortMode = 1;
}
else if (!strcmp(var.value, "per-triangle (normal)"))
{
settings.pvr.rend = 0;
settings.pvr.Emulation.AlphaSortMode = 0;
}
else if (!strcmp(var.value, "per-pixel (accurate)"))
settings.pvr.Emulation.AlphaSortMode = 0; /* value not used for OIT */
{
settings.pvr.rend = 3;
settings.pvr.Emulation.AlphaSortMode = 0; // Not used
}
}
else
{
settings.pvr.rend = 0;
settings.pvr.Emulation.AlphaSortMode = 0;
}
if (!first_startup && previous_renderer != settings.pvr.rend)
renderer_changed = true;
var.key = "reicast_mipmapping";
......@@ -662,17 +665,16 @@ static void update_variables(bool first_startup)
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp(var.value, "512MB"))
pixel_buffer_size = 0x20000000;
pixel_buffer_size = 0x20000000u;
else if (!strcmp(var.value, "1GB"))
pixel_buffer_size = 0x40000000;
pixel_buffer_size = 0x40000000u;
else if (!strcmp(var.value, "2GB"))
pixel_buffer_size = 0x80000000;
pixel_buffer_size = 0x80000000u;
else
pixel_buffer_size = 0x20000000;
pixel_buffer_size = 0x20000000u;
}
else
pixel_buffer_size = 0x20000000;
pixel_buffer_size = 0x20000000u;
#endif
}
......@@ -777,18 +779,6 @@ static void update_variables(bool first_startup)
}
}
#ifndef HAVE_OIT
var.key = "reicast_precompile_shaders";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (!strcmp("disabled", var.value))
settings.pvr.Emulation.precompile_shaders = false;
else
settings.pvr.Emulation.precompile_shaders = true;
}
#endif
#ifdef HAVE_TEXUPSCALE
var.key = "reicast_texupscale";
......@@ -1076,8 +1066,8 @@ void retro_run (void)
// We can now initialize the renderer
if (!renderer_inited)
{
renderer->Init();
renderer_inited = true;
rend_init_renderer();
renderer_inited = true;
}
/// And start rendering
is_dupe = !rend_single_frame();
......@@ -1608,11 +1598,7 @@ const char* retro_get_system_directory(void)
void retro_get_system_info(struct retro_system_info *info)
{
#ifdef HAVE_OIT
info->library_name = "Reicast OIT";
#else
info->library_name = "Reicast";
#endif
#ifndef GIT_VERSION
#define GIT_VERSION ""
#endif
......
......@@ -438,7 +438,6 @@ void LoadSettings(void)
settings.aica.NoSound = 0;
settings.pvr.subdivide_transp = 0;
settings.pvr.ta_skip = 0;
settings.pvr.rend = 0;
//settings.pvr.Emulation.AlphaSortMode= 0;
settings.pvr.Emulation.zMin = 0.f;
settings.pvr.Emulation.zMax = 1.0f;
......
......@@ -8,6 +8,7 @@ extern u32 palette32_ram[1024];
extern bool pal_needs_update,fog_needs_update;
extern u32 pal_hash_256[4];
extern u32 pal_hash_16[64];
extern bool KillTex;
extern u32 detwiddle[2][8][1024];
......
......@@ -4,15 +4,16 @@
* Created on: May 26, 2018
* Author: raph
*/
#include "glcache.h"
#include "gl4.h"
#include "rend/gles/glcache.h"
GLuint pixels_buffer;
GLuint pixels_pointers;
GLuint atomic_buffer;
PipelineShader g_abuffer_final_shader;
PipelineShader g_abuffer_final_nosort_shader;
PipelineShader g_abuffer_clear_shader;
PipelineShader g_abuffer_tr_modvol_shaders[ModeCount];
gl4PipelineShader g_abuffer_final_shader;
gl4PipelineShader g_abuffer_final_nosort_shader;
gl4PipelineShader g_abuffer_clear_shader;
gl4PipelineShader g_abuffer_tr_modvol_shaders[ModeCount];
static GLuint g_quadBuffer = 0;
static GLuint g_quadVertexArray = 0;
......@@ -298,6 +299,11 @@ void initABuffer()
if (pixels_buffer == 0 )
{
// get the max buffer size
GLint64 size;
glGetInteger64v(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &size);