From d4d00a35d77f8f3b4c37ffe4bf2fb29362f2eb68 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 16 Dec 2011 15:09:15 +0100 Subject: [PATCH 01/10] :v --- gfx/sdlwrap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gfx/sdlwrap.c b/gfx/sdlwrap.c index 9cab6d28c0..e276e633b8 100644 --- a/gfx/sdlwrap.c +++ b/gfx/sdlwrap.c @@ -62,13 +62,10 @@ void sdlwrap_set_swap_interval(unsigned interval, bool inited) #else static int (*glx_swap_interval)(int) = NULL; if (!glx_swap_interval) - { SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI"); - } if (!glx_swap_interval) - { SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalMESA"); - } + if (glx_swap_interval) glx_swap_interval(g_interval); else From 0181d97cae538a8f1f41140b4bd4dc5944587287 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 16 Dec 2011 16:02:30 +0100 Subject: [PATCH 02/10] Debork party. Untested. --- xenon/xenon360_video.c | 299 +++++++++++++++++------------------------ 1 file changed, 125 insertions(+), 174 deletions(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index 7266acb82a..5552c66d55 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -27,226 +27,178 @@ #include "driver.h" #include "general.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#define TEX_W 512 +#define TEX_H 512 -#define XE_W 1024 -#define XE_H 1024 - -#define UV_BOTTOM 0 -#define UV_TOP 1 -#define UV_LEFT 2 -#define UV_RIGHT 3 - -// pixel shader -const unsigned int g_xps_PS[] = +static const uint32_t g_PS[] = { - 0x102a1100, 0x000000b4, 0x0000003c, 0x00000000, 0x00000024, 0x00000000, - 0x0000008c, 0x00000000, 0x00000000, 0x00000064, 0x0000001c, 0x00000057, - 0xffff0300, 0x00000001, 0x0000001c, 0x00000000, 0x00000050, 0x00000030, - 0x00030000, 0x00010000, 0x00000040, 0x00000000, 0x54657874, 0x75726553, - 0x616d706c, 0x657200ab, 0x0004000c, 0x00010001, 0x00010000, 0x00000000, - 0x70735f33, 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, - 0x0000003c, 0x10000100, 0x00000008, 0x00000000, 0x00001842, 0x00010003, - 0x00000001, 0x00003050, 0x0000f1a0, 0x00011002, 0x00001200, 0xc4000000, - 0x00001003, 0x00002200, 0x00000000, 0x10081001, 0x1f1ff688, 0x00004000, - 0xc80f8000, 0x00000000, 0xe2010100, 0x00000000, 0x00000000, 0x00000000 + 0x102a1100, 0x000000b4, 0x0000003c, 0x00000000, 0x00000024, 0x00000000, + 0x0000008c, 0x00000000, 0x00000000, 0x00000064, 0x0000001c, 0x00000057, + 0xffff0300, 0x00000001, 0x0000001c, 0x00000000, 0x00000050, 0x00000030, + 0x00030000, 0x00010000, 0x00000040, 0x00000000, 0x54657874, 0x75726553, + 0x616d706c, 0x657200ab, 0x0004000c, 0x00010001, 0x00010000, 0x00000000, + 0x70735f33, 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, + 0x0000003c, 0x10000100, 0x00000008, 0x00000000, 0x00001842, 0x00010003, + 0x00000001, 0x00003050, 0x0000f1a0, 0x00011002, 0x00001200, 0xc4000000, + 0x00001003, 0x00002200, 0x00000000, 0x10081001, 0x1f1ff688, 0x00004000, + 0xc80f8000, 0x00000000, 0xe2010100, 0x00000000, 0x00000000, 0x00000000 }; -// vertex shader -const unsigned int g_xvs_VS[] = +static const uint32_t g_VS[] = { - 0x102a1101, 0x0000009c, 0x00000078, 0x00000000, 0x00000024, 0x00000000, - 0x00000058, 0x00000000, 0x00000000, 0x00000030, 0x0000001c, 0x00000023, - 0xfffe0300, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0x76735f33, - 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, 0x00000078, - 0x00110002, 0x00000000, 0x00000000, 0x00001842, 0x00000001, 0x00000003, - 0x00000002, 0x00000290, 0x00100003, 0x0000a004, 0x00305005, 0x00003050, - 0x0001f1a0, 0x00001007, 0x00001008, 0x70153003, 0x00001200, 0xc2000000, - 0x00001006, 0x00001200, 0xc4000000, 0x00002007, 0x00002200, 0x00000000, - 0x05f82000, 0x00000688, 0x00000000, 0x05f81000, 0x00000688, 0x00000000, - 0x05f80000, 0x00000fc8, 0x00000000, 0xc80f803e, 0x00000000, 0xe2020200, - 0xc8038000, 0x00b0b000, 0xe2000000, 0xc80f8001, 0x00000000, 0xe2010100, - 0x00000000, 0x00000000, 0x00000000 + 0x102a1101, 0x0000009c, 0x00000078, 0x00000000, 0x00000024, 0x00000000, + 0x00000058, 0x00000000, 0x00000000, 0x00000030, 0x0000001c, 0x00000023, + 0xfffe0300, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0x76735f33, + 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, 0x00000078, + 0x00110002, 0x00000000, 0x00000000, 0x00001842, 0x00000001, 0x00000003, + 0x00000002, 0x00000290, 0x00100003, 0x0000a004, 0x00305005, 0x00003050, + 0x0001f1a0, 0x00001007, 0x00001008, 0x70153003, 0x00001200, 0xc2000000, + 0x00001006, 0x00001200, 0xc4000000, 0x00002007, 0x00002200, 0x00000000, + 0x05f82000, 0x00000688, 0x00000000, 0x05f81000, 0x00000688, 0x00000000, + 0x05f80000, 0x00000fc8, 0x00000000, 0xc80f803e, 0x00000000, 0xe2020200, + 0xc8038000, 0x00b0b000, 0xe2000000, 0xc80f8001, 0x00000000, 0xe2010100, + 0x00000000, 0x00000000, 0x00000000 }; -typedef struct DrawVerticeFormats +struct Vertex { - float x, y, z, w; - unsigned int color; - float u, v; -} DrawVerticeFormats; - -typedef struct xenon360_video xenon360_video_t; + float x, y, z, w; + uint32_t color; + float u, v; +}; static bool g_quitting; -typedef struct gl +typedef struct xe { - unsigned char *screen; + struct XenosDevice dev; struct XenosVertexBuffer *vb; - struct XenosDevice * gl_device; - struct XenosDevice real_device; - struct XenosShader * g_pVertexShader; - struct XenosShader * g_pPixelTexturedShader; - struct XenosSurface * g_pTexture; + struct XenosShader *vertex_shader; + struct XenosShader *pixel_shader; + struct XenosSurface *tex; unsigned frame_count; -} gl_t; - -static float ScreenUv[4] = {0.f, 1.0f, 1.0f, 0.f}; +} xe_t; static void xenon360_gfx_free(void *data) { - gl_t *vid = data; + xe_t *vid = data; if (!vid) return; + // FIXME: Proper deinitialization of device resources. + free(vid); } -static void *xenon360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) +static void init_vertex(xe_t *xe) { - gl_t * gl = calloc(1, sizeof(gl_t)); - if (!gl) - return NULL; + xe->vb = Xe_CreateVertexBuffer(&xe->dev, 4 * sizeof(struct Vertex)); + struct Vertex *rect = Xe_VB_Lock(&xe->dev, xe->vb, 0, 4 * sizeof(struct Vertex), XE_LOCK_WRITE); - gl->gl_device = &gl->real_device; + rect[0].x = -1.0; + rect[0].y = -1.0; + rect[0].u = 0.0; + rect[0].v = 0.0; + rect[0].color = 0; - Xe_Init(gl->gl_device); + rect[1].x = 1.0; + rect[1].y = -1.0; + rect[1].u = 1.0; + rect[1].v = 1.0; + rect[1].color = 0; - Xe_SetRenderTarget(gl->gl_device, Xe_GetFramebufferSurface(gl->gl_device)); + rect[2].x = 1.0; + rect[2].y = 1.0; + rect[2].u = 1.0; + rect[2].v = 1.0; + rect[2].color = 0; - static const struct XenosVBFFormat vbf = + rect[3].x = -1.0; + rect[3].y = 1.0; + rect[3].u = 0.0; + rect[3].v = 1.0; + rect[3].color = 0; + + for (unsigned i = 0; i < 3; i++) { - 3, - { - {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4}, - {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, - {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, - } - }; - - gl->g_pPixelTexturedShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xps_PS); - Xe_InstantiateShader(gl->gl_device, gl->g_pPixelTexturedShader, 0); - - gl->g_pVertexShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xvs_VS); - Xe_InstantiateShader(gl->gl_device, gl->g_pVertexShader, 0); - Xe_ShaderApplyVFetchPatches(gl->gl_device, gl->g_pVertexShader, 0, &vbf); - - edram_init(gl->gl_device); - - - // enable filtering for now - - float x = -1.0f; - float y = 1.0f; - float w = 4.0f; - float h = 4.0f; - - gl->vb = Xe_CreateVertexBuffer(gl->gl_device, 3 * sizeof(DrawVerticeFormats)); - DrawVerticeFormats *Rect = Xe_VB_Lock(gl->gl_device, gl->vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE); - - ScreenUv[UV_TOP] = ScreenUv[UV_TOP] * 2; - ScreenUv[UV_LEFT] = ScreenUv[UV_LEFT] * 2; - - // top left - Rect[0].x = x; - Rect[0].y = y; - Rect[0].u = ScreenUv[UV_BOTTOM]; - Rect[0].v = ScreenUv[UV_RIGHT]; - Rect[0].color = 0; - - // bottom left - Rect[1].x = x; - Rect[1].y = y - h; - Rect[1].u = ScreenUv[UV_BOTTOM]; - Rect[1].v = ScreenUv[UV_LEFT]; - Rect[1].color = 0; - - // top right - Rect[2].x = x + w; - Rect[2].y = y; - Rect[2].u = ScreenUv[UV_TOP]; - Rect[2].v = ScreenUv[UV_RIGHT]; - Rect[2].color = 0; - - Rect[3].x = x + w; - Rect[3].y = y; - Rect[3].u = ScreenUv[UV_TOP]; - Rect[3].v = ScreenUv[UV_RIGHT]; - Rect[3].color = 0; - - int i = 0; - for (i = 0; i < 3; i++) - { - Rect[i].z = 0.0; - Rect[i].w = 1.0; + rect[i].z = 0.0; + rect[i].w = 1.0; } - Xe_VB_Unlock(gl->gl_device, gl->vb); - - Xe_SetClearColor(gl->gl_device, 0); - - return gl; + Xe_VB_Unlock(&xe->dev, xe->vb); } -static bool xenon360_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) +static void *xenon360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - gl_t *vid = data; + xe_t *xe = calloc(1, sizeof(*xe)); + if (!xe) + return NULL; - vid->frame_count++; + Xe_Init(&xe->dev); + Xe_SetRenderTarget(&xe->dev, Xe_GetFramebufferSurface(&xe->dev)); + init_vertex(xe); - // update texture viewport - static unsigned old_width = 0; - static unsigned old_height = 0; + static const struct XenosVBFFormat vbf = { + 3, + { + { XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4 }, + { XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4 }, + { XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2 }, + }, + }; - ScreenUv[UV_TOP] = ((float) (width) / (float) XE_W)*2; - ScreenUv[UV_LEFT] = ((float) (height) / (float) XE_H)*2; + xe->pixel_shader = Xe_LoadShaderFromMemory(&xe->dev, (void*)g_PS); + Xe_InstantiateShader(&xe->dev, xe->pixel_shader, 0); - DrawVerticeFormats * Rect = Xe_VB_Lock(vid->gl_device, vid->vb, 0, 3 * sizeof(DrawVerticeFormats), XE_LOCK_WRITE); + xe->vertex_shader = Xe_LoadShaderFromMemory(&xe->dev, (void*)g_VS); + Xe_InstantiateShader(&xe->dev, xe->vertex_shader, 0); + Xe_ShaderApplyVFetchPatches(&xe->dev, xe->vertex_shader, 0, &vbf); - // bottom left - Rect[1].v = ScreenUv[UV_LEFT]; - Rect[2].u = ScreenUv[UV_TOP]; + Xe_SetShader(&xe->dev, SHADER_TYPE_PIXEL, xe->pixel_shader, 0); + Xe_SetShader(&xe->dev, SHADER_TYPE_VERTEX, xe->vertex_shader, 0); + edram_init(&xe->dev); - Xe_VB_Unlock(vid->gl_device, vid->vb); + Xe_SetClearColor(&xe->dev, 0); - old_width = width; - old_height = height; + xe->tex = Xe_CreateTexture(&xe->dev, TEX_W, TEX_H, 1, XE_FMT_5551, 0); + xe->tex->use_filtering = true; + Xe_SetTexture(&xe->dev, 0, xe->tex); - // Refresh texture cache - vid->g_pTexture = Xe_CreateTexture(vid->gl_device, XE_W, XE_H, 1, XE_FMT_5551, 0); - vid->g_pTexture->use_filtering = 1; - uint16_t *dst = Xe_Surface_LockRect(vid->gl_device, vid->g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); + Xe_SetClearColor(&xe->dev, 0); + Xe_SetCullMode(&xe->dev, XE_CULL_NONE); + Xe_SetStreamSource(&xe->dev, 0, xe->vb, 0, sizeof(struct Vertex)); + + return xe; +} + +static bool xenon360_gfx_frame(void *data, const void *frame, + unsigned width, unsigned height, unsigned pitch, + const char *msg) +{ + xe_t *xe = data; + xe->frame_count++; + + //struct Vertex *rect = Xe_VB_Lock(vid->xe_device, vid->vb, 0, 4 * sizeof(struct Vertex), XE_LOCK_WRITE); + // FIXME: Proper UV handling goes here later. + //Xe_VB_Unlock(&xe->dev, xe->vb); + + uint16_t *dst = Xe_Surface_LockRect(&xe->dev, xe->tex, 0, 0, 0, 0, XE_LOCK_WRITE); const uint16_t *src = frame; - unsigned stride_in = pitch >>1; - unsigned stride_out = vid->g_pTexture->wpitch >> 1; - unsigned copy_size =width << 1; + unsigned stride_in = pitch >> 1; + unsigned stride_out = xe->tex->wpitch >> 1; + unsigned copy_size = width << 1; + for (unsigned y = 0; y < height; y++, dst += stride_out, src += stride_in) - memcpy(dst, src, copy_size); - Xe_Surface_Unlock(vid->gl_device, vid->g_pTexture); + memcpy(dst, src, copy_size); - // Reset states - Xe_InvalidateState(vid->gl_device); - Xe_SetClearColor(vid->gl_device, 0); + Xe_Surface_Unlock(&xe->dev, xe->tex); + Xe_InvalidateState(&xe->dev); + + Xe_DrawPrimitive(&xe->dev, XE_PRIMTYPE_TRIANGLESTRIP, 0, 2); - // Select stream - Xe_SetTexture(vid->gl_device, 0, vid->g_pTexture); - Xe_SetCullMode(vid->gl_device, XE_CULL_NONE); - Xe_SetStreamSource(vid->gl_device, 0, vid->vb, 0, sizeof(DrawVerticeFormats)); - - // Select shaders - Xe_SetShader(vid->gl_device, SHADER_TYPE_PIXEL, vid->g_pPixelTexturedShader, 0); - Xe_SetShader(vid->gl_device, SHADER_TYPE_VERTEX, vid->g_pVertexShader, 0); - - // Draw - Xe_DrawPrimitive(vid->gl_device, XE_PRIMTYPE_TRIANGLELIST, 0, 1); - - // Resolve - Xe_Resolve(vid->gl_device); - Xe_Sync(vid->gl_device); + Xe_Resolve(&xe->dev); + Xe_Sync(&xe->dev); return true; } @@ -269,7 +221,6 @@ static bool xenon360_gfx_focus(void *data) return true; } - const video_driver_t video_xenon360 = { .init = xenon360_gfx_init, .frame = xenon360_gfx_frame, From 99497e21cfb3321f30f9a95d1c9b872d9f67e770 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 16 Dec 2011 16:21:58 +0100 Subject: [PATCH 03/10] Minor fix. --- xenon/xenon360_video.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index 5552c66d55..8d132eca69 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -107,15 +107,15 @@ static void init_vertex(xe_t *xe) rect[1].v = 1.0; rect[1].color = 0; - rect[2].x = 1.0; + rect[2].x = -1.0; rect[2].y = 1.0; - rect[2].u = 1.0; + rect[2].u = 0.0; rect[2].v = 1.0; rect[2].color = 0; - rect[3].x = -1.0; + rect[3].x = 1.0; rect[3].y = 1.0; - rect[3].u = 0.0; + rect[3].u = 1.0; rect[3].v = 1.0; rect[3].color = 0; From 6336fb4a1befc8844489feddcd83abbefeb0d2dc Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 16 Dec 2011 16:26:44 +0100 Subject: [PATCH 04/10] ... --- xenon/xenon360_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index 8d132eca69..6bf0121ffa 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -119,7 +119,7 @@ static void init_vertex(xe_t *xe) rect[3].v = 1.0; rect[3].color = 0; - for (unsigned i = 0; i < 3; i++) + for (unsigned i = 0; i < 4; i++) { rect[i].z = 0.0; rect[i].w = 1.0; From 5ed0d00249022762e42173c8f691454556aee0e9 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 16 Dec 2011 16:38:25 +0100 Subject: [PATCH 05/10] Try some stuff. --- xenon/xenon360_video.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index 6bf0121ffa..da80715f93 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -183,6 +183,8 @@ static bool xenon360_gfx_frame(void *data, const void *frame, // FIXME: Proper UV handling goes here later. //Xe_VB_Unlock(&xe->dev, xe->vb); + Xe_InvalidateState(&xe->dev); + uint16_t *dst = Xe_Surface_LockRect(&xe->dev, xe->tex, 0, 0, 0, 0, XE_LOCK_WRITE); const uint16_t *src = frame; unsigned stride_in = pitch >> 1; @@ -193,10 +195,10 @@ static bool xenon360_gfx_frame(void *data, const void *frame, memcpy(dst, src, copy_size); Xe_Surface_Unlock(&xe->dev, xe->tex); - Xe_InvalidateState(&xe->dev); Xe_DrawPrimitive(&xe->dev, XE_PRIMTYPE_TRIANGLESTRIP, 0, 2); + Xe_SetClearColor(&xe->dev, 0); Xe_Resolve(&xe->dev); Xe_Sync(&xe->dev); From 44ad016b918f2bdb82971d7c7874538ce3fc53d7 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Fri, 16 Dec 2011 17:09:33 +0100 Subject: [PATCH 06/10] (Libxenon) Revert to Xenos driver that works - current issues - colors are wrong (doing | XE_FMT_ARGB produces 'distorted' graphics but right colors) - no vsync (doing while Xe_IsVBlank(device) Xe_Sync(device) makes everything too slow --- xenon/xenon360_video.c | 302 ++++++++++++++++++++++++----------------- 1 file changed, 175 insertions(+), 127 deletions(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index da80715f93..2cc0490a54 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -27,180 +27,227 @@ #include "driver.h" #include "general.h" -#define TEX_W 512 -#define TEX_H 512 +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -static const uint32_t g_PS[] = +#define XE_W 1024 +#define XE_H 1024 + +#define UV_BOTTOM 0 +#define UV_TOP 1 +#define UV_LEFT 2 +#define UV_RIGHT 3 + +// pixel shader +const unsigned int g_xps_PS[] = { - 0x102a1100, 0x000000b4, 0x0000003c, 0x00000000, 0x00000024, 0x00000000, - 0x0000008c, 0x00000000, 0x00000000, 0x00000064, 0x0000001c, 0x00000057, - 0xffff0300, 0x00000001, 0x0000001c, 0x00000000, 0x00000050, 0x00000030, - 0x00030000, 0x00010000, 0x00000040, 0x00000000, 0x54657874, 0x75726553, - 0x616d706c, 0x657200ab, 0x0004000c, 0x00010001, 0x00010000, 0x00000000, - 0x70735f33, 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, - 0x0000003c, 0x10000100, 0x00000008, 0x00000000, 0x00001842, 0x00010003, - 0x00000001, 0x00003050, 0x0000f1a0, 0x00011002, 0x00001200, 0xc4000000, - 0x00001003, 0x00002200, 0x00000000, 0x10081001, 0x1f1ff688, 0x00004000, - 0xc80f8000, 0x00000000, 0xe2010100, 0x00000000, 0x00000000, 0x00000000 + 0x102a1100, 0x000000b4, 0x0000003c, 0x00000000, 0x00000024, 0x00000000, + 0x0000008c, 0x00000000, 0x00000000, 0x00000064, 0x0000001c, 0x00000057, + 0xffff0300, 0x00000001, 0x0000001c, 0x00000000, 0x00000050, 0x00000030, + 0x00030000, 0x00010000, 0x00000040, 0x00000000, 0x54657874, 0x75726553, + 0x616d706c, 0x657200ab, 0x0004000c, 0x00010001, 0x00010000, 0x00000000, + 0x70735f33, 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, + 0x0000003c, 0x10000100, 0x00000008, 0x00000000, 0x00001842, 0x00010003, + 0x00000001, 0x00003050, 0x0000f1a0, 0x00011002, 0x00001200, 0xc4000000, + 0x00001003, 0x00002200, 0x00000000, 0x10081001, 0x1f1ff688, 0x00004000, + 0xc80f8000, 0x00000000, 0xe2010100, 0x00000000, 0x00000000, 0x00000000 }; -static const uint32_t g_VS[] = +// vertex shader +const unsigned int g_xvs_VS[] = { - 0x102a1101, 0x0000009c, 0x00000078, 0x00000000, 0x00000024, 0x00000000, - 0x00000058, 0x00000000, 0x00000000, 0x00000030, 0x0000001c, 0x00000023, - 0xfffe0300, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0x76735f33, - 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, 0x00000078, - 0x00110002, 0x00000000, 0x00000000, 0x00001842, 0x00000001, 0x00000003, - 0x00000002, 0x00000290, 0x00100003, 0x0000a004, 0x00305005, 0x00003050, - 0x0001f1a0, 0x00001007, 0x00001008, 0x70153003, 0x00001200, 0xc2000000, - 0x00001006, 0x00001200, 0xc4000000, 0x00002007, 0x00002200, 0x00000000, - 0x05f82000, 0x00000688, 0x00000000, 0x05f81000, 0x00000688, 0x00000000, - 0x05f80000, 0x00000fc8, 0x00000000, 0xc80f803e, 0x00000000, 0xe2020200, - 0xc8038000, 0x00b0b000, 0xe2000000, 0xc80f8001, 0x00000000, 0xe2010100, - 0x00000000, 0x00000000, 0x00000000 + 0x102a1101, 0x0000009c, 0x00000078, 0x00000000, 0x00000024, 0x00000000, + 0x00000058, 0x00000000, 0x00000000, 0x00000030, 0x0000001c, 0x00000023, + 0xfffe0300, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0x76735f33, + 0x5f300032, 0x2e302e32, 0x30333533, 0x2e3000ab, 0x00000000, 0x00000078, + 0x00110002, 0x00000000, 0x00000000, 0x00001842, 0x00000001, 0x00000003, + 0x00000002, 0x00000290, 0x00100003, 0x0000a004, 0x00305005, 0x00003050, + 0x0001f1a0, 0x00001007, 0x00001008, 0x70153003, 0x00001200, 0xc2000000, + 0x00001006, 0x00001200, 0xc4000000, 0x00002007, 0x00002200, 0x00000000, + 0x05f82000, 0x00000688, 0x00000000, 0x05f81000, 0x00000688, 0x00000000, + 0x05f80000, 0x00000fc8, 0x00000000, 0xc80f803e, 0x00000000, 0xe2020200, + 0xc8038000, 0x00b0b000, 0xe2000000, 0xc80f8001, 0x00000000, 0xe2010100, + 0x00000000, 0x00000000, 0x00000000 }; -struct Vertex +typedef struct DrawVerticeFormats { - float x, y, z, w; - uint32_t color; - float u, v; -}; + float x, y, z, w; + unsigned int color; + float u, v; +} DrawVerticeFormats; + +typedef struct xenon360_video xenon360_video_t; static bool g_quitting; -typedef struct xe +typedef struct gl { - struct XenosDevice dev; + unsigned char *screen; struct XenosVertexBuffer *vb; - struct XenosShader *vertex_shader; - struct XenosShader *pixel_shader; - struct XenosSurface *tex; + struct XenosDevice * gl_device; + struct XenosDevice real_device; + struct XenosShader * g_pVertexShader; + struct XenosShader * g_pPixelTexturedShader; + struct XenosSurface * g_pTexture; unsigned frame_count; -} xe_t; +} gl_t; + +static float ScreenUv[4] = {0.f, 1.0f, 1.0f, 0.f}; static void xenon360_gfx_free(void *data) { - xe_t *vid = data; + gl_t *vid = data; if (!vid) return; - // FIXME: Proper deinitialization of device resources. - free(vid); } -static void init_vertex(xe_t *xe) -{ - xe->vb = Xe_CreateVertexBuffer(&xe->dev, 4 * sizeof(struct Vertex)); - struct Vertex *rect = Xe_VB_Lock(&xe->dev, xe->vb, 0, 4 * sizeof(struct Vertex), XE_LOCK_WRITE); - - rect[0].x = -1.0; - rect[0].y = -1.0; - rect[0].u = 0.0; - rect[0].v = 0.0; - rect[0].color = 0; - - rect[1].x = 1.0; - rect[1].y = -1.0; - rect[1].u = 1.0; - rect[1].v = 1.0; - rect[1].color = 0; - - rect[2].x = -1.0; - rect[2].y = 1.0; - rect[2].u = 0.0; - rect[2].v = 1.0; - rect[2].color = 0; - - rect[3].x = 1.0; - rect[3].y = 1.0; - rect[3].u = 1.0; - rect[3].v = 1.0; - rect[3].color = 0; - - for (unsigned i = 0; i < 4; i++) - { - rect[i].z = 0.0; - rect[i].w = 1.0; - } - - Xe_VB_Unlock(&xe->dev, xe->vb); -} - static void *xenon360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - xe_t *xe = calloc(1, sizeof(*xe)); - if (!xe) + gl_t * gl = calloc(1, sizeof(gl_t)); + if (!gl) return NULL; - Xe_Init(&xe->dev); - Xe_SetRenderTarget(&xe->dev, Xe_GetFramebufferSurface(&xe->dev)); + gl->gl_device = &gl->real_device; - init_vertex(xe); + Xe_Init(gl->gl_device); - static const struct XenosVBFFormat vbf = { - 3, - { - { XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4 }, - { XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4 }, - { XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2 }, - }, + Xe_SetRenderTarget(gl->gl_device, Xe_GetFramebufferSurface(gl->gl_device)); + + static const struct XenosVBFFormat vbf = + { + 3, + { + {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4}, + {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, + {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, + } }; - xe->pixel_shader = Xe_LoadShaderFromMemory(&xe->dev, (void*)g_PS); - Xe_InstantiateShader(&xe->dev, xe->pixel_shader, 0); + gl->g_pPixelTexturedShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xps_PS); + Xe_InstantiateShader(gl->gl_device, gl->g_pPixelTexturedShader, 0); - xe->vertex_shader = Xe_LoadShaderFromMemory(&xe->dev, (void*)g_VS); - Xe_InstantiateShader(&xe->dev, xe->vertex_shader, 0); - Xe_ShaderApplyVFetchPatches(&xe->dev, xe->vertex_shader, 0, &vbf); + gl->g_pVertexShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xvs_VS); + Xe_InstantiateShader(gl->gl_device, gl->g_pVertexShader, 0); + Xe_ShaderApplyVFetchPatches(gl->gl_device, gl->g_pVertexShader, 0, &vbf); - Xe_SetShader(&xe->dev, SHADER_TYPE_PIXEL, xe->pixel_shader, 0); - Xe_SetShader(&xe->dev, SHADER_TYPE_VERTEX, xe->vertex_shader, 0); - edram_init(&xe->dev); + gl->g_pTexture = Xe_CreateTexture(gl->gl_device, XE_W, XE_H, 1, XE_FMT_5551, 0); + gl->g_pTexture->use_filtering = 1; - Xe_SetClearColor(&xe->dev, 0); + edram_init(gl->gl_device); - xe->tex = Xe_CreateTexture(&xe->dev, TEX_W, TEX_H, 1, XE_FMT_5551, 0); - xe->tex->use_filtering = true; - Xe_SetTexture(&xe->dev, 0, xe->tex); - Xe_SetClearColor(&xe->dev, 0); - Xe_SetCullMode(&xe->dev, XE_CULL_NONE); - Xe_SetStreamSource(&xe->dev, 0, xe->vb, 0, sizeof(struct Vertex)); + // enable filtering for now - return xe; + float x = -1.0f; + float y = 1.0f; + float w = 4.0f; + float h = 4.0f; + + gl->vb = Xe_CreateVertexBuffer(gl->gl_device, 3 * sizeof(DrawVerticeFormats)); + DrawVerticeFormats *Rect = Xe_VB_Lock(gl->gl_device, gl->vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE); + + ScreenUv[UV_TOP] = ScreenUv[UV_TOP] * 2; + ScreenUv[UV_LEFT] = ScreenUv[UV_LEFT] * 2; + + // top left + Rect[0].x = x; + Rect[0].y = y; + Rect[0].u = ScreenUv[UV_BOTTOM]; + Rect[0].v = ScreenUv[UV_RIGHT]; + Rect[0].color = 0; + + // bottom left + Rect[1].x = x; + Rect[1].y = y - h; + Rect[1].u = ScreenUv[UV_BOTTOM]; + Rect[1].v = ScreenUv[UV_LEFT]; + Rect[1].color = 0; + + // top right + Rect[2].x = x + w; + Rect[2].y = y; + Rect[2].u = ScreenUv[UV_TOP]; + Rect[2].v = ScreenUv[UV_RIGHT]; + Rect[2].color = 0; + + Rect[3].x = x + w; + Rect[3].y = y; + Rect[3].u = ScreenUv[UV_TOP]; + Rect[3].v = ScreenUv[UV_RIGHT]; + Rect[3].color = 0; + + int i = 0; + for (i = 0; i < 3; i++) + { + Rect[i].z = 0.0; + Rect[i].w = 1.0; + } + + Xe_VB_Unlock(gl->gl_device, gl->vb); + + Xe_SetClearColor(gl->gl_device, 0); + + return gl; } -static bool xenon360_gfx_frame(void *data, const void *frame, - unsigned width, unsigned height, unsigned pitch, - const char *msg) +static bool xenon360_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { - xe_t *xe = data; - xe->frame_count++; + gl_t *vid = data; - //struct Vertex *rect = Xe_VB_Lock(vid->xe_device, vid->vb, 0, 4 * sizeof(struct Vertex), XE_LOCK_WRITE); - // FIXME: Proper UV handling goes here later. - //Xe_VB_Unlock(&xe->dev, xe->vb); + vid->frame_count++; - Xe_InvalidateState(&xe->dev); - uint16_t *dst = Xe_Surface_LockRect(&xe->dev, xe->tex, 0, 0, 0, 0, XE_LOCK_WRITE); + // update texture viewport + static unsigned old_width = 0; + static unsigned old_height = 0; + + ScreenUv[UV_TOP] = ((float) (width) / (float) XE_W)*2; + ScreenUv[UV_LEFT] = ((float) (height) / (float) XE_H)*2; + + DrawVerticeFormats * Rect = Xe_VB_Lock(vid->gl_device, vid->vb, 0, 3 * sizeof(DrawVerticeFormats), XE_LOCK_WRITE); + + // bottom left + Rect[1].v = ScreenUv[UV_LEFT]; + Rect[2].u = ScreenUv[UV_TOP]; + + Xe_VB_Unlock(vid->gl_device, vid->vb); + + old_width = width; + old_height = height; + + // Refresh texture cache + uint16_t *dst = Xe_Surface_LockRect(vid->gl_device, vid->g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); const uint16_t *src = frame; - unsigned stride_in = pitch >> 1; - unsigned stride_out = xe->tex->wpitch >> 1; - unsigned copy_size = width << 1; - + unsigned stride_in = pitch >>1; + unsigned stride_out = vid->g_pTexture->wpitch >> 1; + unsigned copy_size =width << 1; for (unsigned y = 0; y < height; y++, dst += stride_out, src += stride_in) - memcpy(dst, src, copy_size); + memcpy(dst, src, copy_size); + Xe_Surface_Unlock(vid->gl_device, vid->g_pTexture); - Xe_Surface_Unlock(&xe->dev, xe->tex); - - Xe_DrawPrimitive(&xe->dev, XE_PRIMTYPE_TRIANGLESTRIP, 0, 2); + // Reset states + Xe_InvalidateState(vid->gl_device); + Xe_SetClearColor(vid->gl_device, 0); - Xe_SetClearColor(&xe->dev, 0); - Xe_Resolve(&xe->dev); - Xe_Sync(&xe->dev); + // Select stream + Xe_SetTexture(vid->gl_device, 0, vid->g_pTexture); + Xe_SetCullMode(vid->gl_device, XE_CULL_NONE); + Xe_SetStreamSource(vid->gl_device, 0, vid->vb, 0, sizeof(DrawVerticeFormats)); + + // Select shaders + Xe_SetShader(vid->gl_device, SHADER_TYPE_PIXEL, vid->g_pPixelTexturedShader, 0); + Xe_SetShader(vid->gl_device, SHADER_TYPE_VERTEX, vid->g_pVertexShader, 0); + + // Draw + Xe_DrawPrimitive(vid->gl_device, XE_PRIMTYPE_TRIANGLELIST, 0, 1); + + // Resolve + Xe_Resolve(vid->gl_device); + Xe_Sync(vid->gl_device); return true; } @@ -223,6 +270,7 @@ static bool xenon360_gfx_focus(void *data) return true; } + const video_driver_t video_xenon360 = { .init = xenon360_gfx_init, .frame = xenon360_gfx_frame, From 034c7c70fbce4de6901409a80ef2bfd5f320b5f4 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Fri, 16 Dec 2011 17:22:37 +0100 Subject: [PATCH 07/10] (Libxenon) Fixed colors --- xenon/xenon360_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index 2cc0490a54..ed1708a95d 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -134,7 +134,7 @@ static void *xenon360_gfx_init(const video_info_t *video, const input_driver_t * Xe_InstantiateShader(gl->gl_device, gl->g_pVertexShader, 0); Xe_ShaderApplyVFetchPatches(gl->gl_device, gl->g_pVertexShader, 0, &vbf); - gl->g_pTexture = Xe_CreateTexture(gl->gl_device, XE_W, XE_H, 1, XE_FMT_5551, 0); + gl->g_pTexture = Xe_CreateTexture(gl->gl_device, XE_W, XE_H, 1, XE_FMT_5551 | XE_FMT_16BE, 0); gl->g_pTexture->use_filtering = 1; edram_init(gl->gl_device); From cbfdc9cf97f6bf9bc809c255733b8c3af9f24e2e Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Fri, 16 Dec 2011 18:54:12 +0100 Subject: [PATCH 08/10] (Libxenon) Changed texture size to 512x512 - stop libxenon development for now - no double buffering/triple buffering available - return to it when it's more mature --- xenon/xenon360_video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xenon/xenon360_video.c b/xenon/xenon360_video.c index ed1708a95d..fdd8369569 100644 --- a/xenon/xenon360_video.c +++ b/xenon/xenon360_video.c @@ -31,8 +31,8 @@ #include "config.h" #endif -#define XE_W 1024 -#define XE_H 1024 +#define XE_W 512 +#define XE_H 512 #define UV_BOTTOM 0 #define UV_TOP 1 From eff4fcecae09cba2a2b83df4fb0279489f8ef9e9 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 18 Dec 2011 13:27:06 +0100 Subject: [PATCH 09/10] Some additions, but still broken. --- wii/input.c | 2 +- wii/video.c | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/wii/input.c b/wii/input.c index 1d64bb329b..eac154acf9 100644 --- a/wii/input.c +++ b/wii/input.c @@ -98,7 +98,7 @@ static bool wii_key_pressed(void *data, int key) switch (key) { case SSNES_QUIT_KEY: - return g_quit; + return g_quit || pad_state[0][SNES_DEVICE_ID_JOYPAD_START]; default: return false; } diff --git a/wii/video.c b/wii/video.c index 18260c1405..70c1214f5b 100644 --- a/wii/video.c +++ b/wii/video.c @@ -78,6 +78,7 @@ static void init_vtx(GXRModeObj *mode) GX_SetDispCopyDst(mode->fbWidth, mode->xfbHeight); GX_SetCopyFilter(mode->aa, mode->sample_pattern, (mode->xfbMode == VI_XFBMODE_SF) ? GX_FALSE : GX_TRUE, mode->vfilter); + GX_SetCopyClear((GXColor) { 0, 0, 0, 0xff }, GX_MAX_Z24); GX_SetFieldMode(mode->field_rendering, (mode->viHeight == 2 * mode->xfbHeight) ? GX_ENABLE : GX_DISABLE); GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); @@ -107,10 +108,10 @@ static void init_vtx(GXRModeObj *mode) GX_Flush(); } -static void init_texture(void) +static void init_texture(unsigned width, unsigned height) { - GX_InitTexObj(&g_tex.obj, g_tex.data, 512, 512, GX_TF_RGB565, GX_MIRROR, GX_MIRROR, GX_FALSE); - GX_InitTexObjLOD(&g_tex.obj, GX_LINEAR, GX_LINEAR, 0, 10, 0, GX_TRUE, GX_FALSE, GX_ANISO_1); + GX_InitTexObj(&g_tex.obj, g_tex.data, width, height, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); + GX_InitTexObjLOD(&g_tex.obj, GX_NEAR, GX_NEAR, 0, 0, 0, GX_TRUE, GX_FALSE, GX_ANISO_1); GX_LoadTexObj(&g_tex.obj, GX_TEXMAP0); GX_InvalidateTexAll(); } @@ -142,7 +143,6 @@ static void *wii_init(const video_info_t *video, GX_SetClipMode(GX_CLIP_DISABLE); init_vtx(mode); - init_texture(); build_disp_list(); *input = NULL; @@ -153,23 +153,14 @@ static void *wii_init(const video_info_t *video, static void update_texture(const uint16_t *src, unsigned width, unsigned height, unsigned pitch) { - width <<= 1; pitch >>= 1; - float tex_w = (float)width / 512; - float tex_h = (float)height / 512; - - tex_coords[4] = tex_w; - tex_coords[6] = tex_w; - tex_coords[3] = tex_h; - tex_coords[5] = tex_h; + // Pitch is totally broken. No idea why. uint16_t *dst = g_tex.data; - for (unsigned i = 0; i < height; i++, dst += 512, src += pitch) - memcpy(dst, src, width); + for (unsigned i = 0; i < height; i++, dst += width, src += pitch) + memcpy(dst, src, width << 1); - DCFlushRange(tex_coords, sizeof(tex_coords)); - GX_InvVtxCache(); - + init_texture(width, height); DCFlushRange(g_tex.data, sizeof(g_tex.data)); GX_InvalidateTexAll(); } @@ -181,15 +172,14 @@ static bool wii_frame(void *data, const void *frame, (void)data; (void)msg; - GX_SetCopyClear((GXColor) { 0, 0, 0, 0xff }, GX_MAX_Z24); - update_texture(frame, width, height, pitch); GX_CallDispList(display_list, display_list_size); GX_DrawDone(); - GX_Flush(); g_framebuf_index ^= 1; GX_CopyDisp(g_framebuf[g_framebuf_index], GX_TRUE); + GX_Flush(); + VIDEO_SetNextFramebuffer(g_framebuf[g_framebuf_index]); VIDEO_Flush(); //VIDEO_WaitVSync(); From f9d4bbf4d3f0e3491163e7c9ddefbd57672c3e25 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 19 Dec 2011 01:27:04 +0100 Subject: [PATCH 10/10] Fix endian issues and strict aliasing. --- sha256.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/sha256.c b/sha256.c index 0830f2eac3..d47b82adb0 100644 --- a/sha256.c +++ b/sha256.c @@ -18,12 +18,11 @@ // SHA256 implementation from bSNES. Written by valditx. // +#include "general.h" #include "sha256.h" #include #include -#define PTR(t, a) ((t*)(a)) - #define SWAP32(x) ((uint32_t)( \ (((uint32_t)(x) & 0x000000ff) << 24) | \ (((uint32_t)(x) & 0x0000ff00) << 8) | \ @@ -31,11 +30,25 @@ (((uint32_t)(x) & 0xff000000) >> 24) \ )) -#define ST32(a, d) *PTR(uint32_t, a) = (d) -#define ST32BE(a, d) ST32(a, SWAP32(d)) +static inline void store32le(uint32_t *addr, uint32_t data) +{ + *addr = is_little_endian() ? data : SWAP32(data); +} -#define LD32(a) *PTR(uint32_t, a) -#define LD32BE(a) SWAP32(LD32(a)) +static inline void store32be(uint32_t *addr, uint32_t data) +{ + *addr = is_little_endian() ? SWAP32(data) : data; +} + +static inline uint32_t load32le(const uint32_t *addr) +{ + return is_little_endian() ? *addr : SWAP32(*addr); +} + +static inline uint32_t load32be(const uint32_t *addr) +{ + return is_little_endian() ? SWAP32(*addr) : *addr; +} #define LSL32(x, n) ((uint32_t)(x) << (n)) #define LSR32(x, n) ((uint32_t)(x) >> (n)) @@ -60,7 +73,11 @@ static const uint32_t T_K[64] = { struct sha256_ctx { - uint8_t in[64]; + union + { + uint8_t u8[64]; + uint32_t u32[16]; + } in; unsigned inlen; uint32_t w[64]; @@ -82,7 +99,7 @@ static void sha256_block(struct sha256_ctx *p) uint32_t t1, t2, maj, ch; for (i = 0; i < 16; i++) - p->w[i] = LD32BE(p->in + i * 4); + p->w[i] = load32be(p->in.u32 + i); for (i = 16; i < 64; i++) { @@ -124,7 +141,7 @@ static void sha256_chunk(struct sha256_ctx *p, const uint8_t *s, unsigned len) l = 64 - p->inlen; l = (len < l) ? len : l; - memcpy(p->in + p->inlen, s, l); + memcpy(p->in.u8 + p->inlen, s, l); s += l; p->inlen += l; len -= l; @@ -137,26 +154,26 @@ static void sha256_chunk(struct sha256_ctx *p, const uint8_t *s, unsigned len) static void sha256_final(struct sha256_ctx *p) { uint64_t len; - p->in[p->inlen++] = 0x80; + p->in.u8[p->inlen++] = 0x80; if (p->inlen > 56) { - memset(p->in + p->inlen, 0, 64 - p->inlen); + memset(p->in.u8 + p->inlen, 0, 64 - p->inlen); sha256_block(p); } - memset(p->in + p->inlen, 0, 56 - p->inlen); + memset(p->in.u8 + p->inlen, 0, 56 - p->inlen); len = p->len << 3; - ST32BE(p->in + 56, len >> 32); - ST32BE(p->in + 60, len); + store32be(p->in.u32 + 14, len >> 32); + store32be(p->in.u32 + 15, len); sha256_block(p); } static void sha256_subhash(struct sha256_ctx *p, uint32_t *t) { for (unsigned i = 0; i < 8; i++) - ST32BE(t++, p->h[i]); + store32be(t++, p->h[i]); } void sha256_hash(char *out, const uint8_t *in, size_t size)