From a725d2c506613d99b5b1e6c709c9ceb5d864e3f4 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 15 Apr 2012 16:47:16 +0200 Subject: [PATCH 1/7] Fix libretro header. --- libretro.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libretro.h b/libretro.h index a21de790d1..a0c5f600b5 100755 --- a/libretro.h +++ b/libretro.h @@ -6,13 +6,15 @@ #ifdef __cplusplus extern "C" { -#elif defined(_MSC_VER) -typedef unsigned char bool; -typedef enum {false, true}; #else +#if defined(_MSC_VER) && !defined(__cplusplus) +#define bool unsigned char +#define true 1 +#define false 0 #else #include #endif +#endif #define RETRO_API_VERSION 1 From 186ea8898bc0af7954e32ea3708c7667d96d629d Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 15 Apr 2012 17:08:43 +0200 Subject: [PATCH 2/7] Add LIGHTGUN_START. --- input/sdl_input.c | 4 ++++ libretro.h | 1 + 2 files changed, 5 insertions(+) diff --git a/input/sdl_input.c b/input/sdl_input.c index e9c0e89cc7..48d36269a8 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -322,6 +322,10 @@ static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id) return sdl->mouse_m; case RETRO_DEVICE_ID_LIGHTGUN_TURBO: return sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_START: + return sdl->mouse_m && sdl->mouse_r; + case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: + return sdl->mouse_m && sdl->mouse_l; default: return 0; } diff --git a/libretro.h b/libretro.h index a0c5f600b5..d0f454a476 100755 --- a/libretro.h +++ b/libretro.h @@ -54,6 +54,7 @@ extern "C" { #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3 #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4 #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5 +#define RETRO_DEVICE_ID_LIGHTGUN_START 6 #define RETRO_REGION_NTSC 0 #define RETRO_REGION_PAL 1 From abaa4f371d4efba47bcf74e60b59c5cdae9b527e Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 15 Apr 2012 17:36:09 +0200 Subject: [PATCH 3/7] Add video_aspect_ratio_auto setting. --- config.def.h | 4 ++++ driver.c | 2 +- settings.c | 4 +++- ssnes.cfg | 11 +++++++++-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 0113bc6f79..d803afba17 100644 --- a/config.def.h +++ b/config.def.h @@ -163,6 +163,10 @@ static const bool video_smooth = true; // On resize and fullscreen, rendering area will stay 4:3 static const bool force_aspect = true; +// Controls aspect ratio handling. +static const float aspect_ratio = -1.0; // Automatic +static const bool aspect_ratio_auto = false; // 1:1 PAR + // Crop overscanned frames (7/8 or 15/15 for interlaced frames). static const bool crop_overscan = true; diff --git a/driver.c b/driver.c index 96f50b19c4..268c44a156 100644 --- a/driver.c +++ b/driver.c @@ -532,7 +532,7 @@ void init_video_input(void) if (geom->aspect_ratio > 0.0f && g_settings.video.aspect_ratio_auto) g_settings.video.aspect_ratio = geom->aspect_ratio; else - g_settings.video.aspect_ratio = (float)geom->base_width / geom->base_height; + g_settings.video.aspect_ratio = (float)geom->base_width / geom->base_height; // 1:1 PAR. SSNES_LOG("Adjusting aspect ratio to %.2f\n", g_settings.video.aspect_ratio); } diff --git a/settings.c b/settings.c index b8345cffbe..1a761dfeda 100644 --- a/settings.c +++ b/settings.c @@ -160,7 +160,8 @@ void config_set_defaults(void) g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; g_settings.video.crop_overscan = crop_overscan; - g_settings.video.aspect_ratio = -1.0f; // Automatic + g_settings.video.aspect_ratio = aspect_ratio; + g_settings.video.aspect_ratio_auto = aspect_ratio_auto; // Let implementation decide if automatic, or 1:1 PAR. g_settings.video.shader_type = SSNES_SHADER_AUTO; g_settings.video.allow_rotate = allow_rotate; @@ -361,6 +362,7 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); CONFIG_GET_BOOL(video.crop_overscan, "video_crop_overscan"); CONFIG_GET_FLOAT(video.aspect_ratio, "video_aspect_ratio"); + CONFIG_GET_BOOL(video.aspect_ratio_auto, "video_aspect_ratio_auto"); CONFIG_GET_FLOAT(video.refresh_rate, "video_refresh_rate"); CONFIG_GET_STRING(video.cg_shader_path, "video_cg_shader"); diff --git a/ssnes.cfg b/ssnes.cfg index 472432ce83..2aa582fc63 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -55,8 +55,15 @@ # Forces rendering area to stay equal to SNES aspect ratio 4:3 or as defined in video_aspect_ratio. # video_force_aspect = true -# A floating point value for video aspect ratio (width / height) -# video_aspect_ratio = 1.333 +# A floating point value for video aspect ratio (width / height). +# If this is not set, aspect ratio is assumed to be automatic. +# Behavior then is defined by video_aspect_ratio_auto. +# video_aspect_ratio = + +# If this is true and video_aspect_ratio is not set, +# aspect ratio is decided by libretro implementation. +# If this is false, 1:1 PAR will always be assumed if video_aspect_ratio is not set. +# video_aspect_ratio_auto = false # Forces cropping of overscanned frames. Crops away top 7 scanlines and 8 bottom scanlines. (15/15 for interlaced frames). # video_crop_overscan = false From 17aa78222316d8040eefc09e1a11b2c598eeea7b Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 15 Apr 2012 17:50:07 +0200 Subject: [PATCH 4/7] (360) MVP now gets fetched from constant table too - stock.cg now requires zero changes from Cg file --- 360/media/shaders/stock.cg | 3 +-- gfx/shader_hlsl.c | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/360/media/shaders/stock.cg b/360/media/shaders/stock.cg index 5f3deebc22..8653cf6710 100644 --- a/360/media/shaders/stock.cg +++ b/360/media/shaders/stock.cg @@ -31,11 +31,10 @@ struct input }; -output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : register(s0), uniform input IN) +output main_fragment(float2 texCoord : TEXCOORD0, uniform sampler2D decal : TEXUNIT0, uniform input IN) { output OUT; OUT.color = tex2D(decal, texCoord); - OUT.color *= IN.output_size.x; return OUT; } diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 155522bcae..d99bd8cbed 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -33,9 +33,10 @@ struct hlsl_program D3DXHANDLE out_size_v; D3DXHANDLE frame_cnt_v; D3DXHANDLE frame_dir_v; + D3DXHANDLE mvp; LPD3DXCONSTANTTABLE v_ctable; LPD3DXCONSTANTTABLE f_ctable; - XMMATRIX mvp; + XMMATRIX mvp_val; }; static IDirect3DDevice9 * d3d_device_ptr; @@ -80,7 +81,7 @@ static const char* stock_hlsl_program = void hlsl_set_proj_matrix(XMMATRIX rotation_value) { if (hlsl_active) - prg[active_index].mvp = rotation_value; + prg[active_index].mvp_val = rotation_value; } void hlsl_set_params(void) @@ -89,8 +90,7 @@ void hlsl_set_params(void) return; //const float val[2] = {2.5f, 2.5f}; - - d3d_device_ptr->SetVertexShaderConstantF(0, (FLOAT*)&prg[active_index].mvp, 4); + prg[active_index].v_ctable->SetMatrix(d3d_device_ptr, prg[active_index].mvp, (D3DXMATRIX*)&prg[active_index].mvp_val); //prg[active_index].f_ctable->SetFloatArray(d3d_device_ptr, prg[active_index].out_size_f, val, 2); } @@ -205,6 +205,7 @@ static void set_program_attributes(unsigned i) prg[i].out_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.output_size"); prg[i].frame_cnt_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_count"); prg[i].frame_dir_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_direction"); + prg[i].mvp = prg[i].v_ctable->GetConstantByName(NULL, "$modelViewProj"); } bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) From 48b8c78de20ad0e1ab115014c3bb823bf6a9703f Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 15 Apr 2012 17:53:48 +0200 Subject: [PATCH 5/7] (360) Remove register specification for MVP - no longer need it --- 360/media/shaders/stock.cg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/360/media/shaders/stock.cg b/360/media/shaders/stock.cg index 8653cf6710..7b8000c952 100644 --- a/360/media/shaders/stock.cg +++ b/360/media/shaders/stock.cg @@ -5,7 +5,7 @@ void main_vertex ( float2 position : POSITION, float2 texCoord : TEXCOORD0, - uniform float4x4 modelViewProj : register(c0), + uniform float4x4 modelViewProj, out float4 oPosition : POSITION, out float2 otexCoord : TEXCOORD ) From 1cdaa652a9d90303965806769494eabad89bee85 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 15 Apr 2012 18:13:24 +0200 Subject: [PATCH 6/7] (360) Attempt to fix memory leaks - still broken --- 360/xdk360_video.cpp | 5 +++-- gfx/shader_hlsl.c | 24 ++++++++++++++---------- gfx/shader_hlsl.h | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 922d96700f..1c892fa3a3 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -189,14 +189,15 @@ static void xdk360_gfx_free(void * data) if (!vid) return; - hlsl_deinit(); - D3DResource_Release((D3DResource *)vid->lpTexture); D3DResource_Release((D3DResource *)vid->vertex_buf); D3DResource_Release((D3DResource *)vid->v_decl); D3DDevice_Release(vid->xdk360_render_device); Direct3D_Release(); + //breaks right now + //hlsl_deinit(); + free(vid); } diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index d99bd8cbed..e5ad5ab0cd 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -106,6 +106,11 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) ret_fp = false; ret_vp = false; + if(prg[index].f_ctable) + D3DResource_Release((D3DResource *)prg[index].f_ctable); + if(prg[index].v_ctable) + D3DResource_Release((D3DResource *)prg[0].v_ctable); + if (path_is_file) { ret_fp = D3DXCompileShaderFromFile(prog, NULL, NULL, "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable); @@ -130,6 +135,11 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) goto end; } + if(prg[index].fprg) + D3DResource_Release((D3DResource *)prg[0].fprg); + if(prg[index].vprg) + D3DResource_Release((D3DResource *)prg[0].vprg); + prg[index].fprg = D3DDevice_CreatePixelShader((const DWORD*)code_f->GetBufferPointer()); prg[index].vprg = D3DDevice_CreateVertexShader((const DWORD*)code_v->GetBufferPointer()); code_f->Release(); @@ -171,12 +181,6 @@ static bool load_plain(const char *path) static void hlsl_deinit_progs(void) { - if (prg[0].fprg) - D3DResource_Release((D3DResource *)prg[0].fprg); - if (prg[0].vprg) - D3DResource_Release((D3DResource *)prg[0].vprg); - D3DResource_Release((D3DResource *)prg[0].f_ctable); - D3DResource_Release((D3DResource *)prg[0].v_ctable); } static void hlsl_deinit_state(void) @@ -210,10 +214,10 @@ static void set_program_attributes(unsigned i) bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) { - if (device_ptr != NULL) - d3d_device_ptr = device_ptr; - else - return false; + if(!device_ptr) + return false; + + d3d_device_ptr = device_ptr; if (strstr(path, ".cgp")) { diff --git a/gfx/shader_hlsl.h b/gfx/shader_hlsl.h index 163b53c7d4..7b083b7202 100644 --- a/gfx/shader_hlsl.h +++ b/gfx/shader_hlsl.h @@ -18,6 +18,7 @@ #ifndef __SSNES_HLSL_H #define __SSNES_HLSL_H +#include "../boolean.h" #include bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr); From 6a942e046a4c3ba850c2a1a0eec75c9b89313392 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Sun, 15 Apr 2012 20:02:51 +0200 Subject: [PATCH 7/7] (360) Flesh out hlsl_set_params --- 360/xdk360_video.cpp | 3 ++- gfx/shader_hlsl.c | 20 ++++++++++++++++++-- gfx/shader_hlsl.h | 4 +++- msvc-360/SSNES-360/SSNES-360.vcxproj | 3 ++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 1c892fa3a3..083e5348e6 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -435,7 +435,8 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } hlsl_use(0); - hlsl_set_params(); + hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, + vid->d3dpp.BackBufferHeight); D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index e5ad5ab0cd..23d01b2061 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -84,12 +84,28 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value) prg[active_index].mvp_val = rotation_value; } -void hlsl_set_params(void) +#define set_param_2f(param, xy, constanttable) \ + if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2); + +void hlsl_set_params(unsigned width, unsigned height, + unsigned tex_width, unsigned tex_height, + unsigned out_width, unsigned out_height) { if (!hlsl_active) return; - //const float val[2] = {2.5f, 2.5f}; + const float ori_size[2] = {(float)width, (float)height }; + const float out_size[2] = {(float)out_width, (float)out_height}; + const float tex_size[2] = {(float)tex_width, (float)tex_height}; + + set_param_2f(prg[active_index].vid_size_f, ori_size, prg[active_index].f_ctable); + set_param_2f(prg[active_index].tex_size_f, tex_size, prg[active_index].f_ctable); + set_param_2f(prg[active_index].out_size_f, out_size, prg[active_index].f_ctable); + + set_param_2f(prg[active_index].vid_size_v, ori_size, prg[active_index].v_ctable); + set_param_2f(prg[active_index].tex_size_v, tex_size, prg[active_index].v_ctable); + set_param_2f(prg[active_index].out_size_v, out_size, prg[active_index].v_ctable); + prg[active_index].v_ctable->SetMatrix(d3d_device_ptr, prg[active_index].mvp, (D3DXMATRIX*)&prg[active_index].mvp_val); //prg[active_index].f_ctable->SetFloatArray(d3d_device_ptr, prg[active_index].out_size_f, val, 2); } diff --git a/gfx/shader_hlsl.h b/gfx/shader_hlsl.h index 7b083b7202..90653d1c02 100644 --- a/gfx/shader_hlsl.h +++ b/gfx/shader_hlsl.h @@ -27,7 +27,9 @@ void hlsl_deinit(void); void hlsl_set_proj_matrix(XMMATRIX rotation_value); -void hlsl_set_params(void); +void hlsl_set_params(unsigned width, unsigned height, + unsigned tex_width, unsigned tex_height, + unsigned out_width, unsigned out_height); void hlsl_use(unsigned index); diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index a65d5b4430..feddcb3605 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -562,6 +562,7 @@ copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg + true @@ -644,4 +645,4 @@ - + \ No newline at end of file