Merge remote-tracking branch 'upstream/master'

This commit is contained in:
radius 2015-04-05 11:49:26 -05:00
commit ae19769ebe
6 changed files with 124 additions and 132 deletions

View File

@ -21,9 +21,7 @@
#endif
#include "d3d.h"
#ifndef _XBOX
#include "render_chain.h"
#endif
#include "../video_viewport.h"
#include "../video_monitor.h"
#include "../../runloop.h"
@ -103,7 +101,6 @@ static HMONITOR monitor_all[MAX_MONITORS];
static unsigned monitor_count;
#endif
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_HLSL)
void renderchain_deinit_shader(void);
bool renderchain_init_shader(void *data);
@ -116,7 +113,6 @@ static bool d3d_init_shader(void *data)
{
return renderchain_init_shader(data);
}
#endif
static void d3d_deinit_chain(d3d_video_t *d3d)
{
@ -140,9 +136,7 @@ static void d3d_deinitialize(d3d_video_t *d3d)
font_ctx->free(d3d->font_handle);
font_ctx = NULL;
d3d_deinit_chain(d3d);
#ifdef HAVE_SHADERS
d3d_deinit_shader(d3d);
#endif
#ifndef _XBOX
d3d->needs_restore = false;
@ -254,13 +248,11 @@ static bool d3d_initialize(d3d_video_t *d3d, const video_info_t *info)
d3d_calculate_rect(d3d, d3d->screen_width, d3d->screen_height,
info->force_aspect, global->system.aspect_ratio);
#ifdef HAVE_SHADERS
if (!d3d_init_shader(d3d))
{
RARCH_ERR("Failed to initialize shader subsystem.\n");
return false;
}
#endif
if (!d3d_init_chain(d3d, info))
{
@ -613,7 +605,7 @@ static bool d3d_construct(d3d_video_t *d3d,
enum rarch_shader_type type =
video_shader_parse_type(settings->video.shader_path, RARCH_SHADER_NONE);
if (settings->video.shader_enable && type == RARCH_SHADER_CG)
d3d->cg_shader = settings->video.shader_path;
d3d->shader_path = settings->video.shader_path;
if (!d3d_process_shader(d3d))
return false;
@ -845,51 +837,6 @@ static RECT d3d_monitor_rect(d3d_video_t *d3d)
}
#endif
#ifndef _XBOX
static void d3d_recompute_pass_sizes(d3d_video_t *d3d)
{
unsigned i;
LinkInfo link_info = {0};
link_info.pass = &d3d->shader.pass[0];
link_info.tex_w = link_info.tex_h =
d3d->video_info.input_scale * RARCH_SCALE_BASE;
unsigned current_width = link_info.tex_w;
unsigned current_height = link_info.tex_h;
unsigned out_width = 0;
unsigned out_height = 0;
if (!renderchain_set_pass_size(d3d->chain, 0,
current_width, current_height))
{
RARCH_ERR("[D3D]: Failed to set pass size.\n");
return;
}
for (i = 1; i < d3d->shader.passes; i++)
{
renderchain_convert_geometry(d3d->chain, &link_info,
&out_width, &out_height,
current_width, current_height, &d3d->final_viewport);
link_info.tex_w = next_pow2(out_width);
link_info.tex_h = next_pow2(out_height);
if (!renderchain_set_pass_size(d3d->chain, i,
link_info.tex_w, link_info.tex_h))
{
RARCH_ERR("[D3D]: Failed to set pass size.\n");
return;
}
current_width = out_width;
current_height = out_height;
link_info.pass = &d3d->shader.pass[i];
}
}
#endif
#ifndef DONT_HAVE_STATE_TRACKER
#ifndef _XBOX
static bool d3d_init_imports(d3d_video_t *d3d)
@ -1146,7 +1093,7 @@ static bool d3d_init_multipass(d3d_video_t *d3d)
unsigned i;
bool use_extra_pass;
video_shader_pass *pass = NULL;
config_file_t *conf = config_file_new(d3d->cg_shader.c_str());
config_file_t *conf = config_file_new(d3d->shader_path.c_str());
if (!conf)
{
@ -1165,7 +1112,7 @@ static bool d3d_init_multipass(d3d_video_t *d3d)
config_file_free(conf);
video_shader_resolve_relative(&d3d->shader, d3d->cg_shader.c_str());
video_shader_resolve_relative(&d3d->shader, d3d->shader_path.c_str());
RARCH_LOG("[D3D9 Meta-Cg] Found %u shaders.\n", d3d->shader.passes);
@ -1259,7 +1206,7 @@ static bool d3d_init_singlepass(d3d_video_t *d3d)
pass->fbo.type_y = RARCH_SCALE_VIEWPORT;
pass->fbo.scale_x = pass->fbo.scale_y;
pass->fbo.type_x = pass->fbo.type_y;
strlcpy(pass->source.path, d3d->cg_shader.c_str(),
strlcpy(pass->source.path, d3d->shader_path.c_str(),
sizeof(pass->source.path));
#endif
@ -1270,7 +1217,7 @@ static bool d3d_process_shader(d3d_video_t *d3d)
{
#ifdef HAVE_FBO
if (strcmp(path_get_extension(
d3d->cg_shader.c_str()), "cgp") == 0)
d3d->shader_path.c_str()), "cgp") == 0)
return d3d_init_multipass(d3d);
#endif
@ -1622,10 +1569,8 @@ static bool d3d_frame(void *data, const void *frame,
d3d->screen_height, d3d->video_info.force_aspect,
global->system.aspect_ratio);
#ifndef _XBOX
renderchain_set_final_viewport(d3d->chain, &d3d->final_viewport);
d3d_recompute_pass_sizes(d3d);
#endif
renderchain_set_final_viewport(d3d,
d3d->chain, &d3d->final_viewport);
d3d->should_resize = false;
}
@ -1815,10 +1760,8 @@ static bool d3d_set_shader(void *data,
break;
}
std::string old_shader = d3d->cg_shader;
#ifdef HAVE_CG
d3d->cg_shader = shader;
#endif
std::string old_shader = d3d->shader_path;
d3d->shader_path = shader;
if (!d3d_process_shader(d3d) || !d3d_restore(d3d))
{
@ -1828,9 +1771,7 @@ static bool d3d_set_shader(void *data,
if (restore_old)
{
#ifdef HAVE_CG
d3d->cg_shader = old_shader;
#endif
d3d->shader_path = old_shader;
d3d_process_shader(d3d);
d3d_restore(d3d);
}

View File

@ -130,7 +130,7 @@ typedef struct d3d_video
unsigned dev_rotation;
D3DVIEWPORT final_viewport;
std::string cg_shader;
std::string shader_path;
#ifndef _XBOX
struct video_shader shader;

View File

@ -265,17 +265,16 @@ void d3d_clear(LPDIRECT3DDEVICE dev,
void d3d_lockrectangle_clear(void *data,
LPDIRECT3DTEXTURE tex,
unsigned level, D3DLOCKED_RECT *lock_rect, RECT *rect,
unsigned flags)
unsigned rectangle_height, unsigned flags)
{
#if defined(_XBOX)
d3d_video_t *chain = (d3d_video_t*)data;
d3d_video_t *d3d = (d3d_video_t*)data;
D3DTexture_LockRect(tex, level, lock_rect, rect, flags);
memset(lock_rect->pBits, 0, chain->tex_h * lock_rect->Pitch);
memset(lock_rect->pBits, 0, d3d->tex_h * lock_rect->Pitch);
#else
Pass *pass = (Pass*)data;
if (SUCCEEDED(tex->LockRect(level, lock_rect, rect, flags)))
{
memset(lock_rect->pBits, level, pass->info.tex_h * lock_rect->Pitch);
memset(lock_rect->pBits, level, rectangle_height * lock_rect->Pitch);
tex->UnlockRect(0);
}
#endif

View File

@ -17,6 +17,7 @@
#include "render_chain.h"
#include <string.h>
#include <retro_inline.h>
#include "../inc/Cg/cg.h"
struct lut_info
{
@ -25,6 +26,29 @@ struct lut_info
bool smooth;
};
struct Vertex
{
float x, y, z;
float u, v;
float lut_u, lut_v;
float r, g, b, a;
};
struct Pass
{
LinkInfo info;
LPDIRECT3DTEXTURE tex;
LPDIRECT3DVERTEXBUFFER vertex_buf;
#ifdef HAVE_CG
CGprogram vPrg, fPrg;
#endif
unsigned last_width, last_height;
#ifdef HAVE_D3D9
LPDIRECT3DVERTEXDECLARATION vertex_decl;
#endif
std::vector<unsigned> attrib_map;
};
typedef struct renderchain
{
LPDIRECT3DDEVICE dev;
@ -822,13 +846,60 @@ void renderchain_clear(void *data)
chain->luts.clear();
}
void renderchain_set_final_viewport(void *data, const void *viewport_data)
static void d3d_recompute_pass_sizes(d3d_video_t *d3d)
{
renderchain_t *chain = (renderchain_t*)data;
unsigned i;
LinkInfo link_info = {0};
link_info.pass = &d3d->shader.pass[0];
link_info.tex_w = link_info.tex_h =
d3d->video_info.input_scale * RARCH_SCALE_BASE;
unsigned current_width = link_info.tex_w;
unsigned current_height = link_info.tex_h;
unsigned out_width = 0;
unsigned out_height = 0;
if (!renderchain_set_pass_size(d3d->chain, 0,
current_width, current_height))
{
RARCH_ERR("[D3D]: Failed to set pass size.\n");
return;
}
for (i = 1; i < d3d->shader.passes; i++)
{
renderchain_convert_geometry(d3d->chain, &link_info,
&out_width, &out_height,
current_width, current_height, &d3d->final_viewport);
link_info.tex_w = next_pow2(out_width);
link_info.tex_h = next_pow2(out_height);
if (!renderchain_set_pass_size(d3d->chain, i,
link_info.tex_w, link_info.tex_h))
{
RARCH_ERR("[D3D]: Failed to set pass size.\n");
return;
}
current_width = out_width;
current_height = out_height;
link_info.pass = &d3d->shader.pass[i];
}
}
void renderchain_set_final_viewport(void *data,
void *renderchain_data, const void *viewport_data)
{
d3d_video_t *d3d = (d3d_video_t*)data;
renderchain_t *chain = (renderchain_t*)renderchain_data;
const D3DVIEWPORT *final_viewport = (const D3DVIEWPORT*)viewport_data;
if (chain)
chain->final_viewport = (D3DVIEWPORT*)final_viewport;
d3d_recompute_pass_sizes(d3d);
}
bool renderchain_set_pass_size(void *data, unsigned pass_index,
@ -1310,13 +1381,38 @@ void renderchain_blit_to_texture(void *data, const void *frame,
if (first->last_width != width || first->last_height != height)
{
d3d_lockrectangle_clear(first, first->tex, 0, &d3dlr,
NULL, D3DLOCK_NOSYSLOCK);
NULL, first->info.tex_h, D3DLOCK_NOSYSLOCK);
}
d3d_texture_blit(driver->video_data, chain->pixel_size, first->tex,
&d3dlr, frame, width, height, pitch);
}
static void renderchain_unbind_all(void *data)
{
unsigned i;
renderchain_t *chain = (renderchain_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
/* Have to be a bit anal about it.
* Render targets hate it when they have filters apparently.
*/
for (i = 0; i < chain->bound_tex.size(); i++)
{
d3d_set_sampler_minfilter(d3dr,
chain->bound_tex[i], D3DTEXF_POINT);
d3d_set_sampler_magfilter(d3dr,
chain->bound_tex[i], D3DTEXF_POINT);
d3d_set_texture(d3dr, chain->bound_tex[i], NULL);
}
for (i = 0; i < chain->bound_vert.size(); i++)
d3d_set_stream_source(d3dr, chain->bound_vert[i], 0, 0, 0);
chain->bound_tex.clear();
chain->bound_vert.clear();
}
void renderchain_render_pass(void *data, void *pass_data, unsigned pass_index)
{
unsigned i;
@ -1402,27 +1498,3 @@ void renderchain_log_info(void *data, const void *info_data)
info->pass->filter == RARCH_FILTER_LINEAR ? "true" : "false");
}
void renderchain_unbind_all(void *data)
{
unsigned i;
renderchain_t *chain = (renderchain_t*)data;
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
/* Have to be a bit anal about it.
* Render targets hate it when they have filters apparently.
*/
for (i = 0; i < chain->bound_tex.size(); i++)
{
d3d_set_sampler_minfilter(d3dr,
chain->bound_tex[i], D3DTEXF_POINT);
d3d_set_sampler_magfilter(d3dr,
chain->bound_tex[i], D3DTEXF_POINT);
d3d_set_texture(d3dr, chain->bound_tex[i], NULL);
}
for (i = 0; i < chain->bound_vert.size(); i++)
d3d_set_stream_source(d3dr, chain->bound_vert[i], 0, 0, 0);
chain->bound_tex.clear();
chain->bound_vert.clear();
}

View File

@ -20,17 +20,8 @@
#include "d3d.h"
#include "../video_state_tracker.h"
#include "../video_shader_parse.h"
#include "../inc/Cg/cg.h"
#include "../../libretro.h"
struct Vertex
{
float x, y, z;
float u, v;
float lut_u, lut_v;
float r, g, b, a;
};
struct LinkInfo
{
unsigned tex_w, tex_h;
@ -45,21 +36,6 @@ enum
TEXTURESMASK = TEXTURES - 1
};
struct Pass
{
LinkInfo info;
LPDIRECT3DTEXTURE tex;
LPDIRECT3DVERTEXBUFFER vertex_buf;
#ifdef HAVE_CG
CGprogram vPrg, fPrg;
#endif
unsigned last_width, last_height;
#ifdef HAVE_D3D9
LPDIRECT3DVERTEXDECLARATION vertex_decl;
#endif
std::vector<unsigned> attrib_map;
};
void renderchain_free(void *data);
void *renderchain_new(void);
@ -78,7 +54,8 @@ bool renderchain_init(void *data, const video_info_t *video_info,
void renderchain_clear(void *data);
void renderchain_set_final_viewport(void *data, const void *viewport_data);
void renderchain_set_final_viewport(void *data,
void *renderchain_data, const void *viewport_data);
bool renderchain_set_pass_size(void *data, unsigned pass_index,
unsigned width, unsigned height);
@ -127,8 +104,6 @@ void renderchain_render_pass(void *data, void *pass_data, unsigned pass_index);
void renderchain_log_info(void *data, const void *info_data);
void renderchain_unbind_all(void *data);
bool renderchain_compile_shaders(void *data, void *fragment_data,
void *vertex_data, const std::string &shader);

View File

@ -250,7 +250,7 @@ static void renderchain_blit_to_texture(void *data, const void *frame,
if (d3d->last_width != width || d3d->last_height != height)
{
d3d_lockrectangle_clear(d3d, d3d->tex,
0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
0, &d3dlr, NULL, 0 /* FIXME - stub */, D3DLOCK_NOSYSLOCK);
}
d3d_texture_blit(driver->video_data, 0, d3d->tex,
@ -294,5 +294,10 @@ static void renderchain_render_pass(void *data, const void *frame,
renderchain_set_mvp(d3d, d3d->screen_width, d3d->screen_height, d3d->dev_rotation);
}
void renderchain_set_final_viewport(void *data,
void *renderchain_data, const void *viewport_data)
{
(void)data;
(void)renderchain_data;
(void)viewport_data;
}