From dcbd252c380c5cceab80aa87fbb9d94b48e3888c Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Apr 2012 18:11:20 +0200 Subject: [PATCH 01/14] Style nits. --- gfx/shader_hlsl.c | 58 +++++++++++++++++++++++++---------------------- gfx/shader_hlsl.h | 2 +- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 739ae746c7..28468278e3 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -39,15 +39,15 @@ struct hlsl_program XMMATRIX mvp_val; }; -static IDirect3DDevice9 * d3d_device_ptr; +static IDirect3DDevice9 *d3d_device_ptr; static struct hlsl_program prg[SSNES_HLSL_MAX_SHADERS] = {0}; static bool hlsl_active = false; static unsigned active_index = 0; -static const char* stock_hlsl_program = +static const char *stock_hlsl_program = "void main_vertex " "( " - " float2 position : POSITION, " + " float2 position : POSITION, " " float2 texCoord : TEXCOORD0, " " uniform float4x4 modelViewProj : register(c0), " " out float4 oPosition : POSITION, " @@ -57,21 +57,21 @@ static const char* stock_hlsl_program = " oPosition = mul(modelViewProj, float4(position, 0.0, 1.0)); " " otexCoord = texCoord; " "} " - " " + " " "struct output " - "{ " + "{ " " float4 color: COLOR; " "}; " - " " + " " "struct input " "{ " " float2 video_size; " " float2 texture_size; " - " float2 output_size; " + " float2 output_size; " "}; " - " " + " " "output main_fragment(float2 texCoord : TEXCOORD0, " - "uniform sampler2D decal : register(s0), uniform input IN) " + "uniform sampler2D decal : register(s0), uniform input IN) " "{ " " output OUT; " " OUT.color = tex2D(decal, tex); " @@ -85,9 +85,9 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value) } #define set_param_2f(param, xy, constanttable) \ - if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2); + if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2) #define set_param_1f(param, x, constanttable) \ - if (param) constanttable->SetFloat(d3d_device_ptr, param, x); + if (param) constanttable->SetFloat(d3d_device_ptr, param, x) void hlsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, @@ -97,9 +97,9 @@ void hlsl_set_params(unsigned width, unsigned height, if (!hlsl_active) return; - 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}; + const float ori_size[2] = { (float)width, (float)height }; + const float tex_size[2] = { (float)tex_width, (float)tex_height }; + const float out_size[2] = { (float)out_width, (float)out_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); @@ -126,21 +126,25 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) ret_fp = false; ret_vp = false; - if(prg[index].f_ctable) + if (prg[index].f_ctable) D3DResource_Release((D3DResource *)prg[index].f_ctable); - if(prg[index].v_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); - ret_vp = D3DXCompileShaderFromFile(prog, NULL, NULL, "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable); + ret_fp = D3DXCompileShaderFromFile(prog, NULL, NULL, + "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable); + ret_vp = D3DXCompileShaderFromFile(prog, NULL, NULL, + "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable); } else { /* TODO - crashes currently - to do with 'end of line' of stock shader */ - ret_fp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable ); - ret_vp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable ); + ret_fp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, + "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable ); + ret_vp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, + "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable ); } if (FAILED(ret_fp) || FAILED(ret_vp) || listing_v || listing_f) @@ -155,9 +159,9 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) goto end; } - if(prg[index].fprg) + if (prg[index].fprg) D3DResource_Release((D3DResource *)prg[0].fprg); - if(prg[index].vprg) + if (prg[index].vprg) D3DResource_Release((D3DResource *)prg[0].vprg); prg[index].fprg = D3DDevice_CreatePixelShader((const DWORD*)code_f->GetBufferPointer()); @@ -166,9 +170,9 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) code_v->Release(); end: - if(listing_f) + if (listing_f) listing_f->Release(); - if(listing_v) + if (listing_v) listing_v->Release(); return ret; } @@ -200,8 +204,7 @@ static bool load_plain(const char *path) } static void hlsl_deinit_progs(void) -{ -} +{} static void hlsl_deinit_state(void) { @@ -234,7 +237,7 @@ static void set_program_attributes(unsigned i) bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) { - if(!device_ptr) + if (!device_ptr) return false; d3d_device_ptr = device_ptr; @@ -275,3 +278,4 @@ void hlsl_deinit(void) hlsl_deinit_state(); } + diff --git a/gfx/shader_hlsl.h b/gfx/shader_hlsl.h index 47d704baf0..c03a91532b 100644 --- a/gfx/shader_hlsl.h +++ b/gfx/shader_hlsl.h @@ -21,7 +21,7 @@ #include "../boolean.h" #include -bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr); +bool hlsl_init(const char *path, IDirect3DDevice9 *device_ptr); void hlsl_deinit(void); From 731f3e7bba47848513555a0e6af47d420ebd2392 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 16 Apr 2012 18:32:04 +0200 Subject: [PATCH 02/14] (360) found bug while in debug mode - have to set texture to NULL first before doing lockrect / unlockrect --- 360/xdk360_video.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 91011507ef..0dc2302b09 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -438,6 +438,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, vid->d3dpp.BackBufferHeight, g_frame_count); + D3DDevice_SetTexture_Inline(vid->xdk360_render_device, 0, NULL); D3DLOCKED_RECT d3dlr; D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); for (unsigned y = 0; y < height; y++) From d51cce764d7406f71d2279190eb5864e7dc66be9 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Apr 2012 18:40:56 +0200 Subject: [PATCH 03/14] Update README a bit. --- README.md | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index c606b6d82c..e9efd49edb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # SSNES -SSNES is a simple frontend for the libsnes library. +SSNES is a simple frontend for the libretro API. An API that attempts to generalize +a retro gaming system, such as SNES, NES, GameBoy, Arcade machines, etc. -# libsnes +# libretro -libsnes is the emulator core of [bSNES](http://www.byuu.org), the most accurate SNES emulator to date, in library form. The libsnes API has been implemented by SNES9x as well, allowing multiple different cores to be used for an emulator that supports libsnes. -This enables the possibility of custom front-ends for the emulator. +libretro is an API that exposes the core of a retro gaming system. +A frontend for libretro handles video output, audio output and input. +A libretro core written in portable C or C++ can run seamlessly on many platforms. # Binaries @@ -28,7 +30,6 @@ SSNES has been ported to the following platforms : SSNES requires these libraries to build: - - [libsnes](http://byuu.org/bsnes/) - SDL SSNES can utilize these libraries if enabled: @@ -50,26 +51,20 @@ SSNES needs at least one of these audio driver libraries: - XAudio2 (Win32) - PulseAudio -# Building libsnes - - - Download bSNES source (link over). - - Add -fPIC to flags in Makefile. - - $ make library profile=performance (accuracy, compatibility are the other profiles. compatibility is a great choice for decent PCs. :D) - - # make prefix=/usr library-install - - # cp snes/libsnes/libsnes.hpp /usr/include/ - - ?!?! - - Profit! +To run properly, SSNES requires a libretro implementation present, however, as it's typically loaded +dynamically, it's not required at build time. # Configuring The default configuration is defined in config.def.h. -These can later be tweaked by using the ssnes config file. +These can later be tweaked by using a config file. A sample configuration file is installed to /etc/ssnes.cfg. This is the system-wide config file. Each user should create a config file in $XDG\_CONFIG\_HOME/ssnes/ssnes.cfg. The users only need to configure a certain option if the desired value deviates from the value defined in config.def.h. -To configure joypads, start up jstest /dev/input/js0 to determine which joypad buttons (and axis) to use. It is also possible to use the ssnes-joyconfig tool as well for simple configuration. +To configure joypads, start up jstest /dev/input/js0 to determine which joypad buttons (and axis) to use. +It is also possible to use the ssnes-joyconfig tool as well for simple configuration. # Compiling and installing @@ -78,8 +73,8 @@ As most packages, SSNES is built using the standard ./configure && make && m Do note that the build system is not autotools based, but resembles it. Notable options for ./configure: ---with-libsnes=: Normally libsnes is located with -lsnes, however, this can be overridden. ---enable-dynamic: Do not link to libsnes at compile time, but load libsnes dynamically at runtime. libsnes\_path in config file defines which library to load. Useful for development. +--with-libretro=: Normally libretro is located with -lsnes, however, this can be overridden. +--enable-dynamic: Do not link to libretro at compile time, but load libretro dynamically at runtime. libretro\_path in config file defines which library to load. Useful for development. Do note that these two options are mutually exclusive. @@ -87,12 +82,12 @@ Do note that these two options are mutually exclusive. It is possible with MinGW to compile for Windows in either msys or Linux/Unix based systems. Do note that Windows build uses a static Makefile since configuration scripts create more harm than good on this platform. Libraries, headers, etc, needed to compile and run SSNES can be fetched with a Makefile target. In Linux/Unix:
-make -f Makefile.win32 libs
-make -f Makefile.win32 CC=i486-mingw32-gcc CXX=i486-mingw32-g++
+make -f Makefile.win libs
+make -f Makefile.win CC=i486-mingw32-gcc CXX=i486-mingw32-g++
In MSYS: -mingw32-make -f Makefile.win32 libs. # You will need to have wget in your patch for this command! MSYS should provide this.
-mingw32-make -f Makefile.win32 +mingw32-make -f Makefile.win libs. # You will need to have wget in your patch for this command! MSYS should provide this.
+mingw32-make -f Makefile.win Win32 (MSVC)
In addition to Mingw, it is also possible to compile a Win32 version of SSNES with Microsoft Visual Studio 2010. @@ -109,7 +104,7 @@ The solution file can be found at the following location: A PKG file will be built which you will be able to install on a jailbroken PS3. -NOTE: A pre-existing libsnes library needs to be present in the root directory in order to link SSNES PS3. This file needs to be called 'libsnes.a'. +NOTE: A pre-existing libretro library needs to be present in the root directory in order to link SSNES PS3. This file needs to be called 'libretro.a'. Xbox 360 (XeXDK)
@@ -119,7 +114,7 @@ The solution file can be found at the following location: msvc-360/SSNES-360/SSNES-360.sln -NOTE: A pre-existing libsnes library needs to be present in the root directory in order to link SSNES 360. +NOTE: A pre-existing libretro library needs to be present in the root directory in order to link SSNES 360. Xbox 360 (Libxenon)
@@ -127,7 +122,7 @@ You will need to have the libxenon libraries and a working Devkit Xenon toolchai make -f Makefile.xenon -NOTE: A pre-existing libsnes library needs to be present in the root directory in order to link SSNES 360 Libxenon. This file needs to be called 'libsnes.a'. +NOTE: A pre-existing libretro library needs to be present in the root directory in order to link SSNES 360 Libxenon. This file needs to be called 'libretro.a'. Wii
@@ -135,7 +130,7 @@ You will need to have the libogc libraries and a working Devkit PPC toolchain in make -f Makefile.wii -NOTE: A pre-existing libsnes library needs to be present in the root directory in order to link SSNES Wii. This file needs to be called 'libsnes.a'. +NOTE: A pre-existing libretro library needs to be present in the root directory in order to link SSNES Wii. This file needs to be called 'libretro.a'. # Filters, bSNES XML shaders and Cg shader support From 68241743976cd1aff31a612794f47f3e85a1e923 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Apr 2012 18:52:14 +0200 Subject: [PATCH 04/14] Clarify README. --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e9efd49edb..d3aa45d0f3 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ SSNES has been ported to the following platforms : - Xbox 360 (Libxenon/XeXDK) - Wii (Libogc) -# Dependencies +# Dependencies (PC) SSNES requires these libraries to build: @@ -54,6 +54,11 @@ SSNES needs at least one of these audio driver libraries: To run properly, SSNES requires a libretro implementation present, however, as it's typically loaded dynamically, it's not required at build time. +# Dependencies (Console ports) + +Console ports have their own dependencies, but generally do not require +anything other than what the respective SDKs provide. + # Configuring The default configuration is defined in config.def.h. From 0934d81a527e1d153760c5d92ae330cfeec36cda Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Apr 2012 20:38:25 +0200 Subject: [PATCH 05/14] Add -Wno-unused-result. --- Makefile | 2 +- Makefile.win | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8872056274..f09b3a96dd 100644 --- a/Makefile +++ b/Makefile @@ -190,7 +190,7 @@ ifeq ($(DEBUG), 1) OPTIMIZE_FLAG = -O0 endif -CFLAGS += -Wall $(OPTIMIZE_FLAG) -g -I. -pedantic +CFLAGS += -Wall -Wno-unused-result $(OPTIMIZE_FLAG) -g -I. -pedantic ifeq ($(CXX_BUILD), 1) CFLAGS += -std=c++0x -xc++ -D__STDC_CONSTANT_MACROS else diff --git a/Makefile.win b/Makefile.win index e847d38f3c..c234e23b05 100644 --- a/Makefile.win +++ b/Makefile.win @@ -153,7 +153,7 @@ ifneq ($(V), 1) Q := @ endif -CFLAGS += -Wall -O3 -I. +CFLAGS += -Wall -Wno-unused-result -O3 -I. ifeq ($(CXX_BUILD), 1) CFLAGS += -std=c++0x -xc++ -D__STDC_CONSTANT_MACROS else From 2f693ad7f2ece14e0e5c4354faf088c10e6c9952 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 16 Apr 2012 22:25:09 +0200 Subject: [PATCH 06/14] Add some comments to libretro header. --- libretro.h | 94 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 21 deletions(-) diff --git a/libretro.h b/libretro.h index d0f454a476..5201656f1f 100755 --- a/libretro.h +++ b/libretro.h @@ -105,20 +105,31 @@ extern "C" { // #define RETRO_ENVIRONMENT_SET_MESSAGE 6 // const struct retro_message * -- // Sets a message to be displayed in implementation-specific manner for a certain amount of 'frames'. + // Should not be used for trivial messages, which should simply be logged to stderr. struct retro_message { - const char *msg; - unsigned frames; + const char *msg; // Message to be displayed. + unsigned frames; // Duration in frames of message. }; struct retro_system_info { - const char *library_name; - const char *library_version; - const char *valid_extensions; - bool need_fullpath; - bool block_extract; + const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc. + const char *library_version; // Descriptive version of core. + + const char *valid_extensions; // A string listing probably rom extensions the core will be able to load, separated with pipe. + // I.e. "bin|rom|iso". + // Typically used for a GUI to filter out extensions. + + bool need_fullpath; // If true, retro_load_game() is guaranteed to provide a valid pathname in retro_game_info::path. + // ::data and ::size are both invalid. + // If false, ::data and ::size are guaranteed to be valid, but ::path might not be valid. + // This is typically set to true for libretro implementations that must load from file. + // Implementations should strive for setting this to false, as it allows the frontend to perform patching, etc. + + bool block_extract; // If true, the frontend is not allowed to extract any archives before loading the real ROM. + // Necessary for certain libretro implementations that load games from zipped archives. }; struct retro_game_geometry @@ -158,32 +169,39 @@ struct retro_game_info { const char *path; // Path to game, UTF-8 encoded. Usually used as a reference. // May be NULL if rom was loaded from stdin or similar. - // SET_NEED_FULLPATH path guaranteed that this path is valid. - const void *data; // Memory buffer of loaded game. - // If the game is too big to load in one go. - // SET_NEED_FULLPATH should be used. - // In this case, data and size will be 0, - // and game can be loaded from path. + // retro_system_info::need_fullpath guaranteed that this path is valid. + const void *data; // Memory buffer of loaded game. Will be NULL if need_fullpath was set. size_t size; // Size of memory buffer. const char *meta; // String of implementation specific meta-data. }; +// Callbacks +// +// Environment callback. Gives implementations a way of performing uncommon tasks. Extensible. typedef bool (*retro_environment_t)(unsigned cmd, void *data); + +// Render a frame. Pixel format is 15-bit XRGB1555 native endian. +// Width and height specify dimensions of buffer. +// Pitch specifices length in bytes between two lines in buffer. typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch); + +// Renders a single audio frame. Should only be used if implementation generates a single sample at a time. +// Format is signed 16-bit native endian. typedef void (*retro_audio_sample_t)(int16_t left, int16_t right); +// Renders multiple audio frames in one go. One frame is defined as a sample of left and right channels, interleaved. +// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames. +// Only one of the audio callbacks must ever be used. typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames); +// Polls input. typedef void (*retro_input_poll_t)(void); +// Queries for input for player 'port'. device will be masked with RETRO_DEVICE_MASK. +// Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that have been set with retro_set_controller_port_device() +// will still use the higher level RETRO_DEVICE_JOYPAD to request input. typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id); -void retro_init(void); -void retro_deinit(void); - -unsigned retro_api_version(void); - -void retro_get_system_info(struct retro_system_info *info); -void retro_get_system_av_info(struct retro_system_av_info *info); - +// Sets callbacks. retro_set_environment() is guaranteed to be called before retro_init(). +// The rest of the set_* functions are guaranteed to have been called before the first call to retro_run() is made. void retro_set_environment(retro_environment_t); void retro_set_video_refresh(retro_video_refresh_t); void retro_set_audio_sample(retro_audio_sample_t); @@ -191,29 +209,63 @@ void retro_set_audio_sample_batch(retro_audio_sample_batch_t); void retro_set_input_poll(retro_input_poll_t); void retro_set_input_state(retro_input_state_t); +// Library global initialization/deinitialization. +void retro_init(void); +void retro_deinit(void); + +// Must return RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised. +unsigned retro_api_version(void); + +// Gets statically known system info. Pointers provided in *info must be statically allocated. +// Can be called at any time, even before retro_init(). +void retro_get_system_info(struct retro_system_info *info); + +// Gets information about system audio/video timings and geometry. +// Can be called only after retro_load_game() has successfully completed. +void retro_get_system_av_info(struct retro_system_av_info *info); + +// Sets device to be used for player 'port'. void retro_set_controller_port_device(unsigned port, unsigned device); +// Resets the current game. void retro_reset(void); + +// Runs the game for one video frame. +// During retro_run(), input_poll callback must be called at least once. +// +// If a frame is not rendered for reasons where a game "dropped" a frame, +// this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true. +// In this case, the video callback can take a NULL argument for data. void retro_run(void); +// Returns the amount of data the implementation requires to serialize internal state (save states). +// Beetween calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to +// ensure that the frontend can allocate a save state buffer once. size_t retro_serialize_size(void); + +// Serializes internal state. If failed, or size is lower than retro_serialize_size(), it should return false, true otherwise. bool retro_serialize(void *data, size_t size); bool retro_unserialize(const void *data, size_t size); void retro_cheat_reset(void); void retro_cheat_set(unsigned index, bool enabled, const char *code); +// Loads a game. bool retro_load_game(const struct retro_game_info *game); +// Loads a "special" kind of game. Should not be used except in extreme cases. bool retro_load_game_special( unsigned game_type, const struct retro_game_info *info, size_t num_info ); +// Unloads a currently loaded game. void retro_unload_game(void); +// Gets region of game. unsigned retro_get_region(void); +// Gets region of memory. void *retro_get_memory_data(unsigned id); size_t retro_get_memory_size(unsigned id); From 6c5285c79209d20f8cd97ac1bfb9ad67096da833 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 05:12:03 +0200 Subject: [PATCH 07/14] (360) Rewrite of xdk360_video.cpp and shader_hlsl.c - use portable class-based function invocations --- 360/xdk360_video.cpp | 102 +++++++++++++++++++++---------------------- gfx/shader_hlsl.c | 26 +++++++---- 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 0dc2302b09..7004a6e7f2 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -189,14 +189,12 @@ static void xdk360_gfx_free(void * data) if (!vid) return; - 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(); + vid->lpTexture->Release(); + vid->vertex_buf->Release(); + vid->v_decl->Release(); + hlsl_deinit(); + vid->xdk360_render_device->Release(); + vid->xdk360_device->Release(); free(vid); } @@ -204,8 +202,8 @@ static void xdk360_gfx_free(void * data) static void set_viewport(bool force_full) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0, FALSE); + vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0); int width = vid->video_mode.fIsHiDef ? 1280 : 640; int height = vid->video_mode.fIsHiDef ? 720 : 480; @@ -257,7 +255,7 @@ static void set_viewport(bool force_full) vp.Y = m_viewport_y_temp; vp.MinZ = m_zNear; vp.MaxZ = m_zFar; - D3DDevice_SetViewport(vid->xdk360_render_device, &vp); + vid->xdk360_render_device->SetViewport(&vp); //if(gl->overscan_enable && !force_full) //{ @@ -303,8 +301,6 @@ static void xdk360_set_aspect_ratio(void * data, uint32_t aspectratio_index) static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - HRESULT ret; - if (g_d3d) return g_d3d; @@ -344,22 +340,24 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vid->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; // D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360 - ret = Direct3D_CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid->d3dpp, &vid->xdk360_render_device); + vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, + &vid->d3dpp, &vid->xdk360_render_device); hlsl_init(g_settings.video.cg_shader_path, vid->xdk360_render_device); - vid->lpTexture = (D3DTexture*) D3DDevice_CreateTexture(512, 512, 1, 1, 0, D3DFMT_LIN_X1R5G5B5, - 0, D3DRTYPE_TEXTURE); + vid->xdk360_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, + 0, &vid->lpTexture, NULL); D3DLOCKED_RECT d3dlr; - D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - D3DTexture_UnlockRect(vid->lpTexture, 0); + vid->lpTexture->UnlockRect(0); vid->last_width = 512; vid->last_height = 512; - vid->vertex_buf = D3DDevice_CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 0, 0); + vid->xdk360_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), + 0, 0, 0, &vid->vertex_buf, NULL); static const DrawVerticeFormats init_verts[] = { { -1.0f, -1.0f, 0.0f, 1.0f }, @@ -368,9 +366,10 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i { 1.0f, 1.0f, 1.0f, 0.0f }, }; - void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); + void *verts_ptr; + vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, init_verts, sizeof(init_verts)); - D3DVertexBuffer_Unlock(vid->vertex_buf); + vid->vertex_buf->Unlock(); static const D3DVERTEXELEMENT9 VertexElements[] = { @@ -379,20 +378,20 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i D3DDECL_END() }; - vid->v_decl = D3DDevice_CreateVertexDeclaration(VertexElements); + vid->xdk360_render_device->CreateVertexDeclaration(VertexElements, &vid->v_decl); - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0, FALSE); + vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0); - D3DDevice_SetRenderState_CullMode(vid->xdk360_render_device, D3DCULL_NONE); - D3DDevice_SetRenderState_ZEnable(vid->xdk360_render_device, FALSE); + vid->xdk360_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + vid->xdk360_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); D3DVIEWPORT9 vp = {0}; vp.Width = vid->video_mode.fIsHiDef ? 1280 : 640; vp.Height = vid->video_mode.fIsHiDef ? 720 : 480; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; - D3DDevice_SetViewport(vid->xdk360_render_device, &vp); + vid->xdk360_render_device->SetViewport(&vp); xdk360_set_orientation(NULL, g_console.screen_orientation); @@ -404,17 +403,17 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { xdk360_video_t *vid = (xdk360_video_t*)data; - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0, FALSE); + vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0); g_frame_count++; if (vid->last_width != width || vid->last_height != height) { D3DLOCKED_RECT d3dlr; - D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - D3DTexture_UnlockRect(vid->lpTexture, 0); + vid->lpTexture->UnlockRect(0); float tex_w = width / 512.0f; float tex_h = height / 512.0f; @@ -426,9 +425,10 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { 1.0f, 1.0f, tex_w, 0.0f }, }; - void *verts_ptr = (BYTE*)D3DVertexBuffer_Lock(vid->vertex_buf, 0, 0, 0); + void *verts_ptr; + vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, verts, sizeof(verts)); - D3DVertexBuffer_Unlock(vid->vertex_buf); + vid->vertex_buf->Unlock(); vid->last_width = width; vid->last_height = height; @@ -438,42 +438,42 @@ static bool xdk360_gfx_frame(void *data, const void *frame, hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, vid->d3dpp.BackBufferHeight, g_frame_count); - D3DDevice_SetTexture_Inline(vid->xdk360_render_device, 0, NULL); + vid->xdk360_render_device->SetTexture(0, NULL); + D3DLOCKED_RECT d3dlr; - D3DTexture_LockRect(vid->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); for (unsigned y = 0; y < height; y++) { const uint8_t *in = (const uint8_t*)frame + y * pitch; uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; memcpy(out, in, width * sizeof(uint16_t)); } - D3DTexture_UnlockRect(vid->lpTexture, 0); + vid->lpTexture->UnlockRect(0); - D3DDevice_SetTexture_Inline(vid->xdk360_render_device, 0, vid->lpTexture); - D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - D3DDevice_SetSamplerState(vid->xdk360_render_device, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + vid->xdk360_render_device->SetTexture(0, vid->lpTexture); + vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - D3DDevice_SetVertexDeclaration(vid->xdk360_render_device, vid->v_decl); - D3DDevice_SetStreamSource_Inline(vid->xdk360_render_device, 0, vid->vertex_buf, 0, - sizeof(DrawVerticeFormats)); + vid->xdk360_render_device->SetVertexDeclaration(vid->v_decl); + vid->xdk360_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); - D3DDevice_DrawVertices(vid->xdk360_render_device, D3DPT_TRIANGLESTRIP, 0, D3DVERTEXCOUNT(D3DPT_TRIANGLESTRIP, 2)); + vid->xdk360_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); if (msg) { if(IS_TIMER_EXPIRED() || g_first_msg) { xdk360_console_format(msg); - g_first_msg = 0; - SET_TIMER_EXPIRATION(30); + g_first_msg = 0; + SET_TIMER_EXPIRATION(30); } xdk360_console_draw(); } if(!vid->block_swap) - D3DDevice_Present(vid->xdk360_render_device); + vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); return true; } @@ -494,7 +494,7 @@ static void xdk360_swap (void * data) { (void)data; xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice_Present(vid->xdk360_render_device); + vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); } static void xdk360_gfx_set_nonblock_state(void *data, bool state) @@ -502,9 +502,9 @@ static void xdk360_gfx_set_nonblock_state(void *data, bool state) xdk360_video_t *vid = (xdk360_video_t*)data; SSNES_LOG("D3D Vsync => %s\n", state ? "off" : "on"); if(state) - D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_IMMEDIATE); + vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE); else - D3DDevice_SetRenderState_PresentInterval(vid->xdk360_render_device, D3DPRESENT_INTERVAL_ONE); + vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE); } static bool xdk360_gfx_alive(void *data) diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 28468278e3..61a70895c6 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -127,9 +127,9 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) ret_vp = false; if (prg[index].f_ctable) - D3DResource_Release((D3DResource *)prg[index].f_ctable); + prg[index].f_ctable->Release(); if (prg[index].v_ctable) - D3DResource_Release((D3DResource *)prg[0].v_ctable); + prg[index].v_ctable->Release(); if (path_is_file) { @@ -160,12 +160,12 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) } if (prg[index].fprg) - D3DResource_Release((D3DResource *)prg[0].fprg); + prg[index].fprg->Release(); if (prg[index].vprg) - D3DResource_Release((D3DResource *)prg[0].vprg); + prg[index].vprg->Release(); - prg[index].fprg = D3DDevice_CreatePixelShader((const DWORD*)code_f->GetBufferPointer()); - prg[index].vprg = D3DDevice_CreateVertexShader((const DWORD*)code_v->GetBufferPointer()); + d3d_device_ptr->CreatePixelShader((const DWORD*)code_f->GetBufferPointer(), &prg[index].fprg); + d3d_device_ptr->CreateVertexShader((const DWORD*)code_v->GetBufferPointer(), &prg[index].vprg); code_f->Release(); code_v->Release(); @@ -204,7 +204,15 @@ static bool load_plain(const char *path) } static void hlsl_deinit_progs(void) -{} +{ + for(int i = 0; i < SSNES_HLSL_MAX_SHADERS; i++) + { + if (prg[i].fprg) + prg[i].fprg->Release(); + if (prg[i].vprg) + prg[i].vprg->Release(); + } +} static void hlsl_deinit_state(void) { @@ -265,8 +273,8 @@ void hlsl_use(unsigned index) if (hlsl_active && prg[index].vprg && prg[index].fprg) { active_index = index; - D3DDevice_SetVertexShader(d3d_device_ptr, prg[index].vprg); - D3DDevice_SetPixelShader(d3d_device_ptr, prg[index].fprg); + d3d_device_ptr->SetVertexShader(prg[index].vprg); + d3d_device_ptr->SetPixelShader(prg[index].fprg); } } From ce7275393e7a56b61f580b4928ae0c5bb2c7f8ff Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 05:23:54 +0200 Subject: [PATCH 08/14] (360) Attempt to make clear in xdk360_video.cpp what is 360-specific and what is not --- 360/fonts.cpp | 14 ++++----- 360/menu.cpp | 6 ++-- 360/xdk360_video.cpp | 71 +++++++++++++++++++++++++------------------- 360/xdk360_video.h | 4 +-- gfx/shader_hlsl.c | 3 +- 5 files changed, 55 insertions(+), 43 deletions(-) diff --git a/360/fonts.cpp b/360/fonts.cpp index 17e2fead84..a0858dab00 100644 --- a/360/fonts.cpp +++ b/360/fonts.cpp @@ -27,7 +27,7 @@ static xdk360_video_font_t m_Font; void xdk360_console_draw(void) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + D3DDevice *m_pd3dDevice = vid->d3d_render_device; // The top line unsigned int nTextLine = ( video_console.m_nCurLine - @@ -55,7 +55,7 @@ HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, unsigned long colTextColor) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *m_pd3dDevice = vid->xdk360_render_device; + D3DDevice *m_pd3dDevice = vid->d3d_render_device; video_console.first_message = true; video_console.m_Buffer = NULL; @@ -354,7 +354,7 @@ static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) // Cache this global into a register xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pd3dDevice = vid->xdk360_render_device; + D3DDevice *pd3dDevice = vid->d3d_render_device; hr = pd3dDevice->CreateVertexDeclaration( decl, &s_FontLocals.m_pFontVertexDecl ); @@ -482,7 +482,7 @@ HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontF } xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pd3dDevice = vid->xdk360_render_device; + D3DDevice *pd3dDevice = vid->d3d_render_device; // Initialize the window D3DDISPLAYMODE DisplayMode; @@ -604,7 +604,7 @@ void xdk360_video_font_begin (xdk360_video_font_t * font) { // Cache the global pointer into a register xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pD3dDevice = vid->xdk360_render_device; + D3DDevice *pD3dDevice = vid->d3d_render_device; // Save state if( font->m_bSaveState ) @@ -681,7 +681,7 @@ void xdk360_video_font_end(xdk360_video_font_t * font) { // Cache the global pointer into a register xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pD3dDevice = vid->xdk360_render_device; + D3DDevice *pD3dDevice = vid->d3d_render_device; D3DDevice_SetTexture_Inline(pD3dDevice, 0, NULL); D3DDevice_SetVertexDeclaration(pD3dDevice, NULL); @@ -711,7 +711,7 @@ void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, flo return; xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - D3DDevice *pd3dDevice = vid->xdk360_render_device; + D3DDevice *pd3dDevice = vid->d3d_render_device; // Set the color as a vertex shader constant float vColor[4]; diff --git a/360/menu.cpp b/360/menu.cpp index 724d574a8d..8b8bf2ffc6 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -489,7 +489,7 @@ int menu_init (void) xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - hr = app.InitShared(vid->xdk360_render_device, &vid->d3dpp, XuiPNGTextureLoader); + hr = app.InitShared(vid->d3d_render_device, &vid->d3dpp, XuiPNGTextureLoader); if (FAILED(hr)) { @@ -544,8 +544,8 @@ void menu_loop(void) ssnes_render_cached_frame(); } else - D3DDevice_Clear(vid->xdk360_render_device, 0, NULL, - D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 32, 32, 64), 1.0, 0, FALSE); + vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + D3DCOLOR_ARGB(255, 32, 32, 64), 1.0f, 0); XINPUT_STATE state; XInputGetState(0, &state); diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 7004a6e7f2..0c086dcfe2 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -14,8 +14,10 @@ * If not, see . */ +// Xbox 360-specific headers #include #include + #include "../driver.h" #include "xdk360_video.h" #include "xdk360_video_resources.h" @@ -34,6 +36,8 @@ static bool g_first_msg; unsigned g_frame_count; void *g_d3d; +/* Xbox 360 specific code */ + struct XPR_HEADER { unsigned long dwMagic; @@ -179,6 +183,8 @@ void PackedResource::Destroy() m_bInitialized = FALSE; } +/* end of Xbox 360 specific code */ + static void xdk360_gfx_free(void * data) { if (g_d3d) @@ -193,8 +199,8 @@ static void xdk360_gfx_free(void * data) vid->vertex_buf->Release(); vid->v_decl->Release(); hlsl_deinit(); - vid->xdk360_render_device->Release(); - vid->xdk360_device->Release(); + vid->d3d_render_device->Release(); + vid->d3d_device->Release(); free(vid); } @@ -202,7 +208,7 @@ static void xdk360_gfx_free(void * data) static void set_viewport(bool force_full) { xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); int width = vid->video_mode.fIsHiDef ? 1280 : 640; @@ -255,7 +261,7 @@ static void set_viewport(bool force_full) vp.Y = m_viewport_y_temp; vp.MinZ = m_zNear; vp.MaxZ = m_zFar; - vid->xdk360_render_device->SetViewport(&vp); + vid->d3d_render_device->SetViewport(&vp); //if(gl->overscan_enable && !force_full) //{ @@ -287,6 +293,7 @@ static void xdk360_set_orientation(void * data, uint32_t orientation) break; } + /* TODO: Move to D3DXMATRIX here */ hlsl_set_proj_matrix(XMMatrixRotationZ(angle)); } @@ -308,8 +315,8 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i if (!vid) return NULL; - vid->xdk360_device = Direct3DCreate9(D3D_SDK_VERSION); - if (!vid->xdk360_device) + vid->d3d_device = Direct3DCreate9(D3D_SDK_VERSION); + if (!vid->d3d_device) { free(vid); return NULL; @@ -340,12 +347,12 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vid->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; // D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360 - vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, - &vid->d3dpp, &vid->xdk360_render_device); + vid->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, + &vid->d3dpp, &vid->d3d_render_device); - hlsl_init(g_settings.video.cg_shader_path, vid->xdk360_render_device); + hlsl_init(g_settings.video.cg_shader_path, vid->d3d_render_device); - vid->xdk360_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, + vid->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, 0, &vid->lpTexture, NULL); D3DLOCKED_RECT d3dlr; @@ -356,7 +363,7 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vid->last_width = 512; vid->last_height = 512; - vid->xdk360_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), + vid->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 0, 0, 0, &vid->vertex_buf, NULL); static const DrawVerticeFormats init_verts[] = { @@ -378,20 +385,20 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i D3DDECL_END() }; - vid->xdk360_render_device->CreateVertexDeclaration(VertexElements, &vid->v_decl); + vid->d3d_render_device->CreateVertexDeclaration(VertexElements, &vid->v_decl); - vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); - vid->xdk360_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - vid->xdk360_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); + vid->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + vid->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); D3DVIEWPORT9 vp = {0}; vp.Width = vid->video_mode.fIsHiDef ? 1280 : 640; vp.Height = vid->video_mode.fIsHiDef ? 720 : 480; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; - vid->xdk360_render_device->SetViewport(&vp); + vid->d3d_render_device->SetViewport(&vp); xdk360_set_orientation(NULL, g_console.screen_orientation); @@ -403,7 +410,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, { xdk360_video_t *vid = (xdk360_video_t*)data; - vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); g_frame_count++; @@ -438,7 +445,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, vid->d3dpp.BackBufferHeight, g_frame_count); - vid->xdk360_render_device->SetTexture(0, NULL); + vid->d3d_render_device->SetTexture(0, NULL); D3DLOCKED_RECT d3dlr; vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); @@ -450,16 +457,18 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } vid->lpTexture->UnlockRect(0); - vid->xdk360_render_device->SetTexture(0, vid->lpTexture); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + vid->d3d_render_device->SetTexture(0, vid->lpTexture); + vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - vid->xdk360_render_device->SetVertexDeclaration(vid->v_decl); - vid->xdk360_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); + vid->d3d_render_device->SetVertexDeclaration(vid->v_decl); + vid->d3d_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); - vid->xdk360_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); + vid->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); + + /* XBox 360 specific font code */ if (msg) { if(IS_TIMER_EXPIRED() || g_first_msg) @@ -473,7 +482,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } if(!vid->block_swap) - vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); + vid->d3d_render_device->Present(NULL, NULL, NULL, NULL); return true; } @@ -494,17 +503,18 @@ static void xdk360_swap (void * data) { (void)data; xdk360_video_t *vid = (xdk360_video_t*)g_d3d; - vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL); + vid->d3d_render_device->Present(NULL, NULL, NULL, NULL); } static void xdk360_gfx_set_nonblock_state(void *data, bool state) { xdk360_video_t *vid = (xdk360_video_t*)data; SSNES_LOG("D3D Vsync => %s\n", state ? "off" : "on"); + /* XBox 360 specific code */ if(state) - vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE); + vid->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE); else - vid->xdk360_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE); + vid->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE); } static bool xdk360_gfx_alive(void *data) @@ -542,6 +552,7 @@ void xdk360_video_init(void) g_first_msg = true; + /* XBox 360 specific font code */ HRESULT hr = xdk360_console_init("game:\\media\\Arial_12.xpr", 0xff000000, 0xffffffff ); diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 5e31d1bb17..b987722f23 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -46,8 +46,8 @@ typedef struct xdk360_video bool vsync; unsigned last_width; unsigned last_height; - IDirect3D9* xdk360_device; - IDirect3DDevice9* xdk360_render_device; + IDirect3D9* d3d_device; + IDirect3DDevice9* d3d_render_device; IDirect3DVertexBuffer9* vertex_buf; IDirect3DTexture9* lpTexture; IDirect3DVertexDeclaration9* v_decl; diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 61a70895c6..02232da600 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -36,7 +36,7 @@ struct hlsl_program D3DXHANDLE mvp; LPD3DXCONSTANTTABLE v_ctable; LPD3DXCONSTANTTABLE f_ctable; - XMMATRIX mvp_val; + XMMATRIX mvp_val; /* TODO: Move to D3DXMATRIX here */ }; static IDirect3DDevice9 *d3d_device_ptr; @@ -111,6 +111,7 @@ void hlsl_set_params(unsigned width, unsigned height, set_param_2f(prg[active_index].out_size_v, out_size, prg[active_index].v_ctable); set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count, prg[active_index].v_ctable); + /* TODO: Move to D3DXMATRIX here */ prg[active_index].v_ctable->SetMatrix(d3d_device_ptr, prg[active_index].mvp, (D3DXMATRIX*)&prg[active_index].mvp_val); } From 3868f4268719390fc507192d583ee3f556dac512 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 05:27:16 +0200 Subject: [PATCH 09/14] (360) Don't exclude stock.cg from deploy any longer --- msvc-360/SSNES-360/SSNES-360.vcxproj | 1 - 1 file changed, 1 deletion(-) diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index feddcb3605..cb7db39155 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -562,7 +562,6 @@ copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg - true From 3a99b0602e05ffc19dd790a83f67ec9a36b31af5 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 05:35:25 +0200 Subject: [PATCH 10/14] (360) Fixed memory freeing bug to do with XUI when exiting program --- 360/main.c | 1 + 360/menu.cpp | 5 +++++ 360/menu.h | 1 + 3 files changed, 7 insertions(+) diff --git a/360/main.c b/360/main.c index dffd2137aa..51af36e37e 100644 --- a/360/main.c +++ b/360/main.c @@ -416,6 +416,7 @@ begin_shutdown: if(path_file_exists(SYS_CONFIG_FILE)) save_settings(); + menu_deinit(); xdk360_video_deinit(); ssnes_exec(); diff --git a/360/menu.cpp b/360/menu.cpp index 8b8bf2ffc6..0f28427569 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -526,6 +526,11 @@ int menu_init (void) return 0; } +void menu_deinit (void) +{ + app.Uninit(); +} + void menu_loop(void) { g_console.menu_enable = true; diff --git a/360/menu.h b/360/menu.h index 16335eff05..200476a70e 100644 --- a/360/menu.h +++ b/360/menu.h @@ -138,6 +138,7 @@ public: }; int menu_init (void); +void menu_deinit (void); void menu_loop (void); extern CSSNES app; From 23d05ea55d9be7d54a9eaae1947ea07ab65badf2 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 05:45:55 +0200 Subject: [PATCH 11/14] (360) Assume Release of d3d render device / device will also free all associated resources --- 360/xdk360_video.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 0c086dcfe2..a0f1e3d125 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -195,9 +195,6 @@ static void xdk360_gfx_free(void * data) if (!vid) return; - vid->lpTexture->Release(); - vid->vertex_buf->Release(); - vid->v_decl->Release(); hlsl_deinit(); vid->d3d_render_device->Release(); vid->d3d_device->Release(); From 9bd2a4256b46a95f8b6f45befc902fe401905515 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Tue, 17 Apr 2012 21:27:47 +0200 Subject: [PATCH 12/14] (360) Move to ps_3_0/vs_3_0 --- gfx/shader_hlsl.c | 21 +++++++++++++++++---- msvc-360/SSNES-360/SSNES-360.vcxproj | 6 ++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 02232da600..dc7ec7484f 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -105,11 +105,13 @@ void hlsl_set_params(unsigned width, unsigned height, 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_1f(prg[active_index].frame_cnt_f, (float)frame_count, prg[active_index].f_ctable); + set_param_1f(prg[active_index].frame_dir_f, g_extern.frame_is_reverse ? -1.0 : 1.0,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); set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count, prg[active_index].v_ctable); + set_param_1f(prg[active_index].frame_dir_v, g_extern.frame_is_reverse ? -1.0 : 1.0,prg[active_index].v_ctable); /* TODO: Move to D3DXMATRIX here */ prg[active_index].v_ctable->SetMatrix(d3d_device_ptr, prg[active_index].mvp, (D3DXMATRIX*)&prg[active_index].mvp_val); @@ -135,17 +137,17 @@ static bool load_program(unsigned index, const char *prog, bool path_is_file) if (path_is_file) { ret_fp = D3DXCompileShaderFromFile(prog, NULL, NULL, - "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable); + "main_fragment", "ps_3_0", 0, &code_f, &listing_f, &prg[index].f_ctable); ret_vp = D3DXCompileShaderFromFile(prog, NULL, NULL, - "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable); + "main_vertex", "vs_3_0", 0, &code_v, &listing_v, &prg[index].v_ctable); } else { /* TODO - crashes currently - to do with 'end of line' of stock shader */ ret_fp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, - "main_fragment", "ps_2_0", 0, &code_f, &listing_f, &prg[index].f_ctable ); + "main_fragment", "ps_3_0", 0, &code_f, &listing_f, &prg[index].f_ctable ); ret_vp = D3DXCompileShader(prog, (UINT)strlen(prog), NULL, NULL, - "main_vertex", "vs_2_0", 0, &code_v, &listing_v, &prg[index].v_ctable ); + "main_vertex", "vs_3_0", 0, &code_v, &listing_v, &prg[index].v_ctable ); } if (FAILED(ret_fp) || FAILED(ret_vp) || listing_v || listing_f) @@ -231,16 +233,27 @@ static bool load_preset(const char *path) static void set_program_attributes(unsigned i) { + SSNES_LOG("Fragment: IN.video_size.\n"); prg[i].vid_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.video_size"); + SSNES_LOG("Fragment: IN.texture_size.\n"); prg[i].tex_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.texture_size"); + SSNES_LOG("Fragment: IN.output_size.\n"); prg[i].out_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.output_size"); + SSNES_LOG("Fragment: IN.frame_count.\n"); prg[i].frame_cnt_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.frame_count"); + SSNES_LOG("Fragment: IN.frame_direction.\n"); prg[i].frame_dir_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.frame_direction"); + SSNES_LOG("Vertex: IN.video_size.\n"); prg[i].vid_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.video_size"); + SSNES_LOG("Vertex: IN.texture_size.\n"); prg[i].tex_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.texture_size"); + SSNES_LOG("Vertex: IN.output_size.\n"); prg[i].out_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.output_size"); + SSNES_LOG("Vertex: IN.frame_count.\n"); prg[i].frame_cnt_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_count"); + SSNES_LOG("Vertex: IN.frame_direction.\n"); prg[i].frame_dir_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_direction"); + SSNES_LOG("Vertex: modelViewProj.\n"); prg[i].mvp = prg[i].v_ctable->GetConstantByName(NULL, "$modelViewProj"); } diff --git a/msvc-360/SSNES-360/SSNES-360.vcxproj b/msvc-360/SSNES-360/SSNES-360.vcxproj index cb7db39155..8750205da1 100644 --- a/msvc-360/SSNES-360/SSNES-360.vcxproj +++ b/msvc-360/SSNES-360/SSNES-360.vcxproj @@ -562,6 +562,12 @@ copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg copy %(FullPath) $(OutDir)media\shaders\stock.cg + true + true + true + true + true + true From 1f10d2d18afffac467b27d811eee180dae7575ce Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Wed, 18 Apr 2012 02:57:46 +0200 Subject: [PATCH 13/14] (360) Changes to shader_hlsl.c --- gfx/shader_hlsl.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index dc7ec7484f..75d09a37db 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -87,7 +87,7 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value) #define set_param_2f(param, xy, constanttable) \ if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2) #define set_param_1f(param, x, constanttable) \ - if (param) constanttable->SetFloat(d3d_device_ptr, param, x) + constanttable->SetFloat(d3d_device_ptr, param, x) void hlsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, @@ -100,17 +100,21 @@ void hlsl_set_params(unsigned width, unsigned height, const float ori_size[2] = { (float)width, (float)height }; const float tex_size[2] = { (float)tex_width, (float)tex_height }; const float out_size[2] = { (float)out_width, (float)out_height }; + float frame_cnt = frame_count; + + prg[active_index].f_ctable->SetDefaults(d3d_device_ptr); + prg[active_index].v_ctable->SetDefaults(d3d_device_ptr); 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_1f(prg[active_index].frame_cnt_f, (float)frame_count, prg[active_index].f_ctable); + set_param_1f(prg[active_index].frame_cnt_f, frame_cnt, prg[active_index].f_ctable); set_param_1f(prg[active_index].frame_dir_f, g_extern.frame_is_reverse ? -1.0 : 1.0,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); - set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count, prg[active_index].v_ctable); + set_param_1f(prg[active_index].frame_cnt_v, frame_cnt, prg[active_index].v_ctable); set_param_1f(prg[active_index].frame_dir_v, g_extern.frame_is_reverse ? -1.0 : 1.0,prg[active_index].v_ctable); /* TODO: Move to D3DXMATRIX here */ @@ -284,12 +288,12 @@ bool hlsl_init(const char *path, IDirect3DDevice9 * device_ptr) void hlsl_use(unsigned index) { - if (hlsl_active && prg[index].vprg && prg[index].fprg) - { - active_index = index; - d3d_device_ptr->SetVertexShader(prg[index].vprg); - d3d_device_ptr->SetPixelShader(prg[index].fprg); - } + if (!hlsl_active) + return; + + active_index = index; + d3d_device_ptr->SetVertexShader(prg[index].vprg); + d3d_device_ptr->SetPixelShader(prg[index].fprg); } // Full deinit. From 8e950ba5bee2af64b5517ce8e97e8e09e6443535 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Wed, 18 Apr 2012 05:01:17 +0200 Subject: [PATCH 14/14] (360) Convert texture first to some color format suitable for GPU/sampling - this fixes most of the problems with the shaders such as Lanzcos, Bead and Blinky. --- 360/xdk360_video.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++ gfx/shader_hlsl.c | 13 +------ 2 files changed, 84 insertions(+), 12 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index a0f1e3d125..0094c338c3 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -38,6 +38,74 @@ void *g_d3d; /* Xbox 360 specific code */ +const DWORD g_MapLinearToSrgbGpuFormat[] = +{ + GPUTEXTUREFORMAT_1_REVERSE, + GPUTEXTUREFORMAT_1, + GPUTEXTUREFORMAT_8, + GPUTEXTUREFORMAT_1_5_5_5, + GPUTEXTUREFORMAT_5_6_5, + GPUTEXTUREFORMAT_6_5_5, + GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16, + GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16, + GPUTEXTUREFORMAT_8_A, + GPUTEXTUREFORMAT_8_B, + GPUTEXTUREFORMAT_8_8, + GPUTEXTUREFORMAT_Cr_Y1_Cb_Y0_REP, + GPUTEXTUREFORMAT_Y1_Cr_Y0_Cb_REP, + GPUTEXTUREFORMAT_16_16_EDRAM, + GPUTEXTUREFORMAT_8_8_8_8_A, + GPUTEXTUREFORMAT_4_4_4_4, + GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16, + GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16, + GPUTEXTUREFORMAT_16_16_16_16_EDRAM, + GPUTEXTUREFORMAT_24_8, + GPUTEXTUREFORMAT_24_8_FLOAT, + GPUTEXTUREFORMAT_16, + GPUTEXTUREFORMAT_16_16, + GPUTEXTUREFORMAT_16_16_16_16, + GPUTEXTUREFORMAT_16_EXPAND, + GPUTEXTUREFORMAT_16_16_EXPAND, + GPUTEXTUREFORMAT_16_16_16_16_EXPAND, + GPUTEXTUREFORMAT_16_FLOAT, + GPUTEXTUREFORMAT_16_16_FLOAT, + GPUTEXTUREFORMAT_16_16_16_16_FLOAT, + GPUTEXTUREFORMAT_32, + GPUTEXTUREFORMAT_32_32, + GPUTEXTUREFORMAT_32_32_32_32, + GPUTEXTUREFORMAT_32_FLOAT, + GPUTEXTUREFORMAT_32_32_FLOAT, + GPUTEXTUREFORMAT_32_32_32_32_FLOAT, + GPUTEXTUREFORMAT_32_AS_8, + GPUTEXTUREFORMAT_32_AS_8_8, + GPUTEXTUREFORMAT_16_MPEG, + GPUTEXTUREFORMAT_16_16_MPEG, + GPUTEXTUREFORMAT_8_INTERLACED, + GPUTEXTUREFORMAT_32_AS_8_INTERLACED, + GPUTEXTUREFORMAT_32_AS_8_8_INTERLACED, + GPUTEXTUREFORMAT_16_INTERLACED, + GPUTEXTUREFORMAT_16_MPEG_INTERLACED, + GPUTEXTUREFORMAT_16_16_MPEG_INTERLACED, + GPUTEXTUREFORMAT_DXN, + GPUTEXTUREFORMAT_8_8_8_8_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT1_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT2_3_AS_16_16_16_16, + GPUTEXTUREFORMAT_DXT4_5_AS_16_16_16_16, + GPUTEXTUREFORMAT_2_10_10_10_AS_16_16_16_16, + GPUTEXTUREFORMAT_10_11_11_AS_16_16_16_16, + GPUTEXTUREFORMAT_11_11_10_AS_16_16_16_16, + GPUTEXTUREFORMAT_32_32_32_FLOAT, + GPUTEXTUREFORMAT_DXT3A, + GPUTEXTUREFORMAT_DXT5A, + GPUTEXTUREFORMAT_CTX1, + GPUTEXTUREFORMAT_DXT3A_AS_1_1_1_1, + GPUTEXTUREFORMAT_8_8_8_8_GAMMA_EDRAM, + GPUTEXTUREFORMAT_2_10_10_10_FLOAT_EDRAM, +}; + struct XPR_HEADER { unsigned long dwMagic; @@ -303,6 +371,19 @@ static void xdk360_set_aspect_ratio(void * data, uint32_t aspectratio_index) set_viewport(false); } +static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture ) +{ + pTexture->Format.SignX = GPUSIGN_GAMMA; + pTexture->Format.SignY = GPUSIGN_GAMMA; + pTexture->Format.SignZ = GPUSIGN_GAMMA; + + XGTEXTURE_DESC desc; + XGGetTextureDesc( pTexture, 0, &desc ); + + //convert to AS_16_16_16_16 format + pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ]; +} + static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { if (g_d3d) @@ -352,6 +433,8 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i vid->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, 0, &vid->lpTexture, NULL); + xdk360_convert_texture_to_as16_srgb(vid->lpTexture); + D3DLOCKED_RECT d3dlr; vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); diff --git a/gfx/shader_hlsl.c b/gfx/shader_hlsl.c index 75d09a37db..abb64866b1 100644 --- a/gfx/shader_hlsl.c +++ b/gfx/shader_hlsl.c @@ -87,7 +87,7 @@ void hlsl_set_proj_matrix(XMMATRIX rotation_value) #define set_param_2f(param, xy, constanttable) \ if (param) constanttable->SetFloatArray(d3d_device_ptr, param, xy, 2) #define set_param_1f(param, x, constanttable) \ - constanttable->SetFloat(d3d_device_ptr, param, x) + if (param) constanttable->SetFloat(d3d_device_ptr, param, x) void hlsl_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, @@ -237,27 +237,16 @@ static bool load_preset(const char *path) static void set_program_attributes(unsigned i) { - SSNES_LOG("Fragment: IN.video_size.\n"); prg[i].vid_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.video_size"); - SSNES_LOG("Fragment: IN.texture_size.\n"); prg[i].tex_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.texture_size"); - SSNES_LOG("Fragment: IN.output_size.\n"); prg[i].out_size_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.output_size"); - SSNES_LOG("Fragment: IN.frame_count.\n"); prg[i].frame_cnt_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.frame_count"); - SSNES_LOG("Fragment: IN.frame_direction.\n"); prg[i].frame_dir_f = prg[i].f_ctable->GetConstantByName(NULL, "$IN.frame_direction"); - SSNES_LOG("Vertex: IN.video_size.\n"); prg[i].vid_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.video_size"); - SSNES_LOG("Vertex: IN.texture_size.\n"); prg[i].tex_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.texture_size"); - SSNES_LOG("Vertex: IN.output_size.\n"); prg[i].out_size_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.output_size"); - SSNES_LOG("Vertex: IN.frame_count.\n"); prg[i].frame_cnt_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_count"); - SSNES_LOG("Vertex: IN.frame_direction.\n"); prg[i].frame_dir_v = prg[i].v_ctable->GetConstantByName(NULL, "$IN.frame_direction"); - SSNES_LOG("Vertex: modelViewProj.\n"); prg[i].mvp = prg[i].v_ctable->GetConstantByName(NULL, "$modelViewProj"); }