Skip to content

Commit

Permalink
Make VitaGL branch (test purposes)
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicMastr committed Jan 28, 2024
1 parent 54096c9 commit c8ab7ce
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 14 deletions.
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#endif

#include <EGL/egl.h>
#include <EGL/eglext.h>
//#include <EGL/eglext.h>
#endif

#if defined(MINGW_ENABLED) || defined(_MSC_VER)
Expand Down
18 changes: 15 additions & 3 deletions drivers/gles2/rasterizer_storage_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEEXTPROC glFramebufferTexture2DMultisampleEXT
#define glRenderbufferStorageMultisample glRenderbufferStorageMultisampleANGLE
#define glFramebufferTexture2DMultisample glFramebufferTexture2DMultisampleANGLE

#elif defined(VITA_ENABLED)
#elif defined(VITA_ENABLED) && defined(PVR_PSP2)
#include <GLES2/gl2ext.h>
#define glRenderbufferStorageMultisample glRenderbufferStorageMultisampleIMG
#define glFramebufferTexture2DMultisample glFramebufferTexture2DMultisampleIMG
Expand Down Expand Up @@ -534,7 +534,7 @@ void RasterizerStorageGLES2::texture_allocate(RID p_texture, int p_width, int p_
texture->images.resize(1);
} break;
case VS::TEXTURE_TYPE_EXTERNAL: {
#if defined(ANDROID_ENABLED) || defined(VITA_ENABLED)
#if defined(ANDROID_ENABLED) || (defined(VITA_ENABLED) && defined(PVR_PSP2))
texture->target = _GL_TEXTURE_EXTERNAL_OES;
#else
texture->target = GL_TEXTURE_2D;
Expand Down Expand Up @@ -5039,6 +5039,8 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
rt->height = MIN(rt->height, config.max_viewport_dimensions[1]);
}

printf("Allocating Rendertarget %dx%d\n", rt->width, rt->height);

GLuint color_internal_format;
GLuint color_format;
GLuint color_type = GL_UNSIGNED_BYTE;
Expand Down Expand Up @@ -5155,7 +5157,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
/* BACK FBO */
/* For MSAA */

#ifndef JAVASCRIPT_ENABLED
#if !defined(JAVASCRIPT_ENABLED) && defined(PVR_PSP2)
if (rt->msaa >= VS::VIEWPORT_MSAA_2X && rt->msaa <= VS::VIEWPORT_MSAA_16X && config.multisample_supported) {
rt->multisample_active = true;

Expand Down Expand Up @@ -5268,7 +5270,11 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
}

// Allocate mipmap chains for post_process effects
#if (defined(VITA_ENABLED) && !defined(PVR_PSP2))
if (0) {
#else
if (!rt->flags[RasterizerStorage::RENDER_TARGET_NO_3D] && rt->width >= 2 && rt->height >= 2) {
#endif
for (int i = 0; i < 2; i++) {
ERR_FAIL_COND(rt->mip_maps[i].sizes.size());
int w = rt->width;
Expand Down Expand Up @@ -6283,6 +6289,9 @@ void RasterizerStorageGLES2::initialize() {
// S3TC it will crash trying to load these textures, as they are not exported in the APK. This is a simple way
// to prevent Android devices trying to load S3TC, by faking lack of hardware support.
#if defined(ANDROID_ENABLED) || defined(IPHONE_ENABLED) || defined(VITA_ENABLED)
#ifndef PVR_PSP2
config.support_npot_repeat_mipmap = false;
#endif
config.s3tc_supported = false;
#endif

Expand Down Expand Up @@ -6446,6 +6455,9 @@ void RasterizerStorageGLES2::initialize() {

//picky requirements for these
config.support_shadow_cubemaps = config.support_depth_texture && config.support_write_depth && config.support_depth_cubemaps;
#if (defined(VITA_ENABLED) && !defined(PVR_PSP2))
config.support_shadow_cubemaps = false;
#endif
if (!config.support_shadow_cubemaps) {
print_verbose("OmniLight cubemap shadows are not supported by this GPU. Falling back to dual paraboloid shadows for all omni lights (faster but less precise).");
}
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles2/shaders/canvas.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* clang-format off */
[vertex]

#define texture2DLod(img, coord, lod) texture2D(img, coord, lod) // I'll pretend like I can't read - Jaylon
#define textureCubeLod(img, coord, lod) textureCube(img, coord, lod)

#ifdef USE_GLES_OVER_GL
#define lowp
#define mediump
Expand Down
3 changes: 3 additions & 0 deletions drivers/gles2/shaders/scene.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* clang-format off */
[vertex]

#define texture2DLod(img, coord, lod) texture2D(img, coord, lod) // I'll pretend like I can't read - Jaylon
#define textureCubeLod(img, coord, lod) textureCube(img, coord, lod)

#ifdef USE_GLES_OVER_GL
#define lowp
#define mediump
Expand Down
43 changes: 41 additions & 2 deletions platform/vita/context_egl_vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,39 @@

#include "context_egl_vita.h"

#ifndef PVR_PSP2
#define MEMORY_MAIN_THRESHOLD 0
#define MEMORY_GFX_THRESHOLD 0
#define MEMORY_PHYCONT_THRESHOLD 0
#define MEMORY_CDGL_THRESHOLD 26 * 1024 * 1024

static bool b_vglInitialized = 0;
#endif

#ifdef PVR_PSP2
void ContextEGL_Vita::release_current() {
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
}

void ContextEGL_Vita::make_current() {
eglMakeCurrent(display, surface, surface, context);
}
#endif

int ContextEGL_Vita::get_window_width() {
#ifdef PVR_PSP2
return width;
#else
return 960;
#endif
}

int ContextEGL_Vita::get_window_height() {
#ifdef PVR_PSP2
return height;
#else
return 544;
#endif
}

void ContextEGL_Vita::reset() {
Expand All @@ -52,13 +71,18 @@ void ContextEGL_Vita::reset() {
}

void ContextEGL_Vita::swap_buffers() {
#ifdef PVR_PSP2
if (eglSwapBuffers(display, surface) != EGL_TRUE) {
cleanup();
initialize();
}
#else
vglSwapBuffers(GL_FALSE);
#endif
};

Error ContextEGL_Vita::initialize() {
#ifdef PVR_PSP2
// Get an appropriate EGL framebuffer configuration
static const EGLint attributeList[] = {
EGL_RED_SIZE, 8,
Expand Down Expand Up @@ -127,9 +151,16 @@ Error ContextEGL_Vita::initialize() {

eglQuerySurface(display, surface, EGL_WIDTH, &width);
eglQuerySurface(display, surface, EGL_HEIGHT, &height);

#else
if (!b_vglInitialized) {
vglInitExtended(0, 960, 544, 8 * 1024 * 1024, SCE_GXM_MULTISAMPLE_NONE);
vglUseExtraMem(GL_FALSE);
vglSetSemanticBindingMode(VGL_MODE_GLOBAL);
b_vglInitialized = 1;
}
#endif
return OK;

#ifdef PVR_PSP2
_fail2:
eglDestroySurface(display, surface);
surface = NULL;
Expand All @@ -138,9 +169,11 @@ Error ContextEGL_Vita::initialize() {
display = NULL;
_fail0:
return ERR_UNCONFIGURED;
#endif
}

void ContextEGL_Vita::cleanup() {
#ifdef PVR_PSP2
if (display != EGL_NO_DISPLAY && surface != EGL_NO_SURFACE) {
eglDestroySurface(display, surface);
surface = EGL_NO_SURFACE;
Expand All @@ -155,6 +188,12 @@ void ContextEGL_Vita::cleanup() {
eglTerminate(display);
display = EGL_NO_DISPLAY;
}
#else
if (b_vglInitialized) {
b_vglInitialized = 0;
vglEnd();
}
#endif
}

ContextEGL_Vita::ContextEGL_Vita(bool gles) :
Expand Down
16 changes: 12 additions & 4 deletions platform/vita/context_egl_vita.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@
#include <psp2/types.h>

#include <EGL/egl.h> // EGL library

#ifdef PVR_PSP2
extern "C" {
#include <gpu_es4/psp2_pvr_hint.h>
}

#else
#define HAVE_GL_HEADERS
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2platform.h>
#include <vitaGL.h>
#endif
class ContextEGL_Vita {
#ifdef PVR_PSP2
Psp2NativeWindow window;

#endif
EGLDisplay display;
EGLContext context;
EGLSurface surface;
Expand All @@ -56,10 +63,11 @@ class ContextEGL_Vita {
bool gles2_context;

public:
#ifdef PVR_PSP2
void release_current();

void make_current();

#endif
int get_window_width();
int get_window_height();
void swap_buffers();
Expand Down
17 changes: 14 additions & 3 deletions platform/vita/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def configure(env):
"-DPOSH_OS_VITA",
'-DPOSH_OS_STRING=\\"vita\\"',
"-D__psp2__",
# "-DPVR_PSP2",
]
)

Expand Down Expand Up @@ -144,6 +145,16 @@ def configure(env):
env.Append(
LIBS=[
"dl",
"vitaGL",
"vitashark",
"SceShaccCgExt",
"SceShaccCg_stub",
"SceGxm_stub",
"mathneon",
"SceKernelDmacMgr_stub",
"SceRazorCapture_stub",
"SceRazorHud_stub",
"SceCommonDialog_stub",
"taihen_stub",
"SceLibKernel_stub",
"SceKernelThreadMgr_stub",
Expand All @@ -169,9 +180,9 @@ def configure(env):
"zstd",
"pcre2-32",
"theora",
"-llibgpu_es4_ext_stub.a",
"-llibIMGEGL_stub.a",
"-llibGLESv2_stub.a",
#"-llibgpu_es4_ext_stub.a",
#"-llibIMGEGL_stub.a",
#"-llibGLESv2_stub.a",
]
)
print(env.get("LIBS"))
7 changes: 6 additions & 1 deletion platform/vita/godot_vita.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <taihen.h>

#ifdef PVR_PSP2
#ifndef MEMORY_GRAPHICS_MB
#define MEMORY_GRAPHICS_MB 256 // Default Split, 256 Graphics/221 Main
#endif
Expand All @@ -48,9 +49,13 @@

int _newlib_heap_size_user = MEMORY_NEWLIB_MB * 1024 * 1024;
unsigned int sceLibcHeapSize = MEMORY_SCELIBC_MB * 1024 * 1024;
#else
int _newlib_heap_size_user = 256 * 1024 * 1024;
#endif

int main(int argc, char *argv[]) {
OS_Vita os;
#ifdef PVR_PSP2
char title_id[0xA];
char app_dir_path[0x100];
char app_kernel_module_path[0x100];
Expand All @@ -67,7 +72,7 @@ int main(int argc, char *argv[]) {
if (res < 0) {
sceClibPrintf("Failed to load kernel module: %08x\n", res);
}

#endif
scePowerSetArmClockFrequency(444);
scePowerSetBusClockFrequency(222);
scePowerSetGpuClockFrequency(222);
Expand Down

0 comments on commit c8ab7ce

Please sign in to comment.